org.spongepowered.api.item.inventory.transaction.SlotTransaction Java Examples
The following examples show how to use
org.spongepowered.api.item.inventory.transaction.SlotTransaction.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: VirtualChestInventory.java From VirtualChest with GNU Lesser General Public License v3.0 | 6 votes |
private void fireClickEvent(ClickInventoryEvent e) { Optional<Player> optional = Sponge.getServer().getPlayer(playerUniqueId); if (optional.isPresent()) { Player player = optional.get(); CompletableFuture<Boolean> future = CompletableFuture.supplyAsync(() -> Boolean.TRUE, executorService); for (SlotTransaction slotTransaction : e.getTransactions()) { Slot slot = slotTransaction.getSlot(); Container targetContainer = e.getTargetInventory(); SlotIndex pos = Iterables.getOnlyElement(slot.parent().getProperties(slot, SlotIndex.class)); if (slot.parent().equals(targetContainer) && slotToListen.matches(pos)) { e.setCancelled(true); if (actionIntervalManager.allowAction(player, acceptableActionIntervalTick)) { int index = Objects.requireNonNull(pos.getValue()); future = future.thenCompose(b -> this.runCommand(e, player, index).thenApply(a -> a && b)); } } } future.thenApply(keepInventoryOpen -> keepInventoryOpen || !plugin.getDispatcher().close(name, player)); } }
Example #2
Source File: BlacklistListener.java From EssentialCmds with MIT License | 6 votes |
@Listener public void onChangeHeldItem(ChangeInventoryEvent.Held event, @Root Player player) { if (!player.hasPermission("essentialcmds.blacklist.bypass")) { for (SlotTransaction transaction : event.getTransactions()) { if (Utils.getBlacklistItems().contains(transaction.getFinal().createStack().getItem().getId())) { if (Utils.areBlacklistMsgsEnabled()) player.sendMessage(Text.of(TextColors.RED, "The item ", TextColors.GRAY, transaction.getFinal().createStack().getItem().getId(), TextColors.RED, " has been confiscated as it is blacklisted.")); transaction.setCustom(Sponge.getRegistry().createBuilder(ItemStack.Builder.class).itemType(ItemTypes.DIRT).quantity(1).build()); } } } }
Example #3
Source File: BlacklistListener.java From EssentialCmds with MIT License | 6 votes |
@Listener public void onChangeEquipment(ChangeInventoryEvent.Equipment event, @Root Player player) { if (!player.hasPermission("essentialcmds.blacklist.bypass")) { for (SlotTransaction transaction : event.getTransactions()) { if (Utils.getBlacklistItems().contains(transaction.getFinal().createStack().getItem().getId())) { if (Utils.areBlacklistMsgsEnabled()) player.sendMessage(Text.of(TextColors.RED, "The item ", TextColors.GRAY, transaction.getFinal().createStack().getItem().getId(), TextColors.RED, " has been confiscated as it is blacklisted.")); transaction.setCustom(Sponge.getRegistry().createBuilder(ItemStack.Builder.class).itemType(ItemTypes.DIRT).quantity(1).build()); } } } }
Example #4
Source File: BlacklistListener.java From EssentialCmds with MIT License | 6 votes |
@Listener public void onPickupItem(ChangeInventoryEvent.Pickup event, @Root Player player) { if (!player.hasPermission("essentialcmds.blacklist.bypass")) { for (SlotTransaction transaction : event.getTransactions()) { if (Utils.getBlacklistItems().contains(transaction.getFinal().createStack().getItem().getId())) { if (Utils.areBlacklistMsgsEnabled()) player.sendMessage(Text.of(TextColors.RED, "The item ", TextColors.GRAY, transaction.getFinal().createStack().getItem().getId(), TextColors.RED, " has been confiscated as it is blacklisted.")); transaction.setCustom(Sponge.getRegistry().createBuilder(ItemStack.Builder.class).itemType(ItemTypes.DIRT).quantity(1).build()); } } } }
Example #5
Source File: InventoryListener.java From Prism with MIT License | 6 votes |
/** * Saves event records when a player picks up an item off of the ground. * * @param event ChangeInventoryEvent.Pickup * @param player Player */ @Listener(order = Order.POST) public void onChangeInventoryPickup(ChangeInventoryEvent.Pickup event, @Root Player player) { if (event.getTransactions().isEmpty() || !Prism.getInstance().getConfig().getEventCategory().isItemPickup()) { return; } for (SlotTransaction transaction : event.getTransactions()) { ItemStackSnapshot itemStack = transaction.getFinal(); int quantity = itemStack.getQuantity(); if (transaction.getOriginal().getType() != ItemTypes.NONE) { quantity -= transaction.getOriginal().getQuantity(); } Prism.getInstance().getLogger().debug("Inventory pickup - {} x{}", itemStack.getType().getId(), quantity); PrismRecord.create() .source(event.getCause()) .event(PrismEvents.ITEM_PICKUP) .itemStack(itemStack, quantity) .location(player.getLocation()) .buildAndSave(); } }
Example #6
Source File: Sponge5ArmorListener.java From ViaVersion with MIT License | 5 votes |
@Listener public void onInventoryClick(ClickInventoryEvent e, @Root Player player) { for (SlotTransaction transaction : e.getTransactions()) { if (ArmorType.isArmor(transaction.getFinal().getType().getId()) || ArmorType.isArmor(e.getCursorTransaction().getFinal().getType().getId())) { sendDelayedArmorUpdate(player); break; } } }
Example #7
Source File: Sponge4ArmorListener.java From ViaVersion with MIT License | 5 votes |
@Listener public void onInventoryClick(ClickInventoryEvent e, @Root Player player) { for (SlotTransaction transaction : e.getTransactions()) { if (ArmorType.isArmor(transaction.getFinal().getType().getId()) || ArmorType.isArmor(e.getCursorTransaction().getFinal().getType().getId())) { sendDelayedArmorUpdate(player); break; } } }
Example #8
Source File: ItemListener.java From UltimateCore with MIT License | 5 votes |
@Listener public void onPickup(ChangeInventoryEvent.Pickup event, @First Player p) { ModuleConfig config = Modules.BLACKLIST.get().getConfig().get(); CommentedConfigurationNode hnode = config.get(); for(SlotTransaction trans : event.getTransactions()){ ItemStack item = trans.getSlot().peek(); CommentedConfigurationNode node = hnode.getNode("items", item.getType().getId()); if (!node.isVirtual()) { if (node.getNode("deny-drop").getBoolean()) { trans.setValid(false); } } } }