Dragging Items in an Inventory GUI

Discussion in 'Spigot Plugin Development' started by Hunky524, May 17, 2016.

  1. I just have a quick question. I currently have a custom shop GUI setup, it is working perfectly fine except for one small issue, when a player is dragging an item across the GUI and clicks to place it while still moving their mouse, it places the item in the GUI when the event should be cancelling it. I have been able to cancel every other way I have found to put/glitch items into the GUI, but I cannot find a solution for this issue. If what I said doesn't make sense, I might try and add a clip to show you guys. If what I said makes sense and you have ideas I'd be glad to hear them :)
     
  2. could we see your code?
     
  3. A clip and perhaps code would help.
     
    • Agree Agree x 1
  4. Code (Text):
    @EventHandler
        public void shopCheck(InventoryClickEvent e) {
            Player p = (Player) e.getWhoClicked();

            if (p.getOpenInventory().getTopInventory() == null)
                return;

            String shopName = p.getOpenInventory().getTopInventory().getTitle().toLowerCase();

            if (!ShopAccessor.serverShops.containsKey(ChatColor.stripColor(shopName)))
                return;

            if (e.getClick().isShiftClick()) {
                e.setCancelled(true);
                return;
            }

            if (e.getClickedInventory() != p.getOpenInventory().getTopInventory())
                return;

            e.setCancelled(true);

            ItemStack clickedItem = e.getCurrentItem();
           
            if (clickedItem == null || clickedItem.getType() == Material.AIR)
                return;
           
            ServerShop shop = ShopAccessor.serverShops.get(ChatColor.stripColor(e.getClickedInventory().getName().toLowerCase()));
            shop.openCheckout(p, clickedItem);
        }
     
  5. Here is a video to try and illustrate my problem better:
     
  6. Your vid is private
     
  7. That's awkward, my bad. Here is a new link just in case:
     
  8. Ohh I see what you mean... Yeah idk how to even fix that tbh
     
  9. A little search in the Javadoc.. >.<
     
    • Agree Agree x 1
  10. I will try out the dragEvent when I get home. I'm going to wait to mark it as solved until I know for sure or in case someone else has a different idea. Thanks though :)
     
  11. Maybe contact a high-p. dev?
     
  12. Yea, I'm not sure. Using InventoryDragEvent doesn't fix the issue so I'm not sure what to do.
     
  13. Strange that it didn't fix it for you. Try debugging your code?
     
  14. Does anyone know how other (even premium) GUI plugins resolve this issue, or do they use InventoryDragEvent?
     
  15. I've used the event before in GUIs and it is the intended way to stop someone from dragging an item to place it. I'm doubtful there even is another way to do it o.o
     
  16. Well seeing as this was a first version of my plugin, and now that I have swapped over to IntelliJ. I am just remaking everything far more efficient and neat that I did before because I know what I want to do. So maybe, just maybe, when I finish recreating the plugin in a couple days here the event will work properly. If not you'll probably see me back here asking more questions.