Solved Transfering Items via hoppers

Discussion in 'Plugin Development' started by Panda_Crafter, Aug 6, 2016.

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

    Panda_Crafter

    Hello, I want to create a wireless transfer via hoppers, but everytime the first item is stuck in the hopper and all the items are moved to the other chest, so how do I fix this?

    Code:
        @EventHandler
        public void onInventoryItemMove(InventoryMoveItemEvent event){
            InventoryHolder holder = event.getDestination().getHolder();
          
            if(holder instanceof BlockState){
                Block block = ((BlockState) holder).getBlock();
              
                if(hasSign(block)){
                    Sign sign = (Sign) getSign(block);
                    if(sign.getLine(0).equalsIgnoreCase(ChatColor.GRAY + "[Transfer]")){
                        if(sign.getLine(3).equalsIgnoreCase("1")){
                            double x = main.getConfig().getDouble("Signs." + sign.getLine(1).toLowerCase() + ".2.x");
                            double y = main.getConfig().getDouble("Signs." + sign.getLine(1).toLowerCase() + ".2.y");
                            double z = main.getConfig().getDouble("Signs." + sign.getLine(1).toLowerCase() + ".2.z");
                          
                            Location loc = new Location(block.getWorld(), x, y, z);
                          
                            if(hasHopper(loc.getBlock())){
                                Hopper hopper = (Hopper) getHopper(loc.getBlock()).getState();
                                event.getInitiator().remove(event.getItem());
                                holder.getInventory().remove(event.getItem());
                                hopper.getInventory().addItem(event.getItem());
                            }
                        }
                    }
                }
            }
          
        }
    
     
  2. Offline

    MrGeneralQ

    If the issue is solved then provide the solution. Otherwise people with the same problem got no clue on how to fix it.
     
  3. Offline

    Panda_Crafter

    if i add this in the place were i should remove the item then the problem is solved:

    Code:
                            Bukkit.getScheduler().runTaskLater(main, new Runnable() {
                               
                                @Override
                                public void run() {
                                    Hopper hop = (Hopper) block.getState();
                                    hop.getInventory().clear();
                                   
                                }
                            }, 1);
    
     
Thread Status:
Not open for further replies.

Share This Page