diff --git a/EpicHoppers-Plugin/pom.xml b/EpicHoppers-Plugin/pom.xml index 5039cad..c079534 100644 --- a/EpicHoppers-Plugin/pom.xml +++ b/EpicHoppers-Plugin/pom.xml @@ -175,7 +175,7 @@ com.github.DeadSilenceIV AdvancedChestsAPI - 2.4 + 3.2-BETA provided diff --git a/EpicHoppers-Plugin/src/main/java/com/craftaro/epichoppers/containers/impl/AdvancedChestImpl.java b/EpicHoppers-Plugin/src/main/java/com/craftaro/epichoppers/containers/impl/AdvancedChestImpl.java index 487531c..31b7238 100644 --- a/EpicHoppers-Plugin/src/main/java/com/craftaro/epichoppers/containers/impl/AdvancedChestImpl.java +++ b/EpicHoppers-Plugin/src/main/java/com/craftaro/epichoppers/containers/impl/AdvancedChestImpl.java @@ -2,10 +2,17 @@ import com.craftaro.epichoppers.containers.CustomContainer; import com.craftaro.epichoppers.containers.IContainer; +import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.inventory.ItemStack; import us.lynuxcraft.deadsilenceiv.advancedchests.AdvancedChestsAPI; import us.lynuxcraft.deadsilenceiv.advancedchests.chest.AdvancedChest; +import us.lynuxcraft.deadsilenceiv.advancedchests.utils.inventory.InteractiveInventory; + +import java.util.Arrays; +import java.util.List; +import java.util.Optional; +import java.util.stream.Collectors; public class AdvancedChestImpl implements IContainer { @Override @@ -14,7 +21,7 @@ public CustomContainer getCustomContainer(Block block) { } static class Container extends CustomContainer { - private final AdvancedChest advancedChest; + private final AdvancedChest advancedChest; public Container(Block block) { this.advancedChest = AdvancedChestsAPI.getChestManager().getAdvancedChest(block.getLocation()); @@ -22,17 +29,25 @@ public Container(Block block) { @Override public boolean addToContainer(ItemStack itemToMove) { - return AdvancedChestsAPI.addItemToChest(this.advancedChest, itemToMove); +// return AdvancedChestsAPI.addItemToChest(this.advancedChest, itemToMove); + if (advancedChest != null) { + Optional inv = advancedChest.getSubInventories().stream().filter(subInventory -> subInventory.getBukkitInventory().firstEmpty() != -1).findFirst(); + if (inv.isPresent()) { + return inv.get().getBukkitInventory().addItem(itemToMove).isEmpty(); + } + } + return false; } @Override public ItemStack[] getItems() { - return this.advancedChest.getAllItems().toArray(new ItemStack[0]); +// return this.advancedChest.getAllItems().toArray(new ItemStack[0]); + return this.advancedChest.getSubInventories().stream().map(subInventory -> subInventory.getBukkitInventory().getContents()).collect(Collectors.toList()).stream().flatMap(Arrays::stream).toArray(ItemStack[]::new); } @Override public void removeFromContainer(ItemStack itemToMove, int amountToMove) { - for (ItemStack item : this.advancedChest.getAllItems()) { + for (ItemStack item : getItems()) { if (item == null) { return; } @@ -41,7 +56,7 @@ public void removeFromContainer(ItemStack itemToMove, int amountToMove) { item.setAmount(item.getAmount() - amountToMove); if (item.getAmount() <= 0) { - this.advancedChest.getAllItems().remove(item); + item.setType(Material.AIR); } return; }