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 ba8e3b98..a7845009 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 @@ -127,17 +128,30 @@ 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 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 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/configplayer/serializer/ConfigurationSerializableSerializer.java b/BauSystem_Main/src/de/steamwar/bausystem/configplayer/serializer/ConfigurationSerializableSerializer.java index 50599ff8..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,11 +21,15 @@ 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; import yapion.serializing.data.DeserializeData; import yapion.serializing.data.SerializeData; +import java.util.ArrayList; import java.util.HashMap; import java.util.Map; @@ -46,10 +50,23 @@ 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) -> { - 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; } @@ -58,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/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"); } 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/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()) { 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")); + } } 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/hotbar/DefaultHotbar.java b/BauSystem_Main/src/de/steamwar/bausystem/features/hotbar/DefaultHotbar.java index abbec165..e0808857 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.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]; 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; } } 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()); } 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: 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..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,20 +21,22 @@ 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.function.DoubleBinaryOperator; import java.util.stream.Collectors; @UtilityClass 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)) { @@ -45,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) { @@ -81,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 99778878..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 @@ -27,28 +27,22 @@ 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 { @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.putIfAbsent(region, new HashSet<>()); Set depthSet = DepthCounter.depthMap.get(region); for (Depth depth : depthSet) { if (depth.update(event.blockList())) { @@ -57,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