Advertisement
broken-arrow

Untitled

Jan 23rd, 2022
565
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     public static ItemStack removeStackFromInventory(int amount, Location fromLocation, Inventory fromInventory, Inventory toInventory, Location targetLocation, boolean pullItems) {
  2.         InventoryHolders inventoryHolder = plugin.getInventoryHoldersCached().createOrGetInventoryHolder(fromLocation, null);
  3.         ItemStack RemoveItemsFromContainerBefore;
  4.         List<ItemStack> itemStacks = null;
  5.         PreHopperMoveItemEvent event;
  6.  
  7.         if (fromInventory != null)
  8.             if (fromInventory.getType() == InventoryType.CHEST && !registry.getTypeofContainer(fromLocation).equals(TypeOfContainers.TypeOfContainer.DEFAULT) && !registry.getTypeofContainer(fromLocation).equals(TypeOfContainers.TypeOfContainer.STORAGEUNIT)) {
  9.                 itemStacks = inventoryHolder.listAllPagesItems();
  10.             } else if (fromInventory.getType() != InventoryType.CHEST || registry.getTypeofContainer(fromLocation).equals(TypeOfContainers.TypeOfContainer.STORAGEUNIT)) {
  11.                 itemStacks = Arrays.asList(fromInventory.getContents());
  12.             }
  13.  
  14.         if (itemStacks != null)
  15.             for (ItemStack stack : itemStacks) {
  16.                 //ItemStack stack = itemStacks.get(i);
  17.                 FilterItems filter = new FilterItems();
  18.                 boolean customfilterContainer = true;
  19.  
  20.                 if (fromInventory.getType() == InventoryType.CHEST && !registry.getTypeofContainer(fromLocation).equals(TypeOfContainers.TypeOfContainer.STORAGEUNIT))
  21.                     event = new PreHopperMoveItemEvent(targetLocation, fromLocation, fromInventory, toInventory, stack);
  22.                 else
  23.                     event = new PreHopperMoveItemEvent(fromLocation, targetLocation, fromInventory, toInventory, stack);
  24.  
  25.                 RegisterEvent.register(event);
  26.                 if (event.isCancelled()) break;
  27.  
  28.                 if (stack != null && pullItems && toInventory != null && toInventory.firstEmpty() == -1 && !ItemUtily.isPlaceLeftInventory(toInventory, stack.getType(), stack.getAmount())) {
  29.                     continue;
  30.                 }
  31.  
  32.                 if (stack != null && targetLocation != null && !registry.getTypeofContainer(targetLocation).equals(TypeOfContainers.TypeOfContainer.DEFAULT)) {
  33.                     customfilterContainer = filter.checkIfItemMatch(targetLocation, stack);
  34.                 } else if (stack != null && fromLocation != null && !registry.getTypeofContainer(fromLocation).equals(TypeOfContainers.TypeOfContainer.DEFAULT)) {
  35.                     customfilterContainer = filter.checkIfItemMatch(fromLocation, stack, targetLocation, pullItems);
  36.                 }
  37.  
  38.                 if (stack != null && customfilterContainer) {
  39.                     RemoveItemsFromContainerBefore = stack.clone();
  40.                     int amountToRemove = Math.min(stack.getAmount(), amount);
  41.                     RemoveItemsFromContainerBefore.setAmount(amountToRemove);
  42.                     //if (!inventoryHolder.canPlaceItemInsideContainer(RemoveItemsFromContainerBefore)) continue;
  43.                     stack.setAmount(stack.getAmount() - amountToRemove);
  44.  
  45.                     return RemoveItemsFromContainerBefore;
  46.                 }
  47.             }
  48.         return null;
  49.     }
  50.  
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement