Skip to content

Commit

Permalink
Update AdvancedChestsAPI
Browse files Browse the repository at this point in the history
  • Loading branch information
ceze88 committed Mar 23, 2024
1 parent ed93cd4 commit 3b18d7c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
2 changes: 1 addition & 1 deletion EpicHoppers-Plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@
<dependency>
<groupId>com.github.DeadSilenceIV</groupId>
<artifactId>AdvancedChestsAPI</artifactId>
<version>2.4</version>
<version>3.2-BETA</version>
<scope>provided</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -14,25 +21,33 @@ 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());
}

@Override
public boolean addToContainer(ItemStack itemToMove) {
return AdvancedChestsAPI.addItemToChest(this.advancedChest, itemToMove);
// return AdvancedChestsAPI.addItemToChest(this.advancedChest, itemToMove);
if (advancedChest != null) {
Optional<InteractiveInventory> 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;
}
Expand All @@ -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;
}
Expand Down

0 comments on commit 3b18d7c

Please sign in to comment.