Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions src/me/ryanhamshire/AutomaticInventory/AutomaticInventory.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.bukkit.*;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.ShulkerBox;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.FileConfiguration;
Expand All @@ -16,6 +17,7 @@
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import org.bukkit.inventory.meta.BlockStateMeta;
import org.bukkit.inventory.meta.PotionMeta;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
Expand Down Expand Up @@ -357,6 +359,51 @@ static DepositRecord depositMatching(PlayerInventory source, Inventory destinati
ItemStack sourceStack = source.getItem(i);
if(sourceStack == null) continue;

// check if item is a Shulker Box
if(sourceStack.getItemMeta() instanceof BlockStateMeta) {
BlockStateMeta im = (BlockStateMeta)sourceStack.getItemMeta();
if(im.getBlockState() instanceof ShulkerBox) {
ShulkerBox sourceShulker = (ShulkerBox) im.getBlockState();

for(int j = 0; j < 27; j++) {
ItemStack stackInShulker = sourceShulker.getInventory().getItem(j);

if(stackInShulker == null) continue;
if (AutomaticInventory.instance.config_noAutoDeposit.contains(stackInShulker.getType())) continue;

String signature = getSignature(stackInShulker);
int shulkerSourceStackSize = stackInShulker.getAmount();

if(eligibleSignatures.contains(signature))
{
HashMap<Integer, ItemStack> notMoved = destination.addItem(stackInShulker);
if(notMoved.isEmpty())
{
sourceShulker.getInventory().clear(j);
deposits.totalItems += shulkerSourceStackSize;
}
else
{
int notMovedCount = notMoved.values().iterator().next().getAmount();
int movedCount = shulkerSourceStackSize - notMovedCount;
if(movedCount == 0)
{
eligibleSignatures.remove(signature);
}
else
{
int newAmount = shulkerSourceStackSize - movedCount;
stackInShulker.setAmount(newAmount);
deposits.totalItems += movedCount;
}
}
}
}
im.setBlockState(sourceShulker);
sourceStack.setItemMeta(im);
}
}

if (AutomaticInventory.instance.config_noAutoDeposit.contains(sourceStack.getType())) continue;

String signature = getSignature(sourceStack);
Expand Down