Solved Deny clicking it or moving it ?

Discussion in 'Plugin Development' started by Sean0402, Aug 13, 2014.

Thread Status:
Not open for further replies.
  1. Hello how do I stop them from dragging out the iron helmet from inside the armour inventory?

    Code:java
    1. @EventHandler
    2. public void onInventoryClick1(InventoryClickEvent e) {
    3. Inventory potions = Bukkit.createInventory(null, 9, ChatColor.GREEN + "Potions");
    4. Inventory enchants = Bukkit.createInventory(null, 9, ChatColor.BLUE + "Enchants");
    5. Inventory armour = Bukkit.createInventory(null, 9, ChatColor.DARK_RED + "Armour");
    6. ItemStack iron_helmet = new ItemStack(Material.IRON_HELMET);
    7. ItemMeta meta = iron_helmet.getItemMeta();
    8. iron_helmet.setItemMeta(meta);
    9. ItemStack helmet = new ItemStack(Material.IRON_HELMET);
    10. ItemMeta im = helmet.getItemMeta();
    11. Player p = (Player)e.getWhoClicked();
    12. if (e.getInventory().getName().equals(ChatColor.GOLD + "Shop")) {
    13. if (e.getCurrentItem() == null)
    14. return;
    15. if (e.getCurrentItem().getItemMeta().getDisplayName()
    16. .equals(ChatColor.DARK_RED + "Armour")) {
    17. e.getWhoClicked().openInventory(armour);
    18. if(e.getCurrentItem() == null)
    19. e.getCurrentItem().hasItemMeta();
    20. armour.setItem(0,iron_helmet);
    21. e.setCancelled(true);
    22. if(e.getCurrentItem().getItemMeta().getDisplayName().equals(ChatColor.DARK_RED + "Armour"))
    23. e.setCancelled(true);
    24. }
     
  2. Offline

    _Cookie_

    InventoryInteractEvent? Just listen for that inventory then cancel it when they try to Interact.. :)
     
  3. _Cookie_ I'm gonna sound stupid but how do I listen for it? How to like find it..
     
  4. Offline

    _Cookie_

    You should just be able to use in your listener,

    Code:java
    1. if(e.getCurrentItem.getType() == Material.IRON_HELMET){
    2. event.setCancelled(true);
    3. }


    Something like that..
     
  5. _Cookie_ For some reason my whole code has broke and no longer is working.. No idea why

    _Cookie_ That doesn't seem to work
    Code:java
    1. @EventHandler
    2. public void onInventoryClick1(InventoryClickEvent e) {
    3. Inventory potions = Bukkit.createInventory(null, 9, ChatColor.GREEN + "Potions");
    4. Inventory enchants = Bukkit.createInventory(null, 9, ChatColor.BLUE + "Enchants");
    5. Inventory armour = Bukkit.createInventory(null, 9, ChatColor.DARK_RED + "Armour");
    6. ItemStack iron_helmet = new ItemStack(Material.IRON_HELMET);
    7. ItemMeta meta = iron_helmet.getItemMeta();
    8. iron_helmet.setItemMeta(meta);
    9. ItemStack helmet = new ItemStack(Material.IRON_HELMET);
    10. ItemMeta im = helmet.getItemMeta();
    11. Player p = (Player)e.getWhoClicked();
    12. if (e.getInventory().getName().equals(ChatColor.GOLD + "Shop")) {
    13. if (e.getCurrentItem() == null)
    14. return;
    15. if (e.getCurrentItem().getItemMeta().getDisplayName()
    16. .equals(ChatColor.DARK_RED + "Armour")) {
    17. e.getWhoClicked().openInventory(armour);
    18. armour.setItem(0,iron_helmet);
    19. if(e.getCurrentItem() == null)
    20. e.getCurrentItem().hasItemMeta();
    21. if(e.getCurrentItem().getType() == Material.IRON_HELMET){
    22. e.setCancelled(true);
    23. }
    24. if(e.getCurrentItem().getItemMeta().getDisplayName().equals(ChatColor.DARK_RED + "Armour"))
    25. e.setCancelled(true);
    26. }


    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  6. Offline

    RenditionsRule

    Try checking if the item ".equals(iron_helmet)" and then run the event cancel code aswell as whatever else you want it to do. It's more complicated the way you do it...

    Sean0402 Check if the current item is exactly the same as the item you are clicking using ".equals()" and then run the event functions.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  7. I solved it anyways! Thanks !
     
Thread Status:
Not open for further replies.

Share This Page