Advertisement
broken-arrow

Untitled

Nov 12th, 2021
681
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.73 KB | None | 0 0
  1.     private void teleportItemsToContainer(Location location, ItemStack[] hopperContents, Inventory hopperInventory) {
  2.         Location linkedContainerLocation = getLinkLocation(location, registry);
  3.  
  4.         if (linkedContainerLocation != null) {
  5.  
  6.             if (!linkedContainerLocation.getWorld().isChunkLoaded(linkedContainerLocation.getBlockX() >> 4, linkedContainerLocation.getBlockZ() >> 4))
  7.                 return;
  8.  
  9.             InventoryHolders customInventory = plugin.getClassinstans().createObjektInventoryHolder(linkedContainerLocation, null);
  10.             if (registry.getTypeofContainer(linkedContainerLocation) != null)
  11.                 switch (registry.getTypeofContainer(linkedContainerLocation)) {
  12.                     case PAGEDCONTAINER:
  13.                     case CRAFTINGCONTAINER:
  14.                     case SELLCHEST:
  15.                     case STORAGEUNIT: {
  16.  
  17.                         ItemStack[] itemStacks = Arrays.stream(hopperContents).filter((contents) -> contents != null &&
  18.                                 contents.getType() != Material.AIR).toArray(ItemStack[]::new);
  19.  
  20.                         Map<Integer, ItemStack> containerLeftOvers = customInventory.addItems(itemStacks);
  21.                         hopperInventory.clear();
  22.                         if (!containerLeftOvers.isEmpty()) {
  23.                             setTeleportedItems(location, false);
  24.                             Collection<ItemStack> collectionItemStack = containerLeftOvers.values();
  25.  
  26.                             hopperInventory.addItem(collectionItemStack.toArray(new ItemStack[0]));
  27.                         } else {
  28.                             registry.setTotalAmountTeleportedItems(location, ItemUtily.countItemStacks(hopperContents, customInventory.getContents(linkedContainerLocation)));
  29.                             setTeleportedItems(location, true);
  30.                         }
  31.  
  32.                         break;
  33.                     }
  34.                     default:
  35.                         ItemStack[] itemStacks = Arrays.stream(hopperContents).filter((contents) -> contents != null &&
  36.                                 contents.getType() != Material.AIR).toArray(ItemStack[]::new);
  37.                         System.out.println("itemstacks " + isTeleportedItems(location));
  38.  
  39.                         HopperTeleportListener event = new HopperTeleportListener(linkedContainerLocation, isTeleportedItems(location), itemStacks);
  40.                         Bukkit.getPluginManager().callEvent(event);
  41.  
  42.                         if (event.isCancelled()) {
  43.                             if (event.isShallRemoveFromHopper())
  44.                                 hopperInventory.clear();
  45.                             break;
  46.                         } else {
  47.                             HashMap<Integer, ItemStack> containerLeftOvers = containerInventory.addItem(itemStacks);
  48.                             hopperInventory.clear();
  49.  
  50.                             if (!containerLeftOvers.isEmpty()) {
  51.                                 setTeleportedItems(location, false);
  52.                                 Collection<ItemStack> collectionItemStack = containerLeftOvers.values();
  53.  
  54.                                 hopperInventory.addItem(collectionItemStack.toArray(new ItemStack[0]));
  55.                             } else {
  56.                                 registry.setTotalAmountTeleportedItems(location, ItemUtily.countItemStacks(hopperContents, containerInventory));
  57.                                 setTeleportedItems(location, itemStacks.length >= 1);
  58.                             }
  59.  
  60.                         }
  61.                         break;
  62.                 }
  63.  
  64.         }
  65.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement