diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/flags/Flag.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/flags/Flag.java index 2be75d1f..305d046c 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/flags/Flag.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/flags/Flag.java @@ -21,6 +21,7 @@ package de.steamwar.bausystem.region.flags; import de.steamwar.bausystem.shared.EnumDisplay; import lombok.Getter; +import lombok.NonNull; import java.util.HashSet; import java.util.Set; @@ -70,6 +71,24 @@ public final class Flag & Flag.Value> implements EnumDispla this.values = defaultValue.getValues(); } + public static Flag valueOf(@NonNull String name) { + for (Flag flag : flags) { + if (flag.name.equalsIgnoreCase(name)) { + return flag; + } + } + throw new IllegalArgumentException("No enum constant Flag." + name); + } + + public Flag.Value valueOfValue(@NonNull String name) { + for (Flag.Value value : values) { + if (value.name().equalsIgnoreCase(name)) { + return value; + } + } + throw new IllegalArgumentException("No enum constant Flag." + this.name + "." + name); + } + public String name() { return name; } diff --git a/BauSystem/BauSystem_RegionFixed/src/de/steamwar/bausystem/region/FixedRegionSystem.java b/BauSystem/BauSystem_RegionFixed/src/de/steamwar/bausystem/region/FixedRegionSystem.java index f9ca3d13..68f3cd18 100644 --- a/BauSystem/BauSystem_RegionFixed/src/de/steamwar/bausystem/region/FixedRegionSystem.java +++ b/BauSystem/BauSystem_RegionFixed/src/de/steamwar/bausystem/region/FixedRegionSystem.java @@ -20,6 +20,8 @@ package de.steamwar.bausystem.region; import de.steamwar.bausystem.region.fixed.FixedGlobalRegion; +import de.steamwar.bausystem.region.fixed.loader.PrototypeLoader; +import de.steamwar.bausystem.region.fixed.loader.RegionLoader; import lombok.NonNull; import org.bukkit.Location; @@ -35,12 +37,12 @@ public class FixedRegionSystem implements RegionSystem { @Override public void load() { - // TODO: Implement + PrototypeLoader.load(); + RegionLoader.load(); } @Override public void save() { - // TODO: Implement } @Override diff --git a/BauSystem/BauSystem_RegionFixed/src/de/steamwar/bausystem/region/fixed/FixedGlobalFlagStorage.java b/BauSystem/BauSystem_RegionFixed/src/de/steamwar/bausystem/region/fixed/FixedGlobalFlagStorage.java index acf9975a..910483cb 100644 --- a/BauSystem/BauSystem_RegionFixed/src/de/steamwar/bausystem/region/fixed/FixedGlobalFlagStorage.java +++ b/BauSystem/BauSystem_RegionFixed/src/de/steamwar/bausystem/region/fixed/FixedGlobalFlagStorage.java @@ -26,8 +26,10 @@ import de.steamwar.bausystem.region.flags.ColorMode; import de.steamwar.bausystem.region.flags.Flag; import de.steamwar.bausystem.region.flags.ProtectMode; import de.steamwar.bausystem.region.flags.TNTMode; +import de.steamwar.bausystem.worlddata.WorldData; import de.steamwar.core.Core; import lombok.NonNull; +import yapion.hierarchy.types.YAPIONObject; import java.util.HashMap; import java.util.Map; @@ -35,9 +37,20 @@ import java.util.Map; public class FixedGlobalFlagStorage implements FlagStorage { private Map, Flag.Value> flagMap = new HashMap<>(); + private YAPIONObject data; - public FixedGlobalFlagStorage() { + public FixedGlobalFlagStorage(YAPIONObject data) { flagMap.put(Flag.TNT, TNTMode.DENY); + this.data = data; + for (final Flag flag : Flag.getFlags()) { + if (!has(flag).isWritable()) continue; + try { + String s = data.getPlainValue(flag.name()); + flagMap.put(flag, flag.valueOfValue(s)); + } catch (Exception e) { + flagMap.put(flag, (Flag.Value) flag.getDefaultValue()); + } + } } @Override @@ -57,6 +70,8 @@ public class FixedGlobalFlagStorage implements FlagStorage { @Override public & Flag.Value> boolean set(@NonNull Flag flag, @NonNull T value) { if (has(flag).isWritable()) { + data.put(flag.name(), value.name()); + WorldData.write(); return flagMap.put(flag, value) != value; } else { return false; diff --git a/BauSystem/BauSystem_RegionFixed/src/de/steamwar/bausystem/region/fixed/FixedGlobalRegion.java b/BauSystem/BauSystem_RegionFixed/src/de/steamwar/bausystem/region/fixed/FixedGlobalRegion.java index 3dbcbdd4..9204489e 100644 --- a/BauSystem/BauSystem_RegionFixed/src/de/steamwar/bausystem/region/fixed/FixedGlobalRegion.java +++ b/BauSystem/BauSystem_RegionFixed/src/de/steamwar/bausystem/region/fixed/FixedGlobalRegion.java @@ -23,6 +23,7 @@ import com.sk89q.worldedit.EditSession; import de.steamwar.bausystem.region.*; import de.steamwar.bausystem.utils.PasteBuilder; import lombok.NonNull; +import lombok.Setter; import org.bukkit.Location; import javax.annotation.Nullable; @@ -37,7 +38,8 @@ public final class FixedGlobalRegion implements Region { private static final Point MIN_POINT = new Point(Integer.MIN_VALUE, Integer.MIN_VALUE, Integer.MIN_VALUE); private static final Point MAX_POINT = new Point(Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE); - private static final FlagStorage FLAG_STORAGE = new FixedGlobalFlagStorage(); + @Setter + private static FlagStorage FLAG_STORAGE; private static final UUID GLOBAL_REGION_ID = new UUID(0, 0); diff --git a/BauSystem/BauSystem_RegionFixed/src/de/steamwar/bausystem/region/fixed/Prototype.java b/BauSystem/BauSystem_RegionFixed/src/de/steamwar/bausystem/region/fixed/Prototype.java index 962d9a19..2569b03c 100644 --- a/BauSystem/BauSystem_RegionFixed/src/de/steamwar/bausystem/region/fixed/Prototype.java +++ b/BauSystem/BauSystem_RegionFixed/src/de/steamwar/bausystem/region/fixed/Prototype.java @@ -127,11 +127,11 @@ public class Prototype { skinMap.put(displayName, new Skin(defaultSkin, null, schematicFile, testblockSchematicFile, buildSchematicFile)); } - if (PROTOTYPE_MAP.containsKey(name)) { - Region.getRegion(PROTOTYPE_MAP.remove(name)).forEach(region -> { - region._setPrototype(this); - }); - } + // if (PROTOTYPE_MAP.containsKey(name)) { + // Region.getRegion(PROTOTYPE_MAP.remove(name)).forEach(region -> { + // region._setPrototype(this); + // }); + // } PROTOTYPE_MAP.put(name, this); } @@ -210,19 +210,20 @@ public class Prototype { } } - public static Region generateRegion(String name, YAPIONObject regionConfig, YAPIONObject regionData) { + public static void generateRegion(String name, YAPIONObject regionConfig, YAPIONObject regionData) { Prototype prototype; if (regionData.containsKey("prototype", String.class)) { prototype = PROTOTYPE_MAP.get(regionData.getPlainValue("prototype")); } else { prototype = PROTOTYPE_MAP.get(regionConfig.getPlainValue("prototype")); } - FlagStorage flagStorage; - if (regionData.containsKey("flagStorage", YAPIONType.OBJECT)) { - flagStorage = FlagStorage.createStorage(regionData.getObject("flagStorage")); - } else { - flagStorage = new FlagStorage(); - } - return new Region(name, prototype, regionConfig, flagStorage, regionData); + System.out.println(name + " " + prototype); + // FlagStorage flagStorage; + // if (regionData.containsKey("flagStorage", YAPIONType.OBJECT)) { + // flagStorage = FlagStorage.createStorage(regionData.getObject("flagStorage")); + // } else { + // flagStorage = new FlagStorage(); + // } + // return new Region(name, prototype, regionConfig, flagStorage, regionData); } } diff --git a/BauSystem/BauSystem_RegionFixed/src/de/steamwar/bausystem/regionold/loader/PrototypeLoader.java.txt b/BauSystem/BauSystem_RegionFixed/src/de/steamwar/bausystem/region/fixed/loader/PrototypeLoader.java similarity index 95% rename from BauSystem/BauSystem_RegionFixed/src/de/steamwar/bausystem/regionold/loader/PrototypeLoader.java.txt rename to BauSystem/BauSystem_RegionFixed/src/de/steamwar/bausystem/region/fixed/loader/PrototypeLoader.java index 001ab702..3bcdefff 100644 --- a/BauSystem/BauSystem_RegionFixed/src/de/steamwar/bausystem/regionold/loader/PrototypeLoader.java.txt +++ b/BauSystem/BauSystem_RegionFixed/src/de/steamwar/bausystem/region/fixed/loader/PrototypeLoader.java @@ -1,7 +1,7 @@ /* * This file is a part of the SteamWar software. * - * Copyright (C) 2021 SteamWar.de-Serverteam + * Copyright (C) 2020 SteamWar.de-Serverteam * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -package de.steamwar.bausystem.region.loader; +package de.steamwar.bausystem.region.fixed.loader; import de.steamwar.bausystem.region.fixed.Prototype; import lombok.experimental.UtilityClass; diff --git a/BauSystem/BauSystem_RegionFixed/src/de/steamwar/bausystem/regionold/loader/RegionLoader.java.txt b/BauSystem/BauSystem_RegionFixed/src/de/steamwar/bausystem/region/fixed/loader/RegionLoader.java similarity index 85% rename from BauSystem/BauSystem_RegionFixed/src/de/steamwar/bausystem/regionold/loader/RegionLoader.java.txt rename to BauSystem/BauSystem_RegionFixed/src/de/steamwar/bausystem/region/fixed/loader/RegionLoader.java index 0fe7a16f..e88c24e6 100644 --- a/BauSystem/BauSystem_RegionFixed/src/de/steamwar/bausystem/regionold/loader/RegionLoader.java.txt +++ b/BauSystem/BauSystem_RegionFixed/src/de/steamwar/bausystem/region/fixed/loader/RegionLoader.java @@ -1,7 +1,7 @@ /* * This file is a part of the SteamWar software. * - * Copyright (C) 2021 SteamWar.de-Serverteam + * Copyright (C) 2020 SteamWar.de-Serverteam * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -17,10 +17,10 @@ * along with this program. If not, see . */ -package de.steamwar.bausystem.region.loader; +package de.steamwar.bausystem.region.fixed.loader; -import de.steamwar.bausystem.region.FlagStorage; -import de.steamwar.bausystem.region.GlobalRegion; +import de.steamwar.bausystem.region.fixed.FixedGlobalFlagStorage; +import de.steamwar.bausystem.region.fixed.FixedGlobalRegion; import de.steamwar.bausystem.region.fixed.Prototype; import de.steamwar.bausystem.worlddata.WorldData; import lombok.experimental.UtilityClass; @@ -80,12 +80,6 @@ public class RegionLoader { globalOptions = new YAPIONObject(); optionsYapionObject.add("global", globalOptions); } - FlagStorage flagStorage; - if (globalOptions.containsKey("flagStorage", YAPIONType.OBJECT)) { - flagStorage = FlagStorage.createStorage(globalOptions.getObject("flagStorage")); - } else { - flagStorage = new FlagStorage(); - } - new GlobalRegion(flagStorage, globalOptions); + FixedGlobalRegion.setFLAG_STORAGE(new FixedGlobalFlagStorage(globalOptions.getObjectOrSetDefault("flagStorage", new YAPIONObject()))); } }