From 5e462ae0972d7ef3512b63f98783e7841024b1aa Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Fri, 5 Aug 2022 14:07:41 +0200 Subject: [PATCH] Armor to Hotbar --- .../bausystem/features/hotbar/DefaultHotbar.java | 10 +++++++--- .../bausystem/features/hotbar/HotbarListener.java | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/hotbar/DefaultHotbar.java b/BauSystem_Main/src/de/steamwar/bausystem/features/hotbar/DefaultHotbar.java index e0808857..2625f0da 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/hotbar/DefaultHotbar.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/hotbar/DefaultHotbar.java @@ -33,11 +33,12 @@ import yapion.serializing.YAPIONSerializer; @UtilityClass public class DefaultHotbar { - private final YAPIONArray DEFAULT_HOTBAR = YAPIONParser.parse("{[{@type(org.bukkit.inventory.ItemStack)v(2230)type(WOODEN_AXE)meta{@type(org.bukkit.inventory.meta.ItemMeta)meta-type(UNSPECIFIC)display-name(WorldEdit Wand)lore{@type(java.util.ArrayList)values[Left click: select pos #1,Right click: select pos #2]}}},{@type(org.bukkit.inventory.ItemStack)v(2230)type(COMPASS)meta{@type(org.bukkit.inventory.meta.ItemMeta)meta-type(UNSPECIFIC)display-name(Navigation Wand)lore{@type(java.util.ArrayList)values[Left click: jump to location,Right click: pass through walls]}}},null,null,null,null,null,null,{@type(org.bukkit.inventory.ItemStack)v(2230)type(NETHER_STAR)meta{@type(org.bukkit.inventory.meta.ItemMeta)meta-type(UNSPECIFIC)display-name(§eBau GUI)}}]}").getArray(""); + private final YAPIONArray DEFAULT_HOTBAR = YAPIONParser.parse("{[{@type(org.bukkit.inventory.ItemStack)v(2230)type(WOODEN_AXE)meta{@type(org.bukkit.inventory.meta.ItemMeta)meta-type(UNSPECIFIC)display-name(WorldEdit Wand)lore{@type(java.util.ArrayList)values[Left click: select pos #1,Right click: select pos #2]}}},{@type(org.bukkit.inventory.ItemStack)v(2230)type(COMPASS)meta{@type(org.bukkit.inventory.meta.ItemMeta)meta-type(UNSPECIFIC)display-name(Navigation Wand)lore{@type(java.util.ArrayList)values[Left click: jump to location,Right click: pass through walls]}}},null,null,null,null,null,null,{@type(org.bukkit.inventory.ItemStack)v(2230)type(NETHER_STAR)meta{@type(org.bukkit.inventory.meta.ItemMeta)meta-type(UNSPECIFIC)display-name(§eBau GUI)}},null,null,{@type(org.bukkit.inventory.ItemStack)v(3117)type(ELYTRA)},null]}").getArray(""); public void updateHotbar(Player p) { - ItemStack[] hotbar = new ItemStack[9]; + ItemStack[] hotbar = new ItemStack[13]; System.arraycopy(p.getInventory().getContents(), 0, hotbar, 0, 9); + System.arraycopy(p.getInventory().getArmorContents(), 0, hotbar, 9, 4); YAPIONArray yapionArray = new YAPIONArray(); for (ItemStack itemStack : hotbar) { if (itemStack != null) { @@ -53,13 +54,16 @@ public class DefaultHotbar { public void setHotbar(Player p) { ItemStack[] hotbar = getItems(p); ItemStack[] inv = p.getInventory().getContents(); + ItemStack[] armor = p.getInventory().getArmorContents(); System.arraycopy(hotbar, 0, inv, 0, 9); + System.arraycopy(hotbar, 9, armor, 0, 4); p.getInventory().setContents(inv); + p.getInventory().setArmorContents(armor); } public ItemStack[] getItems(Player p) { YAPIONArray yapionArray = Config.getInstance().get(p).getYAPIONArrayOrSetDefault("hotbar", defaultHotbar()); - ItemStack[] hotbar = new ItemStack[9]; + ItemStack[] hotbar = new ItemStack[13]; yapionArray.forEach((integer, yapionAnyType) -> { if (yapionAnyType instanceof YAPIONValue) { hotbar[integer] = null; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/hotbar/HotbarListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/hotbar/HotbarListener.java index afd1fb02..9c6f6bbd 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/hotbar/HotbarListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/hotbar/HotbarListener.java @@ -31,7 +31,7 @@ public class HotbarListener implements Listener { @EventHandler(priority = EventPriority.LOWEST) public void onPlayerJoin(PlayerJoinEvent event) { - if (allNull(event.getPlayer().getInventory().getContents())) { + if (allNull(event.getPlayer().getInventory().getContents()) && allNull(event.getPlayer().getInventory().getArmorContents())) { DefaultHotbar.setHotbar(event.getPlayer()); } } -- 2.39.2