Dieser Commit ist enthalten in:
Ursprung
d72d62c9ee
Commit
9d4a718796
@ -1073,8 +1073,6 @@ REGION_REGION_HELP_RESTORE=§8/§eregion restore §8- §7Resets the region, with
|
||||
REGION_REGION_HELP_RESTORE_SCHEMATIC=§8/§eregion restore §8[§7Schematic§8] §8- §7Resets the region, withoout removing your builds
|
||||
REGION_REGION_HELP_COPYPOINT=§8/§eregion copypoint §8- §7Teleport to the regions copy point
|
||||
REGION_REGION_HELP_TESTBLOCKPOINT=§8/§eregion testblockpoint §8- §7Teleport to the regions dummy point
|
||||
REGION_REGION_HELP_CHANGETYPE_INFO=§8/§eregion changetype §8- §7Returns the region type
|
||||
REGION_REGION_HELP_CHANGETYPE=§8/§eregion changetype §8[§7Type§8] §8- §8Sets the region type
|
||||
REGION_REGION_HELP_CHANGESKIN_INFO=§8/§eregion changeskin §8- §7Returns the region skin
|
||||
REGION_REGION_HELP_CHANGESKIN=§8/§eregion changeskin §8[§7Skin§8] §8- §8Sets the region skin
|
||||
REGION_REGION_NOTHING_UNDO=§cNothing left to undo
|
||||
@ -1091,12 +1089,6 @@ REGION_REGION_TP_TEST_BLOCK=§7Teleported to the tesblock
|
||||
REGION_REGION_TP_UNKNOWN=§cUndefined teleport point
|
||||
REGION_REGION_NO_REGION=§cYou are not inside any region
|
||||
REGION_REGION_NO_PERMS=§cYou are not allowed to change the region
|
||||
REGION_REGION_CHANGETYPE_INFO=§7RRegion type is §e{0}
|
||||
REGION_REGION_CHANGETYPE_UNKNOWN=§cRegion type is invalid
|
||||
REGION_REGION_CHANGETYPE_INVALID=§cRegion type is not allowed here
|
||||
REGION_REGION_CHANGETYPE_CHANGE=§7Region type changed to §e{0}
|
||||
REGION_REGION_CHANGETYPE_CHANGE_UPDATE=§7Click §e§lHERE §7to change the region type
|
||||
REGION_REGION_CHANGETYPE_CHANGE_UPDATE_HOVER=§8/§ereset
|
||||
REGION_REGION_CHANGESKIN_INFO=§7Region skin is §e{0}
|
||||
REGION_REGION_CHANGESKIN_INFO_CREATOR=§7Skin created by §e{0}
|
||||
REGION_REGION_CHANGESKIN_UNKNOWN=§cRegion skin is invalid
|
||||
|
@ -1041,8 +1041,6 @@ REGION_REGION_HELP_RESTORE=§8/§eregion restore §8- §7Setzte die Region zurü
|
||||
REGION_REGION_HELP_RESTORE_SCHEMATIC=§8/§eregion restore §8[§7Schematic§8] §8- §7Setzte die Region zurück, ohne das Gebaute zu löschen
|
||||
REGION_REGION_HELP_COPYPOINT=§8/§eregion copypoint §8- §7Teleportiere dich zum Regions Kopierpunkt
|
||||
REGION_REGION_HELP_TESTBLOCKPOINT=§8/§eregion testblockpoint §8- §7Teleportiere dich zum Regions Testblockpunkt
|
||||
REGION_REGION_HELP_CHANGETYPE_INFO=§8/§eregion changetype §8- §7Gebe den Regions Type aus
|
||||
REGION_REGION_HELP_CHANGETYPE=§8/§eregion changetype §8[§7Type§8] §8- §8Setzte den Regions Type
|
||||
REGION_REGION_HELP_CHANGESKIN_INFO=§8/§eregion changeskin §8- §7Gebe den Regions Skin aus
|
||||
REGION_REGION_HELP_CHANGESKIN=§8/§eregion changeskin §8[§7Skin§8] §8- §8Setzte den Regions Skin
|
||||
REGION_REGION_NOTHING_UNDO=§cNichts zum rückgängig machen
|
||||
@ -1059,12 +1057,6 @@ REGION_REGION_TP_TEST_BLOCK=§7Zum Testblock teleportiert
|
||||
REGION_REGION_TP_UNKNOWN=§cNicht definierter Teleportierpunkt
|
||||
REGION_REGION_NO_REGION=§cDu bist in keiner Region
|
||||
REGION_REGION_NO_PERMS=§cDu darfst hier nicht die Region verändern
|
||||
REGION_REGION_CHANGETYPE_INFO=§7Regions Type ist §e{0}
|
||||
REGION_REGION_CHANGETYPE_UNKNOWN=§cRegions Type ist nicht valide
|
||||
REGION_REGION_CHANGETYPE_INVALID=§cRegions Type ist nicht erlaubt hier
|
||||
REGION_REGION_CHANGETYPE_CHANGE=§7Regions Type ist auf §e{0}§7 geändert
|
||||
REGION_REGION_CHANGETYPE_CHANGE_UPDATE=§7Klicke §e§lHIER §7um den Type anzuwenden
|
||||
REGION_REGION_CHANGETYPE_CHANGE_UPDATE_HOVER=§8/§ereset
|
||||
REGION_REGION_CHANGESKIN_INFO=§7Regions Skin ist §e{0}
|
||||
REGION_REGION_CHANGESKIN_INFO_CREATOR=§7Skin erstellt von §e{0}
|
||||
REGION_REGION_CHANGESKIN_UNKNOWN=§cRegions Skin ist nicht valide
|
||||
|
@ -21,11 +21,10 @@ package de.steamwar.bausystem;
|
||||
|
||||
import com.comphenix.tinyprotocol.TinyProtocol;
|
||||
import de.steamwar.bausystem.configplayer.Config;
|
||||
import de.steamwar.bausystem.linkage.LinkageUtils;
|
||||
import de.steamwar.bausystem.region.loader.PrototypeLoader;
|
||||
import de.steamwar.bausystem.region.loader.RegionLoader;
|
||||
import de.steamwar.bausystem.region.loader.Updater;
|
||||
import de.steamwar.bausystem.worlddata.WorldData;
|
||||
import de.steamwar.bausystem.linkage.LinkageUtils;
|
||||
import de.steamwar.message.Message;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.Bukkit;
|
||||
@ -69,9 +68,6 @@ public class BauSystem extends JavaPlugin implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
new Updater(PrototypeLoader.file, PrototypeLoader::load);
|
||||
new Updater(RegionLoader.file, RegionLoader::load);
|
||||
|
||||
LinkageUtils.link();
|
||||
|
||||
// This could disable any watchdog stuff. We need to investigate if this is a problem.
|
||||
@ -96,7 +92,7 @@ public class BauSystem extends JavaPlugin implements Listener {
|
||||
public void onDisable() {
|
||||
LinkageUtils.unlink();
|
||||
|
||||
WorldData.write();
|
||||
WorldData.getInstance().save();
|
||||
Config.saveAll();
|
||||
TinyProtocol.instance.close();
|
||||
}
|
||||
|
@ -26,4 +26,6 @@ import java.lang.annotation.Target;
|
||||
|
||||
@Target({ElementType.FIELD})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface ConfigField {}
|
||||
public @interface ConfigField {
|
||||
boolean required() default false;
|
||||
}
|
||||
|
@ -34,6 +34,8 @@ public class YamlConfig implements ConfigurationSerializable {
|
||||
ConfigurationSerialization.registerClass(configType);
|
||||
}
|
||||
|
||||
public YamlConfig() {}
|
||||
|
||||
public YamlConfig(ConfigurationSection configuration) {
|
||||
this(configuration.getValues(false));
|
||||
}
|
||||
@ -42,15 +44,13 @@ public class YamlConfig implements ConfigurationSerializable {
|
||||
Arrays.stream(getClass().getDeclaredFields())
|
||||
.filter(field -> field.isAnnotationPresent(ConfigField.class))
|
||||
.forEach(field -> {
|
||||
String name = field.getName();
|
||||
try {
|
||||
field.setAccessible(true);
|
||||
field.set(this, map.computeIfAbsent(field.getName(), name -> {
|
||||
try {
|
||||
return getClass().getDeclaredField(name.toUpperCase() + "_DEFAULT").get(null);
|
||||
} catch (IllegalAccessException | NoSuchFieldException e) {
|
||||
throw new IllegalStateException(getClass().getName() + "." + field.getName() + " has no default field", e);
|
||||
}
|
||||
}));
|
||||
field.set(this, map.containsKey(name) ? map.get(name) : getClass().getDeclaredField(name.toUpperCase() + "_DEFAULT").get(null));
|
||||
} catch (NoSuchFieldException e) {
|
||||
if(field.getAnnotation(ConfigField.class).required())
|
||||
throw new IllegalStateException(getClass().getName() + "." + field.getName() + " is required", e);
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new IllegalStateException(getClass().getName() + "." + field.getName() + " is inaccessible for deserializer", e);
|
||||
}
|
||||
|
@ -30,7 +30,6 @@ import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
import java.io.StringReader;
|
||||
@ -57,7 +56,6 @@ public class Config extends YamlConfig {
|
||||
@Setter
|
||||
@ConfigField
|
||||
private boolean nightvision;
|
||||
private static final boolean NIGHTVISION_DEFAULT = false;
|
||||
|
||||
private Config(UUID uuid, ConfigurationSection configuration) {
|
||||
super(configuration);
|
||||
@ -73,10 +71,6 @@ public class Config extends YamlConfig {
|
||||
|
||||
@Linked
|
||||
public static class ConfigListener implements Listener {
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
get(event.getPlayer());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||
|
@ -22,11 +22,11 @@ package de.steamwar.bausystem.features.region;
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.Permission;
|
||||
import de.steamwar.bausystem.features.util.SelectCommand;
|
||||
import de.steamwar.bausystem.region.Prototype;
|
||||
import de.steamwar.bausystem.region.Region;
|
||||
import de.steamwar.bausystem.region.RegionUtils;
|
||||
import de.steamwar.bausystem.region.utils.RegionExtensionType;
|
||||
import de.steamwar.bausystem.region.utils.RegionType;
|
||||
import de.steamwar.bausystem.worlddata.WorldData;
|
||||
import de.steamwar.command.PreviousArguments;
|
||||
import de.steamwar.command.SWCommand;
|
||||
import de.steamwar.command.TypeMapper;
|
||||
@ -155,36 +155,6 @@ public class RegionCommand extends SWCommand {
|
||||
BauSystem.MESSAGE.send("REGION_REGION_TP_TEST_BLOCK", p);
|
||||
}
|
||||
|
||||
@Register(value = "changetype", description = "REGION_REGION_HELP_CHANGETYPE_INFO")
|
||||
@Register("type")
|
||||
public void changeTypeCommand(Player p) {
|
||||
Region region = Region.getRegion(p.getLocation());
|
||||
if (checkGlobalRegion(region, p)) {
|
||||
return;
|
||||
}
|
||||
BauSystem.MESSAGE.send("REGION_REGION_CHANGETYPE_INFO", p, region.getPrototype().getDisplayName());
|
||||
}
|
||||
|
||||
@Register(value = "changetype", description = "REGION_REGION_HELP_CHANGETYPE")
|
||||
@Register("type")
|
||||
public void changeTypeCommand(@Validator("WORLD") Player p, @Mapper("regionTypeMapper") String s) {
|
||||
Region region = Region.getRegion(p.getLocation());
|
||||
if (checkGlobalRegion(region, p)) {
|
||||
return;
|
||||
}
|
||||
Prototype prototype = Prototype.getByDisplayName(s);
|
||||
if (prototype == null) {
|
||||
BauSystem.MESSAGE.send("REGION_REGION_CHANGETYPE_UNKNOWN", p);
|
||||
} else {
|
||||
if (region.setPrototype(prototype)) {
|
||||
BauSystem.MESSAGE.send("REGION_REGION_CHANGETYPE_CHANGE", p, s);
|
||||
BauSystem.MESSAGE.send("REGION_REGION_CHANGETYPE_CHANGE_UPDATE", p, BauSystem.MESSAGE.parse("REGION_REGION_CHANGETYPE_CHANGE_UPDATE_HOVER", p), new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/reset"));
|
||||
} else {
|
||||
BauSystem.MESSAGE.send("REGION_REGION_CHANGETYPE_INVALID", p);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Register(value = "changeskin", description = "REGION_REGION_HELP_CHANGESKIN_INFO")
|
||||
@Register("skin")
|
||||
public void changeSkinCommand(Player p) {
|
||||
@ -193,7 +163,7 @@ public class RegionCommand extends SWCommand {
|
||||
return;
|
||||
}
|
||||
BauSystem.MESSAGE.send("REGION_REGION_CHANGESKIN_INFO", p, region.getSkin());
|
||||
String creator = region.getPrototype().getSkinMap().get(region.getSkin()).getCreator();
|
||||
String creator = region.getPrototype().getSkins().get(region.getSkin()).getCreator();
|
||||
if (creator != null) {
|
||||
BauSystem.MESSAGE.send("REGION_REGION_CHANGESKIN_INFO_CREATOR", p, creator);
|
||||
}
|
||||
@ -206,10 +176,11 @@ public class RegionCommand extends SWCommand {
|
||||
if (checkGlobalRegion(region, p)) {
|
||||
return;
|
||||
}
|
||||
if (!region.getPrototype().getSkinMap().containsKey(s)) {
|
||||
if (!region.getPrototype().getSkins().containsKey(s)) {
|
||||
BauSystem.MESSAGE.send("REGION_REGION_CHANGESKIN_UNKNOWN", p);
|
||||
} else {
|
||||
if (region.setSkin(s)) {
|
||||
WorldData.getInstance().save();
|
||||
BauSystem.MESSAGE.send("REGION_REGION_CHANGESKIN_CHANGE", p, s);
|
||||
BauSystem.MESSAGE.send("REGION_REGION_CHANGESKIN_CHANGE_UPDATE", p, BauSystem.MESSAGE.parse("REGION_REGION_CHANGESKIN_CHANGE_UPDATE_HOVER", p), new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/reset"));
|
||||
} else {
|
||||
@ -218,26 +189,6 @@ public class RegionCommand extends SWCommand {
|
||||
}
|
||||
}
|
||||
|
||||
@Mapper(value = "regionTypeMapper", local = true)
|
||||
private TypeMapper<String> regionTypeMapper() {
|
||||
return new TypeMapper<String>() {
|
||||
@Override
|
||||
public List<String> tabCompletes(CommandSender commandSender, PreviousArguments previousArguments, String s) {
|
||||
Player p = (Player) commandSender;
|
||||
Region region = Region.getRegion(p.getLocation());
|
||||
if (region.isGlobal()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return region.getPrototypes().stream().map(Prototype::getByName).map(Prototype::getDisplayName).map(c -> c.replace(' ', '_')).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String map(CommandSender commandSender, PreviousArguments previousArguments, String s) {
|
||||
return s.replace('_', ' ');
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Mapper(value = "skinTypeMapper", local = true)
|
||||
private TypeMapper<String> skinTypeMapper() {
|
||||
return new TypeMapper<String>() {
|
||||
@ -248,7 +199,7 @@ public class RegionCommand extends SWCommand {
|
||||
if (region.isGlobal()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return region.getPrototype().getSkinMap().keySet().stream().map(c -> c.replace(' ', '_')).collect(Collectors.toList());
|
||||
return region.getPrototype().getSkins().keySet().stream().map(c -> c.replace(' ', '_')).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -19,64 +19,45 @@
|
||||
|
||||
package de.steamwar.bausystem.region;
|
||||
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.region.flags.Flag;
|
||||
import de.steamwar.bausystem.region.tags.Tag;
|
||||
import yapion.hierarchy.types.YAPIONObject;
|
||||
import org.bukkit.configuration.serialization.ConfigurationSerializable;
|
||||
|
||||
import java.util.EnumMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
import java.util.logging.Level;
|
||||
|
||||
/**
|
||||
* Tags and Flags are not allowed to have overlaping names.
|
||||
*/
|
||||
public class FlagStorage {
|
||||
public class FlagStorage implements ConfigurationSerializable {
|
||||
|
||||
public static FlagStorage createStorage(YAPIONObject yapionObject) {
|
||||
FlagStorage flagStorage = new FlagStorage();
|
||||
for (final Flag flag : Flag.getFlags()) {
|
||||
try {
|
||||
String s = yapionObject.getPlainValue(flag.name());
|
||||
flagStorage.set(flag, flag.getFlagValueOf(s));
|
||||
} catch (Exception e) {
|
||||
flagStorage.set(flag, flag.getDefaultValue());
|
||||
}
|
||||
}
|
||||
for (final Tag tag : Tag.values()) {
|
||||
if (yapionObject.containsKey(tag.name())) {
|
||||
flagStorage.set(tag);
|
||||
}
|
||||
}
|
||||
return flagStorage;
|
||||
}
|
||||
|
||||
public static YAPIONObject toYAPION(FlagStorage flagStorage) {
|
||||
YAPIONObject yapionObject = new YAPIONObject();
|
||||
for (final Flag flag : Flag.getFlags()) {
|
||||
if (flag.getDefaultValue() == flagStorage.flags.getOrDefault(flag, flag.getDefaultValue())) {
|
||||
yapionObject.remove(flag.name());
|
||||
} else {
|
||||
yapionObject.add(flag.name(), flagStorage.get(flag).getValue().name());
|
||||
}
|
||||
}
|
||||
for (Tag tag : Tag.values()) {
|
||||
if (flagStorage.tagSet.contains(tag)) {
|
||||
yapionObject.add(tag.name(), "");
|
||||
} else {
|
||||
yapionObject.remove(tag.name());
|
||||
}
|
||||
}
|
||||
return yapionObject;
|
||||
}
|
||||
|
||||
protected Map<Flag, Flag.Value<?>> flags;
|
||||
protected Set<Tag> tagSet;
|
||||
private final Map<Flag, Flag.Value<?>> flags = new EnumMap<>(Flag.class);
|
||||
private final Set<Tag> tags = new HashSet<>();
|
||||
|
||||
public FlagStorage() {
|
||||
flags = new EnumMap<>(Flag.class);
|
||||
tagSet = new HashSet<>();
|
||||
readKeys();
|
||||
for (final Flag flag : Flag.getFlags()) {
|
||||
flags.put(flag, flag.getDefaultValue());
|
||||
}
|
||||
}
|
||||
|
||||
public FlagStorage(Map<String, Object> map) {
|
||||
this();
|
||||
|
||||
for(Map.Entry<String, Object> entry : map.entrySet()) {
|
||||
try {
|
||||
Flag flag = Flag.valueOf(entry.getKey());
|
||||
flags.put(flag, flag.getFlagValueOf((String) entry.getValue()));
|
||||
continue;
|
||||
} catch (IllegalArgumentException ignored) {}
|
||||
|
||||
try {
|
||||
tags.add(Tag.valueOf(entry.getKey()));
|
||||
continue;
|
||||
} catch (IllegalArgumentException ignored) {}
|
||||
|
||||
BauSystem.getInstance().getLogger().log(Level.INFO, "Unknown region flag ignored: " + entry.getKey());
|
||||
}
|
||||
}
|
||||
|
||||
public boolean set(final Flag flagType, final Flag.Value<?> value) {
|
||||
@ -88,20 +69,22 @@ public class FlagStorage {
|
||||
}
|
||||
|
||||
public boolean set(final Tag tag) {
|
||||
return tagSet.add(tag);
|
||||
return tags.add(tag);
|
||||
}
|
||||
|
||||
public boolean remove(final Tag tag) {
|
||||
return tagSet.remove(tag);
|
||||
return tags.remove(tag);
|
||||
}
|
||||
|
||||
public boolean is(final Tag tag) {
|
||||
return tagSet.contains(tag);
|
||||
return tags.contains(tag);
|
||||
}
|
||||
|
||||
private void readKeys() {
|
||||
for (final Flag flag : Flag.getFlags()) {
|
||||
flags.put(flag, flag.getDefaultValue());
|
||||
}
|
||||
@Override
|
||||
public Map<String, Object> serialize() {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
flags.forEach((flag, value) -> result.put(flag.name(), value.getName()));
|
||||
tags.forEach(tag -> result.put(tag.name(), null));
|
||||
return result;
|
||||
}
|
||||
}
|
@ -21,17 +21,18 @@ package de.steamwar.bausystem.region;
|
||||
|
||||
import de.steamwar.bausystem.region.utils.RegionExtensionType;
|
||||
import de.steamwar.bausystem.region.utils.RegionType;
|
||||
import de.steamwar.bausystem.worlddata.WorldData;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.Location;
|
||||
import yapion.hierarchy.types.YAPIONObject;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
|
||||
public class GlobalRegion extends Region {
|
||||
|
||||
@Getter
|
||||
static GlobalRegion instance;
|
||||
|
||||
public GlobalRegion(FlagStorage flagStorage, YAPIONObject regionData) {
|
||||
super("global", null, new YAPIONObject(), flagStorage, regionData);
|
||||
public GlobalRegion(ConfigurationSection regionConfig, WorldData.RegionConfig config) {
|
||||
super(regionConfig, config);
|
||||
instance = this;
|
||||
}
|
||||
|
||||
|
@ -19,6 +19,8 @@
|
||||
|
||||
package de.steamwar.bausystem.region;
|
||||
|
||||
import de.steamwar.bausystem.config.ConfigField;
|
||||
import de.steamwar.bausystem.config.YamlConfig;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
@ -27,15 +29,24 @@ import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Getter
|
||||
@ToString
|
||||
@EqualsAndHashCode
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@AllArgsConstructor
|
||||
public class Point {
|
||||
public class Point extends YamlConfig {
|
||||
|
||||
private final int x;
|
||||
private final int y;
|
||||
private final int z;
|
||||
@ConfigField(required = true)
|
||||
private int x;
|
||||
@ConfigField(required = true)
|
||||
private int y;
|
||||
@ConfigField(required = true)
|
||||
private int z;
|
||||
|
||||
public Point(Map<String, Object> map) {
|
||||
super(map);
|
||||
}
|
||||
|
||||
public static Point fromLocation(final Location location) {
|
||||
return new Point(location.getBlockX(), location.getBlockY(), location.getBlockZ());
|
||||
|
@ -19,10 +19,10 @@
|
||||
|
||||
package de.steamwar.bausystem.region;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import de.steamwar.bausystem.config.ConfigField;
|
||||
import de.steamwar.bausystem.config.YamlConfig;
|
||||
import lombok.Getter;
|
||||
import yapion.hierarchy.types.YAPIONObject;
|
||||
import yapion.hierarchy.types.YAPIONType;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
@ -31,7 +31,12 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Getter
|
||||
public class Prototype {
|
||||
public class Prototype extends YamlConfig {
|
||||
|
||||
static {
|
||||
register(YamlConfig.class);
|
||||
register(SubPrototype.class);
|
||||
}
|
||||
|
||||
static final Map<String, Prototype> PROTOTYPE_MAP = new HashMap<>();
|
||||
|
||||
@ -47,180 +52,131 @@ public class Prototype {
|
||||
return new ArrayList<>(PROTOTYPE_MAP.values());
|
||||
}
|
||||
|
||||
@AllArgsConstructor
|
||||
@Getter
|
||||
public static class Skin {
|
||||
private final String name;
|
||||
private final String creator; // Nullable
|
||||
public static class Skin extends YamlConfig {
|
||||
@ConfigField
|
||||
private String creator;
|
||||
|
||||
@ConfigField(required = true)
|
||||
private String schematic;
|
||||
private final File schematicFile;
|
||||
private final File testblockSchematicFile; // Nullable
|
||||
private final File buildSchematicFile; // Nullable
|
||||
|
||||
@ConfigField
|
||||
private String testblockSchematic;
|
||||
private final File testblockSchematicFile;
|
||||
|
||||
@ConfigField
|
||||
private String buildSchematic;
|
||||
private final File buildSchematicFile;
|
||||
|
||||
@ConfigField
|
||||
private boolean disabled;
|
||||
|
||||
public Skin(Map<String, Object> map) {
|
||||
super(map);
|
||||
schematicFile = new File(schematic);
|
||||
testblockSchematicFile = testblockSchematic != null ? new File(testblockSchematic) : null;
|
||||
buildSchematicFile = buildSchematic != null ? new File(buildSchematic) : null;
|
||||
}
|
||||
}
|
||||
|
||||
private final String name;
|
||||
private final String displayName;
|
||||
private final String defaultSkin;
|
||||
private final Map<String, Skin> skinMap = new HashMap<>();
|
||||
@ConfigField
|
||||
private String displayName;
|
||||
@ConfigField
|
||||
private String defaultSkin;
|
||||
@ConfigField(required = true)
|
||||
private Map<String, Skin> skins;
|
||||
|
||||
private final int sizeX;
|
||||
private final int sizeY;
|
||||
private final int sizeZ;
|
||||
@ConfigField(required = true)
|
||||
private int sizeX;
|
||||
@ConfigField(required = true)
|
||||
private int sizeY;
|
||||
@ConfigField(required = true)
|
||||
private int sizeZ;
|
||||
|
||||
private final int floorOffset;
|
||||
private final int waterOffset;
|
||||
@ConfigField
|
||||
private int floorOffset;
|
||||
@ConfigField
|
||||
private int waterOffset;
|
||||
|
||||
private final SubPrototype testblock; // Nullable
|
||||
private final SubPrototype build; // Nullable
|
||||
@ConfigField
|
||||
private SubPrototype testblock;
|
||||
@ConfigField
|
||||
private SubPrototype build;
|
||||
|
||||
private final int copyPointOffsetX;
|
||||
private final int copyPointOffsetY;
|
||||
private final int copyPointOffsetZ;
|
||||
@ConfigField
|
||||
private int copyPointOffsetX;
|
||||
@ConfigField
|
||||
private int copyPointOffsetY;
|
||||
@ConfigField
|
||||
private int copyPointOffsetZ;
|
||||
|
||||
public Prototype(String name, YAPIONObject yapionObject) {
|
||||
this.name = name;
|
||||
displayName = yapionObject.getPlainValueOrDefault("displayName", name);
|
||||
public Prototype(ConfigurationSection config) {
|
||||
super(config);
|
||||
name = config.getName();
|
||||
|
||||
sizeX = yapionObject.getPlainValue("sizeX");
|
||||
sizeY = yapionObject.getPlainValue("sizeY");
|
||||
sizeZ = yapionObject.getPlainValue("sizeZ");
|
||||
if(displayName == null)
|
||||
displayName = name;
|
||||
if(defaultSkin == null)
|
||||
defaultSkin = displayName;
|
||||
|
||||
copyPointOffsetX = yapionObject.getPlainValueOrDefault("copyOffsetX", 0);
|
||||
copyPointOffsetY = yapionObject.getPlainValueOrDefault("copyOffsetY", 0);
|
||||
copyPointOffsetZ = yapionObject.getPlainValueOrDefault("copyOffsetZ", 0);
|
||||
skins.entrySet().removeIf(entry -> entry.getValue().isDisabled());
|
||||
|
||||
floorOffset = yapionObject.getPlainValueOrDefault("floorOffset", 0);
|
||||
waterOffset = yapionObject.getPlainValueOrDefault("waterOffset", 0);
|
||||
|
||||
if (yapionObject.containsKey("testblock", YAPIONType.OBJECT)) {
|
||||
testblock = new SubPrototype(yapionObject.getObject("testblock"));
|
||||
} else {
|
||||
testblock = null;
|
||||
}
|
||||
if (yapionObject.containsKey("build", YAPIONType.OBJECT)) {
|
||||
build = new SubPrototype(yapionObject.getObject("build"));
|
||||
} else {
|
||||
build = null;
|
||||
}
|
||||
|
||||
this.defaultSkin = yapionObject.getPlainValueOrDefault("defaultSkin", displayName);
|
||||
if (yapionObject.containsKey("skins", YAPIONType.ARRAY)) {
|
||||
yapionObject.getArray("skins").forEach(yapionAnyType -> {
|
||||
YAPIONObject skinObject = (YAPIONObject) yapionAnyType;
|
||||
String skinName = skinObject.getPlainValue("name");
|
||||
String skinCreator = skinObject.getPlainValueOrDefault("creator", null);
|
||||
String schematicFileName = skinObject.getPlainValue("schematic");
|
||||
String testblockSchematicFileName = skinObject.getPlainValueOrDefault("testblockSchematic", null);
|
||||
String buildSchematicFileName = skinObject.getPlainValueOrDefault("buildSchematic", null);
|
||||
boolean disabled = skinObject.getPlainValueOrDefault("disabled", false);
|
||||
if (disabled) {
|
||||
return;
|
||||
}
|
||||
skinMap.put(skinName, new Skin(skinName, skinCreator, new File(schematicFileName), testblockSchematicFileName == null ? null : new File(testblockSchematicFileName), buildSchematicFileName == null ? null : new File(buildSchematicFileName)));
|
||||
});
|
||||
} else {
|
||||
String s = yapionObject.getPlainValueOrDefault("schematic", null);
|
||||
File schematicFile = s == null ? null : new File(s);
|
||||
File testblockSchematicFile = testblock != null ? testblock.getSchematicFile() : null;
|
||||
File buildSchematicFile = build != null ? build.getSchematicFile() : null;
|
||||
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);
|
||||
});
|
||||
}
|
||||
PROTOTYPE_MAP.put(name, this);
|
||||
}
|
||||
|
||||
@Getter
|
||||
public static class SubPrototype {
|
||||
public static class SubPrototype extends YamlConfig {
|
||||
|
||||
private final int offsetX;
|
||||
private final int offsetY;
|
||||
private final int offsetZ;
|
||||
@ConfigField
|
||||
private int offsetX;
|
||||
@ConfigField
|
||||
private int offsetY;
|
||||
@ConfigField
|
||||
private int offsetZ;
|
||||
|
||||
private final int sizeX;
|
||||
private final int sizeY;
|
||||
private final int sizeZ;
|
||||
@ConfigField(required = true)
|
||||
private int sizeX;
|
||||
@ConfigField(required = true)
|
||||
private int sizeY;
|
||||
@ConfigField(required = true)
|
||||
private int sizeZ;
|
||||
|
||||
private final File schematicFile; // Nullable
|
||||
@ConfigField
|
||||
private String schematic;
|
||||
private final File schematicFile;
|
||||
|
||||
private final int extensionNegativeX;
|
||||
private final int extensionPositiveX;
|
||||
private final int extensionNegativeY;
|
||||
private final int extensionPositiveY;
|
||||
private final int extensionNegativeZ;
|
||||
private final int extensionPositiveZ;
|
||||
|
||||
private boolean extensionRegistered;
|
||||
@ConfigField
|
||||
private int extensionNegativeX;
|
||||
@ConfigField
|
||||
private int extensionPositiveX;
|
||||
@ConfigField
|
||||
private int extensionNegativeY;
|
||||
@ConfigField
|
||||
private int extensionPositiveY;
|
||||
@ConfigField
|
||||
private int extensionNegativeZ;
|
||||
@ConfigField
|
||||
private int extensionPositiveZ;
|
||||
private final boolean extensionRegistered;
|
||||
|
||||
@ConfigField
|
||||
private int copyOffsetX;
|
||||
@ConfigField
|
||||
private int copyOffsetY;
|
||||
@ConfigField
|
||||
private int copyOffsetZ;
|
||||
private final boolean hasCopyPoint;
|
||||
private final int copyOffsetX;
|
||||
private final int copyOffsetY;
|
||||
private final int copyOffsetZ;
|
||||
|
||||
private SubPrototype(YAPIONObject yapionObject) {
|
||||
offsetX = yapionObject.getPlainValueOrDefault("offsetX", 0);
|
||||
offsetY = yapionObject.getPlainValueOrDefault("offsetY", 0);
|
||||
offsetZ = yapionObject.getPlainValueOrDefault("offsetZ", 0);
|
||||
public SubPrototype(Map<String, Object> map) {
|
||||
super(map);
|
||||
|
||||
sizeX = yapionObject.getPlainValue("sizeX");
|
||||
sizeY = yapionObject.getPlainValue("sizeY");
|
||||
sizeZ = yapionObject.getPlainValue("sizeZ");
|
||||
|
||||
if (yapionObject.containsKey("schematic", String.class)) {
|
||||
schematicFile = new File(yapionObject.getValue("schematic", String.class).get());
|
||||
} else {
|
||||
schematicFile = null;
|
||||
}
|
||||
|
||||
if (yapionObject.containsKey("extensionX", Integer.class)) {
|
||||
extensionNegativeX = yapionObject.getPlainValue("extensionX");
|
||||
extensionPositiveX = yapionObject.getPlainValue("extensionX");
|
||||
} else {
|
||||
extensionNegativeX = yapionObject.getPlainValueOrDefault("extensionNegativeX", 0);
|
||||
extensionPositiveX = yapionObject.getPlainValueOrDefault("extensionPositiveX", 0);
|
||||
}
|
||||
|
||||
if (yapionObject.containsKey("extensionY", Integer.class)) {
|
||||
extensionNegativeY = yapionObject.getPlainValue("extensionY");
|
||||
extensionPositiveY = yapionObject.getPlainValue("extensionY");
|
||||
} else {
|
||||
extensionNegativeY = yapionObject.getPlainValueOrDefault("extensionNegativeY", 0);
|
||||
extensionPositiveY = yapionObject.getPlainValueOrDefault("extensionPositiveY", 0);
|
||||
}
|
||||
|
||||
if (yapionObject.containsKey("extensionZ", Integer.class)) {
|
||||
extensionNegativeZ = yapionObject.getPlainValue("extensionZ");
|
||||
extensionPositiveZ = yapionObject.getPlainValue("extensionZ");
|
||||
} else {
|
||||
extensionNegativeZ = yapionObject.getPlainValueOrDefault("extensionNegativeZ", 0);
|
||||
extensionPositiveZ = yapionObject.getPlainValueOrDefault("extensionPositiveZ", 0);
|
||||
}
|
||||
schematicFile = schematic != null ? new File(schematic) : null;
|
||||
|
||||
extensionRegistered = extensionNegativeX != 0 || extensionPositiveX != 0 || extensionNegativeY != 0 || extensionPositiveY != 0 || extensionNegativeZ != 0 || extensionPositiveZ != 0;
|
||||
|
||||
copyOffsetX = yapionObject.getPlainValueOrDefault("copyOffsetX", 0);
|
||||
copyOffsetY = yapionObject.getPlainValueOrDefault("copyOffsetY", 0);
|
||||
copyOffsetZ = yapionObject.getPlainValueOrDefault("copyOffsetZ", 0);
|
||||
hasCopyPoint = yapionObject.containsKey("copyOffsetX") || yapionObject.containsKey("copyOffsetY") || yapionObject.containsKey("copyOffsetZ");
|
||||
hasCopyPoint = map.containsKey("copyOffsetX") || map.containsKey("copyOffsetY") || map.containsKey("copyOffsetZ");
|
||||
}
|
||||
}
|
||||
|
||||
public static Region 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);
|
||||
}
|
||||
}
|
||||
|
@ -24,6 +24,8 @@ import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.bukkit.BukkitWorld;
|
||||
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.config.ConfigField;
|
||||
import de.steamwar.bausystem.config.YamlConfig;
|
||||
import de.steamwar.bausystem.region.flags.Flag;
|
||||
import de.steamwar.bausystem.region.flags.flagvalues.ColorMode;
|
||||
import de.steamwar.bausystem.region.flags.flagvalues.TNTMode;
|
||||
@ -32,6 +34,7 @@ import de.steamwar.bausystem.region.utils.RegionExtensionType;
|
||||
import de.steamwar.bausystem.region.utils.RegionType;
|
||||
import de.steamwar.bausystem.shared.SizedStack;
|
||||
import de.steamwar.bausystem.utils.FlatteningWrapper;
|
||||
import de.steamwar.bausystem.worlddata.WorldData;
|
||||
import de.steamwar.core.Core;
|
||||
import de.steamwar.sql.SchematicData;
|
||||
import de.steamwar.sql.SchematicNode;
|
||||
@ -40,9 +43,7 @@ import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import yapion.hierarchy.types.YAPIONObject;
|
||||
import yapion.hierarchy.types.YAPIONType;
|
||||
import yapion.hierarchy.types.YAPIONValue;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@ -56,7 +57,7 @@ import java.util.stream.Collectors;
|
||||
import static de.steamwar.bausystem.region.RegionUtils.paste;
|
||||
|
||||
@Getter
|
||||
public class Region {
|
||||
public class Region extends YamlConfig {
|
||||
|
||||
@Getter
|
||||
private static final Map<String, Region> REGION_MAP = new HashMap<>();
|
||||
@ -80,13 +81,16 @@ public class Region {
|
||||
REGION_MAP.values().forEach(region -> region.set(flagType, value));
|
||||
}
|
||||
|
||||
YAPIONObject regionData;
|
||||
private final String name;
|
||||
@ConfigField
|
||||
private String prototypeName;
|
||||
private final Prototype prototype;
|
||||
|
||||
private String name;
|
||||
private Prototype prototype;
|
||||
private Set<String> prototypes;
|
||||
private String skin;
|
||||
@ConfigField
|
||||
private String linkedRegionName;
|
||||
private Region linkedRegion;
|
||||
|
||||
@ConfigField
|
||||
private Point minPoint;
|
||||
private Point maxPoint;
|
||||
|
||||
@ -108,10 +112,7 @@ public class Region {
|
||||
private Point copyPoint; // Nullable
|
||||
private Point testBlockPoint; // Nullable
|
||||
|
||||
private String linkedRegionName = null; // Nullable
|
||||
private Region linkedRegion = null; // Nullable
|
||||
|
||||
private FlagStorage flagStorage;
|
||||
private final WorldData.RegionConfig config;
|
||||
|
||||
@Getter(AccessLevel.PRIVATE)
|
||||
private SizedStack<EditSession> undoSessions;
|
||||
@ -119,104 +120,62 @@ public class Region {
|
||||
@Getter(AccessLevel.PRIVATE)
|
||||
private SizedStack<EditSession> redoSessions;
|
||||
|
||||
public Region(String name, Prototype prototype, YAPIONObject regionConfig, FlagStorage flagStorage, YAPIONObject regionData) {
|
||||
this.name = name;
|
||||
this.regionData = regionData;
|
||||
if (prototype != null) {
|
||||
REGION_MAP.put(name, this);
|
||||
}
|
||||
public Region(ConfigurationSection regionConfig, WorldData.RegionConfig config) {
|
||||
super(regionConfig);
|
||||
name = regionConfig.getName();
|
||||
prototype = prototypeName != null ? Prototype.getByName(prototypeName) : null;
|
||||
|
||||
linkedRegionName = regionConfig.getPlainValueOrDefault("optionsLinkedWith", null);
|
||||
|
||||
prototypes = new HashSet<>();
|
||||
if (regionConfig.containsKey("prototypes", YAPIONType.ARRAY)) {
|
||||
regionConfig.getArray("prototypes").forEach(yapionAnyType -> {
|
||||
if (yapionAnyType instanceof YAPIONValue) {
|
||||
prototypes.add(((YAPIONValue<String>) yapionAnyType).get());
|
||||
}
|
||||
});
|
||||
}
|
||||
if (regionConfig.containsKey("prototype")) {
|
||||
prototypes.add(regionConfig.getPlainValue("prototype"));
|
||||
}
|
||||
|
||||
this.flagStorage = flagStorage;
|
||||
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"));
|
||||
}
|
||||
if (prototype != null && prototypes.contains(prototype.getName())) {
|
||||
generatePrototypeData(prototype, point);
|
||||
} else if (regionConfig.containsKey("prototype")) {
|
||||
generatePrototypeData(Prototype.getByName(regionConfig.getPlainValue("prototype")), point);
|
||||
}
|
||||
if (prototype != null) {
|
||||
skin = regionData.getPlainValueOrDefault("skin", prototype.getDefaultSkin());
|
||||
if (!prototype.getSkinMap().containsKey(skin)) {
|
||||
skin = prototype.getDefaultSkin();
|
||||
}
|
||||
}
|
||||
regionData.add("skin", skin);
|
||||
this.config = config;
|
||||
|
||||
if (!hasType(RegionType.BUILD) || !hasType(RegionType.TESTBLOCK)) {
|
||||
flagStorage.set(Flag.TNT, TNTMode.DENY);
|
||||
}
|
||||
config.getFlagStorage().set(Flag.TNT, TNTMode.DENY);
|
||||
}
|
||||
|
||||
private void generatePrototypeData(Prototype prototype, Point point) {
|
||||
if (prototype == null) {
|
||||
if(prototype == null)
|
||||
return;
|
||||
|
||||
if (!prototype.getSkins().containsKey(config.getSkin())) {
|
||||
config.setSkin(prototype.getDefaultSkin());
|
||||
}
|
||||
|
||||
this.prototype = prototype;
|
||||
this.skin = prototype.getDefaultSkin();
|
||||
|
||||
this.minPoint = point;
|
||||
this.maxPoint = point.add(prototype.getSizeX() - 1, prototype.getSizeY() - 1, prototype.getSizeZ() - 1);
|
||||
maxPoint = minPoint.add(prototype.getSizeX() - 1, prototype.getSizeY() - 1, prototype.getSizeZ() - 1);
|
||||
|
||||
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() - 1, prototype.getTestblock().getSizeY() - 1, prototype.getTestblock().getSizeZ() - 1);
|
||||
minPointTestblock = minPoint.add(prototype.getTestblock().getOffsetX(), prototype.getTestblock().getOffsetY(), prototype.getTestblock().getOffsetZ());
|
||||
maxPointTestblock = minPointTestblock.add(prototype.getTestblock().getSizeX() - 1, prototype.getTestblock().getSizeY() - 1, prototype.getTestblock().getSizeZ() - 1);
|
||||
|
||||
this.minPointTestblockExtension = this.minPointTestblock.subtract(prototype.getTestblock().getExtensionNegativeX(), prototype.getTestblock().getExtensionNegativeY(), prototype.getTestblock().getExtensionNegativeZ());
|
||||
this.maxPointTestblockExtension = this.maxPointTestblock.add(prototype.getTestblock().getExtensionPositiveX(), prototype.getTestblock().getExtensionPositiveY(), prototype.getTestblock().getExtensionPositiveZ());
|
||||
minPointTestblockExtension = minPointTestblock.subtract(prototype.getTestblock().getExtensionNegativeX(), prototype.getTestblock().getExtensionNegativeY(), prototype.getTestblock().getExtensionNegativeZ());
|
||||
maxPointTestblockExtension = maxPointTestblock.add(prototype.getTestblock().getExtensionPositiveX(), prototype.getTestblock().getExtensionPositiveY(), prototype.getTestblock().getExtensionPositiveZ());
|
||||
|
||||
if (prototype.getTestblock().getCopyOffsetX() != 0 || prototype.getTestblock().getCopyOffsetY() != 0 || prototype.getTestblock().getCopyOffsetZ() != 0) {
|
||||
this.testBlockPoint = this.minPointTestblock.add(prototype.getTestblock().getCopyOffsetX(), prototype.getTestblock().getCopyOffsetY(), prototype.getTestblock().getCopyOffsetZ());
|
||||
testBlockPoint = minPointTestblock.add(prototype.getTestblock().getCopyOffsetX(), prototype.getTestblock().getCopyOffsetY(), prototype.getTestblock().getCopyOffsetZ());
|
||||
} else {
|
||||
this.testBlockPoint = this.minPointTestblock.add(prototype.getTestblock().getSizeX() / 2, 0, -1);
|
||||
testBlockPoint = minPointTestblock.add(prototype.getTestblock().getSizeX() / 2, 0, -1);
|
||||
}
|
||||
}
|
||||
|
||||
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() - 1, prototype.getBuild().getSizeY() - 1, prototype.getBuild().getSizeZ() - 1);
|
||||
minPointBuild = minPoint.add(prototype.getBuild().getOffsetX(), prototype.getBuild().getOffsetY(), prototype.getBuild().getOffsetZ());
|
||||
maxPointBuild = minPointBuild.add(prototype.getBuild().getSizeX() - 1, prototype.getBuild().getSizeY() - 1, prototype.getBuild().getSizeZ() - 1);
|
||||
|
||||
this.minPointBuildExtension = this.minPointBuild.subtract(prototype.getBuild().getExtensionNegativeX(), prototype.getBuild().getExtensionNegativeY(), prototype.getBuild().getExtensionNegativeZ());
|
||||
this.maxPointBuildExtension = this.maxPointBuild.add(prototype.getBuild().getExtensionPositiveX(), prototype.getBuild().getExtensionPositiveY(), prototype.getBuild().getExtensionPositiveZ());
|
||||
minPointBuildExtension = minPointBuild.subtract(prototype.getBuild().getExtensionNegativeX(), prototype.getBuild().getExtensionNegativeY(), prototype.getBuild().getExtensionNegativeZ());
|
||||
maxPointBuildExtension = maxPointBuild.add(prototype.getBuild().getExtensionPositiveX(), prototype.getBuild().getExtensionPositiveY(), prototype.getBuild().getExtensionPositiveZ());
|
||||
|
||||
if (!prototype.getBuild().isHasCopyPoint() && (prototype.getCopyPointOffsetX() != 0 || prototype.getCopyPointOffsetY() != 0 || prototype.getCopyPointOffsetZ() != 0)) {
|
||||
this.copyPoint = minPoint.add(prototype.getCopyPointOffsetX(), prototype.getCopyPointOffsetY(), prototype.getCopyPointOffsetZ());
|
||||
copyPoint = this.minPoint.add(prototype.getCopyPointOffsetX(), prototype.getCopyPointOffsetY(), prototype.getCopyPointOffsetZ());
|
||||
} else if (prototype.getBuild().getCopyOffsetX() != 0 || prototype.getBuild().getCopyOffsetY() != 0 || prototype.getBuild().getCopyOffsetZ() != 0) {
|
||||
this.copyPoint = this.minPointBuild.add(prototype.getBuild().getCopyOffsetX(), prototype.getBuild().getCopyOffsetY(), prototype.getBuild().getCopyOffsetZ());
|
||||
copyPoint = this.minPointBuild.add(prototype.getBuild().getCopyOffsetX(), prototype.getBuild().getCopyOffsetY(), prototype.getBuild().getCopyOffsetZ());
|
||||
} else {
|
||||
this.copyPoint = this.minPointBuild.add(prototype.getBuild().getSizeX() / 2, 0, prototype.getBuild().getSizeZ());
|
||||
copyPoint = this.minPointBuild.add(prototype.getBuild().getSizeX() / 2, 0, prototype.getBuild().getSizeZ());
|
||||
}
|
||||
} else if (prototype.getCopyPointOffsetX() != 0 || prototype.getCopyPointOffsetY() != 0 || prototype.getCopyPointOffsetZ() != 0) {
|
||||
this.copyPoint = minPoint.add(prototype.getCopyPointOffsetX(), prototype.getCopyPointOffsetY(), prototype.getCopyPointOffsetZ());
|
||||
copyPoint = this.minPoint.add(prototype.getCopyPointOffsetX(), prototype.getCopyPointOffsetY(), prototype.getCopyPointOffsetZ());
|
||||
}
|
||||
|
||||
if (prototype.getFloorOffset() != 0) {
|
||||
floorLevel = minPoint.getY() + prototype.getFloorOffset();
|
||||
} else {
|
||||
floorLevel = 0;
|
||||
}
|
||||
floorLevel = prototype.getFloorOffset() != 0 ? this.minPoint.getY() + prototype.getFloorOffset() : 0;
|
||||
waterLevel = prototype.getWaterOffset() != 0 ? this.minPoint.getY() + prototype.getWaterOffset() : 0;
|
||||
|
||||
if (prototype.getWaterOffset() != 0) {
|
||||
waterLevel = minPoint.getY() + prototype.getWaterOffset();
|
||||
} else {
|
||||
waterLevel = 0;
|
||||
}
|
||||
REGION_MAP.put(name, this);
|
||||
}
|
||||
|
||||
public boolean inRegion(Location location, RegionType regionType, RegionExtensionType regionExtensionType) {
|
||||
@ -280,8 +239,12 @@ public class Region {
|
||||
}
|
||||
}
|
||||
|
||||
public String getSkin() {
|
||||
return config.getSkin();
|
||||
}
|
||||
|
||||
public String getDisplayName() {
|
||||
return prototype != null ? prototype.getSkinMap().get(skin).getName() : "";
|
||||
return prototype != null ? config.getSkin() : "";
|
||||
}
|
||||
|
||||
private void setLinkedRegion(Predicate<Region> regionConsumer) {
|
||||
@ -312,66 +275,52 @@ public class Region {
|
||||
return linkedRegion;
|
||||
}
|
||||
|
||||
public boolean setPrototype(@NonNull Prototype prototype) {
|
||||
if (!prototypes.contains(prototype.getName())) {
|
||||
return false;
|
||||
}
|
||||
return _setPrototype(prototype);
|
||||
}
|
||||
|
||||
boolean _setPrototype(@NonNull Prototype prototype) {
|
||||
generatePrototypeData(prototype, minPoint);
|
||||
RegionUtils.save(this);
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean setSkin(@NonNull String skinName) {
|
||||
if (!prototype.getSkinMap().containsKey(skinName)) {
|
||||
if (!prototype.getSkins().containsKey(skinName)) {
|
||||
return false;
|
||||
}
|
||||
this.skin = skinName;
|
||||
config.setSkin(skinName);
|
||||
setLinkedRegion(region -> {
|
||||
region.skin = skinName;
|
||||
region.config.setSkin(skinName);
|
||||
return true;
|
||||
});
|
||||
regionData.add("skin", skin);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void set(Flag flagType, Flag.Value<?> value) {
|
||||
if (flagStorage.set(flagType, value)) {
|
||||
if (config.getFlagStorage().set(flagType, value)) {
|
||||
RegionUtils.save(this);
|
||||
}
|
||||
setLinkedRegion(region -> region.flagStorage.set(flagType, value));
|
||||
setLinkedRegion(region -> region.config.getFlagStorage().set(flagType, value));
|
||||
}
|
||||
|
||||
public void set(Tag tag) {
|
||||
if (flagStorage.set(tag)) {
|
||||
if (config.getFlagStorage().set(tag)) {
|
||||
RegionUtils.save(this);
|
||||
}
|
||||
setLinkedRegion(region -> region.flagStorage.set(tag));
|
||||
setLinkedRegion(region -> region.config.getFlagStorage().set(tag));
|
||||
}
|
||||
|
||||
public void remove(Tag tag) {
|
||||
if (flagStorage.remove(tag)) {
|
||||
if (config.getFlagStorage().remove(tag)) {
|
||||
RegionUtils.save(this);
|
||||
}
|
||||
}
|
||||
|
||||
public Flag.Value<?> get(Flag flagType) {
|
||||
return flagStorage.get(flagType);
|
||||
return config.getFlagStorage().get(flagType);
|
||||
}
|
||||
|
||||
public boolean get(Tag tagType) {
|
||||
return flagStorage.is(tagType);
|
||||
return config.getFlagStorage().is(tagType);
|
||||
}
|
||||
|
||||
public <T extends Enum<T> & Flag.Value<T>> T getPlain(Flag flagType) {
|
||||
return (T) flagStorage.get(flagType).getValue();
|
||||
return (T) config.getFlagStorage().get(flagType).getValue();
|
||||
}
|
||||
|
||||
public <T extends Enum<T> & Flag.Value<T>> T getPlain(Flag flagType, Class<T> type) {
|
||||
return (T) flagStorage.get(flagType).getValue();
|
||||
return (T) config.getFlagStorage().get(flagType).getValue();
|
||||
}
|
||||
|
||||
public Point getMinPoint(RegionType regionType, RegionExtensionType regionExtensionType) {
|
||||
@ -404,12 +353,12 @@ public class Region {
|
||||
}
|
||||
switch (regionType) {
|
||||
case TESTBLOCK:
|
||||
return prototype.getSkinMap().get(skin).getTestblockSchematicFile() != null;
|
||||
return prototype.getSkins().get(config.getSkin()).getTestblockSchematicFile() != null;
|
||||
case BUILD:
|
||||
return prototype.getSkinMap().get(skin).getBuildSchematicFile() != null;
|
||||
return prototype.getSkins().get(config.getSkin()).getBuildSchematicFile() != null;
|
||||
default:
|
||||
case NORMAL:
|
||||
return prototype.getSkinMap().get(skin).getSchematicFile() != null;
|
||||
return prototype.getSkins().get(config.getSkin()).getSchematicFile() != null;
|
||||
}
|
||||
}
|
||||
|
||||
@ -456,13 +405,13 @@ public class Region {
|
||||
case BUILD:
|
||||
pastePoint = minPointBuild.add(prototype.getBuild().getSizeX() / 2, 0, prototype.getBuild().getSizeZ() / 2);
|
||||
if (schematic == null) {
|
||||
tempFile = prototype.getSkinMap().get(skin).getBuildSchematicFile();
|
||||
tempFile = prototype.getSkins().get(config.getSkin()).getBuildSchematicFile();
|
||||
}
|
||||
break;
|
||||
case TESTBLOCK:
|
||||
pastePoint = minPointTestblock.add(prototype.getTestblock().getSizeX() / 2, 0, 0);
|
||||
if (schematic == null) {
|
||||
tempFile = prototype.getSkinMap().get(skin).getTestblockSchematicFile();
|
||||
tempFile = prototype.getSkins().get(config.getSkin()).getTestblockSchematicFile();
|
||||
pastePoint = pastePoint.add(0, 0, prototype.getTestblock().getSizeZ() / 2);
|
||||
} else {
|
||||
clipboard = new SchematicData(schematic).load();
|
||||
@ -483,7 +432,7 @@ public class Region {
|
||||
case NORMAL:
|
||||
pastePoint = minPoint.add(prototype.getSizeX() / 2, 0, prototype.getSizeZ() / 2);
|
||||
if (schematic == null) {
|
||||
tempFile = prototype.getSkinMap().get(skin).getSchematicFile();
|
||||
tempFile = prototype.getSkins().get(config.getSkin()).getSchematicFile();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -79,11 +79,7 @@ public class RegionUtils {
|
||||
}
|
||||
|
||||
static void save(Region region) {
|
||||
if (region.getPrototype() != null) {
|
||||
region.regionData.add("prototype", region.getPrototype().getName());
|
||||
}
|
||||
region.regionData.add("flagStorage", FlagStorage.toYAPION(region.getFlagStorage()));
|
||||
WorldData.write();
|
||||
WorldData.getInstance().save();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -22,39 +22,19 @@ package de.steamwar.bausystem.region.loader;
|
||||
import de.steamwar.bausystem.region.Prototype;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.bukkit.Bukkit;
|
||||
import yapion.hierarchy.diff.DiffDelete;
|
||||
import yapion.hierarchy.diff.YAPIONDiff;
|
||||
import yapion.hierarchy.types.YAPIONObject;
|
||||
import yapion.parser.YAPIONParser;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
@UtilityClass
|
||||
public class PrototypeLoader {
|
||||
|
||||
private YAPIONObject loaded = null;
|
||||
public static final File file = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "prototypes.yapion");
|
||||
public static final File file = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "prototypes.yml");
|
||||
|
||||
public void load() {
|
||||
YAPIONObject yapionObject = null;
|
||||
try (BufferedInputStream bufferedInputStream = new BufferedInputStream(new FileInputStream(file))) {
|
||||
yapionObject = YAPIONParser.parse(bufferedInputStream);
|
||||
} catch (IOException e) {
|
||||
throw new SecurityException(e.getMessage(), e);
|
||||
}
|
||||
YamlConfiguration config = YamlConfiguration.loadConfiguration(file);
|
||||
|
||||
if (loaded != null && new YAPIONDiff(loaded, yapionObject).getDiffs().stream().anyMatch(DiffDelete.class::isInstance)) {
|
||||
throw new SecurityException("Version was not the specified version needed.");
|
||||
}
|
||||
loaded = yapionObject;
|
||||
|
||||
yapionObject.forEach((key, yapionAnyType) -> {
|
||||
if (yapionAnyType instanceof YAPIONObject) {
|
||||
new Prototype(key, (YAPIONObject) yapionAnyType);
|
||||
}
|
||||
});
|
||||
for(String key : config.getKeys(false))
|
||||
new Prototype(config.getConfigurationSection(key));
|
||||
}
|
||||
}
|
||||
|
@ -19,73 +19,29 @@
|
||||
|
||||
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 de.steamwar.bausystem.region.Region;
|
||||
import de.steamwar.bausystem.worlddata.WorldData;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.bukkit.Bukkit;
|
||||
import yapion.hierarchy.diff.DiffChange;
|
||||
import yapion.hierarchy.diff.YAPIONDiff;
|
||||
import yapion.hierarchy.types.YAPIONObject;
|
||||
import yapion.hierarchy.types.YAPIONType;
|
||||
import yapion.parser.YAPIONParser;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
@UtilityClass
|
||||
public class RegionLoader {
|
||||
|
||||
private YAPIONObject loaded = null;
|
||||
public static final File file = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "regions.yapion");
|
||||
public static final File file = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "regions.yml");
|
||||
|
||||
public void load() {
|
||||
YAPIONObject yapionObject = null;
|
||||
try (BufferedInputStream bufferedInputStream = new BufferedInputStream(new FileInputStream(file))) {
|
||||
yapionObject = YAPIONParser.parse(bufferedInputStream);
|
||||
} catch (IOException e) {
|
||||
throw new SecurityException(e.getMessage(), e);
|
||||
}
|
||||
YamlConfiguration config = YamlConfiguration.loadConfiguration(file);
|
||||
|
||||
if (loaded != null && new YAPIONDiff(loaded, yapionObject).getDiffs().stream().anyMatch(diffBase -> !(diffBase instanceof DiffChange))) {
|
||||
throw new SecurityException("Version was not the specified version needed.");
|
||||
for(String key : config.getKeys(false)) {
|
||||
WorldData.RegionConfig regionConfig = WorldData.getInstance().getRegionConfig(key);
|
||||
if(key.equals("global"))
|
||||
new GlobalRegion(config.getConfigurationSection(key), regionConfig);
|
||||
else
|
||||
new Region(config.getConfigurationSection(key), regionConfig);
|
||||
}
|
||||
loaded = yapionObject;
|
||||
|
||||
YAPIONObject optionsYapionObject = WorldData.getRegionsData();
|
||||
yapionObject.forEach((key, yapionAnyType) -> {
|
||||
if (key.equals("global")) {
|
||||
return;
|
||||
}
|
||||
if (!(yapionAnyType instanceof YAPIONObject)) {
|
||||
return;
|
||||
}
|
||||
|
||||
YAPIONObject regionConfig = (YAPIONObject) yapionAnyType;
|
||||
YAPIONObject regionData = new YAPIONObject();
|
||||
if (optionsYapionObject.containsKey(key, YAPIONType.OBJECT)) {
|
||||
regionData = optionsYapionObject.getObject(key);
|
||||
} else {
|
||||
optionsYapionObject.add(key, regionData);
|
||||
}
|
||||
|
||||
Prototype.generateRegion(key, regionConfig, regionData);
|
||||
});
|
||||
|
||||
YAPIONObject globalOptions = optionsYapionObject.getObject("global");
|
||||
if (globalOptions == null) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -1,47 +0,0 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2021 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.loader;
|
||||
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class Updater {
|
||||
|
||||
private long lastUpdate;
|
||||
|
||||
public Updater(File file, Runnable updaterCode) {
|
||||
this.lastUpdate = file.lastModified();
|
||||
Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), () -> {
|
||||
if (file.lastModified() > lastUpdate + 10) {
|
||||
try {
|
||||
updaterCode.run();
|
||||
Bukkit.getLogger().log(Level.INFO, "Update complete of " + file.getAbsolutePath());
|
||||
} catch (Exception e) {
|
||||
Bukkit.getLogger().log(Level.INFO, "Error while loading file " + file.getAbsolutePath() + " for config: " + e.getMessage(), e);
|
||||
}
|
||||
lastUpdate = file.lastModified();
|
||||
}
|
||||
}, 20, 20);
|
||||
}
|
||||
|
||||
}
|
@ -19,9 +19,17 @@
|
||||
|
||||
package de.steamwar.bausystem.worlddata;
|
||||
|
||||
import de.steamwar.bausystem.config.ConfigField;
|
||||
import de.steamwar.bausystem.config.YamlConfig;
|
||||
import de.steamwar.bausystem.region.FlagStorage;
|
||||
import de.steamwar.sql.SteamwarUser;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import de.steamwar.sql.UserConfig;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.configuration.serialization.ConfigurationSerialization;
|
||||
import yapion.hierarchy.output.FileOutput;
|
||||
import yapion.hierarchy.types.YAPIONObject;
|
||||
import yapion.parser.InputStreamCharsets;
|
||||
@ -32,60 +40,62 @@ import java.io.BufferedInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@UtilityClass
|
||||
public class WorldData {
|
||||
public class WorldData extends YamlConfig {
|
||||
|
||||
private final File optionsFile = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "options.yapion");
|
||||
private YAPIONObject worldData;
|
||||
|
||||
public YAPIONObject getWorldData() {
|
||||
if (worldData == null) {
|
||||
read();
|
||||
}
|
||||
return worldData;
|
||||
static {
|
||||
ConfigurationSerialization.registerClass(FlagStorage.class);
|
||||
YamlConfig.register(RegionConfig.class);
|
||||
}
|
||||
|
||||
public YAPIONObject getRegionsData() {
|
||||
return getWorldData().getYAPIONObjectOrSetDefault("regions", new YAPIONObject());
|
||||
private static final File optionsFile = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "options.yml");
|
||||
@Getter
|
||||
private static WorldData instance = new WorldData(YamlConfiguration.loadConfiguration(optionsFile));
|
||||
|
||||
@ConfigField
|
||||
private final Map<String, RegionConfig> regionConfigs = new HashMap<>();
|
||||
|
||||
|
||||
public WorldData(ConfigurationSection configuration) {
|
||||
super(configuration);
|
||||
instance = this;
|
||||
}
|
||||
|
||||
public RegionConfig getRegionConfig(String region) {
|
||||
return regionConfigs.computeIfAbsent(region, name -> new RegionConfig());
|
||||
}
|
||||
|
||||
public YAPIONObject getWarpData() {
|
||||
return getWorldData().getYAPIONObjectOrSetDefault("warps", new YAPIONObject());
|
||||
}
|
||||
|
||||
private void read() {
|
||||
worldData = new YAPIONObject();
|
||||
if (optionsFile.length() != 0) {
|
||||
try (BufferedInputStream bufferedInputStream = new BufferedInputStream(new FileInputStream(optionsFile))) {
|
||||
worldData = YAPIONParser.parse(bufferedInputStream, new StreamOptions().charset(InputStreamCharsets.UTF_8));
|
||||
if (!worldData.containsKey("regions")) {
|
||||
YAPIONObject yapionObject = new YAPIONObject();
|
||||
yapionObject.add("regions", worldData);
|
||||
worldData = yapionObject;
|
||||
write();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
// Ignored
|
||||
}
|
||||
}
|
||||
public void save() {
|
||||
YamlConfiguration config = new YamlConfiguration();
|
||||
for(Map.Entry<String, Object> entry : serialize().entrySet())
|
||||
config.set(entry.getKey(), entry.getValue());
|
||||
|
||||
// Conversion from old simulator saving to new one
|
||||
if (worldData.containsKey("simulators")) {
|
||||
YAPIONObject yapionObject = worldData.getObject("simulators");
|
||||
worldData.remove("simulators");
|
||||
yapionObject.forEach((s, yapionAnyType) -> {
|
||||
SteamwarUser steamwarUser = SteamwarUser.get(Integer.parseInt(s));
|
||||
SimulatorData.saveSimulator(steamwarUser, new YAPIONObject().add("", yapionAnyType));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public void write() {
|
||||
try {
|
||||
worldData.toYAPION(new FileOutput(optionsFile)).close();
|
||||
} catch (IOException e) {
|
||||
// Ignored
|
||||
config.save(optionsFile);
|
||||
} catch (IOException ignored) {}
|
||||
}
|
||||
|
||||
@Getter
|
||||
public static class RegionConfig extends YamlConfig {
|
||||
|
||||
@ConfigField(required = true)
|
||||
private FlagStorage flagStorage;
|
||||
@Setter
|
||||
@ConfigField
|
||||
private String skin;
|
||||
|
||||
private RegionConfig() {
|
||||
flagStorage = new FlagStorage();
|
||||
}
|
||||
|
||||
public RegionConfig(Map<String, Object> map) {
|
||||
super(map);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren