getting clicked item.

Discussion in 'Plugin Development' started by TheGamesHawk2001, Dec 4, 2014.

Thread Status:
Not open for further replies.
  1. Hey. I have an inventory and I want it to do a separate thing when they click on a different block.
    Here's my code and it doesn't seem to do anything when I click on stone.

    Code:java
    1. public static Inventory Inv = Bukkit.createInventory(null, 18, F.green + "Select a kit!");
    2.  
    3. //INVENTORY
    4. static {
    5. //TP places
    6. ItemStack snowblock = new ItemStack(Material.SNOW_BLOCK, 1);
    7. ItemMeta snowmeta = snowblock.getItemMeta();
    8. snowmeta.setDisplayName(F.gold + F.bold + "Sweets");
    9. snowmeta.setLore(Arrays.asList(F.gray + "Teleport to the Sweet shop."));
    10. snowblock.setItemMeta(snowmeta);
    11. Inv.setItem(9, snowblock);
    12. //InMate
    13. ItemStack stone = new ItemStack(Material.STONE, 1);
    14. ItemMeta stonemeta = stone.getItemMeta();
    15. stonemeta.setDisplayName(F.pink + "Inmate (Click me)");
    16. stonemeta.setLore(Arrays.asList(F.gray + "Kit inmate is the most basic kit."));
    17. stone.setItemMeta(stonemeta);
    18. Inv.setItem(1, stone);
    19.  
    20.  
    21. }
    22.  
    23. public HashMap<String, Long> inmateCool = new HashMap<String, Long>();
    24.  
    25. @EventHandler
    26. public void onInventoryClick(InventoryClickEvent event) {
    27. Player player = (Player) event.getWhoClicked(); // The player that clicked the item
    28. ItemStack clicked = event.getCurrentItem(); // The item that was clicked
    29. Inventory inventory = event.getInventory(); // The inventory that was clicked in
    30. if (inventory.getName().equals(Inv.getName())) { // The inventory is our custom Inventory
    31. if (clicked.getType() == Material.STONE) { // Stone, the inmate kit
    32. event.setCancelled(true); // Make it so the item cant be taken
     
  2. Offline

    SuperOriginal

    Did you register your events correctly, and why do you have a static body?
     
  3. Offline

    Dragonphase

    ILLOGICAL USE OF STATIC KEYWORD
    [​IMG]
    PLEASE LEARN JAVA AND OOP

    Or, you could make the ItemStack and Inventory constant by appending the final keyword...
     
  4. Offline

    SuperOriginal

    TheGamesHawk2001 Just because a tutorial says so doesn't mean it's the absolute right/effiecient way to do something.
     
  5. Well, Can you give me an alternative?
     
  6. If you take a look on youtube or the forums there are a few tutorials / ways to do it, for example this is a tutorial from Turqmelon located at youtube.
     
  7. Offline

    mythbusterma

    TheSuddenlyFamous

    Please don't link awful YouTube tutorials, it really degrades the quality of these forums.

    TheGamesHawk2001

    Add final modifiers, it's something that should be constant anyway.
     
  8. Offline

    JordyPwner

Thread Status:
Not open for further replies.

Share This Page