Selling Commands - Shopkeepers/Shopkeepers-Wiki GitHub Wiki
It is possible to create items that execute a command when they are traded, instead of being given to the trading player or shopkeeper.
Create an item that executes a command when traded
You can use the /shopkeeper setTradedCommand <command|'-'|'?'>
command to assign a command to the item that you currently hold in your main hand.
Examples:
/shopkeeper settradedcommand tellraw {player_name} "Items received. Thank you."
/shopkeeper settradedcommand eco give {player_name} 100
When the item is traded (either sold by or to a shopkeeper), it is destroyed and the assigned command is executed as often as there are items in the traded item stack.
The command is stored inside the item's data in the PublicBukkitValues
section with key shopkeepers:traded_command
.
You can use other tools, commands, or plugins to change the appearance and other properties of the item however you like: As long as the item contains a value with this key, it will execute the command when it is traded.
Placeholders
The following placeholders are supported inside the assigned command:
{player_name}
: Replaced with the trading player's name.{player_uuid}
: Replaced with the trading player's unique id.{player_displayname}
: Replaced with the trading player's display name.{shop_uuid}
: Replaced with the shopkeeper's unique id.
Executing multiple commands
Only a single command can be assigned to an item (see Limitations). However, you can define simple command sequences and execute them via a command alias in Bukkit's commands.yml
file.
Executing the command as the trading player
The assigned command is run by the server console.
You can use Minecraft's /execute
command to execute a command as the trading player.
Trading for nothing in return
This feature can also be used to set up trades that give nothing in return, e.g. if you, as an admin, want to use a player shopkeeper as a sophisticated way to collect items: Just set up a trade with a result item that has some dummy command (e.g. tellraw
) assigned.
Limitations
This feature is not meant to replace the requirement for custom third-party plugins or scripts in order to implement complex or custom trading behaviors. In order to reduce implementation and maintenance effort and prevent this feature from evolving into a complex scripting engine over time, only a single command can be assigned to an item, and only a very limited set of placeholders is supported (see above).
Any more advanced features, e.g. random command selections, conditional commands, delays between commands, etc., are left to be implemented by third-party plugins or scripts, and then be invoked via command.
For example, you can also take a look at scripting plugins such as DenizenScript
: This plugin allows you to write custom scripts that can then be invoked via the /ex
command.
If additional context information is required, e.g. about the shopkeeper's location or shop owner, a custom plugin that listens for the ShopkeeperTradeEvent
might be better suited to implement the intended behavior.