2020-07-05 03:36:46 +00:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
|
From: William Blake Galbreath <Blake.Galbreath@GMail.com>
|
|
|
|
Date: Fri, 3 Jul 2020 11:58:56 -0500
|
|
|
|
Subject: [PATCH] Add PrepareResultEvent
|
|
|
|
|
|
|
|
Adds a new event for all crafting stations that generate a result slot item
|
|
|
|
|
2020-07-22 23:35:44 +00:00
|
|
|
Anvil, Grindstone and Smithing now extend this event
|
2020-07-05 03:36:46 +00:00
|
|
|
|
2021-03-16 07:19:45 +00:00
|
|
|
diff --git a/src/main/java/net/minecraft/world/inventory/Container.java b/src/main/java/net/minecraft/world/inventory/Container.java
|
|
|
|
index e9733fd9dac89d31dbad391cb22a8c84216045db..e7c29d194d5c3e3b1b79228758f7a3d8aa060fbd 100644
|
|
|
|
--- a/src/main/java/net/minecraft/world/inventory/Container.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/inventory/Container.java
|
|
|
|
@@ -142,6 +142,7 @@ public abstract class Container {
|
2020-07-05 19:33:23 +00:00
|
|
|
return nonnulllist;
|
|
|
|
}
|
|
|
|
|
2020-08-02 05:39:36 +00:00
|
|
|
+ public final void notifyListeners() { this.c(); } // Paper - OBFHELPER
|
2020-07-05 19:33:23 +00:00
|
|
|
public void c() {
|
|
|
|
int i;
|
|
|
|
|
2021-03-16 07:19:45 +00:00
|
|
|
diff --git a/src/main/java/net/minecraft/world/inventory/ContainerAnvil.java b/src/main/java/net/minecraft/world/inventory/ContainerAnvil.java
|
|
|
|
index ff618bbb3fc4acfce51f5e5e6a504a63e9ad77cd..ae5674ae9c539720a657838a640050cd3b4dc5b5 100644
|
|
|
|
--- a/src/main/java/net/minecraft/world/inventory/ContainerAnvil.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/inventory/ContainerAnvil.java
|
|
|
|
@@ -307,6 +307,7 @@ public class ContainerAnvil extends ContainerAnvilAbstract {
|
2020-07-05 03:36:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
this.e();
|
2020-07-05 19:33:23 +00:00
|
|
|
+ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareResultEvent(this, 2); // Paper
|
2020-07-05 03:36:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// CraftBukkit start
|
2021-03-16 07:19:45 +00:00
|
|
|
diff --git a/src/main/java/net/minecraft/world/inventory/ContainerAnvilAbstract.java b/src/main/java/net/minecraft/world/inventory/ContainerAnvilAbstract.java
|
2021-04-18 09:02:48 +00:00
|
|
|
index 5f176b1a02b217cf907f3a41d637e9059c43e928..8d6a23beb44cce2e4e13a814047da5f84d35830d 100644
|
2021-03-16 07:19:45 +00:00
|
|
|
--- a/src/main/java/net/minecraft/world/inventory/ContainerAnvilAbstract.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/inventory/ContainerAnvilAbstract.java
|
2021-04-18 09:02:48 +00:00
|
|
|
@@ -74,6 +74,7 @@ public abstract class ContainerAnvilAbstract extends Container {
|
2020-07-05 19:33:23 +00:00
|
|
|
super.a(iinventory);
|
|
|
|
if (iinventory == this.repairInventory) {
|
2020-07-05 03:36:46 +00:00
|
|
|
this.e();
|
2020-07-05 19:33:23 +00:00
|
|
|
+ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareResultEvent(this, 2); // Paper
|
2020-07-05 03:36:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2021-03-16 07:19:45 +00:00
|
|
|
diff --git a/src/main/java/net/minecraft/world/inventory/ContainerCartography.java b/src/main/java/net/minecraft/world/inventory/ContainerCartography.java
|
|
|
|
index ce3c22d6f05703874eedf634331ea92ef4c039bf..031e75dc1f3dd6fc1cee684e8e7a105b3e402127 100644
|
|
|
|
--- a/src/main/java/net/minecraft/world/inventory/ContainerCartography.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/inventory/ContainerCartography.java
|
|
|
|
@@ -148,6 +148,7 @@ public class ContainerCartography extends Container {
|
2020-07-05 03:36:46 +00:00
|
|
|
this.a(itemstack, itemstack1, itemstack2);
|
|
|
|
}
|
|
|
|
|
2020-07-05 19:33:23 +00:00
|
|
|
+ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareResultEvent(this, 2); // Paper
|
2020-07-05 03:36:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void a(ItemStack itemstack, ItemStack itemstack1, ItemStack itemstack2) {
|
2021-03-16 07:19:45 +00:00
|
|
|
diff --git a/src/main/java/net/minecraft/world/inventory/ContainerGrindstone.java b/src/main/java/net/minecraft/world/inventory/ContainerGrindstone.java
|
|
|
|
index fad7355a549aef811bca43be198af3d1c0a53980..1d5dcbbd3870eb8e1013a97f6ce882bfc096bf95 100644
|
|
|
|
--- a/src/main/java/net/minecraft/world/inventory/ContainerGrindstone.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/inventory/ContainerGrindstone.java
|
|
|
|
@@ -157,6 +157,7 @@ public class ContainerGrindstone extends Container {
|
2020-07-05 03:36:46 +00:00
|
|
|
super.a(iinventory);
|
|
|
|
if (iinventory == this.craftInventory) {
|
|
|
|
this.e();
|
2020-07-05 19:33:23 +00:00
|
|
|
+ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareResultEvent(this, 2); // Paper
|
2020-07-05 03:36:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2021-03-16 07:19:45 +00:00
|
|
|
diff --git a/src/main/java/net/minecraft/world/inventory/ContainerLoom.java b/src/main/java/net/minecraft/world/inventory/ContainerLoom.java
|
|
|
|
index 350a9b6525a95a00e72e836f1cc9e1a6b99fdd7a..7980930cc712e37a788f894bf2d2ee2b1cfc1196 100644
|
|
|
|
--- a/src/main/java/net/minecraft/world/inventory/ContainerLoom.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/inventory/ContainerLoom.java
|
|
|
|
@@ -190,7 +190,8 @@ public class ContainerLoom extends Container {
|
2020-07-05 19:33:23 +00:00
|
|
|
}
|
2020-07-05 03:36:46 +00:00
|
|
|
|
|
|
|
this.j();
|
2020-07-05 19:33:23 +00:00
|
|
|
- this.c();
|
|
|
|
+ //this.c(); // Paper - done below
|
|
|
|
+ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareResultEvent(this, 3); // Paper
|
2020-07-05 03:36:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-03-16 07:19:45 +00:00
|
|
|
diff --git a/src/main/java/net/minecraft/world/inventory/ContainerSmithing.java b/src/main/java/net/minecraft/world/inventory/ContainerSmithing.java
|
2021-04-18 09:02:48 +00:00
|
|
|
index 3791a8c2b4b5879e4ee331b7e427c9c1c1e4a623..a51280e5affbe399d276b4ee409b196dddfd40ac 100644
|
2021-03-16 07:19:45 +00:00
|
|
|
--- a/src/main/java/net/minecraft/world/inventory/ContainerSmithing.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/inventory/ContainerSmithing.java
|
2021-04-18 09:02:48 +00:00
|
|
|
@@ -80,6 +80,7 @@ public class ContainerSmithing extends ContainerAnvilAbstract {
|
|
|
|
// CraftBukkit end
|
2020-07-05 03:36:46 +00:00
|
|
|
}
|
|
|
|
|
2020-07-05 19:33:23 +00:00
|
|
|
+ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareResultEvent(this, 2); // Paper
|
2020-07-05 03:36:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-03-16 07:19:45 +00:00
|
|
|
diff --git a/src/main/java/net/minecraft/world/inventory/ContainerStonecutter.java b/src/main/java/net/minecraft/world/inventory/ContainerStonecutter.java
|
|
|
|
index cfcb2469569edd51bbb74ca8d7a35a1ec0ecb434..1589d9ca201d386d11d9fd57fa8ba6848bae215c 100644
|
|
|
|
--- a/src/main/java/net/minecraft/world/inventory/ContainerStonecutter.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/inventory/ContainerStonecutter.java
|
|
|
|
@@ -156,6 +156,7 @@ public class ContainerStonecutter extends Container {
|
2020-07-05 03:36:46 +00:00
|
|
|
this.a(iinventory, itemstack);
|
|
|
|
}
|
|
|
|
|
2020-07-05 19:33:23 +00:00
|
|
|
+ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareResultEvent(this, 1); // Paper
|
2020-07-05 03:36:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void a(IInventory iinventory, ItemStack itemstack) {
|
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
2021-04-18 09:02:48 +00:00
|
|
|
index 0b6ce7a3c077982a5f341baf3049e6ce66eaa194..2e4dc2fb42b10243ddacbf5af606910a5769ea01 100644
|
2020-07-05 03:36:46 +00:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
2021-03-16 13:04:28 +00:00
|
|
|
@@ -1512,19 +1512,44 @@ public class CraftEventFactory {
|
2020-07-05 03:36:46 +00:00
|
|
|
return event;
|
|
|
|
}
|
|
|
|
|
|
|
|
- public static PrepareAnvilEvent callPrepareAnvilEvent(InventoryView view, ItemStack item) {
|
2020-07-05 06:25:29 +00:00
|
|
|
- PrepareAnvilEvent event = new PrepareAnvilEvent(view, CraftItemStack.asCraftMirror(item).clone());
|
|
|
|
- event.getView().getPlayer().getServer().getPluginManager().callEvent(event);
|
|
|
|
+ // Paper start - disable this method, handled below
|
2020-07-05 03:36:46 +00:00
|
|
|
+ public static void callPrepareAnvilEvent(InventoryView view, ItemStack item) { // Paper - verify nothing uses return - handled below in PrepareResult
|
2020-07-05 06:25:29 +00:00
|
|
|
+ PrepareAnvilEvent event = new PrepareAnvilEvent(view, CraftItemStack.asCraftMirror(item)); // Paper - remove clone
|
|
|
|
+ //event.getView().getPlayer().getServer().getPluginManager().callEvent(event); // disable event
|
2020-07-05 03:36:46 +00:00
|
|
|
event.getInventory().setItem(2, event.getResult());
|
2020-07-05 19:33:23 +00:00
|
|
|
- return event;
|
2020-07-05 03:36:46 +00:00
|
|
|
+ //return event; // Paper
|
2020-07-05 19:33:23 +00:00
|
|
|
}
|
2020-07-05 06:25:29 +00:00
|
|
|
+ // Paper end
|
2020-07-22 23:35:44 +00:00
|
|
|
|
|
|
|
- public static PrepareSmithingEvent callPrepareSmithingEvent(InventoryView view, ItemStack item) {
|
|
|
|
- PrepareSmithingEvent event = new PrepareSmithingEvent(view, CraftItemStack.asCraftMirror(item).clone());
|
|
|
|
- event.getView().getPlayer().getServer().getPluginManager().callEvent(event);
|
|
|
|
+ // Paper start - disable this method, handled in callPrepareResultEvent
|
|
|
|
+ public static void callPrepareSmithingEvent(InventoryView view, ItemStack item) { // Paper - verify nothing uses return - handled below in PrepareResult
|
|
|
|
+ PrepareSmithingEvent event = new PrepareSmithingEvent(view, CraftItemStack.asCraftMirror(item)); // Paper - remove clone
|
|
|
|
+ //event.getView().getPlayer().getServer().getPluginManager().callEvent(event); // Paper - disable event
|
|
|
|
event.getInventory().setItem(2, event.getResult());
|
|
|
|
- return event;
|
|
|
|
+ //return event; // Paper
|
|
|
|
}
|
|
|
|
+ // Paper end
|
2020-07-05 03:36:46 +00:00
|
|
|
+
|
|
|
|
+ // Paper start - support specific overrides for prepare result
|
2021-03-16 13:04:28 +00:00
|
|
|
+ public static void callPrepareResultEvent(Container container, int resultSlot) {
|
2020-07-05 03:36:46 +00:00
|
|
|
+ com.destroystokyo.paper.event.inventory.PrepareResultEvent event;
|
2020-07-05 19:33:23 +00:00
|
|
|
+ InventoryView view = container.getBukkitView();
|
|
|
|
+ org.bukkit.inventory.ItemStack origItem = view.getTopInventory().getItem(resultSlot);
|
|
|
|
+ CraftItemStack result = origItem != null ? CraftItemStack.asCraftCopy(origItem) : null;
|
2020-07-05 03:36:46 +00:00
|
|
|
+ if (view.getTopInventory() instanceof org.bukkit.inventory.AnvilInventory) {
|
|
|
|
+ event = new PrepareAnvilEvent(view, result);
|
|
|
|
+ } else if (view.getTopInventory() instanceof org.bukkit.inventory.GrindstoneInventory) {
|
|
|
|
+ event = new com.destroystokyo.paper.event.inventory.PrepareGrindstoneEvent(view, result);
|
2020-07-22 23:35:44 +00:00
|
|
|
+ } else if (view.getTopInventory() instanceof org.bukkit.inventory.SmithingInventory) {
|
|
|
|
+ event = new PrepareSmithingEvent(view, result);
|
2020-07-05 03:36:46 +00:00
|
|
|
+ } else {
|
|
|
|
+ event = new com.destroystokyo.paper.event.inventory.PrepareResultEvent(view, result);
|
|
|
|
+ }
|
|
|
|
+ event.callEvent();
|
|
|
|
+ event.getInventory().setItem(resultSlot, event.getResult());
|
2020-07-05 19:33:23 +00:00
|
|
|
+ container.notifyListeners();
|
|
|
|
+ }
|
2020-07-05 03:36:46 +00:00
|
|
|
+ // Paper end
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Mob spawner event.
|