Solved onInventoryClose, for loop, drop all items within

Discussion in 'Plugin Development' started by Ross Gosling, Jan 2, 2014.

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

    Ross Gosling

    I create inventories that players will open when they click a furnace and when they close the inventory screen, all of the items left within the furnace disappear.

    To fix this I need to drop all the items on top of the players location when the furnace closes.

    I just need help with the for loop.

        public void onInventoryClose(InventoryCloseEvent event) {
            Player player = (Player) event.getPlayer();
            Inventory inventory = event.getInventory();
            InventoryType type = inventory.getType();
            if(type.equals(InventoryType.FURNACE)) {
                player.sendMessage("Type: " + type);
                for(>>"Every Individual ItemStack Within The Furnace"<<) {
                    Location location = player.getLocation();
                    World world = location.getWorld();
                    world.dropItem(location, ItemStack);
  2. Offline


    try to do this:
    1. for (ItemStack is : event.getEntity().getInventory()) {
    2. if (!(is == null)) {
    3. Location location = player.getLocation();
    4. location.setY(Location.getY()+1);
    5. World world = location.getWorld();
    7. world.dropItem(location, is);}
    8. }

    That should drop the items. But if you want to clear the furnace as well don't forget to do:
    1. event.getEntity().getInventory().clear();
    Ross Gosling likes this.
  3. Offline

    Ross Gosling

    Works like a charm, thanks
  4. Offline


    You're welcome
Thread Status:
Not open for further replies.

Share This Page