@@ -2,12 +2,10 @@ package com.willfp.eco.core.gui.slot;
|
||||
|
||||
import com.willfp.eco.core.Eco;
|
||||
import com.willfp.eco.core.gui.slot.functional.SlotProvider;
|
||||
import com.willfp.eco.core.items.TestableItem;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
@@ -30,14 +28,6 @@ public interface Slot {
|
||||
*/
|
||||
boolean isCaptive();
|
||||
|
||||
/**
|
||||
* Get default captive item.
|
||||
*
|
||||
* @param player The player.
|
||||
* @return The item, or null if no captive default was found.
|
||||
*/
|
||||
@Nullable TestableItem getCaptiveDefault(@NotNull Player player);
|
||||
|
||||
/**
|
||||
* Create a builder for an ItemStack.
|
||||
*
|
||||
|
||||
@@ -3,14 +3,10 @@ package com.willfp.eco.core.gui.slot;
|
||||
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;
|
||||
import com.willfp.eco.core.items.TestableItem;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* Builder to create slots.
|
||||
@@ -134,17 +130,7 @@ public interface SlotBuilder {
|
||||
*
|
||||
* @return The builder.
|
||||
*/
|
||||
default SlotBuilder setCaptive() {
|
||||
return setCaptive(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set slot to be a captive default with a default provider.
|
||||
*
|
||||
* @param provider The provider.
|
||||
* @return The builder.
|
||||
*/
|
||||
SlotBuilder setCaptive(@Nullable Function<Player, TestableItem> provider);
|
||||
SlotBuilder setCaptive();
|
||||
|
||||
/**
|
||||
* Build the slot.
|
||||
|
||||
@@ -43,10 +43,7 @@ class MenuRenderedInventory(
|
||||
val renderedItem = slot.getItemStack(player)
|
||||
val itemStack = inventory.getItem(i) ?: continue
|
||||
|
||||
val isCaptiveDefault = (slot.getCaptiveDefault(player)?.matches(itemStack))
|
||||
?: (renderedItem == itemStack)
|
||||
|
||||
if (isCaptiveDefault || itemStack.type.isAir || itemStack.amount == 0) {
|
||||
if (itemStack == renderedItem || itemStack.type.isAir || itemStack.amount == 0) {
|
||||
continue
|
||||
}
|
||||
|
||||
|
||||
@@ -2,12 +2,9 @@ package com.willfp.eco.internal.gui.slot
|
||||
|
||||
import com.willfp.eco.core.gui.slot.functional.SlotHandler
|
||||
import com.willfp.eco.core.gui.slot.functional.SlotProvider
|
||||
import com.willfp.eco.core.items.TestableItem
|
||||
import org.bukkit.entity.Player
|
||||
|
||||
class EcoCaptiveSlot(
|
||||
provider: SlotProvider,
|
||||
private val captiveDefault: ((Player) -> TestableItem?)?
|
||||
provider: SlotProvider
|
||||
) : EcoSlot(
|
||||
provider,
|
||||
allowMovingItem,
|
||||
@@ -20,12 +17,8 @@ class EcoCaptiveSlot(
|
||||
override fun isCaptive(): Boolean {
|
||||
return true
|
||||
}
|
||||
|
||||
override fun getCaptiveDefault(player: Player): TestableItem? {
|
||||
return captiveDefault?.invoke(player)
|
||||
}
|
||||
}
|
||||
|
||||
private val allowMovingItem = SlotHandler { event, _, _ ->
|
||||
event.isCancelled = false
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,6 @@ import com.willfp.eco.core.gui.slot.Slot
|
||||
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
|
||||
import com.willfp.eco.core.items.TestableItem
|
||||
import com.willfp.eco.internal.gui.menu.getMenu
|
||||
import org.bukkit.Material
|
||||
import org.bukkit.entity.Player
|
||||
@@ -56,8 +55,4 @@ open class EcoSlot(
|
||||
override fun isCaptive(): Boolean {
|
||||
return false
|
||||
}
|
||||
|
||||
override fun getCaptiveDefault(player: Player): TestableItem? {
|
||||
return null
|
||||
}
|
||||
}
|
||||
@@ -5,13 +5,9 @@ import com.willfp.eco.core.gui.slot.SlotBuilder
|
||||
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
|
||||
import com.willfp.eco.core.items.TestableItem
|
||||
import org.bukkit.entity.Player
|
||||
import java.util.function.Function
|
||||
|
||||
class EcoSlotBuilder(private val provider: SlotProvider) : SlotBuilder {
|
||||
private var captive = false
|
||||
private var captiveDefault: ((Player) -> TestableItem?)? = null
|
||||
private var updater: SlotUpdater = SlotUpdater { player, menu, _ -> provider.provide(player, menu) }
|
||||
|
||||
private var onLeftClick =
|
||||
@@ -50,11 +46,8 @@ class EcoSlotBuilder(private val provider: SlotProvider) : SlotBuilder {
|
||||
return this
|
||||
}
|
||||
|
||||
override fun setCaptive(provider: Function<Player, TestableItem>?): SlotBuilder {
|
||||
override fun setCaptive(): SlotBuilder {
|
||||
captive = true
|
||||
if (provider != null) {
|
||||
captiveDefault = { provider.apply(it) }
|
||||
}
|
||||
return this
|
||||
}
|
||||
|
||||
@@ -65,7 +58,7 @@ class EcoSlotBuilder(private val provider: SlotProvider) : SlotBuilder {
|
||||
|
||||
override fun build(): Slot {
|
||||
return if (captive) {
|
||||
EcoCaptiveSlot(provider, captiveDefault)
|
||||
EcoCaptiveSlot(provider)
|
||||
} else {
|
||||
EcoSlot(provider, onLeftClick, onRightClick, onShiftLeftClick, onShiftRightClick, onMiddleClick, updater)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user