Anvil API

This commit is contained in:
William Blake Galbreath
2025-01-05 11:51:38 -08:00
committed by granny
parent 0a46145697
commit 30672ed8f7
11 changed files with 375 additions and 414 deletions

View File

@@ -0,0 +1,45 @@
--- a/src/main/java/org/bukkit/inventory/AnvilInventory.java
+++ b/src/main/java/org/bukkit/inventory/AnvilInventory.java
@@ -138,4 +_,42 @@
setItem(2, result);
}
// Paper end
+
+ // Purpur start
+ /**
+ * Gets if the player viewing the anvil inventory can bypass experience cost
+ *
+ * @return whether the player viewing the anvil inventory can bypass the experience cost
+ * @deprecated use {@link AnvilView#canBypassCost()}.
+ */
+ @Deprecated(forRemoval = true, since = "1.21")
+ boolean canBypassCost();
+
+ /**
+ * Set if the player viewing the anvil inventory can bypass the experience cost
+ *
+ * @param bypassCost whether the player viewing the anvil inventory can bypass the experience cost
+ * @deprecated use {@link AnvilView#setBypassCost(boolean)}.
+ */
+ @Deprecated(forRemoval = true, since = "1.21")
+ void setBypassCost(boolean bypassCost);
+
+ /**
+ * Gets if the player viewing the anvil inventory can do unsafe enchants
+ *
+ * @return whether the player viewing the anvil inventory can do unsafe enchants
+ * @deprecated use {@link AnvilView#canDoUnsafeEnchants()}.
+ */
+ @Deprecated(forRemoval = true, since = "1.21")
+ boolean canDoUnsafeEnchants();
+
+ /**
+ * Set if the player viewing the anvil inventory can do unsafe enchants
+ *
+ * @param canDoUnsafeEnchants whether the player viewing the anvil inventory can do unsafe enchants
+ * @deprecated use {@link AnvilView#setDoUnsafeEnchants(boolean)}.
+ */
+ @Deprecated(forRemoval = true, since = "1.21")
+ void setDoUnsafeEnchants(boolean canDoUnsafeEnchants);
+ // Purpur end
}

View File

@@ -0,0 +1,37 @@
--- a/src/main/java/org/bukkit/inventory/view/AnvilView.java
+++ b/src/main/java/org/bukkit/inventory/view/AnvilView.java
@@ -89,4 +_,34 @@
*/
void bypassEnchantmentLevelRestriction(boolean bypassEnchantmentLevelRestriction);
// Paper end - bypass anvil level restrictions
+
+ // Purpur start - Anvil API
+ /**
+ * Gets if the player viewing the anvil inventory can bypass experience cost
+ *
+ * @return whether the player viewing the anvil inventory can bypass the experience cost
+ */
+ boolean canBypassCost();
+
+ /**
+ * Set if the player viewing the anvil inventory can bypass the experience cost
+ *
+ * @param bypassCost whether the player viewing the anvil inventory can bypass the experience cost
+ */
+ void setBypassCost(boolean bypassCost);
+
+ /**
+ * Gets if the player viewing the anvil inventory can do unsafe enchants
+ *
+ * @return whether the player viewing the anvil inventory can do unsafe enchants
+ */
+ boolean canDoUnsafeEnchants();
+
+ /**
+ * Set if the player viewing the anvil inventory can do unsafe enchants
+ *
+ * @param canDoUnsafeEnchants whether the player viewing the anvil inventory can do unsafe enchants
+ */
+ void setDoUnsafeEnchants(boolean canDoUnsafeEnchants);
+ // Purpur end - Anvil API
}

View File

@@ -0,0 +1,50 @@
package org.purpurmc.purpur.event.inventory;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList;
import org.bukkit.event.inventory.InventoryEvent;
import org.bukkit.inventory.AnvilInventory;
import org.bukkit.inventory.InventoryView;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.ApiStatus;
import org.jspecify.annotations.NullMarked;
/**
* Called when a player takes the result item out of an anvil
*/
@NullMarked
public class AnvilTakeResultEvent extends InventoryEvent {
private static final HandlerList handlers = new HandlerList();
private final Player player;
private final ItemStack result;
@ApiStatus.Internal
public AnvilTakeResultEvent(HumanEntity player, InventoryView view, ItemStack result) {
super(view);
this.player = (Player) player;
this.result = result;
}
public Player getPlayer() {
return player;
}
public ItemStack getResult() {
return result;
}
@Override
public AnvilInventory getInventory() {
return (AnvilInventory) super.getInventory();
}
@Override
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
}

View File

@@ -0,0 +1,35 @@
package org.purpurmc.purpur.event.inventory;
import org.bukkit.event.HandlerList;
import org.bukkit.event.inventory.InventoryEvent;
import org.bukkit.inventory.AnvilInventory;
import org.bukkit.inventory.InventoryView;
import org.jetbrains.annotations.ApiStatus;
import org.jspecify.annotations.NullMarked;
/**
* Called when anvil slots change, triggering the result slot to be updated
*/
@NullMarked
public class AnvilUpdateResultEvent extends InventoryEvent {
private static final HandlerList handlers = new HandlerList();
@ApiStatus.Internal
public AnvilUpdateResultEvent(InventoryView view) {
super(view);
}
@Override
public AnvilInventory getInventory() {
return (AnvilInventory) super.getInventory();
}
@Override
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
}