@Override @SuppressWarnings("deprecation") public int clear(int id, int data) { int removed = 0; for (Slot slot : this.getHandle().<Slot>slots()) { Optional<org.spongepowered.api.item.inventory.ItemStack> stackOptional = slot.peek(); if (stackOptional.isPresent()) { org.spongepowered.api.item.inventory.ItemStack stack = stackOptional.get(); if (id == -1 || stack.getItem() == MaterialConverter.asItem(Material.getMaterial(id))) { int damage = DurabilityConverter.getDamageValue(stack.getContainers()); if (data == -1 || damage == data) { removed += stack.getQuantity(); slot.clear(); } } } } return removed; }
@Listener public void onInteractInventoryEvent(InteractInventoryEvent.Open event, @Root Player player) { if (!event.getTargetInventory().getArchetype().getId().equals("minecraft:player")) { WorldSettings settings = WorldSettings.get(player.getWorld()); if (settings.isNonPlayerPickupAllowed()) { return; } Iterable<Inventory> iterable; try { iterable = event.getTargetInventory().slots(); } catch (Exception e) { return; } for (Inventory inventory : iterable) { Slot slot = (Slot) inventory; Optional<ItemStack> optionalItemStack = slot.peek(); if (!optionalItemStack.isPresent()) { continue; } ItemStack itemStack = optionalItemStack.get(); BigDecimal amount = WalletDrop.getValue(itemStack); if (amount.compareTo(BigDecimal.ZERO) == 0) { continue; } slot.clear(); } } }