Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static ItemStack removeStackFromInventory(int amount, Location fromLocation, Inventory fromInventory, Inventory toInventory, Location targetLocation, boolean pullItems) {
- InventoryHolders inventoryHolder = plugin.getInventoryHoldersCached().createOrGetInventoryHolder(fromLocation, null);
- ItemStack RemoveItemsFromContainerBefore;
- List<ItemStack> itemStacks = null;
- PreHopperMoveItemEvent event;
- if (fromInventory != null)
- if (fromInventory.getType() == InventoryType.CHEST && !registry.getTypeofContainer(fromLocation).equals(TypeOfContainers.TypeOfContainer.DEFAULT) && !registry.getTypeofContainer(fromLocation).equals(TypeOfContainers.TypeOfContainer.STORAGEUNIT)) {
- itemStacks = inventoryHolder.listAllPagesItems();
- } else if (fromInventory.getType() != InventoryType.CHEST || registry.getTypeofContainer(fromLocation).equals(TypeOfContainers.TypeOfContainer.STORAGEUNIT)) {
- itemStacks = Arrays.asList(fromInventory.getContents());
- }
- if (itemStacks != null)
- for (ItemStack stack : itemStacks) {
- //ItemStack stack = itemStacks.get(i);
- FilterItems filter = new FilterItems();
- boolean customfilterContainer = true;
- if (fromInventory.getType() == InventoryType.CHEST && !registry.getTypeofContainer(fromLocation).equals(TypeOfContainers.TypeOfContainer.STORAGEUNIT))
- event = new PreHopperMoveItemEvent(targetLocation, fromLocation, fromInventory, toInventory, stack);
- else
- event = new PreHopperMoveItemEvent(fromLocation, targetLocation, fromInventory, toInventory, stack);
- RegisterEvent.register(event);
- if (event.isCancelled()) break;
- if (stack != null && pullItems && toInventory != null && toInventory.firstEmpty() == -1 && !ItemUtily.isPlaceLeftInventory(toInventory, stack.getType(), stack.getAmount())) {
- continue;
- }
- if (stack != null && targetLocation != null && !registry.getTypeofContainer(targetLocation).equals(TypeOfContainers.TypeOfContainer.DEFAULT)) {
- customfilterContainer = filter.checkIfItemMatch(targetLocation, stack);
- } else if (stack != null && fromLocation != null && !registry.getTypeofContainer(fromLocation).equals(TypeOfContainers.TypeOfContainer.DEFAULT)) {
- customfilterContainer = filter.checkIfItemMatch(fromLocation, stack, targetLocation, pullItems);
- }
- if (stack != null && customfilterContainer) {
- RemoveItemsFromContainerBefore = stack.clone();
- int amountToRemove = Math.min(stack.getAmount(), amount);
- RemoveItemsFromContainerBefore.setAmount(amountToRemove);
- //if (!inventoryHolder.canPlaceItemInsideContainer(RemoveItemsFromContainerBefore)) continue;
- stack.setAmount(stack.getAmount() - amountToRemove);
- return RemoveItemsFromContainerBefore;
- }
- }
- return null;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement