SteamWar/BauSystem2.0
Archiviert
12
0

YeetAPION: Region
Einige Prüfungen sind fehlgeschlagen
SteamWarCI Build failed

Dieser Commit ist enthalten in:
Lixfel 2023-05-14 19:30:31 +02:00
Ursprung d72d62c9ee
Commit 9d4a718796
17 geänderte Dateien mit 315 neuen und 593 gelöschten Zeilen

Datei anzeigen

@ -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_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_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_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_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_HELP_CHANGESKIN=§8/§eregion changeskin §8[§7Skin§8] §8- §8Sets the region skin
REGION_REGION_NOTHING_UNDO=§cNothing left to undo 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_TP_UNKNOWN=§cUndefined teleport point
REGION_REGION_NO_REGION=§cYou are not inside any region REGION_REGION_NO_REGION=§cYou are not inside any region
REGION_REGION_NO_PERMS=§cYou are not allowed to change the 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=§7Region skin is §e{0}
REGION_REGION_CHANGESKIN_INFO_CREATOR=§7Skin created by §e{0} REGION_REGION_CHANGESKIN_INFO_CREATOR=§7Skin created by §e{0}
REGION_REGION_CHANGESKIN_UNKNOWN=§cRegion skin is invalid REGION_REGION_CHANGESKIN_UNKNOWN=§cRegion skin is invalid

Datei anzeigen

@ -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_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_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_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_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_HELP_CHANGESKIN=§8/§eregion changeskin §8[§7Skin§8] §8- §8Setzte den Regions Skin
REGION_REGION_NOTHING_UNDO=§cNichts zum rückgängig machen 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_TP_UNKNOWN=§cNicht definierter Teleportierpunkt
REGION_REGION_NO_REGION=§cDu bist in keiner Region REGION_REGION_NO_REGION=§cDu bist in keiner Region
REGION_REGION_NO_PERMS=§cDu darfst hier nicht die Region verändern 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=§7Regions Skin ist §e{0}
REGION_REGION_CHANGESKIN_INFO_CREATOR=§7Skin erstellt von §e{0} REGION_REGION_CHANGESKIN_INFO_CREATOR=§7Skin erstellt von §e{0}
REGION_REGION_CHANGESKIN_UNKNOWN=§cRegions Skin ist nicht valide REGION_REGION_CHANGESKIN_UNKNOWN=§cRegions Skin ist nicht valide

Datei anzeigen

@ -21,11 +21,10 @@ package de.steamwar.bausystem;
import com.comphenix.tinyprotocol.TinyProtocol; import com.comphenix.tinyprotocol.TinyProtocol;
import de.steamwar.bausystem.configplayer.Config; 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.PrototypeLoader;
import de.steamwar.bausystem.region.loader.RegionLoader; import de.steamwar.bausystem.region.loader.RegionLoader;
import de.steamwar.bausystem.region.loader.Updater;
import de.steamwar.bausystem.worlddata.WorldData; import de.steamwar.bausystem.worlddata.WorldData;
import de.steamwar.bausystem.linkage.LinkageUtils;
import de.steamwar.message.Message; import de.steamwar.message.Message;
import lombok.Getter; import lombok.Getter;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -69,9 +68,6 @@ public class BauSystem extends JavaPlugin implements Listener {
return; return;
} }
new Updater(PrototypeLoader.file, PrototypeLoader::load);
new Updater(RegionLoader.file, RegionLoader::load);
LinkageUtils.link(); LinkageUtils.link();
// This could disable any watchdog stuff. We need to investigate if this is a problem. // 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() { public void onDisable() {
LinkageUtils.unlink(); LinkageUtils.unlink();
WorldData.write(); WorldData.getInstance().save();
Config.saveAll(); Config.saveAll();
TinyProtocol.instance.close(); TinyProtocol.instance.close();
} }

Datei anzeigen

@ -26,4 +26,6 @@ import java.lang.annotation.Target;
@Target({ElementType.FIELD}) @Target({ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
public @interface ConfigField {} public @interface ConfigField {
boolean required() default false;
}

Datei anzeigen

@ -34,6 +34,8 @@ public class YamlConfig implements ConfigurationSerializable {
ConfigurationSerialization.registerClass(configType); ConfigurationSerialization.registerClass(configType);
} }
public YamlConfig() {}
public YamlConfig(ConfigurationSection configuration) { public YamlConfig(ConfigurationSection configuration) {
this(configuration.getValues(false)); this(configuration.getValues(false));
} }
@ -42,15 +44,13 @@ public class YamlConfig implements ConfigurationSerializable {
Arrays.stream(getClass().getDeclaredFields()) Arrays.stream(getClass().getDeclaredFields())
.filter(field -> field.isAnnotationPresent(ConfigField.class)) .filter(field -> field.isAnnotationPresent(ConfigField.class))
.forEach(field -> { .forEach(field -> {
String name = field.getName();
try { try {
field.setAccessible(true); field.setAccessible(true);
field.set(this, map.computeIfAbsent(field.getName(), name -> { field.set(this, map.containsKey(name) ? map.get(name) : getClass().getDeclaredField(name.toUpperCase() + "_DEFAULT").get(null));
try { } catch (NoSuchFieldException e) {
return getClass().getDeclaredField(name.toUpperCase() + "_DEFAULT").get(null); if(field.getAnnotation(ConfigField.class).required())
} catch (IllegalAccessException | NoSuchFieldException e) { throw new IllegalStateException(getClass().getName() + "." + field.getName() + " is required", e);
throw new IllegalStateException(getClass().getName() + "." + field.getName() + " has no default field", e);
}
}));
} catch (IllegalAccessException e) { } catch (IllegalAccessException e) {
throw new IllegalStateException(getClass().getName() + "." + field.getName() + " is inaccessible for deserializer", e); throw new IllegalStateException(getClass().getName() + "." + field.getName() + " is inaccessible for deserializer", e);
} }

Datei anzeigen

@ -30,7 +30,6 @@ import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerQuitEvent;
import java.io.StringReader; import java.io.StringReader;
@ -57,7 +56,6 @@ public class Config extends YamlConfig {
@Setter @Setter
@ConfigField @ConfigField
private boolean nightvision; private boolean nightvision;
private static final boolean NIGHTVISION_DEFAULT = false;
private Config(UUID uuid, ConfigurationSection configuration) { private Config(UUID uuid, ConfigurationSection configuration) {
super(configuration); super(configuration);
@ -73,10 +71,6 @@ public class Config extends YamlConfig {
@Linked @Linked
public static class ConfigListener implements Listener { public static class ConfigListener implements Listener {
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
get(event.getPlayer());
}
@EventHandler @EventHandler
public void onPlayerQuit(PlayerQuitEvent event) { public void onPlayerQuit(PlayerQuitEvent event) {

Datei anzeigen

@ -22,11 +22,11 @@ package de.steamwar.bausystem.features.region;
import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.Permission;
import de.steamwar.bausystem.features.util.SelectCommand; import de.steamwar.bausystem.features.util.SelectCommand;
import de.steamwar.bausystem.region.Prototype;
import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.region.Region;
import de.steamwar.bausystem.region.RegionUtils; import de.steamwar.bausystem.region.RegionUtils;
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 de.steamwar.bausystem.worlddata.WorldData;
import de.steamwar.command.PreviousArguments; import de.steamwar.command.PreviousArguments;
import de.steamwar.command.SWCommand; import de.steamwar.command.SWCommand;
import de.steamwar.command.TypeMapper; import de.steamwar.command.TypeMapper;
@ -155,36 +155,6 @@ public class RegionCommand extends SWCommand {
BauSystem.MESSAGE.send("REGION_REGION_TP_TEST_BLOCK", p); 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(value = "changeskin", description = "REGION_REGION_HELP_CHANGESKIN_INFO")
@Register("skin") @Register("skin")
public void changeSkinCommand(Player p) { public void changeSkinCommand(Player p) {
@ -193,7 +163,7 @@ public class RegionCommand extends SWCommand {
return; return;
} }
BauSystem.MESSAGE.send("REGION_REGION_CHANGESKIN_INFO", p, region.getSkin()); 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) { if (creator != null) {
BauSystem.MESSAGE.send("REGION_REGION_CHANGESKIN_INFO_CREATOR", p, creator); BauSystem.MESSAGE.send("REGION_REGION_CHANGESKIN_INFO_CREATOR", p, creator);
} }
@ -206,10 +176,11 @@ public class RegionCommand extends SWCommand {
if (checkGlobalRegion(region, p)) { if (checkGlobalRegion(region, p)) {
return; return;
} }
if (!region.getPrototype().getSkinMap().containsKey(s)) { if (!region.getPrototype().getSkins().containsKey(s)) {
BauSystem.MESSAGE.send("REGION_REGION_CHANGESKIN_UNKNOWN", p); BauSystem.MESSAGE.send("REGION_REGION_CHANGESKIN_UNKNOWN", p);
} else { } else {
if (region.setSkin(s)) { if (region.setSkin(s)) {
WorldData.getInstance().save();
BauSystem.MESSAGE.send("REGION_REGION_CHANGESKIN_CHANGE", p, s); 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")); 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 { } 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) @Mapper(value = "skinTypeMapper", local = true)
private TypeMapper<String> skinTypeMapper() { private TypeMapper<String> skinTypeMapper() {
return new TypeMapper<String>() { return new TypeMapper<String>() {
@ -248,7 +199,7 @@ public class RegionCommand extends SWCommand {
if (region.isGlobal()) { if (region.isGlobal()) {
return Collections.emptyList(); 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 @Override

Datei anzeigen

@ -19,64 +19,45 @@
package de.steamwar.bausystem.region; package de.steamwar.bausystem.region;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.region.flags.Flag; import de.steamwar.bausystem.region.flags.Flag;
import de.steamwar.bausystem.region.tags.Tag; 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.*;
import java.util.HashSet; import java.util.logging.Level;
import java.util.Map;
import java.util.Set;
/** /**
* Tags and Flags are not allowed to have overlaping names. * Tags and Flags are not allowed to have overlaping names.
*/ */
public class FlagStorage { public class FlagStorage implements ConfigurationSerializable {
public static FlagStorage createStorage(YAPIONObject yapionObject) { private final Map<Flag, Flag.Value<?>> flags = new EnumMap<>(Flag.class);
FlagStorage flagStorage = new FlagStorage(); private final Set<Tag> tags = new HashSet<>();
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;
public FlagStorage() { public FlagStorage() {
flags = new EnumMap<>(Flag.class); for (final Flag flag : Flag.getFlags()) {
tagSet = new HashSet<>(); flags.put(flag, flag.getDefaultValue());
readKeys(); }
}
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) { public boolean set(final Flag flagType, final Flag.Value<?> value) {
@ -88,20 +69,22 @@ public class FlagStorage {
} }
public boolean set(final Tag tag) { public boolean set(final Tag tag) {
return tagSet.add(tag); return tags.add(tag);
} }
public boolean remove(final Tag tag) { public boolean remove(final Tag tag) {
return tagSet.remove(tag); return tags.remove(tag);
} }
public boolean is(final Tag tag) { public boolean is(final Tag tag) {
return tagSet.contains(tag); return tags.contains(tag);
} }
private void readKeys() { @Override
for (final Flag flag : Flag.getFlags()) { public Map<String, Object> serialize() {
flags.put(flag, flag.getDefaultValue()); 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;
} }
} }

Datei anzeigen

@ -21,17 +21,18 @@ package de.steamwar.bausystem.region;
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 de.steamwar.bausystem.worlddata.WorldData;
import lombok.Getter; import lombok.Getter;
import org.bukkit.Location; import org.bukkit.Location;
import yapion.hierarchy.types.YAPIONObject; import org.bukkit.configuration.ConfigurationSection;
public class GlobalRegion extends Region { public class GlobalRegion extends Region {
@Getter @Getter
static GlobalRegion instance; static GlobalRegion instance;
public GlobalRegion(FlagStorage flagStorage, YAPIONObject regionData) { public GlobalRegion(ConfigurationSection regionConfig, WorldData.RegionConfig config) {
super("global", null, new YAPIONObject(), flagStorage, regionData); super(regionConfig, config);
instance = this; instance = this;
} }

Datei anzeigen

@ -19,6 +19,8 @@
package de.steamwar.bausystem.region; package de.steamwar.bausystem.region;
import de.steamwar.bausystem.config.ConfigField;
import de.steamwar.bausystem.config.YamlConfig;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import lombok.Getter; import lombok.Getter;
@ -27,15 +29,24 @@ import org.bukkit.Location;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.Map;
@Getter @Getter
@ToString @ToString
@EqualsAndHashCode @EqualsAndHashCode(callSuper = false)
@AllArgsConstructor @AllArgsConstructor
public class Point { public class Point extends YamlConfig {
private final int x; @ConfigField(required = true)
private final int y; private int x;
private final int z; @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) { public static Point fromLocation(final Location location) {
return new Point(location.getBlockX(), location.getBlockY(), location.getBlockZ()); return new Point(location.getBlockX(), location.getBlockY(), location.getBlockZ());

Datei anzeigen

@ -19,10 +19,10 @@
package de.steamwar.bausystem.region; package de.steamwar.bausystem.region;
import lombok.AllArgsConstructor; import de.steamwar.bausystem.config.ConfigField;
import de.steamwar.bausystem.config.YamlConfig;
import lombok.Getter; import lombok.Getter;
import yapion.hierarchy.types.YAPIONObject; import org.bukkit.configuration.ConfigurationSection;
import yapion.hierarchy.types.YAPIONType;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
@ -31,7 +31,12 @@ import java.util.List;
import java.util.Map; import java.util.Map;
@Getter @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<>(); static final Map<String, Prototype> PROTOTYPE_MAP = new HashMap<>();
@ -47,180 +52,131 @@ public class Prototype {
return new ArrayList<>(PROTOTYPE_MAP.values()); return new ArrayList<>(PROTOTYPE_MAP.values());
} }
@AllArgsConstructor
@Getter @Getter
public static class Skin { public static class Skin extends YamlConfig {
private final String name; @ConfigField
private final String creator; // Nullable private String creator;
@ConfigField(required = true)
private String schematic;
private final File schematicFile; 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 name;
private final String displayName; @ConfigField
private final String defaultSkin; private String displayName;
private final Map<String, Skin> skinMap = new HashMap<>(); @ConfigField
private String defaultSkin;
@ConfigField(required = true)
private Map<String, Skin> skins;
private final int sizeX; @ConfigField(required = true)
private final int sizeY; private int sizeX;
private final int sizeZ; @ConfigField(required = true)
private int sizeY;
@ConfigField(required = true)
private int sizeZ;
private final int floorOffset; @ConfigField
private final int waterOffset; private int floorOffset;
@ConfigField
private int waterOffset;
private final SubPrototype testblock; // Nullable @ConfigField
private final SubPrototype build; // Nullable private SubPrototype testblock;
@ConfigField
private SubPrototype build;
private final int copyPointOffsetX; @ConfigField
private final int copyPointOffsetY; private int copyPointOffsetX;
private final int copyPointOffsetZ; @ConfigField
private int copyPointOffsetY;
@ConfigField
private int copyPointOffsetZ;
public Prototype(String name, YAPIONObject yapionObject) { public Prototype(ConfigurationSection config) {
this.name = name; super(config);
displayName = yapionObject.getPlainValueOrDefault("displayName", name); name = config.getName();
sizeX = yapionObject.getPlainValue("sizeX"); if(displayName == null)
sizeY = yapionObject.getPlainValue("sizeY"); displayName = name;
sizeZ = yapionObject.getPlainValue("sizeZ"); if(defaultSkin == null)
defaultSkin = displayName;
copyPointOffsetX = yapionObject.getPlainValueOrDefault("copyOffsetX", 0); skins.entrySet().removeIf(entry -> entry.getValue().isDisabled());
copyPointOffsetY = yapionObject.getPlainValueOrDefault("copyOffsetY", 0);
copyPointOffsetZ = yapionObject.getPlainValueOrDefault("copyOffsetZ", 0);
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); PROTOTYPE_MAP.put(name, this);
} }
@Getter @Getter
public static class SubPrototype { public static class SubPrototype extends YamlConfig {
private final int offsetX; @ConfigField
private final int offsetY; private int offsetX;
private final int offsetZ; @ConfigField
private int offsetY;
@ConfigField
private int offsetZ;
private final int sizeX; @ConfigField(required = true)
private final int sizeY; private int sizeX;
private final int sizeZ; @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; @ConfigField
private final int extensionPositiveX; private int extensionNegativeX;
private final int extensionNegativeY; @ConfigField
private final int extensionPositiveY; private int extensionPositiveX;
private final int extensionNegativeZ; @ConfigField
private final int extensionPositiveZ; private int extensionNegativeY;
@ConfigField
private boolean extensionRegistered; 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 boolean hasCopyPoint;
private final int copyOffsetX;
private final int copyOffsetY;
private final int copyOffsetZ;
private SubPrototype(YAPIONObject yapionObject) { public SubPrototype(Map<String, Object> map) {
offsetX = yapionObject.getPlainValueOrDefault("offsetX", 0); super(map);
offsetY = yapionObject.getPlainValueOrDefault("offsetY", 0);
offsetZ = yapionObject.getPlainValueOrDefault("offsetZ", 0);
sizeX = yapionObject.getPlainValue("sizeX"); schematicFile = schematic != null ? new File(schematic) : null;
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);
}
extensionRegistered = extensionNegativeX != 0 || extensionPositiveX != 0 || extensionNegativeY != 0 || extensionPositiveY != 0 || extensionNegativeZ != 0 || extensionPositiveZ != 0; extensionRegistered = extensionNegativeX != 0 || extensionPositiveX != 0 || extensionNegativeY != 0 || extensionPositiveY != 0 || extensionNegativeZ != 0 || extensionPositiveZ != 0;
copyOffsetX = yapionObject.getPlainValueOrDefault("copyOffsetX", 0); hasCopyPoint = map.containsKey("copyOffsetX") || map.containsKey("copyOffsetY") || map.containsKey("copyOffsetZ");
copyOffsetY = yapionObject.getPlainValueOrDefault("copyOffsetY", 0);
copyOffsetZ = yapionObject.getPlainValueOrDefault("copyOffsetZ", 0);
hasCopyPoint = yapionObject.containsKey("copyOffsetX") || yapionObject.containsKey("copyOffsetY") || yapionObject.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);
}
} }

Datei anzeigen

@ -24,6 +24,8 @@ import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.bukkit.BukkitWorld; import com.sk89q.worldedit.bukkit.BukkitWorld;
import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.extent.clipboard.Clipboard;
import de.steamwar.bausystem.BauSystem; 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.Flag;
import de.steamwar.bausystem.region.flags.flagvalues.ColorMode; import de.steamwar.bausystem.region.flags.flagvalues.ColorMode;
import de.steamwar.bausystem.region.flags.flagvalues.TNTMode; 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.region.utils.RegionType;
import de.steamwar.bausystem.shared.SizedStack; import de.steamwar.bausystem.shared.SizedStack;
import de.steamwar.bausystem.utils.FlatteningWrapper; import de.steamwar.bausystem.utils.FlatteningWrapper;
import de.steamwar.bausystem.worlddata.WorldData;
import de.steamwar.core.Core; import de.steamwar.core.Core;
import de.steamwar.sql.SchematicData; import de.steamwar.sql.SchematicData;
import de.steamwar.sql.SchematicNode; import de.steamwar.sql.SchematicNode;
@ -40,9 +43,7 @@ import lombok.Getter;
import lombok.NonNull; import lombok.NonNull;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import yapion.hierarchy.types.YAPIONObject; import org.bukkit.configuration.ConfigurationSection;
import yapion.hierarchy.types.YAPIONType;
import yapion.hierarchy.types.YAPIONValue;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@ -56,7 +57,7 @@ import java.util.stream.Collectors;
import static de.steamwar.bausystem.region.RegionUtils.paste; import static de.steamwar.bausystem.region.RegionUtils.paste;
@Getter @Getter
public class Region { public class Region extends YamlConfig {
@Getter @Getter
private static final Map<String, Region> REGION_MAP = new HashMap<>(); 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)); 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; @ConfigField
private Prototype prototype; private String linkedRegionName;
private Set<String> prototypes; private Region linkedRegion;
private String skin;
@ConfigField
private Point minPoint; private Point minPoint;
private Point maxPoint; private Point maxPoint;
@ -108,10 +112,7 @@ public class Region {
private Point copyPoint; // Nullable private Point copyPoint; // Nullable
private Point testBlockPoint; // Nullable private Point testBlockPoint; // Nullable
private String linkedRegionName = null; // Nullable private final WorldData.RegionConfig config;
private Region linkedRegion = null; // Nullable
private FlagStorage flagStorage;
@Getter(AccessLevel.PRIVATE) @Getter(AccessLevel.PRIVATE)
private SizedStack<EditSession> undoSessions; private SizedStack<EditSession> undoSessions;
@ -119,104 +120,62 @@ public class Region {
@Getter(AccessLevel.PRIVATE) @Getter(AccessLevel.PRIVATE)
private SizedStack<EditSession> redoSessions; private SizedStack<EditSession> redoSessions;
public Region(String name, Prototype prototype, YAPIONObject regionConfig, FlagStorage flagStorage, YAPIONObject regionData) { public Region(ConfigurationSection regionConfig, WorldData.RegionConfig config) {
this.name = name; super(regionConfig);
this.regionData = regionData; name = regionConfig.getName();
if (prototype != null) { prototype = prototypeName != null ? Prototype.getByName(prototypeName) : null;
REGION_MAP.put(name, this);
}
linkedRegionName = regionConfig.getPlainValueOrDefault("optionsLinkedWith", null); this.config = config;
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);
if (!hasType(RegionType.BUILD) || !hasType(RegionType.TESTBLOCK)) { 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; return;
if (!prototype.getSkins().containsKey(config.getSkin())) {
config.setSkin(prototype.getDefaultSkin());
} }
this.prototype = prototype; maxPoint = minPoint.add(prototype.getSizeX() - 1, prototype.getSizeY() - 1, prototype.getSizeZ() - 1);
this.skin = prototype.getDefaultSkin();
this.minPoint = point;
this.maxPoint = point.add(prototype.getSizeX() - 1, prototype.getSizeY() - 1, prototype.getSizeZ() - 1);
if (prototype.getTestblock() != null) { if (prototype.getTestblock() != null) {
this.minPointTestblock = point.add(prototype.getTestblock().getOffsetX(), prototype.getTestblock().getOffsetY(), prototype.getTestblock().getOffsetZ()); minPointTestblock = minPoint.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); 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()); minPointTestblockExtension = 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()); 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) { 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 { } 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) { if (prototype.getBuild() != null) {
this.minPointBuild = point.add(prototype.getBuild().getOffsetX(), prototype.getBuild().getOffsetY(), prototype.getBuild().getOffsetZ()); minPointBuild = minPoint.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); 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()); minPointBuildExtension = 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()); 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)) { 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) { } 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 { } 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) { } 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 = prototype.getFloorOffset() != 0 ? this.minPoint.getY() + prototype.getFloorOffset() : 0;
floorLevel = minPoint.getY() + prototype.getFloorOffset(); waterLevel = prototype.getWaterOffset() != 0 ? this.minPoint.getY() + prototype.getWaterOffset() : 0;
} else {
floorLevel = 0;
}
if (prototype.getWaterOffset() != 0) { REGION_MAP.put(name, this);
waterLevel = minPoint.getY() + prototype.getWaterOffset();
} else {
waterLevel = 0;
}
} }
public boolean inRegion(Location location, RegionType regionType, RegionExtensionType regionExtensionType) { 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() { public String getDisplayName() {
return prototype != null ? prototype.getSkinMap().get(skin).getName() : ""; return prototype != null ? config.getSkin() : "";
} }
private void setLinkedRegion(Predicate<Region> regionConsumer) { private void setLinkedRegion(Predicate<Region> regionConsumer) {
@ -312,66 +275,52 @@ public class Region {
return linkedRegion; 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) { public boolean setSkin(@NonNull String skinName) {
if (!prototype.getSkinMap().containsKey(skinName)) { if (!prototype.getSkins().containsKey(skinName)) {
return false; return false;
} }
this.skin = skinName; config.setSkin(skinName);
setLinkedRegion(region -> { setLinkedRegion(region -> {
region.skin = skinName; region.config.setSkin(skinName);
return true; return true;
}); });
regionData.add("skin", skin);
return true; return true;
} }
public void set(Flag flagType, Flag.Value<?> value) { public void set(Flag flagType, Flag.Value<?> value) {
if (flagStorage.set(flagType, value)) { if (config.getFlagStorage().set(flagType, value)) {
RegionUtils.save(this); RegionUtils.save(this);
} }
setLinkedRegion(region -> region.flagStorage.set(flagType, value)); setLinkedRegion(region -> region.config.getFlagStorage().set(flagType, value));
} }
public void set(Tag tag) { public void set(Tag tag) {
if (flagStorage.set(tag)) { if (config.getFlagStorage().set(tag)) {
RegionUtils.save(this); RegionUtils.save(this);
} }
setLinkedRegion(region -> region.flagStorage.set(tag)); setLinkedRegion(region -> region.config.getFlagStorage().set(tag));
} }
public void remove(Tag tag) { public void remove(Tag tag) {
if (flagStorage.remove(tag)) { if (config.getFlagStorage().remove(tag)) {
RegionUtils.save(this); RegionUtils.save(this);
} }
} }
public Flag.Value<?> get(Flag flagType) { public Flag.Value<?> get(Flag flagType) {
return flagStorage.get(flagType); return config.getFlagStorage().get(flagType);
} }
public boolean get(Tag tagType) { 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) { 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) { 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) { public Point getMinPoint(RegionType regionType, RegionExtensionType regionExtensionType) {
@ -404,12 +353,12 @@ public class Region {
} }
switch (regionType) { switch (regionType) {
case TESTBLOCK: case TESTBLOCK:
return prototype.getSkinMap().get(skin).getTestblockSchematicFile() != null; return prototype.getSkins().get(config.getSkin()).getTestblockSchematicFile() != null;
case BUILD: case BUILD:
return prototype.getSkinMap().get(skin).getBuildSchematicFile() != null; return prototype.getSkins().get(config.getSkin()).getBuildSchematicFile() != null;
default: default:
case NORMAL: 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: case BUILD:
pastePoint = minPointBuild.add(prototype.getBuild().getSizeX() / 2, 0, prototype.getBuild().getSizeZ() / 2); pastePoint = minPointBuild.add(prototype.getBuild().getSizeX() / 2, 0, prototype.getBuild().getSizeZ() / 2);
if (schematic == null) { if (schematic == null) {
tempFile = prototype.getSkinMap().get(skin).getBuildSchematicFile(); tempFile = prototype.getSkins().get(config.getSkin()).getBuildSchematicFile();
} }
break; break;
case TESTBLOCK: case TESTBLOCK:
pastePoint = minPointTestblock.add(prototype.getTestblock().getSizeX() / 2, 0, 0); pastePoint = minPointTestblock.add(prototype.getTestblock().getSizeX() / 2, 0, 0);
if (schematic == null) { 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); pastePoint = pastePoint.add(0, 0, prototype.getTestblock().getSizeZ() / 2);
} else { } else {
clipboard = new SchematicData(schematic).load(); clipboard = new SchematicData(schematic).load();
@ -483,7 +432,7 @@ public class Region {
case NORMAL: case NORMAL:
pastePoint = minPoint.add(prototype.getSizeX() / 2, 0, prototype.getSizeZ() / 2); pastePoint = minPoint.add(prototype.getSizeX() / 2, 0, prototype.getSizeZ() / 2);
if (schematic == null) { if (schematic == null) {
tempFile = prototype.getSkinMap().get(skin).getSchematicFile(); tempFile = prototype.getSkins().get(config.getSkin()).getSchematicFile();
} }
break; break;
} }

Datei anzeigen

@ -79,11 +79,7 @@ public class RegionUtils {
} }
static void save(Region region) { static void save(Region region) {
if (region.getPrototype() != null) { WorldData.getInstance().save();
region.regionData.add("prototype", region.getPrototype().getName());
}
region.regionData.add("flagStorage", FlagStorage.toYAPION(region.getFlagStorage()));
WorldData.write();
} }
} }

Datei anzeigen

@ -22,39 +22,19 @@ 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.diff.DiffDelete; import org.bukkit.configuration.file.YamlConfiguration;
import yapion.hierarchy.diff.YAPIONDiff;
import yapion.hierarchy.types.YAPIONObject;
import yapion.parser.YAPIONParser;
import java.io.BufferedInputStream;
import java.io.File; import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
@UtilityClass @UtilityClass
public class PrototypeLoader { public class PrototypeLoader {
private YAPIONObject loaded = null; public static final File file = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "prototypes.yml");
public static final File file = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "prototypes.yapion");
public void load() { public void load() {
YAPIONObject yapionObject = null; YamlConfiguration config = YamlConfiguration.loadConfiguration(file);
try (BufferedInputStream bufferedInputStream = new BufferedInputStream(new FileInputStream(file))) {
yapionObject = YAPIONParser.parse(bufferedInputStream);
} catch (IOException e) {
throw new SecurityException(e.getMessage(), e);
}
if (loaded != null && new YAPIONDiff(loaded, yapionObject).getDiffs().stream().anyMatch(DiffDelete.class::isInstance)) { for(String key : config.getKeys(false))
throw new SecurityException("Version was not the specified version needed."); new Prototype(config.getConfigurationSection(key));
}
loaded = yapionObject;
yapionObject.forEach((key, yapionAnyType) -> {
if (yapionAnyType instanceof YAPIONObject) {
new Prototype(key, (YAPIONObject) yapionAnyType);
}
});
} }
} }

Datei anzeigen

@ -19,73 +19,29 @@
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.GlobalRegion;
import de.steamwar.bausystem.region.Prototype; import de.steamwar.bausystem.region.Region;
import de.steamwar.bausystem.worlddata.WorldData; import de.steamwar.bausystem.worlddata.WorldData;
import lombok.experimental.UtilityClass; import lombok.experimental.UtilityClass;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import yapion.hierarchy.diff.DiffChange; import org.bukkit.configuration.file.YamlConfiguration;
import yapion.hierarchy.diff.YAPIONDiff;
import yapion.hierarchy.types.YAPIONObject;
import yapion.hierarchy.types.YAPIONType;
import yapion.parser.YAPIONParser;
import java.io.BufferedInputStream;
import java.io.File; import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
@UtilityClass @UtilityClass
public class RegionLoader { public class RegionLoader {
private YAPIONObject loaded = null; public static final File file = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "regions.yml");
public static final File file = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "regions.yapion");
public void load() { public void load() {
YAPIONObject yapionObject = null; YamlConfiguration config = YamlConfiguration.loadConfiguration(file);
try (BufferedInputStream bufferedInputStream = new BufferedInputStream(new FileInputStream(file))) {
yapionObject = YAPIONParser.parse(bufferedInputStream); for(String key : config.getKeys(false)) {
} catch (IOException e) { WorldData.RegionConfig regionConfig = WorldData.getInstance().getRegionConfig(key);
throw new SecurityException(e.getMessage(), e); if(key.equals("global"))
new GlobalRegion(config.getConfigurationSection(key), regionConfig);
else
new Region(config.getConfigurationSection(key), regionConfig);
} }
if (loaded != null && new YAPIONDiff(loaded, yapionObject).getDiffs().stream().anyMatch(diffBase -> !(diffBase instanceof DiffChange))) {
throw new SecurityException("Version was not the specified version needed.");
}
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);
} }
} }

Datei anzeigen

@ -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);
}
}

Datei anzeigen

@ -19,9 +19,17 @@
package de.steamwar.bausystem.worlddata; 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 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.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.output.FileOutput;
import yapion.hierarchy.types.YAPIONObject; import yapion.hierarchy.types.YAPIONObject;
import yapion.parser.InputStreamCharsets; import yapion.parser.InputStreamCharsets;
@ -32,60 +40,62 @@ import java.io.BufferedInputStream;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
@UtilityClass public class WorldData extends YamlConfig {
public class WorldData {
private final File optionsFile = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "options.yapion"); static {
private YAPIONObject worldData; ConfigurationSerialization.registerClass(FlagStorage.class);
YamlConfig.register(RegionConfig.class);
public YAPIONObject getWorldData() {
if (worldData == null) {
read();
}
return worldData;
} }
public YAPIONObject getRegionsData() { private static final File optionsFile = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "options.yml");
return getWorldData().getYAPIONObjectOrSetDefault("regions", new YAPIONObject()); @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() { public YAPIONObject getWarpData() {
return getWorldData().getYAPIONObjectOrSetDefault("warps", new YAPIONObject()); return getWorldData().getYAPIONObjectOrSetDefault("warps", new YAPIONObject());
} }
private void read() { public void save() {
worldData = new YAPIONObject(); YamlConfiguration config = new YamlConfiguration();
if (optionsFile.length() != 0) { for(Map.Entry<String, Object> entry : serialize().entrySet())
try (BufferedInputStream bufferedInputStream = new BufferedInputStream(new FileInputStream(optionsFile))) { config.set(entry.getKey(), entry.getValue());
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
}
}
// Conversion from old simulator saving to new one try {
if (worldData.containsKey("simulators")) { config.save(optionsFile);
YAPIONObject yapionObject = worldData.getObject("simulators"); } catch (IOException ignored) {}
worldData.remove("simulators");
yapionObject.forEach((s, yapionAnyType) -> {
SteamwarUser steamwarUser = SteamwarUser.get(Integer.parseInt(s));
SimulatorData.saveSimulator(steamwarUser, new YAPIONObject().add("", yapionAnyType));
});
}
} }
public void write() { @Getter
try { public static class RegionConfig extends YamlConfig {
worldData.toYAPION(new FileOutput(optionsFile)).close();
} catch (IOException e) { @ConfigField(required = true)
// Ignored private FlagStorage flagStorage;
@Setter
@ConfigField
private String skin;
private RegionConfig() {
flagStorage = new FlagStorage();
}
public RegionConfig(Map<String, Object> map) {
super(map);
} }
} }
} }