Solved InventoryClickEvent duplication

Discussion in 'Plugin Development' started by savagesun, Jan 2, 2014.

Thread Status:
Not open for further replies.
  1. Offline


    I've seen ghost items come about from this ever since I can remember. However, now it seems the items are not just ghost item. Using the updateInventory() method in the Player class does not help. I've also tried using the (also deprecated) setCursor(...) method in the InventoryClickEvent class, but this has not solved it either.

    Here's the code I've been working with:
    1. public class InventoryClickListener implements Listener {
    3. //FIXME duplication issues, cannot drag back
    4. @EventHandler
    5. public void onInventoryClick(InventoryClickEvent evt) {
    6. if(evt.getInventory().getType().equals(InventoryType.CHEST)) {//we're viewing a chest
    7. if(!(evt.getRawSlot() >= evt.getView().getTopInventory().getSize()) && !evt.getSlotType().equals(SlotType.OUTSIDE)) {//we're actually using the chest && we're not clicking outside
    8. if (ChestShopSign.isShopChest(((BlockState) evt.getInventory().getHolder()).getBlock())) {//this is a chest shop
    9. if(evt.getWhoClicked() instanceof Player) {//it's a player clicking
    10. Player p = (Player)evt.getWhoClicked();
    12. if(!p.hasPermission("")) {//they don't have perms to move things around.
    13. p.sendMessage(ChatColor.RED + "You cannot move items in shops!");
    14. evt.setCancelled(true);
    15. }
    16. }
    17. }
    18. }
    19. }
    20. }
    21. }

    It works for the most part, minus the duplication. The steps to recreating the duplication are to take the item from a chest, place it in the player inventory "E" key out of the inventory, reopen the player inventory and place it in the hotbar. From there the item can be used regularly.

    Have I goofed somewhere in the code? Any help is appreciated. Thanks!
  2. Offline


    I had a very similar problem. I fixed mine with player.updateInventory(), but that seems not to be working for you. Is there another way to update the CHEST inventory though?, because its technically not the player's inventory. I could be wrong though, I'm still a newb. PLUS try evt.setResult(Result.DENY).
  3. Offline


    savagesun Check if you have any other plugins or any code that may conflict with this. I have tested it and it works 100%. No problems.
  4. Offline


    It appears that the issue arises from joining the server under a 1.7.2 profile. When connected through a 1.7.4 client everything works perfectly fine. Can anyone else replicate this?
  5. Offline


    I read this from a plugin description:
    Warning: Minecraft (Client) 1.7.2 has some bugs regarding inventory clicks, that create ghost items (they're not real, but is confusing). It's fixed in 1.7.4.
Thread Status:
Not open for further replies.

Share This Page