Minecraft plugin program by clicking on item in special inventory to execute a command?

Za
- in Plugins
1

Minecraft plugin program by clicking on item in special inventory to execute a command?

How can you do that?

Here is my source code:

@Override
public boolean onCommand (CommandSender sender, Command cmd, String label, String [] args) {
Player p = (player) transmitter;
if (p.hasPermission ("rankup.open")) {
if ((sender instanceof Player)) {
if (args.length == 0) {
Inventory inventory = Bukkit.createInventory (null, 93, "§6§lRang Shop"); p.sendMessage ("§7You have the Rank-Up menu open!"); p.openInventory (inventory);
ItemStack cost1 = new ItemStack (Material.GOLD_NUGGET);
ItemMeta ITEMMETA = kost1.getItemMeta ();
ITEMMETA.setDisplayName ( "$ §4§l10.000");
kosten1.setItemMeta (ITEMMETA);

ItemStack cost2 = new ItemStack (Material.GOLD_NUGGET);
ItemMeta item = kost2.getItemMeta ();
item.setDisplayName ( "$ §4§l100.000");
kosten2.setItemMeta (item);

ItemStack cost3 = new ItemStack (Material.GOLD_NUGGET);
ItemMeta halt = kosten3.getItemMeta ();
halt.setDisplayName ( "$ §4§l1.000.000");
kosten3.setItemMeta (halt);

ItemStack diamond = new ItemStack (Material.DIAMOND_BLOCK);
ItemMeta itemMeta = diamond.getItemMeta ();
itemMeta.setDisplayName ("§b§lDiamond Rank");
diamond.setItemMeta (itemMeta);

inventory.setItem (11, diamond);

ItemStack ultra = new ItemStack (Material.EMERALD_BLOCK);
ItemMeta ItemMeta = ultra.getItemMeta ();
ItemMeta.setDisplayName ("§a§lUltra rank");
ultra.setItemMeta (ItemMeta);

inventory.setItem (13, ultra);

ItemStack supreme = new ItemStack (Material.PURPUR_BLOCK);
ItemMeta iTemMeta = supreme.getItemMeta ();
iTemMeta.setDisplayName ("§d§lSupreme Rank");
supreme.setItemMeta (iTemMeta);

inventory.setItem (15, supreme);

ItemStack glass = new ItemStack (Material.STAINED_GLASS_PANE);
ItemMeta itemmeta = glass.getItemMeta ();
itemmeta.setDisplayName ( "§6Ränge");
glass.setItemMeta (itemmeta);

inventory.setItem (0, glass);
inventory.setItem (1, glass);
inventory.setItem (2, glass);
inventory.setItem (3, glass);
inventory.setItem (4, glass);
inventory.setItem (5, glass);
inventory.setItem (6, glass);
inventory.setItem (7, glass);
inventory.setItem (8, glass);
inventory.setItem (9, glass);
inventory.setItem (10, glass);
inventory.setItem (12, glass);
inventory.setItem (14, glass);
inventory.setItem (16, glass);
inventory.setItem (17, glass);
inventory.setItem (18, glass);
inventory.setItem (19, glass);
inventory.setItem (20, cost1);
inventory.setItem (21, glass);
inventory.setItem (22, cost2);
inventory.setItem (23, glass);
inventory.setItem (24, cost3);
inventory.setItem (25, glass);
inventory.setItem (26, glass);
inventory.setItem (27, glass);
inventory.setItem (28, glass);

}
}
{

}

}

return false;
}
@EventHandler
public void onClick (InventoryClickEvent e) {
if (e.getInventory (). GetName (). Equals ("§6§lRang Shop")) {
if (e.getCurrentItem ()! = null && e.getCurrentItem (). GetType ()! = Material.AIR) {
e.setCancelled (true);
}
}
}
}}

Di

Just that

InventoryClickEvent # getCurrentItem ()

then you get back an ItemStack and can either compare the name or the material.

Information about the ItemStack can be found here: https://hub.spigotmc.org/...Stack.html

Information about the InventoryClickEvent here: https://hub.spigotmc.org/...Event.html