Add RegionExtensionType
Add RegionType Implemen Region System
Dieser Commit ist enthalten in:
Ursprung
68f5d8726d
Commit
77a62a8063
@ -22,6 +22,7 @@ package de.steamwar.bausystem;
|
|||||||
import de.steamwar.bausystem.config.ColorConfig;
|
import de.steamwar.bausystem.config.ColorConfig;
|
||||||
import de.steamwar.bausystem.linkage.LinkageUtils;
|
import de.steamwar.bausystem.linkage.LinkageUtils;
|
||||||
import de.steamwar.bausystem.region.loader.PrototypeLoader;
|
import de.steamwar.bausystem.region.loader.PrototypeLoader;
|
||||||
|
import de.steamwar.bausystem.region.loader.RegionLoader;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
@ -39,6 +40,7 @@ public class BauSystem extends JavaPlugin implements Listener {
|
|||||||
SWUtils.setBausystem(instance);
|
SWUtils.setBausystem(instance);
|
||||||
|
|
||||||
PrototypeLoader.load();
|
PrototypeLoader.load();
|
||||||
|
RegionLoader.load();
|
||||||
|
|
||||||
LinkageUtils.link();
|
LinkageUtils.link();
|
||||||
}
|
}
|
||||||
|
@ -19,17 +19,11 @@
|
|||||||
|
|
||||||
package de.steamwar.bausystem.region;
|
package de.steamwar.bausystem.region;
|
||||||
|
|
||||||
import com.google.gson.JsonObject;
|
|
||||||
import com.google.gson.JsonPrimitive;
|
|
||||||
import de.steamwar.bausystem.region.flags.Flag;
|
import de.steamwar.bausystem.region.flags.Flag;
|
||||||
|
import yapion.annotations.object.YAPIONData;
|
||||||
|
|
||||||
import java.util.EnumMap;
|
import java.util.EnumMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import yapion.annotations.object.YAPIONData;
|
|
||||||
import yapion.hierarchy.api.groups.YAPIONAnyType;
|
|
||||||
import yapion.hierarchy.types.YAPIONObject;
|
|
||||||
import yapion.hierarchy.types.YAPIONValue;
|
|
||||||
|
|
||||||
|
|
||||||
@YAPIONData
|
@YAPIONData
|
||||||
public class FlagStorage {
|
public class FlagStorage {
|
||||||
|
@ -19,5 +19,25 @@
|
|||||||
|
|
||||||
package de.steamwar.bausystem.region;
|
package de.steamwar.bausystem.region;
|
||||||
|
|
||||||
public class GlobalRegion {
|
import de.steamwar.bausystem.region.utils.RegionExtensionType;
|
||||||
|
import de.steamwar.bausystem.region.utils.RegionType;
|
||||||
|
import lombok.Getter;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import yapion.hierarchy.types.YAPIONObject;
|
||||||
|
|
||||||
|
public class GlobalRegion extends Region {
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
static GlobalRegion instance;
|
||||||
|
|
||||||
|
public GlobalRegion(FlagStorage flagStorage) {
|
||||||
|
super(null, new YAPIONObject(), flagStorage);
|
||||||
|
|
||||||
|
instance = this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean inRegion(Location location, RegionType regionType, RegionExtensionType regionExtensionType) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,9 +19,11 @@
|
|||||||
|
|
||||||
package de.steamwar.bausystem.region;
|
package de.steamwar.bausystem.region;
|
||||||
|
|
||||||
|
import de.steamwar.bausystem.region.flags.Flag;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import yapion.hierarchy.types.YAPIONObject;
|
import yapion.hierarchy.types.YAPIONObject;
|
||||||
import yapion.hierarchy.types.YAPIONType;
|
import yapion.hierarchy.types.YAPIONType;
|
||||||
|
import yapion.serializing.YAPIONDeserializer;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -30,7 +32,7 @@ import java.util.Map;
|
|||||||
@Getter
|
@Getter
|
||||||
public class Prototype {
|
public class Prototype {
|
||||||
|
|
||||||
private static final Map<String, Prototype> PROTOTYPE_MAP = new HashMap<>();
|
static final Map<String, Prototype> PROTOTYPE_MAP = new HashMap<>();
|
||||||
|
|
||||||
private final String name;
|
private final String name;
|
||||||
private final String displayName;
|
private final String displayName;
|
||||||
@ -136,7 +138,19 @@ public class Prototype {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Region generateRegion(YAPIONObject regionConfig, YAPIONObject regionData) {
|
public static Region generateRegion(YAPIONObject regionConfig, YAPIONObject regionData) {
|
||||||
return null;
|
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) YAPIONDeserializer.deserialize(regionData.getObject("flagStorage"));
|
||||||
|
} else {
|
||||||
|
flagStorage = new FlagStorage();
|
||||||
|
}
|
||||||
|
return new Region(prototype, regionConfig, flagStorage);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -19,15 +19,35 @@
|
|||||||
|
|
||||||
package de.steamwar.bausystem.region;
|
package de.steamwar.bausystem.region;
|
||||||
|
|
||||||
|
import de.steamwar.bausystem.region.utils.RegionExtensionType;
|
||||||
|
import de.steamwar.bausystem.region.utils.RegionType;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import yapion.hierarchy.types.YAPIONObject;
|
||||||
|
import yapion.hierarchy.types.YAPIONType;
|
||||||
|
import yapion.hierarchy.types.YAPIONValue;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
public class Region {
|
public class Region {
|
||||||
|
|
||||||
|
private static final List<Region> REGION_LIST = new ArrayList<>();
|
||||||
|
|
||||||
|
public static Region getRegion(Location location) {
|
||||||
|
for (Region region : REGION_LIST) {
|
||||||
|
if (region.inRegion(location, RegionType.NORMAL, RegionExtensionType.NORMAL)) {
|
||||||
|
return region;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return GlobalRegion.instance;
|
||||||
|
}
|
||||||
|
|
||||||
private Prototype prototype;
|
private Prototype prototype;
|
||||||
private Set<Prototype> alternativePrototypes;
|
private Set<Prototype> prototypes;
|
||||||
|
|
||||||
private Point minPoint;
|
private Point minPoint;
|
||||||
private Point maxPoint;
|
private Point maxPoint;
|
||||||
@ -48,4 +68,35 @@ public class Region {
|
|||||||
|
|
||||||
private FlagStorage flagStorage;
|
private FlagStorage flagStorage;
|
||||||
|
|
||||||
|
public Region(Prototype prototype, YAPIONObject regionConfig, FlagStorage flagStorage) {
|
||||||
|
if (prototype != null) {
|
||||||
|
REGION_LIST.add(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
prototypes = new HashSet<>();
|
||||||
|
if (regionConfig.containsKey("prototypes", YAPIONType.ARRAY)) {
|
||||||
|
regionConfig.getArray("prototypes").forEach(yapionAnyType -> {
|
||||||
|
if (yapionAnyType instanceof YAPIONValue) {
|
||||||
|
prototypes.add(Prototype.PROTOTYPE_MAP.get(((YAPIONValue<String>) yapionAnyType).get()));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
this.flagStorage = flagStorage;
|
||||||
|
generatePrototypeData(prototype);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void generatePrototypeData(Prototype prototype) {
|
||||||
|
if (prototype != null && !prototypes.contains(prototype)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.prototype = prototype;
|
||||||
|
|
||||||
|
// TODO: implement generation
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean inRegion(Location location, RegionType regionType, RegionExtensionType regionExtensionType) {
|
||||||
|
// TODO: implement inRegion
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -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.output.StringOutput;
|
||||||
|
import yapion.hierarchy.output.SystemOutput;
|
||||||
import yapion.hierarchy.types.YAPIONObject;
|
import yapion.hierarchy.types.YAPIONObject;
|
||||||
import yapion.parser.YAPIONParser;
|
import yapion.parser.YAPIONParser;
|
||||||
|
|
||||||
|
@ -19,12 +19,69 @@
|
|||||||
|
|
||||||
package de.steamwar.bausystem.region.loader;
|
package de.steamwar.bausystem.region.loader;
|
||||||
|
|
||||||
|
import de.steamwar.bausystem.region.FlagStorage;
|
||||||
|
import de.steamwar.bausystem.region.GlobalRegion;
|
||||||
|
import de.steamwar.bausystem.region.Prototype;
|
||||||
import lombok.experimental.UtilityClass;
|
import lombok.experimental.UtilityClass;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import yapion.hierarchy.types.YAPIONObject;
|
||||||
|
import yapion.hierarchy.types.YAPIONType;
|
||||||
|
import yapion.parser.YAPIONParser;
|
||||||
|
import yapion.serializing.YAPIONDeserializer;
|
||||||
|
|
||||||
|
import java.io.BufferedInputStream;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
@UtilityClass
|
@UtilityClass
|
||||||
public class RegionLoader {
|
public class RegionLoader {
|
||||||
|
|
||||||
public void load() {
|
public void load() {
|
||||||
|
File file = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "regions.yapion");
|
||||||
|
YAPIONObject yapionObject = null;
|
||||||
|
try (BufferedInputStream bufferedInputStream = new BufferedInputStream(new FileInputStream(file))) {
|
||||||
|
yapionObject = YAPIONParser.parse(bufferedInputStream);
|
||||||
|
} catch (IOException e) {
|
||||||
|
Bukkit.getLogger().log(Level.SEVERE, e.getMessage(), e);
|
||||||
|
Bukkit.shutdown();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
File optionsFile = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "options.yapion");
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
if (!(yapionAnyType instanceof YAPIONObject)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
YAPIONObject regionConfig = (YAPIONObject) yapionAnyType;
|
||||||
|
YAPIONObject regionData = new YAPIONObject();
|
||||||
|
if (finalOptionsYapionObject.containsKey(key, YAPIONType.OBJECT)) {
|
||||||
|
regionData = finalOptionsYapionObject.getObject(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
Prototype.generateRegion(regionConfig, regionData);
|
||||||
|
});
|
||||||
|
|
||||||
|
YAPIONObject globalOptions = optionsYapionObject.getObject("global");
|
||||||
|
FlagStorage flagStorage;
|
||||||
|
if (globalOptions != null && globalOptions.containsKey("flagStorage", YAPIONType.OBJECT)) {
|
||||||
|
flagStorage = (FlagStorage) YAPIONDeserializer.deserialize(globalOptions.getObject("flagStorage"));
|
||||||
|
} else {
|
||||||
|
flagStorage = new FlagStorage();
|
||||||
|
}
|
||||||
|
new GlobalRegion(flagStorage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,25 @@
|
|||||||
|
/*
|
||||||
|
* This file is a part of the SteamWar software.
|
||||||
|
*
|
||||||
|
* 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
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.steamwar.bausystem.region.utils;
|
||||||
|
|
||||||
|
public enum RegionExtensionType {
|
||||||
|
NORMAL,
|
||||||
|
EXTENSION
|
||||||
|
}
|
@ -0,0 +1,26 @@
|
|||||||
|
/*
|
||||||
|
* This file is a part of the SteamWar software.
|
||||||
|
*
|
||||||
|
* 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
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.steamwar.bausystem.region.utils;
|
||||||
|
|
||||||
|
public enum RegionType {
|
||||||
|
NORMAL,
|
||||||
|
BUILD,
|
||||||
|
TESTBLOCK
|
||||||
|
}
|
In neuem Issue referenzieren
Einen Benutzer sperren