From b89c1c8f344ae0376c9dd556654a0e11e5b35849 Mon Sep 17 00:00:00 2001 From: PseudoKnight Date: Mon, 15 Jul 2024 03:53:28 -0700 Subject: [PATCH] Add player to item_pre_craft --- .../bukkit/events/BukkitInventoryEvents.java | 5 ++++ .../events/MCPrepareItemCraftEvent.java | 2 ++ .../core/events/drivers/InventoryEvents.java | 24 +++++++++++-------- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/laytonsmith/abstraction/bukkit/events/BukkitInventoryEvents.java b/src/main/java/com/laytonsmith/abstraction/bukkit/events/BukkitInventoryEvents.java index f968ae4568..f9f342f194 100644 --- a/src/main/java/com/laytonsmith/abstraction/bukkit/events/BukkitInventoryEvents.java +++ b/src/main/java/com/laytonsmith/abstraction/bukkit/events/BukkitInventoryEvents.java @@ -541,6 +541,11 @@ public BukkitMCPrepareItemCraftEvent(PrepareItemCraftEvent event) { e = event; } + @Override + public MCPlayer getPlayer() { + return new BukkitMCPlayer(e.getViewers().get(0)); + } + @Override public MCRecipe getRecipe() { return BukkitConvertor.BukkitGetRecipe(e.getRecipe()); diff --git a/src/main/java/com/laytonsmith/abstraction/events/MCPrepareItemCraftEvent.java b/src/main/java/com/laytonsmith/abstraction/events/MCPrepareItemCraftEvent.java index 1e7266f5ee..3941aa7cef 100644 --- a/src/main/java/com/laytonsmith/abstraction/events/MCPrepareItemCraftEvent.java +++ b/src/main/java/com/laytonsmith/abstraction/events/MCPrepareItemCraftEvent.java @@ -1,9 +1,11 @@ package com.laytonsmith.abstraction.events; import com.laytonsmith.abstraction.MCCraftingInventory; +import com.laytonsmith.abstraction.MCPlayer; import com.laytonsmith.abstraction.MCRecipe; public interface MCPrepareItemCraftEvent extends MCInventoryEvent { + MCPlayer getPlayer(); MCRecipe getRecipe(); diff --git a/src/main/java/com/laytonsmith/core/events/drivers/InventoryEvents.java b/src/main/java/com/laytonsmith/core/events/drivers/InventoryEvents.java index dd43fdf6be..6fc8f8cb5e 100644 --- a/src/main/java/com/laytonsmith/core/events/drivers/InventoryEvents.java +++ b/src/main/java/com/laytonsmith/core/events/drivers/InventoryEvents.java @@ -904,11 +904,14 @@ public String getName() { @Override public String docs() { return "{}" - + " Fires when a recipe is formed in a crafting matrix, but the result has not yet been clicked." - + " {viewers: all humanentities viewing the screen this event takes place in | matrix | result" - + " | isRepair: true if this event was triggered by a repair operation (different than normal crafting)" - + " | recipe: information about the formed recipe, or null if there is not one}" - + " { result: the product of the recipe. }" + + " Fires when a slot is clicked in a crafting matrix." + + " Can also fire when clearing an inventory with the the /clear command or shift-clicking the" + + " 'Destroy Item' button in creative mode." + + " {player: the name of the player who clicked" + + " | viewers | matrix: an array of item arrays in the crafting matrix | result" + + " | isRepair: true if this event was triggered by a repair operation" + + " | recipe: an array of data about the formed recipe, or null if there is not one}" + + " { result: the item array product of the recipe. }" + " {}"; } @@ -927,8 +930,7 @@ public BindableEvent convert(CArray manualObject, Target t) { @Override public Map evaluate(BindableEvent event) throws EventException { - if(event instanceof MCPrepareItemCraftEvent) { - MCPrepareItemCraftEvent e = (MCPrepareItemCraftEvent) event; + if(event instanceof MCPrepareItemCraftEvent e) { Map ret = evaluate_helper(e); Target t = Target.UNKNOWN; CArray viewers = new CArray(t); @@ -936,6 +938,7 @@ public Map evaluate(BindableEvent event) throws EventException { viewers.push(new CString(v.getName(), t), t); } ret.put("viewers", viewers); + ret.put("player", new CString(e.getPlayer().getName(), t)); ret.put("recipe", ObjectGenerator.GetGenerator().recipe(e.getRecipe(), t)); ret.put("isRepair", CBoolean.get(e.isRepair())); CArray matrix = CArray.GetAssociativeArray(t); @@ -985,7 +988,8 @@ public String getName() { @Override public String docs() { return "{}" - + " Fires when a recipe is formed in an anvil, but the result has not yet been clicked." + + " Fires when a slot other than the result is clicked in an anvil." + + " Can fire multiple times per click." + " { player: the player using the anvil." + " | first_item: the first item being used in the recipe." + " | second_item: the second item being used in the recipe." @@ -1090,7 +1094,7 @@ public String getName() { @Override public String docs() { return "{}" - + " Fires when a slot is clicked in a smithing table other than the result." + + " Fires when a slot other than the result is clicked in a smithing table." + " Can fire multiple times per click." + " { player: the player using the smithing table." + " | first_item: the first item being used in the recipe." @@ -1171,7 +1175,7 @@ public String getName() { @Override public String docs() { return "{}" - + " Fires when a slot is clicked in a grindstone other than the result. (MC 1.19.3+)" + + " Fires when a slot other than the result is clicked in a grindstone. (MC 1.19.3+)" + " Can fire multiple times per click." + " { player: the player using the grindstone." + " | upper_item: the first item being used in the recipe."