Add an action
First of all
You should see how create a new item if you do not have read it.
Types of Actions
There is 3 types of actions :
LEFT_CLICK
RIGHT_CLICK
MIDDLE_CLICK
These actions allow you to add an effect when one of these action is used on your items.
Create a new action
GuiItem myItem() {
GuiItem item = new GuiItem(Material.MATERIAL)
.setAction(ItemActions.LEFT_CLICK,
(player, plugin) {
//here the plugin == null because we didn't set it in constructor
Bukkit.getConsoleSender().sendMessage("Player " +
player.getDisplayName() +
" clicked on my item !");
}
);
return item;
}
Pay attention, when you use your plugin in an action, you have to cast it because plugin argument is a JavaPlugin and not your plugin directly.
Last updated