3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-12-15 11:00:06 +01:00

Added PlayerStonecutterRecipeSelectEvent

Co-Authored-By: MiniDigger <admin@minidigger.me>
Dieser Commit ist enthalten in:
Jake Potrebic 2020-11-27 17:15:15 -08:00 committet von MiniDigger | Martin
Ursprung fc885f966e
Commit 091e6700fe
2 geänderte Dateien mit 180 neuen und 0 gelöschten Zeilen

Datei anzeigen

@ -0,0 +1,71 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Jake Potrebic <jake.m.potrebic@gmail.com>
Date: Fri, 27 Nov 2020 17:13:59 -0800
Subject: [PATCH] Added PlayerStonecutterRecipeSelectEvent
diff --git a/src/main/java/io/papermc/paper/event/player/PlayerStonecutterRecipeSelectEvent.java b/src/main/java/io/papermc/paper/event/player/PlayerStonecutterRecipeSelectEvent.java
new file mode 100644
index 0000000000000000000000000000000000000000..fb1bca3a9d12096c9a2b2663f466a8ff5f2b4319
--- /dev/null
+++ b/src/main/java/io/papermc/paper/event/player/PlayerStonecutterRecipeSelectEvent.java
@@ -0,0 +1,59 @@
+package io.papermc.paper.event.player;
+
+import org.bukkit.entity.Player;
+import org.bukkit.event.Cancellable;
+import org.bukkit.event.HandlerList;
+import org.bukkit.event.player.PlayerEvent;
+import org.bukkit.inventory.StonecutterInventory;
+import org.bukkit.inventory.StonecuttingRecipe;
+import org.jetbrains.annotations.NotNull;
+
+public class PlayerStonecutterRecipeSelectEvent extends PlayerEvent implements Cancellable {
+
+ private static final HandlerList HANDLER_LIST = new HandlerList();
+
+ private boolean cancelled;
+ private final StonecutterInventory stonecutterInventory;
+ private StonecuttingRecipe stonecuttingRecipe;
+
+ public PlayerStonecutterRecipeSelectEvent(@NotNull Player player, @NotNull StonecutterInventory stonecutterInventory, @NotNull StonecuttingRecipe stonecuttingRecipe) {
+ super(player);
+ this.stonecutterInventory = stonecutterInventory;
+ this.stonecuttingRecipe = stonecuttingRecipe;
+ }
+
+ @NotNull
+ public StonecutterInventory getStonecutterInventory() {
+ return stonecutterInventory;
+ }
+
+ @NotNull
+ public StonecuttingRecipe getStonecuttingRecipe() {
+ return stonecuttingRecipe;
+ }
+
+ public void setStonecuttingRecipe(@NotNull StonecuttingRecipe stonecuttingRecipe) {
+ this.stonecuttingRecipe = stonecuttingRecipe;
+ }
+
+ @Override
+ public boolean isCancelled() {
+ return cancelled;
+ }
+
+ @Override
+ public void setCancelled(boolean cancel) {
+ this.cancelled = cancel;
+ }
+
+ @NotNull
+ @Override
+ public HandlerList getHandlers() {
+ return HANDLER_LIST;
+ }
+
+ @NotNull
+ public static HandlerList getHandlerList() {
+ return HANDLER_LIST;
+ }
+}

Datei anzeigen

@ -0,0 +1,109 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Jake Potrebic <jake.m.potrebic@gmail.com>
Date: Fri, 27 Nov 2020 17:14:27 -0800
Subject: [PATCH] Added PlayerStonecutterRecipeSelectEvent
Co-Authored-By: MiniDigger <admin@minidigger.me>
diff --git a/src/main/java/net/minecraft/server/Container.java b/src/main/java/net/minecraft/server/Container.java
index 3de58cd344c37451873aa8a12b5d9e65f390ec8f..a5c92b2b7fe42b81e7feebf8969a08bd7d08e0e6 100644
--- a/src/main/java/net/minecraft/server/Container.java
+++ b/src/main/java/net/minecraft/server/Container.java
@@ -101,7 +101,7 @@ public abstract class Container {
return slot;
}
- protected ContainerProperty a(ContainerProperty containerproperty) {
+ protected ContainerProperty addDataSlot(ContainerProperty containerproperty) { return a(containerproperty); } protected ContainerProperty a(ContainerProperty containerproperty) { // Paper - OBFHELPER
this.d.add(containerproperty);
return containerproperty;
}
diff --git a/src/main/java/net/minecraft/server/ContainerProperty.java b/src/main/java/net/minecraft/server/ContainerProperty.java
index e26b8569340fb0240439ff85d481bd3de19c0ae3..7523c77a914d7e78b4ef08c1ef329d2ef38d3091 100644
--- a/src/main/java/net/minecraft/server/ContainerProperty.java
+++ b/src/main/java/net/minecraft/server/ContainerProperty.java
@@ -20,7 +20,7 @@ public abstract class ContainerProperty {
};
}
- public static ContainerProperty a(final int[] aint, final int i) {
+ public static ContainerProperty shared(final int[] aint, final int i) { return a(aint, i); } public static ContainerProperty a(final int[] aint, final int i) { // Paper - OBFHELPER
return new ContainerProperty() {
@Override
public int get() {
@@ -54,7 +54,7 @@ public abstract class ContainerProperty {
public abstract void set(int i);
- public boolean c() {
+ public boolean checkAndClearUpdateFlag() { return c(); } public boolean c() { // Paper - OBFHELPER
int i = this.get();
boolean flag = i != this.a;
diff --git a/src/main/java/net/minecraft/server/ContainerStonecutter.java b/src/main/java/net/minecraft/server/ContainerStonecutter.java
index 3506473f9b9f4c747f7b737d9bd02bef8ea6d83e..5a34796fa0f2a3c250722777b9131fee5e8cf04a 100644
--- a/src/main/java/net/minecraft/server/ContainerStonecutter.java
+++ b/src/main/java/net/minecraft/server/ContainerStonecutter.java
@@ -8,13 +8,14 @@ import org.bukkit.craftbukkit.inventory.CraftInventoryStonecutter;
import org.bukkit.craftbukkit.inventory.CraftInventoryView;
import org.bukkit.entity.Player;
// CraftBukkit end
+import io.papermc.paper.event.player.PlayerStonecutterRecipeSelectEvent; // Paper
public class ContainerStonecutter extends Container {
private final ContainerAccess containerAccess;
private final ContainerProperty containerProperty;
private final World world;
- private List<RecipeStonecutting> i;
+ private List<RecipeStonecutting> i; public final List<RecipeStonecutting> getRecipes() { return this.i; } // Paper - OBFHELPER
private ItemStack j;
private long k;
final Slot c;
@@ -44,7 +45,7 @@ public class ContainerStonecutter extends Container {
public ContainerStonecutter(int i, PlayerInventory playerinventory, final ContainerAccess containeraccess) {
super(Containers.STONECUTTER, i);
- this.containerProperty = ContainerProperty.a();
+ this.containerProperty = addDataSlot(ContainerProperty.shared(new int[1], 0)); // Paper - allow replication
this.i = Lists.newArrayList();
this.j = ItemStack.b;
this.l = () -> {
@@ -122,13 +123,36 @@ public class ContainerStonecutter extends Container {
@Override
public boolean a(EntityHuman entityhuman, int i) {
if (this.d(i)) {
- this.containerProperty.set(i);
+ // Paper start
+ int recipeIndex = i;
+ this.containerProperty.set(recipeIndex);
+ this.containerProperty.checkAndClearUpdateFlag(); // mark as changed
+ if (this.isValidRecipeIndex(i)) {
+ PlayerStonecutterRecipeSelectEvent event = new PlayerStonecutterRecipeSelectEvent((Player) entityhuman.getBukkitEntity(), (org.bukkit.inventory.StonecutterInventory) getBukkitView().getTopInventory(), (org.bukkit.inventory.StonecuttingRecipe) this.getRecipes().get(i).toBukkitRecipe());
+ if (!event.callEvent()) {
+ ((Player) entityhuman.getBukkitEntity()).updateInventory();
+ return false;
+ }
+ int newRecipeIndex;
+ if (!this.getRecipes().get(recipeIndex).getKey().equals(org.bukkit.craftbukkit.util.CraftNamespacedKey.toMinecraft(event.getStonecuttingRecipe().getKey()))) { // If the recipe did NOT stay the same
+ for (newRecipeIndex = 0; newRecipeIndex < this.getRecipes().size(); newRecipeIndex++) {
+ if (this.getRecipes().get(newRecipeIndex).getKey().equals(org.bukkit.craftbukkit.util.CraftNamespacedKey.toMinecraft(event.getStonecuttingRecipe().getKey()))) {
+ recipeIndex = newRecipeIndex;
+ break;
+ }
+ }
+ }
+ }
+ ((Player) entityhuman.getBukkitEntity()).updateInventory();
+ this.containerProperty.set(recipeIndex); // set new index, so that listeners can read it
+ // Paper end
this.i();
}
return true;
}
+ private boolean isValidRecipeIndex(int index) { return this.d(index); } // Paper - OBFHELPER
private boolean d(int i) {
return i >= 0 && i < this.i.size();
}