Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 18 additions & 17 deletions api/src/main/java/com/lishid/openinv/IOpenInv.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,16 @@
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import org.bukkit.inventory.InventoryView;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.Nullable;

import java.util.UUID;
import java.util.logging.Logger;

/**
* Interface defining behavior for the OpenInv plugin.
*/
@NullMarked
public interface IOpenInv {

/**
Expand Down Expand Up @@ -76,39 +77,39 @@ public interface IOpenInv {
* @return the active implementation for the server version
* @throws IllegalStateException if the server version is unsupported
*/
@NotNull IAnySilentContainer getAnySilentContainer();
IAnySilentContainer getAnySilentContainer();

/**
* Get whether a user has AnyContainer mode enabled.
*
* @param offline the user to obtain the state of
* @return true if AnyContainer mode is enabled
*/
boolean getAnyContainerStatus(@NotNull OfflinePlayer offline);
boolean getAnyContainerStatus(OfflinePlayer offline);

/**
* Set whether a user has AnyContainer mode enabled.
*
* @param offline the user to set the state of
* @param status the state of the mode
*/
void setAnyContainerStatus(@NotNull OfflinePlayer offline, boolean status);
void setAnyContainerStatus(OfflinePlayer offline, boolean status);

/**
* Get whether a user has SilentContainer mode enabled.
*
* @param offline the user to obtain the state of
* @return true if SilentContainer mode is enabled
*/
boolean getSilentContainerStatus(@NotNull OfflinePlayer offline);
boolean getSilentContainerStatus(OfflinePlayer offline);

/**
* Set whether a user has SilentContainer mode enabled.
*
* @param offline the user to set the state of
* @param status the state of the mode
*/
void setSilentContainerStatus(@NotNull OfflinePlayer offline, boolean status);
void setSilentContainerStatus(OfflinePlayer offline, boolean status);

/**
* Get an {@link ISpecialEnderChest} for a user.
Expand All @@ -119,8 +120,8 @@ public interface IOpenInv {
* @throws IllegalStateException if the server version is unsupported
* @throws InstantiationException if there was an issue creating the inventory
*/
@NotNull ISpecialEnderChest getSpecialEnderChest(
@NotNull Player player,
ISpecialEnderChest getSpecialEnderChest(
Player player,
boolean online
) throws InstantiationException;

Expand All @@ -133,16 +134,16 @@ public interface IOpenInv {
* @throws IllegalStateException if the server version is unsupported
* @throws InstantiationException if there was an issue creating the inventory
*/
@NotNull ISpecialPlayerInventory getSpecialInventory(
@NotNull Player player,
ISpecialPlayerInventory getSpecialInventory(
Player player,
boolean online
) throws InstantiationException;

/**
* @deprecated Use {@link #openInventory(Player, ISpecialInventory, boolean)}
*/
@Deprecated(forRemoval = true, since = "5.2.0")
@Nullable InventoryView openInventory(@NotNull Player player, @NotNull ISpecialInventory inventory);
@Nullable InventoryView openInventory(Player player, ISpecialInventory inventory);

/**
* Open an {@link ISpecialInventory} for a {@link Player}.
Expand All @@ -152,7 +153,7 @@ public interface IOpenInv {
* @param viewOnly whether the inventory should be view-only
* @return the resulting {@link InventoryView}
*/
@Nullable InventoryView openInventory(@NotNull Player player, @NotNull ISpecialInventory inventory, boolean viewOnly);
@Nullable InventoryView openInventory(Player player, ISpecialInventory inventory, boolean viewOnly);

/**
* Check if a {@link Player} is currently loaded by OpenInv.
Expand All @@ -161,7 +162,7 @@ public interface IOpenInv {
* @return whether the {@code Player} is loaded
* @since 4.2.0
*/
boolean isPlayerLoaded(@NotNull UUID playerUuid);
boolean isPlayerLoaded(UUID playerUuid);

/**
* Load a {@link Player} from an {@link OfflinePlayer}. If the user has not played before or the default world for
Expand All @@ -171,7 +172,7 @@ public interface IOpenInv {
* @return the loaded {@code Player}
* @throws IllegalStateException if the server version is unsupported
*/
@Nullable Player loadPlayer(@NotNull final OfflinePlayer offline);
@Nullable Player loadPlayer(final OfflinePlayer offline);

/**
* Match an existing {@link OfflinePlayer}. If the name is a {@link UUID#toString() UUID string}, this will only
Expand All @@ -184,14 +185,14 @@ public interface IOpenInv {
* @param name the string to match
* @return the user with the closest matching name
*/
@Nullable OfflinePlayer matchPlayer(@NotNull String name);
@Nullable OfflinePlayer matchPlayer(String name);

/**
* Forcibly close inventories of and unload any cached data for a user.
*
* @param offline the {@link OfflinePlayer} to unload
*/
void unload(@NotNull OfflinePlayer offline);
void unload(OfflinePlayer offline);

Logger getLogger();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jspecify.annotations.NullMarked;

/**
* Event fired before OpenInv saves a player's data when closing an {@link ISpecialInventory}.
*/
@NullMarked
public class OpenPlayerSaveEvent extends PlayerSaveEvent {

private static final HandlerList HANDLERS = new HandlerList();
Expand All @@ -26,10 +27,11 @@ public class OpenPlayerSaveEvent extends PlayerSaveEvent {
*/
@RestrictedApi(
explanation = "Constructor is not considered part of the API and may be subject to change.",
link = "",
allowedOnPath = ".*/com/lishid/openinv/event/OpenEvents.java"
)
@ApiStatus.Internal
OpenPlayerSaveEvent(@NotNull Player player, @NotNull ISpecialInventory inventory) {
OpenPlayerSaveEvent(Player player, ISpecialInventory inventory) {
super(player);
this.inventory = inventory;
}
Expand All @@ -39,11 +41,10 @@ public class OpenPlayerSaveEvent extends PlayerSaveEvent {
*
* @return the special inventory
*/
public @NotNull ISpecialInventory getInventory() {
public ISpecialInventory getInventory() {
return inventory;
}

@NotNull
@Override
public HandlerList getHandlers() {
return HANDLERS;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
import org.bukkit.event.HandlerList;
import org.bukkit.event.player.PlayerEvent;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jspecify.annotations.NullMarked;

/**
* Event fired before a {@link Player} loaded via OpenInv is saved.
*/
@NullMarked
public class PlayerSaveEvent extends PlayerEvent implements Cancellable {

private static final HandlerList HANDLERS = new HandlerList();
Expand All @@ -27,10 +28,11 @@ public class PlayerSaveEvent extends PlayerEvent implements Cancellable {
*/
@RestrictedApi(
explanation = "Constructor is not considered part of the API and may be subject to change.",
link = "",
allowedOnPath = ".*/com/lishid/openinv/event/(OpenPlayerSaveEvent|OpenEvents).java"
)
@ApiStatus.Internal
PlayerSaveEvent(@NotNull Player player) {
PlayerSaveEvent(Player player) {
super(player);
}

Expand All @@ -54,7 +56,6 @@ public void setCancelled(boolean cancel) {
this.cancelled = cancel;
}

@NotNull
@Override
public HandlerList getHandlers() {
return HANDLERS;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,29 @@
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jspecify.annotations.NullMarked;

import java.util.UUID;

/**
* Event fired after OpenInv modifies a toggleable setting for a player.
*/
@NullMarked
public class PlayerToggledEvent extends Event {

private static final HandlerList HANDLERS = new HandlerList();

private final @NotNull PlayerToggle toggle;
private final @NotNull UUID uuid;
private final PlayerToggle toggle;
private final UUID uuid;
private final boolean enabled;

@RestrictedApi(
explanation = "Constructor is not considered part of the API and may be subject to change.",
link = "",
allowedOnPath = ".*/com/lishid/openinv/event/OpenEvents.java"
)
@ApiStatus.Internal
PlayerToggledEvent(@NotNull PlayerToggle toggle, @NotNull UUID uuid, boolean enabled) {
PlayerToggledEvent(PlayerToggle toggle, UUID uuid, boolean enabled) {
this.toggle = toggle;
this.uuid = uuid;
this.enabled = enabled;
Expand All @@ -36,7 +38,7 @@ public class PlayerToggledEvent extends Event {
*
* @return the toggle
*/
public @NotNull PlayerToggle getToggle() {
public PlayerToggle getToggle() {
return toggle;
}

Expand All @@ -45,7 +47,7 @@ public class PlayerToggledEvent extends Event {
*
* @return the player ID
*/
public @NotNull UUID getPlayerId() {
public UUID getPlayerId() {
return uuid;
}

Expand All @@ -58,7 +60,6 @@ public boolean isEnabled() {
return enabled;
}

@NotNull
@Override
public HandlerList getHandlers() {
return HANDLERS;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.util.BoundingBox;
import org.jetbrains.annotations.NotNull;
import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.Nullable;

@NullMarked
public interface IAnySilentContainer {

/**
Expand All @@ -39,30 +41,30 @@ public interface IAnySilentContainer {
* @param block the {@link Block} of the container
* @return true if the container can be opened
*/
boolean activateContainer(@NotNull Player player, boolean silent, @NotNull Block block);
boolean activateContainer(Player player, boolean silent, Block block);

/**
* Perform operations required to close the current container silently.
*
* @param player the {@link Player} closing a container
*/
void deactivateContainer(@NotNull Player player);
void deactivateContainer(Player player);

/**
* Check if the container at the given coordinates is blocked.
*
* @param block the {@link Block} of the container
* @return true if the container is blocked
*/
boolean isAnyContainerNeeded(@NotNull Block block);
boolean isAnyContainerNeeded(Block block);

/**
* Check if a shulker box block cannot be opened under ordinary circumstances.
*
* @param shulkerBox the shulker box block
* @return whether the container is blocked
*/
default boolean isShulkerBlocked(@NotNull Block shulkerBox) {
default boolean isShulkerBlocked(Block shulkerBox) {
Directional directional = (Directional) shulkerBox.getBlockData();
BlockFace facing = directional.getFacing();
// Construct a new 1-block bounding box at the origin.
Expand All @@ -81,7 +83,7 @@ default boolean isShulkerBlocked(@NotNull Block shulkerBox) {
* @param chest the chest block
* @return whether the container is blocked
*/
default boolean isChestBlocked(@NotNull Block chest) {
default boolean isChestBlocked(Block chest) {
org.bukkit.block.Block relative = chest.getRelative(0, 1, 0);
return relative.getType().isOccluding()
|| !chest.getWorld().getNearbyEntities(BoundingBox.of(relative), Cat.class::isInstance).isEmpty();
Expand All @@ -93,15 +95,15 @@ default boolean isChestBlocked(@NotNull Block chest) {
* @param block the potential container
* @return true if the type is a supported container
*/
boolean isAnySilentContainer(@NotNull Block block);
boolean isAnySilentContainer(Block block);

/**
* Check if the given {@link BlockState} is a container which can be unblocked or silenced.
*
* @param blockState the potential container
* @return true if the type is a supported container
*/
default boolean isAnySilentContainer(@NotNull BlockState blockState) {
default boolean isAnySilentContainer(BlockState blockState) {
return (blockState instanceof InventoryHolder holder && isAnySilentContainer(holder))
|| blockState instanceof EnderChest;
}
Expand All @@ -112,7 +114,7 @@ default boolean isAnySilentContainer(@NotNull BlockState blockState) {
* @param holder the potential container
* @return true if the type is a supported container
*/
default boolean isAnySilentContainer(@NotNull InventoryHolder holder) {
default boolean isAnySilentContainer(@Nullable InventoryHolder holder) {
return holder instanceof org.bukkit.block.EnderChest
|| holder instanceof org.bukkit.block.Chest
|| holder instanceof org.bukkit.block.DoubleChest
Expand All @@ -126,6 +128,6 @@ default boolean isAnySilentContainer(@NotNull InventoryHolder holder) {
* @param inventory the potential container inventory
* @return true if the type is a supported container
*/
boolean isAnySilentContainer(@NotNull Inventory inventory);
boolean isAnySilentContainer(Inventory inventory);

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,16 @@
package com.lishid.openinv.internal;

import org.bukkit.event.inventory.InventoryType;
import org.jetbrains.annotations.NotNull;
import org.jspecify.annotations.NullMarked;

/**
* An {@link ISpecialInventory} representing an ender chest.
*/
@NullMarked
public interface ISpecialEnderChest extends ISpecialInventory {

@Override
default @NotNull InventoryType getBukkitType() {
default InventoryType getBukkitType() {
return InventoryType.ENDER_CHEST;
}

Expand Down
Loading
Loading