PaperMC/Spigot-Server-Patches/Add-PrepareResultEvent.patch

165 lines
9.1 KiB
Diff
Raw Normal View History

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
Anvil, Grindstone and Smithing now extend this event
diff --git a/src/main/java/net/minecraft/world/inventory/Container.java b/src/main/java/net/minecraft/world/inventory/Container.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/inventory/Container.java
+++ b/src/main/java/net/minecraft/world/inventory/Container.java
@@ -0,0 +0,0 @@ public abstract class Container {
return nonnulllist;
}
+ public final void notifyListeners() { this.c(); } // Paper - OBFHELPER
public void c() {
int i;
diff --git a/src/main/java/net/minecraft/world/inventory/ContainerAnvil.java b/src/main/java/net/minecraft/world/inventory/ContainerAnvil.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/inventory/ContainerAnvil.java
+++ b/src/main/java/net/minecraft/world/inventory/ContainerAnvil.java
@@ -0,0 +0,0 @@ public class ContainerAnvil extends ContainerAnvilAbstract {
}
this.e();
+ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareResultEvent(this, 2); // Paper
}
// CraftBukkit start
diff --git a/src/main/java/net/minecraft/world/inventory/ContainerAnvilAbstract.java b/src/main/java/net/minecraft/world/inventory/ContainerAnvilAbstract.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/inventory/ContainerAnvilAbstract.java
+++ b/src/main/java/net/minecraft/world/inventory/ContainerAnvilAbstract.java
@@ -0,0 +0,0 @@ public abstract class ContainerAnvilAbstract extends Container {
super.a(iinventory);
if (iinventory == this.repairInventory) {
this.e();
+ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareResultEvent(this, 2); // Paper
}
}
diff --git a/src/main/java/net/minecraft/world/inventory/ContainerCartography.java b/src/main/java/net/minecraft/world/inventory/ContainerCartography.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/inventory/ContainerCartography.java
+++ b/src/main/java/net/minecraft/world/inventory/ContainerCartography.java
@@ -0,0 +0,0 @@ public class ContainerCartography extends Container {
this.a(itemstack, itemstack1, itemstack2);
}
+ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareResultEvent(this, 2); // Paper
}
private void a(ItemStack itemstack, ItemStack itemstack1, ItemStack itemstack2) {
diff --git a/src/main/java/net/minecraft/world/inventory/ContainerGrindstone.java b/src/main/java/net/minecraft/world/inventory/ContainerGrindstone.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/inventory/ContainerGrindstone.java
+++ b/src/main/java/net/minecraft/world/inventory/ContainerGrindstone.java
@@ -0,0 +0,0 @@ public class ContainerGrindstone extends Container {
super.a(iinventory);
if (iinventory == this.craftInventory) {
this.e();
+ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareResultEvent(this, 2); // Paper
}
}
diff --git a/src/main/java/net/minecraft/world/inventory/ContainerLoom.java b/src/main/java/net/minecraft/world/inventory/ContainerLoom.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/inventory/ContainerLoom.java
+++ b/src/main/java/net/minecraft/world/inventory/ContainerLoom.java
@@ -0,0 +0,0 @@ public class ContainerLoom extends Container {
}
this.j();
- this.c();
+ //this.c(); // Paper - done below
+ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareResultEvent(this, 3); // Paper
}
@Override
diff --git a/src/main/java/net/minecraft/world/inventory/ContainerSmithing.java b/src/main/java/net/minecraft/world/inventory/ContainerSmithing.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/inventory/ContainerSmithing.java
+++ b/src/main/java/net/minecraft/world/inventory/ContainerSmithing.java
@@ -0,0 +0,0 @@ public class ContainerSmithing extends ContainerAnvilAbstract {
org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareSmithingEvent(getBukkitView(), itemstack); // CraftBukkit
}
+ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareResultEvent(this, 2); // Paper
}
@Override
diff --git a/src/main/java/net/minecraft/world/inventory/ContainerStonecutter.java b/src/main/java/net/minecraft/world/inventory/ContainerStonecutter.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/inventory/ContainerStonecutter.java
+++ b/src/main/java/net/minecraft/world/inventory/ContainerStonecutter.java
@@ -0,0 +0,0 @@ public class ContainerStonecutter extends Container {
this.a(iinventory, itemstack);
}
+ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareResultEvent(this, 1); // Paper
}
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
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
+++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
@@ -0,0 +0,0 @@ public class CraftEventFactory {
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
+ 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
event.getInventory().setItem(2, event.getResult());
- return event;
+ //return event; // Paper
}
2020-07-05 08:25:29 +02:00
+ // Paper end
- 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
+
+ // Paper start - support specific overrides for prepare result
2021-03-16 14:04:28 +01:00
+ public static void callPrepareResultEvent(Container container, int resultSlot) {
+ com.destroystokyo.paper.event.inventory.PrepareResultEvent event;
+ InventoryView view = container.getBukkitView();
+ org.bukkit.inventory.ItemStack origItem = view.getTopInventory().getItem(resultSlot);
+ CraftItemStack result = origItem != null ? CraftItemStack.asCraftCopy(origItem) : null;
+ 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);
+ } else if (view.getTopInventory() instanceof org.bukkit.inventory.SmithingInventory) {
+ event = new PrepareSmithingEvent(view, result);
+ } else {
+ event = new com.destroystokyo.paper.event.inventory.PrepareResultEvent(view, result);
+ }
+ event.callEvent();
+ event.getInventory().setItem(resultSlot, event.getResult());
+ container.notifyListeners();
+ }
+ // Paper end
/**
* Mob spawner event.