From b61138efee2f04f4372c0f36e8ec27da5a16d7d5 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 9 May 2021 17:29:44 +0200 Subject: [PATCH] Update PrototypeLoader and RegionLoader to DiffSystem --- .../bausystem/region/loader/PrototypeLoader.java | 9 +++++---- .../steamwar/bausystem/region/loader/RegionLoader.java | 9 +++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/region/loader/PrototypeLoader.java b/BauSystem_Main/src/de/steamwar/bausystem/region/loader/PrototypeLoader.java index 199c2875..6324fff8 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/region/loader/PrototypeLoader.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/region/loader/PrototypeLoader.java @@ -22,6 +22,8 @@ package de.steamwar.bausystem.region.loader; import de.steamwar.bausystem.region.Prototype; import lombok.experimental.UtilityClass; import org.bukkit.Bukkit; +import yapion.hierarchy.diff.DiffBase; +import yapion.hierarchy.diff.YAPIONDiff; import yapion.hierarchy.types.YAPIONObject; import yapion.parser.YAPIONParser; @@ -33,7 +35,7 @@ import java.io.IOException; @UtilityClass public class PrototypeLoader { - private int loadedVersion = 0; + private YAPIONObject loaded = null; public static final File file = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "prototypes.yapion"); public void load() { @@ -44,11 +46,10 @@ public class PrototypeLoader { throw new SecurityException(e.getMessage(), e); } - int currentVersion = yapionObject.getPlainValueOrDefault("@version", -1); - if (currentVersion != loadedVersion && loadedVersion != 0) { + if (loaded != null && new YAPIONDiff(loaded, yapionObject).getDiffs().stream().anyMatch(diffBase -> !(diffBase instanceof DiffBase.DiffChange))) { throw new SecurityException("Version was not the specified version needed."); } - loadedVersion = currentVersion; + loaded = yapionObject; yapionObject.forEach((key, yapionAnyType) -> { if (yapionAnyType instanceof YAPIONObject) { 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 8d78cbf3..cbe1b3f4 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,8 @@ import de.steamwar.bausystem.region.GlobalRegion; import de.steamwar.bausystem.region.Prototype; import lombok.experimental.UtilityClass; import org.bukkit.Bukkit; +import yapion.hierarchy.diff.DiffBase; +import yapion.hierarchy.diff.YAPIONDiff; import yapion.hierarchy.output.FileOutput; import yapion.hierarchy.types.YAPIONObject; import yapion.hierarchy.types.YAPIONType; @@ -37,7 +39,7 @@ import java.io.IOException; @UtilityClass public class RegionLoader { - private int loadedVersion = 0; + private YAPIONObject loaded = null; private YAPIONObject optionsYapionObject; public static final File file = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "regions.yapion"); @@ -57,11 +59,10 @@ public class RegionLoader { throw new SecurityException(e.getMessage(), e); } - int currentVersion = yapionObject.getPlainValueOrDefault("@version", -1); - if (currentVersion != loadedVersion && loadedVersion != 0) { + if (loaded != null && new YAPIONDiff(loaded, yapionObject).getDiffs().stream().anyMatch(diffBase -> !(diffBase instanceof DiffBase.DiffChange))) { throw new SecurityException("Version was not the specified version needed."); } - loadedVersion = currentVersion; + loaded = yapionObject; File optionsFile = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "options.yapion"); optionsYapionObject = new YAPIONObject();