SteamWar/BauSystem2.0
Archiviert
12
0

Armor to Hotbar #99

Zusammengeführt
YoyoNow hat 1 Commits von armor_to_hotbar nach master 2022-08-05 20:34:30 +02:00 zusammengeführt
2 geänderte Dateien mit 8 neuen und 4 gelöschten Zeilen
Nur Änderungen aus Commit 5e462ae097 werden angezeigt - Alle Commits anzeigen

Datei anzeigen

@ -33,11 +33,12 @@ import yapion.serializing.YAPIONSerializer;
@UtilityClass @UtilityClass
public class DefaultHotbar { 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) { 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().getContents(), 0, hotbar, 0, 9);
System.arraycopy(p.getInventory().getArmorContents(), 0, hotbar, 9, 4);
YAPIONArray yapionArray = new YAPIONArray(); YAPIONArray yapionArray = new YAPIONArray();
for (ItemStack itemStack : hotbar) { for (ItemStack itemStack : hotbar) {
if (itemStack != null) { if (itemStack != null) {
@ -53,13 +54,16 @@ public class DefaultHotbar {
public void setHotbar(Player p) { public void setHotbar(Player p) {
ItemStack[] hotbar = getItems(p); ItemStack[] hotbar = getItems(p);
ItemStack[] inv = p.getInventory().getContents(); ItemStack[] inv = p.getInventory().getContents();
ItemStack[] armor = p.getInventory().getArmorContents();
System.arraycopy(hotbar, 0, inv, 0, 9); System.arraycopy(hotbar, 0, inv, 0, 9);
System.arraycopy(hotbar, 9, armor, 0, 4);
p.getInventory().setContents(inv); p.getInventory().setContents(inv);
p.getInventory().setArmorContents(armor);
} }
public ItemStack[] getItems(Player p) { public ItemStack[] getItems(Player p) {
YAPIONArray yapionArray = Config.getInstance().get(p).getYAPIONArrayOrSetDefault("hotbar", defaultHotbar()); YAPIONArray yapionArray = Config.getInstance().get(p).getYAPIONArrayOrSetDefault("hotbar", defaultHotbar());
ItemStack[] hotbar = new ItemStack[9]; ItemStack[] hotbar = new ItemStack[13];
yapionArray.forEach((integer, yapionAnyType) -> { yapionArray.forEach((integer, yapionAnyType) -> {
if (yapionAnyType instanceof YAPIONValue) { if (yapionAnyType instanceof YAPIONValue) {
hotbar[integer] = null; hotbar[integer] = null;

Datei anzeigen

@ -31,7 +31,7 @@ public class HotbarListener implements Listener {
@EventHandler(priority = EventPriority.LOWEST) @EventHandler(priority = EventPriority.LOWEST)
public void onPlayerJoin(PlayerJoinEvent event) { 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()); DefaultHotbar.setHotbar(event.getPlayer());
} }
} }