SteamWar/BauSystem2.0
Archiviert
12
0

YeetAPION #176

Geschlossen
Lixfel möchte 8 Commits von reconfig nach master mergen
52 geänderte Dateien mit 827 neuen und 1499 gelöschten Zeilen

Datei anzeigen

@ -43,9 +43,6 @@ sourceSets {
} }
dependencies { dependencies {
// implementation 'yoyosource:YAPION:0.25.3'
implementation files("${projectDir}/../libs/YAPION-SNAPSHOT.jar")
compileOnly 'org.projectlombok:lombok:1.18.22' compileOnly 'org.projectlombok:lombok:1.18.22'
testCompileOnly 'org.projectlombok:lombok:1.18.22' testCompileOnly 'org.projectlombok:lombok:1.18.22'
annotationProcessor 'org.projectlombok:lombok:1.18.22' annotationProcessor 'org.projectlombok:lombok:1.18.22'

Datei anzeigen

@ -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_RESTORE_SCHEMATIC=§8/§eregion restore §8[§7Schematic§8] §8- §7Resets the region, withoout removing your builds
REGION_REGION_HELP_COPYPOINT=§8/§eregion copypoint §8- §7Teleport to the regions copy point REGION_REGION_HELP_COPYPOINT=§8/§eregion copypoint §8- §7Teleport to the regions copy point
REGION_REGION_HELP_TESTBLOCKPOINT=§8/§eregion testblockpoint §8- §7Teleport to the regions dummy point REGION_REGION_HELP_TESTBLOCKPOINT=§8/§eregion testblockpoint §8- §7Teleport to the regions dummy point
REGION_REGION_HELP_CHANGETYPE_INFO=§8/§eregion changetype §8- §7Returns the region type
REGION_REGION_HELP_CHANGETYPE=§8/§eregion changetype §8[§7Type§8] §8- §8Sets the region type
REGION_REGION_HELP_CHANGESKIN_INFO=§8/§eregion changeskin §8- §7Returns the region skin REGION_REGION_HELP_CHANGESKIN_INFO=§8/§eregion changeskin §8- §7Returns the region skin
REGION_REGION_HELP_CHANGESKIN=§8/§eregion changeskin §8[§7Skin§8] §8- §8Sets the region skin REGION_REGION_HELP_CHANGESKIN=§8/§eregion changeskin §8[§7Skin§8] §8- §8Sets the region skin
REGION_REGION_NOTHING_UNDO=§cNothing left to undo REGION_REGION_NOTHING_UNDO=§cNothing left to undo
@ -820,12 +818,6 @@ REGION_REGION_TP_TEST_BLOCK=§7Teleported to the tesblock
REGION_REGION_TP_UNKNOWN=§cUndefined teleport point REGION_REGION_TP_UNKNOWN=§cUndefined teleport point
REGION_REGION_NO_REGION=§cYou are not inside any region REGION_REGION_NO_REGION=§cYou are not inside any region
REGION_REGION_NO_PERMS=§cYou are not allowed to change the region REGION_REGION_NO_PERMS=§cYou are not allowed to change the region
REGION_REGION_CHANGETYPE_INFO=§7RRegion type is §e{0}
REGION_REGION_CHANGETYPE_UNKNOWN=§cRegion type is invalid
REGION_REGION_CHANGETYPE_INVALID=§cRegion type is not allowed here
REGION_REGION_CHANGETYPE_CHANGE=§7Region type changed to §e{0}
REGION_REGION_CHANGETYPE_CHANGE_UPDATE=§7Click §e§lHERE §7to change the region type
REGION_REGION_CHANGETYPE_CHANGE_UPDATE_HOVER=§8/§ereset
REGION_REGION_CHANGESKIN_INFO=§7Region skin is §e{0} REGION_REGION_CHANGESKIN_INFO=§7Region skin is §e{0}
REGION_REGION_CHANGESKIN_INFO_CREATOR=§7Skin created by §e{0} REGION_REGION_CHANGESKIN_INFO_CREATOR=§7Skin created by §e{0}
REGION_REGION_CHANGESKIN_UNKNOWN=§cRegion skin is invalid REGION_REGION_CHANGESKIN_UNKNOWN=§cRegion skin is invalid

Datei anzeigen

@ -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_RESTORE_SCHEMATIC=§8/§eregion restore §8[§7Schematic§8] §8- §7Setzte die Region zurück, ohne das Gebaute zu löschen
REGION_REGION_HELP_COPYPOINT=§8/§eregion copypoint §8- §7Teleportiere dich zum Regions Kopierpunkt REGION_REGION_HELP_COPYPOINT=§8/§eregion copypoint §8- §7Teleportiere dich zum Regions Kopierpunkt
REGION_REGION_HELP_TESTBLOCKPOINT=§8/§eregion testblockpoint §8- §7Teleportiere dich zum Regions Testblockpunkt REGION_REGION_HELP_TESTBLOCKPOINT=§8/§eregion testblockpoint §8- §7Teleportiere dich zum Regions Testblockpunkt
REGION_REGION_HELP_CHANGETYPE_INFO=§8/§eregion changetype §8- §7Gebe den Regions Type aus
REGION_REGION_HELP_CHANGETYPE=§8/§eregion changetype §8[§7Type§8] §8- §8Setzte den Regions Type
REGION_REGION_HELP_CHANGESKIN_INFO=§8/§eregion changeskin §8- §7Gebe den Regions Skin aus REGION_REGION_HELP_CHANGESKIN_INFO=§8/§eregion changeskin §8- §7Gebe den Regions Skin aus
REGION_REGION_HELP_CHANGESKIN=§8/§eregion changeskin §8[§7Skin§8] §8- §8Setzte den Regions Skin REGION_REGION_HELP_CHANGESKIN=§8/§eregion changeskin §8[§7Skin§8] §8- §8Setzte den Regions Skin
REGION_REGION_NOTHING_UNDO=§cNichts zum rückgängig machen REGION_REGION_NOTHING_UNDO=§cNichts zum rückgängig machen
@ -783,12 +781,6 @@ REGION_REGION_TP_TEST_BLOCK=§7Zum Testblock teleportiert
REGION_REGION_TP_UNKNOWN=§cNicht definierter Teleportierpunkt REGION_REGION_TP_UNKNOWN=§cNicht definierter Teleportierpunkt
REGION_REGION_NO_REGION=§cDu bist in keiner Region REGION_REGION_NO_REGION=§cDu bist in keiner Region
REGION_REGION_NO_PERMS=§cDu darfst hier nicht die Region verändern REGION_REGION_NO_PERMS=§cDu darfst hier nicht die Region verändern
REGION_REGION_CHANGETYPE_INFO=§7Regions Type ist §e{0}
REGION_REGION_CHANGETYPE_UNKNOWN=§cRegions Type ist nicht valide
REGION_REGION_CHANGETYPE_INVALID=§cRegions Type ist nicht erlaubt hier
REGION_REGION_CHANGETYPE_CHANGE=§7Regions Type ist auf §e{0}§7 geändert
REGION_REGION_CHANGETYPE_CHANGE_UPDATE=§7Klicke §e§lHIER §7um den Type anzuwenden
REGION_REGION_CHANGETYPE_CHANGE_UPDATE_HOVER=§8/§ereset
REGION_REGION_CHANGESKIN_INFO=§7Regions Skin ist §e{0} REGION_REGION_CHANGESKIN_INFO=§7Regions Skin ist §e{0}
REGION_REGION_CHANGESKIN_INFO_CREATOR=§7Skin erstellt von §e{0} REGION_REGION_CHANGESKIN_INFO_CREATOR=§7Skin erstellt von §e{0}
REGION_REGION_CHANGESKIN_UNKNOWN=§cRegions Skin ist nicht valide REGION_REGION_CHANGESKIN_UNKNOWN=§cRegions Skin ist nicht valide

Datei anzeigen

@ -26,11 +26,10 @@ import de.steamwar.bausystem.features.tpslimit.TPSLimitUtils;
import de.steamwar.bausystem.features.tpslimit.TPSUtils; import de.steamwar.bausystem.features.tpslimit.TPSUtils;
import de.steamwar.bausystem.features.tpslimit.TPSWarpUtils; import de.steamwar.bausystem.features.tpslimit.TPSWarpUtils;
import de.steamwar.bausystem.features.world.RamUsage; 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.PrototypeLoader;
import de.steamwar.bausystem.region.loader.RegionLoader; import de.steamwar.bausystem.region.loader.RegionLoader;
import de.steamwar.bausystem.region.loader.Updater;
import de.steamwar.bausystem.worlddata.WorldData; import de.steamwar.bausystem.worlddata.WorldData;
import de.steamwar.bausystem.linkage.LinkageUtils;
import de.steamwar.message.Message; import de.steamwar.message.Message;
import lombok.Getter; import lombok.Getter;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -79,9 +78,6 @@ public class BauSystem extends JavaPlugin implements Listener {
return; return;
} }
new Updater(PrototypeLoader.file, PrototypeLoader::load);
new Updater(RegionLoader.file, RegionLoader::load);
LinkageUtils.link(); LinkageUtils.link();
RamUsage.init(); RamUsage.init();
@ -107,8 +103,8 @@ public class BauSystem extends JavaPlugin implements Listener {
public void onDisable() { public void onDisable() {
LinkageUtils.unlink(); LinkageUtils.unlink();
WorldData.write(); WorldData.getInstance().save();
Config.getInstance().saveAll(); Config.saveAll();
TinyProtocol.instance.close(); TinyProtocol.instance.close();
} }

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

@ -19,129 +19,120 @@
package de.steamwar.bausystem.configplayer; 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.linkage.Linked;
import de.steamwar.sql.UserConfig; import de.steamwar.sql.UserConfig;
import lombok.Getter; import lombok.Getter;
import org.bukkit.Bukkit; import lombok.Setter;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerQuitEvent;
import yapion.hierarchy.output.StringOutput;
import yapion.hierarchy.types.YAPIONObject;
import yapion.parser.YAPIONParser;
import yapion.serializing.SerializeManager;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
import java.util.logging.Level;
@Linked public class Config extends YamlConfig {
Review

@Getter könnte hier stehen statt an jedem Field.

@Getter könnte hier stehen statt an jedem Field.
public class Config implements Listener {
static { private static final Map<UUID, Config> playerConfigurations = new HashMap<>();
SerializeManager.add(new ConfigurationSerializableSerializer());
public static Config get(Player player) { //TODO: NULL
return playerConfigurations.computeIfAbsent(player.getUniqueId(), uuid -> new Config(uuid, fromUserConfig(uuid, "bausystem")));
} }
@Getter public static void saveAll() {
private static Config instance; playerConfigurations.forEach((uuid, config) -> config.save());
{
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);
});
playerConfigurations.clear(); playerConfigurations.clear();
} }
/** private final UUID uuid;
* Save a PlayerConfig, this does not remove the key value mapping from the map.
* @Getter
* @param player the player to save the config. @Setter
*/ @ConfigField
public void save(Player player) { private boolean nightvision;
UUID uuid = player.getUniqueId();
if (playerConfigurations.containsKey(uuid)) { @Getter
YAPIONObject yapionObject = playerConfigurations.get(uuid); @Setter
String string = yapionObject.toYAPION(new StringOutput()).getResult(); @ConfigField
UserConfig.updatePlayerConfig(uuid, "bausystem", string); 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) { public void save() {
int version = yapionObject.getPlainValue("@version"); UserConfig.updatePlayerConfig(uuid, "bausystem", toYaml().saveToString());
while (version < ConfigCreator.currentVersion) { }
ConfigConverter configConverter = CONFIG_CONVERTER_MAP.getOrDefault(version, null);
if (configConverter == null) { @Linked
Bukkit.getLogger().log(Level.SEVERE, "No updater found for version " + version); public static class ConfigListener implements Listener {
return ConfigCreator.createDefaultConfig();
@EventHandler
public void onPlayerQuit(PlayerQuitEvent event) {
get(event.getPlayer()).save();
playerConfigurations.remove(event.getPlayer().getUniqueId());
} }
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;
}
return yapionObject;
} }
} }

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

@ -79,7 +79,7 @@ public class Detonator {
public static void activateDetonator(DetonatorStorage detonator) { public static void activateDetonator(DetonatorStorage detonator) {
Player p = detonator.getPlayer(); Player p = detonator.getPlayer();
if (Config.getInstance().get(p).getPlainValueOrDefault("detonator-autostart", false)) { if (Config.get(p).isDetonatorAutostart()) {
AutostartListener.instance.activate(p); AutostartListener.instance.activate(p);
} }

Datei anzeigen

@ -76,8 +76,8 @@ public class DetonatorCommand extends SWCommand {
@Register(value = "autostart", description = "DETONATOR_HELP_AUTOSTART") @Register(value = "autostart", description = "DETONATOR_HELP_AUTOSTART")
public void toggleAutostartTimer(Player p) { public void toggleAutostartTimer(Player p) {
boolean current = Config.getInstance().get(p).getPlainValueOrDefault("detonator-autostart", false); boolean current = Config.get(p).isDetonatorAutostart();
Config.getInstance().get(p).put("detonator-autostart", !current); Config.get(p).setDetonatorAutostart(!current);
if (!current) { if (!current) {
BauSystem.MESSAGE.send("DETONATOR_AUTOSTART_ENABLE", p); BauSystem.MESSAGE.send("DETONATOR_AUTOSTART_ENABLE", p);
} else { } else {

Datei anzeigen

@ -67,7 +67,7 @@ public class BauGUI {
if (!updating) { if (!updating) {
OPEN_INVS.add(p); 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)); SWInventory inv = new SWInventory(p, mapping.getSize(), BauSystem.MESSAGE.parse("GUI_NAME", p));
getITEMS().values().forEach(item -> { getITEMS().values().forEach(item -> {
if (!mapping.isShown(item.getId())) { if (!mapping.isShown(item.getId())) {

Datei anzeigen

@ -53,7 +53,7 @@ public class BauGuiEditor implements Listener {
private static final List<Player> open_Edits = new ArrayList<>(); private static final List<Player> open_Edits = new ArrayList<>();
public static void openGuiEditor(Player p, ItemStack cursor) { 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)); Inventory inv = Bukkit.createInventory(null, mapping.getSize() + 9, BauSystem.MESSAGE.parse("GUI_EDITOR_TITLE", p));
for (Map.Entry<Integer, Integer> e : mapping.getMapping().entrySet()) { for (Map.Entry<Integer, Integer> e : mapping.getMapping().entrySet()) {
if (e.getValue() >= 0) { if (e.getValue() >= 0) {
@ -78,7 +78,6 @@ public class BauGuiEditor implements Listener {
p.openInventory(inv); p.openInventory(inv);
p.getOpenInventory().setCursor(cursor == null ? new SWItem().getItemStack() : cursor); p.getOpenInventory().setCursor(cursor == null ? new SWItem().getItemStack() : cursor);
open_Edits.add(p); open_Edits.add(p);
BauGuiMapping.startWatchdog();
} }
private static ItemStack addId(ItemStack itemStack, int id) { private static ItemStack addId(ItemStack itemStack, int id) {
@ -101,7 +100,7 @@ public class BauGuiEditor implements Listener {
ItemStack i = event.getCurrentItem(); ItemStack i = event.getCurrentItem();
Player p = (Player) event.getWhoClicked(); Player p = (Player) event.getWhoClicked();
BauGuiMapping mapping = BauGuiMapping.getGuiMapping(p); BauGuiMapping mapping = new BauGuiMapping(p);
if (event.getClickedInventory() == p.getInventory()) { if (event.getClickedInventory() == p.getInventory()) {
event.setCancelled(true); event.setCancelled(true);
} }
@ -194,13 +193,10 @@ public class BauGuiEditor implements Listener {
} }
private void saveMapping(Player p) { private void saveMapping(Player p) {
saveMapping(p.getOpenInventory(), BauGuiMapping.getGuiMapping(p)); saveMapping(p.getOpenInventory(), new BauGuiMapping(p));
} }
private void saveMapping(InventoryView view, BauGuiMapping mapping) { private void saveMapping(InventoryView view, BauGuiMapping mapping) {
if (mapping.isSaved()) {
return;
}
HashMap<Integer, Integer> newMapping = new HashMap<>(); HashMap<Integer, Integer> newMapping = new HashMap<>();
for (int i = 0; i < view.getTopInventory().getContents().length; i++) { for (int i = 0; i < view.getTopInventory().getContents().length; i++) {
@ -216,7 +212,6 @@ public class BauGuiEditor implements Listener {
} }
mapping.setMapping(newMapping); mapping.setMapping(newMapping);
mapping.save();
} }
@EventHandler @EventHandler
@ -227,7 +222,7 @@ public class BauGuiEditor implements Listener {
Player p = (Player) event.getPlayer(); Player p = (Player) event.getPlayer();
saveMapping(event.getView(), BauGuiMapping.getGuiMapping(p)); saveMapping(event.getView(), new BauGuiMapping(p));
open_Edits.remove(p); open_Edits.remove(p);
} }
} }

Datei anzeigen

@ -19,82 +19,50 @@
package de.steamwar.bausystem.features.gui.editor; package de.steamwar.bausystem.features.gui.editor;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.configplayer.Config; 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.Getter;
import lombok.Setter;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player; 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 { 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 @Getter
private final Player owner; private final Player owner;
@Getter
@Setter
private boolean saved;
protected BauGuiMapping(YAPIONObject object, Player p) { public BauGuiMapping(Player p) {
this.object = object;
this.owner = p; this.owner = p;
fromUUID.put(p.getUniqueId(), this);
mappings.add(this);
} }
public static BauGuiMapping getGuiMapping(Player p) { private Map<String, Integer> getInternalMapping() {
BauGuiMapping mapping = fromUUID.get(p.getUniqueId()); return Config.get(owner).getBaugui();
if (mapping == null) {
YAPIONObject yapionObject = Config.getInstance().get(p);
mapping = new BauGuiMapping(yapionObject.getObject("baugui"), p);
}
return mapping;
} }
public boolean isShown(int id) { 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) { public int getSlot(int id) {
return object.getPlainValue(Integer.toString(id)); return getInternalMapping().getOrDefault(Integer.toString(id), 0);
} }
public Map<Integer, Integer> getMapping() { 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) { 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() { public int getSize() {
return object.getPlainValueOrDefault("size", 45); return getInternalMapping().getOrDefault("size", 45);
} }
public void setSize(int size) { public void setSize(int size) {
@ -102,37 +70,6 @@ public class BauGuiMapping {
return; return;
} }
object.add("size", size); getInternalMapping().put("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);
}
} }
} }

Datei anzeigen

@ -19,75 +19,89 @@
package de.steamwar.bausystem.features.hotbar; 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 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.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import yapion.hierarchy.types.YAPIONArray; import org.bukkit.inventory.meta.ItemMeta;
import yapion.hierarchy.types.YAPIONObject;
import yapion.hierarchy.types.YAPIONValue;
import yapion.parser.YAPIONParser;
import yapion.serializing.YAPIONDeserializer;
import yapion.serializing.YAPIONSerializer;
import java.util.HashSet; import java.util.ArrayList;
import java.util.Set; import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
@UtilityClass public class DefaultHotbar extends YamlConfig {
public class DefaultHotbar {
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) { public static DefaultHotbar get(Player p) {
ItemStack[] hotbar = new ItemStack[13]; return new DefaultHotbar(p, fromUserConfig(p.getUniqueId(), configName));
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));
}
}
Config.getInstance().get(p).add("hotbar-" + Core.getVersion(), yapionArray);
Config.getInstance().save(p);
} }
public void setHotbar(Player p) { private final Player player;
ItemStack[] hotbar = getItems(p);
ItemStack[] inv = p.getInventory().getContents(); @Getter
ItemStack[] armor = p.getInventory().getArmorContents(); @ConfigField
System.arraycopy(hotbar, 0, inv, 0, 9); private final List<ItemStack> hotbar = new ArrayList<>(13);
System.arraycopy(hotbar, 9, armor, 0, 4);
p.getInventory().setContents(inv); public DefaultHotbar(Player player, ConfigurationSection config) {
p.getInventory().setArmorContents(armor); 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);
}
} }
public ItemStack[] getItems(Player p) { public void update() {
Config.getInstance().get(p).remap("hotbar", "hotbar-19"); hotbar.clear();
YAPIONArray yapionArray = Config.getInstance().get(p).getYAPIONArrayOrSetDefault("hotbar-" + Core.getVersion(), defaultHotbar());
ItemStack[] hotbar = new ItemStack[13]; for(int i = 0; i < 9; i++)
Set<Integer> invalid = new HashSet<>(); hotbar.add(player.getInventory().getContents()[i]);
yapionArray.forEach((integer, yapionAnyType) -> {
if (yapionAnyType instanceof YAPIONValue) { for(int i = 0; i < 4; i++)
hotbar[integer] = null; hotbar.add(player.getInventory().getArmorContents()[i]);
} else {
try { UserConfig.updatePlayerConfig(player.getUniqueId(), configName, toYaml().saveToString());
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 YAPIONArray defaultHotbar() { public void load() {
return DEFAULT_HOTBAR; 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);
}
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;
} }
} }

Datei anzeigen

@ -26,6 +26,8 @@ import de.steamwar.linkage.Linked;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import java.util.List;
@Linked @Linked
public class HotbarCommand extends SWCommand { public class HotbarCommand extends SWCommand {
@ -36,23 +38,23 @@ public class HotbarCommand extends SWCommand {
@Register(value = "load", description = "HOTBAR_HELP_LOAD") @Register(value = "load", description = "HOTBAR_HELP_LOAD")
public void loadHotbar(Player p) { public void loadHotbar(Player p) {
DefaultHotbar.setHotbar(p); DefaultHotbar.get(p).load();
BauSystem.MESSAGE.send("HOTBAR_LOADED", p); BauSystem.MESSAGE.send("HOTBAR_LOADED", p);
} }
@Register(value = "save", description = "HOTBAR_HELP_SAVE") @Register(value = "save", description = "HOTBAR_HELP_SAVE")
public void saveHotbar(Player p) { public void saveHotbar(Player p) {
DefaultHotbar.updateHotbar(p); DefaultHotbar.get(p).update();
BauSystem.MESSAGE.send("HOTBAR_SAVED", p); BauSystem.MESSAGE.send("HOTBAR_SAVED", p);
} }
@Register(value = "show", description = "HOTBAR_HELP_SHOW") @Register(value = "show", description = "HOTBAR_HELP_SHOW")
public void showHotbar(Player p) { public void showHotbar(Player p) {
SWInventory inv = new SWInventory(p, 18, BauSystem.MESSAGE.parse("HOTBAR_INVENTORY", p)); SWInventory inv = new SWInventory(p, 18, BauSystem.MESSAGE.parse("HOTBAR_INVENTORY", p));
ItemStack[] hotbar = DefaultHotbar.getItems(p); List<ItemStack> hotbar = DefaultHotbar.get(p).getHotbar();
for (int i = 0; i < hotbar.length; i++) { for (int i = 0; i < hotbar.size(); i++) {
if (hotbar[i] == null) continue; if (hotbar.get(i) == null) continue;
inv.setItem(i, hotbar[i], clickType -> { inv.setItem(i, hotbar.get(i), clickType -> {
}); });
} }
inv.open(); inv.open();

Datei anzeigen

@ -31,7 +31,7 @@ public class HotbarListener implements Listener {
@EventHandler(priority = EventPriority.LOWEST) @EventHandler(priority = EventPriority.LOWEST)
public void onPlayerJoin(PlayerJoinEvent event) { public void onPlayerJoin(PlayerJoinEvent event) {
if (allNull(event.getPlayer().getInventory().getContents()) && allNull(event.getPlayer().getInventory().getArmorContents())) { if (allNull(event.getPlayer().getInventory().getContents()) && allNull(event.getPlayer().getInventory().getArmorContents())) {
DefaultHotbar.setHotbar(event.getPlayer()); DefaultHotbar.get(event.getPlayer()).load();
} }
} }

Datei anzeigen

@ -30,7 +30,7 @@ public class InventoryFillBauGuiItem extends BauGuiItem {
@Override @Override
public ItemStack getItem(Player player) { 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(); return new SWItem(Material.HOPPER, BauSystem.MESSAGE.parse("OTHER_ITEMS_INVENTORY_FILL_NAME", player), Collections.singletonList(BauSystem.MESSAGE.parse(loreKey, player)), false, clickType -> {}).getItemStack();
} }

Datei anzeigen

@ -38,7 +38,7 @@ public class InventoryFiller implements Listener {
@EventHandler @EventHandler
public void onPlayerDropItem(PlayerDropItemEvent event) { 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; if (!event.getPlayer().isSneaking()) return;
Block block = event.getPlayer().getTargetBlockExact(5); Block block = event.getPlayer().getTargetBlockExact(5);
if (block == null) return; if (block == null) return;
@ -59,7 +59,7 @@ public class InventoryFiller implements Listener {
*/ */
@EventHandler @EventHandler
public void onPlayerItemHeld(PlayerItemHeldEvent event) { 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; if (!event.getPlayer().isSneaking()) return;
ItemStack itemStack = event.getPlayer().getInventory().getItemInMainHand(); ItemStack itemStack = event.getPlayer().getInventory().getItemInMainHand();
if (itemStack.getType() == Material.AIR) return; if (itemStack.getType() == Material.AIR) return;

Datei anzeigen

@ -16,8 +16,8 @@ public class InventoryFillerCommand extends SWCommand {
@Register(description = {"INVENTORY_FILL_HELP", "INVENTORY_FILL_INFO"}) @Register(description = {"INVENTORY_FILL_HELP", "INVENTORY_FILL_INFO"})
public void toggle(Player player) { public void toggle(Player player) {
boolean inventoryFill = Config.getInstance().get(player).getPlainValueOrDefault("inventoryfill", false); boolean inventoryFill = Config.get(player).isInventoryFill();
Config.getInstance().get(player).put("inventoryfill", !inventoryFill); Config.get(player).setInventoryFill(!inventoryFill);
if (!inventoryFill) { if (!inventoryFill) {
SWUtils.sendToActionbar(player, BauSystem.MESSAGE.parse("INVENTORY_FILL_ENABLE", player)); SWUtils.sendToActionbar(player, BauSystem.MESSAGE.parse("INVENTORY_FILL_ENABLE", player));
BauSystem.MESSAGE.send("INVENTORY_FILL_INFO", player); BauSystem.MESSAGE.send("INVENTORY_FILL_INFO", player);

Datei anzeigen

@ -22,11 +22,11 @@ package de.steamwar.bausystem.features.region;
import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.Permission;
import de.steamwar.bausystem.features.util.SelectCommand; import de.steamwar.bausystem.features.util.SelectCommand;
import de.steamwar.bausystem.region.Prototype;
import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.region.Region;
import de.steamwar.bausystem.region.RegionUtils; import de.steamwar.bausystem.region.RegionUtils;
import de.steamwar.bausystem.region.utils.RegionExtensionType; import de.steamwar.bausystem.region.utils.RegionExtensionType;
import de.steamwar.bausystem.region.utils.RegionType; import de.steamwar.bausystem.region.utils.RegionType;
import de.steamwar.bausystem.worlddata.WorldData;
import de.steamwar.command.PreviousArguments; import de.steamwar.command.PreviousArguments;
import de.steamwar.command.SWCommand; import de.steamwar.command.SWCommand;
import de.steamwar.command.TypeMapper; import de.steamwar.command.TypeMapper;
@ -155,36 +155,6 @@ public class RegionCommand extends SWCommand {
BauSystem.MESSAGE.send("REGION_REGION_TP_TEST_BLOCK", p); BauSystem.MESSAGE.send("REGION_REGION_TP_TEST_BLOCK", p);
} }
@Register(value = "changetype", description = "REGION_REGION_HELP_CHANGETYPE_INFO")
@Register("type")
public void changeTypeCommand(Player p) {
Region region = Region.getRegion(p.getLocation());
if (checkGlobalRegion(region, p)) {
return;
}
BauSystem.MESSAGE.send("REGION_REGION_CHANGETYPE_INFO", p, region.getPrototype().getDisplayName());
}
@Register(value = "changetype", description = "REGION_REGION_HELP_CHANGETYPE")
@Register("type")
public void changeTypeCommand(@Validator("WORLD") Player p, @Mapper("regionTypeMapper") String s) {
Region region = Region.getRegion(p.getLocation());
if (checkGlobalRegion(region, p)) {
return;
}
Prototype prototype = Prototype.getByDisplayName(s);
if (prototype == null) {
BauSystem.MESSAGE.send("REGION_REGION_CHANGETYPE_UNKNOWN", p);
} else {
if (region.setPrototype(prototype)) {
BauSystem.MESSAGE.send("REGION_REGION_CHANGETYPE_CHANGE", p, s);
BauSystem.MESSAGE.send("REGION_REGION_CHANGETYPE_CHANGE_UPDATE", p, BauSystem.MESSAGE.parse("REGION_REGION_CHANGETYPE_CHANGE_UPDATE_HOVER", p), new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/reset"));
} else {
BauSystem.MESSAGE.send("REGION_REGION_CHANGETYPE_INVALID", p);
}
}
}
@Register(value = "changeskin", description = "REGION_REGION_HELP_CHANGESKIN_INFO") @Register(value = "changeskin", description = "REGION_REGION_HELP_CHANGESKIN_INFO")
@Register("skin") @Register("skin")
public void changeSkinCommand(Player p) { public void changeSkinCommand(Player p) {
@ -193,7 +163,7 @@ public class RegionCommand extends SWCommand {
return; return;
} }
BauSystem.MESSAGE.send("REGION_REGION_CHANGESKIN_INFO", p, region.getSkin()); BauSystem.MESSAGE.send("REGION_REGION_CHANGESKIN_INFO", p, region.getSkin());
String creator = region.getPrototype().getSkinMap().get(region.getSkin()).getCreator(); String creator = region.getPrototype().getSkins().get(region.getSkin()).getCreator();
if (creator != null) { if (creator != null) {
BauSystem.MESSAGE.send("REGION_REGION_CHANGESKIN_INFO_CREATOR", p, creator); BauSystem.MESSAGE.send("REGION_REGION_CHANGESKIN_INFO_CREATOR", p, creator);
} }
@ -206,10 +176,11 @@ public class RegionCommand extends SWCommand {
if (checkGlobalRegion(region, p)) { if (checkGlobalRegion(region, p)) {
return; return;
} }
if (!region.getPrototype().getSkinMap().containsKey(s)) { if (!region.getPrototype().getSkins().containsKey(s)) {
BauSystem.MESSAGE.send("REGION_REGION_CHANGESKIN_UNKNOWN", p); BauSystem.MESSAGE.send("REGION_REGION_CHANGESKIN_UNKNOWN", p);
} else { } else {
if (region.setSkin(s)) { if (region.setSkin(s)) {
WorldData.getInstance().save();
BauSystem.MESSAGE.send("REGION_REGION_CHANGESKIN_CHANGE", p, s); BauSystem.MESSAGE.send("REGION_REGION_CHANGESKIN_CHANGE", p, s);
BauSystem.MESSAGE.send("REGION_REGION_CHANGESKIN_CHANGE_UPDATE", p, BauSystem.MESSAGE.parse("REGION_REGION_CHANGESKIN_CHANGE_UPDATE_HOVER", p), new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/reset")); BauSystem.MESSAGE.send("REGION_REGION_CHANGESKIN_CHANGE_UPDATE", p, BauSystem.MESSAGE.parse("REGION_REGION_CHANGESKIN_CHANGE_UPDATE_HOVER", p), new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/reset"));
} else { } else {
@ -218,26 +189,6 @@ public class RegionCommand extends SWCommand {
} }
} }
@Mapper(value = "regionTypeMapper", local = true)
private TypeMapper<String> regionTypeMapper() {
return new TypeMapper<String>() {
@Override
public List<String> tabCompletes(CommandSender commandSender, PreviousArguments previousArguments, String s) {
Player p = (Player) commandSender;
Region region = Region.getRegion(p.getLocation());
if (region.isGlobal()) {
return Collections.emptyList();
}
return region.getPrototypes().stream().map(Prototype::getByName).map(Prototype::getDisplayName).map(c -> c.replace(' ', '_')).collect(Collectors.toList());
}
@Override
public String map(CommandSender commandSender, PreviousArguments previousArguments, String s) {
return s.replace('_', ' ');
}
};
}
@Mapper(value = "skinTypeMapper", local = true) @Mapper(value = "skinTypeMapper", local = true)
private TypeMapper<String> skinTypeMapper() { private TypeMapper<String> skinTypeMapper() {
return new TypeMapper<String>() { return new TypeMapper<String>() {
@ -248,7 +199,7 @@ public class RegionCommand extends SWCommand {
if (region.isGlobal()) { if (region.isGlobal()) {
return Collections.emptyList(); return Collections.emptyList();
} }
return region.getPrototype().getSkinMap().keySet().stream().map(c -> c.replace(' ', '_')).collect(Collectors.toList()); return region.getPrototype().getSkins().keySet().stream().map(c -> c.replace(' ', '_')).collect(Collectors.toList());
} }
@Override @Override

Datei anzeigen

@ -21,24 +21,18 @@ package de.steamwar.bausystem.features.simulator;
import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.SWUtils; import de.steamwar.bausystem.SWUtils;
import de.steamwar.bausystem.features.simulator.tnt.TNTElement;
import de.steamwar.bausystem.utils.ItemUtils; import de.steamwar.bausystem.utils.ItemUtils;
import de.steamwar.inventory.SWItem; import de.steamwar.inventory.SWItem;
import de.steamwar.linkage.Linked; import de.steamwar.linkage.Linked;
import de.steamwar.linkage.api.Disable; import de.steamwar.linkage.api.Disable;
import de.steamwar.linkage.api.Enable; import de.steamwar.linkage.api.Enable;
import de.steamwar.sql.SteamwarUser;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.NamespacedKey; import org.bukkit.NamespacedKey;
import org.bukkit.World; import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta; 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.File;
import java.io.IOException; import java.io.IOException;
@ -46,17 +40,15 @@ import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors;
@Linked @Linked
public class SimulatorStorage implements Enable, Disable { 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 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) { public static void createNewSimulator(String name) {
tntSimulators.put(name, new TNTSimulator()); tntSimulators.put(name, new TNTSimulator());
@ -107,11 +99,11 @@ public class SimulatorStorage implements Enable, Disable {
if (tntSimulator != null) { if (tntSimulator != null) {
tntSimulator.close(); tntSimulator.close();
} }
new File(simulatorsDir, name + ".simulator").delete(); new File(simulatorsDir, name + ".yml").delete();
} }
public static void copySimulator(TNTSimulator tntSimulator, String name) { 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) { public static void removeSimulator(ItemStack itemStack) {
@ -139,48 +131,11 @@ public class SimulatorStorage implements Enable, Disable {
if (files == null) return; if (files == null) return;
for (File file : files) { for (File file : files) {
YAPIONObject yapionObject; String name = file.getName();
try { if(!name.endsWith(".yml"))
yapionObject = YAPIONParser.parse(file);
} catch (YAPIONException | IOException e) {
continue; 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) { tntSimulators.put(name.substring(0, name.length() - 4), new TNTSimulator(YamlConfiguration.loadConfiguration(file)));
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);
} }
} }
@ -188,9 +143,9 @@ public class SimulatorStorage implements Enable, Disable {
public void disable() { public void disable() {
for (Map.Entry<String, TNTSimulator> entry : tntSimulators.entrySet()) { for (Map.Entry<String, TNTSimulator> entry : tntSimulators.entrySet()) {
try { try {
entry.getValue().toYAPION().toFile(new File(simulatorsDir, entry.getKey() + ".simulator")); entry.getValue().toYaml().save(new File(simulatorsDir, entry.getKey() + ".yml"));
} catch (Exception e) { } catch (IOException e) {
e.printStackTrace(); throw new SecurityException(e);
} }
} }
} }

Datei anzeigen

@ -20,6 +20,8 @@
package de.steamwar.bausystem.features.simulator; package de.steamwar.bausystem.features.simulator;
import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.config.ConfigField;
import de.steamwar.bausystem.config.YamlConfig;
import de.steamwar.bausystem.configplayer.Config; import de.steamwar.bausystem.configplayer.Config;
import de.steamwar.bausystem.features.simulator.gui.TNTElementGUI; import de.steamwar.bausystem.features.simulator.gui.TNTElementGUI;
import de.steamwar.bausystem.features.simulator.gui.TNTSimulatorGui; import de.steamwar.bausystem.features.simulator.gui.TNTSimulatorGui;
@ -36,10 +38,8 @@ import de.steamwar.entity.REntityServer;
import lombok.Getter; import lombok.Getter;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player; 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.*;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
@ -47,40 +47,29 @@ import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@Getter @Getter
public class TNTSimulator { public class TNTSimulator extends YamlConfig {
private Set<Player> players = new HashSet<>(); static {
private REntityServer entityServer = new REntityServer(); 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 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) { for(SimulatorElement element : tntElementList)
material = Material.valueOf(yapionObject.getStringOrDefault("material", Material.TNT.name())); element.init(entityServer, null);
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;
} }
public void close() { public void close() {
@ -218,7 +207,7 @@ public class TNTSimulator {
AtomicBoolean needsAutoTrace = new AtomicBoolean(); AtomicBoolean needsAutoTrace = new AtomicBoolean();
players.forEach(player -> { players.forEach(player -> {
boolean simulatorAutoTrace = Config.getInstance().get(player).getPlainValueOrDefault("simulatorAutoTrace", false); boolean simulatorAutoTrace = Config.get(player).isSimulatorAutoTrace();
if (simulatorAutoTrace) { if (simulatorAutoTrace) {
needsAutoTrace.set(true); needsAutoTrace.set(true);
player.performCommand("trace show"); player.performCommand("trace show");

Datei anzeigen

@ -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 -> { 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); open(player, currentTntSimulator, currentTntGroup, simulatorElements, back);
})); }));
} }

Datei anzeigen

@ -22,21 +22,23 @@ package de.steamwar.bausystem.features.simulator.tnt;
import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.region.Region;
import de.steamwar.bausystem.shared.Pair; import de.steamwar.bausystem.shared.Pair;
import de.steamwar.entity.REntity; import de.steamwar.entity.REntity;
import de.steamwar.entity.REntityServer;
import de.steamwar.inventory.SWItem; import de.steamwar.inventory.SWItem;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.configuration.serialization.ConfigurationSerializable;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import yapion.hierarchy.types.YAPIONObject;
import java.util.*; import java.util.*;
public interface SimulatorElement { public interface SimulatorElement extends ConfigurationSerializable {
Map<SimulatorElement, Set<Runnable>> observer = new HashMap<>(); Map<SimulatorElement, Set<Runnable>> observer = new HashMap<>();
Map<Runnable, Runnable> closeObserver = new HashMap<>(); Map<Runnable, Runnable> closeObserver = new HashMap<>();
YAPIONObject toYAPION(); void init(REntityServer entityServer, TNTGroup tntGroup);
List<REntity> getEntities(); List<REntity> getEntities();
void getEntity(List<SimulatorElement> elements, REntity entity); void getEntity(List<SimulatorElement> elements, REntity entity);

Datei anzeigen

@ -20,8 +20,9 @@
package de.steamwar.bausystem.features.simulator.tnt; package de.steamwar.bausystem.features.simulator.tnt;
import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.config.ConfigField;
import de.steamwar.bausystem.config.YamlConfig;
import de.steamwar.bausystem.features.simulator.OrderUtils; 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.Region;
import de.steamwar.bausystem.region.flags.Flag; import de.steamwar.bausystem.region.flags.Flag;
import de.steamwar.bausystem.region.flags.flagvalues.FreezeMode; 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.Player;
import org.bukkit.entity.TNTPrimed; import org.bukkit.entity.TNTPrimed;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import yapion.hierarchy.types.YAPIONObject;
import java.util.*; import java.util.*;
@Getter @Getter
public class TNTElement implements SimulatorElement { public class TNTElement extends YamlConfig implements SimulatorElement {
private static final World WORLD = Bukkit.getWorlds().get(0); private static final World WORLD = Bukkit.getWorlds().get(0);
private final REntityServer entityServer; private REntityServer entityServer;
private RFallingBlockEntity entity; private RFallingBlockEntity entity;
TNTGroup tntGroup = null; @Setter
private TNTGroup tntGroup;
private final Vector position; @ConfigField
private Vector position;
@ConfigField
private int fuseTicks = 80; private int fuseTicks = 80;
@ConfigField
private int count = 1; private int count = 1;
@ConfigField
private int tickOffset = 0; private int tickOffset = 0;
@Setter @Setter
@ConfigField
private boolean xVelocity = false; private boolean xVelocity = false;
@Setter @Setter
@ConfigField
private boolean yVelocity = false; private boolean yVelocity = false;
@Setter @Setter
@ConfigField
private boolean zVelocity = false; private boolean zVelocity = false;
@ConfigField
private Material order = Material.REPEATER; private Material order = Material.REPEATER;
@ConfigField
private Material material = Material.TNT; private Material material = Material.TNT;
@ConfigField
private boolean disabled = false; private boolean disabled = false;
public TNTElement(Vector position, TNTGroup tntGroup, REntityServer entityServer) { public TNTElement(Vector position, TNTGroup tntGroup, REntityServer entityServer) {
this.entityServer = entityServer;
this.tntGroup = tntGroup;
this.position = position; this.position = position;
initEntity(); init(entityServer, tntGroup);
} }
public TNTElement(YAPIONObject yapionObject, TNTGroup tntGroup, REntityServer entityServer) { public TNTElement(Map<String, Object> map) {
this.entityServer = entityServer; super(map);
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();
} }
@Override @Override
public YAPIONObject toYAPION() { public void init(REntityServer entityServer, TNTGroup tntGroup) {
YAPIONObject yapionObject = new YAPIONObject(); this.entityServer = entityServer;
yapionObject.add("x", position.getX()); this.tntGroup = tntGroup;
yapionObject.add("y", position.getY()); this.entity = new RFallingBlockEntity(entityServer, getPosition().toLocation(WORLD), Material.TNT);
yapionObject.add("z", position.getZ()); this.entity.setNoGravity(true);
yapionObject.add("fuseTicks", fuseTicks); _updatePosition();
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;
} }
@Override @Override
@ -191,7 +173,7 @@ public class TNTElement implements SimulatorElement {
@Override @Override
public boolean locations(Map<Integer, Map<Integer, Set<Pair<Runnable, Integer>>>> result, Region region, Location radius) { public boolean locations(Map<Integer, Map<Integer, Set<Pair<Runnable, Integer>>>> result, Region region, Location radius) {
if (disabled) return false; if (disabled) return false;
Location location = getPosition().toLocation(SimulatorStorage.WORLD); Location location = getPosition().toLocation(WORLD);
if (region.isGlobal() && location.distanceSquared(radius) > 10000) { if (region.isGlobal() && location.distanceSquared(radius) > 10000) {
return false; return false;
} }
@ -199,14 +181,14 @@ public class TNTElement implements SimulatorElement {
return false; return false;
} }
Region thisRegion = Region.getRegion(location); Region thisRegion = Region.getRegion(location);
if (thisRegion.getFlagStorage().get(Flag.FREEZE) == FreezeMode.ACTIVE) { if (thisRegion.get(Flag.FREEZE) == FreezeMode.ACTIVE) {
return true; return true;
} }
result.computeIfAbsent(getTickOffset(), ignore -> new HashMap<>()) result.computeIfAbsent(getTickOffset(), ignore -> new HashMap<>())
.computeIfAbsent(OrderUtils.order(order), ignore -> new HashSet<>()) .computeIfAbsent(OrderUtils.order(order), ignore -> new HashSet<>())
.add(new Pair<>(() -> { .add(new Pair<>(() -> {
SimulatorStorage.WORLD.spawn(location, TNTPrimed.class, tntPrimed -> { WORLD.spawn(location, TNTPrimed.class, tntPrimed -> {
tntPrimed.setFuseTicks(fuseTicks); tntPrimed.setFuseTicks(fuseTicks);
if (!xVelocity) tntPrimed.setVelocity(tntPrimed.getVelocity().setX(0)); if (!xVelocity) tntPrimed.setVelocity(tntPrimed.getVelocity().setX(0));
if (!yVelocity) tntPrimed.setVelocity(tntPrimed.getVelocity().setY(0)); if (!yVelocity) tntPrimed.setVelocity(tntPrimed.getVelocity().setY(0));

Datei anzeigen

@ -20,6 +20,8 @@
package de.steamwar.bausystem.features.simulator.tnt; package de.steamwar.bausystem.features.simulator.tnt;
import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.config.ConfigField;
import de.steamwar.bausystem.config.YamlConfig;
import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.region.Region;
import de.steamwar.bausystem.shared.Pair; import de.steamwar.bausystem.shared.Pair;
import de.steamwar.entity.REntity; import de.steamwar.entity.REntity;
@ -30,8 +32,6 @@ import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import yapion.hierarchy.types.YAPIONArray;
import yapion.hierarchy.types.YAPIONObject;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -40,50 +40,36 @@ import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@Getter @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; private int tickOffset = 0;
@ConfigField
private Material material = Material.BARREL; private Material material = Material.BARREL;
@ConfigField
private boolean disabled = false; private boolean disabled = false;
private List<TNTElement> elements = new ArrayList<>(); @ConfigField
private final List<TNTElement> elements = new ArrayList<>();
public TNTGroup(Vector position) { public TNTGroup(Vector position) {
this.position = position; this.position = position;
} }
public TNTGroup(YAPIONObject yapionObject, REntityServer entityServer) { public TNTGroup(Map<String, Object> map) {
this.position = new Vector(yapionObject.getDoubleOrDefault("x", 0), yapionObject.getDoubleOrDefault("y", 0), yapionObject.getDoubleOrDefault("z", 0)); super(map);
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();
}
} }
@Override @Override
public YAPIONObject toYAPION() { public void init(REntityServer entityServer, TNTGroup tntGroup) {
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) { for(TNTElement element : elements) {
yapionArray.add(element.toYAPION()); element.init(entityServer, this);
} }
yapionObject.add("elements", yapionArray);
return yapionObject;
} }
public void add(TNTElement tntElement) { public void add(TNTElement tntElement) {
tntElement.tntGroup = this; tntElement.setTntGroup(this);
elements.add(tntElement); elements.add(tntElement);
} }

Datei anzeigen

@ -59,7 +59,7 @@ public class Laufbau {
editSession = WorldEditUtils.getEditSession(player); editSession = WorldEditUtils.getEditSession(player);
elements = BlockBoundingBox.elements.stream().filter(blockBoundingBox -> { elements = BlockBoundingBox.elements.stream().filter(blockBoundingBox -> {
return !LaufbauUtils.isDeactivated(player, blockBoundingBox); return !LaufbauUtils.get(player).isDeactivated(blockBoundingBox);
}).collect(Collectors.toList()); }).collect(Collectors.toList());
if (preferingBlastResistance) { if (preferingBlastResistance) {
elements.sort((o1, o2) -> { elements.sort((o1, o2) -> {

Datei anzeigen

@ -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) -> { 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) { if (entry.getValue().size() == 1) {
LaufbauUtils.toggle(p, entry.getValue().get(0)); LaufbauUtils.get(p).toggle(entry.getValue().get(0));
open(); open();
return; return;
} }
@ -80,13 +80,13 @@ public class LaufbauSettings {
lore = itemMeta.getLore(); lore = itemMeta.getLore();
} }
lore.add(""); 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); itemMeta.setLore(lore);
swItem.setItemMeta(itemMeta); swItem.setItemMeta(itemMeta);
list.add(new SWListInv.SWListEntry<>(swItem, bb)); 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) -> { 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); open(key);
}); });
inv.setItem(49, new SWItem(Material.ARROW, BauSystem.MESSAGE.parse("LAUFBAU_SETTINGS_GUI_BACK", p), clickType -> { 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 = itemMeta.getLore();
} }
lore.add(""); 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("");
lore.add(BauSystem.MESSAGE.parse("LAUFBAU_SETTINGS_TOGGLE", p)); lore.add(BauSystem.MESSAGE.parse("LAUFBAU_SETTINGS_TOGGLE", p));
itemMeta.setLore(lore); itemMeta.setLore(lore);
swItem.setItemMeta(itemMeta); swItem.setItemMeta(itemMeta);
return swItem; return swItem;
} else { } 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) { 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 -> {}); 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) { 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()) { if (count != blockBoundingBoxes.size()) {
blockBoundingBoxes.forEach(bb -> { blockBoundingBoxes.forEach(bb -> {
if (!LaufbauUtils.isDeactivated(p, bb)) { if (!LaufbauUtils.get(p).isDeactivated(bb)) {
LaufbauUtils.toggle(p, bb); LaufbauUtils.get(p).toggle(bb);
} }
}); });
} else { } else {
blockBoundingBoxes.forEach(bb -> { blockBoundingBoxes.forEach(bb -> {
LaufbauUtils.toggle(p, bb); LaufbauUtils.get(p).toggle(bb);
}); });
} }
} }

Datei anzeigen

@ -20,63 +20,28 @@
package de.steamwar.bausystem.features.slaves.laufbau; package de.steamwar.bausystem.features.slaves.laufbau;
import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.config.ConfigField;
import de.steamwar.bausystem.config.YamlConfig;
import de.steamwar.inventory.SWItem; import de.steamwar.inventory.SWItem;
import de.steamwar.linkage.Linked; import de.steamwar.linkage.Linked;
import de.steamwar.sql.UserConfig; import de.steamwar.sql.UserConfig;
import lombok.Cleanup;
import lombok.SneakyThrows; import lombok.SneakyThrows;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.inventory.meta.ItemMeta; 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.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
@Linked public class LaufbauUtils extends YamlConfig {
public class LaufbauUtils implements Listener {
private static Map<Player, YAPIONObject> yapionObjectMap = new HashMap<>(); private static final Map<Player, LaufbauUtils> utilsMap = new HashMap<>();
public static LaufbauUtils get(Player p) {
@EventHandler return utilsMap.computeIfAbsent(p, player -> new LaufbauUtils(fromUserConfig(player.getUniqueId(), "bausystem-laufbau")));
@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()));
} }
public static Cuboid pixelCuboid(double pixelX, double pixelY, double pixelZ, double pixelDX, double pixelDY, double pixelDZ) { 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) + "]"; return name + "[" + String.join(",", lore) + "]";
} }
@SneakyThrows @ConfigField
public static boolean isDeactivated(Player p, BlockBoundingBox bb) { private final List<String> deactivated = new ArrayList<>();
if (bb.getSwItem() == null) {
return false; public LaufbauUtils(ConfigurationSection config) {
} super(config);
String identifier = identifier(bb);
YAPIONObject yapionObject = yapionObjectMap.get(p);
if (yapionObject == null) {
return false;
}
return yapionObject.containsKey(identifier);
} }
@SneakyThrows @SneakyThrows
public static void toggle(Player p, BlockBoundingBox bb) { public boolean isDeactivated(BlockBoundingBox bb) {
if (bb.getSwItem() == null) { if (bb.getSwItem() == null) {
return false;
}
return deactivated.contains(identifier(bb));
}
@SneakyThrows
public void toggle(BlockBoundingBox bb) {
if (bb.getSwItem() == null)
return; return;
}
String identifier = identifier(bb); String identifier = identifier(bb);
YAPIONObject yapionObject = yapionObjectMap.get(p); if(deactivated.remove(identifier))
if (yapionObject == null) { return;
yapionObject = new YAPIONObject(); deactivated.add(identifier);
yapionObjectMap.put(p, yapionObject);
} }
if (yapionObject.containsKey(identifier)) {
yapionObject.remove(identifier); @Linked
} else { public static class LaufbauUtilListener implements Listener {
yapionObject.put(identifier, new YAPIONObject());
@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());
} }
} }
} }

Datei anzeigen

@ -35,8 +35,8 @@ public class SmartPlaceCommand extends SWCommand {
@Register(description = {"SMART_PLACE_HELP", "SMART_PLACE_INFO"}) @Register(description = {"SMART_PLACE_HELP", "SMART_PLACE_INFO"})
public void genericToggle(Player p) { public void genericToggle(Player p) {
boolean smartPlace = Config.getInstance().get(p).getPlainValueOrDefault("smartPlace", false); boolean smartPlace = Config.get(p).isSmartPlace();
Config.getInstance().get(p).put("smartPlace", !smartPlace); Config.get(p).setSmartPlace(!smartPlace);
if (!smartPlace) { if (!smartPlace) {
SWUtils.sendToActionbar(p, BauSystem.MESSAGE.parse("SMART_PLACE_ENABLE", p)); SWUtils.sendToActionbar(p, BauSystem.MESSAGE.parse("SMART_PLACE_ENABLE", p));
BauSystem.MESSAGE.send("SMART_PLACE_INFO", p); BauSystem.MESSAGE.send("SMART_PLACE_INFO", p);

Datei anzeigen

@ -46,7 +46,7 @@ public class SmartPlaceListener implements Listener {
@EventHandler @EventHandler
public void onBlockPlace(BlockPlaceEvent event) { 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(); if (smartPlaceBehaviours.isEmpty()) LinkageUtils.linkSmartPlace();
SmartPlaceBehaviour.SmartPlaceResult smartPlaceResult = SmartPlaceBehaviour.SmartPlaceResult.IGNORED; SmartPlaceBehaviour.SmartPlaceResult smartPlaceResult = SmartPlaceBehaviour.SmartPlaceResult.IGNORED;
for (SmartPlaceBehaviour smartPlaceBehaviour : smartPlaceBehaviours) { for (SmartPlaceBehaviour smartPlaceBehaviour : smartPlaceBehaviours) {
@ -61,7 +61,7 @@ public class SmartPlaceListener implements Listener {
@EventHandler @EventHandler
public void onPlayerInteract(PlayerInteractEvent event) { 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 (smartPlaceBehaviours.isEmpty()) LinkageUtils.linkSmartPlace();
if (event.getAction() != Action.RIGHT_CLICK_BLOCK) return; if (event.getAction() != Action.RIGHT_CLICK_BLOCK) return;
if (event.getPlayer().getGameMode() == GameMode.SPECTATOR) return; if (event.getPlayer().getGameMode() == GameMode.SPECTATOR) return;

Datei anzeigen

@ -34,14 +34,9 @@ import net.md_5.bungee.api.chat.ClickEvent;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import yapion.hierarchy.output.StringOutput;
import yapion.hierarchy.types.YAPIONObject;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.*;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@Linked @Linked
public class SkinCommand extends SWCommand { public class SkinCommand extends SWCommand {
@ -98,17 +93,15 @@ public class SkinCommand extends SWCommand {
Region.copy(region.getMinPointTestblock(), region.getMaxPointTestblock(), testblockFile); Region.copy(region.getMinPointTestblock(), region.getMaxPointTestblock(), testblockFile);
} }
YAPIONObject yapionObject = new YAPIONObject(); Prototype.Skin skin = new Prototype.Skin(Collections.emptyMap());
yapionObject.add("name", name);
if (!creator.equals("public")) { if (!creator.equals("public")) {
yapionObject.add("creator", creator); skin.setCreator(creator);
} }
yapionObject.add("type", typeKuerzel); skin.setSchematic(arenaFile.getPath());
yapionObject.add("schematic", arenaFile.getPath());
if (testblockFile != null) { 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") @Register("boundary")

Datei anzeigen

@ -34,18 +34,15 @@ public class BlockCounter {
public final Map<Region, BlockCount> blockCountMap = new HashMap<>(); public final Map<Region, BlockCount> blockCountMap = new HashMap<>();
public boolean isActive(final Player p) { public boolean isActive(final Player p) {
if (!Config.getInstance().get(p).containsKey("blockCounter")) { return Config.get(p).isBlockCounter();
return false;
}
return Config.getInstance().get(p).getPlainValue("blockCounter");
} }
public void enable(final Player p) { public void enable(final Player p) {
Config.getInstance().get(p).put("blockCounter", true); Config.get(p).setBlockCounter(true);
} }
public void disable(final Player p) { 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) { public String getMessage(Player player, int count, int tntCount, long tick, long lastTick) {

Datei anzeigen

@ -33,9 +33,7 @@ import org.bukkit.entity.Player;
import org.bukkit.entity.TNTPrimed; import org.bukkit.entity.TNTPrimed;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scheduler.BukkitTask; import org.bukkit.scheduler.BukkitTask;
import yapion.utils.ReflectionsUtils;
import java.lang.reflect.Field;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
@ -45,7 +43,7 @@ import java.util.stream.Collectors;
@UtilityClass @UtilityClass
public class FreezeUtils { public class FreezeUtils {
private static final Field field; private static final Reflection.FieldAccessor<Boolean> field;
public static final boolean freezeEnabled; public static final boolean freezeEnabled;
private static final Reflection.MethodInvoker getWorldHandle = Reflection.getTypedMethod(Reflection.getClass("{obc}.CraftWorld"), "getHandle", null); 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; private static final World world;
static { static {
field = ReflectionsUtils.getField(Reflection.getClass("{nms.server.level}.WorldServer"), "freezed"); Reflection.FieldAccessor<Boolean> f = null;
if (field != null) field.setAccessible(true); try {
f = Reflection.getField("{nms.server.level}.WorldServer", "freezed", boolean.class);
} catch (IllegalArgumentException ignored) {}
field = f;
freezeEnabled = field != null; freezeEnabled = field != null;
world = Bukkit.getWorlds().get(0); world = Bukkit.getWorlds().get(0);
} }
@ -76,13 +77,9 @@ public class FreezeUtils {
private void setFreeze(World world, boolean state) { private void setFreeze(World world, boolean state) {
if (freezeEnabled) { if (freezeEnabled) {
try {
field.set(getWorldHandle.invoke(world), state); field.set(getWorldHandle.invoke(world), state);
cacheEntityPackets(state); cacheEntityPackets(state);
frozen = state; frozen = state;
} catch (IllegalAccessException e) {
// Ignored;
}
} }
} }

Datei anzeigen

@ -30,7 +30,6 @@ import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType; import org.bukkit.potion.PotionEffectType;
import yapion.hierarchy.types.YAPIONObject;
@Linked @Linked
public class NightVisionCommand extends SWCommand implements Listener { public class NightVisionCommand extends SWCommand implements Listener {
@ -41,15 +40,15 @@ public class NightVisionCommand extends SWCommand implements Listener {
@Register(description = "NIGHT_VISION_HELP") @Register(description = "NIGHT_VISION_HELP")
public void genericCommand(Player p) { public void genericCommand(Player p) {
YAPIONObject yapionObject = Config.getInstance().get(p); Config config = Config.get(p);
boolean value = !yapionObject.getBooleanOrDefault("nightvision", false); config.setNightvision(!config.isNightvision());
yapionObject.put("nightvision", value); config.save();
setNightVision(p, value); setNightVision(p, config.isNightvision());
} }
@EventHandler @EventHandler
public void onPlayerJoin(PlayerJoinEvent event) { 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) { private void setNightVision(Player p, boolean value) {

Datei anzeigen

@ -19,88 +19,70 @@
package de.steamwar.bausystem.features.warp; 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 de.steamwar.bausystem.worlddata.WorldData;
import lombok.Getter; 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.entity.Player;
import org.bukkit.event.player.PlayerTeleportEvent; 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 @Getter
public class Warp { public class Warp extends YamlConfig {
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);
}
@ConfigField
private String name; private String name;
@ConfigField
private Location location; private Location location;
@ConfigField
private Material mat; private Material mat;
private Warp(String name) { public Warp(String name, Location location, Material mat) {
this.name = name; this.name = name;
this.location = location;
this.mat = mat;
WorldData.getInstance().addWarp(this);
} }
public Warp(String name, Player player) { public Warp(String name, Player player) {
this.name = name; this.name = name;
this.location = player.getLocation(); this.location = player.getLocation();
this.mat = Material.COMPASS; this.mat = Material.COMPASS;
warpMap.put(name, this);
WorldData.getInstance().addWarp(this);
} }
public Warp(String name, YAPIONObject object) { public Warp(Map<String, Object> map) {
this.name = name; super(map);
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 static Set<String> getWarpNames() { public static Set<String> getWarpNames() {
return warpMap.keySet(); return WorldData.getInstance().getWarps().keySet();
} }
public static List<Warp> getWarps() { public static List<Warp> getWarps() {
return new ArrayList<>(warpMap.values()); return new ArrayList<>(WorldData.getInstance().getWarps().values());
} }
public static Warp getWarp(String name) { public static Warp getWarp(String name) {
return warpMap.get(name); return WorldData.getInstance().getWarps().get(name);
} }
public void setMat(Material mat) { public void setMat(Material mat) {
this.mat = mat; this.mat = mat;
} }
public void setLocation(Location location) {
this.location = location;
}
public void delete() { public void delete() {
warpMap.remove(name); WorldData.getInstance().getWarps().remove(name);
WorldData.getWarpData().remove(name);
} }
public void teleport(Player player) { public void teleport(Player player) {

Datei anzeigen

@ -22,26 +22,22 @@ package de.steamwar.bausystem.features.warp;
import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.Permission;
import de.steamwar.bausystem.utils.ListChatView; import de.steamwar.bausystem.utils.ListChatView;
import de.steamwar.bausystem.worlddata.WorldData;
import de.steamwar.command.SWCommand; import de.steamwar.command.SWCommand;
import de.steamwar.command.SWCommandUtils; import de.steamwar.command.SWCommandUtils;
import de.steamwar.command.TypeMapper; import de.steamwar.command.TypeMapper;
import de.steamwar.command.TypeValidator; import de.steamwar.command.TypeValidator;
import de.steamwar.linkage.Linked; 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.ChatColor;
import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.ComponentBuilder; import net.md_5.bungee.api.chat.ComponentBuilder;
import net.md_5.bungee.api.chat.HoverEvent; import net.md_5.bungee.api.chat.HoverEvent;
import net.md_5.bungee.api.chat.TextComponent; import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import yapion.hierarchy.types.YAPIONObject;
import java.util.ArrayList; import java.util.ArrayList;
@Linked @Linked
public class WarpCommand extends SWCommand implements Disable, Enable { public class WarpCommand extends SWCommand {
private static final String[] FORBIDDEN_NAMES = new String[]{ private static final String[] FORBIDDEN_NAMES = new String[]{
"add", "create", "delete", "list", "info", "gui" "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)); 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());
}
}
} }

Datei anzeigen

@ -19,64 +19,45 @@
package de.steamwar.bausystem.region; package de.steamwar.bausystem.region;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.region.flags.Flag; import de.steamwar.bausystem.region.flags.Flag;
import de.steamwar.bausystem.region.tags.Tag; import de.steamwar.bausystem.region.tags.Tag;
import yapion.hierarchy.types.YAPIONObject; import org.bukkit.configuration.serialization.ConfigurationSerializable;
import java.util.EnumMap; import java.util.*;
import java.util.HashSet; import java.util.logging.Level;
import java.util.Map;
import java.util.Set;
/** /**
* Tags and Flags are not allowed to have overlaping names. * Tags and Flags are not allowed to have overlaping names.
*/ */
public class FlagStorage { public class FlagStorage implements ConfigurationSerializable {
public static FlagStorage createStorage(YAPIONObject yapionObject) { private final Map<Flag, Flag.Value<?>> flags = new EnumMap<>(Flag.class);
FlagStorage flagStorage = new FlagStorage(); private final Set<Tag> tags = new HashSet<>();
for (final Flag flag : Flag.getFlags()) {
try {
String s = yapionObject.getPlainValue(flag.name());
flagStorage.set(flag, flag.getFlagValueOf(s));
} catch (Exception e) {
flagStorage.set(flag, flag.getDefaultValue());
}
}
for (final Tag tag : Tag.values()) {
if (yapionObject.containsKey(tag.name())) {
flagStorage.set(tag);
}
}
return flagStorage;
}
public static YAPIONObject toYAPION(FlagStorage flagStorage) {
YAPIONObject yapionObject = new YAPIONObject();
for (final Flag flag : Flag.getFlags()) {
if (flag.getDefaultValue() == flagStorage.flags.getOrDefault(flag, flag.getDefaultValue())) {
yapionObject.remove(flag.name());
} else {
yapionObject.add(flag.name(), flagStorage.get(flag).getValue().name());
}
}
for (Tag tag : Tag.values()) {
if (flagStorage.tagSet.contains(tag)) {
yapionObject.add(tag.name(), "");
} else {
yapionObject.remove(tag.name());
}
}
return yapionObject;
}
protected Map<Flag, Flag.Value<?>> flags;
protected Set<Tag> tagSet;
public FlagStorage() { public FlagStorage() {
flags = new EnumMap<>(Flag.class); for (final Flag flag : Flag.getFlags()) {
tagSet = new HashSet<>(); flags.put(flag, flag.getDefaultValue());
readKeys(); }
}
public FlagStorage(Map<String, Object> map) {
this();
for(Map.Entry<String, Object> entry : map.entrySet()) {
try {
Flag flag = Flag.valueOf(entry.getKey());
flags.put(flag, flag.getFlagValueOf((String) entry.getValue()));
continue;
} catch (IllegalArgumentException ignored) {}
try {
tags.add(Tag.valueOf(entry.getKey()));
continue;
} catch (IllegalArgumentException ignored) {}
BauSystem.getInstance().getLogger().log(Level.INFO, "Unknown region flag ignored: " + entry.getKey());
}
} }
public boolean set(final Flag flagType, final Flag.Value<?> value) { public boolean set(final Flag flagType, final Flag.Value<?> value) {
@ -88,20 +69,22 @@ public class FlagStorage {
} }
public boolean set(final Tag tag) { public boolean set(final Tag tag) {
return tagSet.add(tag); return tags.add(tag);
} }
public boolean remove(final Tag tag) { public boolean remove(final Tag tag) {
return tagSet.remove(tag); return tags.remove(tag);
} }
public boolean is(final Tag tag) { public boolean is(final Tag tag) {
return tagSet.contains(tag); return tags.contains(tag);
} }
private void readKeys() { @Override
for (final Flag flag : Flag.getFlags()) { public Map<String, Object> serialize() {
flags.put(flag, flag.getDefaultValue()); Map<String, Object> result = new HashMap<>();
} flags.forEach((flag, value) -> result.put(flag.name(), value.getName()));
tags.forEach(tag -> result.put(tag.name(), null));
return result;
} }
} }

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

@ -19,10 +19,11 @@
package de.steamwar.bausystem.region; package de.steamwar.bausystem.region;
import lombok.AllArgsConstructor; import de.steamwar.bausystem.config.ConfigField;
import de.steamwar.bausystem.config.YamlConfig;
import lombok.Getter; import lombok.Getter;
import yapion.hierarchy.types.YAPIONObject; import lombok.Setter;
import yapion.hierarchy.types.YAPIONType; import org.bukkit.configuration.ConfigurationSection;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
@ -31,7 +32,12 @@ import java.util.List;
import java.util.Map; import java.util.Map;
@Getter @Getter
public class Prototype { public class Prototype extends YamlConfig {
static {
register(YamlConfig.class);
register(SubPrototype.class);
}
static final Map<String, Prototype> PROTOTYPE_MAP = new HashMap<>(); static final Map<String, Prototype> PROTOTYPE_MAP = new HashMap<>();
@ -47,180 +53,132 @@ public class Prototype {
return new ArrayList<>(PROTOTYPE_MAP.values()); return new ArrayList<>(PROTOTYPE_MAP.values());
} }
@AllArgsConstructor
@Getter @Getter
public static class Skin { @Setter
private final String name; public static class Skin extends YamlConfig {
private final String creator; // Nullable @ConfigField
private String creator;
@ConfigField(required = true)
private String schematic;
private final File schematicFile; private final File schematicFile;
private final File testblockSchematicFile; // Nullable
private final File buildSchematicFile; // Nullable @ConfigField
private String testblockSchematic;
private final File testblockSchematicFile;
@ConfigField
private String buildSchematic;
private final File buildSchematicFile;
@ConfigField
private boolean disabled;
public Skin(Map<String, Object> map) {
super(map);
schematicFile = new File(schematic);
testblockSchematicFile = testblockSchematic != null ? new File(testblockSchematic) : null;
buildSchematicFile = buildSchematic != null ? new File(buildSchematic) : null;
}
} }
private final String name; private final String name;
private final String displayName; @ConfigField
private final String defaultSkin; private String displayName;
private final Map<String, Skin> skinMap = new HashMap<>(); @ConfigField
private String defaultSkin;
@ConfigField(required = true)
private Map<String, Skin> skins;
private final int sizeX; @ConfigField(required = true)
private final int sizeY; private int sizeX;
private final int sizeZ; @ConfigField(required = true)
private int sizeY;
@ConfigField(required = true)
private int sizeZ;
private final int floorOffset; @ConfigField
private final int waterOffset; private int floorOffset;
@ConfigField
private int waterOffset;
private final SubPrototype testblock; // Nullable @ConfigField
private final SubPrototype build; // Nullable private SubPrototype testblock;
@ConfigField
private SubPrototype build;
private final int copyPointOffsetX; @ConfigField
private final int copyPointOffsetY; private int copyPointOffsetX;
private final int copyPointOffsetZ; @ConfigField
private int copyPointOffsetY;
@ConfigField
private int copyPointOffsetZ;
public Prototype(String name, YAPIONObject yapionObject) { public Prototype(ConfigurationSection config) {
this.name = name; super(config);
displayName = yapionObject.getPlainValueOrDefault("displayName", name); name = config.getName();
sizeX = yapionObject.getPlainValue("sizeX"); if(displayName == null)
sizeY = yapionObject.getPlainValue("sizeY"); displayName = name;
sizeZ = yapionObject.getPlainValue("sizeZ"); if(defaultSkin == null)
defaultSkin = displayName;
copyPointOffsetX = yapionObject.getPlainValueOrDefault("copyOffsetX", 0); skins.entrySet().removeIf(entry -> entry.getValue().isDisabled());
copyPointOffsetY = yapionObject.getPlainValueOrDefault("copyOffsetY", 0);
copyPointOffsetZ = yapionObject.getPlainValueOrDefault("copyOffsetZ", 0);
floorOffset = yapionObject.getPlainValueOrDefault("floorOffset", 0);
waterOffset = yapionObject.getPlainValueOrDefault("waterOffset", 0);
if (yapionObject.containsKey("testblock", YAPIONType.OBJECT)) {
testblock = new SubPrototype(yapionObject.getObject("testblock"));
} else {
testblock = null;
}
if (yapionObject.containsKey("build", YAPIONType.OBJECT)) {
build = new SubPrototype(yapionObject.getObject("build"));
} else {
build = null;
}
this.defaultSkin = yapionObject.getPlainValueOrDefault("defaultSkin", displayName);
if (yapionObject.containsKey("skins", YAPIONType.ARRAY)) {
yapionObject.getArray("skins").forEach(yapionAnyType -> {
YAPIONObject skinObject = (YAPIONObject) yapionAnyType;
String skinName = skinObject.getPlainValue("name");
String skinCreator = skinObject.getPlainValueOrDefault("creator", null);
String schematicFileName = skinObject.getPlainValue("schematic");
String testblockSchematicFileName = skinObject.getPlainValueOrDefault("testblockSchematic", null);
String buildSchematicFileName = skinObject.getPlainValueOrDefault("buildSchematic", null);
boolean disabled = skinObject.getPlainValueOrDefault("disabled", false);
if (disabled) {
return;
}
skinMap.put(skinName, new Skin(skinName, skinCreator, new File(schematicFileName), testblockSchematicFileName == null ? null : new File(testblockSchematicFileName), buildSchematicFileName == null ? null : new File(buildSchematicFileName)));
});
} else {
String s = yapionObject.getPlainValueOrDefault("schematic", null);
File schematicFile = s == null ? null : new File(s);
File testblockSchematicFile = testblock != null ? testblock.getSchematicFile() : null;
File buildSchematicFile = build != null ? build.getSchematicFile() : null;
skinMap.put(displayName, new Skin(defaultSkin, null, schematicFile, testblockSchematicFile, buildSchematicFile));
}
if (PROTOTYPE_MAP.containsKey(name)) {
Region.getRegion(PROTOTYPE_MAP.remove(name)).forEach(region -> {
region._setPrototype(this);
});
}
PROTOTYPE_MAP.put(name, this); PROTOTYPE_MAP.put(name, this);
} }
@Getter @Getter
public static class SubPrototype { public static class SubPrototype extends YamlConfig {
private final int offsetX; @ConfigField
private final int offsetY; private int offsetX;
private final int offsetZ; @ConfigField
private int offsetY;
@ConfigField
private int offsetZ;
private final int sizeX; @ConfigField(required = true)
private final int sizeY; private int sizeX;
private final int sizeZ; @ConfigField(required = true)
private int sizeY;
@ConfigField(required = true)
private int sizeZ;
private final File schematicFile; // Nullable @ConfigField
private String schematic;
private final File schematicFile;
private final int extensionNegativeX; @ConfigField
private final int extensionPositiveX; private int extensionNegativeX;
private final int extensionNegativeY; @ConfigField
private final int extensionPositiveY; private int extensionPositiveX;
private final int extensionNegativeZ; @ConfigField
private final int extensionPositiveZ; private int extensionNegativeY;
@ConfigField
private boolean extensionRegistered; private int extensionPositiveY;
@ConfigField
private int extensionNegativeZ;
@ConfigField
private int extensionPositiveZ;
private final boolean extensionRegistered;
@ConfigField
private int copyOffsetX;
@ConfigField
private int copyOffsetY;
@ConfigField
private int copyOffsetZ;
private final boolean hasCopyPoint; private final boolean hasCopyPoint;
private final int copyOffsetX;
private final int copyOffsetY;
private final int copyOffsetZ;
private SubPrototype(YAPIONObject yapionObject) { public SubPrototype(Map<String, Object> map) {
offsetX = yapionObject.getPlainValueOrDefault("offsetX", 0); super(map);
offsetY = yapionObject.getPlainValueOrDefault("offsetY", 0);
offsetZ = yapionObject.getPlainValueOrDefault("offsetZ", 0);
sizeX = yapionObject.getPlainValue("sizeX"); schematicFile = schematic != null ? new File(schematic) : null;
sizeY = yapionObject.getPlainValue("sizeY");
sizeZ = yapionObject.getPlainValue("sizeZ");
if (yapionObject.containsKey("schematic", String.class)) {
schematicFile = new File(yapionObject.getValue("schematic", String.class).get());
} else {
schematicFile = null;
}
if (yapionObject.containsKey("extensionX", Integer.class)) {
extensionNegativeX = yapionObject.getPlainValue("extensionX");
extensionPositiveX = yapionObject.getPlainValue("extensionX");
} else {
extensionNegativeX = yapionObject.getPlainValueOrDefault("extensionNegativeX", 0);
extensionPositiveX = yapionObject.getPlainValueOrDefault("extensionPositiveX", 0);
}
if (yapionObject.containsKey("extensionY", Integer.class)) {
extensionNegativeY = yapionObject.getPlainValue("extensionY");
extensionPositiveY = yapionObject.getPlainValue("extensionY");
} else {
extensionNegativeY = yapionObject.getPlainValueOrDefault("extensionNegativeY", 0);
extensionPositiveY = yapionObject.getPlainValueOrDefault("extensionPositiveY", 0);
}
if (yapionObject.containsKey("extensionZ", Integer.class)) {
extensionNegativeZ = yapionObject.getPlainValue("extensionZ");
extensionPositiveZ = yapionObject.getPlainValue("extensionZ");
} else {
extensionNegativeZ = yapionObject.getPlainValueOrDefault("extensionNegativeZ", 0);
extensionPositiveZ = yapionObject.getPlainValueOrDefault("extensionPositiveZ", 0);
}
extensionRegistered = extensionNegativeX != 0 || extensionPositiveX != 0 || extensionNegativeY != 0 || extensionPositiveY != 0 || extensionNegativeZ != 0 || extensionPositiveZ != 0; extensionRegistered = extensionNegativeX != 0 || extensionPositiveX != 0 || extensionNegativeY != 0 || extensionPositiveY != 0 || extensionNegativeZ != 0 || extensionPositiveZ != 0;
copyOffsetX = yapionObject.getPlainValueOrDefault("copyOffsetX", 0); hasCopyPoint = map.containsKey("copyOffsetX") || map.containsKey("copyOffsetY") || map.containsKey("copyOffsetZ");
copyOffsetY = yapionObject.getPlainValueOrDefault("copyOffsetY", 0);
copyOffsetZ = yapionObject.getPlainValueOrDefault("copyOffsetZ", 0);
hasCopyPoint = yapionObject.containsKey("copyOffsetX") || yapionObject.containsKey("copyOffsetY") || yapionObject.containsKey("copyOffsetZ");
} }
} }
public static Region generateRegion(String name, YAPIONObject regionConfig, YAPIONObject regionData) {
Prototype prototype;
if (regionData.containsKey("prototype", String.class)) {
prototype = PROTOTYPE_MAP.get(regionData.getPlainValue("prototype"));
} else {
prototype = PROTOTYPE_MAP.get(regionConfig.getPlainValue("prototype"));
}
FlagStorage flagStorage;
if (regionData.containsKey("flagStorage", YAPIONType.OBJECT)) {
flagStorage = FlagStorage.createStorage(regionData.getObject("flagStorage"));
} else {
flagStorage = new FlagStorage();
}
return new Region(name, prototype, regionConfig, flagStorage, regionData);
}
} }

Datei anzeigen

@ -24,6 +24,8 @@ import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.bukkit.BukkitWorld; import com.sk89q.worldedit.bukkit.BukkitWorld;
import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.extent.clipboard.Clipboard;
import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.config.ConfigField;
import de.steamwar.bausystem.config.YamlConfig;
import de.steamwar.bausystem.region.flags.Flag; import de.steamwar.bausystem.region.flags.Flag;
import de.steamwar.bausystem.region.flags.flagvalues.ColorMode; import de.steamwar.bausystem.region.flags.flagvalues.ColorMode;
import de.steamwar.bausystem.region.flags.flagvalues.TNTMode; import de.steamwar.bausystem.region.flags.flagvalues.TNTMode;
@ -32,6 +34,7 @@ import de.steamwar.bausystem.region.utils.RegionExtensionType;
import de.steamwar.bausystem.region.utils.RegionType; import de.steamwar.bausystem.region.utils.RegionType;
import de.steamwar.bausystem.shared.SizedStack; import de.steamwar.bausystem.shared.SizedStack;
import de.steamwar.bausystem.utils.FlatteningWrapper; import de.steamwar.bausystem.utils.FlatteningWrapper;
import de.steamwar.bausystem.worlddata.WorldData;
import de.steamwar.core.Core; import de.steamwar.core.Core;
import de.steamwar.sql.SchematicData; import de.steamwar.sql.SchematicData;
import de.steamwar.sql.SchematicNode; import de.steamwar.sql.SchematicNode;
@ -40,9 +43,7 @@ import lombok.Getter;
import lombok.NonNull; import lombok.NonNull;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import yapion.hierarchy.types.YAPIONObject; import org.bukkit.configuration.ConfigurationSection;
import yapion.hierarchy.types.YAPIONType;
import yapion.hierarchy.types.YAPIONValue;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@ -56,7 +57,7 @@ import java.util.stream.Collectors;
import static de.steamwar.bausystem.region.RegionUtils.paste; import static de.steamwar.bausystem.region.RegionUtils.paste;
@Getter @Getter
public class Region { public class Region extends YamlConfig {
@Getter @Getter
private static final Map<String, Region> REGION_MAP = new HashMap<>(); private static final Map<String, Region> REGION_MAP = new HashMap<>();
@ -80,13 +81,16 @@ public class Region {
REGION_MAP.values().forEach(region -> region.set(flagType, value)); REGION_MAP.values().forEach(region -> region.set(flagType, value));
} }
YAPIONObject regionData; private final String name;
@ConfigField
private String prototypeName;
private final Prototype prototype;
private String name; @ConfigField
private Prototype prototype; private String linkedRegionName;
private Set<String> prototypes; private Region linkedRegion;
private String skin;
@ConfigField
private Point minPoint; private Point minPoint;
private Point maxPoint; private Point maxPoint;
@ -108,10 +112,7 @@ public class Region {
private Point copyPoint; // Nullable private Point copyPoint; // Nullable
private Point testBlockPoint; // Nullable private Point testBlockPoint; // Nullable
private String linkedRegionName = null; // Nullable private final WorldData.RegionConfig config;
private Region linkedRegion = null; // Nullable
private FlagStorage flagStorage;
@Getter(AccessLevel.PRIVATE) @Getter(AccessLevel.PRIVATE)
private SizedStack<EditSession> undoSessions; private SizedStack<EditSession> undoSessions;
@ -119,104 +120,62 @@ public class Region {
@Getter(AccessLevel.PRIVATE) @Getter(AccessLevel.PRIVATE)
private SizedStack<EditSession> redoSessions; private SizedStack<EditSession> redoSessions;
public Region(String name, Prototype prototype, YAPIONObject regionConfig, FlagStorage flagStorage, YAPIONObject regionData) { public Region(ConfigurationSection regionConfig, WorldData.RegionConfig config) {
this.name = name; super(regionConfig);
this.regionData = regionData; name = regionConfig.getName();
if (prototype != null) { prototype = prototypeName != null ? Prototype.getByName(prototypeName) : null;
REGION_MAP.put(name, this);
}
linkedRegionName = regionConfig.getPlainValueOrDefault("optionsLinkedWith", null); this.config = config;
prototypes = new HashSet<>();
if (regionConfig.containsKey("prototypes", YAPIONType.ARRAY)) {
regionConfig.getArray("prototypes").forEach(yapionAnyType -> {
if (yapionAnyType instanceof YAPIONValue) {
prototypes.add(((YAPIONValue<String>) yapionAnyType).get());
}
});
}
if (regionConfig.containsKey("prototype")) {
prototypes.add(regionConfig.getPlainValue("prototype"));
}
this.flagStorage = flagStorage;
Point point = null;
if (regionConfig.containsKey("minX", Integer.class) && regionConfig.containsKey("minY", Integer.class) && regionConfig.containsKey("minZ", Integer.class)) {
point = new Point(regionConfig.getPlainValue("minX"), regionConfig.getPlainValue("minY"), regionConfig.getPlainValue("minZ"));
}
if (prototype != null && prototypes.contains(prototype.getName())) {
generatePrototypeData(prototype, point);
} else if (regionConfig.containsKey("prototype")) {
generatePrototypeData(Prototype.getByName(regionConfig.getPlainValue("prototype")), point);
}
if (prototype != null) {
skin = regionData.getPlainValueOrDefault("skin", prototype.getDefaultSkin());
if (!prototype.getSkinMap().containsKey(skin)) {
skin = prototype.getDefaultSkin();
}
}
regionData.add("skin", skin);
if (!hasType(RegionType.BUILD) || !hasType(RegionType.TESTBLOCK)) { if (!hasType(RegionType.BUILD) || !hasType(RegionType.TESTBLOCK)) {
flagStorage.set(Flag.TNT, TNTMode.DENY); config.getFlagStorage().set(Flag.TNT, TNTMode.DENY);
}
} }
private void generatePrototypeData(Prototype prototype, Point point) { if(prototype == null)
if (prototype == null) {
return; return;
if (!prototype.getSkins().containsKey(config.getSkin())) {
config.setSkin(prototype.getDefaultSkin());
} }
this.prototype = prototype; maxPoint = minPoint.add(prototype.getSizeX() - 1, prototype.getSizeY() - 1, prototype.getSizeZ() - 1);
this.skin = prototype.getDefaultSkin();
this.minPoint = point;
this.maxPoint = point.add(prototype.getSizeX() - 1, prototype.getSizeY() - 1, prototype.getSizeZ() - 1);
if (prototype.getTestblock() != null) { if (prototype.getTestblock() != null) {
this.minPointTestblock = point.add(prototype.getTestblock().getOffsetX(), prototype.getTestblock().getOffsetY(), prototype.getTestblock().getOffsetZ()); minPointTestblock = minPoint.add(prototype.getTestblock().getOffsetX(), prototype.getTestblock().getOffsetY(), prototype.getTestblock().getOffsetZ());
this.maxPointTestblock = this.minPointTestblock.add(prototype.getTestblock().getSizeX() - 1, prototype.getTestblock().getSizeY() - 1, prototype.getTestblock().getSizeZ() - 1); maxPointTestblock = minPointTestblock.add(prototype.getTestblock().getSizeX() - 1, prototype.getTestblock().getSizeY() - 1, prototype.getTestblock().getSizeZ() - 1);
this.minPointTestblockExtension = this.minPointTestblock.subtract(prototype.getTestblock().getExtensionNegativeX(), prototype.getTestblock().getExtensionNegativeY(), prototype.getTestblock().getExtensionNegativeZ()); minPointTestblockExtension = minPointTestblock.subtract(prototype.getTestblock().getExtensionNegativeX(), prototype.getTestblock().getExtensionNegativeY(), prototype.getTestblock().getExtensionNegativeZ());
this.maxPointTestblockExtension = this.maxPointTestblock.add(prototype.getTestblock().getExtensionPositiveX(), prototype.getTestblock().getExtensionPositiveY(), prototype.getTestblock().getExtensionPositiveZ()); maxPointTestblockExtension = maxPointTestblock.add(prototype.getTestblock().getExtensionPositiveX(), prototype.getTestblock().getExtensionPositiveY(), prototype.getTestblock().getExtensionPositiveZ());
if (prototype.getTestblock().getCopyOffsetX() != 0 || prototype.getTestblock().getCopyOffsetY() != 0 || prototype.getTestblock().getCopyOffsetZ() != 0) { if (prototype.getTestblock().getCopyOffsetX() != 0 || prototype.getTestblock().getCopyOffsetY() != 0 || prototype.getTestblock().getCopyOffsetZ() != 0) {
this.testBlockPoint = this.minPointTestblock.add(prototype.getTestblock().getCopyOffsetX(), prototype.getTestblock().getCopyOffsetY(), prototype.getTestblock().getCopyOffsetZ()); testBlockPoint = minPointTestblock.add(prototype.getTestblock().getCopyOffsetX(), prototype.getTestblock().getCopyOffsetY(), prototype.getTestblock().getCopyOffsetZ());
} else { } else {
this.testBlockPoint = this.minPointTestblock.add(prototype.getTestblock().getSizeX() / 2, 0, -1); testBlockPoint = minPointTestblock.add(prototype.getTestblock().getSizeX() / 2, 0, -1);
} }
} }
if (prototype.getBuild() != null) { if (prototype.getBuild() != null) {
this.minPointBuild = point.add(prototype.getBuild().getOffsetX(), prototype.getBuild().getOffsetY(), prototype.getBuild().getOffsetZ()); minPointBuild = minPoint.add(prototype.getBuild().getOffsetX(), prototype.getBuild().getOffsetY(), prototype.getBuild().getOffsetZ());
this.maxPointBuild = this.minPointBuild.add(prototype.getBuild().getSizeX() - 1, prototype.getBuild().getSizeY() - 1, prototype.getBuild().getSizeZ() - 1); maxPointBuild = minPointBuild.add(prototype.getBuild().getSizeX() - 1, prototype.getBuild().getSizeY() - 1, prototype.getBuild().getSizeZ() - 1);
this.minPointBuildExtension = this.minPointBuild.subtract(prototype.getBuild().getExtensionNegativeX(), prototype.getBuild().getExtensionNegativeY(), prototype.getBuild().getExtensionNegativeZ()); minPointBuildExtension = minPointBuild.subtract(prototype.getBuild().getExtensionNegativeX(), prototype.getBuild().getExtensionNegativeY(), prototype.getBuild().getExtensionNegativeZ());
this.maxPointBuildExtension = this.maxPointBuild.add(prototype.getBuild().getExtensionPositiveX(), prototype.getBuild().getExtensionPositiveY(), prototype.getBuild().getExtensionPositiveZ()); maxPointBuildExtension = maxPointBuild.add(prototype.getBuild().getExtensionPositiveX(), prototype.getBuild().getExtensionPositiveY(), prototype.getBuild().getExtensionPositiveZ());
if (!prototype.getBuild().isHasCopyPoint() && (prototype.getCopyPointOffsetX() != 0 || prototype.getCopyPointOffsetY() != 0 || prototype.getCopyPointOffsetZ() != 0)) { if (!prototype.getBuild().isHasCopyPoint() && (prototype.getCopyPointOffsetX() != 0 || prototype.getCopyPointOffsetY() != 0 || prototype.getCopyPointOffsetZ() != 0)) {
this.copyPoint = minPoint.add(prototype.getCopyPointOffsetX(), prototype.getCopyPointOffsetY(), prototype.getCopyPointOffsetZ()); copyPoint = this.minPoint.add(prototype.getCopyPointOffsetX(), prototype.getCopyPointOffsetY(), prototype.getCopyPointOffsetZ());
} else if (prototype.getBuild().getCopyOffsetX() != 0 || prototype.getBuild().getCopyOffsetY() != 0 || prototype.getBuild().getCopyOffsetZ() != 0) { } else if (prototype.getBuild().getCopyOffsetX() != 0 || prototype.getBuild().getCopyOffsetY() != 0 || prototype.getBuild().getCopyOffsetZ() != 0) {
this.copyPoint = this.minPointBuild.add(prototype.getBuild().getCopyOffsetX(), prototype.getBuild().getCopyOffsetY(), prototype.getBuild().getCopyOffsetZ()); copyPoint = this.minPointBuild.add(prototype.getBuild().getCopyOffsetX(), prototype.getBuild().getCopyOffsetY(), prototype.getBuild().getCopyOffsetZ());
} else { } else {
this.copyPoint = this.minPointBuild.add(prototype.getBuild().getSizeX() / 2, 0, prototype.getBuild().getSizeZ()); copyPoint = this.minPointBuild.add(prototype.getBuild().getSizeX() / 2, 0, prototype.getBuild().getSizeZ());
} }
} else if (prototype.getCopyPointOffsetX() != 0 || prototype.getCopyPointOffsetY() != 0 || prototype.getCopyPointOffsetZ() != 0) { } else if (prototype.getCopyPointOffsetX() != 0 || prototype.getCopyPointOffsetY() != 0 || prototype.getCopyPointOffsetZ() != 0) {
this.copyPoint = minPoint.add(prototype.getCopyPointOffsetX(), prototype.getCopyPointOffsetY(), prototype.getCopyPointOffsetZ()); copyPoint = this.minPoint.add(prototype.getCopyPointOffsetX(), prototype.getCopyPointOffsetY(), prototype.getCopyPointOffsetZ());
} }
if (prototype.getFloorOffset() != 0) { floorLevel = prototype.getFloorOffset() != 0 ? this.minPoint.getY() + prototype.getFloorOffset() : 0;
floorLevel = minPoint.getY() + prototype.getFloorOffset(); waterLevel = prototype.getWaterOffset() != 0 ? this.minPoint.getY() + prototype.getWaterOffset() : 0;
} else {
floorLevel = 0;
}
if (prototype.getWaterOffset() != 0) { REGION_MAP.put(name, this);
waterLevel = minPoint.getY() + prototype.getWaterOffset();
} else {
waterLevel = 0;
}
} }
public boolean inRegion(Location location, RegionType regionType, RegionExtensionType regionExtensionType) { public boolean inRegion(Location location, RegionType regionType, RegionExtensionType regionExtensionType) {
@ -280,8 +239,12 @@ public class Region {
} }
} }
public String getSkin() {
return config.getSkin();
}
public String getDisplayName() { public String getDisplayName() {
return prototype != null ? prototype.getSkinMap().get(skin).getName() : ""; return prototype != null ? config.getSkin() : "";
} }
private void setLinkedRegion(Predicate<Region> regionConsumer) { private void setLinkedRegion(Predicate<Region> regionConsumer) {
@ -312,66 +275,52 @@ public class Region {
return linkedRegion; return linkedRegion;
} }
public boolean setPrototype(@NonNull Prototype prototype) {
if (!prototypes.contains(prototype.getName())) {
return false;
}
return _setPrototype(prototype);
}
boolean _setPrototype(@NonNull Prototype prototype) {
generatePrototypeData(prototype, minPoint);
RegionUtils.save(this);
return true;
}
public boolean setSkin(@NonNull String skinName) { public boolean setSkin(@NonNull String skinName) {
if (!prototype.getSkinMap().containsKey(skinName)) { if (!prototype.getSkins().containsKey(skinName)) {
return false; return false;
} }
this.skin = skinName; config.setSkin(skinName);
setLinkedRegion(region -> { setLinkedRegion(region -> {
region.skin = skinName; region.config.setSkin(skinName);
return true; return true;
}); });
regionData.add("skin", skin);
return true; return true;
} }
public void set(Flag flagType, Flag.Value<?> value) { public void set(Flag flagType, Flag.Value<?> value) {
if (flagStorage.set(flagType, value)) { if (config.getFlagStorage().set(flagType, value)) {
RegionUtils.save(this); RegionUtils.save(this);
} }
setLinkedRegion(region -> region.flagStorage.set(flagType, value)); setLinkedRegion(region -> region.config.getFlagStorage().set(flagType, value));
} }
public void set(Tag tag) { public void set(Tag tag) {
if (flagStorage.set(tag)) { if (config.getFlagStorage().set(tag)) {
RegionUtils.save(this); RegionUtils.save(this);
} }
setLinkedRegion(region -> region.flagStorage.set(tag)); setLinkedRegion(region -> region.config.getFlagStorage().set(tag));
} }
public void remove(Tag tag) { public void remove(Tag tag) {
if (flagStorage.remove(tag)) { if (config.getFlagStorage().remove(tag)) {
RegionUtils.save(this); RegionUtils.save(this);
} }
} }
public Flag.Value<?> get(Flag flagType) { public Flag.Value<?> get(Flag flagType) {
return flagStorage.get(flagType); return config.getFlagStorage().get(flagType);
} }
public boolean get(Tag tagType) { public boolean get(Tag tagType) {
return flagStorage.is(tagType); return config.getFlagStorage().is(tagType);
} }
public <T extends Enum<T> & Flag.Value<T>> T getPlain(Flag flagType) { public <T extends Enum<T> & Flag.Value<T>> T getPlain(Flag flagType) {
return (T) flagStorage.get(flagType).getValue(); return (T) config.getFlagStorage().get(flagType).getValue();
} }
public <T extends Enum<T> & Flag.Value<T>> T getPlain(Flag flagType, Class<T> type) { public <T extends Enum<T> & Flag.Value<T>> T getPlain(Flag flagType, Class<T> type) {
return (T) flagStorage.get(flagType).getValue(); return (T) config.getFlagStorage().get(flagType).getValue();
} }
public Point getMinPoint(RegionType regionType, RegionExtensionType regionExtensionType) { public Point getMinPoint(RegionType regionType, RegionExtensionType regionExtensionType) {
@ -404,12 +353,12 @@ public class Region {
} }
switch (regionType) { switch (regionType) {
case TESTBLOCK: case TESTBLOCK:
return prototype.getSkinMap().get(skin).getTestblockSchematicFile() != null; return prototype.getSkins().get(config.getSkin()).getTestblockSchematicFile() != null;
case BUILD: case BUILD:
return prototype.getSkinMap().get(skin).getBuildSchematicFile() != null; return prototype.getSkins().get(config.getSkin()).getBuildSchematicFile() != null;
default: default:
case NORMAL: case NORMAL:
return prototype.getSkinMap().get(skin).getSchematicFile() != null; return prototype.getSkins().get(config.getSkin()).getSchematicFile() != null;
} }
} }
@ -456,13 +405,13 @@ public class Region {
case BUILD: case BUILD:
pastePoint = minPointBuild.add(prototype.getBuild().getSizeX() / 2, 0, prototype.getBuild().getSizeZ() / 2); pastePoint = minPointBuild.add(prototype.getBuild().getSizeX() / 2, 0, prototype.getBuild().getSizeZ() / 2);
if (schematic == null) { if (schematic == null) {
tempFile = prototype.getSkinMap().get(skin).getBuildSchematicFile(); tempFile = prototype.getSkins().get(config.getSkin()).getBuildSchematicFile();
} }
break; break;
case TESTBLOCK: case TESTBLOCK:
pastePoint = minPointTestblock.add(prototype.getTestblock().getSizeX() / 2, 0, 0); pastePoint = minPointTestblock.add(prototype.getTestblock().getSizeX() / 2, 0, 0);
if (schematic == null) { if (schematic == null) {
tempFile = prototype.getSkinMap().get(skin).getTestblockSchematicFile(); tempFile = prototype.getSkins().get(config.getSkin()).getTestblockSchematicFile();
pastePoint = pastePoint.add(0, 0, prototype.getTestblock().getSizeZ() / 2); pastePoint = pastePoint.add(0, 0, prototype.getTestblock().getSizeZ() / 2);
} else { } else {
clipboard = new SchematicData(schematic).load(); clipboard = new SchematicData(schematic).load();
@ -483,7 +432,7 @@ public class Region {
case NORMAL: case NORMAL:
pastePoint = minPoint.add(prototype.getSizeX() / 2, 0, prototype.getSizeZ() / 2); pastePoint = minPoint.add(prototype.getSizeX() / 2, 0, prototype.getSizeZ() / 2);
if (schematic == null) { if (schematic == null) {
tempFile = prototype.getSkinMap().get(skin).getSchematicFile(); tempFile = prototype.getSkins().get(config.getSkin()).getSchematicFile();
} }
break; break;
} }

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

@ -1,47 +0,0 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2021 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.region.loader;
import de.steamwar.bausystem.BauSystem;
import org.bukkit.Bukkit;
import java.io.File;
import java.util.logging.Level;
public class Updater {
private long lastUpdate;
public Updater(File file, Runnable updaterCode) {
this.lastUpdate = file.lastModified();
Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), () -> {
if (file.lastModified() > lastUpdate + 10) {
try {
updaterCode.run();
Bukkit.getLogger().log(Level.INFO, "Update complete of " + file.getAbsolutePath());
} catch (Exception e) {
Bukkit.getLogger().log(Level.INFO, "Error while loading file " + file.getAbsolutePath() + " for config: " + e.getMessage(), e);
}
lastUpdate = file.lastModified();
}
}, 20, 20);
}
}

Datei anzeigen

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

Datei anzeigen

@ -19,73 +19,78 @@
package de.steamwar.bausystem.worlddata; package de.steamwar.bausystem.worlddata;
import de.steamwar.sql.SteamwarUser; import de.steamwar.bausystem.config.ConfigField;
import lombok.experimental.UtilityClass; 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 org.bukkit.Bukkit;
import yapion.hierarchy.output.FileOutput; import org.bukkit.Material;
import yapion.hierarchy.types.YAPIONObject; import org.bukkit.configuration.ConfigurationSection;
import yapion.parser.InputStreamCharsets; import org.bukkit.configuration.file.YamlConfiguration;
import yapion.parser.YAPIONParser; import org.bukkit.configuration.serialization.ConfigurationSerialization;
import yapion.parser.options.StreamOptions;
import java.io.BufferedInputStream;
import java.io.File; import java.io.File;
import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
@UtilityClass public class WorldData extends YamlConfig {
public class WorldData {
private final File optionsFile = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "options.yapion"); static {
private YAPIONObject worldData; ConfigurationSerialization.registerClass(FlagStorage.class);
register(RegionConfig.class);
public YAPIONObject getWorldData() { register(Warp.class);
if (worldData == null) {
read();
}
return worldData;
} }
public YAPIONObject getRegionsData() { private static final File optionsFile = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "options.yml");
return getWorldData().getYAPIONObjectOrSetDefault("regions", new YAPIONObject()); @Getter
} private static WorldData instance = new WorldData(YamlConfiguration.loadConfiguration(optionsFile));
public YAPIONObject getWarpData() { @ConfigField
return getWorldData().getYAPIONObjectOrSetDefault("warps", new YAPIONObject()); private final Map<String, RegionConfig> regionConfigs = new HashMap<>();
} @Getter
@ConfigField
private final Map<String, Warp> warps = new HashMap<>();
private void read() { public WorldData(ConfigurationSection configuration) {
worldData = new YAPIONObject(); super(configuration);
if (optionsFile.length() != 0) { instance = this;
try (BufferedInputStream bufferedInputStream = new BufferedInputStream(new FileInputStream(optionsFile))) { if(warps.isEmpty()) {
worldData = YAPIONParser.parse(bufferedInputStream, new StreamOptions().charset(InputStreamCharsets.UTF_8)); new Warp("WorldSpawn", Bukkit.getWorlds().get(0).getSpawnLocation(), Material.NETHER_STAR);
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 public RegionConfig getRegionConfig(String region) {
if (worldData.containsKey("simulators")) { return regionConfigs.computeIfAbsent(region, name -> new RegionConfig());
YAPIONObject yapionObject = worldData.getObject("simulators");
worldData.remove("simulators");
yapionObject.forEach((s, yapionAnyType) -> {
SteamwarUser steamwarUser = SteamwarUser.get(Integer.parseInt(s));
SimulatorData.saveSimulator(steamwarUser, new YAPIONObject().add("", yapionAnyType));
});
}
} }
public void write() { public void addWarp(Warp warp) {
warps.put(warp.getName(), warp);
}
public void save() {
try { try {
worldData.toYAPION(new FileOutput(optionsFile)).close(); toYaml().save(optionsFile);
} catch (IOException e) { } catch (IOException ignored) {}
// 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);
} }
} }
} }

Datei anzeigen

@ -46,10 +46,6 @@ allprojects {
repositories { repositories {
mavenCentral() mavenCentral()
maven {
url = uri("https://raw.githubusercontent.com/yoyosource/YAPION/master/releases")
}
maven { maven {
url = uri("https://repo.codemc.io/repository/maven-snapshots/") url = uri("https://repo.codemc.io/repository/maven-snapshots/")
} }

Binäre Datei nicht angezeigt.