Plugin Help Block item from entering chest in any way

Discussion in 'Plugin Help/Development/Requests' started by Scorpionvssub, Jul 22, 2016.

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

    Scorpionvssub

    Code:
        @EventHandler
        public void onInventoryClick(InventoryClickEvent e) {
            if (e.getClick().isShiftClick()) {
                Inventory clicked = e.getClickedInventory();
                if (clicked == e.getWhoClicked().getInventory()) {
                    ItemStack clickedON = e.getCurrentItem();
    
                    if (clickedON != null && (clickedON.getType().equals(Material.PAPER))) {
                        String pa = ChatColor.stripColor(clickedON.getItemMeta().getDisplayName());
    
                        if (pa == null) {
                            return;
                        }
                        if (pa.equals(plugin.getConfig().getString("ClueSettings.name"))) {
                            e.getWhoClicked().sendMessage("Not allowed to shiftclick");
                            e.setCancelled(true);
                        }
                    }
                }
            }
        }
    
        @EventHandler
        public void onItemMove(InventoryMoveItemEvent e) {
            Player clicked = (Player) e.getSource();
            if (e.getDestination() instanceof Chest) {
                ItemStack onCursor = e.getItem();
                if (onCursor != null && (onCursor.getType().equals(Material.PAPER))) {
                    clicked.sendMessage("thats also a paper ...");
                    String pa = ChatColor.stripColor(onCursor.getItemMeta().getDisplayName());
    
                    if (pa == null) {
                        return;
                    }
                    if (pa.equals(plugin.getConfig().getString("ClueSettings.name"))) {
                        clicked.sendMessage("Not allowed to move this item");
                        e.setCancelled(true);
                    }
                }
            }
        }
    
        @EventHandler
        public void onInventoryDrag(InventoryDragEvent e) {
            ItemStack dragged = e.getOldCursor();
            e.getWhoClicked().sendMessage("Drag Event");
            if (dragged.getType().equals(Material.PAPER)) {
                e.getWhoClicked().sendMessage("its a paper yup");
                String pa = ChatColor.stripColor(dragged.getItemMeta().getDisplayName());
    
                if (pa == null) {
                    e.getWhoClicked().sendMessage("That item has no name...");
                    return;
                }
                if (pa.equals(plugin.getConfig().getString("ClueSettings.name"))) {
                    int inventorysize = e.getInventory().getSize();
                    for (int i : e.getRawSlots()) {
                        if (i < inventorysize) {
                            e.setCancelled(true);
                            break;
                        }
                    }
                }
    
            }
        }
    im trying to block a certain item from being moved basicly at all, including from inventorys to another inventory, in any way shape or form. leftclicking dragging etc. like chests enderchests and hoppers or other items with some type of inventory

    I got the shiftclick to work, the drag only works for 10% of the time and the move event doesn't do anything at all really
    Anyone got an idea?
     
  2. Offline

    thapengwin

    You need the click event only, and to detect all cases. If you can't click, you can neither drag nor move.
     
  3. Offline

    Scorpionvssub

    Code:
        @EventHandler (priority = EventPriority.HIGH)
        public void onItemMove(InventoryMoveItemEvent e) {
            System.out.println("Item being moved");
            if (e.getDestination().getType() == InventoryType.CHEST) {
                System.out.println("Chest use");
                ItemStack clickedON = e.getItem();
                System.out.println("Clicked on " + clickedON);
    
                if (clickedON != null && (clickedON.getType().equals(Material.PAPER))) {
                    System.out.println("Thats a paper");
                    String pa = ChatColor.stripColor(String.valueOf(clickedON.getItemMeta().getDisplayName()));
    
                    if (pa == null) {
                        return;
                    }
                    if (pa.equals(plugin.getConfig().getString("ClueSettings.name"))) {
                        System.out.println("Thats a clue");
                        e.setCancelled(true);
                    }
                }
            }
        }
    When i place this(the item) into a hopper it spams my console with everything and won't allow the hopper to add said item to the chest. BUT i fail to see why the plugin only blocks hoppers which i didn't specify and still allows players to put the items into the chest while also not specified i mainly just attempted a global block of the item entering the chest in any way via player aswell as hoppers...i don't get it..Shiftclicking is blocked though

    bump

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jul 23, 2016
Thread Status:
Not open for further replies.

Share This Page