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
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);
}
@ -82,7 +88,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) {
@ -90,7 +100,7 @@ public class Region {
return;
}
if (!prototypes.contains(prototype)) {
if (this.prototype != null && !prototypes.contains(prototype)) {
return;
}
this.prototype = prototype;
@ -98,17 +108,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) {
@ -151,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,20 +78,26 @@ 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);
} 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();
}
new GlobalRegion(flagStorage);
new GlobalRegion(flagStorage, globalOptions);
}
}