2020-07-05 05:36:46 +02: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-23 01:35:44 +02:00
|
|
|
Anvil, Grindstone and Smithing now extend this event
|
2020-07-05 05:36:46 +02:00
|
|
|
|
2020-07-05 21:33:23 +02:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/Container.java b/src/main/java/net/minecraft/server/Container.java
|
2020-08-25 04:22:08 +02:00
|
|
|
index 1045bd6eaa977b0142b4496c3f872ffae767a0f1..73a057b074af938a03decb0a53784aff321411ab 100644
|
2020-07-05 21:33:23 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/Container.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/Container.java
|
|
|
|
@@ -126,6 +126,7 @@ public abstract class Container {
|
|
|
|
return nonnulllist;
|
|
|
|
}
|
|
|
|
|
2020-08-02 07:39:36 +02:00
|
|
|
+ public final void notifyListeners() { this.c(); } // Paper - OBFHELPER
|
2020-07-05 21:33:23 +02:00
|
|
|
public void c() {
|
|
|
|
int i;
|
|
|
|
|
2020-07-05 05:36:46 +02:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/ContainerAnvil.java b/src/main/java/net/minecraft/server/ContainerAnvil.java
|
2020-07-05 21:33:23 +02:00
|
|
|
index 24631b2bcb2a1d057c1fb6596ff401133c8b548a..fc2038df89f25c07f6f853f6df41fe9b203c3585 100644
|
2020-07-05 05:36:46 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/ContainerAnvil.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/ContainerAnvil.java
|
2020-07-05 21:33:23 +02:00
|
|
|
@@ -294,6 +294,7 @@ public class ContainerAnvil extends ContainerAnvilAbstract {
|
2020-07-05 05:36:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
this.e();
|
2020-07-05 21:33:23 +02:00
|
|
|
+ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareResultEvent(this, 2); // Paper
|
2020-07-05 05:36:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// CraftBukkit start
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/ContainerAnvilAbstract.java b/src/main/java/net/minecraft/server/ContainerAnvilAbstract.java
|
2020-08-25 04:22:08 +02:00
|
|
|
index 70f9c189cb92656ba07ef7c60cfff646c2980b9e..1b7724422fc5d6a99fe60837d1f48585775a933a 100644
|
2020-07-05 05:36:46 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/ContainerAnvilAbstract.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/ContainerAnvilAbstract.java
|
2020-07-05 21:33:23 +02:00
|
|
|
@@ -65,6 +65,7 @@ public abstract class ContainerAnvilAbstract extends Container {
|
|
|
|
super.a(iinventory);
|
|
|
|
if (iinventory == this.repairInventory) {
|
2020-07-05 05:36:46 +02:00
|
|
|
this.e();
|
2020-07-05 21:33:23 +02:00
|
|
|
+ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareResultEvent(this, 2); // Paper
|
2020-07-05 05:36:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/ContainerCartography.java b/src/main/java/net/minecraft/server/ContainerCartography.java
|
2020-09-03 10:47:24 +02:00
|
|
|
index b829a481394167593ccf7521770802531b9ed483..0dd8623591827cd29fdf7916bf9a4b182816f28a 100644
|
2020-07-05 05:36:46 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/ContainerCartography.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/ContainerCartography.java
|
2020-09-03 10:47:24 +02:00
|
|
|
@@ -135,6 +135,7 @@ public class ContainerCartography extends Container {
|
2020-07-05 05:36:46 +02:00
|
|
|
this.a(itemstack, itemstack1, itemstack2);
|
|
|
|
}
|
|
|
|
|
2020-07-05 21:33:23 +02:00
|
|
|
+ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareResultEvent(this, 2); // Paper
|
2020-07-05 05:36:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private void a(ItemStack itemstack, ItemStack itemstack1, ItemStack itemstack2) {
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/ContainerGrindstone.java b/src/main/java/net/minecraft/server/ContainerGrindstone.java
|
2020-07-05 21:33:23 +02:00
|
|
|
index fe9a083b724a8657cac8462b3f44d3cc12a4db58..39f809a37b58e008e7ef32c0759eeecbde26bc94 100644
|
2020-07-05 05:36:46 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/ContainerGrindstone.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/ContainerGrindstone.java
|
2020-07-05 21:33:23 +02:00
|
|
|
@@ -144,6 +144,7 @@ public class ContainerGrindstone extends Container {
|
2020-07-05 05:36:46 +02:00
|
|
|
super.a(iinventory);
|
|
|
|
if (iinventory == this.craftInventory) {
|
|
|
|
this.e();
|
2020-07-05 21:33:23 +02:00
|
|
|
+ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareResultEvent(this, 2); // Paper
|
2020-07-05 05:36:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/ContainerLoom.java b/src/main/java/net/minecraft/server/ContainerLoom.java
|
2020-07-05 21:33:23 +02:00
|
|
|
index 9490f74ee426e162844432073b3d78a2b6cddb32..1fe21ca13a1eecb64cb2d3f4f18993e181d26ae2 100644
|
2020-07-05 05:36:46 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/ContainerLoom.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/ContainerLoom.java
|
2020-07-05 21:33:23 +02:00
|
|
|
@@ -174,7 +174,8 @@ public class ContainerLoom extends Container {
|
|
|
|
}
|
2020-07-05 05:36:46 +02:00
|
|
|
|
|
|
|
this.j();
|
2020-07-05 21:33:23 +02:00
|
|
|
- this.c();
|
|
|
|
+ //this.c(); // Paper - done below
|
|
|
|
+ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareResultEvent(this, 3); // Paper
|
2020-07-05 05:36:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/ContainerSmithing.java b/src/main/java/net/minecraft/server/ContainerSmithing.java
|
2020-09-03 10:47:24 +02:00
|
|
|
index a6bfc4a49ea0a789cea3706fdd6673837a4b0829..61ef3adcfb021e222042de62ad06a2e7d808f5b5 100644
|
2020-07-05 05:36:46 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/ContainerSmithing.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/ContainerSmithing.java
|
2020-08-25 04:22:08 +02:00
|
|
|
@@ -68,6 +68,7 @@ public class ContainerSmithing extends ContainerAnvilAbstract {
|
2020-07-23 01:35:44 +02:00
|
|
|
org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareSmithingEvent(getBukkitView(), itemstack); // CraftBukkit
|
2020-07-05 05:36:46 +02:00
|
|
|
}
|
|
|
|
|
2020-07-05 21:33:23 +02:00
|
|
|
+ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareResultEvent(this, 2); // Paper
|
2020-07-05 05:36:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/ContainerStonecutter.java b/src/main/java/net/minecraft/server/ContainerStonecutter.java
|
2020-09-03 10:47:24 +02:00
|
|
|
index ba3db09763d94d730c3fe8662e4dbb24e0636786..3506473f9b9f4c747f7b737d9bd02bef8ea6d83e 100644
|
2020-07-05 05:36:46 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/ContainerStonecutter.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/ContainerStonecutter.java
|
2020-09-03 10:47:24 +02:00
|
|
|
@@ -142,6 +142,7 @@ public class ContainerStonecutter extends Container {
|
2020-07-05 05:36:46 +02:00
|
|
|
this.a(iinventory, itemstack);
|
|
|
|
}
|
|
|
|
|
2020-07-05 21:33:23 +02:00
|
|
|
+ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareResultEvent(this, 1); // Paper
|
2020-07-05 05:36:46 +02: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-02-05 23:52:27 +01:00
|
|
|
index 44cf5fe48650790b3372e9ebbb0b5d6c4b997f62..fe36039b7dbfeebc1e01a9cefc5f8f391087fee6 100644
|
2020-07-05 05:36:46 +02:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
2021-02-05 23:52:27 +01:00
|
|
|
@@ -1509,19 +1509,44 @@ public class CraftEventFactory {
|
2020-07-05 05:36:46 +02:00
|
|
|
return event;
|
|
|
|
}
|
|
|
|
|
|
|
|
- public static PrepareAnvilEvent callPrepareAnvilEvent(InventoryView view, ItemStack item) {
|
2020-07-05 08:25:29 +02: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 05:36:46 +02:00
|
|
|
+ public static void callPrepareAnvilEvent(InventoryView view, ItemStack item) { // Paper - verify nothing uses return - handled below in PrepareResult
|
2020-07-05 08:25:29 +02:00
|
|
|
+ PrepareAnvilEvent event = new PrepareAnvilEvent(view, CraftItemStack.asCraftMirror(item)); // Paper - remove clone
|
|
|
|
+ //event.getView().getPlayer().getServer().getPluginManager().callEvent(event); // disable event
|
2020-07-05 05:36:46 +02:00
|
|
|
event.getInventory().setItem(2, event.getResult());
|
2020-07-05 21:33:23 +02:00
|
|
|
- return event;
|
2020-07-05 05:36:46 +02:00
|
|
|
+ //return event; // Paper
|
2020-07-05 21:33:23 +02:00
|
|
|
}
|
2020-07-05 08:25:29 +02:00
|
|
|
+ // Paper end
|
2020-07-23 01:35:44 +02: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 05:36:46 +02:00
|
|
|
+
|
|
|
|
+ // Paper start - support specific overrides for prepare result
|
2020-07-05 21:33:23 +02:00
|
|
|
+ public static void callPrepareResultEvent(net.minecraft.server.Container container, int resultSlot) {
|
2020-07-05 05:36:46 +02:00
|
|
|
+ com.destroystokyo.paper.event.inventory.PrepareResultEvent event;
|
2020-07-05 21:33:23 +02: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 05:36:46 +02: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-23 01:35:44 +02:00
|
|
|
+ } else if (view.getTopInventory() instanceof org.bukkit.inventory.SmithingInventory) {
|
|
|
|
+ event = new PrepareSmithingEvent(view, result);
|
2020-07-05 05:36:46 +02:00
|
|
|
+ } else {
|
|
|
|
+ event = new com.destroystokyo.paper.event.inventory.PrepareResultEvent(view, result);
|
|
|
|
+ }
|
|
|
|
+ event.callEvent();
|
|
|
|
+ event.getInventory().setItem(resultSlot, event.getResult());
|
2020-07-05 21:33:23 +02:00
|
|
|
+ container.notifyListeners();
|
|
|
|
+ }
|
2020-07-05 05:36:46 +02:00
|
|
|
+ // Paper end
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Mob spawner event.
|