SteamWar/BauSystem2.0
Archiviert
12
0

Add RegionLoader.save

Dieser Commit ist enthalten in:
yoyosource 2021-04-18 18:37:32 +02:00
Ursprung 1c1ed8cdf7
Commit bdeaa67383
5 geänderte Dateien mit 45 neuen und 9 gelöschten Zeilen

Datei anzeigen

@ -48,5 +48,7 @@ public class BauSystem extends JavaPlugin implements Listener {
@Override
public void onDisable() {
LinkageUtils.unlink();
RegionLoader.save();
}
}

Datei anzeigen

@ -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;
}

Datei anzeigen

@ -150,7 +150,7 @@ public class Prototype {
} else {
flagStorage = new FlagStorage();
}
return new Region(prototype, regionConfig, flagStorage);
return new Region(prototype, regionConfig, flagStorage, regionData);
}
}

Datei anzeigen

@ -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<Prototype> 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 <T extends Enum<T> & Flag.Value<T>> Flag.Value<T> get(Flag flagType) {
return flagStorage.get(flagType);
}
}

Datei anzeigen

@ -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);
}
}