SteamWar/BauSystem2.0
Archiviert
12
0

Update PrototypeLoader and RegionLoader to DiffSystem

Dieser Commit ist enthalten in:
yoyosource 2021-05-09 17:29:44 +02:00
Ursprung 90026b8903
Commit b61138efee
2 geänderte Dateien mit 10 neuen und 8 gelöschten Zeilen

Datei anzeigen

@ -22,6 +22,8 @@ package de.steamwar.bausystem.region.loader;
import de.steamwar.bausystem.region.Prototype; import de.steamwar.bausystem.region.Prototype;
import lombok.experimental.UtilityClass; import lombok.experimental.UtilityClass;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import yapion.hierarchy.diff.DiffBase;
import yapion.hierarchy.diff.YAPIONDiff;
import yapion.hierarchy.types.YAPIONObject; import yapion.hierarchy.types.YAPIONObject;
import yapion.parser.YAPIONParser; import yapion.parser.YAPIONParser;
@ -33,7 +35,7 @@ import java.io.IOException;
@UtilityClass @UtilityClass
public class PrototypeLoader { 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 static final File file = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "prototypes.yapion");
public void load() { public void load() {
@ -44,11 +46,10 @@ public class PrototypeLoader {
throw new SecurityException(e.getMessage(), e); throw new SecurityException(e.getMessage(), e);
} }
int currentVersion = yapionObject.getPlainValueOrDefault("@version", -1); if (loaded != null && new YAPIONDiff(loaded, yapionObject).getDiffs().stream().anyMatch(diffBase -> !(diffBase instanceof DiffBase.DiffChange))) {
if (currentVersion != loadedVersion && loadedVersion != 0) {
throw new SecurityException("Version was not the specified version needed."); throw new SecurityException("Version was not the specified version needed.");
} }
loadedVersion = currentVersion; loaded = yapionObject;
yapionObject.forEach((key, yapionAnyType) -> { yapionObject.forEach((key, yapionAnyType) -> {
if (yapionAnyType instanceof YAPIONObject) { if (yapionAnyType instanceof YAPIONObject) {

Datei anzeigen

@ -24,6 +24,8 @@ import de.steamwar.bausystem.region.GlobalRegion;
import de.steamwar.bausystem.region.Prototype; import de.steamwar.bausystem.region.Prototype;
import lombok.experimental.UtilityClass; import lombok.experimental.UtilityClass;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import yapion.hierarchy.diff.DiffBase;
import yapion.hierarchy.diff.YAPIONDiff;
import yapion.hierarchy.output.FileOutput; import yapion.hierarchy.output.FileOutput;
import yapion.hierarchy.types.YAPIONObject; import yapion.hierarchy.types.YAPIONObject;
import yapion.hierarchy.types.YAPIONType; import yapion.hierarchy.types.YAPIONType;
@ -37,7 +39,7 @@ import java.io.IOException;
@UtilityClass @UtilityClass
public class RegionLoader { public class RegionLoader {
private int loadedVersion = 0; private YAPIONObject loaded = null;
private YAPIONObject optionsYapionObject; private YAPIONObject optionsYapionObject;
public static final File file = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "regions.yapion"); 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); throw new SecurityException(e.getMessage(), e);
} }
int currentVersion = yapionObject.getPlainValueOrDefault("@version", -1); if (loaded != null && new YAPIONDiff(loaded, yapionObject).getDiffs().stream().anyMatch(diffBase -> !(diffBase instanceof DiffBase.DiffChange))) {
if (currentVersion != loadedVersion && loadedVersion != 0) {
throw new SecurityException("Version was not the specified version needed."); 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"); File optionsFile = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "options.yapion");
optionsYapionObject = new YAPIONObject(); optionsYapionObject = new YAPIONObject();