Solved Listen for hopper moving item into another hopper

Discussion in 'Spigot Plugin Development' started by Webmets, Jun 4, 2017.

  1. Hello, for a plugin im currently working on, I want to prevent certain hoppers (I have a List<Block> for the hoppers that are canceled), and in the InventoryMoveItemEvent, I can listen for items being moved. However, I need to get the location of the inventory (After I did the checks to make sure both inventories are indeed hoppers). How can I go about doing this?
    So far, I have this basic code
    Code (Text):

    @EventHandler
        public void InventoryMoveItemEvent(InventoryMoveItemEvent e) {
            if(e.getDestination().getType() != InventoryType.HOPPER) return;
            if(e.getSource().getType() != InventoryType.HOPPER) return;
        }
     
     
  2. Thanks for the tip!
    After looking more into it, I found you can cast inventory holder to a Hopper instance, and then get the block that way aswell.

    Problem solved
     
  3. I took a quick look and made this code
    Code (Text):

    @EventHandler
    public void hopperMove(InventoryMoveItemEvent e) {
        if(e.getDestination().getType() != InventoryType.HOPPER) return;
        if(e.getSource().getType() != InventoryType.HOPPER) return;
        Hopper hopper = (Hopper) e.getDestination().getHolder();
        Location loc = hopper.getLocation();
    }
    EDIT: You sniped me by second .-.
     
  4. Haha, thanks for the help anyway :)