SteamWar/BauSystem2.0
Archiviert
12
0

Merge remote-tracking branch 'origin/master'

Dieser Commit ist enthalten in:
Zeanon 2021-04-18 18:48:04 +02:00
Commit 8e739d17c8
5 geänderte Dateien mit 70 neuen und 20 gelöschten Zeilen

Datei anzeigen

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

Datei anzeigen

@ -30,8 +30,8 @@ public class GlobalRegion extends Region {
@Getter @Getter
static GlobalRegion instance; static GlobalRegion instance;
public GlobalRegion(FlagStorage flagStorage) { public GlobalRegion(FlagStorage flagStorage, YAPIONObject regionData) {
super(null, new YAPIONObject(), flagStorage); super(null, new YAPIONObject(), flagStorage, regionData);
instance = this; instance = this;
} }

Datei anzeigen

@ -150,7 +150,7 @@ public class Prototype {
} else { } else {
flagStorage = new FlagStorage(); 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; 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.RegionExtensionType;
import de.steamwar.bausystem.region.utils.RegionType; import de.steamwar.bausystem.region.utils.RegionType;
import lombok.Getter; import lombok.Getter;
import lombok.NonNull;
import org.bukkit.Location; import org.bukkit.Location;
import yapion.hierarchy.types.YAPIONObject; import yapion.hierarchy.types.YAPIONObject;
import yapion.hierarchy.types.YAPIONType; import yapion.hierarchy.types.YAPIONType;
import yapion.hierarchy.types.YAPIONValue; import yapion.hierarchy.types.YAPIONValue;
import yapion.serializing.YAPIONSerializer;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
@ -46,6 +49,8 @@ public class Region {
return GlobalRegion.instance; return GlobalRegion.instance;
} }
private YAPIONObject regionData;
private Prototype prototype; private Prototype prototype;
private Set<Prototype> prototypes; private Set<Prototype> prototypes;
@ -68,7 +73,8 @@ public class Region {
private FlagStorage flagStorage; 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) { if (prototype != null) {
REGION_LIST.add(this); REGION_LIST.add(this);
} }
@ -82,7 +88,11 @@ public class Region {
}); });
} }
this.flagStorage = flagStorage; 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) { private void generatePrototypeData(Prototype prototype, Point point) {
@ -90,7 +100,7 @@ public class Region {
return; return;
} }
if (!prototypes.contains(prototype)) { if (this.prototype != null && !prototypes.contains(prototype)) {
return; return;
} }
this.prototype = prototype; this.prototype = prototype;
@ -98,18 +108,22 @@ public class Region {
this.minPoint = point; this.minPoint = point;
this.maxPoint = point.add(prototype.getSizeX(), prototype.getSizeY(), prototype.getSizeZ()); this.maxPoint = point.add(prototype.getSizeX(), prototype.getSizeY(), prototype.getSizeZ());
if (prototype.getTestblock() != null) {
this.minPointTestblock = point.add(prototype.getTestblock().getOffsetX(), prototype.getTestblock().getOffsetY(), prototype.getTestblock().getOffsetZ()); 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.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.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.maxPointTestblockExtension = this.maxPointTestblock.add(prototype.getTestblock().getExtensionPositiveX(), prototype.getTestblock().getExtensionPositiveY(), prototype.getTestblock().getExtensionPositiveZ());
}
if (prototype.getBuild() != null) {
this.minPointBuild = point.add(prototype.getBuild().getOffsetX(), prototype.getBuild().getOffsetY(), prototype.getBuild().getOffsetZ()); 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.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.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.maxPointBuildExtension = this.maxPointBuild.add(prototype.getBuild().getExtensionPositiveX(), prototype.getBuild().getExtensionPositiveY(), prototype.getBuild().getExtensionPositiveZ());
} }
}
public boolean inRegion(Location location, RegionType regionType, RegionExtensionType regionExtensionType) { public boolean inRegion(Location location, RegionType regionType, RegionExtensionType regionExtensionType) {
if (!hasType(regionType)) { if (!hasType(regionType)) {
@ -151,4 +165,22 @@ public class Region {
public String getDisplayName() { public String getDisplayName() {
return prototype != null ? prototype.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 de.steamwar.bausystem.region.Prototype;
import lombok.experimental.UtilityClass; import lombok.experimental.UtilityClass;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
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;
import yapion.parser.YAPIONParser; import yapion.parser.YAPIONParser;
@ -38,6 +39,16 @@ import java.util.logging.Level;
@UtilityClass @UtilityClass
public class RegionLoader { 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() { public void load() {
File file = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "regions.yapion"); File file = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "regions.yapion");
YAPIONObject yapionObject = null; YAPIONObject yapionObject = null;
@ -50,14 +61,13 @@ public class RegionLoader {
} }
File optionsFile = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "options.yapion"); 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))) { try (BufferedInputStream bufferedInputStream = new BufferedInputStream(new FileInputStream(optionsFile))) {
optionsYapionObject = YAPIONParser.parse(bufferedInputStream); optionsYapionObject = YAPIONParser.parse(bufferedInputStream);
} catch (IOException e) { } catch (IOException e) {
// Ignored // Ignored
} }
YAPIONObject finalOptionsYapionObject = optionsYapionObject;
yapionObject.forEach((key, yapionAnyType) -> { yapionObject.forEach((key, yapionAnyType) -> {
if (key.equals("global")) { if (key.equals("global")) {
return; return;
@ -68,20 +78,26 @@ public class RegionLoader {
YAPIONObject regionConfig = (YAPIONObject) yapionAnyType; YAPIONObject regionConfig = (YAPIONObject) yapionAnyType;
YAPIONObject regionData = new YAPIONObject(); YAPIONObject regionData = new YAPIONObject();
if (finalOptionsYapionObject.containsKey(key, YAPIONType.OBJECT)) { if (optionsYapionObject.containsKey(key, YAPIONType.OBJECT)) {
regionData = finalOptionsYapionObject.getObject(key); regionData = optionsYapionObject.getObject(key);
} else {
optionsYapionObject.add(key, regionData);
} }
Prototype.generateRegion(regionConfig, regionData); Prototype.generateRegion(regionConfig, regionData);
}); });
YAPIONObject globalOptions = optionsYapionObject.getObject("global"); YAPIONObject globalOptions = optionsYapionObject.getObject("global");
if (globalOptions == null) {
globalOptions = new YAPIONObject();
optionsYapionObject.add("global", globalOptions);
}
FlagStorage flagStorage; FlagStorage flagStorage;
if (globalOptions != null && globalOptions.containsKey("flagStorage", YAPIONType.OBJECT)) { if (globalOptions.containsKey("flagStorage", YAPIONType.OBJECT)) {
flagStorage = (FlagStorage) YAPIONDeserializer.deserialize(globalOptions.getObject("flagStorage")); flagStorage = (FlagStorage) YAPIONDeserializer.deserialize(globalOptions.getObject("flagStorage"));
} else { } else {
flagStorage = new FlagStorage(); flagStorage = new FlagStorage();
} }
new GlobalRegion(flagStorage); new GlobalRegion(flagStorage, globalOptions);
} }
} }