Fixed captive slot changes PR
This commit is contained in:
@@ -42,23 +42,13 @@ public abstract class CustomSlot implements Slot {
|
||||
|
||||
@Override
|
||||
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(player, menu);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCaptiveForItem(@NotNull final Player player,
|
||||
@NotNull final Menu menu,
|
||||
@Nullable final ItemStack item) {
|
||||
if (delegate == null) {
|
||||
throw new IllegalStateException("Custom Slot was not initialized!");
|
||||
}
|
||||
|
||||
return delegate.isCaptiveForItem(player, menu, item);
|
||||
return delegate.isCaptive(player, menu, item);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -71,8 +61,8 @@ public abstract class CustomSlot implements Slot {
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Slot getActionableSlot(@NotNull final Player player,
|
||||
@NotNull final Menu menu) {
|
||||
public final @NotNull Slot getActionableSlot(@NotNull final Player player,
|
||||
@NotNull final Menu menu) {
|
||||
return delegate;
|
||||
}
|
||||
|
||||
|
||||
@@ -36,15 +36,9 @@ public abstract class ReactiveSlot implements Slot {
|
||||
|
||||
@Override
|
||||
public boolean isCaptive(@NotNull final Player player,
|
||||
@NotNull final Menu menu) {
|
||||
return getSlot(player, menu).isCaptive(player, menu);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCaptiveForItem(@NotNull final Player player,
|
||||
@NotNull final Menu menu,
|
||||
@Nullable final ItemStack item) {
|
||||
return getSlot(player, menu).isCaptiveForItem(player, menu, item);
|
||||
return getSlot(player, menu).isCaptive(player, menu, item);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -47,17 +47,18 @@ public interface Slot extends GUIComponent {
|
||||
}
|
||||
|
||||
/**
|
||||
* If the slot is captive for this item. (Can this item be placed in it).
|
||||
* If the slot is captive for a given item (can this item be placed in it).
|
||||
*
|
||||
* @param player The player.
|
||||
* @param menu The menu.
|
||||
* @param player The player.
|
||||
* @param menu The menu.
|
||||
* @param itemStack The item.
|
||||
* @return If captive.
|
||||
*/
|
||||
default boolean isCaptiveForItem(@NotNull final Player player,
|
||||
default boolean isCaptive(@NotNull final Player player,
|
||||
@NotNull final Menu menu,
|
||||
@Nullable final ItemStack itemStack) {
|
||||
return false;
|
||||
// Delegate to no-item version for backwards compatibility.
|
||||
return this.isCaptive(player, menu);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -146,15 +146,19 @@ public interface SlotBuilder {
|
||||
* @param predicate The predicate. Returns true when the slot should not be captive.
|
||||
* @return The builder.
|
||||
*/
|
||||
SlotBuilder notCaptiveFor(Predicate<Player> predicate);
|
||||
default SlotBuilder notCaptiveFor(@NotNull final Predicate<Player> predicate) {
|
||||
return this.notCaptiveFor((player, itemStack) -> predicate.test(player));
|
||||
}
|
||||
|
||||
/**
|
||||
* Prevent captive for players that match a predicate.
|
||||
* Prevent captive for players and items that match a predicate.
|
||||
*
|
||||
* @param predicate The predicate. Returns true when the slot should not be captive.
|
||||
* @return The builder.
|
||||
*/
|
||||
SlotBuilder notCaptiveForItem(BiPredicate<Player, @Nullable ItemStack> predicate);
|
||||
default SlotBuilder notCaptiveFor(@NotNull BiPredicate<Player, @Nullable ItemStack> predicate) {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the ItemStack updater.
|
||||
|
||||
@@ -72,11 +72,11 @@ fun SlotBuilder.onClick(clickType: ClickType, action: (Player, InventoryClickEve
|
||||
|
||||
/** @see SlotBuilder.notCaptiveFor */
|
||||
fun SlotBuilder.notCaptiveFor(test: (Player) -> Boolean): SlotBuilder =
|
||||
this.notCaptiveFor { test(it) }
|
||||
this.notCaptiveFor { t, _ -> test(t) }
|
||||
|
||||
/** @see SlotBuilder.notCaptiveFor */
|
||||
fun SlotBuilder.notCaptiveForItem(test: (Player, ItemStack?) -> Boolean): SlotBuilder =
|
||||
this.notCaptiveForItem { player, item -> test(player, item) }
|
||||
fun SlotBuilder.notCaptiveFor(test: (Player, ItemStack?) -> Boolean): SlotBuilder =
|
||||
this.notCaptiveFor { player, item -> test(player, item) }
|
||||
|
||||
/**
|
||||
* @see SlotBuilder.setModifier
|
||||
|
||||
Reference in New Issue
Block a user