Made captivity reactive
This commit is contained in:
@@ -128,6 +128,13 @@ public interface Menu {
|
||||
*/
|
||||
Map<String, Object> getState(@NotNull Player player);
|
||||
|
||||
/**
|
||||
* Re-render the menu for a player.
|
||||
*
|
||||
* @param player The player.
|
||||
*/
|
||||
void refresh(@NotNull Player player);
|
||||
|
||||
/**
|
||||
* Write data.
|
||||
*
|
||||
@@ -171,13 +178,6 @@ public interface Menu {
|
||||
@Deprecated(since = "6.35.0", forRemoval = true)
|
||||
Set<NamespacedKey> getKeys(@NotNull Player player);
|
||||
|
||||
/**
|
||||
* Re-render the menu for a player.
|
||||
*
|
||||
* @param player The player.
|
||||
*/
|
||||
void refresh(@NotNull Player player);
|
||||
|
||||
/**
|
||||
* Create a builder with a given amount of rows.
|
||||
*
|
||||
|
||||
@@ -40,21 +40,13 @@ public abstract class CustomSlot implements Slot {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCaptive() {
|
||||
public boolean isCaptive(@NotNull final Player player,
|
||||
@NotNull final Menu menu) {
|
||||
if (delegate == null) {
|
||||
throw new IllegalStateException("Custom Slot was not initialized!");
|
||||
}
|
||||
|
||||
return delegate.isCaptive();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNotCaptiveFor(@NotNull final Player player) {
|
||||
if (delegate == null) {
|
||||
throw new IllegalStateException("Custom Slot was not initialized!");
|
||||
}
|
||||
|
||||
return delegate.isNotCaptiveFor(player);
|
||||
return delegate.isCaptive(player, menu);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -66,19 +58,6 @@ public abstract class CustomSlot implements Slot {
|
||||
return delegate.isCaptiveFromEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the delegate slot.
|
||||
* <p>
|
||||
* This is not required to add the slot to a menu, but is instead used internally.
|
||||
*
|
||||
* @return The slot.
|
||||
* @deprecated Replaced with {@link Slot#getActionableSlot(Player, Menu)}
|
||||
*/
|
||||
@Deprecated(since = "6.43.0", forRemoval = true)
|
||||
public Slot getDelegate() {
|
||||
return this.delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Slot getActionableSlot(@NotNull final Player player,
|
||||
@NotNull final Menu menu) {
|
||||
@@ -99,4 +78,17 @@ public abstract class CustomSlot implements Slot {
|
||||
public final Slot getSlotAt(int row, int column) {
|
||||
return Slot.super.getSlotAt(row, column);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the delegate slot.
|
||||
* <p>
|
||||
* This is not required to add the slot to a menu, but is instead used internally.
|
||||
*
|
||||
* @return The slot.
|
||||
* @deprecated Replaced with {@link Slot#getActionableSlot(Player, Menu)}
|
||||
*/
|
||||
@Deprecated(since = "6.43.0", forRemoval = true)
|
||||
public Slot getDelegate() {
|
||||
return this.delegate;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,8 +34,9 @@ public abstract class ReactiveSlot implements Slot {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCaptive() {
|
||||
return false;
|
||||
public boolean isCaptive(@NotNull final Player player,
|
||||
@NotNull final Menu menu) {
|
||||
return getSlot(player, menu).isCaptive(player, menu);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -30,9 +30,14 @@ public interface Slot extends GUIComponent {
|
||||
/**
|
||||
* If the slot is captive. (Can items be placed in it).
|
||||
*
|
||||
* @param player The player.
|
||||
* @param menu The menu.
|
||||
* @return If captive.
|
||||
*/
|
||||
boolean isCaptive();
|
||||
default boolean isCaptive(@NotNull final Player player,
|
||||
@NotNull final Menu menu) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the actionable slot to be shown.
|
||||
@@ -43,22 +48,16 @@ public interface Slot extends GUIComponent {
|
||||
* <p>
|
||||
* **Never** return {@code this} from this method. Always make sure that your
|
||||
* slots eventually delegate to a slot created by {@link Slot#builder()}.
|
||||
* <p>
|
||||
* {@code this} is returned by default for backwards-compatibility.
|
||||
*
|
||||
* @param player The player.
|
||||
* @param menu The menu.
|
||||
* @return The slot.
|
||||
*/
|
||||
Slot getActionableSlot(@NotNull final Player player,
|
||||
@NotNull final Menu menu);
|
||||
|
||||
/**
|
||||
* If the slot is not captive for a player.
|
||||
*
|
||||
* @param player The player.
|
||||
* @return If not captive for the player.
|
||||
*/
|
||||
default boolean isNotCaptiveFor(@NotNull Player player) {
|
||||
return false;
|
||||
default Slot getActionableSlot(@NotNull final Player player,
|
||||
@NotNull final Menu menu) {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -135,4 +134,27 @@ public interface Slot extends GUIComponent {
|
||||
static SlotBuilder builder(@NotNull final SlotProvider provider) {
|
||||
return Eco.getHandler().getGUIFactory().createSlotBuilder(provider);
|
||||
}
|
||||
|
||||
/**
|
||||
* If the slot is not captive for a player.
|
||||
*
|
||||
* @param player The player.
|
||||
* @return If not captive for the player.
|
||||
* @deprecated Captivity is now reactive, this method can produce incorrect results.
|
||||
*/
|
||||
@Deprecated(since = "6.43.0", forRemoval = true)
|
||||
default boolean isNotCaptiveFor(@NotNull Player player) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* If the slot is captive. (Can items be placed in it).
|
||||
*
|
||||
* @return If captive.
|
||||
* @deprecated Captivity is now reactive, this method can produce incorrect results.
|
||||
*/
|
||||
@Deprecated(since = "6.43.0", forRemoval = true)
|
||||
default boolean isCaptive() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -145,21 +145,6 @@ public interface SlotBuilder {
|
||||
*/
|
||||
SlotBuilder notCaptiveFor(@NotNull Predicate<Player> predicate);
|
||||
|
||||
/**
|
||||
* Modify the ItemStack.
|
||||
*
|
||||
* @param modifier The modifier.
|
||||
* @return The builder.
|
||||
* @deprecated Use {@link SlotBuilder#setUpdater(SlotUpdater)} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
default SlotBuilder setModifier(@NotNull SlotModifier modifier) {
|
||||
return setUpdater((player, menu, previous) -> {
|
||||
modifier.modify(player, menu, previous);
|
||||
return previous;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the ItemStack updater.
|
||||
*
|
||||
@@ -191,4 +176,19 @@ public interface SlotBuilder {
|
||||
* @return The slot.
|
||||
*/
|
||||
Slot build();
|
||||
|
||||
/**
|
||||
* Modify the ItemStack.
|
||||
*
|
||||
* @param modifier The modifier.
|
||||
* @return The builder.
|
||||
* @deprecated Use {@link SlotBuilder#setUpdater(SlotUpdater)} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
default SlotBuilder setModifier(@NotNull SlotModifier modifier) {
|
||||
return setUpdater((player, menu, previous) -> {
|
||||
modifier.modify(player, menu, previous);
|
||||
return previous;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user