mirror of
https://github.com/songoda/EpicHoppers.git
synced 2024-11-22 02:05:52 +01:00
Update AdvancedChestsAPI
This commit is contained in:
parent
ed93cd4db7
commit
3b18d7c165
@ -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>
|
||||
|
@ -2,10 +2,17 @@ package com.craftaro.epichoppers.containers.impl;
|
||||
|
||||
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 class AdvancedChestImpl implements IContainer {
|
||||
}
|
||||
|
||||
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 class AdvancedChestImpl implements IContainer {
|
||||
|
||||
@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;
|
||||
}
|
||||
@ -41,7 +56,7 @@ public class AdvancedChestImpl implements IContainer {
|
||||
item.setAmount(item.getAmount() - amountToMove);
|
||||
|
||||
if (item.getAmount() <= 0) {
|
||||
this.advancedChest.getAllItems().remove(item);
|
||||
item.setType(Material.AIR);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user