mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-29 12:27:59 +01:00
f3727ff757
Upstream has released updates that appear to apply and compile correctly. This update has not been tested by PaperMC and as with ANY update, please do your own testing Bukkit Changes: 14883d6b SPIGOT-6078: Add SmithItemEvent and expand SmithingInventory API CraftBukkit Changes: 115244c7 SPIGOT-6078: Add SmithItemEvent and expand SmithingInventory API
165 lines
9.0 KiB
Diff
165 lines
9.0 KiB
Diff
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 {
|
|
// CraftBukkit end
|
|
}
|
|
|
|
+ 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) {
|
|
- 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
|
|
+ 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
|
|
}
|
|
+ // 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
|
|
+ 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.
|