UnMovable items

Discussion in 'Spigot Plugin Development' started by FiXed, May 30, 2016.

  1. So I've been writing a plugin for some time and have tried making an item completely unmoveable but it's not working, they can always drag it or use number keys, I've tried to disable those but I don't want to disable any other item in their inventory so it gets a bit tricky, I've been trying for about 30 mins to try and find a way to disable moving a certain item in the players inventory and it just won't work. This is my current code:
    Code (Java):
        @EventHandler
        public void onDrag(InventoryDragEvent event) {
            if (event.getCursor().equals(ServerSelector.getAPI().getServerSelector())
                    || event.getOldCursor().equals(ServerSelector.getAPI().getServerSelector())) {
                event.setCancelled(true);
            }
        }

        @EventHandler
        public void onClick(InventoryClickEvent event) {
            if (event.getCurrentItem().equals(ServerSelector.getAPI().getServerSelector())) {
                event.setCancelled(true);
            }
        }
    And I can still do this:
    http://i.imgur.com/robF0iP.gifv

    If anyone could give me some pseudo code or something to help that would be great.
     
  2. I use this for the inventory click event:

    Code (Text):
    if (e.getCurrentItem() != null) {
                if (e.getCurrentItem().hasItemMeta() && e.getCurrentItem().getItemMeta().hasDisplayName()) {
                    if (e.getCurrentItem().getItemMeta().getDisplayName().equals(ChatColor.GREEN + "Game Menu!")) {
                        e.setCancelled(true);
                        return;
                    }
                }
            }
     
  3. And if you want it so the player can not drop the item either:
    Code (Text):
    if (e.getItemDrop().getItemStack().isSimilar(LobbySelector.star)) {
                if (e.getItemDrop().getItemStack().hasItemMeta()
                        && e.getItemDrop().getItemStack().getItemMeta().hasDisplayName()) {
                    if (e.getItemDrop().getItemStack().getItemMeta().getDisplayName()
                            .equals(ChatColor.GREEN + "Lobby Selector!")) {
                        e.setCancelled(true);
                        return;
                    }
                }
            }
    but substitute the names and itemstack with yours for both.
     
  4. I'm only looking for drag pretty much, that's my only real problem...
     
  5. Did you try this? It works without the drag event for me.
     
  6. try dragging and number clicking the items, what's your server IP I wanna see the game menu in action :p
     
  7. InventoryInteractEvent maybe?
     
  8. play.universalpvp.us
     
  9. I'll try
    can't log in
     
  10. Hmm, must be fortforward issues.. ugh
     
  11. If I do that then I can't get an item being touched or anything like that, I want to block a player from moving a single item, not from moving all items.
     
  12. I can move the menu:
    [​IMG]
     
  13. Oh wtf
     
  14. It works, for the nether star.
     
  15. Does it work now