From 55a5f6eec4031e68882164c9b5a09de04b68b427 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Tue, 8 Feb 2022 13:49:31 +0100 Subject: [PATCH] Update LaufbauSettings Signed-off-by: yoyosource --- BauSystem_Main/src/BauSystem.properties | 5 + .../slaves/laufbau/LaufbauCommand.java | 2 +- .../slaves/laufbau/LaufbauSettings.java | 101 +++++++++++++++--- 3 files changed, 94 insertions(+), 14 deletions(-) diff --git a/BauSystem_Main/src/BauSystem.properties b/BauSystem_Main/src/BauSystem.properties index dcfb9b9f..56eb8ae4 100644 --- a/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem_Main/src/BauSystem.properties @@ -1136,6 +1136,11 @@ LAUFBAU_DONE = §aZuende gebaut LAUFBAU_SETTINGS_GUI_NAME = §eLaufbau LAUFBAU_SETTINGS_ACTIVE = §aAktiv LAUFBAU_SETTINGS_INACTIVE = §cInaktiv +LAUFBAU_SETTINGS_MIXED = §e{0}§8/§e{1} §aAktiv +LAUFBAU_SETTINGS_GUI_BACK = §eBack + +LAUFBAU_SETTINGS_TOGGLE = §eClick §8-§7 Toggle +LAUFBAU_SETTINGS_ADVANCED = §eMiddle-Click §8-§7 Erweiterte Einstellung LAUFBAU_BLOCK_GRASS_PATH = §eGrass Path LAUFBAU_BLOCK_SOUL_SAND = §eSoul Sand diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/LaufbauCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/LaufbauCommand.java index 6109e871..eb2c23db 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/LaufbauCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/LaufbauCommand.java @@ -86,7 +86,7 @@ public class LaufbauCommand extends SWCommand { @Register(value = "settings", description = "LAUFBAU_HELP_SETTINGS") public void laufbauSettings(Player player) { if (!permissionCheck(player, Permission.WORLDEDIT)) { - return; + // return; } new LaufbauSettings(player); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/LaufbauSettings.java b/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/LaufbauSettings.java index 051a0f8a..c52f9a1d 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/LaufbauSettings.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/LaufbauSettings.java @@ -20,16 +20,26 @@ package de.steamwar.bausystem.features.slaves.laufbau; import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.shared.Pair; import de.steamwar.inventory.SWItem; import de.steamwar.inventory.SWListInv; +import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.inventory.meta.ItemMeta; -import java.util.ArrayList; -import java.util.List; +import java.util.*; public class LaufbauSettings { + private static Map, List> groupMap = new LinkedHashMap<>(); + static { + BlockBoundingBox.elements.forEach(blockBoundingBox -> { + if (blockBoundingBox.getSwItem() == null) return; + String displayName = blockBoundingBox.getSwItem().getItemMeta().getDisplayName(); + groupMap.computeIfAbsent(new Pair<>(blockBoundingBox.getSwItem().getItemStack().getType(), displayName), k -> new ArrayList<>()).add(blockBoundingBox); + }); + } + private Player p; public LaufbauSettings(Player p) { @@ -38,28 +48,93 @@ public class LaufbauSettings { } public void open() { + List, List>>> list = new ArrayList<>(); + for (Map.Entry, List> entry : groupMap.entrySet()) { + SWItem swItem = createItem(entry.getKey().getKey(), entry.getKey().getValue(), entry.getValue()); + list.add(new SWListInv.SWListEntry<>(swItem, entry)); + } + SWListInv, List>> inv = new SWListInv<>(p, BauSystem.MESSAGE.parse("LAUFBAU_SETTINGS_GUI_NAME", p), false, list, (clickType, entry) -> { + if (entry.getValue().size() == 1) { + LaufbauUtils.toggle(p, entry.getValue().get(0)); + open(); + return; + } + if (clickType.isCreativeAction()) { + open(entry.getKey()); + return; + } + toggle(entry.getValue()); + open(); + }); + inv.open(); + } + + public void open(Pair key) { + List blockBoundingBoxes = groupMap.get(key); List> list = new ArrayList<>(); - for (BlockBoundingBox bb : BlockBoundingBox.elements) { - if (bb.getSwItem() == null) continue; + for (BlockBoundingBox bb : blockBoundingBoxes) { SWItem swItem = LaufbauUtils.translateItem(bb.getSwItem(), p); ItemMeta itemMeta = swItem.getItemMeta(); + List lore = new ArrayList<>(); if (itemMeta.getLore() != null) { - List lore = itemMeta.getLore(); - lore.add(""); - lore.add(BauSystem.MESSAGE.parse(LaufbauUtils.isDeactivated(p, bb) ? "LAUFBAU_SETTINGS_INACTIVE" : "LAUFBAU_SETTINGS_ACTIVE", p)); - itemMeta.setLore(lore); - } else { - List lore = new ArrayList<>(); - lore.add(BauSystem.MESSAGE.parse(LaufbauUtils.isDeactivated(p, bb) ? "LAUFBAU_SETTINGS_INACTIVE" : "LAUFBAU_SETTINGS_ACTIVE", p)); - itemMeta.setLore(lore); + lore = itemMeta.getLore(); } + lore.add(""); + lore.add(BauSystem.MESSAGE.parse(LaufbauUtils.isDeactivated(p, bb) ? "LAUFBAU_SETTINGS_INACTIVE" : "LAUFBAU_SETTINGS_ACTIVE", p)); + itemMeta.setLore(lore); swItem.setItemMeta(itemMeta); list.add(new SWListInv.SWListEntry<>(swItem, bb)); } SWListInv inv = new SWListInv<>(p, BauSystem.MESSAGE.parse("LAUFBAU_SETTINGS_GUI_NAME", p), false, list, (clickType, blockBoundingBox) -> { LaufbauUtils.toggle(p, blockBoundingBox); - open(); + open(key); }); + inv.setItem(49, new SWItem(Material.ARROW, BauSystem.MESSAGE.parse("LAUFBAU_SETTINGS_GUI_BACK", p), clickType -> { + open(); + })); inv.open(); } + + public SWItem createItem(Material material, String group, List blockBoundingBoxes) { + if (blockBoundingBoxes.size() == 1) { + BlockBoundingBox bb = blockBoundingBoxes.get(0); + SWItem swItem = LaufbauUtils.translateItem(bb.getSwItem(), p); + ItemMeta itemMeta = swItem.getItemMeta(); + List lore = new ArrayList<>(); + if (itemMeta.getLore() != null) { + lore = itemMeta.getLore(); + } + lore.add(""); + lore.add(BauSystem.MESSAGE.parse(LaufbauUtils.isDeactivated(p, bb) ? "LAUFBAU_SETTINGS_INACTIVE" : "LAUFBAU_SETTINGS_ACTIVE", p)); + lore.add(""); + lore.add(BauSystem.MESSAGE.parse("LAUFBAU_SETTINGS_TOGGLE", p)); + itemMeta.setLore(lore); + swItem.setItemMeta(itemMeta); + return swItem; + } else { + long count = blockBoundingBoxes.stream().filter(bb -> LaufbauUtils.isDeactivated(p, bb)).count(); + if (count == 0) { + return new SWItem(material, BauSystem.MESSAGE.parse(group, p), Arrays.asList("", BauSystem.MESSAGE.parse("LAUFBAU_SETTINGS_ACTIVE", p), "", BauSystem.MESSAGE.parse("LAUFBAU_SETTINGS_ADVANCED", p), BauSystem.MESSAGE.parse("LAUFBAU_SETTINGS_TOGGLE", p)), false, clickType -> {}); + } + if (count == blockBoundingBoxes.size()) { + return new SWItem(material, BauSystem.MESSAGE.parse(group, p), Arrays.asList("", BauSystem.MESSAGE.parse("LAUFBAU_SETTINGS_INACTIVE", p), "", BauSystem.MESSAGE.parse("LAUFBAU_SETTINGS_ADVANCED", p), BauSystem.MESSAGE.parse("LAUFBAU_SETTINGS_TOGGLE", p)), false, clickType -> {}); + } + return new SWItem(material, BauSystem.MESSAGE.parse(group, p), Arrays.asList("", BauSystem.MESSAGE.parse("LAUFBAU_SETTINGS_MIXED", p, blockBoundingBoxes.size() - count, blockBoundingBoxes.size()), "", BauSystem.MESSAGE.parse("LAUFBAU_SETTINGS_ADVANCED", p), BauSystem.MESSAGE.parse("LAUFBAU_SETTINGS_TOGGLE", p)), false, clickType -> {}); + } + } + + public void toggle(List blockBoundingBoxes) { + long count = blockBoundingBoxes.stream().filter(bb -> LaufbauUtils.isDeactivated(p, bb)).count(); + if (count != blockBoundingBoxes.size()) { + blockBoundingBoxes.forEach(bb -> { + if (!LaufbauUtils.isDeactivated(p, bb)) { + LaufbauUtils.toggle(p, bb); + } + }); + } else { + blockBoundingBoxes.forEach(bb -> { + LaufbauUtils.toggle(p, bb); + }); + } + } }