From 63c376fd4ed45ba5c1749c857b5568c52f2e73ea Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 18 Apr 2021 18:21:34 +0200 Subject: [PATCH 1/4] Fix Region.generatePrototypeData --- BauSystem_Main/src/de/steamwar/bausystem/region/Region.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java b/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java index 17ba6b10..e06b8006 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java @@ -90,7 +90,7 @@ public class Region { return; } - if (!prototypes.contains(prototype)) { + if (this.prototype != null && !prototypes.contains(prototype)) { return; } this.prototype = prototype; From 1c1ed8cdf71e42902d5f6dfe8b74a24afedb79ce Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 18 Apr 2021 18:27:54 +0200 Subject: [PATCH 2/4] Fix Region.generatePrototypeData --- .../de/steamwar/bausystem/region/Region.java | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java b/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java index e06b8006..fdd814f7 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java @@ -82,7 +82,11 @@ public class Region { }); } this.flagStorage = flagStorage; - generatePrototypeData(prototype, regionConfig.getPlainValue("minPoint")); + Point point = null; + if (regionConfig.containsKey("minX", Integer.class) && regionConfig.containsKey("minY", Integer.class) && regionConfig.containsKey("minZ", Integer.class)) { + point = new Point(regionConfig.getPlainValue("minX"), regionConfig.getPlainValue("minY"), regionConfig.getPlainValue("minZ")); + } + generatePrototypeData(prototype, point); } private void generatePrototypeData(Prototype prototype, Point point) { @@ -98,17 +102,21 @@ public class Region { this.minPoint = point; this.maxPoint = point.add(prototype.getSizeX(), prototype.getSizeY(), prototype.getSizeZ()); - this.minPointTestblock = point.add(prototype.getTestblock().getOffsetX(), prototype.getTestblock().getOffsetY(), prototype.getTestblock().getOffsetZ()); - this.maxPointTestblock = this.minPointTestblock.add(prototype.getTestblock().getSizeX(), prototype.getTestblock().getSizeY(), prototype.getTestblock().getSizeZ()); + if (prototype.getTestblock() != null) { + this.minPointTestblock = point.add(prototype.getTestblock().getOffsetX(), prototype.getTestblock().getOffsetY(), prototype.getTestblock().getOffsetZ()); + this.maxPointTestblock = this.minPointTestblock.add(prototype.getTestblock().getSizeX(), prototype.getTestblock().getSizeY(), prototype.getTestblock().getSizeZ()); - this.minPointTestblockExtension = this.minPointTestblock.substract(prototype.getTestblock().getExtensionNegativeX(), prototype.getTestblock().getExtensionNegativeY(), prototype.getTestblock().getExtensionNegativeZ()); - this.maxPointTestblockExtension = this.maxPointTestblock.add(prototype.getTestblock().getExtensionPositiveX(), prototype.getTestblock().getExtensionPositiveY(), prototype.getTestblock().getExtensionPositiveZ()); + this.minPointTestblockExtension = this.minPointTestblock.substract(prototype.getTestblock().getExtensionNegativeX(), prototype.getTestblock().getExtensionNegativeY(), prototype.getTestblock().getExtensionNegativeZ()); + this.maxPointTestblockExtension = this.maxPointTestblock.add(prototype.getTestblock().getExtensionPositiveX(), prototype.getTestblock().getExtensionPositiveY(), prototype.getTestblock().getExtensionPositiveZ()); + } - this.minPointBuild = point.add(prototype.getBuild().getOffsetX(), prototype.getBuild().getOffsetY(), prototype.getBuild().getOffsetZ()); - this.maxPointBuild = this.minPointBuild.add(prototype.getBuild().getSizeX(), prototype.getBuild().getSizeY(), prototype.getBuild().getSizeZ()); + if (prototype.getBuild() != null) { + this.minPointBuild = point.add(prototype.getBuild().getOffsetX(), prototype.getBuild().getOffsetY(), prototype.getBuild().getOffsetZ()); + this.maxPointBuild = this.minPointBuild.add(prototype.getBuild().getSizeX(), prototype.getBuild().getSizeY(), prototype.getBuild().getSizeZ()); - this.minPointBuildExtension = this.minPointBuild.substract(prototype.getBuild().getExtensionNegativeX(), prototype.getBuild().getExtensionNegativeY(), prototype.getBuild().getExtensionNegativeZ()); - this.maxPointBuildExtension = this.maxPointBuild.add(prototype.getBuild().getExtensionPositiveX(), prototype.getBuild().getExtensionPositiveY(), prototype.getBuild().getExtensionPositiveZ()); + this.minPointBuildExtension = this.minPointBuild.substract(prototype.getBuild().getExtensionNegativeX(), prototype.getBuild().getExtensionNegativeY(), prototype.getBuild().getExtensionNegativeZ()); + this.maxPointBuildExtension = this.maxPointBuild.add(prototype.getBuild().getExtensionPositiveX(), prototype.getBuild().getExtensionPositiveY(), prototype.getBuild().getExtensionPositiveZ()); + } } public boolean inRegion(Location location, RegionType regionType, RegionExtensionType regionExtensionType) { From bdeaa673839ef4b92f767eeec55fa8efea94d02f Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 18 Apr 2021 18:37:32 +0200 Subject: [PATCH 3/4] Add RegionLoader.save --- .../src/de/steamwar/bausystem/BauSystem.java | 2 ++ .../bausystem/region/GlobalRegion.java | 4 +-- .../steamwar/bausystem/region/Prototype.java | 2 +- .../de/steamwar/bausystem/region/Region.java | 26 ++++++++++++++++++- .../bausystem/region/loader/RegionLoader.java | 20 ++++++++++---- 5 files changed, 45 insertions(+), 9 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java index 2dcb4ac7..f9042ec1 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java @@ -48,5 +48,7 @@ public class BauSystem extends JavaPlugin implements Listener { @Override public void onDisable() { LinkageUtils.unlink(); + + RegionLoader.save(); } } \ No newline at end of file diff --git a/BauSystem_Main/src/de/steamwar/bausystem/region/GlobalRegion.java b/BauSystem_Main/src/de/steamwar/bausystem/region/GlobalRegion.java index cae2bec9..5f236e85 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/region/GlobalRegion.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/region/GlobalRegion.java @@ -30,8 +30,8 @@ public class GlobalRegion extends Region { @Getter static GlobalRegion instance; - public GlobalRegion(FlagStorage flagStorage) { - super(null, new YAPIONObject(), flagStorage); + public GlobalRegion(FlagStorage flagStorage, YAPIONObject regionData) { + super(null, new YAPIONObject(), flagStorage, regionData); instance = this; } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/region/Prototype.java b/BauSystem_Main/src/de/steamwar/bausystem/region/Prototype.java index b57c0b0a..31ce8786 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/region/Prototype.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/region/Prototype.java @@ -150,7 +150,7 @@ public class Prototype { } else { flagStorage = new FlagStorage(); } - return new Region(prototype, regionConfig, flagStorage); + return new Region(prototype, regionConfig, flagStorage, regionData); } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java b/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java index fdd814f7..503e5334 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java @@ -19,13 +19,16 @@ package de.steamwar.bausystem.region; +import de.steamwar.bausystem.region.flags.Flag; import de.steamwar.bausystem.region.utils.RegionExtensionType; import de.steamwar.bausystem.region.utils.RegionType; import lombok.Getter; +import lombok.NonNull; import org.bukkit.Location; import yapion.hierarchy.types.YAPIONObject; import yapion.hierarchy.types.YAPIONType; import yapion.hierarchy.types.YAPIONValue; +import yapion.serializing.YAPIONSerializer; import java.util.ArrayList; import java.util.HashSet; @@ -46,6 +49,8 @@ public class Region { return GlobalRegion.instance; } + private YAPIONObject regionData; + private Prototype prototype; private Set prototypes; @@ -68,7 +73,8 @@ public class Region { private FlagStorage flagStorage; - public Region(Prototype prototype, YAPIONObject regionConfig, FlagStorage flagStorage) { + public Region(Prototype prototype, YAPIONObject regionConfig, FlagStorage flagStorage, YAPIONObject regionData) { + this.regionData = regionData; if (prototype != null) { REGION_LIST.add(this); } @@ -159,4 +165,22 @@ public class Region { public String getDisplayName() { return prototype != null ? prototype.getDisplayName() : ""; } + + public void setPrototype(@NonNull Prototype prototype) { + if (this.prototype == null) { + return; + } + regionData.add("prototype", prototype.getName()); + generatePrototypeData(prototype, minPoint); + } + + public void set(Flag flagType, Flag.Value value) { + if (flagStorage.set(flagType, value)) { + regionData.add("flagStorage", YAPIONSerializer.serialize(flagStorage)); + } + } + + public & Flag.Value> Flag.Value get(Flag flagType) { + return flagStorage.get(flagType); + } } \ No newline at end of file diff --git a/BauSystem_Main/src/de/steamwar/bausystem/region/loader/RegionLoader.java b/BauSystem_Main/src/de/steamwar/bausystem/region/loader/RegionLoader.java index 4dbb33ef..19f86a56 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/region/loader/RegionLoader.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/region/loader/RegionLoader.java @@ -24,6 +24,7 @@ import de.steamwar.bausystem.region.GlobalRegion; import de.steamwar.bausystem.region.Prototype; import lombok.experimental.UtilityClass; import org.bukkit.Bukkit; +import yapion.hierarchy.output.FileOutput; import yapion.hierarchy.types.YAPIONObject; import yapion.hierarchy.types.YAPIONType; import yapion.parser.YAPIONParser; @@ -38,6 +39,16 @@ import java.util.logging.Level; @UtilityClass public class RegionLoader { + private YAPIONObject optionsYapionObject; + + public void save() { + try { + optionsYapionObject.toYAPION(new FileOutput(new File(Bukkit.getWorlds().get(0).getWorldFolder(), "options.yapion"))).close(); + } catch (IOException e) { + // Ignored + } + } + public void load() { File file = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "regions.yapion"); YAPIONObject yapionObject = null; @@ -50,14 +61,13 @@ public class RegionLoader { } File optionsFile = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "options.yapion"); - YAPIONObject optionsYapionObject = new YAPIONObject(); + optionsYapionObject = new YAPIONObject(); try (BufferedInputStream bufferedInputStream = new BufferedInputStream(new FileInputStream(optionsFile))) { optionsYapionObject = YAPIONParser.parse(bufferedInputStream); } catch (IOException e) { // Ignored } - YAPIONObject finalOptionsYapionObject = optionsYapionObject; yapionObject.forEach((key, yapionAnyType) -> { if (key.equals("global")) { return; @@ -68,8 +78,8 @@ public class RegionLoader { YAPIONObject regionConfig = (YAPIONObject) yapionAnyType; YAPIONObject regionData = new YAPIONObject(); - if (finalOptionsYapionObject.containsKey(key, YAPIONType.OBJECT)) { - regionData = finalOptionsYapionObject.getObject(key); + if (optionsYapionObject.containsKey(key, YAPIONType.OBJECT)) { + regionData = optionsYapionObject.getObject(key); } Prototype.generateRegion(regionConfig, regionData); @@ -82,6 +92,6 @@ public class RegionLoader { } else { flagStorage = new FlagStorage(); } - new GlobalRegion(flagStorage); + new GlobalRegion(flagStorage, globalOptions); } } From c77e0007523419cae46a0c96b4153353d4794ba6 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 18 Apr 2021 18:43:14 +0200 Subject: [PATCH 4/4] Add RegionLoader.save --- .../de/steamwar/bausystem/region/loader/RegionLoader.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/region/loader/RegionLoader.java b/BauSystem_Main/src/de/steamwar/bausystem/region/loader/RegionLoader.java index 19f86a56..5bd0ce7a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/region/loader/RegionLoader.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/region/loader/RegionLoader.java @@ -80,14 +80,20 @@ public class RegionLoader { YAPIONObject regionData = new YAPIONObject(); if (optionsYapionObject.containsKey(key, YAPIONType.OBJECT)) { regionData = optionsYapionObject.getObject(key); + } else { + optionsYapionObject.add(key, regionData); } Prototype.generateRegion(regionConfig, regionData); }); YAPIONObject globalOptions = optionsYapionObject.getObject("global"); + if (globalOptions == null) { + globalOptions = new YAPIONObject(); + optionsYapionObject.add("global", globalOptions); + } FlagStorage flagStorage; - if (globalOptions != null && globalOptions.containsKey("flagStorage", YAPIONType.OBJECT)) { + if (globalOptions.containsKey("flagStorage", YAPIONType.OBJECT)) { flagStorage = (FlagStorage) YAPIONDeserializer.deserialize(globalOptions.getObject("flagStorage")); } else { flagStorage = new FlagStorage();