diff --git a/eco-api/src/main/java/com/willfp/eco/core/gui/slot/CustomSlot.java b/eco-api/src/main/java/com/willfp/eco/core/gui/slot/CustomSlot.java index 00a1d6bf..1cb53038 100644 --- a/eco-api/src/main/java/com/willfp/eco/core/gui/slot/CustomSlot.java +++ b/eco-api/src/main/java/com/willfp/eco/core/gui/slot/CustomSlot.java @@ -51,14 +51,14 @@ public abstract class CustomSlot implements Slot { } @Override - public final boolean canCaptivateItem(@NotNull final Player player, + public final boolean isAllowedCaptive(@NotNull final Player player, @NotNull final Menu menu, @Nullable final ItemStack itemStack) { if (delegate == null) { throw new IllegalStateException("Custom Slot was not initialized!"); } - return delegate.canCaptivateItem(player, menu, itemStack); + return delegate.isAllowedCaptive(player, menu, itemStack); } @Override diff --git a/eco-api/src/main/java/com/willfp/eco/core/gui/slot/ReactiveSlot.java b/eco-api/src/main/java/com/willfp/eco/core/gui/slot/ReactiveSlot.java index f4321817..fa86a857 100644 --- a/eco-api/src/main/java/com/willfp/eco/core/gui/slot/ReactiveSlot.java +++ b/eco-api/src/main/java/com/willfp/eco/core/gui/slot/ReactiveSlot.java @@ -41,10 +41,10 @@ public abstract class ReactiveSlot implements Slot { } @Override - public final boolean canCaptivateItem(@NotNull final Player player, - @NotNull final Menu menu, - @Nullable final ItemStack itemStack) { - return getSlot(player, menu).canCaptivateItem(player, menu, itemStack); + public final boolean isAllowedCaptive(@NotNull final Player player, + @NotNull final Menu menu, + @Nullable final ItemStack itemStack) { + return getSlot(player, menu).isAllowedCaptive(player, menu, itemStack); } @Override diff --git a/eco-api/src/main/java/com/willfp/eco/core/gui/slot/Slot.java b/eco-api/src/main/java/com/willfp/eco/core/gui/slot/Slot.java index a9b2f4ba..34f25678 100644 --- a/eco-api/src/main/java/com/willfp/eco/core/gui/slot/Slot.java +++ b/eco-api/src/main/java/com/willfp/eco/core/gui/slot/Slot.java @@ -47,14 +47,14 @@ public interface Slot extends GUIComponent { } /** - * If the slot is captive for a given item (can this item be placed in it). + * If the slot allows a certain item to be placed in it. * * @param player The player. * @param menu The menu. * @param itemStack The item; use null if the item is unknown. * @return If captive. */ - default boolean canCaptivateItem(@NotNull final Player player, + default boolean isAllowedCaptive(@NotNull final Player player, @NotNull final Menu menu, @Nullable final ItemStack itemStack) { return true; diff --git a/eco-api/src/main/java/com/willfp/eco/core/gui/slot/SlotBuilder.java b/eco-api/src/main/java/com/willfp/eco/core/gui/slot/SlotBuilder.java index 1e86e7a2..fef7cc10 100644 --- a/eco-api/src/main/java/com/willfp/eco/core/gui/slot/SlotBuilder.java +++ b/eco-api/src/main/java/com/willfp/eco/core/gui/slot/SlotBuilder.java @@ -1,6 +1,6 @@ package com.willfp.eco.core.gui.slot; -import com.willfp.eco.core.gui.slot.functional.CaptiveCondition; +import com.willfp.eco.core.gui.slot.functional.CaptiveFilter; import com.willfp.eco.core.gui.slot.functional.SlotHandler; import com.willfp.eco.core.gui.slot.functional.SlotModifier; import com.willfp.eco.core.gui.slot.functional.SlotUpdater; @@ -149,10 +149,10 @@ public interface SlotBuilder { /** * Set a whitelist for allowed captive items. * - * @param condition The condition. Returns true when the slot should be captive. + * @param filter The filter. * @return The builder. */ - default SlotBuilder setCaptiveCondition(@NotNull final CaptiveCondition condition) { + default SlotBuilder setCaptiveFilter(@NotNull final CaptiveFilter filter) { return this; } diff --git a/eco-api/src/main/java/com/willfp/eco/core/gui/slot/functional/CaptiveCondition.java b/eco-api/src/main/java/com/willfp/eco/core/gui/slot/functional/CaptiveFilter.java similarity index 72% rename from eco-api/src/main/java/com/willfp/eco/core/gui/slot/functional/CaptiveCondition.java rename to eco-api/src/main/java/com/willfp/eco/core/gui/slot/functional/CaptiveFilter.java index df4f4761..24a6cd1c 100644 --- a/eco-api/src/main/java/com/willfp/eco/core/gui/slot/functional/CaptiveCondition.java +++ b/eco-api/src/main/java/com/willfp/eco/core/gui/slot/functional/CaptiveFilter.java @@ -7,19 +7,19 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; /** - * Interface to test if a captive slot is captive given a player, menu, and item. + * Interface to test if a captive slot is allowed to contain an item given a player and a menu. */ @FunctionalInterface -public interface CaptiveCondition { +public interface CaptiveFilter { /** - * Get if the slot is captive. + * Get if allowed. * * @param player The player. * @param menu The menu. * @param itemStack The item. * @return If captive. */ - boolean isCaptive(@NotNull Player player, + boolean isAllowed(@NotNull Player player, @NotNull Menu menu, @Nullable ItemStack itemStack); } diff --git a/eco-api/src/main/kotlin/com/willfp/eco/core/gui/GUIHelpers.kt b/eco-api/src/main/kotlin/com/willfp/eco/core/gui/GUIHelpers.kt index a90f352e..1d3acf6c 100644 --- a/eco-api/src/main/kotlin/com/willfp/eco/core/gui/GUIHelpers.kt +++ b/eco-api/src/main/kotlin/com/willfp/eco/core/gui/GUIHelpers.kt @@ -74,9 +74,9 @@ fun SlotBuilder.onClick(clickType: ClickType, action: (Player, InventoryClickEve fun SlotBuilder.notCaptiveFor(test: (Player) -> Boolean): SlotBuilder = this.notCaptiveFor { test(it) } -/** @see SlotBuilder.setCaptiveCondition */ -fun SlotBuilder.setCaptiveCondition(test: (Player, Menu, ItemStack?) -> Boolean): SlotBuilder = - this.setCaptiveCondition { a, b, c -> test(a, b, c) } +/** @see SlotBuilder.setCaptiveFilter */ +fun SlotBuilder.setCaptiveFilter(test: (Player, Menu, ItemStack?) -> Boolean): SlotBuilder = + this.setCaptiveFilter { a, b, c -> test(a, b, c) } /** * @see SlotBuilder.setModifier diff --git a/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/gui/slot/EcoCaptiveSlot.kt b/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/gui/slot/EcoCaptiveSlot.kt index c2f83eff..d25b4ce3 100644 --- a/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/gui/slot/EcoCaptiveSlot.kt +++ b/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/gui/slot/EcoCaptiveSlot.kt @@ -1,7 +1,7 @@ package com.willfp.eco.internal.gui.slot import com.willfp.eco.core.gui.menu.Menu -import com.willfp.eco.core.gui.slot.functional.CaptiveCondition +import com.willfp.eco.core.gui.slot.functional.CaptiveFilter import com.willfp.eco.core.gui.slot.functional.SlotHandler import com.willfp.eco.core.gui.slot.functional.SlotProvider import com.willfp.eco.util.toSingletonList @@ -13,11 +13,11 @@ class EcoCaptiveSlot( provider: SlotProvider, private val captiveFromEmpty: Boolean, private val notCaptiveFor: (Player) -> Boolean, - private val condition: CaptiveCondition + private val filter: CaptiveFilter ) : EcoSlot( provider, ClickType.values().associateWith { - captiveWithTest(notCaptiveFor, condition).toSingletonList() + captiveWithTest(notCaptiveFor, filter).toSingletonList() }, { _, _, prev -> prev } ) { @@ -25,8 +25,8 @@ class EcoCaptiveSlot( return !notCaptiveFor(player) } - override fun canCaptivateItem(player: Player, menu: Menu, itemStack: ItemStack?): Boolean { - return condition.isCaptive(player, menu, itemStack) + override fun isAllowedCaptive(player: Player, menu: Menu, itemStack: ItemStack?): Boolean { + return filter.isAllowed(player, menu, itemStack) } override fun isCaptiveFromEmpty(): Boolean { @@ -36,12 +36,12 @@ class EcoCaptiveSlot( private fun captiveWithTest( playerTest: (Player) -> Boolean, - condition: CaptiveCondition + filter: CaptiveFilter ): SlotHandler = SlotHandler { event, _, menu -> val player = event.whoClicked as Player val allowedForPlayer = !playerTest(player) - val allowedForCondition = condition.isCaptive(player, menu, event.currentItem) + val allowedForCondition = filter.isAllowed(player, menu, event.currentItem) event.isCancelled = !(allowedForCondition && allowedForPlayer) } diff --git a/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/gui/slot/EcoSlotBuilder.kt b/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/gui/slot/EcoSlotBuilder.kt index 7703147a..c8668296 100644 --- a/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/gui/slot/EcoSlotBuilder.kt +++ b/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/gui/slot/EcoSlotBuilder.kt @@ -2,7 +2,7 @@ package com.willfp.eco.internal.gui.slot import com.willfp.eco.core.gui.slot.Slot import com.willfp.eco.core.gui.slot.SlotBuilder -import com.willfp.eco.core.gui.slot.functional.CaptiveCondition +import com.willfp.eco.core.gui.slot.functional.CaptiveFilter import com.willfp.eco.core.gui.slot.functional.SlotHandler import com.willfp.eco.core.gui.slot.functional.SlotProvider import com.willfp.eco.core.gui.slot.functional.SlotUpdater @@ -17,7 +17,8 @@ class EcoSlotBuilder(private val provider: SlotProvider) : SlotBuilder { private val handlers = mutableMapOf>() - private var captiveCondition = CaptiveCondition { _, _, _ -> true } + private var captiveFilter = + CaptiveFilter { _, _, _ -> true } private var notCaptiveFor: (Player) -> Boolean = { _ -> false} override fun onClick(type: ClickType, action: SlotHandler): SlotBuilder { @@ -30,8 +31,8 @@ class EcoSlotBuilder(private val provider: SlotProvider) : SlotBuilder { return this } - override fun setCaptiveCondition(condition: CaptiveCondition): SlotBuilder { - captiveCondition = condition + override fun setCaptiveFilter(filter: CaptiveFilter): SlotBuilder { + captiveFilter = filter return this } @@ -52,7 +53,7 @@ class EcoSlotBuilder(private val provider: SlotProvider) : SlotBuilder { provider, captiveFromEmpty, notCaptiveFor, - captiveCondition + captiveFilter ) } else { EcoSlot( diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/gui/GUIListener.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/gui/GUIListener.kt index 62b23f29..93a0122d 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/gui/GUIListener.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/gui/GUIListener.kt @@ -95,7 +95,7 @@ class GUIListener(private val plugin: EcoPlugin) : Listener { val slot = menu.getSlot(row, column, player) - if (!slot.isCaptive(player, menu) && slot.canCaptivateItem(player, menu, event.currentItem)) { + if (!slot.isCaptive(player, menu) && slot.isAllowedCaptive(player, menu, event.currentItem)) { event.isCancelled = true } } diff --git a/gradle.properties b/gradle.properties index f9733eeb..fa723f55 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,3 @@ -version = 6.46.1 +version = 6.47.0 plugin-name = eco kotlin.code.style = official \ No newline at end of file