Removing Items on the InventoryMoveItemEvent

Discussion in 'Spigot Plugin Development' started by AndrewAubury, Apr 16, 2017.

  1. Hello this is probs going to be easy but i dont know how to do it....

    How can i remove the item from the event?

    Code (Text):
        public void onInventoryMoveItem(InventoryMoveItemEvent e) {
            if (e.getDestination().getType() == InventoryType.HOPPER) {
                Main.getInst().getServer().broadcastMessage("Moving Item to hopper!");
                ASkyBlockAPI api = Main.getInst().api;
                // THE ITEM HAS GONE IN TO THE HOPPER!
                Inventory inv = e.getDestination();
                Location loc = inv.getLocation();
                Block b = loc.getBlock();
                UUID owner = api.getIslandAt(loc).getOwner();
                if (loc.subtract(0, 1, 0).getBlock().getType() == Material.ENDER_CHEST) {
                    Main.getInst().getServer().broadcastMessage("Will attempt to put it in the ender inv!");
                    Inventory einv = IslandInventoryStorage.getInstance().getInventory(owner);

    As you can see i am getting My Own inventory and putting the item in there but then it does not remove the other item so it ends up one staying in the chest or hopper and then the other one in the custom inventory
  2. So if I'm getting this right, you want to remove items that go into the chest via a hipper and add them to an enderchest?
  3. Im trying to make it so that i can put then from a chest to a custom inventory using this set up upload_2017-4-16_21-50-28.png
  4. Oh right,
    Do any of your debug statements trigger?
  5. All of them Trigger the item goes in to the enderchest inventory but not removed from the chest or hopper
  6. You may want to store the itemstack, then iterate over the inventory and if the item is the same to remove it