Fixed captive slot changes PR

This commit is contained in:
Auxilor
2022-11-17 15:10:05 +00:00
parent f05c5f3cd6
commit bcb7401c74
8 changed files with 31 additions and 64 deletions

View File

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

View File

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

View File

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

View File

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

View File

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