Ghaz-ranka

Untitled

May 20th, 2017
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. package zorg.esinia.server.events;
  2.  
  3. import org.spongepowered.api.entity.living.player.Player;
  4. import org.spongepowered.api.event.Listener;
  5. import org.spongepowered.api.event.filter.Getter;
  6. import org.spongepowered.api.event.filter.cause.Root;
  7. import org.spongepowered.api.event.item.inventory.ClickInventoryEvent;
  8. import org.spongepowered.api.item.inventory.Inventory;
  9. import org.spongepowered.api.item.inventory.InventoryArchetypes;
  10. import org.spongepowered.api.item.inventory.crafting.CraftingOutput;
  11. //Class name and main method
  12. public class EventInventoryClick {
  13. //listener for event
  14. @Listener
  15. //Event for clicking in an inventory. Root is filtered to player, getter to create inventory variable
  16. public void onItemCraft(ClickInventoryEvent event, @Root Player player, @Getter("getTargetInventory") Inventory inventory) {
  17.  
  18. //if the inventories archetype is player or workbench it proceeds
  19. if (inventory.getArchetype() == InventoryArchetypes.PLAYER || inventory.getArchetype() == InventoryArchetypes.WORKBENCH) {
  20. //creates an inventory variable named craftingOutputs based off the CraftingOutput class
  21. Inventory craftingOutputs = inventory.query(CraftingOutput.class);
  22. //loops the slots in the craftingoutput variable and if there is an itemstack it saves it as a variable and proceeds
  23. craftingOutputs.slots().forEach(slot -> slot.peek().ifPresent(itemStack -> {
  24. //Cancels the event
  25. event.setCancelled(true);
  26. }));
  27. }
  28. }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment