forked from SteamWar/SteamWar
Make FixedGlobalFlagStorage load the options from file
This commit is contained in:
+4
-2
@@ -20,6 +20,8 @@
|
||||
package de.steamwar.bausystem.region;
|
||||
|
||||
import de.steamwar.bausystem.region.fixed.FixedGlobalRegion;
|
||||
import de.steamwar.bausystem.region.fixed.loader.PrototypeLoader;
|
||||
import de.steamwar.bausystem.region.fixed.loader.RegionLoader;
|
||||
import lombok.NonNull;
|
||||
import org.bukkit.Location;
|
||||
|
||||
@@ -35,12 +37,12 @@ public class FixedRegionSystem implements RegionSystem {
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
// TODO: Implement
|
||||
PrototypeLoader.load();
|
||||
RegionLoader.load();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save() {
|
||||
// TODO: Implement
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+16
-1
@@ -26,8 +26,10 @@ import de.steamwar.bausystem.region.flags.ColorMode;
|
||||
import de.steamwar.bausystem.region.flags.Flag;
|
||||
import de.steamwar.bausystem.region.flags.ProtectMode;
|
||||
import de.steamwar.bausystem.region.flags.TNTMode;
|
||||
import de.steamwar.bausystem.worlddata.WorldData;
|
||||
import de.steamwar.core.Core;
|
||||
import lombok.NonNull;
|
||||
import yapion.hierarchy.types.YAPIONObject;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -35,9 +37,20 @@ import java.util.Map;
|
||||
public class FixedGlobalFlagStorage implements FlagStorage {
|
||||
|
||||
private Map<Flag<?>, Flag.Value<?>> flagMap = new HashMap<>();
|
||||
private YAPIONObject data;
|
||||
|
||||
public FixedGlobalFlagStorage() {
|
||||
public FixedGlobalFlagStorage(YAPIONObject data) {
|
||||
flagMap.put(Flag.TNT, TNTMode.DENY);
|
||||
this.data = data;
|
||||
for (final Flag flag : Flag.getFlags()) {
|
||||
if (!has(flag).isWritable()) continue;
|
||||
try {
|
||||
String s = data.getPlainValue(flag.name());
|
||||
flagMap.put(flag, flag.valueOfValue(s));
|
||||
} catch (Exception e) {
|
||||
flagMap.put(flag, (Flag.Value<?>) flag.getDefaultValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -57,6 +70,8 @@ public class FixedGlobalFlagStorage implements FlagStorage {
|
||||
@Override
|
||||
public <T extends Enum<T> & Flag.Value<T>> boolean set(@NonNull Flag<T> flag, @NonNull T value) {
|
||||
if (has(flag).isWritable()) {
|
||||
data.put(flag.name(), value.name());
|
||||
WorldData.write();
|
||||
return flagMap.put(flag, value) != value;
|
||||
} else {
|
||||
return false;
|
||||
|
||||
+3
-1
@@ -23,6 +23,7 @@ import com.sk89q.worldedit.EditSession;
|
||||
import de.steamwar.bausystem.region.*;
|
||||
import de.steamwar.bausystem.utils.PasteBuilder;
|
||||
import lombok.NonNull;
|
||||
import lombok.Setter;
|
||||
import org.bukkit.Location;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
@@ -37,7 +38,8 @@ public final class FixedGlobalRegion implements Region {
|
||||
private static final Point MIN_POINT = new Point(Integer.MIN_VALUE, Integer.MIN_VALUE, Integer.MIN_VALUE);
|
||||
private static final Point MAX_POINT = new Point(Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE);
|
||||
|
||||
private static final FlagStorage FLAG_STORAGE = new FixedGlobalFlagStorage();
|
||||
@Setter
|
||||
private static FlagStorage FLAG_STORAGE;
|
||||
|
||||
private static final UUID GLOBAL_REGION_ID = new UUID(0, 0);
|
||||
|
||||
|
||||
+14
-13
@@ -127,11 +127,11 @@ public class Prototype {
|
||||
skinMap.put(displayName, new Skin(defaultSkin, null, schematicFile, testblockSchematicFile, buildSchematicFile));
|
||||
}
|
||||
|
||||
if (PROTOTYPE_MAP.containsKey(name)) {
|
||||
Region.getRegion(PROTOTYPE_MAP.remove(name)).forEach(region -> {
|
||||
region._setPrototype(this);
|
||||
});
|
||||
}
|
||||
// if (PROTOTYPE_MAP.containsKey(name)) {
|
||||
// Region.getRegion(PROTOTYPE_MAP.remove(name)).forEach(region -> {
|
||||
// region._setPrototype(this);
|
||||
// });
|
||||
// }
|
||||
PROTOTYPE_MAP.put(name, this);
|
||||
}
|
||||
|
||||
@@ -210,19 +210,20 @@ public class Prototype {
|
||||
}
|
||||
}
|
||||
|
||||
public static Region generateRegion(String name, YAPIONObject regionConfig, YAPIONObject regionData) {
|
||||
public static void generateRegion(String name, YAPIONObject regionConfig, YAPIONObject regionData) {
|
||||
Prototype prototype;
|
||||
if (regionData.containsKey("prototype", String.class)) {
|
||||
prototype = PROTOTYPE_MAP.get(regionData.getPlainValue("prototype"));
|
||||
} else {
|
||||
prototype = PROTOTYPE_MAP.get(regionConfig.getPlainValue("prototype"));
|
||||
}
|
||||
FlagStorage flagStorage;
|
||||
if (regionData.containsKey("flagStorage", YAPIONType.OBJECT)) {
|
||||
flagStorage = FlagStorage.createStorage(regionData.getObject("flagStorage"));
|
||||
} else {
|
||||
flagStorage = new FlagStorage();
|
||||
}
|
||||
return new Region(name, prototype, regionConfig, flagStorage, regionData);
|
||||
System.out.println(name + " " + prototype);
|
||||
// FlagStorage flagStorage;
|
||||
// if (regionData.containsKey("flagStorage", YAPIONType.OBJECT)) {
|
||||
// flagStorage = FlagStorage.createStorage(regionData.getObject("flagStorage"));
|
||||
// } else {
|
||||
// flagStorage = new FlagStorage();
|
||||
// }
|
||||
// return new Region(name, prototype, regionConfig, flagStorage, regionData);
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2021 SteamWar.de-Serverteam
|
||||
* Copyright (C) 2020 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
@@ -17,7 +17,7 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.bausystem.region.loader;
|
||||
package de.steamwar.bausystem.region.fixed.loader;
|
||||
|
||||
import de.steamwar.bausystem.region.fixed.Prototype;
|
||||
import lombok.experimental.UtilityClass;
|
||||
+5
-11
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2021 SteamWar.de-Serverteam
|
||||
* Copyright (C) 2020 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
@@ -17,10 +17,10 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.bausystem.region.loader;
|
||||
package de.steamwar.bausystem.region.fixed.loader;
|
||||
|
||||
import de.steamwar.bausystem.region.FlagStorage;
|
||||
import de.steamwar.bausystem.region.GlobalRegion;
|
||||
import de.steamwar.bausystem.region.fixed.FixedGlobalFlagStorage;
|
||||
import de.steamwar.bausystem.region.fixed.FixedGlobalRegion;
|
||||
import de.steamwar.bausystem.region.fixed.Prototype;
|
||||
import de.steamwar.bausystem.worlddata.WorldData;
|
||||
import lombok.experimental.UtilityClass;
|
||||
@@ -80,12 +80,6 @@ public class RegionLoader {
|
||||
globalOptions = new YAPIONObject();
|
||||
optionsYapionObject.add("global", globalOptions);
|
||||
}
|
||||
FlagStorage flagStorage;
|
||||
if (globalOptions.containsKey("flagStorage", YAPIONType.OBJECT)) {
|
||||
flagStorage = FlagStorage.createStorage(globalOptions.getObject("flagStorage"));
|
||||
} else {
|
||||
flagStorage = new FlagStorage();
|
||||
}
|
||||
new GlobalRegion(flagStorage, globalOptions);
|
||||
FixedGlobalRegion.setFLAG_STORAGE(new FixedGlobalFlagStorage(globalOptions.getObjectOrSetDefault("flagStorage", new YAPIONObject())));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user