From 2165682234aa0325de8d9bbf1afbe32476e74c2b Mon Sep 17 00:00:00 2001 From: yoyosource Date: Mon, 24 May 2021 12:46:19 +0200 Subject: [PATCH 01/11] Update ConfigurationSerializableSerializer Signed-off-by: yoyosource --- .../ConfigurationSerializableSerializer.java | 11 ++- .../features/hotbar/DefaultHotbar.java | 80 ++++++++----------- 2 files changed, 43 insertions(+), 48 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/configplayer/serializer/ConfigurationSerializableSerializer.java b/BauSystem_Main/src/de/steamwar/bausystem/configplayer/serializer/ConfigurationSerializableSerializer.java index 50599ff8..de0ad78e 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/configplayer/serializer/ConfigurationSerializableSerializer.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/configplayer/serializer/ConfigurationSerializableSerializer.java @@ -21,11 +21,13 @@ package de.steamwar.bausystem.configplayer.serializer; import org.bukkit.configuration.serialization.ConfigurationSerializable; import org.bukkit.configuration.serialization.ConfigurationSerialization; +import yapion.hierarchy.api.groups.YAPIONAnyType; import yapion.hierarchy.types.YAPIONObject; import yapion.serializing.api.SerializerObject; import yapion.serializing.data.DeserializeData; import yapion.serializing.data.SerializeData; +import java.util.ArrayList; import java.util.HashMap; import java.util.Map; @@ -49,7 +51,14 @@ public class ConfigurationSerializableSerializer extends SerializerObject serializeDataMap = serializeData.object.serialize(); serializeDataMap.forEach((s, o) -> { - yapionObject.add(s, serializeData.serialize(o)); + YAPIONAnyType yapionAnyType = serializeData.serialize(o); + if (yapionAnyType instanceof YAPIONObject) { + YAPIONObject object = (YAPIONObject) yapionAnyType; + if (object.containsKey(TYPE_IDENTIFIER) && object.getPlainValue(TYPE_IDENTIFIER).equals("com.google.common.collect.RegularImmutableList")) { + object.put(TYPE_IDENTIFIER, ArrayList.class.getTypeName()); + } + } + yapionObject.add(s, yapionAnyType); }); return yapionObject; } 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 abbec165..23ed1665 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/hotbar/DefaultHotbar.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/hotbar/DefaultHotbar.java @@ -20,71 +20,57 @@ package de.steamwar.bausystem.features.hotbar; import de.steamwar.bausystem.configplayer.Config; -import org.bukkit.configuration.file.YamlConfiguration; +import lombok.experimental.UtilityClass; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; +import yapion.hierarchy.types.YAPIONArray; +import yapion.hierarchy.types.YAPIONObject; +import yapion.hierarchy.types.YAPIONValue; +import yapion.parser.YAPIONParser; +import yapion.serializing.YAPIONDeserializer; +import yapion.serializing.YAPIONSerializer; -import java.io.StringReader; - -// TODO: 16.05.2021 @Yoyo muss mal was Fixen, dann Item Save auf Yapion umstellen +@UtilityClass public class DefaultHotbar { - public static void updateHotbar(Player p) { + private final YAPIONArray DEFAULT_HOTBAR = YAPIONParser.parse("{[{@type(org.bukkit.configuration.serialization.ConfigurationSerializable)v(2230)type(WOODEN_AXE)meta{@type(org.bukkit.configuration.serialization.ConfigurationSerializable)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.configuration.serialization.ConfigurationSerializable)v(2230)type(COMPASS)meta{@type(org.bukkit.configuration.serialization.ConfigurationSerializable)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.configuration.serialization.ConfigurationSerializable)v(2230)type(NETHER_STAR)meta{@type(org.bukkit.configuration.serialization.ConfigurationSerializable)meta-type(UNSPECIFIC)display-name(§eBau GUI)}}]}").getArray(""); + + public void updateHotbar(Player p) { ItemStack[] hotbar = new ItemStack[9]; System.arraycopy(p.getInventory().getContents(), 0, hotbar, 0, 9); - YamlConfiguration configuration = new YamlConfiguration(); - configuration.set("Items", hotbar); - Config.getInstance().get(p).add("hotbar", configuration.saveToString()); + YAPIONArray yapionArray = new YAPIONArray(); + for (ItemStack itemStack : hotbar) { + if (itemStack != null) { + yapionArray.add(YAPIONSerializer.serialize(itemStack)); + } else { + yapionArray.add(new YAPIONValue<>(null)); + } + } + Config.getInstance().get(p).add("hotbar", yapionArray); Config.getInstance().save(p); } - public static void setHotbar(Player p) { + public void setHotbar(Player p) { ItemStack[] hotbar = getItems(p); ItemStack[] inv = p.getInventory().getContents(); System.arraycopy(hotbar, 0, inv, 0, 9); p.getInventory().setContents(inv); } - public static ItemStack[] getItems(Player p) { - YamlConfiguration hb = YamlConfiguration.loadConfiguration(new StringReader(Config.getInstance().get(p).getPlainValueOrDefault("hotbar", defaultHotbar()))); - ItemStack[] hotbar = hb.getList("Items").toArray(new ItemStack[9]); + public ItemStack[] getItems(Player p) { + YAPIONArray yapionArray = Config.getInstance().get(p).getYAPIONArrayOrSetDefault("hotbar", defaultHotbar());; + ItemStack[] hotbar = new ItemStack[9]; + yapionArray.forEach((integer, yapionAnyType) -> { + if (yapionAnyType instanceof YAPIONValue) { + hotbar[integer] = null; + } else { + hotbar[integer] = (ItemStack) YAPIONDeserializer.deserialize((YAPIONObject) yapionAnyType); + } + }); return hotbar; } - public static String defaultHotbar() { - return "Items:\n" + - "- ==: org.bukkit.inventory.ItemStack\n" + - " v: 2230\n" + - " type: WOODEN_AXE\n" + - " meta:\n" + - " ==: ItemMeta\n" + - " meta-type: UNSPECIFIC\n" + - " display-name: WorldEdit Wand\n" + - " lore:\n" + - " - 'Left click: select pos #1'\n" + - " - 'Right click: select pos #2'\n" + - "- ==: org.bukkit.inventory.ItemStack\n" + - " v: 2230\n" + - " type: COMPASS\n" + - " meta:\n" + - " ==: ItemMeta\n" + - " meta-type: UNSPECIFIC\n" + - " display-name: Navigation Wand\n" + - " lore:\n" + - " - 'Left click: jump to location'\n" + - " - 'Right click: pass through walls'\n" + - "- null\n" + - "- null\n" + - "- null\n" + - "- null\n" + - "- null\n" + - "- null\n" + - "- ==: org.bukkit.inventory.ItemStack\n" + - " v: 2230\n" + - " type: NETHER_STAR\n" + - " meta:\n" + - " ==: ItemMeta\n" + - " meta-type: UNSPECIFIC\n" + - " display-name: §eBau GUI\n"; + public YAPIONArray defaultHotbar() { + return DEFAULT_HOTBAR; } } From 3ce014b2673f5387a6ac31419d9706c3fcc2aa0e Mon Sep 17 00:00:00 2001 From: yoyosource Date: Mon, 24 May 2021 13:10:03 +0200 Subject: [PATCH 02/11] Update DefaultHotbar from YAML to YAPION Signed-off-by: yoyosource --- .../ConfigurationSerializableSerializer.java | 19 +++++++++++++++++-- .../features/hotbar/DefaultHotbar.java | 4 ++-- .../features/hotbar/HotbarListener.java | 1 - 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/configplayer/serializer/ConfigurationSerializableSerializer.java b/BauSystem_Main/src/de/steamwar/bausystem/configplayer/serializer/ConfigurationSerializableSerializer.java index de0ad78e..eecd1ef1 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/configplayer/serializer/ConfigurationSerializableSerializer.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/configplayer/serializer/ConfigurationSerializableSerializer.java @@ -21,6 +21,8 @@ package de.steamwar.bausystem.configplayer.serializer; import org.bukkit.configuration.serialization.ConfigurationSerializable; import org.bukkit.configuration.serialization.ConfigurationSerialization; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; import yapion.hierarchy.api.groups.YAPIONAnyType; import yapion.hierarchy.types.YAPIONObject; import yapion.serializing.api.SerializerObject; @@ -48,7 +50,13 @@ public class ConfigurationSerializableSerializer extends SerializerObject serializeData) { YAPIONObject yapionObject = new YAPIONObject(); - yapionObject.add(TYPE_IDENTIFIER, type().getTypeName()); + yapionObject.add(TYPE_IDENTIFIER, serializeData.object.getClass().getTypeName()); + if (serializeData.object instanceof ItemStack) { + yapionObject.add(TYPE_IDENTIFIER, ItemStack.class.getTypeName()); + } + if (serializeData.object instanceof ItemMeta) { + yapionObject.add(TYPE_IDENTIFIER, ItemMeta.class.getTypeName()); + } Map serializeDataMap = serializeData.object.serialize(); serializeDataMap.forEach((s, o) -> { YAPIONAnyType yapionAnyType = serializeData.serialize(o); @@ -67,7 +75,14 @@ public class ConfigurationSerializableSerializer extends SerializerObject deserializeData) { Map deserializeDataMap = new HashMap<>(); deserializeData.object.forEach((s, yapionAnyType) -> { - if (s.equals(TYPE_IDENTIFIER)) return; + if (s.equals(TYPE_IDENTIFIER)) { + if (yapionAnyType.toString().equals("(org.bukkit.inventory.meta.ItemMeta)")) { + deserializeDataMap.put("==", "ItemMeta"); + } else { + deserializeDataMap.put("==", deserializeData.deserialize(yapionAnyType)); + } + return; + } deserializeDataMap.put(s, deserializeData.deserialize(yapionAnyType)); }); return ConfigurationSerialization.deserializeObject(deserializeDataMap); 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 23ed1665..e0808857 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/hotbar/DefaultHotbar.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/hotbar/DefaultHotbar.java @@ -33,7 +33,7 @@ import yapion.serializing.YAPIONSerializer; @UtilityClass public class DefaultHotbar { - private final YAPIONArray DEFAULT_HOTBAR = YAPIONParser.parse("{[{@type(org.bukkit.configuration.serialization.ConfigurationSerializable)v(2230)type(WOODEN_AXE)meta{@type(org.bukkit.configuration.serialization.ConfigurationSerializable)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.configuration.serialization.ConfigurationSerializable)v(2230)type(COMPASS)meta{@type(org.bukkit.configuration.serialization.ConfigurationSerializable)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.configuration.serialization.ConfigurationSerializable)v(2230)type(NETHER_STAR)meta{@type(org.bukkit.configuration.serialization.ConfigurationSerializable)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)}}]}").getArray(""); public void updateHotbar(Player p) { ItemStack[] hotbar = new ItemStack[9]; @@ -58,7 +58,7 @@ public class DefaultHotbar { } 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]; yapionArray.forEach((integer, yapionAnyType) -> { if (yapionAnyType instanceof YAPIONValue) { 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 5772c878..afd1fb02 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,6 @@ public class HotbarListener implements Listener { @EventHandler(priority = EventPriority.LOWEST) public void onPlayerJoin(PlayerJoinEvent event) { - System.out.println(event.getPlayer().getInventory().getContents()); if (allNull(event.getPlayer().getInventory().getContents())) { DefaultHotbar.setHotbar(event.getPlayer()); } From 9503b91e58a1f532de54f972fcfec8ea223a9b1d Mon Sep 17 00:00:00 2001 From: yoyosource Date: Mon, 24 May 2021 13:13:01 +0200 Subject: [PATCH 03/11] Removed unused instance in AutoStartCommand Signed-off-by: yoyosource --- .../bausystem/features/autostart/AutoStartCommand.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/autostart/AutoStartCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/autostart/AutoStartCommand.java index f6e89445..d2da652f 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/autostart/AutoStartCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/autostart/AutoStartCommand.java @@ -23,16 +23,12 @@ import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.SWUtils; import de.steamwar.bausystem.linkage.LinkageType; import de.steamwar.bausystem.linkage.Linked; -import de.steamwar.bausystem.linkage.LinkedInstance; import de.steamwar.command.SWCommand; import org.bukkit.entity.Player; @Linked(LinkageType.COMMAND) public class AutoStartCommand extends SWCommand { - @LinkedInstance - private AutostartListener autostartListener; - public AutoStartCommand() { super("timer", "autostarttimer", "at", "autostart"); } From e666ff07395933c7cd42454b05d87e4ed93a1db5 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Mon, 24 May 2021 13:25:38 +0200 Subject: [PATCH 04/11] Add DetonatorCommand.toggleAutostartTimer Signed-off-by: yoyosource --- .../features/autostart/AutostartListener.java | 14 ++++++++++++-- .../bausystem/features/detonator/Detonator.java | 6 ++++++ .../features/detonator/DetonatorCommand.java | 9 +++++++++ 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/autostart/AutostartListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/autostart/AutostartListener.java index 98814659..9f90799c 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/autostart/AutostartListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/autostart/AutostartListener.java @@ -47,6 +47,13 @@ import java.util.Map; @Linked(LinkageType.LISTENER) public class AutostartListener implements Listener { + @Getter + public static AutostartListener instance; + + { + instance = this; + } + public static ItemStack getWandItem(Player player) { ItemStack itemStack = new SWItem(Material.FIREWORK_STAR, BauSystem.MESSAGE.parse("AUTOSTART_ITEM_NAME", player), Arrays.asList(BauSystem.MESSAGE.parse("AUTOSTART_ITEM_LORE", player)), false, null).getItemStack(); ItemUtils.setItem(itemStack, "autostart"); @@ -64,8 +71,11 @@ public class AutostartListener implements Listener { if (event.getClickedBlock() == null) { return; } - Player player = event.getPlayer(); - Region region = Region.getRegion(event.getClickedBlock().getLocation()); + activate(event.getPlayer()); + } + + public void activate(Player player) { + Region region = Region.getRegion(player.getLocation()); if (region.isGlobal()) { BauSystem.MESSAGE.send("AUTOSTART_MESSAGE_NO-REGION", player); return; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/detonator/Detonator.java b/BauSystem_Main/src/de/steamwar/bausystem/features/detonator/Detonator.java index 899beb4f..f7dbb2f9 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/detonator/Detonator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/detonator/Detonator.java @@ -22,6 +22,8 @@ package de.steamwar.bausystem.features.detonator; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.SWUtils; import de.steamwar.bausystem.config.ColorConfig; +import de.steamwar.bausystem.configplayer.Config; +import de.steamwar.bausystem.features.autostart.AutostartListener; import de.steamwar.bausystem.features.detonator.storage.DetonatorStorage; import de.steamwar.bausystem.features.detonator.storage.ItemStorage; import de.steamwar.core.VersionedRunnable; @@ -75,6 +77,10 @@ public class Detonator { public static void activateDetonator(DetonatorStorage detonator) { Player p = detonator.getPlayer(); + if (Config.getInstance().get(p).getPlainValueOrDefault("detonator-autostart", false)) { + AutostartListener.instance.activate(p); + } + Map> deactivate = new HashMap<>(); Set invalid = new HashSet<>(); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/detonator/DetonatorCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/detonator/DetonatorCommand.java index b7615379..c5c72221 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/detonator/DetonatorCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/detonator/DetonatorCommand.java @@ -19,8 +19,10 @@ package de.steamwar.bausystem.features.detonator; +import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.SWUtils; import de.steamwar.bausystem.config.ColorConfig; +import de.steamwar.bausystem.configplayer.Config; import de.steamwar.bausystem.features.detonator.storage.DetonatorStorage; import de.steamwar.bausystem.features.detonator.storage.ItemStorage; import de.steamwar.bausystem.linkage.LinkageType; @@ -81,4 +83,11 @@ public class DetonatorCommand extends SWCommand { storage.clear(); storage.write(); } + + @Register("autostart") + public void toggleAutostartTimer(Player p) { + boolean current = Config.getInstance().get(p).getPlainValueOrDefault("detonator-autostart", false); + Config.getInstance().get(p).put("detonator-autostart", !current); + p.sendMessage(BauSystem.PREFIX + "Autostart beim detonate " + (!current ? "§aangeschaltet" : "§causgeschaltet")); + } } From 1a1f7b49b30c427885bf1144f3d2bfc9cec471d5 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Mon, 24 May 2021 13:34:09 +0200 Subject: [PATCH 05/11] Optimize imports DepthCounter Signed-off-by: yoyosource --- .../bausystem/features/testblock/depthcounter/DepthCounter.java | 1 - 1 file changed, 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/depthcounter/DepthCounter.java b/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/depthcounter/DepthCounter.java index 4402bbca..be963a13 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/depthcounter/DepthCounter.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/depthcounter/DepthCounter.java @@ -27,7 +27,6 @@ import org.bukkit.entity.Player; import org.bukkit.util.Vector; import java.util.*; -import java.util.function.DoubleBinaryOperator; import java.util.stream.Collectors; @UtilityClass From 399171f58ec14e69b07743a9d13137634ce7b304 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Mon, 24 May 2021 15:23:46 +0200 Subject: [PATCH 06/11] Update DepthCounterListener to count extension area as well Signed-off-by: yoyosource --- .../testblock/depthcounter/DepthCounterListener.java | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/depthcounter/DepthCounterListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/depthcounter/DepthCounterListener.java index 99778878..47f98554 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/depthcounter/DepthCounterListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/depthcounter/DepthCounterListener.java @@ -40,15 +40,12 @@ public class DepthCounterListener implements Listener { @EventHandler public void onEntityExplode(EntityExplodeEvent event) { Region region = Region.getRegion(event.getLocation()); - boolean testblock = event.blockList().stream().anyMatch(block -> region.inRegion(block.getLocation(), RegionType.TESTBLOCK, RegionExtensionType.NORMAL)); + boolean testblock = event.blockList().stream().anyMatch(block -> region.inRegion(block.getLocation(), RegionType.TESTBLOCK, RegionExtensionType.EXTENSION)); if (!testblock) { return; } - if (!DepthCounter.depthMap.containsKey(region)) { - DepthCounter.depthMap.put(region, new HashSet<>()); - } - + DepthCounter.depthMap.computeIfAbsent(region, r -> new HashSet<>()); Set depthSet = DepthCounter.depthMap.get(region); for (Depth depth : depthSet) { if (depth.update(event.blockList())) { From 7eb642793c2d878ef003972afdb0fb56d3040531 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Mon, 24 May 2021 16:07:32 +0200 Subject: [PATCH 07/11] Update DepthCounter to save in PlayerConfig Signed-off-by: yoyosource --- .../src/de/steamwar/bausystem/BauSystem.java | 2 ++ .../bausystem/configplayer/Config.java | 8 +++++ .../testblock/depthcounter/DepthCounter.java | 36 +++++++++---------- .../depthcounter/DepthCounterListener.java | 13 ------- 4 files changed, 28 insertions(+), 31 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java index da7f4ee9..6e58f6c6 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java @@ -20,6 +20,7 @@ package de.steamwar.bausystem; import de.steamwar.bausystem.config.ColorConfig; +import de.steamwar.bausystem.configplayer.Config; import de.steamwar.bausystem.linkage.LinkageUtils; import de.steamwar.bausystem.region.loader.PrototypeLoader; import de.steamwar.bausystem.region.loader.RegionLoader; @@ -75,6 +76,7 @@ public class BauSystem extends JavaPlugin implements Listener { LinkageUtils.unlink(); RegionLoader.save(); + Config.getInstance().saveAll(); } private void fixLogging() { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/configplayer/Config.java b/BauSystem_Main/src/de/steamwar/bausystem/configplayer/Config.java index 7ad889c4..bc9cde30 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/configplayer/Config.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/configplayer/Config.java @@ -96,6 +96,14 @@ public class Config implements Listener { return playerConfigurations.get(uuid); } + public void saveAll() { + playerConfigurations.forEach((uuid, yapionObject) -> { + String string = yapionObject.toYAPION(new StringOutput()).getResult(); + UserConfig.updatePlayerConfig(uuid, "bausystem", string); + }); + playerConfigurations.clear(); + } + /** * Save a PlayerConfig, this does not remove the key value mapping from the map. * diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/depthcounter/DepthCounter.java b/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/depthcounter/DepthCounter.java index be963a13..d4194ae9 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/depthcounter/DepthCounter.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/depthcounter/DepthCounter.java @@ -21,10 +21,12 @@ package de.steamwar.bausystem.features.testblock.depthcounter; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.config.ColorConfig; +import de.steamwar.bausystem.configplayer.Config; import de.steamwar.bausystem.region.Region; import lombok.experimental.UtilityClass; import org.bukkit.entity.Player; import org.bukkit.util.Vector; +import yapion.hierarchy.types.YAPIONObject; import java.util.*; import java.util.stream.Collectors; @@ -33,7 +35,8 @@ import java.util.stream.Collectors; public class DepthCounter { public final Map> depthMap = new HashMap<>(); - public final Map> playerSettings = new HashMap<>(); + + private static final YAPIONObject DEFAULT = new YAPIONObject().add("X", "").add("Y", "").add("Z", ""); public void toggleMode(final Player p, final CountMode countMode) { if (isActive(p, countMode)) { @@ -44,35 +47,29 @@ public class DepthCounter { } public boolean isActive(final Player p, final CountMode countMode) { - final Set countModes = playerSettings.get(p); - return countModes != null && countModes.contains(countMode); + return Config.getInstance().get(p).getYAPIONObjectOrSetDefault("depth-counter", (YAPIONObject) DEFAULT.copy()).containsKey(countMode.name()); } public void addMode(final Player p, final CountMode countMode) { - final Set countModes = playerSettings.get(p); - if (countModes != null) { - countModes.add(countMode); - } else { - playerSettings.put(p, new HashSet<>(Collections.singletonList(countMode))); + if (!isActive(p, countMode)) { + Config.getInstance().get(p).getObject("depth-counter").add(countMode.name(), ""); } } public void removeMode(final Player p, final CountMode countMode) { - final Set countModes = playerSettings.get(p); - if (countModes != null) { - countModes.remove(countMode); - if (countModes.isEmpty()) { - removePlayer(p); - } + if (isActive(p, countMode)) { + Config.getInstance().get(p).getObject("depth-counter").remove(countMode.name()); } } public void setModes(final Player p, final Set countModes) { - playerSettings.put(p, countModes); + YAPIONObject yapionObject = new YAPIONObject(); + countModes.forEach(countMode -> yapionObject.put(countMode.name(), "")); + Config.getInstance().get(p).put("depth-counter", yapionObject); } public void removePlayer(final Player p) { - playerSettings.remove(p); + Config.getInstance().get(p).put("depth-counter", new YAPIONObject()); } public Vector blockVector(Vector vector) { @@ -80,8 +77,11 @@ public class DepthCounter { } public Set getModes(Player p) { - final Set countModes = playerSettings.get(p); - return countModes == null ? Collections.emptySet() : countModes.stream().sorted().collect(Collectors.toCollection(LinkedHashSet::new)); + Set countModes = new HashSet<>(); + Config.getInstance().get(p).getYAPIONObjectOrSetDefault("depth-counter", (YAPIONObject) DEFAULT.copy()).forEach((s, yapionAnyType) -> { + countModes.add(CountMode.valueOf(s)); + }); + return countModes.stream().sorted().collect(Collectors.toCollection(LinkedHashSet::new)); } public boolean hasModes(Player p) { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/depthcounter/DepthCounterListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/depthcounter/DepthCounterListener.java index 47f98554..43e52d70 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/depthcounter/DepthCounterListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/depthcounter/DepthCounterListener.java @@ -27,13 +27,10 @@ import de.steamwar.bausystem.region.utils.RegionType; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.entity.EntityExplodeEvent; -import org.bukkit.event.player.PlayerJoinEvent; -import org.bukkit.event.player.PlayerQuitEvent; import java.util.HashSet; import java.util.Set; - @Linked(LinkageType.LISTENER) public class DepthCounterListener implements Listener { @@ -54,14 +51,4 @@ public class DepthCounterListener implements Listener { } depthSet.add(new Depth(region, event.blockList())); } - - @EventHandler - public void onLeave(PlayerQuitEvent event) { - DepthCounter.removePlayer(event.getPlayer()); - } - - @EventHandler - public void onJoin(PlayerJoinEvent event) { - DepthCounter.setModes(event.getPlayer(), CountMode.ALL()); - } } \ No newline at end of file From cef509a9cea47c6763179c168264a958416f3507 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Mon, 24 May 2021 16:18:15 +0200 Subject: [PATCH 08/11] Update DepthCounterListener to count extension area as well Signed-off-by: yoyosource --- .../features/testblock/depthcounter/DepthCounterListener.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/depthcounter/DepthCounterListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/depthcounter/DepthCounterListener.java index 43e52d70..24dc48ad 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/depthcounter/DepthCounterListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/depthcounter/DepthCounterListener.java @@ -42,7 +42,7 @@ public class DepthCounterListener implements Listener { return; } - DepthCounter.depthMap.computeIfAbsent(region, r -> new HashSet<>()); + DepthCounter.depthMap.putIfAbsent(region, new HashSet<>()); Set depthSet = DepthCounter.depthMap.get(region); for (Depth depth : depthSet) { if (depth.update(event.blockList())) { From 7f14d73fe244c1ebe6098ca3ae2efd06c6deea9c Mon Sep 17 00:00:00 2001 From: yoyosource Date: Mon, 24 May 2021 16:30:01 +0200 Subject: [PATCH 09/11] Update InfoCommand Signed-off-by: yoyosource --- BauSystem_Main/src/BauSystem.properties | 1 + .../src/de/steamwar/bausystem/features/bau/InfoCommand.java | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/BauSystem_Main/src/BauSystem.properties b/BauSystem_Main/src/BauSystem.properties index ea4451e7..cb153beb 100644 --- a/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem_Main/src/BauSystem.properties @@ -118,6 +118,7 @@ BAU-INFO_COMMAND_HELP = §8/§ebauinfo §8- §7Gibt Informationen über den Bau BAU-INFO_COMMAND_OWNER = §7Besitzer: §e{0} BAU-INFO_COMMAND_MEMBER = §7Mitglieder: §e BAU-INFO_COMMAND_FLAG = §e{0} §8: §7{1} +BAU-INFO_COMMAND_TPS = TPS:§e # Countingwand COUNTINGWAND_ITEM_NAME = §eZollstock diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/bau/InfoCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/bau/InfoCommand.java index 146b5057..921db9b1 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/bau/InfoCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/bau/InfoCommand.java @@ -63,7 +63,7 @@ public class InfoCommand extends SWCommand { p.sendMessage(membermessage.toString()); StringBuilder tpsMessage = new StringBuilder(); - tpsMessage.append(BauSystem.PREFIX).append("TPS:§e"); + tpsMessage.append(BauSystem.MESSAGE.parsePrefixed("BAU-INFO_COMMAND_TPS", p)); tpsMessage.append(" ").append(getTps(TPSWatcher.TPSType.ONE_SECOND)); tpsMessage.append(" ").append(getTps(TPSWatcher.TPSType.TEN_SECONDS)); if (!TPSWarpUtils.isWarping()) { From a7e14074a95f00434bbf4a99412623cfef88b769 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Mon, 24 May 2021 16:33:32 +0200 Subject: [PATCH 10/11] Update BauSystem.properties Signed-off-by: yoyosource --- BauSystem_Main/src/BauSystem.properties | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/BauSystem_Main/src/BauSystem.properties b/BauSystem_Main/src/BauSystem.properties index cb153beb..9e9f14ef 100644 --- a/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem_Main/src/BauSystem.properties @@ -134,11 +134,11 @@ HOTBAR_LOADED = §7Deine Standard Hotbar wurde geladen HOTBAR_INVENTORY = Standard Hotbar # GUI -GUI_EDITOR_ITEM-NAME=§eGui Editor -GUI_EXPORT_CODE=§eDein Gui-Code: -GUI_EXPORT_CODE-HOVER=§eKopieren -GUI_IMPORT_INVALID-CODE=§eInvalieder Gui-Code -GUI_IMPORT_CODE-SUCCESSFUL=§eGui-Code eingelesen +GUI_EDITOR_ITEM-NAME = §eGui Editor +GUI_EXPORT_CODE = §eDein Gui-Code: +GUI_EXPORT_CODE-HOVER = §eKopieren +GUI_IMPORT_INVALID-CODE = §eInvalieder Gui-Code +GUI_IMPORT_CODE-SUCCESSFUL = §eGui-Code eingelesen # Trace TRACE_RECORD = §aan From 1c2353fab2e190045158320ec6c8f9e60ea0f8ac Mon Sep 17 00:00:00 2001 From: yoyosource Date: Mon, 24 May 2021 17:30:54 +0200 Subject: [PATCH 11/11] Update Detoblock Signed-off-by: yoyosource --- .../features/detonator/Detoblock.java | 33 ++++++++----------- BauSystem_Main/src/BauSystem.properties | 13 ++++++++ .../features/detonator/DetonatorListener.java | 4 +-- .../features/loader/LoaderButton.java | 14 +++----- 4 files changed, 32 insertions(+), 32 deletions(-) diff --git a/BauSystem_API/src/de/steamwar/bausystem/features/detonator/Detoblock.java b/BauSystem_API/src/de/steamwar/bausystem/features/detonator/Detoblock.java index 10163594..f14d8d88 100644 --- a/BauSystem_API/src/de/steamwar/bausystem/features/detonator/Detoblock.java +++ b/BauSystem_API/src/de/steamwar/bausystem/features/detonator/Detoblock.java @@ -21,30 +21,23 @@ package de.steamwar.bausystem.features.detonator; import lombok.AllArgsConstructor; import lombok.Getter; +import lombok.RequiredArgsConstructor; @AllArgsConstructor +@RequiredArgsConstructor +@Getter public enum Detoblock { - SWITCH(0, true, "Hebel"), - WOOD_BUTTON(30, "Knopf"), - STONE_BUTTON(20, "Knopf"), - PRESSURE_PLATE(30, "Druckplatte"), - WEIGHTED_PRESSURE_PLATE(20, "Druckplatte"), - TRIPWIRE(30, "Tripwire"), - NOTEBLOCK(1, "Noteblock"), - DAYLIGHTSENSOR(0, true, "Tageslichtsensor"), - POWERABLE(0, true, "Aktivierbarer Block"), - INVALID(-1, "Invalider"); + SWITCH(0, true, "DETONATOR_BUTTON_SWITCH"), + WOOD_BUTTON(30, "DETONATOR_BUTTON_WOOD-Button"), + STONE_BUTTON(20, "DETONATOR_BUTTON_STONE-Button"), + PRESSURE_PLATE(30, "DETONATOR_BUTTON_PRESSURE-PLATE"), + WEIGHTED_PRESSURE_PLATE(20, "DETONATOR_BUTTON_WEIGHTED-PRESSURE-PLATE"), + TRIPWIRE(30, "DETONATOR_BUTTON_TRIPWIRE"), + NOTEBLOCK(1, "DETONATOR_BUTTON_NOTEBLOCK"), + DAYLIGHTSENSOR(0, true, "DETONATOR_BUTTON_DAYLIGHTSENSOR"), + INVALID(-1, "DETONATOR_BUTTON_INVALID"); - @Getter private final int time; - @Getter - private final boolean toggle; - @Getter + private boolean toggle; private final String name; - - Detoblock(int time, String name) { - this.time = time; - this.name = name; - toggle = false; - } } diff --git a/BauSystem_Main/src/BauSystem.properties b/BauSystem_Main/src/BauSystem.properties index 9e9f14ef..24fa166a 100644 --- a/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem_Main/src/BauSystem.properties @@ -128,6 +128,19 @@ COUNTINGWAND_MESSAGE_R-CLICK = §7Erste Position bei: §8[§7{0}§8, §7{1}§8, COUNTINGWAND_MESSAGE_L-CLICK = §7Zweite Position bei: §8[§7{0}§8, §7{1}§8, §7{2}§8] ({3}) COUNTINGWAND_MESSAGE_DIMENSION = §e{0}§8, §e{1}§8, §e{2} +# Detonator +DETONATOR_LOC_REMOVE = §e{0} entfernt +DETONATOR_LOC_ADD = §e{0} hinzugefügt +DETONATOR_BUTTON_SWITCH = Hebel +DETONATOR_BUTTON_WOOD-Button = Knopf +DETONATOR_BUTTON_STONE-Button = Knopf +DETONATOR_BUTTON_PRESSURE-PLATE = Druckplatte +DETONATOR_BUTTON_WEIGHTED-PRESSURE-PLATE = Druckplatte +DETONATOR_BUTTON_TRIPWIRE = Tripwire +DETONATOR_BUTTON_NOTEBLOCK = Noteblock +DETONATOR_BUTTON_DAYLIGHTSENSOR = Tageslichtsensor +DETONATOR_BUTTON_INVALID = Invalider + # Hotbar HOTBAR_SAVED = §7Deine Hotbar wurde als Standard gespeichert HOTBAR_LOADED = §7Deine Standard Hotbar wurde geladen diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/detonator/DetonatorListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/detonator/DetonatorListener.java index 593708d4..48be9e53 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/detonator/DetonatorListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/detonator/DetonatorListener.java @@ -89,10 +89,10 @@ public class DetonatorListener implements Listener { } if (detonator.getLocations().contains(location)) { detonator.removeLocation(location); - SWUtils.sendToActionbar(p, ColorConfig.HIGHLIGHT + detoblock.getName() + " entfernt"); + SWUtils.sendToActionbar(p, BauSystem.MESSAGE.parse("DETONATOR_LOC_REMOVE", p, BauSystem.MESSAGE.parse(detoblock.getName(), p))); } else { detonator.addLocation(location); - SWUtils.sendToActionbar(p, ColorConfig.HIGHLIGHT + detoblock.getName() + " hinzugefügt"); + SWUtils.sendToActionbar(p, BauSystem.MESSAGE.parse("DETONATOR_LOC_ADD", p, BauSystem.MESSAGE.parse(detoblock.getName(), p))); } detonator.write(); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderButton.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderButton.java index dc1804c4..331954b3 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderButton.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderButton.java @@ -21,9 +21,12 @@ package de.steamwar.bausystem.features.loader; import lombok.AllArgsConstructor; import lombok.Getter; +import lombok.RequiredArgsConstructor; import org.bukkit.block.Block; @AllArgsConstructor +@RequiredArgsConstructor +@Getter public enum LoaderButton { SWITCH(0, true, "LOADER_BUTTON_SWITCH"), WOOD_BUTTON(30, "LOADER_BUTTON_WOOD-Button"), @@ -35,19 +38,10 @@ public enum LoaderButton { DAYLIGHTSENSOR(0, true, "LOADER_BUTTON_DAYLIGHTSENSOR"), INVALID(-1, "LOADER_BUTTON_INVALID"); - @Getter private final int time; - @Getter - private final boolean toggle; - @Getter + private boolean toggle; private final String name; - LoaderButton(int time, String name) { - this.time = time; - this.name = name; - toggle = false; - } - public static LoaderButton fromBlock(Block block) { switch (block.getType()) { case LEVER: