YeetAPION #176
@ -43,9 +43,6 @@ sourceSets {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
// implementation 'yoyosource:YAPION:0.25.3'
|
||||
implementation files("${projectDir}/../libs/YAPION-SNAPSHOT.jar")
|
||||
|
||||
compileOnly 'org.projectlombok:lombok:1.18.22'
|
||||
testCompileOnly 'org.projectlombok:lombok:1.18.22'
|
||||
annotationProcessor 'org.projectlombok:lombok:1.18.22'
|
||||
|
@ -802,8 +802,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
|
||||
@ -820,12 +818,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
|
||||
|
@ -765,8 +765,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
|
||||
@ -783,12 +781,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
|
||||
|
@ -26,11 +26,10 @@ import de.steamwar.bausystem.features.tpslimit.TPSLimitUtils;
|
||||
import de.steamwar.bausystem.features.tpslimit.TPSUtils;
|
||||
import de.steamwar.bausystem.features.tpslimit.TPSWarpUtils;
|
||||
import de.steamwar.bausystem.features.world.RamUsage;
|
||||
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;
|
||||
@ -79,9 +78,6 @@ public class BauSystem extends JavaPlugin implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
new Updater(PrototypeLoader.file, PrototypeLoader::load);
|
||||
new Updater(RegionLoader.file, RegionLoader::load);
|
||||
|
||||
LinkageUtils.link();
|
||||
RamUsage.init();
|
||||
|
||||
@ -107,8 +103,8 @@ public class BauSystem extends JavaPlugin implements Listener {
|
||||
public void onDisable() {
|
||||
LinkageUtils.unlink();
|
||||
|
||||
WorldData.write();
|
||||
Config.getInstance().saveAll();
|
||||
WorldData.getInstance().save();
|
||||
Config.saveAll();
|
||||
TinyProtocol.instance.close();
|
||||
}
|
||||
|
||||
|
31
BauSystem_Main/src/de/steamwar/bausystem/config/ConfigField.java
Normale Datei
31
BauSystem_Main/src/de/steamwar/bausystem/config/ConfigField.java
Normale Datei
@ -0,0 +1,31 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 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.config;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Target({ElementType.FIELD})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface ConfigField {
|
||||
boolean required() default false;
|
||||
}
|
95
BauSystem_Main/src/de/steamwar/bausystem/config/YamlConfig.java
Normale Datei
95
BauSystem_Main/src/de/steamwar/bausystem/config/YamlConfig.java
Normale Datei
@ -0,0 +1,95 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 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.config;
|
||||
|
||||
import de.steamwar.sql.UserConfig;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.configuration.serialization.ConfigurationSerializable;
|
||||
import org.bukkit.configuration.serialization.ConfigurationSerialization;
|
||||
|
||||
import java.io.StringReader;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class YamlConfig implements ConfigurationSerializable {
|
||||
|
||||
public static void register(Class<? extends YamlConfig> configType) {
|
||||
ConfigurationSerialization.registerClass(configType);
|
||||
}
|
||||
|
||||
public static YamlConfiguration fromUserConfig(UUID uuid, String name) {
|
||||
String config = UserConfig.getConfig(uuid, name);
|
||||
if(config == null)
|
||||
return new YamlConfiguration();
|
||||
|
||||
return YamlConfiguration.loadConfiguration(new StringReader(config));
|
||||
}
|
||||
|
||||
public YamlConfig() {}
|
||||
|
||||
public YamlConfig(ConfigurationSection configuration) {
|
||||
this(configuration.getValues(false));
|
||||
}
|
||||
|
||||
public YamlConfig(Map<String, Object> map) {
|
||||
Arrays.stream(getClass().getDeclaredFields())
|
||||
.filter(field -> field.isAnnotationPresent(ConfigField.class))
|
||||
.forEach(field -> {
|
||||
String name = field.getName();
|
||||
try {
|
||||
field.setAccessible(true);
|
||||
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);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> serialize() {
|
||||
return Arrays.stream(getClass().getDeclaredFields())
|
||||
.filter(field -> field.isAnnotationPresent(ConfigField.class))
|
||||
.collect(Collectors.toMap(
|
||||
Field::getName,
|
||||
field -> {
|
||||
try {
|
||||
field.setAccessible(true);
|
||||
return field.get(this);
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new IllegalStateException(getClass().getName() + "." + field.getName() + " is inaccessible for serializer", e);
|
||||
}
|
||||
}
|
||||
));
|
||||
}
|
||||
|
||||
public YamlConfiguration toYaml() {
|
||||
YamlConfiguration config = new YamlConfiguration();
|
||||
for(Map.Entry<String, Object> entry : serialize().entrySet())
|
||||
config.set(entry.getKey(), entry.getValue());
|
||||
return config;
|
||||
}
|
||||
}
|
@ -19,129 +19,120 @@
|
||||
|
||||
package de.steamwar.bausystem.configplayer;
|
||||
|
||||
import de.steamwar.bausystem.configplayer.serializer.ConfigurationSerializableSerializer;
|
||||
import de.steamwar.bausystem.config.ConfigField;
|
||||
import de.steamwar.bausystem.config.YamlConfig;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import de.steamwar.sql.UserConfig;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.Bukkit;
|
||||
import lombok.Setter;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
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 yapion.hierarchy.output.StringOutput;
|
||||
import yapion.hierarchy.types.YAPIONObject;
|
||||
import yapion.parser.YAPIONParser;
|
||||
import yapion.serializing.SerializeManager;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
|
||||
@Linked
|
||||
public class Config implements Listener {
|
||||
public class Config extends YamlConfig {
|
||||
|
||||
|
||||
static {
|
||||
SerializeManager.add(new ConfigurationSerializableSerializer());
|
||||
private static final Map<UUID, Config> playerConfigurations = new HashMap<>();
|
||||
|
||||
public static Config get(Player player) { //TODO: NULL
|
||||
return playerConfigurations.computeIfAbsent(player.getUniqueId(), uuid -> new Config(uuid, fromUserConfig(uuid, "bausystem")));
|
||||
}
|
||||
|
||||
@Getter
|
||||
private static Config instance;
|
||||
|
||||
{
|
||||
instance = this;
|
||||
}
|
||||
|
||||
private final Map<UUID, YAPIONObject> playerConfigurations = new HashMap<>();
|
||||
|
||||
private static final Map<Integer, ConfigConverter> CONFIG_CONVERTER_MAP = new HashMap<>();
|
||||
|
||||
public static void addConfigConverter(ConfigConverter configConverter) {
|
||||
CONFIG_CONVERTER_MAP.putIfAbsent(configConverter.version(), configConverter);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
get(event.getPlayer());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||
save(event.getPlayer());
|
||||
playerConfigurations.remove(event.getPlayer().getUniqueId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a PlayerConfig, optionally loads it from the DataBase and migrates it if necessary.
|
||||
*
|
||||
* @param player the player from whom to get the config.
|
||||
* @return the config object
|
||||
*/
|
||||
public YAPIONObject get(Player player) {
|
||||
UUID uuid = player.getUniqueId();
|
||||
if (!playerConfigurations.containsKey(uuid)) {
|
||||
String s = UserConfig.getConfig(uuid, "bausystem");
|
||||
YAPIONObject yapionObject;
|
||||
if (s == null) {
|
||||
yapionObject = ConfigCreator.createDefaultConfig();
|
||||
} else {
|
||||
yapionObject = YAPIONParser.parse(s);
|
||||
}
|
||||
yapionObject = update(yapionObject);
|
||||
playerConfigurations.put(uuid, yapionObject);
|
||||
return yapionObject;
|
||||
}
|
||||
return playerConfigurations.get(uuid);
|
||||
}
|
||||
|
||||
public void saveAll() {
|
||||
playerConfigurations.forEach((uuid, yapionObject) -> {
|
||||
String string = yapionObject.toYAPION(new StringOutput()).getResult();
|
||||
UserConfig.updatePlayerConfig(uuid, "bausystem", string);
|
||||
});
|
||||
public static void saveAll() {
|
||||
playerConfigurations.forEach((uuid, config) -> config.save());
|
||||
playerConfigurations.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Save a PlayerConfig, this does not remove the key value mapping from the map.
|
||||
*
|
||||
* @param player the player to save the config.
|
||||
*/
|
||||
public void save(Player player) {
|
||||
UUID uuid = player.getUniqueId();
|
||||
if (playerConfigurations.containsKey(uuid)) {
|
||||
YAPIONObject yapionObject = playerConfigurations.get(uuid);
|
||||
String string = yapionObject.toYAPION(new StringOutput()).getResult();
|
||||
UserConfig.updatePlayerConfig(uuid, "bausystem", string);
|
||||
private final UUID uuid;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@ConfigField
|
||||
private boolean nightvision;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@ConfigField
|
||||
private boolean simulatorAutoTrace;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@ConfigField
|
||||
private boolean detonatorAutostart;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@ConfigField
|
||||
private boolean blockCounter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@ConfigField
|
||||
private boolean smartPlace;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@ConfigField
|
||||
private boolean inventoryFill;
|
||||
|
||||
@Getter
|
||||
@ConfigField
|
||||
private final Map<String, Integer> baugui = new HashMap<>();
|
||||
|
||||
private Config(UUID uuid, ConfigurationSection configuration) {
|
||||
super(configuration);
|
||||
this.uuid = uuid;
|
||||
|
||||
if(baugui.isEmpty()) {
|
||||
// 0: ? | 1: ? | 2: 10 | 3: 3 | 4: 7 | 5: 17 | 6: 15 | 7: ? | 8: ?
|
||||
// 9: 5 | 10: ? | 11: ? | 12: ? | 13: ? | 14: ? | 15: ? | 16: ? | 17: 16
|
||||
// 18: 4 | 19: ? | 20: 19 | 21: 21 | 22: 9 | 23: 0 | 24: 1 | 25: ? | 26: 11
|
||||
// 27: 6 | 28: ? | 29: ? | 30: ? | 31: ? | 32: ? | 33: ? | 34: ? | 35: 18
|
||||
// 36: ? | 37: 23 | 38: 20 | 39: 8 | 40: 22 | 41: 26 | 42: 12 | 43: 14 | 44: ?
|
||||
|
||||
baugui.put("size", 45);
|
||||
baugui.put("10", 2);
|
||||
baugui.put("3", 3);
|
||||
baugui.put("7", 4);
|
||||
baugui.put("17", 5);
|
||||
baugui.put("15", 6);
|
||||
baugui.put("5", 9);
|
||||
baugui.put("16", 17);
|
||||
baugui.put("4", 18);
|
||||
baugui.put("19", 20);
|
||||
baugui.put("21", 21);
|
||||
baugui.put("9", 22);
|
||||
baugui.put("0", 23);
|
||||
baugui.put("1", 24);
|
||||
baugui.put("11", 26);
|
||||
baugui.put("6", 27);
|
||||
baugui.put("18", 35);
|
||||
baugui.put("23", 37);
|
||||
baugui.put("20", 38);
|
||||
baugui.put("8", 39);
|
||||
baugui.put("22", 40);
|
||||
baugui.put("26", 41);
|
||||
baugui.put("12", 42);
|
||||
baugui.put("14", 43);
|
||||
}
|
||||
}
|
||||
|
||||
private YAPIONObject update(YAPIONObject yapionObject) {
|
||||
int version = yapionObject.getPlainValue("@version");
|
||||
while (version < ConfigCreator.currentVersion) {
|
||||
ConfigConverter configConverter = CONFIG_CONVERTER_MAP.getOrDefault(version, null);
|
||||
if (configConverter == null) {
|
||||
Bukkit.getLogger().log(Level.SEVERE, "No updater found for version " + version);
|
||||
return ConfigCreator.createDefaultConfig();
|
||||
}
|
||||
try {
|
||||
configConverter.update(yapionObject);
|
||||
} catch (Exception e) {
|
||||
Bukkit.getLogger().log(Level.SEVERE, e.getMessage(), e);
|
||||
return ConfigCreator.createDefaultConfig();
|
||||
}
|
||||
int newVersion = yapionObject.getPlainValue("@version");
|
||||
if (version == newVersion) {
|
||||
Bukkit.getLogger().log(Level.SEVERE, "Version Tag was the same after conversion");
|
||||
return ConfigCreator.createDefaultConfig();
|
||||
}
|
||||
if (newVersion < version) {
|
||||
Bukkit.getLogger().log(Level.SEVERE, "Version Tag was earlier after conversion");
|
||||
return ConfigCreator.createDefaultConfig();
|
||||
}
|
||||
version = newVersion;
|
||||
public void save() {
|
||||
UserConfig.updatePlayerConfig(uuid, "bausystem", toYaml().saveToString());
|
||||
}
|
||||
|
||||
@Linked
|
||||
public static class ConfigListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||
get(event.getPlayer()).save();
|
||||
playerConfigurations.remove(event.getPlayer().getUniqueId());
|
||||
}
|
||||
return yapionObject;
|
||||
}
|
||||
}
|
||||
|
@ -1,37 +0,0 @@
|
||||
package de.steamwar.bausystem.configplayer;
|
||||
|
||||
import yapion.hierarchy.types.YAPIONObject;
|
||||
|
||||
/**
|
||||
* A new {@link ConfigConverter} should be written when you remove anything
|
||||
* from the Config or modify any mayor part. When you move anything from
|
||||
* any key to any other key you should write a new {@link ConfigConverter}.
|
||||
* For adding any new key you should be able to get the default without
|
||||
* having it in the Config. Anything you need to change you should also
|
||||
* change the {@link ConfigCreator} accordingly, to produce the new Config.
|
||||
*/
|
||||
public interface ConfigConverter {
|
||||
|
||||
/**
|
||||
* This describes the version this Converter can convert from. The version
|
||||
* it should convert to is the version 1 above this number. But this is not
|
||||
* a necessity. In the config Object as parameter given in {@link #update(YAPIONObject)}
|
||||
* you should update the <b>@version</b> variable in the root object to the
|
||||
* new version this converter produced.
|
||||
*
|
||||
* @return the version number
|
||||
*/
|
||||
int version();
|
||||
|
||||
/**
|
||||
* This method should update everything needed to go from a lower config
|
||||
* version to a higher. It should update the <b>@version</b> variable
|
||||
* accordingly. Anything else is up the implementation. If anything goes wrong
|
||||
* do not silently exit this method, throw an Exception. The updater Code will
|
||||
* deal with it. Never leave the inputted object in a corrupted state.
|
||||
*
|
||||
* @param config the config object to update
|
||||
*/
|
||||
void update(YAPIONObject config);
|
||||
|
||||
}
|
@ -1,61 +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.configplayer;
|
||||
|
||||
import de.steamwar.bausystem.features.hotbar.DefaultHotbar;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import yapion.hierarchy.types.YAPIONObject;
|
||||
|
||||
@UtilityClass
|
||||
public class ConfigCreator {
|
||||
|
||||
public static final int currentVersion = 1;
|
||||
|
||||
public YAPIONObject createDefaultConfig() {
|
||||
YAPIONObject yapionObject = new YAPIONObject();
|
||||
// This call should never be touched
|
||||
yapionObject.add("@version", currentVersion);
|
||||
|
||||
// Any initialising goes into here
|
||||
yapionObject.add("baugui", defaultBauGui());
|
||||
|
||||
// Default Hotbar Gui
|
||||
yapionObject.add("hotbar", DefaultHotbar.defaultHotbar());
|
||||
return yapionObject;
|
||||
}
|
||||
|
||||
private YAPIONObject defaultBauGui() {
|
||||
YAPIONObject yapionObject = new YAPIONObject();
|
||||
|
||||
// 0: ? | 1: ? | 2: 10 | 3: 3 | 4: 7 | 5: 17 | 6: 15 | 7: ? | 8: ?
|
||||
// 9: 5 | 10: ? | 11: ? | 12: ? | 13: ? | 14: ? | 15: ? | 16: ? | 17: 16
|
||||
// 18: 4 | 19: ? | 20: 19 | 21: 21 | 22: 9 | 23: 0 | 24: 1 | 25: ? | 26: 11
|
||||
// 27: 6 | 28: ? | 29: ? | 30: ? | 31: ? | 32: ? | 33: ? | 34: ? | 35: 18
|
||||
// 36: ? | 37: 23 | 38: 20 | 39: 8 | 40: 22 | 41: 26 | 42: 12 | 43: 14 | 44: ?
|
||||
|
||||
yapionObject.add("10", 2).add("3", 3).add("7", 4).add("17", 5).add("15", 6);
|
||||
yapionObject.add("5", 9).add("4", 18).add("6", 27);
|
||||
yapionObject.add("16", 17).add("11", 26).add("18", 35);
|
||||
yapionObject.add("19", 20).add("21", 21).add("9", 22).add("0", 23).add("1", 24);
|
||||
yapionObject.add("23", 37).add("20", 38).add("8", 39).add("22", 40).add("26", 41).add("12", 42).add("14", 43);
|
||||
yapionObject.add("size", 45);
|
||||
return yapionObject;
|
||||
}
|
||||
}
|
@ -1,90 +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.configplayer.serializer;
|
||||
|
||||
import org.bukkit.configuration.serialization.ConfigurationSerializable;
|
||||
import org.bukkit.configuration.serialization.ConfigurationSerialization;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import yapion.hierarchy.api.groups.YAPIONAnyType;
|
||||
import yapion.hierarchy.types.YAPIONObject;
|
||||
import yapion.serializing.api.SerializerObject;
|
||||
import yapion.serializing.data.DeserializeData;
|
||||
import yapion.serializing.data.SerializeData;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static yapion.utils.IdentifierUtils.TYPE_IDENTIFIER;
|
||||
|
||||
public class ConfigurationSerializableSerializer extends SerializerObject<ConfigurationSerializable> {
|
||||
|
||||
@Override
|
||||
public Class<ConfigurationSerializable> type() {
|
||||
return ConfigurationSerializable.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInterface() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public YAPIONObject serialize(SerializeData<ConfigurationSerializable> serializeData) {
|
||||
YAPIONObject yapionObject = new YAPIONObject();
|
||||
yapionObject.add(TYPE_IDENTIFIER, serializeData.object.getClass().getTypeName());
|
||||
if (serializeData.object instanceof ItemStack) {
|
||||
yapionObject.add(TYPE_IDENTIFIER, ItemStack.class.getTypeName());
|
||||
}
|
||||
if (serializeData.object instanceof ItemMeta) {
|
||||
yapionObject.add(TYPE_IDENTIFIER, ItemMeta.class.getTypeName());
|
||||
}
|
||||
Map<String, Object> serializeDataMap = serializeData.object.serialize();
|
||||
serializeDataMap.forEach((s, o) -> {
|
||||
YAPIONAnyType yapionAnyType = serializeData.serialize(o);
|
||||
if (yapionAnyType instanceof YAPIONObject) {
|
||||
YAPIONObject object = (YAPIONObject) yapionAnyType;
|
||||
if (object.containsKey(TYPE_IDENTIFIER) && object.getPlainValue(TYPE_IDENTIFIER).equals("com.google.common.collect.RegularImmutableList")) {
|
||||
object.put(TYPE_IDENTIFIER, ArrayList.class.getTypeName());
|
||||
}
|
||||
}
|
||||
yapionObject.add(s, yapionAnyType);
|
||||
});
|
||||
return yapionObject;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigurationSerializable deserialize(DeserializeData<YAPIONObject> deserializeData) {
|
||||
Map<String, Object> deserializeDataMap = new HashMap<>();
|
||||
deserializeData.object.forEach((s, yapionAnyType) -> {
|
||||
if (s.equals(TYPE_IDENTIFIER)) {
|
||||
if (yapionAnyType.toString().equals("(org.bukkit.inventory.meta.ItemMeta)")) {
|
||||
deserializeDataMap.put("==", "ItemMeta");
|
||||
} else {
|
||||
deserializeDataMap.put("==", deserializeData.deserialize(yapionAnyType));
|
||||
}
|
||||
return;
|
||||
}
|
||||
deserializeDataMap.put(s, deserializeData.deserialize(yapionAnyType));
|
||||
});
|
||||
return ConfigurationSerialization.deserializeObject(deserializeDataMap);
|
||||
}
|
||||
}
|
@ -79,7 +79,7 @@ public class Detonator {
|
||||
|
||||
public static void activateDetonator(DetonatorStorage detonator) {
|
||||
Player p = detonator.getPlayer();
|
||||
if (Config.getInstance().get(p).getPlainValueOrDefault("detonator-autostart", false)) {
|
||||
if (Config.get(p).isDetonatorAutostart()) {
|
||||
AutostartListener.instance.activate(p);
|
||||
}
|
||||
|
||||
|
@ -76,8 +76,8 @@ public class DetonatorCommand extends SWCommand {
|
||||
|
||||
@Register(value = "autostart", description = "DETONATOR_HELP_AUTOSTART")
|
||||
public void toggleAutostartTimer(Player p) {
|
||||
boolean current = Config.getInstance().get(p).getPlainValueOrDefault("detonator-autostart", false);
|
||||
Config.getInstance().get(p).put("detonator-autostart", !current);
|
||||
boolean current = Config.get(p).isDetonatorAutostart();
|
||||
Config.get(p).setDetonatorAutostart(!current);
|
||||
if (!current) {
|
||||
BauSystem.MESSAGE.send("DETONATOR_AUTOSTART_ENABLE", p);
|
||||
} else {
|
||||
|
@ -67,7 +67,7 @@ public class BauGUI {
|
||||
if (!updating) {
|
||||
OPEN_INVS.add(p);
|
||||
}
|
||||
BauGuiMapping mapping = BauGuiMapping.getGuiMapping(p);
|
||||
BauGuiMapping mapping = new BauGuiMapping(p);
|
||||
SWInventory inv = new SWInventory(p, mapping.getSize(), BauSystem.MESSAGE.parse("GUI_NAME", p));
|
||||
getITEMS().values().forEach(item -> {
|
||||
if (!mapping.isShown(item.getId())) {
|
||||
|
@ -53,7 +53,7 @@ public class BauGuiEditor implements Listener {
|
||||
private static final List<Player> open_Edits = new ArrayList<>();
|
||||
|
||||
public static void openGuiEditor(Player p, ItemStack cursor) {
|
||||
BauGuiMapping mapping = BauGuiMapping.getGuiMapping(p);
|
||||
BauGuiMapping mapping = new BauGuiMapping(p);
|
||||
Inventory inv = Bukkit.createInventory(null, mapping.getSize() + 9, BauSystem.MESSAGE.parse("GUI_EDITOR_TITLE", p));
|
||||
for (Map.Entry<Integer, Integer> e : mapping.getMapping().entrySet()) {
|
||||
if (e.getValue() >= 0) {
|
||||
@ -78,7 +78,6 @@ public class BauGuiEditor implements Listener {
|
||||
p.openInventory(inv);
|
||||
p.getOpenInventory().setCursor(cursor == null ? new SWItem().getItemStack() : cursor);
|
||||
open_Edits.add(p);
|
||||
BauGuiMapping.startWatchdog();
|
||||
}
|
||||
|
||||
private static ItemStack addId(ItemStack itemStack, int id) {
|
||||
@ -101,7 +100,7 @@ public class BauGuiEditor implements Listener {
|
||||
|
||||
ItemStack i = event.getCurrentItem();
|
||||
Player p = (Player) event.getWhoClicked();
|
||||
BauGuiMapping mapping = BauGuiMapping.getGuiMapping(p);
|
||||
BauGuiMapping mapping = new BauGuiMapping(p);
|
||||
if (event.getClickedInventory() == p.getInventory()) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
@ -194,13 +193,10 @@ public class BauGuiEditor implements Listener {
|
||||
}
|
||||
|
||||
private void saveMapping(Player p) {
|
||||
saveMapping(p.getOpenInventory(), BauGuiMapping.getGuiMapping(p));
|
||||
saveMapping(p.getOpenInventory(), new BauGuiMapping(p));
|
||||
}
|
||||
|
||||
private void saveMapping(InventoryView view, BauGuiMapping mapping) {
|
||||
if (mapping.isSaved()) {
|
||||
return;
|
||||
}
|
||||
HashMap<Integer, Integer> newMapping = new HashMap<>();
|
||||
|
||||
for (int i = 0; i < view.getTopInventory().getContents().length; i++) {
|
||||
@ -216,7 +212,6 @@ public class BauGuiEditor implements Listener {
|
||||
}
|
||||
|
||||
mapping.setMapping(newMapping);
|
||||
mapping.save();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@ -227,7 +222,7 @@ public class BauGuiEditor implements Listener {
|
||||
|
||||
Player p = (Player) event.getPlayer();
|
||||
|
||||
saveMapping(event.getView(), BauGuiMapping.getGuiMapping(p));
|
||||
saveMapping(event.getView(), new BauGuiMapping(p));
|
||||
open_Edits.remove(p);
|
||||
}
|
||||
}
|
||||
|
@ -19,82 +19,50 @@
|
||||
|
||||
package de.steamwar.bausystem.features.gui.editor;
|
||||
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.configplayer.Config;
|
||||
import de.steamwar.bausystem.features.gui.BauGUI;
|
||||
import de.steamwar.bausystem.linkage.specific.BauGuiItem;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
import yapion.hierarchy.types.YAPIONObject;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class BauGuiMapping {
|
||||
|
||||
private static final HashMap<UUID, BauGuiMapping> fromUUID = new HashMap<>();
|
||||
private static final List<BauGuiMapping> mappings = new ArrayList<>();
|
||||
|
||||
private static BukkitTask task;
|
||||
|
||||
public static void startWatchdog() {
|
||||
if (task == null) {
|
||||
Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), bukkitTask -> {
|
||||
mappings.forEach(BauGuiMapping::tick);
|
||||
if (BauGuiEditor.getOpen_Edits().isEmpty()) {
|
||||
bukkitTask.cancel();
|
||||
task = null;
|
||||
}
|
||||
}, 1, 1);
|
||||
}
|
||||
}
|
||||
|
||||
@Getter
|
||||
private final YAPIONObject object;
|
||||
@Getter
|
||||
private final Player owner;
|
||||
@Getter
|
||||
@Setter
|
||||
private boolean saved;
|
||||
|
||||
protected BauGuiMapping(YAPIONObject object, Player p) {
|
||||
this.object = object;
|
||||
public BauGuiMapping(Player p) {
|
||||
this.owner = p;
|
||||
fromUUID.put(p.getUniqueId(), this);
|
||||
mappings.add(this);
|
||||
}
|
||||
|
||||
public static BauGuiMapping getGuiMapping(Player p) {
|
||||
BauGuiMapping mapping = fromUUID.get(p.getUniqueId());
|
||||
|
||||
if (mapping == null) {
|
||||
YAPIONObject yapionObject = Config.getInstance().get(p);
|
||||
mapping = new BauGuiMapping(yapionObject.getObject("baugui"), p);
|
||||
}
|
||||
|
||||
return mapping;
|
||||
private Map<String, Integer> getInternalMapping() {
|
||||
return Config.get(owner).getBaugui();
|
||||
}
|
||||
|
||||
public boolean isShown(int id) {
|
||||
return object.getPlainValueOrDefault(Integer.toString(id), -1) >= 0;
|
||||
return getInternalMapping().getOrDefault(Integer.toString(id), -1) >= 0;
|
||||
}
|
||||
|
||||
public int getSlot(int id) {
|
||||
return object.getPlainValue(Integer.toString(id));
|
||||
return getInternalMapping().getOrDefault(Integer.toString(id), 0);
|
||||
}
|
||||
|
||||
public Map<Integer, Integer> getMapping() {
|
||||
return internalReadMap();
|
||||
return getInternalMapping().entrySet().stream().collect(Collectors.toMap(entry -> Integer.valueOf(entry.getKey()), Map.Entry::getValue));
|
||||
}
|
||||
|
||||
public void setMapping(Map<Integer, Integer> mapping) {
|
||||
internalWriteMap(mapping);
|
||||
Map<String, Integer> map = getInternalMapping();
|
||||
map.clear();
|
||||
|
||||
for(Map.Entry<Integer, Integer> entry : mapping.entrySet())
|
||||
map.put(String.valueOf(entry.getKey()), entry.getValue());
|
||||
|
||||
Config.get(owner).save();
|
||||
}
|
||||
|
||||
public int getSize() {
|
||||
return object.getPlainValueOrDefault("size", 45);
|
||||
return getInternalMapping().getOrDefault("size", 45);
|
||||
}
|
||||
|
||||
public void setSize(int size) {
|
||||
@ -102,37 +70,6 @@ public class BauGuiMapping {
|
||||
return;
|
||||
}
|
||||
|
||||
object.add("size", size);
|
||||
}
|
||||
|
||||
private void tick() {
|
||||
this.saved = false;
|
||||
}
|
||||
|
||||
public void save() {
|
||||
if (saved) return;
|
||||
YAPIONObject config = Config.getInstance().get(owner);
|
||||
config.add("baugui", object);
|
||||
Config.getInstance().save(owner);
|
||||
saved = true;
|
||||
}
|
||||
|
||||
private Map<Integer, Integer> internalReadMap() {
|
||||
Map<Integer, Integer> map = new HashMap<>();
|
||||
for (Map.Entry<Integer, BauGuiItem> e : BauGUI.getITEMS().entrySet()) {
|
||||
Integer value = object.getPlainValueOrDefault(e.getKey().toString(), -1);
|
||||
if (value == -1) continue;
|
||||
map.put(e.getKey(), value);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
private void internalWriteMap(Map<Integer, Integer> map) {
|
||||
for (Map.Entry<Integer, BauGuiItem> e : BauGUI.getITEMS().entrySet()) {
|
||||
object.remove(e.getKey().toString());
|
||||
Integer value = map.getOrDefault(e.getKey(), -1);
|
||||
if (value == -1) continue;
|
||||
object.add(e.getKey().toString(), value);
|
||||
}
|
||||
getInternalMapping().put("size", size);
|
||||
}
|
||||
}
|
||||
|
@ -19,75 +19,89 @@
|
||||
|
||||
package de.steamwar.bausystem.features.hotbar;
|
||||
|
||||
import de.steamwar.bausystem.configplayer.Config;
|
||||
import de.steamwar.bausystem.config.ConfigField;
|
||||
import de.steamwar.bausystem.config.YamlConfig;
|
||||
import de.steamwar.core.Core;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import de.steamwar.sql.UserConfig;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import yapion.hierarchy.types.YAPIONArray;
|
||||
import yapion.hierarchy.types.YAPIONObject;
|
||||
import yapion.hierarchy.types.YAPIONValue;
|
||||
import yapion.parser.YAPIONParser;
|
||||
import yapion.serializing.YAPIONDeserializer;
|
||||
import yapion.serializing.YAPIONSerializer;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@UtilityClass
|
||||
public class DefaultHotbar {
|
||||
public class DefaultHotbar extends YamlConfig {
|
||||
|
||||
private final YAPIONArray DEFAULT_HOTBAR = YAPIONParser.parse("{[{@type(org.bukkit.inventory.ItemStack)v(2230)type(WOODEN_AXE)meta{@type(org.bukkit.inventory.meta.ItemMeta)meta-type(UNSPECIFIC)display-name(WorldEdit Wand)lore{@type(java.util.ArrayList)values[Left click: select pos #1,Right click: select pos #2]}}},{@type(org.bukkit.inventory.ItemStack)v(2230)type(COMPASS)meta{@type(org.bukkit.inventory.meta.ItemMeta)meta-type(UNSPECIFIC)display-name(Navigation Wand)lore{@type(java.util.ArrayList)values[Left click: jump to location,Right click: pass through walls]}}},null,null,null,null,null,null,{@type(org.bukkit.inventory.ItemStack)v(2230)type(NETHER_STAR)meta{@type(org.bukkit.inventory.meta.ItemMeta)meta-type(UNSPECIFIC)display-name(§eBau GUI)}},null,null,{@type(org.bukkit.inventory.ItemStack)v(3117)type(ELYTRA)},null]}").getArray("");
|
||||
public static final String configName = "bauhotbar-" + Core.getVersion();
|
||||
|
||||
public void updateHotbar(Player p) {
|
||||
ItemStack[] hotbar = new ItemStack[13];
|
||||
System.arraycopy(p.getInventory().getContents(), 0, hotbar, 0, 9);
|
||||
System.arraycopy(p.getInventory().getArmorContents(), 0, hotbar, 9, 4);
|
||||
YAPIONArray yapionArray = new YAPIONArray();
|
||||
for (ItemStack itemStack : hotbar) {
|
||||
if (itemStack != null) {
|
||||
yapionArray.add(YAPIONSerializer.serialize(itemStack));
|
||||
} else {
|
||||
yapionArray.add(new YAPIONValue<>(null));
|
||||
}
|
||||
public static DefaultHotbar get(Player p) {
|
||||
return new DefaultHotbar(p, fromUserConfig(p.getUniqueId(), configName));
|
||||
}
|
||||
|
||||
private final Player player;
|
||||
|
||||
@Getter
|
||||
@ConfigField
|
||||
private final List<ItemStack> hotbar = new ArrayList<>(13);
|
||||
|
||||
public DefaultHotbar(Player player, ConfigurationSection config) {
|
||||
super(config);
|
||||
this.player = player;
|
||||
|
||||
if(hotbar.isEmpty()) {
|
||||
hotbar.add(newNamedStack(Material.WOODEN_AXE, "WorldEdit Wand", "Left click: select pos #1", "Right click: select pos #2"));
|
||||
hotbar.add(newNamedStack(Material.COMPASS, "Navigation Wand", "Left click: jump to location", "Right click: pass through walls"));
|
||||
hotbar.add(null);
|
||||
hotbar.add(null);
|
||||
hotbar.add(null);
|
||||
hotbar.add(null);
|
||||
hotbar.add(null);
|
||||
hotbar.add(null);
|
||||
hotbar.add(newNamedStack(Material.NETHER_STAR, "§eBau GUI"));
|
||||
hotbar.add(null);
|
||||
hotbar.add(null);
|
||||
hotbar.add(new ItemStack(Material.ELYTRA));
|
||||
hotbar.add(null);
|
||||
}
|
||||
Config.getInstance().get(p).add("hotbar-" + Core.getVersion(), yapionArray);
|
||||
Config.getInstance().save(p);
|
||||
}
|
||||
|
||||
public void setHotbar(Player p) {
|
||||
ItemStack[] hotbar = getItems(p);
|
||||
ItemStack[] inv = p.getInventory().getContents();
|
||||
ItemStack[] armor = p.getInventory().getArmorContents();
|
||||
System.arraycopy(hotbar, 0, inv, 0, 9);
|
||||
System.arraycopy(hotbar, 9, armor, 0, 4);
|
||||
p.getInventory().setContents(inv);
|
||||
p.getInventory().setArmorContents(armor);
|
||||
public void update() {
|
||||
hotbar.clear();
|
||||
|
||||
for(int i = 0; i < 9; i++)
|
||||
hotbar.add(player.getInventory().getContents()[i]);
|
||||
|
||||
for(int i = 0; i < 4; i++)
|
||||
hotbar.add(player.getInventory().getArmorContents()[i]);
|
||||
|
||||
UserConfig.updatePlayerConfig(player.getUniqueId(), configName, toYaml().saveToString());
|
||||
}
|
||||
|
||||
public ItemStack[] getItems(Player p) {
|
||||
Config.getInstance().get(p).remap("hotbar", "hotbar-19");
|
||||
YAPIONArray yapionArray = Config.getInstance().get(p).getYAPIONArrayOrSetDefault("hotbar-" + Core.getVersion(), defaultHotbar());
|
||||
ItemStack[] hotbar = new ItemStack[13];
|
||||
Set<Integer> invalid = new HashSet<>();
|
||||
yapionArray.forEach((integer, yapionAnyType) -> {
|
||||
if (yapionAnyType instanceof YAPIONValue) {
|
||||
hotbar[integer] = null;
|
||||
} else {
|
||||
try {
|
||||
hotbar[integer] = YAPIONDeserializer.deserialize((YAPIONObject) yapionAnyType);
|
||||
} catch (Exception e) {
|
||||
invalid.add(integer);
|
||||
hotbar[integer] = null;
|
||||
}
|
||||
}
|
||||
});
|
||||
invalid.forEach(i -> yapionArray.set(i, new YAPIONValue<>(null)));
|
||||
if (!invalid.isEmpty()) Config.getInstance().save(p);
|
||||
return hotbar;
|
||||
public void load() {
|
||||
ItemStack[] inv = player.getInventory().getContents();
|
||||
ItemStack[] armor = player.getInventory().getArmorContents();
|
||||
System.arraycopy(hotbar.toArray(new ItemStack[0]), 0, inv, 0, 9);
|
||||
System.arraycopy(hotbar.toArray(new ItemStack[0]), 9, armor, 0, 4);
|
||||
player.getInventory().setContents(inv);
|
||||
player.getInventory().setArmorContents(armor);
|
||||
}
|
||||
|
||||
public YAPIONArray defaultHotbar() {
|
||||
return DEFAULT_HOTBAR;
|
||||
private static ItemStack newNamedStack(Material material, String displayName, String... lore) {
|
||||
ItemStack stack = new ItemStack(material);
|
||||
ItemMeta meta = stack.getItemMeta();
|
||||
|
||||
if(displayName != null)
|
||||
meta.setDisplayName(displayName);
|
||||
|
||||
if(lore.length > 0)
|
||||
meta.setLore(Arrays.stream(lore).collect(Collectors.toList()));
|
||||
|
||||
stack.setItemMeta(meta);
|
||||
return stack;
|
||||
}
|
||||
}
|
||||
|
@ -26,6 +26,8 @@ import de.steamwar.linkage.Linked;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Linked
|
||||
public class HotbarCommand extends SWCommand {
|
||||
|
||||
@ -36,23 +38,23 @@ public class HotbarCommand extends SWCommand {
|
||||
|
||||
@Register(value = "load", description = "HOTBAR_HELP_LOAD")
|
||||
public void loadHotbar(Player p) {
|
||||
DefaultHotbar.setHotbar(p);
|
||||
DefaultHotbar.get(p).load();
|
||||
BauSystem.MESSAGE.send("HOTBAR_LOADED", p);
|
||||
}
|
||||
|
||||
@Register(value = "save", description = "HOTBAR_HELP_SAVE")
|
||||
public void saveHotbar(Player p) {
|
||||
DefaultHotbar.updateHotbar(p);
|
||||
DefaultHotbar.get(p).update();
|
||||
BauSystem.MESSAGE.send("HOTBAR_SAVED", p);
|
||||
}
|
||||
|
||||
@Register(value = "show", description = "HOTBAR_HELP_SHOW")
|
||||
public void showHotbar(Player p) {
|
||||
SWInventory inv = new SWInventory(p, 18, BauSystem.MESSAGE.parse("HOTBAR_INVENTORY", p));
|
||||
ItemStack[] hotbar = DefaultHotbar.getItems(p);
|
||||
for (int i = 0; i < hotbar.length; i++) {
|
||||
if (hotbar[i] == null) continue;
|
||||
inv.setItem(i, hotbar[i], clickType -> {
|
||||
List<ItemStack> hotbar = DefaultHotbar.get(p).getHotbar();
|
||||
for (int i = 0; i < hotbar.size(); i++) {
|
||||
if (hotbar.get(i) == null) continue;
|
||||
inv.setItem(i, hotbar.get(i), clickType -> {
|
||||
});
|
||||
}
|
||||
inv.open();
|
||||
|
@ -31,7 +31,7 @@ public class HotbarListener implements Listener {
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
if (allNull(event.getPlayer().getInventory().getContents()) && allNull(event.getPlayer().getInventory().getArmorContents())) {
|
||||
DefaultHotbar.setHotbar(event.getPlayer());
|
||||
DefaultHotbar.get(event.getPlayer()).load();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -30,7 +30,7 @@ public class InventoryFillBauGuiItem extends BauGuiItem {
|
||||
|
||||
@Override
|
||||
public ItemStack getItem(Player player) {
|
||||
String loreKey = Config.getInstance().get(player).getPlainValueOrDefault("inventoryfill", false) ? "OTHER_ITEMS_INVENTORY_FILL_LORE_ACTIVE" : "OTHER_ITEMS_INVENTORY_FILL_LORE_INACTIVE";
|
||||
String loreKey = Config.get(player).isInventoryFill() ? "OTHER_ITEMS_INVENTORY_FILL_LORE_ACTIVE" : "OTHER_ITEMS_INVENTORY_FILL_LORE_INACTIVE";
|
||||
return new SWItem(Material.HOPPER, BauSystem.MESSAGE.parse("OTHER_ITEMS_INVENTORY_FILL_NAME", player), Collections.singletonList(BauSystem.MESSAGE.parse(loreKey, player)), false, clickType -> {}).getItemStack();
|
||||
}
|
||||
|
||||
|
@ -38,7 +38,7 @@ public class InventoryFiller implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerDropItem(PlayerDropItemEvent event) {
|
||||
if (!Config.getInstance().get(event.getPlayer()).getPlainValueOrDefault("inventoryfill", false)) return;
|
||||
if (!Config.get(event.getPlayer()).isInventoryFill()) return;
|
||||
if (!event.getPlayer().isSneaking()) return;
|
||||
Block block = event.getPlayer().getTargetBlockExact(5);
|
||||
if (block == null) return;
|
||||
@ -59,7 +59,7 @@ public class InventoryFiller implements Listener {
|
||||
*/
|
||||
@EventHandler
|
||||
public void onPlayerItemHeld(PlayerItemHeldEvent event) {
|
||||
if (!Config.getInstance().get(event.getPlayer()).getPlainValueOrDefault("inventoryfill", false)) return;
|
||||
if (!Config.get(event.getPlayer()).isInventoryFill()) return;
|
||||
if (!event.getPlayer().isSneaking()) return;
|
||||
ItemStack itemStack = event.getPlayer().getInventory().getItemInMainHand();
|
||||
if (itemStack.getType() == Material.AIR) return;
|
||||
|
@ -16,8 +16,8 @@ public class InventoryFillerCommand extends SWCommand {
|
||||
|
||||
@Register(description = {"INVENTORY_FILL_HELP", "INVENTORY_FILL_INFO"})
|
||||
public void toggle(Player player) {
|
||||
boolean inventoryFill = Config.getInstance().get(player).getPlainValueOrDefault("inventoryfill", false);
|
||||
Config.getInstance().get(player).put("inventoryfill", !inventoryFill);
|
||||
boolean inventoryFill = Config.get(player).isInventoryFill();
|
||||
Config.get(player).setInventoryFill(!inventoryFill);
|
||||
if (!inventoryFill) {
|
||||
SWUtils.sendToActionbar(player, BauSystem.MESSAGE.parse("INVENTORY_FILL_ENABLE", player));
|
||||
BauSystem.MESSAGE.send("INVENTORY_FILL_INFO", player);
|
||||
|
@ -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
|
||||
|
@ -21,24 +21,18 @@ package de.steamwar.bausystem.features.simulator;
|
||||
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.SWUtils;
|
||||
import de.steamwar.bausystem.features.simulator.tnt.TNTElement;
|
||||
import de.steamwar.bausystem.utils.ItemUtils;
|
||||
import de.steamwar.inventory.SWItem;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import de.steamwar.linkage.api.Disable;
|
||||
import de.steamwar.linkage.api.Enable;
|
||||
import de.steamwar.sql.SteamwarUser;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import yapion.exceptions.YAPIONException;
|
||||
import yapion.hierarchy.types.YAPIONArray;
|
||||
import yapion.hierarchy.types.YAPIONObject;
|
||||
import yapion.parser.YAPIONParser;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@ -46,17 +40,15 @@ import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Linked
|
||||
public class SimulatorStorage implements Enable, Disable {
|
||||
|
||||
public static final World WORLD = Bukkit.getWorlds().get(0);
|
||||
private static final File simulatorsDir = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "simulators");
|
||||
|
||||
private static NamespacedKey simulatorSelection = SWUtils.getNamespaceKey("simulator_selection");
|
||||
private static final NamespacedKey simulatorSelection = SWUtils.getNamespaceKey("simulator_selection");
|
||||
|
||||
private static Map<String, TNTSimulator> tntSimulators = new HashMap<>();
|
||||
private static final Map<String, TNTSimulator> tntSimulators = new HashMap<>();
|
||||
|
||||
public static void createNewSimulator(String name) {
|
||||
tntSimulators.put(name, new TNTSimulator());
|
||||
@ -107,11 +99,11 @@ public class SimulatorStorage implements Enable, Disable {
|
||||
if (tntSimulator != null) {
|
||||
tntSimulator.close();
|
||||
}
|
||||
new File(simulatorsDir, name + ".simulator").delete();
|
||||
new File(simulatorsDir, name + ".yml").delete();
|
||||
}
|
||||
|
||||
public static void copySimulator(TNTSimulator tntSimulator, String name) {
|
||||
tntSimulators.put(name, new TNTSimulator(tntSimulator.toYAPION()));
|
||||
tntSimulators.put(name, new TNTSimulator(tntSimulator.toYaml()));
|
||||
}
|
||||
|
||||
public static void removeSimulator(ItemStack itemStack) {
|
||||
@ -139,48 +131,11 @@ public class SimulatorStorage implements Enable, Disable {
|
||||
if (files == null) return;
|
||||
|
||||
for (File file : files) {
|
||||
YAPIONObject yapionObject;
|
||||
try {
|
||||
yapionObject = YAPIONParser.parse(file);
|
||||
} catch (YAPIONException | IOException e) {
|
||||
String name = file.getName();
|
||||
if(!name.endsWith(".yml"))
|
||||
continue;
|
||||
}
|
||||
if (file.getName().endsWith(".yapion")) {
|
||||
String name = file.getName().substring(0, file.getName().length() - 7);
|
||||
try {
|
||||
SteamwarUser steamwarUser = SteamwarUser.get(Integer.parseInt(name));
|
||||
convert(file, steamwarUser);
|
||||
} catch (Exception e) {
|
||||
file.delete();
|
||||
}
|
||||
} else {
|
||||
String name = file.getName().substring(0, file.getName().length() - ".simulator".length());
|
||||
tntSimulators.put(name, new TNTSimulator(yapionObject));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void convert(File file, SteamwarUser steamwarUser) {
|
||||
YAPIONObject yapionObject;
|
||||
try {
|
||||
yapionObject = YAPIONParser.parse(file);
|
||||
} catch (YAPIONException | IOException e) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
file.delete();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
for (String s : yapionObject.getKeys()) {
|
||||
String newName = steamwarUser.getUserName() + (s.isEmpty() ? "" : "_" + s);
|
||||
YAPIONArray content = yapionObject.getArray(s);
|
||||
if (content.isEmpty()) continue;
|
||||
TNTSimulator tntSimulator = new TNTSimulator();
|
||||
for (YAPIONObject element : content.streamObject().collect(Collectors.toList())) {
|
||||
tntSimulator.getTntElementList().add(new TNTElement(element, null, tntSimulator.getEntityServer()));
|
||||
}
|
||||
tntSimulators.put(newName, tntSimulator);
|
||||
tntSimulators.put(name.substring(0, name.length() - 4), new TNTSimulator(YamlConfiguration.loadConfiguration(file)));
|
||||
}
|
||||
}
|
||||
|
||||
@ -188,9 +143,9 @@ public class SimulatorStorage implements Enable, Disable {
|
||||
public void disable() {
|
||||
for (Map.Entry<String, TNTSimulator> entry : tntSimulators.entrySet()) {
|
||||
try {
|
||||
entry.getValue().toYAPION().toFile(new File(simulatorsDir, entry.getKey() + ".simulator"));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
entry.getValue().toYaml().save(new File(simulatorsDir, entry.getKey() + ".yml"));
|
||||
} catch (IOException e) {
|
||||
throw new SecurityException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -20,6 +20,8 @@
|
||||
package de.steamwar.bausystem.features.simulator;
|
||||
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.config.ConfigField;
|
||||
import de.steamwar.bausystem.config.YamlConfig;
|
||||
import de.steamwar.bausystem.configplayer.Config;
|
||||
import de.steamwar.bausystem.features.simulator.gui.TNTElementGUI;
|
||||
import de.steamwar.bausystem.features.simulator.gui.TNTSimulatorGui;
|
||||
@ -36,10 +38,8 @@ import de.steamwar.entity.REntityServer;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.Player;
|
||||
import yapion.hierarchy.types.YAPIONArray;
|
||||
import yapion.hierarchy.types.YAPIONObject;
|
||||
import yapion.hierarchy.types.YAPIONType;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
@ -47,40 +47,29 @@ import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Getter
|
||||
public class TNTSimulator {
|
||||
public class TNTSimulator extends YamlConfig {
|
||||
|
||||
private Set<Player> players = new HashSet<>();
|
||||
private REntityServer entityServer = new REntityServer();
|
||||
static {
|
||||
register(TNTGroup.class);
|
||||
register(TNTElement.class);
|
||||
}
|
||||
|
||||
private final Set<Player> players = new HashSet<>();
|
||||
private final REntityServer entityServer = new REntityServer();
|
||||
|
||||
@ConfigField
|
||||
private Material material = Material.TNT;
|
||||
|
||||
private List<SimulatorElement> tntElementList = new ArrayList<>();
|
||||
@ConfigField
|
||||
private final List<SimulatorElement> tntElementList = new ArrayList<>();
|
||||
|
||||
public TNTSimulator() {
|
||||
public TNTSimulator() {}
|
||||
|
||||
}
|
||||
public TNTSimulator(ConfigurationSection section) {
|
||||
super(section);
|
||||
|
||||
public TNTSimulator(YAPIONObject yapionObject) {
|
||||
material = Material.valueOf(yapionObject.getStringOrDefault("material", Material.TNT.name()));
|
||||
YAPIONArray yapionArray = yapionObject.getArrayOrDefault("tntElements", new YAPIONArray());
|
||||
for (YAPIONObject element : yapionArray.streamObject().collect(Collectors.toList())) {
|
||||
if (element.containsKey("elements", YAPIONType.ARRAY)) {
|
||||
tntElementList.add(new TNTGroup(element, entityServer));
|
||||
} else {
|
||||
tntElementList.add(new TNTElement(element, null, entityServer));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public YAPIONObject toYAPION() {
|
||||
YAPIONObject yapionObject = new YAPIONObject();
|
||||
yapionObject.add("material", material.name());
|
||||
YAPIONArray yapionArray = new YAPIONArray();
|
||||
for (SimulatorElement element : tntElementList) {
|
||||
yapionArray.add(element.toYAPION());
|
||||
}
|
||||
yapionObject.add("tntElements", yapionArray);
|
||||
return yapionObject;
|
||||
for(SimulatorElement element : tntElementList)
|
||||
element.init(entityServer, null);
|
||||
}
|
||||
|
||||
public void close() {
|
||||
@ -218,7 +207,7 @@ public class TNTSimulator {
|
||||
|
||||
AtomicBoolean needsAutoTrace = new AtomicBoolean();
|
||||
players.forEach(player -> {
|
||||
boolean simulatorAutoTrace = Config.getInstance().get(player).getPlainValueOrDefault("simulatorAutoTrace", false);
|
||||
boolean simulatorAutoTrace = Config.get(player).isSimulatorAutoTrace();
|
||||
if (simulatorAutoTrace) {
|
||||
needsAutoTrace.set(true);
|
||||
player.performCommand("trace show");
|
||||
|
@ -119,9 +119,9 @@ public class TNTSimulatorGui {
|
||||
}));
|
||||
}
|
||||
|
||||
boolean simulatorAutoTrace = Config.getInstance().get(player).getPlainValueOrDefault("simulatorAutoTrace", false);
|
||||
boolean simulatorAutoTrace = Config.get(player).isSimulatorAutoTrace();
|
||||
inv.setItem(47, new SWItem(simulatorAutoTrace ? Material.CHAIN_COMMAND_BLOCK : Material.COMMAND_BLOCK, BauSystem.MESSAGE.parse("SIMULATOR_GUI_AUTO_TRACE", player, simulatorAutoTrace), clickType -> {
|
||||
Config.getInstance().get(player).put("simulatorAutoTrace", !simulatorAutoTrace);
|
||||
Config.get(player).setSimulatorAutoTrace(!simulatorAutoTrace);
|
||||
open(player, currentTntSimulator, currentTntGroup, simulatorElements, back);
|
||||
}));
|
||||
}
|
||||
|
@ -22,21 +22,23 @@ package de.steamwar.bausystem.features.simulator.tnt;
|
||||
import de.steamwar.bausystem.region.Region;
|
||||
import de.steamwar.bausystem.shared.Pair;
|
||||
import de.steamwar.entity.REntity;
|
||||
import de.steamwar.entity.REntityServer;
|
||||
import de.steamwar.inventory.SWItem;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.serialization.ConfigurationSerializable;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.Vector;
|
||||
import yapion.hierarchy.types.YAPIONObject;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public interface SimulatorElement {
|
||||
public interface SimulatorElement extends ConfigurationSerializable {
|
||||
|
||||
Map<SimulatorElement, Set<Runnable>> observer = new HashMap<>();
|
||||
Map<Runnable, Runnable> closeObserver = new HashMap<>();
|
||||
|
||||
YAPIONObject toYAPION();
|
||||
void init(REntityServer entityServer, TNTGroup tntGroup);
|
||||
|
||||
List<REntity> getEntities();
|
||||
void getEntity(List<SimulatorElement> elements, REntity entity);
|
||||
|
||||
|
@ -20,8 +20,9 @@
|
||||
package de.steamwar.bausystem.features.simulator.tnt;
|
||||
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.config.ConfigField;
|
||||
import de.steamwar.bausystem.config.YamlConfig;
|
||||
import de.steamwar.bausystem.features.simulator.OrderUtils;
|
||||
import de.steamwar.bausystem.features.simulator.SimulatorStorage;
|
||||
import de.steamwar.bausystem.region.Region;
|
||||
import de.steamwar.bausystem.region.flags.Flag;
|
||||
import de.steamwar.bausystem.region.flags.flagvalues.FreezeMode;
|
||||
@ -41,81 +42,62 @@ import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.TNTPrimed;
|
||||
import org.bukkit.util.Vector;
|
||||
import yapion.hierarchy.types.YAPIONObject;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@Getter
|
||||
public class TNTElement implements SimulatorElement {
|
||||
public class TNTElement extends YamlConfig implements SimulatorElement {
|
||||
|
||||
private static final World WORLD = Bukkit.getWorlds().get(0);
|
||||
|
||||
private final REntityServer entityServer;
|
||||
private REntityServer entityServer;
|
||||
private RFallingBlockEntity entity;
|
||||
TNTGroup tntGroup = null;
|
||||
@Setter
|
||||
private TNTGroup tntGroup;
|
||||
|
||||
private final Vector position;
|
||||
@ConfigField
|
||||
private Vector position;
|
||||
@ConfigField
|
||||
private int fuseTicks = 80;
|
||||
@ConfigField
|
||||
private int count = 1;
|
||||
@ConfigField
|
||||
private int tickOffset = 0;
|
||||
|
||||
@Setter
|
||||
@ConfigField
|
||||
private boolean xVelocity = false;
|
||||
|
||||
@Setter
|
||||
@ConfigField
|
||||
private boolean yVelocity = false;
|
||||
|
||||
@Setter
|
||||
@ConfigField
|
||||
private boolean zVelocity = false;
|
||||
@ConfigField
|
||||
private Material order = Material.REPEATER;
|
||||
@ConfigField
|
||||
private Material material = Material.TNT;
|
||||
@ConfigField
|
||||
private boolean disabled = false;
|
||||
|
||||
public TNTElement(Vector position, TNTGroup tntGroup, REntityServer entityServer) {
|
||||
this.entityServer = entityServer;
|
||||
this.tntGroup = tntGroup;
|
||||
this.position = position;
|
||||
initEntity();
|
||||
init(entityServer, tntGroup);
|
||||
}
|
||||
|
||||
public TNTElement(YAPIONObject yapionObject, TNTGroup tntGroup, REntityServer entityServer) {
|
||||
this.entityServer = entityServer;
|
||||
this.tntGroup = tntGroup;
|
||||
this.position = new Vector(yapionObject.getDoubleOrDefault("x", yapionObject.getDoubleOrDefault("positionX", 0)), yapionObject.getDoubleOrDefault("y", yapionObject.getDoubleOrDefault("positionY", 0)), yapionObject.getDoubleOrDefault("z", yapionObject.getDoubleOrDefault("positionZ", 0)));
|
||||
this.disabled = yapionObject.getBooleanOrDefault("disabled", false);
|
||||
this.fuseTicks = yapionObject.getIntOrDefault("fuseTicks", 80);
|
||||
this.count = yapionObject.getIntOrDefault("count", 1);
|
||||
this.tickOffset = yapionObject.getIntOrDefault("tickOffset", 0);
|
||||
this.xVelocity = yapionObject.getBooleanOrDefault("xVelocity", false);
|
||||
this.yVelocity = yapionObject.getBooleanOrDefault("yVelocity", false);
|
||||
this.zVelocity = yapionObject.getBooleanOrDefault("zVelocity", false);
|
||||
this.order = Material.valueOf(yapionObject.getStringOrDefault("order", yapionObject.getBooleanOrDefault("comparator", false) ? Material.COMPARATOR.name() : Material.REPEATER.name()));
|
||||
this.material = Material.valueOf(yapionObject.getStringOrDefault("material", Material.TNT.name()));
|
||||
initEntity();
|
||||
}
|
||||
|
||||
private void initEntity() {
|
||||
this.entity = new RFallingBlockEntity(entityServer, getPosition().toLocation(WORLD), Material.TNT);
|
||||
this.entity.setNoGravity(true);
|
||||
_updatePosition();
|
||||
public TNTElement(Map<String, Object> map) {
|
||||
super(map);
|
||||
}
|
||||
|
||||
@Override
|
||||
public YAPIONObject toYAPION() {
|
||||
YAPIONObject yapionObject = new YAPIONObject();
|
||||
yapionObject.add("x", position.getX());
|
||||
yapionObject.add("y", position.getY());
|
||||
yapionObject.add("z", position.getZ());
|
||||
yapionObject.add("fuseTicks", fuseTicks);
|
||||
yapionObject.add("count", count);
|
||||
yapionObject.add("tickOffset", tickOffset);
|
||||
yapionObject.add("xVelocity", xVelocity);
|
||||
yapionObject.add("yVelocity", yVelocity);
|
||||
yapionObject.add("zVelocity", zVelocity);
|
||||
yapionObject.add("order", order.name());
|
||||
yapionObject.add("material", material.name());
|
||||
yapionObject.add("disabled", disabled);
|
||||
return yapionObject;
|
||||
public void init(REntityServer entityServer, TNTGroup tntGroup) {
|
||||
this.entityServer = entityServer;
|
||||
this.tntGroup = tntGroup;
|
||||
this.entity = new RFallingBlockEntity(entityServer, getPosition().toLocation(WORLD), Material.TNT);
|
||||
this.entity.setNoGravity(true);
|
||||
_updatePosition();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -191,7 +173,7 @@ public class TNTElement implements SimulatorElement {
|
||||
@Override
|
||||
public boolean locations(Map<Integer, Map<Integer, Set<Pair<Runnable, Integer>>>> result, Region region, Location radius) {
|
||||
if (disabled) return false;
|
||||
Location location = getPosition().toLocation(SimulatorStorage.WORLD);
|
||||
Location location = getPosition().toLocation(WORLD);
|
||||
if (region.isGlobal() && location.distanceSquared(radius) > 10000) {
|
||||
return false;
|
||||
}
|
||||
@ -199,14 +181,14 @@ public class TNTElement implements SimulatorElement {
|
||||
return false;
|
||||
}
|
||||
Region thisRegion = Region.getRegion(location);
|
||||
if (thisRegion.getFlagStorage().get(Flag.FREEZE) == FreezeMode.ACTIVE) {
|
||||
if (thisRegion.get(Flag.FREEZE) == FreezeMode.ACTIVE) {
|
||||
return true;
|
||||
}
|
||||
|
||||
result.computeIfAbsent(getTickOffset(), ignore -> new HashMap<>())
|
||||
.computeIfAbsent(OrderUtils.order(order), ignore -> new HashSet<>())
|
||||
.add(new Pair<>(() -> {
|
||||
SimulatorStorage.WORLD.spawn(location, TNTPrimed.class, tntPrimed -> {
|
||||
WORLD.spawn(location, TNTPrimed.class, tntPrimed -> {
|
||||
tntPrimed.setFuseTicks(fuseTicks);
|
||||
if (!xVelocity) tntPrimed.setVelocity(tntPrimed.getVelocity().setX(0));
|
||||
if (!yVelocity) tntPrimed.setVelocity(tntPrimed.getVelocity().setY(0));
|
||||
|
@ -20,6 +20,8 @@
|
||||
package de.steamwar.bausystem.features.simulator.tnt;
|
||||
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.config.ConfigField;
|
||||
import de.steamwar.bausystem.config.YamlConfig;
|
||||
import de.steamwar.bausystem.region.Region;
|
||||
import de.steamwar.bausystem.shared.Pair;
|
||||
import de.steamwar.entity.REntity;
|
||||
@ -30,8 +32,6 @@ import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.Vector;
|
||||
import yapion.hierarchy.types.YAPIONArray;
|
||||
import yapion.hierarchy.types.YAPIONObject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -40,50 +40,36 @@ import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Getter
|
||||
public class TNTGroup implements SimulatorElement {
|
||||
public class TNTGroup extends YamlConfig implements SimulatorElement {
|
||||
|
||||
private final Vector position;
|
||||
@ConfigField
|
||||
private Vector position;
|
||||
@ConfigField
|
||||
private int tickOffset = 0;
|
||||
@ConfigField
|
||||
private Material material = Material.BARREL;
|
||||
@ConfigField
|
||||
private boolean disabled = false;
|
||||
private List<TNTElement> elements = new ArrayList<>();
|
||||
@ConfigField
|
||||
private final List<TNTElement> elements = new ArrayList<>();
|
||||
|
||||
public TNTGroup(Vector position) {
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
public TNTGroup(YAPIONObject yapionObject, REntityServer entityServer) {
|
||||
this.position = new Vector(yapionObject.getDoubleOrDefault("x", 0), yapionObject.getDoubleOrDefault("y", 0), yapionObject.getDoubleOrDefault("z", 0));
|
||||
this.tickOffset = yapionObject.getIntOrDefault("tickOffset", 0);
|
||||
this.material = Material.getMaterial(yapionObject.getStringOrDefault("material", "BARREL"));
|
||||
this.disabled = yapionObject.getBooleanOrDefault("disabled", false);
|
||||
YAPIONArray elements = yapionObject.getArrayOrDefault("elements", new YAPIONArray());
|
||||
for (YAPIONObject element : elements.streamObject().collect(Collectors.toList())) {
|
||||
TNTElement tntElement = new TNTElement(element, this, entityServer);
|
||||
this.elements.add(tntElement);
|
||||
tntElement._updatePosition();
|
||||
}
|
||||
public TNTGroup(Map<String, Object> map) {
|
||||
super(map);
|
||||
}
|
||||
|
||||
@Override
|
||||
public YAPIONObject toYAPION() {
|
||||
YAPIONObject yapionObject = new YAPIONObject();
|
||||
yapionObject.add("x", position.getX());
|
||||
yapionObject.add("y", position.getY());
|
||||
yapionObject.add("z", position.getZ());
|
||||
yapionObject.add("tickOffset", tickOffset);
|
||||
yapionObject.add("material", material.name());
|
||||
yapionObject.add("disabled", disabled);
|
||||
YAPIONArray yapionArray = new YAPIONArray();
|
||||
for (TNTElement element : elements) {
|
||||
yapionArray.add(element.toYAPION());
|
||||
public void init(REntityServer entityServer, TNTGroup tntGroup) {
|
||||
for(TNTElement element : elements) {
|
||||
element.init(entityServer, this);
|
||||
}
|
||||
yapionObject.add("elements", yapionArray);
|
||||
return yapionObject;
|
||||
}
|
||||
|
||||
public void add(TNTElement tntElement) {
|
||||
tntElement.tntGroup = this;
|
||||
tntElement.setTntGroup(this);
|
||||
elements.add(tntElement);
|
||||
}
|
||||
|
||||
|
@ -59,7 +59,7 @@ public class Laufbau {
|
||||
editSession = WorldEditUtils.getEditSession(player);
|
||||
|
||||
elements = BlockBoundingBox.elements.stream().filter(blockBoundingBox -> {
|
||||
return !LaufbauUtils.isDeactivated(player, blockBoundingBox);
|
||||
return !LaufbauUtils.get(player).isDeactivated(blockBoundingBox);
|
||||
}).collect(Collectors.toList());
|
||||
if (preferingBlastResistance) {
|
||||
elements.sort((o1, o2) -> {
|
||||
|
@ -55,7 +55,7 @@ public class LaufbauSettings {
|
||||
}
|
||||
SWListInv<Map.Entry<Pair<Material, String>, List<BlockBoundingBox>>> inv = new SWListInv<>(p, BauSystem.MESSAGE.parse("LAUFBAU_SETTINGS_GUI_NAME", p), false, list, (clickType, entry) -> {
|
||||
if (entry.getValue().size() == 1) {
|
||||
LaufbauUtils.toggle(p, entry.getValue().get(0));
|
||||
LaufbauUtils.get(p).toggle(entry.getValue().get(0));
|
||||
open();
|
||||
return;
|
||||
}
|
||||
@ -80,13 +80,13 @@ public class LaufbauSettings {
|
||||
lore = itemMeta.getLore();
|
||||
}
|
||||
lore.add("");
|
||||
lore.add(BauSystem.MESSAGE.parse(LaufbauUtils.isDeactivated(p, bb) ? "LAUFBAU_SETTINGS_INACTIVE" : "LAUFBAU_SETTINGS_ACTIVE", p));
|
||||
lore.add(BauSystem.MESSAGE.parse(LaufbauUtils.get(p).isDeactivated(bb) ? "LAUFBAU_SETTINGS_INACTIVE" : "LAUFBAU_SETTINGS_ACTIVE", p));
|
||||
itemMeta.setLore(lore);
|
||||
swItem.setItemMeta(itemMeta);
|
||||
list.add(new SWListInv.SWListEntry<>(swItem, bb));
|
||||
}
|
||||
SWListInv<BlockBoundingBox> inv = new SWListInv<>(p, BauSystem.MESSAGE.parse("LAUFBAU_SETTINGS_GUI_NAME", p), false, list, (clickType, blockBoundingBox) -> {
|
||||
LaufbauUtils.toggle(p, blockBoundingBox);
|
||||
LaufbauUtils.get(p).toggle(blockBoundingBox);
|
||||
open(key);
|
||||
});
|
||||
inv.setItem(49, new SWItem(Material.ARROW, BauSystem.MESSAGE.parse("LAUFBAU_SETTINGS_GUI_BACK", p), clickType -> {
|
||||
@ -105,14 +105,14 @@ public class LaufbauSettings {
|
||||
lore = itemMeta.getLore();
|
||||
}
|
||||
lore.add("");
|
||||
lore.add(BauSystem.MESSAGE.parse(LaufbauUtils.isDeactivated(p, bb) ? "LAUFBAU_SETTINGS_INACTIVE" : "LAUFBAU_SETTINGS_ACTIVE", p));
|
||||
lore.add(BauSystem.MESSAGE.parse(LaufbauUtils.get(p).isDeactivated(bb) ? "LAUFBAU_SETTINGS_INACTIVE" : "LAUFBAU_SETTINGS_ACTIVE", p));
|
||||
lore.add("");
|
||||
lore.add(BauSystem.MESSAGE.parse("LAUFBAU_SETTINGS_TOGGLE", p));
|
||||
itemMeta.setLore(lore);
|
||||
swItem.setItemMeta(itemMeta);
|
||||
return swItem;
|
||||
} else {
|
||||
long count = blockBoundingBoxes.stream().filter(bb -> LaufbauUtils.isDeactivated(p, bb)).count();
|
||||
long count = blockBoundingBoxes.stream().filter(bb -> LaufbauUtils.get(p).isDeactivated(bb)).count();
|
||||
if (count == 0) {
|
||||
return new SWItem(material, BauSystem.MESSAGE.parse(group, p), Arrays.asList("", BauSystem.MESSAGE.parse("LAUFBAU_SETTINGS_ACTIVE", p), "", BauSystem.MESSAGE.parse("LAUFBAU_SETTINGS_ADVANCED", p), BauSystem.MESSAGE.parse("LAUFBAU_SETTINGS_TOGGLE", p)), false, clickType -> {});
|
||||
}
|
||||
@ -124,16 +124,16 @@ public class LaufbauSettings {
|
||||
}
|
||||
|
||||
public void toggle(List<BlockBoundingBox> blockBoundingBoxes) {
|
||||
long count = blockBoundingBoxes.stream().filter(bb -> LaufbauUtils.isDeactivated(p, bb)).count();
|
||||
long count = blockBoundingBoxes.stream().filter(bb -> LaufbauUtils.get(p).isDeactivated(bb)).count();
|
||||
if (count != blockBoundingBoxes.size()) {
|
||||
blockBoundingBoxes.forEach(bb -> {
|
||||
if (!LaufbauUtils.isDeactivated(p, bb)) {
|
||||
LaufbauUtils.toggle(p, bb);
|
||||
if (!LaufbauUtils.get(p).isDeactivated(bb)) {
|
||||
LaufbauUtils.get(p).toggle(bb);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
blockBoundingBoxes.forEach(bb -> {
|
||||
LaufbauUtils.toggle(p, bb);
|
||||
LaufbauUtils.get(p).toggle(bb);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -20,63 +20,28 @@
|
||||
package de.steamwar.bausystem.features.slaves.laufbau;
|
||||
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.config.ConfigField;
|
||||
import de.steamwar.bausystem.config.YamlConfig;
|
||||
import de.steamwar.inventory.SWItem;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import de.steamwar.sql.UserConfig;
|
||||
import lombok.Cleanup;
|
||||
import lombok.SneakyThrows;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
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 org.bukkit.inventory.meta.ItemMeta;
|
||||
import yapion.hierarchy.output.StreamOutput;
|
||||
import yapion.hierarchy.types.YAPIONObject;
|
||||
import yapion.parser.YAPIONParser;
|
||||
import yapion.parser.options.StreamOptions;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
import java.util.zip.GZIPOutputStream;
|
||||
|
||||
@Linked
|
||||
public class LaufbauUtils implements Listener {
|
||||
public class LaufbauUtils extends YamlConfig {
|
||||
|
||||
private static Map<Player, YAPIONObject> yapionObjectMap = new HashMap<>();
|
||||
|
||||
@EventHandler
|
||||
@SneakyThrows
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
String config = UserConfig.getConfig(event.getPlayer().getUniqueId(), "bausystem-laufbau");
|
||||
if (config == null) {
|
||||
return;
|
||||
}
|
||||
byte[] bytes = Base64.getDecoder().decode(config);
|
||||
@Cleanup GZIPInputStream gzipInputStream = new GZIPInputStream(new ByteArrayInputStream(bytes));
|
||||
YAPIONObject yapionObject = new YAPIONParser(gzipInputStream, new StreamOptions().stopOnStreamEnd(true)).parse().result();
|
||||
yapionObjectMap.put(event.getPlayer(), yapionObject);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@SneakyThrows
|
||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||
YAPIONObject yapionObject = yapionObjectMap.get(event.getPlayer());
|
||||
if (yapionObject == null) {
|
||||
return;
|
||||
}
|
||||
if (yapionObject.isEmpty()) {
|
||||
UserConfig.removePlayerConfig(event.getPlayer().getUniqueId(), "bausystem-laufbau");
|
||||
return;
|
||||
}
|
||||
@Cleanup ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
||||
@Cleanup GZIPOutputStream gzipOutputStream = new GZIPOutputStream(byteArrayOutputStream);
|
||||
yapionObject.toYAPION(new StreamOutput(gzipOutputStream)).close();
|
||||
UserConfig.updatePlayerConfig(event.getPlayer().getUniqueId(), "bausystem-laufbau", Base64.getEncoder().encodeToString(byteArrayOutputStream.toByteArray()));
|
||||
private static final Map<Player, LaufbauUtils> utilsMap = new HashMap<>();
|
||||
public static LaufbauUtils get(Player p) {
|
||||
return utilsMap.computeIfAbsent(p, player -> new LaufbauUtils(fromUserConfig(player.getUniqueId(), "bausystem-laufbau")));
|
||||
}
|
||||
|
||||
public static Cuboid pixelCuboid(double pixelX, double pixelY, double pixelZ, double pixelDX, double pixelDY, double pixelDZ) {
|
||||
@ -119,34 +84,42 @@ public class LaufbauUtils implements Listener {
|
||||
return name + "[" + String.join(",", lore) + "]";
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public static boolean isDeactivated(Player p, BlockBoundingBox bb) {
|
||||
if (bb.getSwItem() == null) {
|
||||
return false;
|
||||
}
|
||||
String identifier = identifier(bb);
|
||||
YAPIONObject yapionObject = yapionObjectMap.get(p);
|
||||
if (yapionObject == null) {
|
||||
return false;
|
||||
}
|
||||
return yapionObject.containsKey(identifier);
|
||||
@ConfigField
|
||||
private final List<String> deactivated = new ArrayList<>();
|
||||
|
||||
public LaufbauUtils(ConfigurationSection config) {
|
||||
super(config);
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public static void toggle(Player p, BlockBoundingBox bb) {
|
||||
public boolean isDeactivated(BlockBoundingBox bb) {
|
||||
if (bb.getSwItem() == null) {
|
||||
return false;
|
||||
}
|
||||
return deactivated.contains(identifier(bb));
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public void toggle(BlockBoundingBox bb) {
|
||||
if (bb.getSwItem() == null)
|
||||
return;
|
||||
}
|
||||
|
||||
String identifier = identifier(bb);
|
||||
YAPIONObject yapionObject = yapionObjectMap.get(p);
|
||||
if (yapionObject == null) {
|
||||
yapionObject = new YAPIONObject();
|
||||
yapionObjectMap.put(p, yapionObject);
|
||||
}
|
||||
if (yapionObject.containsKey(identifier)) {
|
||||
yapionObject.remove(identifier);
|
||||
} else {
|
||||
yapionObject.put(identifier, new YAPIONObject());
|
||||
if(deactivated.remove(identifier))
|
||||
return;
|
||||
deactivated.add(identifier);
|
||||
}
|
||||
|
||||
@Linked
|
||||
public static class LaufbauUtilListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||
LaufbauUtils util = utilsMap.remove(event.getPlayer());
|
||||
if(util == null)
|
||||
return;
|
||||
|
||||
UserConfig.updatePlayerConfig(event.getPlayer().getUniqueId(), "bausystem-laufbau", util.toYaml().saveToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -35,8 +35,8 @@ public class SmartPlaceCommand extends SWCommand {
|
||||
|
||||
@Register(description = {"SMART_PLACE_HELP", "SMART_PLACE_INFO"})
|
||||
public void genericToggle(Player p) {
|
||||
boolean smartPlace = Config.getInstance().get(p).getPlainValueOrDefault("smartPlace", false);
|
||||
Config.getInstance().get(p).put("smartPlace", !smartPlace);
|
||||
boolean smartPlace = Config.get(p).isSmartPlace();
|
||||
Config.get(p).setSmartPlace(!smartPlace);
|
||||
if (!smartPlace) {
|
||||
SWUtils.sendToActionbar(p, BauSystem.MESSAGE.parse("SMART_PLACE_ENABLE", p));
|
||||
BauSystem.MESSAGE.send("SMART_PLACE_INFO", p);
|
||||
|
@ -46,7 +46,7 @@ public class SmartPlaceListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onBlockPlace(BlockPlaceEvent event) {
|
||||
if (!Config.getInstance().get(event.getPlayer()).getPlainValueOrDefault("smartPlace", false)) return;
|
||||
if (!Config.get(event.getPlayer()).isSmartPlace()) return;
|
||||
if (smartPlaceBehaviours.isEmpty()) LinkageUtils.linkSmartPlace();
|
||||
SmartPlaceBehaviour.SmartPlaceResult smartPlaceResult = SmartPlaceBehaviour.SmartPlaceResult.IGNORED;
|
||||
for (SmartPlaceBehaviour smartPlaceBehaviour : smartPlaceBehaviours) {
|
||||
@ -61,7 +61,7 @@ public class SmartPlaceListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||
if (!Config.getInstance().get(event.getPlayer()).getPlainValueOrDefault("smartPlace", false)) return;
|
||||
if (!Config.get(event.getPlayer()).isSmartPlace()) return;
|
||||
if (smartPlaceBehaviours.isEmpty()) LinkageUtils.linkSmartPlace();
|
||||
if (event.getAction() != Action.RIGHT_CLICK_BLOCK) return;
|
||||
if (event.getPlayer().getGameMode() == GameMode.SPECTATOR) return;
|
||||
|
@ -34,14 +34,9 @@ import net.md_5.bungee.api.chat.ClickEvent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import yapion.hierarchy.output.StringOutput;
|
||||
import yapion.hierarchy.types.YAPIONObject;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
|
||||
@Linked
|
||||
public class SkinCommand extends SWCommand {
|
||||
@ -98,17 +93,15 @@ public class SkinCommand extends SWCommand {
|
||||
Region.copy(region.getMinPointTestblock(), region.getMaxPointTestblock(), testblockFile);
|
||||
}
|
||||
|
||||
YAPIONObject yapionObject = new YAPIONObject();
|
||||
yapionObject.add("name", name);
|
||||
Prototype.Skin skin = new Prototype.Skin(Collections.emptyMap());
|
||||
if (!creator.equals("public")) {
|
||||
yapionObject.add("creator", creator);
|
||||
skin.setCreator(creator);
|
||||
}
|
||||
yapionObject.add("type", typeKuerzel);
|
||||
yapionObject.add("schematic", arenaFile.getPath());
|
||||
skin.setSchematic(arenaFile.getPath());
|
||||
if (testblockFile != null) {
|
||||
yapionObject.add("testblockSchematic", testblockFile.getPath());
|
||||
skin.setTestblockSchematic(testblockFile.getPath());
|
||||
}
|
||||
BauSystem.MESSAGE.send("SKIN_MESSAGE", p, BauSystem.MESSAGE.parse("SKIN_MESSAGE_HOVER", p), new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, yapionObject.toYAPION(new StringOutput(true)).getResult()));
|
||||
BauSystem.MESSAGE.send("SKIN_MESSAGE", p, BauSystem.MESSAGE.parse("SKIN_MESSAGE_HOVER", p), new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, skin.toYaml().saveToString()));
|
||||
}
|
||||
|
||||
@Register("boundary")
|
||||
|
@ -34,18 +34,15 @@ public class BlockCounter {
|
||||
public final Map<Region, BlockCount> blockCountMap = new HashMap<>();
|
||||
|
||||
public boolean isActive(final Player p) {
|
||||
if (!Config.getInstance().get(p).containsKey("blockCounter")) {
|
||||
return false;
|
||||
}
|
||||
return Config.getInstance().get(p).getPlainValue("blockCounter");
|
||||
return Config.get(p).isBlockCounter();
|
||||
}
|
||||
|
||||
public void enable(final Player p) {
|
||||
Config.getInstance().get(p).put("blockCounter", true);
|
||||
Config.get(p).setBlockCounter(true);
|
||||
}
|
||||
|
||||
public void disable(final Player p) {
|
||||
Config.getInstance().get(p).put("blockCounter", false);
|
||||
Config.get(p).setBlockCounter(false);
|
||||
}
|
||||
|
||||
public String getMessage(Player player, int count, int tntCount, long tick, long lastTick) {
|
||||
|
@ -33,9 +33,7 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.TNTPrimed;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
import yapion.utils.ReflectionsUtils;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
@ -45,7 +43,7 @@ import java.util.stream.Collectors;
|
||||
@UtilityClass
|
||||
public class FreezeUtils {
|
||||
|
||||
private static final Field field;
|
||||
private static final Reflection.FieldAccessor<Boolean> field;
|
||||
public static final boolean freezeEnabled;
|
||||
|
||||
private static final Reflection.MethodInvoker getWorldHandle = Reflection.getTypedMethod(Reflection.getClass("{obc}.CraftWorld"), "getHandle", null);
|
||||
@ -56,8 +54,11 @@ public class FreezeUtils {
|
||||
private static final World world;
|
||||
|
||||
static {
|
||||
field = ReflectionsUtils.getField(Reflection.getClass("{nms.server.level}.WorldServer"), "freezed");
|
||||
if (field != null) field.setAccessible(true);
|
||||
Reflection.FieldAccessor<Boolean> f = null;
|
||||
try {
|
||||
f = Reflection.getField("{nms.server.level}.WorldServer", "freezed", boolean.class);
|
||||
} catch (IllegalArgumentException ignored) {}
|
||||
field = f;
|
||||
freezeEnabled = field != null;
|
||||
world = Bukkit.getWorlds().get(0);
|
||||
}
|
||||
@ -76,13 +77,9 @@ public class FreezeUtils {
|
||||
|
||||
private void setFreeze(World world, boolean state) {
|
||||
if (freezeEnabled) {
|
||||
try {
|
||||
field.set(getWorldHandle.invoke(world), state);
|
||||
cacheEntityPackets(state);
|
||||
frozen = state;
|
||||
} catch (IllegalAccessException e) {
|
||||
// Ignored;
|
||||
}
|
||||
field.set(getWorldHandle.invoke(world), state);
|
||||
cacheEntityPackets(state);
|
||||
frozen = state;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -30,7 +30,6 @@ import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
import yapion.hierarchy.types.YAPIONObject;
|
||||
|
||||
@Linked
|
||||
public class NightVisionCommand extends SWCommand implements Listener {
|
||||
@ -41,15 +40,15 @@ public class NightVisionCommand extends SWCommand implements Listener {
|
||||
|
||||
@Register(description = "NIGHT_VISION_HELP")
|
||||
public void genericCommand(Player p) {
|
||||
YAPIONObject yapionObject = Config.getInstance().get(p);
|
||||
boolean value = !yapionObject.getBooleanOrDefault("nightvision", false);
|
||||
yapionObject.put("nightvision", value);
|
||||
setNightVision(p, value);
|
||||
Config config = Config.get(p);
|
||||
config.setNightvision(!config.isNightvision());
|
||||
config.save();
|
||||
setNightVision(p, config.isNightvision());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
setNightVision(event.getPlayer(), Config.getInstance().get(event.getPlayer()).getBooleanOrDefault("nightvision", false));
|
||||
setNightVision(event.getPlayer(), Config.get(event.getPlayer()).isNightvision());
|
||||
}
|
||||
|
||||
private void setNightVision(Player p, boolean value) {
|
||||
|
@ -19,88 +19,70 @@
|
||||
|
||||
package de.steamwar.bausystem.features.warp;
|
||||
|
||||
import de.steamwar.bausystem.config.ConfigField;
|
||||
import de.steamwar.bausystem.config.YamlConfig;
|
||||
import de.steamwar.bausystem.worlddata.WorldData;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.SoundCategory;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
import yapion.hierarchy.types.YAPIONObject;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
@Getter
|
||||
public class Warp {
|
||||
|
||||
private static Map<String, Warp> warpMap = new HashMap<>();
|
||||
|
||||
static {
|
||||
Warp worldSpawn = new Warp("WorldSpawn");
|
||||
worldSpawn.setLocation(Bukkit.getWorlds().get(0).getSpawnLocation());
|
||||
worldSpawn.setMat(Material.NETHER_STAR);
|
||||
warpMap.put("WorldSpawn", worldSpawn);
|
||||
}
|
||||
public class Warp extends YamlConfig {
|
||||
|
||||
@ConfigField
|
||||
private String name;
|
||||
@ConfigField
|
||||
private Location location;
|
||||
@ConfigField
|
||||
private Material mat;
|
||||
|
||||
private Warp(String name) {
|
||||
public Warp(String name, Location location, Material mat) {
|
||||
this.name = name;
|
||||
this.location = location;
|
||||
this.mat = mat;
|
||||
|
||||
WorldData.getInstance().addWarp(this);
|
||||
}
|
||||
|
||||
public Warp(String name, Player player) {
|
||||
this.name = name;
|
||||
this.location = player.getLocation();
|
||||
this.mat = Material.COMPASS;
|
||||
warpMap.put(name, this);
|
||||
|
||||
WorldData.getInstance().addWarp(this);
|
||||
}
|
||||
|
||||
public Warp(String name, YAPIONObject object) {
|
||||
this.name = name;
|
||||
double x = object.getPlainValue("x");
|
||||
double y = object.getPlainValue("y");
|
||||
double z = object.getPlainValue("z");
|
||||
float yaw = object.getPlainValue("yaw");
|
||||
float pitch = object.getPlainValue("pitch");
|
||||
location = new Location(Bukkit.getWorlds().get(0), x, y, z, yaw, pitch);
|
||||
mat = Material.getMaterial(object.getPlainValue("material"));
|
||||
warpMap.put(name, this);
|
||||
}
|
||||
|
||||
public YAPIONObject output() {
|
||||
YAPIONObject yapionObject = new YAPIONObject();
|
||||
yapionObject.add("x", location.getX());
|
||||
yapionObject.add("y", location.getY());
|
||||
yapionObject.add("z", location.getZ());
|
||||
yapionObject.add("yaw", location.getYaw());
|
||||
yapionObject.add("pitch", location.getPitch());
|
||||
yapionObject.add("material", mat.toString());
|
||||
return yapionObject;
|
||||
public Warp(Map<String, Object> map) {
|
||||
super(map);
|
||||
}
|
||||
|
||||
public static Set<String> getWarpNames() {
|
||||
return warpMap.keySet();
|
||||
return WorldData.getInstance().getWarps().keySet();
|
||||
}
|
||||
|
||||
public static List<Warp> getWarps() {
|
||||
return new ArrayList<>(warpMap.values());
|
||||
return new ArrayList<>(WorldData.getInstance().getWarps().values());
|
||||
}
|
||||
|
||||
public static Warp getWarp(String name) {
|
||||
return warpMap.get(name);
|
||||
return WorldData.getInstance().getWarps().get(name);
|
||||
}
|
||||
|
||||
public void setMat(Material mat) {
|
||||
this.mat = mat;
|
||||
}
|
||||
|
||||
public void setLocation(Location location) {
|
||||
this.location = location;
|
||||
}
|
||||
|
||||
public void delete() {
|
||||
warpMap.remove(name);
|
||||
WorldData.getWarpData().remove(name);
|
||||
WorldData.getInstance().getWarps().remove(name);
|
||||
}
|
||||
|
||||
public void teleport(Player player) {
|
||||
|
@ -22,26 +22,22 @@ package de.steamwar.bausystem.features.warp;
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.Permission;
|
||||
import de.steamwar.bausystem.utils.ListChatView;
|
||||
import de.steamwar.bausystem.worlddata.WorldData;
|
||||
import de.steamwar.command.SWCommand;
|
||||
import de.steamwar.command.SWCommandUtils;
|
||||
import de.steamwar.command.TypeMapper;
|
||||
import de.steamwar.command.TypeValidator;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import de.steamwar.linkage.api.Disable;
|
||||
import de.steamwar.linkage.api.Enable;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.md_5.bungee.api.chat.ClickEvent;
|
||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||
import net.md_5.bungee.api.chat.HoverEvent;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import org.bukkit.entity.Player;
|
||||
import yapion.hierarchy.types.YAPIONObject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@Linked
|
||||
public class WarpCommand extends SWCommand implements Disable, Enable {
|
||||
public class WarpCommand extends SWCommand {
|
||||
|
||||
private static final String[] FORBIDDEN_NAMES = new String[]{
|
||||
"add", "create", "delete", "list", "info", "gui"
|
||||
@ -141,19 +137,4 @@ public class WarpCommand extends SWCommand implements Disable, Enable {
|
||||
player.performCommand("warp list " + String.join(" ", args));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enable() {
|
||||
WorldData.getWarpData().forEach((name, yapionAnyType) -> {
|
||||
new Warp(name, (YAPIONObject) yapionAnyType);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disable() {
|
||||
YAPIONObject yapionObject = WorldData.getWarpData();
|
||||
for (Warp warp : Warp.getWarps()) {
|
||||
yapionObject.add(warp.getName(), warp.output());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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,11 @@
|
||||
|
||||
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 lombok.Setter;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
@ -31,7 +32,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 +53,132 @@ public class Prototype {
|
||||
return new ArrayList<>(PROTOTYPE_MAP.values());
|
||||
}
|
||||
|
||||
@AllArgsConstructor
|
||||
@Getter
|
||||
public static class Skin {
|
||||
private final String name;
|
||||
private final String creator; // Nullable
|
||||
@Setter
|
||||
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;
|
||||
}
|
||||
|
@ -90,11 +90,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);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
@ -1,101 +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.worlddata;
|
||||
|
||||
import de.steamwar.sql.SteamwarUser;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import yapion.hierarchy.output.FileOutput;
|
||||
import yapion.hierarchy.types.YAPIONArray;
|
||||
import yapion.hierarchy.types.YAPIONObject;
|
||||
import yapion.parser.InputStreamCharsets;
|
||||
import yapion.parser.YAPIONParser;
|
||||
import yapion.parser.options.FileOptions;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
@UtilityClass
|
||||
public class SimulatorData {
|
||||
|
||||
private final File simulatorsDir = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "simulators");
|
||||
|
||||
static {
|
||||
simulatorsDir.mkdirs();
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public YAPIONObject getSimulator(Player player) {
|
||||
File file = getFile(player);
|
||||
if (!file.exists()) {
|
||||
return new YAPIONObject();
|
||||
}
|
||||
return YAPIONParser.parse(file, new FileOptions().charset(InputStreamCharsets.UTF_8));
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
private void internalSaveSimulator(Player player, YAPIONObject yapionObject) {
|
||||
File file = getFile(player);
|
||||
yapionObject.toYAPION(new FileOutput(file)).close();
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
void saveSimulator(SteamwarUser steamwarUser, YAPIONObject yapionObject) {
|
||||
File file = new File(simulatorsDir, steamwarUser.getId() + ".yapion");
|
||||
yapionObject.toYAPION(new FileOutput(file)).close();
|
||||
}
|
||||
|
||||
public List<String> listSimulator(Player player) {
|
||||
List<String> strings = getSimulator(player).getKeys();
|
||||
strings.remove("");
|
||||
return strings;
|
||||
}
|
||||
|
||||
public void saveSimulator(Player player, String name) {
|
||||
YAPIONObject yapionObject = getSimulator(player);
|
||||
yapionObject.put(name, yapionObject.getArray("").copy());
|
||||
internalSaveSimulator(player, yapionObject);
|
||||
}
|
||||
|
||||
public void saveSimulator(Player player, YAPIONArray simulator) {
|
||||
YAPIONObject yapionObject = getSimulator(player);
|
||||
yapionObject.put("", simulator);
|
||||
internalSaveSimulator(player, yapionObject);
|
||||
}
|
||||
|
||||
public void loadSimulator(Player player, String name) {
|
||||
YAPIONObject yapionObject = getSimulator(player);
|
||||
yapionObject.put("", yapionObject.getArray(name).copy());
|
||||
internalSaveSimulator(player, yapionObject);
|
||||
}
|
||||
|
||||
public void removeSimulator(Player player, String name) {
|
||||
YAPIONObject yapionObject = getSimulator(player);
|
||||
yapionObject.remove(name);
|
||||
internalSaveSimulator(player, yapionObject);
|
||||
}
|
||||
|
||||
private File getFile(Player player) {
|
||||
SteamwarUser steamwarUser = SteamwarUser.get(player.getUniqueId());
|
||||
return new File(simulatorsDir, steamwarUser.getId() + ".yapion");
|
||||
}
|
||||
}
|
@ -19,73 +19,78 @@
|
||||
|
||||
package de.steamwar.bausystem.worlddata;
|
||||
|
||||
import de.steamwar.sql.SteamwarUser;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import de.steamwar.bausystem.config.ConfigField;
|
||||
import de.steamwar.bausystem.config.YamlConfig;
|
||||
import de.steamwar.bausystem.features.warp.Warp;
|
||||
import de.steamwar.bausystem.region.FlagStorage;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.bukkit.Bukkit;
|
||||
import yapion.hierarchy.output.FileOutput;
|
||||
import yapion.hierarchy.types.YAPIONObject;
|
||||
import yapion.parser.InputStreamCharsets;
|
||||
import yapion.parser.YAPIONParser;
|
||||
import yapion.parser.options.StreamOptions;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.configuration.serialization.ConfigurationSerialization;
|
||||
|
||||
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);
|
||||
register(RegionConfig.class);
|
||||
register(Warp.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));
|
||||
|
||||
public YAPIONObject getWarpData() {
|
||||
return getWorldData().getYAPIONObjectOrSetDefault("warps", new YAPIONObject());
|
||||
}
|
||||
@ConfigField
|
||||
private final Map<String, RegionConfig> regionConfigs = new HashMap<>();
|
||||
@Getter
|
||||
@ConfigField
|
||||
private final Map<String, Warp> warps = new HashMap<>();
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
// 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 WorldData(ConfigurationSection configuration) {
|
||||
super(configuration);
|
||||
instance = this;
|
||||
if(warps.isEmpty()) {
|
||||
new Warp("WorldSpawn", Bukkit.getWorlds().get(0).getSpawnLocation(), Material.NETHER_STAR);
|
||||
}
|
||||
}
|
||||
|
||||
public void write() {
|
||||
public RegionConfig getRegionConfig(String region) {
|
||||
return regionConfigs.computeIfAbsent(region, name -> new RegionConfig());
|
||||
}
|
||||
|
||||
public void addWarp(Warp warp) {
|
||||
warps.put(warp.getName(), warp);
|
||||
}
|
||||
|
||||
public void save() {
|
||||
try {
|
||||
worldData.toYAPION(new FileOutput(optionsFile)).close();
|
||||
} catch (IOException e) {
|
||||
// Ignored
|
||||
toYaml().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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -46,10 +46,6 @@ allprojects {
|
||||
repositories {
|
||||
mavenCentral()
|
||||
|
||||
maven {
|
||||
url = uri("https://raw.githubusercontent.com/yoyosource/YAPION/master/releases")
|
||||
}
|
||||
|
||||
maven {
|
||||
url = uri("https://repo.codemc.io/repository/maven-snapshots/")
|
||||
}
|
||||
|
Binäre Datei nicht angezeigt.
In neuem Issue referenzieren
Einen Benutzer sperren
@Getter könnte hier stehen statt an jedem Field.