Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void teleportItemsToContainer(Location location, ItemStack[] hopperContents, Inventory hopperInventory) {
- Location linkedContainerLocation = getLinkLocation(location, registry);
- if (linkedContainerLocation != null) {
- if (!linkedContainerLocation.getWorld().isChunkLoaded(linkedContainerLocation.getBlockX() >> 4, linkedContainerLocation.getBlockZ() >> 4))
- return;
- InventoryHolders customInventory = plugin.getClassinstans().createObjektInventoryHolder(linkedContainerLocation, null);
- if (registry.getTypeofContainer(linkedContainerLocation) != null)
- switch (registry.getTypeofContainer(linkedContainerLocation)) {
- case PAGEDCONTAINER:
- case CRAFTINGCONTAINER:
- case SELLCHEST:
- case STORAGEUNIT: {
- ItemStack[] itemStacks = Arrays.stream(hopperContents).filter((contents) -> contents != null &&
- contents.getType() != Material.AIR).toArray(ItemStack[]::new);
- Map<Integer, ItemStack> containerLeftOvers = customInventory.addItems(itemStacks);
- hopperInventory.clear();
- if (!containerLeftOvers.isEmpty()) {
- setTeleportedItems(location, false);
- Collection<ItemStack> collectionItemStack = containerLeftOvers.values();
- hopperInventory.addItem(collectionItemStack.toArray(new ItemStack[0]));
- } else {
- registry.setTotalAmountTeleportedItems(location, ItemUtily.countItemStacks(hopperContents, customInventory.getContents(linkedContainerLocation)));
- setTeleportedItems(location, true);
- }
- break;
- }
- default:
- ItemStack[] itemStacks = Arrays.stream(hopperContents).filter((contents) -> contents != null &&
- contents.getType() != Material.AIR).toArray(ItemStack[]::new);
- System.out.println("itemstacks " + isTeleportedItems(location));
- HopperTeleportListener event = new HopperTeleportListener(linkedContainerLocation, isTeleportedItems(location), itemStacks);
- Bukkit.getPluginManager().callEvent(event);
- if (event.isCancelled()) {
- if (event.isShallRemoveFromHopper())
- hopperInventory.clear();
- break;
- } else {
- HashMap<Integer, ItemStack> containerLeftOvers = containerInventory.addItem(itemStacks);
- hopperInventory.clear();
- if (!containerLeftOvers.isEmpty()) {
- setTeleportedItems(location, false);
- Collection<ItemStack> collectionItemStack = containerLeftOvers.values();
- hopperInventory.addItem(collectionItemStack.toArray(new ItemStack[0]));
- } else {
- registry.setTotalAmountTeleportedItems(location, ItemUtily.countItemStacks(hopperContents, containerInventory));
- setTeleportedItems(location, itemStacks.length >= 1);
- }
- }
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement