|
| 1 | +package fr.maxlego08.menu.api.utils; |
| 2 | + |
| 3 | +import fr.maxlego08.menu.api.interfaces.TriConsumer; |
| 4 | +import fr.maxlego08.menu.api.players.inventory.InventoriesPlayer; |
| 5 | +import org.bukkit.Material; |
| 6 | +import org.bukkit.entity.Player; |
| 7 | +import org.bukkit.inventory.ItemStack; |
| 8 | +import org.bukkit.inventory.PlayerInventory; |
| 9 | + |
| 10 | +import java.util.function.BiConsumer; |
| 11 | + |
| 12 | +public enum ClearInvType { |
| 13 | + DEFAULT(InventoriesPlayer::giveInventory,(player, slot) -> player.getInventory().setItem(slot, new ItemStack(Material.AIR)),(player, slot, playerInventory) -> playerInventory.clear(slot)), |
| 14 | + PACKET_EVENT("packetevents") |
| 15 | + ; |
| 16 | + |
| 17 | + private BiConsumer<InventoriesPlayer, Player> onInventoryClose; |
| 18 | + private BiConsumer<Player,Integer > onButtonClear; |
| 19 | + private TriConsumer<Player, Integer, PlayerInventory> removeItem; |
| 20 | + private final String requiredPlugin; |
| 21 | + |
| 22 | + ClearInvType(String requiredPlugin) { |
| 23 | + this.requiredPlugin = requiredPlugin; |
| 24 | + this.onInventoryClose = (inventoriesPlayer, player) -> { |
| 25 | + // No action |
| 26 | + }; |
| 27 | + this.onButtonClear = (slot, player) -> { |
| 28 | + // No action |
| 29 | + }; |
| 30 | + this.removeItem = (player, slot, playerInventory) -> { |
| 31 | + // No action |
| 32 | + }; |
| 33 | + } |
| 34 | + |
| 35 | + ClearInvType(BiConsumer<InventoriesPlayer, Player> onInventoryClose, BiConsumer<Player, Integer> onButtonClear, TriConsumer<Player, Integer, PlayerInventory> removeItem) { |
| 36 | + this.onInventoryClose = onInventoryClose; |
| 37 | + this.onButtonClear = onButtonClear; |
| 38 | + this.removeItem = removeItem; |
| 39 | + this.requiredPlugin = null; |
| 40 | + } |
| 41 | + |
| 42 | + public BiConsumer<InventoriesPlayer, Player> getOnInventoryClose() { |
| 43 | + return this.onInventoryClose; |
| 44 | + } |
| 45 | + |
| 46 | + public void setOnInventoryClose(BiConsumer<InventoriesPlayer, Player> onInventoryClose) { |
| 47 | + this.onInventoryClose = onInventoryClose; |
| 48 | + } |
| 49 | + |
| 50 | + public BiConsumer<Player, Integer> getOnButtonClear() { |
| 51 | + return this.onButtonClear; |
| 52 | + } |
| 53 | + |
| 54 | + public void setOnButtonClear(BiConsumer<Player, Integer> onButtonClear) { |
| 55 | + this.onButtonClear = onButtonClear; |
| 56 | + } |
| 57 | + |
| 58 | + public TriConsumer<Player, Integer, PlayerInventory> getRemoveItem() { |
| 59 | + return this.removeItem; |
| 60 | + } |
| 61 | + |
| 62 | + public void setRemoveItem(TriConsumer<Player, Integer, PlayerInventory> removeItem) { |
| 63 | + this.removeItem = removeItem; |
| 64 | + } |
| 65 | + |
| 66 | + public String getRequiredPlugin() { |
| 67 | + return this.requiredPlugin; |
| 68 | + } |
| 69 | + |
| 70 | + public boolean hasRequiredPlugin() { |
| 71 | + return this.requiredPlugin != null && !this.requiredPlugin.isEmpty(); |
| 72 | + } |
| 73 | +} |
0 commit comments