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

145 lines
7.4 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 and Grindstone now extend this event
diff --git a/src/main/java/net/minecraft/server/ContainerAnvil.java b/src/main/java/net/minecraft/server/ContainerAnvil.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/server/ContainerAnvil.java
+++ b/src/main/java/net/minecraft/server/ContainerAnvil.java
@@ -0,0 +0,0 @@ public class ContainerAnvil extends ContainerAnvilAbstract {
}
this.e();
+
+ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareResultEvent(getBukkitView(), this.resultInventory.getItem(0), 2); // Paper
}
// CraftBukkit start
diff --git a/src/main/java/net/minecraft/server/ContainerAnvilAbstract.java b/src/main/java/net/minecraft/server/ContainerAnvilAbstract.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/server/ContainerAnvilAbstract.java
+++ b/src/main/java/net/minecraft/server/ContainerAnvilAbstract.java
@@ -0,0 +0,0 @@ public abstract class ContainerAnvilAbstract extends Container {
this.e();
}
+ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareResultEvent(getBukkitView(), this.resultInventory.getItem(0), 2); // Paper
}
@Override
diff --git a/src/main/java/net/minecraft/server/ContainerCartography.java b/src/main/java/net/minecraft/server/ContainerCartography.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/server/ContainerCartography.java
+++ b/src/main/java/net/minecraft/server/ContainerCartography.java
@@ -0,0 +0,0 @@ public class ContainerCartography extends Container {
this.a(itemstack, itemstack1, itemstack2);
}
+ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareResultEvent(getBukkitView(), this.resultInventory.getItem(0), 2); // Paper
}
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
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/server/ContainerGrindstone.java
+++ b/src/main/java/net/minecraft/server/ContainerGrindstone.java
@@ -0,0 +0,0 @@ import org.bukkit.craftbukkit.inventory.CraftInventoryGrindstone;
import org.bukkit.craftbukkit.inventory.CraftInventoryView;
import org.bukkit.entity.Player;
// CraftBukkit end
+// Paper start
+import org.bukkit.craftbukkit.inventory.CraftItemStack;
+import com.destroystokyo.paper.event.inventory.PrepareGrindstoneEvent;
+// Paper end
public class ContainerGrindstone extends Container {
@@ -0,0 +0,0 @@ public class ContainerGrindstone extends Container {
super.a(iinventory);
if (iinventory == this.craftInventory) {
this.e();
+ // Paper start
+ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareResultEvent(getBukkitView(), this.resultInventory.getItem(0), 2); // Paper
+ // Paper end
}
}
diff --git a/src/main/java/net/minecraft/server/ContainerLoom.java b/src/main/java/net/minecraft/server/ContainerLoom.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/server/ContainerLoom.java
+++ b/src/main/java/net/minecraft/server/ContainerLoom.java
@@ -0,0 +0,0 @@ public class ContainerLoom extends Container {
this.j();
this.c();
+
+ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareResultEvent(getBukkitView(), this.resultInventory.getItem(0), 3); // Paper
}
@Override
diff --git a/src/main/java/net/minecraft/server/ContainerSmithing.java b/src/main/java/net/minecraft/server/ContainerSmithing.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/server/ContainerSmithing.java
+++ b/src/main/java/net/minecraft/server/ContainerSmithing.java
@@ -0,0 +0,0 @@ public class ContainerSmithing extends ContainerAnvilAbstract {
this.resultInventory.setItem(0, itemstack);
}
+ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareResultEvent(getBukkitView(), this.resultInventory.getItem(0), 2); // Paper
}
@Override
diff --git a/src/main/java/net/minecraft/server/ContainerStonecutter.java b/src/main/java/net/minecraft/server/ContainerStonecutter.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/server/ContainerStonecutter.java
+++ b/src/main/java/net/minecraft/server/ContainerStonecutter.java
@@ -0,0 +0,0 @@ public class ContainerStonecutter extends Container {
this.a(iinventory, itemstack);
}
+ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareResultEvent(getBukkitView(), this.resultInventory.getItem(0), 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) {
+ public static void callPrepareAnvilEvent(InventoryView view, ItemStack item) { // Paper - verify nothing uses return - handled below in PrepareResult
+ if (true) return; // Paper - nothing
PrepareAnvilEvent event = new PrepareAnvilEvent(view, CraftItemStack.asCraftMirror(item).clone());
event.getView().getPlayer().getServer().getPluginManager().callEvent(event);
event.getInventory().setItem(2, event.getResult());
+ //return event; // Paper
+ }
+
+ // Paper start - support specific overrides for prepare result
+ public static com.destroystokyo.paper.event.inventory.PrepareResultEvent callPrepareResultEvent(InventoryView view, ItemStack item, int resultSlot) {
+ com.destroystokyo.paper.event.inventory.PrepareResultEvent event;
+ CraftItemStack result = CraftItemStack.asCraftMirror(item).clone();
+ 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 {
+ event = new com.destroystokyo.paper.event.inventory.PrepareResultEvent(view, result);
+ }
+ event.callEvent();
+ event.getInventory().setItem(resultSlot, event.getResult());
return event;
}
+ // Paper end
/**
* Mob spawner event.