From c878a6a183ebc7d2edb1b9f3723d6a72bcbb9af8 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Mon, 7 Feb 2022 19:54:28 +0100 Subject: [PATCH] Fix LanternBoundingBox Add LaufbauSettings gui working Signed-off-by: yoyosource --- BauSystem_Main/src/BauSystem.properties | 5 +- .../features/slaves/laufbau/Laufbau.java | 8 +- .../slaves/laufbau/LaufbauCommand.java | 2 +- .../slaves/laufbau/LaufbauSettings.java | 26 ++++- .../features/slaves/laufbau/LaufbauUtils.java | 101 +++++++++++++++--- .../boundingboxes/LanternBoundingBox.java | 6 +- .../bausystem/linkage/LinkageUtils.java | 2 + 7 files changed, 126 insertions(+), 24 deletions(-) diff --git a/BauSystem_Main/src/BauSystem.properties b/BauSystem_Main/src/BauSystem.properties index a6f4a7cc..dcfb9b9f 100644 --- a/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem_Main/src/BauSystem.properties @@ -1127,12 +1127,15 @@ LAUFBAU_STATE_FILTERING_TRACES = Traces filtern LAUFBAU_STATE_PROCESSING_TRACES = Traces verbinden LAUFBAU_STATE_EXPANDING_TRACES = Traces aufblähen LAUFBAU_STATE_SPLITTING_POINTS = Punkte trennen +LAUFBAU_STATE_SHRINKING_POINTS = Punkte ausdünnen LAUFBAU_STATE_CREATING_INNER_BLOCKS = Innenraum füllen LAUFBAU_STATE_CREATING_OUTER_BLOCKS = Mantel bauen LAUFBAU_SIMPLE_PROGRESS = §e{0}§8: §e{1}§8/§e{2} LAUFBAU_DONE = §aZuende gebaut -LAUFBAU_SETTING_GUI_NAME = §eLaufbau +LAUFBAU_SETTINGS_GUI_NAME = §eLaufbau +LAUFBAU_SETTINGS_ACTIVE = §aAktiv +LAUFBAU_SETTINGS_INACTIVE = §cInaktiv LAUFBAU_BLOCK_GRASS_PATH = §eGrass Path LAUFBAU_BLOCK_SOUL_SAND = §eSoul Sand diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/Laufbau.java b/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/Laufbau.java index 2ce9c527..d9ba482f 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/Laufbau.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/Laufbau.java @@ -31,6 +31,7 @@ import org.bukkit.util.Vector; import java.util.ArrayList; import java.util.Comparator; import java.util.List; +import java.util.stream.Collectors; public class Laufbau { @@ -48,12 +49,12 @@ public class Laufbau { private CreatingInnerBlocksState creatingInnerBlocksState = null; private CreatingOuterBlocksState creatingOuterBlocksState = null; - private List elements = new ArrayList<>(BlockBoundingBox.elements); + private List elements; @Getter private EditSession editSession; - public Laufbau(Location pos1, Location pos2, boolean preferingBlastResistance) { + public Laufbau(Player player, Location pos1, Location pos2, boolean preferingBlastResistance) { this.world = pos1.getWorld(); this.pos1 = new Location(world, Math.min(pos1.getBlockX(), pos2.getBlockX()), Math.min(pos1.getBlockY(), pos2.getBlockY()), Math.min(pos1.getBlockZ(), pos2.getBlockZ())); this.pos2 = new Location(world, Math.max(pos1.getBlockX(), pos2.getBlockX()), Math.max(pos1.getBlockY(), pos2.getBlockY()), Math.max(pos1.getBlockZ(), pos2.getBlockZ())); @@ -64,6 +65,9 @@ public class Laufbau { editSession = WorldEditUtils.getEditSession(world); + elements = BlockBoundingBox.elements.stream().filter(blockBoundingBox -> { + return !LaufbauUtils.isDeactivated(player, blockBoundingBox); + }).collect(Collectors.toList()); if (preferingBlastResistance) { elements.sort((o1, o2) -> { int compared = Double.compare(o1.blockData.getMaterial().getBlastResistance(), o2.blockData.getMaterial().getBlastResistance()); 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 e751c33c..6109e871 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 @@ -57,7 +57,7 @@ public class LaufbauCommand extends SWCommand { BauSystem.MESSAGE.send("LAUFBAU_NO_WORLDEDIT", player); return; } - Laufbau laufbau = new Laufbau(selection.getKey(), selection.getValue(), preferingBlastResistance); + Laufbau laufbau = new Laufbau(player, selection.getKey(), selection.getValue(), preferingBlastResistance); new BukkitRunnable() { @Override public void run() { 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 b2215e77..051a0f8a 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,8 +20,10 @@ package de.steamwar.bausystem.features.slaves.laufbau; import de.steamwar.bausystem.BauSystem; +import de.steamwar.inventory.SWItem; import de.steamwar.inventory.SWListInv; import org.bukkit.entity.Player; +import org.bukkit.inventory.meta.ItemMeta; import java.util.ArrayList; import java.util.List; @@ -32,13 +34,31 @@ public class LaufbauSettings { public LaufbauSettings(Player p) { this.p = p; + open(); + } + + public void open() { List> list = new ArrayList<>(); for (BlockBoundingBox bb : BlockBoundingBox.elements) { if (bb.getSwItem() == null) continue; - list.add(new SWListInv.SWListEntry<>(LaufbauUtils.translateItem(bb.getSwItem(), p), bb)); + SWItem swItem = LaufbauUtils.translateItem(bb.getSwItem(), p); + ItemMeta itemMeta = swItem.getItemMeta(); + 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); + } + swItem.setItemMeta(itemMeta); + list.add(new SWListInv.SWListEntry<>(swItem, bb)); } - SWListInv inv = new SWListInv<>(p, BauSystem.MESSAGE.parse("LAUFBAU_SETTING_GUI_NAME", p), false, list, (clickType, blockBoundingBox) -> { - p.sendMessage(LaufbauUtils.identifier(blockBoundingBox.getSwItem())); + SWListInv inv = new SWListInv<>(p, BauSystem.MESSAGE.parse("LAUFBAU_SETTINGS_GUI_NAME", p), false, list, (clickType, blockBoundingBox) -> { + LaufbauUtils.toggle(p, blockBoundingBox); + open(); }); inv.open(); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/LaufbauUtils.java b/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/LaufbauUtils.java index 6c06d2d3..34164338 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/LaufbauUtils.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/LaufbauUtils.java @@ -20,19 +20,64 @@ package de.steamwar.bausystem.features.slaves.laufbau; import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.linkage.LinkageType; +import de.steamwar.bausystem.linkage.Linked; import de.steamwar.inventory.SWItem; -import lombok.experimental.UtilityClass; +import de.steamwar.sql.UserConfig; +import lombok.Cleanup; +import lombok.SneakyThrows; import org.bukkit.Material; import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.inventory.meta.ItemMeta; +import yapion.hierarchy.output.StreamOutput; +import yapion.hierarchy.types.YAPIONObject; +import yapion.parser.YAPIONParser; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.util.*; import java.util.stream.Collectors; +import java.util.zip.GZIPInputStream; +import java.util.zip.GZIPOutputStream; -@UtilityClass -public class LaufbauUtils { +@Linked(LinkageType.LISTENER) +public class LaufbauUtils implements Listener { + + private static Map yapionObjectMap = new HashMap<>(); + + @EventHandler + @SneakyThrows + public void onPlayerJoin(PlayerJoinEvent event) { + String config = UserConfig.getConfig(event.getPlayer().getUniqueId(), "bausystem-laufbau"); + if (config == null) { + return; + } + byte[] bytes = Base64.getDecoder().decode(config); + @Cleanup GZIPInputStream gzipInputStream = new GZIPInputStream(new ByteArrayInputStream(bytes)); + YAPIONObject yapionObject = new YAPIONParser(gzipInputStream, true).parse().result(); + yapionObjectMap.put(event.getPlayer(), yapionObject); + } + + @EventHandler + @SneakyThrows + public void onPlayerQuit(PlayerQuitEvent event) { + YAPIONObject yapionObject = yapionObjectMap.get(event.getPlayer()); + if (yapionObject == null) { + return; + } + if (yapionObject.isEmpty()) { + UserConfig.removePlayerConfig(event.getPlayer().getUniqueId(), "bausystem-laufbau"); + return; + } + @Cleanup ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + @Cleanup GZIPOutputStream gzipOutputStream = new GZIPOutputStream(byteArrayOutputStream); + yapionObject.toYAPION(new StreamOutput(gzipOutputStream)).close(); + UserConfig.updatePlayerConfig(event.getPlayer().getUniqueId(), "bausystem-laufbau", Base64.getEncoder().encodeToString(byteArrayOutputStream.toByteArray())); + } public static Cuboid pixelCuboid(double pixelX, double pixelY, double pixelZ, double pixelDX, double pixelDY, double pixelDZ) { return new Cuboid(pixelToBlock(pixelX), pixelToBlock(pixelY), pixelToBlock(pixelZ), pixelToBlock(pixelDX), pixelToBlock(pixelDY), pixelToBlock(pixelDZ)); @@ -57,23 +102,51 @@ public class LaufbauUtils { }); } - public static String identifier(SWItem item) { + public static String identifier(BlockBoundingBox bb) { + if (bb.getSwItem() == null) { + return null; + } + SWItem item = bb.getSwItem(); ItemMeta itemMeta = item.getItemMeta(); List lore = new ArrayList<>(); if (itemMeta.getLore() != null) { lore = itemMeta.getLore() .stream() .map(s -> s.substring(8)) - .map(s -> { - return s.replace("ATTACHMENT", "*") - .replace("CONNECTION", "CON") - .replace("FACING", "*") - .replace("LAYERS", "*") - .replace("SHAPE", "*"); - }) .collect(Collectors.toList()); } String name = itemMeta.getDisplayName().substring(14); return name + "[" + String.join(",", lore) + "]"; } + + @SneakyThrows + public static boolean isDeactivated(Player p, BlockBoundingBox bb) { + if (bb.getSwItem() == null) { + return false; + } + String identifier = identifier(bb); + YAPIONObject yapionObject = yapionObjectMap.get(p); + if (yapionObject == null) { + return false; + } + return yapionObject.containsKey(identifier); + } + + @SneakyThrows + public static void toggle(Player p, BlockBoundingBox bb) { + if (bb.getSwItem() == null) { + return; + } + String identifier = identifier(bb); + YAPIONObject yapionObject = yapionObjectMap.get(p); + if (yapionObject == null) { + yapionObject = new YAPIONObject(); + yapionObjectMap.put(p, yapionObject); + } + if (yapionObject.containsKey(identifier)) { + yapionObject.remove(identifier); + } else { + yapionObject.put(identifier, new YAPIONObject()); + } + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/boundingboxes/LanternBoundingBox.java b/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/boundingboxes/LanternBoundingBox.java index dfda9d62..5299186d 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/boundingboxes/LanternBoundingBox.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/boundingboxes/LanternBoundingBox.java @@ -48,15 +48,15 @@ public class LanternBoundingBox implements Enable { List cuboidList = new ArrayList<>(); cuboidList.add(pixelCuboid(5, 0, 5, 6, 7, 6)); cuboidList.add(pixelCuboid(6, 7, 6, 4, 2, 4)); - new BlockBoundingBox(lantern, cuboidList, createItem("LAUFBAU_BLOCK_LANTERN", Material.LANTERN, "LAUFBAU_HANGING")); + new BlockBoundingBox(lantern, cuboidList, createItem("LAUFBAU_BLOCK_LANTERN", Material.LANTERN)); } public void hangingLantern() { Lantern lantern = (Lantern) Material.LANTERN.createBlockData(); - lantern.setHanging(false); + lantern.setHanging(true); List cuboidList = new ArrayList<>(); cuboidList.add(pixelCuboid(5, 1, 5, 6, 7, 6)); cuboidList.add(pixelCuboid(6, 8, 6, 4, 2, 4)); - new BlockBoundingBox(lantern, cuboidList, createItem("LAUFBAU_BLOCK_LANTERN", Material.LANTERN)); + new BlockBoundingBox(lantern, cuboidList, createItem("LAUFBAU_BLOCK_LANTERN", Material.LANTERN, "LAUFBAU_HANGING")); } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/linkage/LinkageUtils.java b/BauSystem_Main/src/de/steamwar/bausystem/linkage/LinkageUtils.java index 825eff86..7ba894ae 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/linkage/LinkageUtils.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/linkage/LinkageUtils.java @@ -20,6 +20,7 @@ package de.steamwar.bausystem.linkage; import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.configplayer.Config; import de.steamwar.bausystem.utils.FlatteningWrapper; import de.steamwar.bausystem.utils.NMSWrapper; import lombok.experimental.UtilityClass; @@ -42,6 +43,7 @@ public class LinkageUtils { private Set fieldsToLink = new HashSet<>(); { + objectMap.put(Config.class, Config.getInstance()); objectMap.put(BauSystem.class, BauSystem.getInstance()); objectMap.put(FlatteningWrapper.IFlatteningWrapper.class, FlatteningWrapper.impl); objectMap.put(NMSWrapper.INMSWrapper.class, NMSWrapper.impl);