From 576f627798f7d47d5d2314ce1adf2e00b1f1fd32 Mon Sep 17 00:00:00 2001 From: Bukkit/Spigot Date: Thu, 23 Mar 2023 20:55:12 +1100 Subject: [PATCH] SPIGOT-7309: Add API for jukebox inventories By: Parker Hawke --- .../main/java/org/bukkit/block/Jukebox.java | 19 +++++++++- .../bukkit/event/inventory/InventoryType.java | 4 +++ .../bukkit/inventory/JukeboxInventory.java | 35 +++++++++++++++++++ 3 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 paper-api/src/main/java/org/bukkit/inventory/JukeboxInventory.java diff --git a/paper-api/src/main/java/org/bukkit/block/Jukebox.java b/paper-api/src/main/java/org/bukkit/block/Jukebox.java index 321e5e034a..337fc4a503 100644 --- a/paper-api/src/main/java/org/bukkit/block/Jukebox.java +++ b/paper-api/src/main/java/org/bukkit/block/Jukebox.java @@ -1,14 +1,16 @@ package org.bukkit.block; import org.bukkit.Material; +import org.bukkit.inventory.BlockInventoryHolder; import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.JukeboxInventory; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; /** * Represents a captured state of a jukebox. */ -public interface Jukebox extends TileState { +public interface Jukebox extends TileState, BlockInventoryHolder { /** * Gets the record inserted into the jukebox. @@ -62,4 +64,19 @@ public interface Jukebox extends TileState { * @throws IllegalStateException if this block state is not placed */ public boolean eject(); + + /** + * @return inventory + * @see Container#getInventory() + */ + @NotNull + @Override + JukeboxInventory getInventory(); + + /** + * @return snapshot inventory + * @see Container#getSnapshotInventory() + */ + @NotNull + JukeboxInventory getSnapshotInventory(); } diff --git a/paper-api/src/main/java/org/bukkit/event/inventory/InventoryType.java b/paper-api/src/main/java/org/bukkit/event/inventory/InventoryType.java index 4fb754cd7f..629c1bf79c 100644 --- a/paper-api/src/main/java/org/bukkit/event/inventory/InventoryType.java +++ b/paper-api/src/main/java/org/bukkit/event/inventory/InventoryType.java @@ -138,6 +138,10 @@ public enum InventoryType { * Pseudo chiseled bookshelf inventory, with 6 slots of undefined type. */ CHISELED_BOOKSHELF(6, "Chiseled Bookshelf", false), + /** + * Pseudo jukebox inventory with 1 slot of undefined type. + */ + JUKEBOX(1, "Jukebox", false), /** * The new smithing inventory, with 3 CRAFTING slots and 1 RESULT slot. * diff --git a/paper-api/src/main/java/org/bukkit/inventory/JukeboxInventory.java b/paper-api/src/main/java/org/bukkit/inventory/JukeboxInventory.java new file mode 100644 index 0000000000..f4b3b7f145 --- /dev/null +++ b/paper-api/src/main/java/org/bukkit/inventory/JukeboxInventory.java @@ -0,0 +1,35 @@ +package org.bukkit.inventory; + +import org.bukkit.Tag; +import org.bukkit.block.Jukebox; +import org.jetbrains.annotations.Nullable; + +/** + * Interface to the inventory of a Jukebox. + */ +public interface JukeboxInventory extends Inventory { + + /** + * Set the record in the jukebox. + *

+ * This will immediately start playing the inserted item or stop playing if the + * item provided is null. If the provided item is not a record (according to + * {@link Tag#ITEMS_MUSIC_DISCS}), this method will do nothing and not set the + * item in the inventory. + * + * @param item the new record + */ + void setRecord(@Nullable ItemStack item); + + /** + * Get the record in the jukebox. + * + * @return the current record + */ + @Nullable + ItemStack getRecord(); + + @Nullable + @Override + public Jukebox getHolder(); +}