Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package zorg.esinia.server.events;
- import org.spongepowered.api.entity.living.player.Player;
- import org.spongepowered.api.event.Listener;
- import org.spongepowered.api.event.filter.Getter;
- import org.spongepowered.api.event.filter.cause.Root;
- import org.spongepowered.api.event.item.inventory.ClickInventoryEvent;
- import org.spongepowered.api.item.inventory.Inventory;
- import org.spongepowered.api.item.inventory.InventoryArchetypes;
- import org.spongepowered.api.item.inventory.crafting.CraftingOutput;
- //Class name and main method
- public class EventInventoryClick {
- //listener for event
- @Listener
- //Event for clicking in an inventory. Root is filtered to player, getter to create inventory variable
- public void onItemCraft(ClickInventoryEvent event, @Root Player player, @Getter("getTargetInventory") Inventory inventory) {
- //if the inventories archetype is player or workbench it proceeds
- if (inventory.getArchetype() == InventoryArchetypes.PLAYER || inventory.getArchetype() == InventoryArchetypes.WORKBENCH) {
- //creates an inventory variable named craftingOutputs based off the CraftingOutput class
- Inventory craftingOutputs = inventory.query(CraftingOutput.class);
- //loops the slots in the craftingoutput variable and if there is an itemstack it saves it as a variable and proceeds
- craftingOutputs.slots().forEach(slot -> slot.peek().ifPresent(itemStack -> {
- //Cancels the event
- event.setCancelled(true);
- }));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment