SPIGOT-7309: Add API for jukebox inventories

By: Parker Hawke <hawkeboyz2@hotmail.com>
This commit is contained in:
Bukkit/Spigot 2023-03-23 20:55:12 +11:00
parent 027afe0c44
commit 576f627798
3 changed files with 57 additions and 1 deletions

View file

@ -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();
}

View file

@ -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.
*

View file

@ -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.
* <p>
* 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();
}