From f878efab32e599341da70b4f01299ecf05decd88 Mon Sep 17 00:00:00 2001 From: MoBrot <90271578+MoBrot@users.noreply.github.com> Date: Sun, 4 Sep 2022 21:16:57 +0200 Subject: [PATCH] +Add InventoryFillBauGuiItem +Add OTHER_ITEMS_INVENTORY_FILL_NAME in BauSystem.properties --- BauSystem_Main/src/BauSystem.properties | 1 + .../inventoryfiller/InventoryFiller.java | 2 - .../InventoryFillerCommand.java | 7 ++-- .../util/items/InventoryFillBauGuiItem.java | 40 +++++++++++++++++++ 4 files changed, 44 insertions(+), 6 deletions(-) create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/util/items/InventoryFillBauGuiItem.java diff --git a/BauSystem_Main/src/BauSystem.properties b/BauSystem_Main/src/BauSystem.properties index c878ab57..0ccb5281 100644 --- a/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem_Main/src/BauSystem.properties @@ -885,6 +885,7 @@ OTHER_ITEMS_GAMEMODE_LORE_2=§eLeft-Click§8:§7 Toggle between survival and adv OTHER_ITEMS_KILLALL_NAME=§eKillAll OTHER_ITEMS_KILLALL_LORE_1=§eWithout Shift§8:§7 only this region OTHER_ITEMS_KILLALL_LORE_2=§eWith Shift§8:§7 global +OTHER_ITEMS_INVENTORY_FILL_NAME=§eInventoryFill OTHER_SLOT_INVALID_SLOT=§cInvalid slot OTHER_NOCLIP_SLOT_INFO=§7With /slot you can change the selected slot and take another block in the slot. OTHER_NOCLIP_SLOT_HELP_PICK = §8/§eslot pick §8-§7 Take the faced block into your inventory. diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/inventoryfiller/InventoryFiller.java b/BauSystem_Main/src/de/steamwar/bausystem/features/inventoryfiller/InventoryFiller.java index 068aaf2d..dd7c1b01 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/inventoryfiller/InventoryFiller.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/inventoryfiller/InventoryFiller.java @@ -39,7 +39,6 @@ public class InventoryFiller implements Listener { @EventHandler public void onPlayerDropItem(PlayerDropItemEvent event) { - if (!Config.getInstance().get(event.getPlayer()).getPlainValueOrDefault("inventoryfill", false)) return; if (!event.getPlayer().isSneaking()) return; Block block = event.getPlayer().getTargetBlockExact(5); @@ -61,7 +60,6 @@ public class InventoryFiller implements Listener { */ @EventHandler public void onPlayerItemHeld(PlayerItemHeldEvent event) { - if (!Config.getInstance().get(event.getPlayer()).getPlainValueOrDefault("inventoryfill", false)) return; if (!event.getPlayer().isSneaking()) return; ItemStack itemStack = event.getPlayer().getInventory().getItemInMainHand(); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/inventoryfiller/InventoryFillerCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/inventoryfiller/InventoryFillerCommand.java index 1c13d8b5..8ef0d841 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/inventoryfiller/InventoryFillerCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/inventoryfiller/InventoryFillerCommand.java @@ -17,14 +17,13 @@ public class InventoryFillerCommand extends SWCommand { @Register(description = {"INVENTORY_FILL_HELP", "INVENTORY_FILL_INFO"}) public void toggle(Player player) { - boolean inventoryFill = Config.getInstance().get(player).getPlainValueOrDefault("inventoryfill", false); Config.getInstance().get(player).put("inventoryfill", !inventoryFill); - - if(!inventoryFill) { + if (!inventoryFill) { SWUtils.sendToActionbar(player, BauSystem.MESSAGE.parse("INVENTORY_FILL_ENABLE", player)); BauSystem.MESSAGE.send("INVENTORY_FILL_INFO", player); - }else + }else { SWUtils.sendToActionbar(player, BauSystem.MESSAGE.parse("INVENTORY_FILL_DISABLE", player)); + } } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/util/items/InventoryFillBauGuiItem.java b/BauSystem_Main/src/de/steamwar/bausystem/features/util/items/InventoryFillBauGuiItem.java new file mode 100644 index 00000000..c09468b1 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/util/items/InventoryFillBauGuiItem.java @@ -0,0 +1,40 @@ +package de.steamwar.bausystem.features.util.items; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.Permission; +import de.steamwar.bausystem.features.inventoryfiller.InventoryFillerCommand; +import de.steamwar.bausystem.linkage.LinkageType; +import de.steamwar.bausystem.linkage.Linked; +import de.steamwar.bausystem.linkage.LinkedInstance; +import de.steamwar.bausystem.linkage.specific.BauGuiItem; +import de.steamwar.inventory.SWItem; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; +import org.bukkit.inventory.ItemStack; + +@Linked(LinkageType.BAU_GUI_ITEM) +public class InventoryFillBauGuiItem extends BauGuiItem { + public InventoryFillBauGuiItem() { + super(34); + } + + @LinkedInstance + public InventoryFillerCommand command; + + @Override + public Permission permission() { + return Permission.MEMBER; + } + + @Override + public ItemStack getItem(Player player) { + return new SWItem(Material.BARREL, BauSystem.MESSAGE.parse("OTHER_ITEMS_INVENTORY_FILL_NAME", player), null, false, clickType -> {}).getItemStack(); + } + + @Override + public boolean click(ClickType click, Player p) { + command.toggle(p); + return false; + } +}