forked from SteamWar/SteamWar
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9e0314472b |
@@ -47,7 +47,7 @@ dependencies {
|
|||||||
compileOnly(libs.netty)
|
compileOnly(libs.netty)
|
||||||
|
|
||||||
implementation(libs.luaj)
|
implementation(libs.luaj)
|
||||||
// implementation(files("$projectDir/../libs/YAPION-SNAPSHOT.jar"))
|
implementation(files("$projectDir/../libs/YAPION-SNAPSHOT.jar"))
|
||||||
}
|
}
|
||||||
|
|
||||||
widener {
|
widener {
|
||||||
|
|||||||
@@ -20,7 +20,8 @@
|
|||||||
package de.steamwar.bausystem;
|
package de.steamwar.bausystem;
|
||||||
|
|
||||||
import de.steamwar.bausystem.config.BauServer;
|
import de.steamwar.bausystem.config.BauServer;
|
||||||
import de.steamwar.bausystem.config.ConfigStore;
|
import de.steamwar.bausystem.configplayer.Config;
|
||||||
|
import de.steamwar.bausystem.configplayer.ConfigConverter;
|
||||||
import de.steamwar.bausystem.features.gui.BauGUI;
|
import de.steamwar.bausystem.features.gui.BauGUI;
|
||||||
import de.steamwar.bausystem.features.script.lua.SteamWarLuaPlugin;
|
import de.steamwar.bausystem.features.script.lua.SteamWarLuaPlugin;
|
||||||
import de.steamwar.bausystem.features.script.lua.libs.LuaLib;
|
import de.steamwar.bausystem.features.script.lua.libs.LuaLib;
|
||||||
@@ -35,6 +36,7 @@ import de.steamwar.bausystem.region.Region;
|
|||||||
import de.steamwar.bausystem.region.RegionSystem;
|
import de.steamwar.bausystem.region.RegionSystem;
|
||||||
import de.steamwar.bausystem.utils.ScoreboardElement;
|
import de.steamwar.bausystem.utils.ScoreboardElement;
|
||||||
import de.steamwar.bausystem.utils.TickManager;
|
import de.steamwar.bausystem.utils.TickManager;
|
||||||
|
import de.steamwar.bausystem.worlddata.WorldData;
|
||||||
import de.steamwar.command.AbstractValidator;
|
import de.steamwar.command.AbstractValidator;
|
||||||
import de.steamwar.command.SWCommandUtils;
|
import de.steamwar.command.SWCommandUtils;
|
||||||
import de.steamwar.core.CRIUSleepEvent;
|
import de.steamwar.core.CRIUSleepEvent;
|
||||||
@@ -110,6 +112,9 @@ public class BauSystem extends JavaPlugin implements Listener {
|
|||||||
if (any instanceof PanzernAlgorithm) {
|
if (any instanceof PanzernAlgorithm) {
|
||||||
Panzern.add((PanzernAlgorithm) any);
|
Panzern.add((PanzernAlgorithm) any);
|
||||||
}
|
}
|
||||||
|
if (any instanceof ConfigConverter) {
|
||||||
|
Config.addConfigConverter((ConfigConverter) any);
|
||||||
|
}
|
||||||
if (any instanceof BoundingBoxLoader) {
|
if (any instanceof BoundingBoxLoader) {
|
||||||
((BoundingBoxLoader) any).load();
|
((BoundingBoxLoader) any).load();
|
||||||
}
|
}
|
||||||
@@ -155,8 +160,9 @@ public class BauSystem extends JavaPlugin implements Listener {
|
|||||||
@Override
|
@Override
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
linker.unlink();
|
linker.unlink();
|
||||||
|
WorldData.write();
|
||||||
RegionSystem.INSTANCE.save();
|
RegionSystem.INSTANCE.save();
|
||||||
ConfigStore.saveAll();
|
Config.getInstance().saveAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
private <T extends CommandSender> AbstractValidator<T, ?> validator(Permission permission) {
|
private <T extends CommandSender> AbstractValidator<T, ?> validator(Permission permission) {
|
||||||
|
|||||||
@@ -1,47 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of the SteamWar software.
|
|
||||||
*
|
|
||||||
* Copyright (C) 2025 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;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Converts a config of one version into the next version, e.g. ConfigV1 to
|
|
||||||
* ConfigV2. The converter for the second newest version converts into the
|
|
||||||
* current version. Converters are registered in the {@link ConfigStore}
|
|
||||||
* of the config.
|
|
||||||
*
|
|
||||||
* @param <F> the config version to convert from
|
|
||||||
* @param <T> the config version to convert to
|
|
||||||
*/
|
|
||||||
public interface ConfigConverter<F extends VersionedConfig, T extends VersionedConfig> {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the version this converter converts from
|
|
||||||
*/
|
|
||||||
int version();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Converts the config to the next version. If anything goes wrong do not
|
|
||||||
* silently exit this method, throw an Exception. The {@link ConfigStore}
|
|
||||||
* will deal with it.
|
|
||||||
*
|
|
||||||
* @param config the config to convert
|
|
||||||
* @return the converted config
|
|
||||||
*/
|
|
||||||
T convert(F config);
|
|
||||||
}
|
|
||||||
@@ -1,364 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of the SteamWar software.
|
|
||||||
*
|
|
||||||
* Copyright (C) 2026 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 com.google.gson.Gson;
|
|
||||||
import com.google.gson.JsonObject;
|
|
||||||
import com.google.gson.JsonParser;
|
|
||||||
import de.steamwar.sql.UserConfig;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.nio.file.StandardCopyOption;
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
|
||||||
import java.util.function.Function;
|
|
||||||
import java.util.function.Predicate;
|
|
||||||
import java.util.function.Supplier;
|
|
||||||
import java.util.logging.Level;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Loads, converts and saves a versioned config stored as JSON. Older versions
|
|
||||||
* are converted with the registered {@link ConfigConverter}s, legacy formats
|
|
||||||
* that are not JSON can be read with {@link #legacy(Predicate, Function)}.
|
|
||||||
* <p>
|
|
||||||
* A store can be bound to where the config is stored:
|
|
||||||
* <ul>
|
|
||||||
* <li>{@link #userConfig(String)}: one config per player in the {@link UserConfig}, use {@link #get(Player)}</li>
|
|
||||||
* <li>{@link #file(File)}: one config in a file, use {@link #get()}</li>
|
|
||||||
* <li>unbound: use {@link #load(File)} and {@link #save(File, VersionedConfig)}</li>
|
|
||||||
* </ul>
|
|
||||||
*
|
|
||||||
* @param <T> the current config version
|
|
||||||
*/
|
|
||||||
public class ConfigStore<T extends VersionedConfig> {
|
|
||||||
|
|
||||||
private static final List<ConfigStore<?>> STORES = new ArrayList<>();
|
|
||||||
|
|
||||||
private final Class<T> type;
|
|
||||||
private final int version;
|
|
||||||
private final Supplier<T> defaultConfig;
|
|
||||||
|
|
||||||
private final Map<Integer, Class<? extends VersionedConfig>> jsonVersions = new HashMap<>();
|
|
||||||
private final Map<Integer, ConfigConverter<?, ?>> converters = new HashMap<>();
|
|
||||||
private final List<LegacyFormat> legacyFormats = new ArrayList<>();
|
|
||||||
private Gson gson = new Gson();
|
|
||||||
private Integer unversionedVersion = null;
|
|
||||||
|
|
||||||
private String userConfigKey = null;
|
|
||||||
private Predicate<T> removeIf = config -> false;
|
|
||||||
private final Map<UUID, T> playerConfigs = new ConcurrentHashMap<>();
|
|
||||||
|
|
||||||
private File file = null;
|
|
||||||
private File legacyFile = null;
|
|
||||||
private Function<String, ? extends VersionedConfig> legacyFileReader = null;
|
|
||||||
private T fileConfig = null;
|
|
||||||
|
|
||||||
private record LegacyFormat(Predicate<String> matches, Function<String, ? extends VersionedConfig> reader) {
|
|
||||||
}
|
|
||||||
|
|
||||||
public ConfigStore(Class<T> type, int version, Supplier<T> defaultConfig) {
|
|
||||||
this.type = type;
|
|
||||||
this.version = version;
|
|
||||||
this.defaultConfig = defaultConfig;
|
|
||||||
jsonVersions.put(version, type);
|
|
||||||
STORES.add(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ConfigStore<T> gson(Gson gson) {
|
|
||||||
this.gson = gson;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Registers an older config version that is stored as JSON.
|
|
||||||
*/
|
|
||||||
public ConfigStore<T> jsonVersion(int version, Class<? extends VersionedConfig> type) {
|
|
||||||
jsonVersions.put(version, type);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ConfigStore<T> converter(ConfigConverter<?, ?> converter) {
|
|
||||||
if (converters.putIfAbsent(converter.version(), converter) != null) {
|
|
||||||
throw new IllegalStateException("Duplicate converter for version " + converter.version() + " of " + type.getSimpleName());
|
|
||||||
}
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Registers a legacy format that is not JSON, stored strings matching the predicate are read by the reader.
|
|
||||||
*/
|
|
||||||
public ConfigStore<T> legacy(Predicate<String> matches, Function<String, ? extends VersionedConfig> reader) {
|
|
||||||
legacyFormats.add(new LegacyFormat(matches, reader));
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The version of stored JSON without a version field.
|
|
||||||
*/
|
|
||||||
public ConfigStore<T> unversioned(int version) {
|
|
||||||
this.unversionedVersion = version;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Binds this store to the {@link UserConfig} with the given key, one config per player.
|
|
||||||
*/
|
|
||||||
public ConfigStore<T> userConfig(String key) {
|
|
||||||
this.userConfigKey = key;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Removes the config from the {@link UserConfig} instead of saving it, if the predicate matches.
|
|
||||||
*/
|
|
||||||
public ConfigStore<T> removeIf(Predicate<T> removeIf) {
|
|
||||||
this.removeIf = removeIf;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Binds this store to a single file.
|
|
||||||
*/
|
|
||||||
public ConfigStore<T> file(File file) {
|
|
||||||
this.file = file;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Legacy file to read, if the file of this store does not exist yet.
|
|
||||||
*/
|
|
||||||
public ConfigStore<T> legacyFile(File legacyFile, Function<String, ? extends VersionedConfig> reader) {
|
|
||||||
this.legacyFile = legacyFile;
|
|
||||||
this.legacyFileReader = reader;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reads a stored config and converts it to the current version.
|
|
||||||
*
|
|
||||||
* @throws RuntimeException if the config could not be read or converted
|
|
||||||
*/
|
|
||||||
public T read(String stored) {
|
|
||||||
for (LegacyFormat legacyFormat : legacyFormats) {
|
|
||||||
if (legacyFormat.matches().test(stored)) {
|
|
||||||
return update(legacyFormat.reader().apply(stored));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
JsonObject json = JsonParser.parseString(stored).getAsJsonObject();
|
|
||||||
int storedVersion;
|
|
||||||
if (json.has("version")) {
|
|
||||||
storedVersion = json.get("version").getAsInt();
|
|
||||||
} else if (unversionedVersion != null) {
|
|
||||||
storedVersion = unversionedVersion;
|
|
||||||
json.addProperty("version", storedVersion);
|
|
||||||
} else {
|
|
||||||
throw new IllegalStateException("Missing version of " + type.getSimpleName());
|
|
||||||
}
|
|
||||||
Class<? extends VersionedConfig> storedType = jsonVersions.get(storedVersion);
|
|
||||||
if (storedType == null) {
|
|
||||||
throw new IllegalStateException("Unknown version " + storedVersion + " of " + type.getSimpleName());
|
|
||||||
}
|
|
||||||
return update(gson.fromJson(json, storedType));
|
|
||||||
}
|
|
||||||
|
|
||||||
public String write(T config) {
|
|
||||||
return gson.toJson(config);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Converts a config to the current version.
|
|
||||||
*/
|
|
||||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
|
||||||
public T update(VersionedConfig config) {
|
|
||||||
while (config.getVersion() < version) {
|
|
||||||
ConfigConverter converter = converters.get(config.getVersion());
|
|
||||||
if (converter == null) {
|
|
||||||
throw new IllegalStateException("No converter found for version " + config.getVersion() + " of " + type.getSimpleName());
|
|
||||||
}
|
|
||||||
VersionedConfig converted = converter.convert(config);
|
|
||||||
if (converted.getVersion() <= config.getVersion()) {
|
|
||||||
throw new IllegalStateException("Version did not increase after conversion of version " + config.getVersion() + " of " + type.getSimpleName());
|
|
||||||
}
|
|
||||||
config = converted;
|
|
||||||
}
|
|
||||||
if (!type.isInstance(config)) {
|
|
||||||
throw new IllegalStateException("Version " + config.getVersion() + " is not the current version of " + type.getSimpleName());
|
|
||||||
}
|
|
||||||
return type.cast(config);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the config stored in the file, or the default config if the file is missing or empty
|
|
||||||
* @throws RuntimeException if the config could not be read or converted
|
|
||||||
*/
|
|
||||||
public T load(File file) throws IOException {
|
|
||||||
if (file.length() == 0) {
|
|
||||||
return defaultConfig.get();
|
|
||||||
}
|
|
||||||
return read(Files.readString(file.toPath(), StandardCharsets.UTF_8));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void save(File file, T config) throws IOException {
|
|
||||||
Files.writeString(file.toPath(), write(config), StandardCharsets.UTF_8);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the config of a player, loads it from the {@link UserConfig} and converts it if necessary.
|
|
||||||
*/
|
|
||||||
public T get(Player player) {
|
|
||||||
requireUserConfig();
|
|
||||||
return playerConfigs.computeIfAbsent(player.getUniqueId(), this::loadPlayer);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Save the config of a player, this does not unload the config.
|
|
||||||
*/
|
|
||||||
public void save(Player player) {
|
|
||||||
requireUserConfig();
|
|
||||||
T config = playerConfigs.get(player.getUniqueId());
|
|
||||||
if (config != null) {
|
|
||||||
savePlayer(player.getUniqueId(), config);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Save and unload the config of a player.
|
|
||||||
*/
|
|
||||||
public void unload(Player player) {
|
|
||||||
if (userConfigKey == null) return;
|
|
||||||
T config = playerConfigs.remove(player.getUniqueId());
|
|
||||||
if (config != null) {
|
|
||||||
savePlayer(player.getUniqueId(), config);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private T loadPlayer(UUID uuid) {
|
|
||||||
String stored = UserConfig.getConfig(uuid, userConfigKey);
|
|
||||||
if (stored == null) {
|
|
||||||
return defaultConfig.get();
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
return read(stored);
|
|
||||||
} catch (Exception e) {
|
|
||||||
Bukkit.getLogger().log(Level.SEVERE, "Could not load " + type.getSimpleName() + " of " + uuid, e);
|
|
||||||
return defaultConfig.get();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void savePlayer(UUID uuid, T config) {
|
|
||||||
if (removeIf.test(config)) {
|
|
||||||
UserConfig.removePlayerConfig(uuid, userConfigKey);
|
|
||||||
} else {
|
|
||||||
UserConfig.updatePlayerConfig(uuid, userConfigKey, write(config));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void requireUserConfig() {
|
|
||||||
if (userConfigKey == null) {
|
|
||||||
throw new IllegalStateException(type.getSimpleName() + " is not stored in the UserConfig");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the config of the file of this store, loads it and converts it if necessary.
|
|
||||||
*/
|
|
||||||
public T get() {
|
|
||||||
requireFile();
|
|
||||||
if (fileConfig == null) {
|
|
||||||
fileConfig = loadFile();
|
|
||||||
save();
|
|
||||||
}
|
|
||||||
return fileConfig;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Save the config to the file of this store, if it was loaded.
|
|
||||||
*/
|
|
||||||
public void save() {
|
|
||||||
requireFile();
|
|
||||||
if (fileConfig == null) return;
|
|
||||||
try {
|
|
||||||
save(file, fileConfig);
|
|
||||||
} catch (IOException e) {
|
|
||||||
Bukkit.getLogger().log(Level.SEVERE, "Could not write " + file, e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private T loadFile() {
|
|
||||||
try {
|
|
||||||
if (file.length() != 0) {
|
|
||||||
return load(file);
|
|
||||||
}
|
|
||||||
if (legacyFile != null && legacyFile.length() != 0) {
|
|
||||||
return update(legacyFileReader.apply(Files.readString(legacyFile.toPath(), StandardCharsets.UTF_8)));
|
|
||||||
}
|
|
||||||
return defaultConfig.get();
|
|
||||||
} catch (Exception e) {
|
|
||||||
Bukkit.getLogger().log(Level.SEVERE, "Could not load " + file + ", using default " + type.getSimpleName(), e);
|
|
||||||
backupBrokenFile();
|
|
||||||
return defaultConfig.get();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void backupBrokenFile() {
|
|
||||||
if (file.length() == 0) return;
|
|
||||||
try {
|
|
||||||
Files.copy(file.toPath(), new File(file.getParentFile(), file.getName() + ".broken").toPath(), StandardCopyOption.REPLACE_EXISTING);
|
|
||||||
} catch (IOException e) {
|
|
||||||
Bukkit.getLogger().log(Level.SEVERE, "Could not backup broken " + file, e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void requireFile() {
|
|
||||||
if (file == null) {
|
|
||||||
throw new IllegalStateException(type.getSimpleName() + " is not bound to a file");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void unloadAll(Player player) {
|
|
||||||
STORES.forEach(store -> store.unload(player));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Saves every loaded config and unloads the configs of the players.
|
|
||||||
*/
|
|
||||||
public static void saveAll() {
|
|
||||||
for (ConfigStore<?> store : STORES) {
|
|
||||||
if (store.userConfigKey != null) {
|
|
||||||
store.playerConfigs.forEach((uuid, config) -> saveUnchecked(store, uuid, config));
|
|
||||||
store.playerConfigs.clear();
|
|
||||||
}
|
|
||||||
if (store.file != null) {
|
|
||||||
store.save();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
private static <T extends VersionedConfig> void saveUnchecked(ConfigStore<T> store, UUID uuid, Object config) {
|
|
||||||
store.savePlayer(uuid, (T) config);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,45 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of the SteamWar software.
|
|
||||||
*
|
|
||||||
* Copyright (C) 2026 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.core.CRIUSleepEvent;
|
|
||||||
import de.steamwar.linkage.Linked;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.EventPriority;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Saves and unloads the configs of the {@link ConfigStore}s bound to the UserConfig
|
|
||||||
* when a player quits, configs are loaded on first use.
|
|
||||||
*/
|
|
||||||
@Linked
|
|
||||||
public class ConfigStoreListener implements Listener {
|
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.MONITOR)
|
|
||||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
|
||||||
ConfigStore.unloadAll(event.getPlayer());
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onCRIUSleep(CRIUSleepEvent event) {
|
|
||||||
ConfigStore.saveAll();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of the SteamWar software.
|
|
||||||
*
|
|
||||||
* Copyright (C) 2026 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;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Common interface of every version of a config stored by a {@link ConfigStore},
|
|
||||||
* the current version (e.g. Config) and every older version (ConfigV1, ConfigV2, ...).
|
|
||||||
*/
|
|
||||||
public interface VersionedConfig {
|
|
||||||
|
|
||||||
int getVersion();
|
|
||||||
}
|
|
||||||
-95
@@ -1,95 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of the SteamWar software.
|
|
||||||
*
|
|
||||||
* Copyright (C) 2026 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.legacy;
|
|
||||||
|
|
||||||
import lombok.experimental.UtilityClass;
|
|
||||||
import org.bukkit.configuration.serialization.ConfigurationSerialization;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.LinkedHashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Deserializes {@link ItemStack}s that were serialized by YAPION, read with {@link YapionReader}.
|
|
||||||
*/
|
|
||||||
@UtilityClass
|
|
||||||
@Deprecated
|
|
||||||
public class YapionItemDeserializer {
|
|
||||||
|
|
||||||
private static final String TYPE_IDENTIFIER = "@type";
|
|
||||||
|
|
||||||
public ItemStack deserializeItem(Object yapion) {
|
|
||||||
if (yapion == null) return null;
|
|
||||||
Object result = deserialize(yapion);
|
|
||||||
if (result instanceof ItemStack itemStack) return itemStack;
|
|
||||||
throw new IllegalArgumentException("Not an ItemStack: " + result);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Object deserialize(Object yapion) {
|
|
||||||
if (yapion instanceof List<?> list) {
|
|
||||||
List<Object> result = new ArrayList<>();
|
|
||||||
list.forEach(o -> result.add(deserialize(o)));
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
if (yapion instanceof YapionReader.YapionMap map) {
|
|
||||||
Map<Object, Object> result = new LinkedHashMap<>();
|
|
||||||
map.entries().forEach((key, value) -> result.put(deserialize(key), deserialize(value)));
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
if (yapion instanceof Map<?, ?> object) {
|
|
||||||
return deserializeObject(object);
|
|
||||||
}
|
|
||||||
return yapion;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Object deserializeObject(Map<?, ?> object) {
|
|
||||||
Map<String, Object> data = new LinkedHashMap<>();
|
|
||||||
object.forEach((key, value) -> {
|
|
||||||
if (!TYPE_IDENTIFIER.equals(key)) data.put((String) key, deserialize(value));
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!(object.get(TYPE_IDENTIFIER) instanceof String type)) {
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
Class<?> javaType = javaUtilClass(type);
|
|
||||||
if (javaType != null && Collection.class.isAssignableFrom(javaType)) {
|
|
||||||
return data.getOrDefault("values", new ArrayList<>());
|
|
||||||
}
|
|
||||||
if (javaType != null && Map.class.isAssignableFrom(javaType)) {
|
|
||||||
return data.containsKey("values") ? data.get("values") : data;
|
|
||||||
}
|
|
||||||
|
|
||||||
data.put(ConfigurationSerialization.SERIALIZED_TYPE_KEY, type.equals("org.bukkit.inventory.meta.ItemMeta") ? "ItemMeta" : type);
|
|
||||||
return ConfigurationSerialization.deserializeObject(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Class<?> javaUtilClass(String type) {
|
|
||||||
if (!type.startsWith("java.util.")) return null;
|
|
||||||
try {
|
|
||||||
return Class.forName(type);
|
|
||||||
} catch (ClassNotFoundException e) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,323 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of the SteamWar software.
|
|
||||||
*
|
|
||||||
* Copyright (C) 2026 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.legacy;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.LinkedHashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Minimal reader for the legacy YAPION format, only used to migrate old data.
|
|
||||||
* <p>
|
|
||||||
* The result is built from plain java objects:
|
|
||||||
* <ul>
|
|
||||||
* <li>YAPION objects {@code {key(value)}} become a {@link LinkedHashMap} of String to value</li>
|
|
||||||
* <li>YAPION arrays {@code [a,b]} become a {@link List}</li>
|
|
||||||
* <li>YAPION maps {@code <(a):(b)>} become a {@link YapionMap}</li>
|
|
||||||
* <li>YAPION values {@code (value)} become null, Boolean, Number or String</li>
|
|
||||||
* </ul>
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public class YapionReader {
|
|
||||||
|
|
||||||
private static final Pattern INTEGER = Pattern.compile("[-+]?\\d+");
|
|
||||||
private static final Pattern DECIMAL = Pattern.compile("[-+]?(\\d+\\.\\d*|\\.\\d+|\\d+)([eE][-+]?\\d+)?");
|
|
||||||
|
|
||||||
public record YapionMap(Map<Object, Object> entries) {
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Map<String, Object> parse(String yapion) {
|
|
||||||
YapionReader reader = new YapionReader(yapion);
|
|
||||||
reader.skipWhitespace();
|
|
||||||
Map<String, Object> result = reader.readObject();
|
|
||||||
reader.skipWhitespace();
|
|
||||||
if (reader.index != yapion.length()) {
|
|
||||||
throw reader.error("Unexpected trailing content");
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static double getDouble(Map<?, ?> object, String key, double defaultValue) {
|
|
||||||
return object.get(key) instanceof Number value ? value.doubleValue() : defaultValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int getInt(Map<?, ?> object, String key, int defaultValue) {
|
|
||||||
return object.get(key) instanceof Number value ? value.intValue() : defaultValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean getBoolean(Map<?, ?> object, String key, boolean defaultValue) {
|
|
||||||
return object.get(key) instanceof Boolean value ? value : defaultValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getString(Map<?, ?> object, String key, String defaultValue) {
|
|
||||||
return object.get(key) instanceof String value ? value : defaultValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the entries of the array that are YAPION objects
|
|
||||||
*/
|
|
||||||
public static List<Map<?, ?>> getObjects(Map<?, ?> object, String key) {
|
|
||||||
List<Map<?, ?>> objects = new ArrayList<>();
|
|
||||||
if (object.get(key) instanceof List<?> array) {
|
|
||||||
array.forEach(o -> {
|
|
||||||
if (o instanceof Map<?, ?> map) objects.add(map);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return objects;
|
|
||||||
}
|
|
||||||
|
|
||||||
private final String input;
|
|
||||||
private int index = 0;
|
|
||||||
|
|
||||||
private YapionReader(String input) {
|
|
||||||
this.input = input;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Object readAny() {
|
|
||||||
return switch (peek()) {
|
|
||||||
case '{' -> readObject();
|
|
||||||
case '[' -> readArray();
|
|
||||||
case '<' -> readMap();
|
|
||||||
case '(' -> readValue();
|
|
||||||
default -> throw error("Expected '{', '[', '<' or '('");
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
private Map<String, Object> readObject() {
|
|
||||||
expect('{');
|
|
||||||
Map<String, Object> object = new LinkedHashMap<>();
|
|
||||||
while (true) {
|
|
||||||
skipWhitespace();
|
|
||||||
if (peek() == '}') {
|
|
||||||
index++;
|
|
||||||
return object;
|
|
||||||
}
|
|
||||||
StringBuilder key = new StringBuilder();
|
|
||||||
while (true) {
|
|
||||||
char c = peek();
|
|
||||||
if (c == '(' || c == '{' || c == '[' || c == '<') break;
|
|
||||||
if (c == '}') throw error("Key without value");
|
|
||||||
key.append(readChar());
|
|
||||||
}
|
|
||||||
object.put(key.toString(), readAny());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<Object> readArray() {
|
|
||||||
expect('[');
|
|
||||||
List<Object> array = new ArrayList<>();
|
|
||||||
skipWhitespace();
|
|
||||||
if (peek() == ']') {
|
|
||||||
index++;
|
|
||||||
return array;
|
|
||||||
}
|
|
||||||
while (true) {
|
|
||||||
int start = index;
|
|
||||||
skipWhitespace();
|
|
||||||
char c = peek();
|
|
||||||
if (c == '{' || c == '[' || c == '<' || c == '(') {
|
|
||||||
array.add(readAny());
|
|
||||||
skipWhitespace();
|
|
||||||
} else {
|
|
||||||
// Whitespace is part of plain values
|
|
||||||
index = start;
|
|
||||||
StringBuilder value = new StringBuilder();
|
|
||||||
while (peek() != ',' && peek() != ']') {
|
|
||||||
value.append(readChar());
|
|
||||||
}
|
|
||||||
array.add(typed(value.toString()));
|
|
||||||
}
|
|
||||||
char separator = input.charAt(index++);
|
|
||||||
if (separator == ']') return array;
|
|
||||||
if (separator != ',') throw error("Expected ',' or ']'");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private YapionMap readMap() {
|
|
||||||
expect('<');
|
|
||||||
Map<Object, Object> map = new LinkedHashMap<>();
|
|
||||||
while (true) {
|
|
||||||
skipWhitespace();
|
|
||||||
if (peek() == '>') {
|
|
||||||
index++;
|
|
||||||
return new YapionMap(map);
|
|
||||||
}
|
|
||||||
Object key = readAny();
|
|
||||||
skipWhitespace();
|
|
||||||
expect(':');
|
|
||||||
skipWhitespace();
|
|
||||||
map.put(key, readAny());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* YAPION does not escape parentheses in values, balanced parentheses are part of the value.
|
|
||||||
* A backslash only escapes a backslash, a unicode sequence or a control character, otherwise it is kept.
|
|
||||||
*/
|
|
||||||
private Object readValue() {
|
|
||||||
expect('(');
|
|
||||||
StringBuilder value = new StringBuilder();
|
|
||||||
int depth = 0;
|
|
||||||
while (true) {
|
|
||||||
char c = peek();
|
|
||||||
if (c == '\\') {
|
|
||||||
value.append(readValueEscape());
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
index++;
|
|
||||||
if (c == '(') {
|
|
||||||
depth++;
|
|
||||||
} else if (c == ')') {
|
|
||||||
if (depth == 0) break;
|
|
||||||
depth--;
|
|
||||||
}
|
|
||||||
value.append(c);
|
|
||||||
}
|
|
||||||
return typed(value.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
private String readValueEscape() {
|
|
||||||
index++;
|
|
||||||
if (index >= input.length()) return "\\";
|
|
||||||
char escaped = input.charAt(index);
|
|
||||||
switch (escaped) {
|
|
||||||
case '\\', '(', ')':
|
|
||||||
index++;
|
|
||||||
return String.valueOf(escaped);
|
|
||||||
case 'n':
|
|
||||||
index++;
|
|
||||||
return "\n";
|
|
||||||
case 't':
|
|
||||||
index++;
|
|
||||||
return "\t";
|
|
||||||
case 'r':
|
|
||||||
index++;
|
|
||||||
return "\r";
|
|
||||||
case 'u':
|
|
||||||
if (index + 5 <= input.length() && input.substring(index + 1, index + 5).matches("[0-9a-fA-F]{4}")) {
|
|
||||||
char unicode = (char) Integer.parseInt(input.substring(index + 1, index + 5), 16);
|
|
||||||
index += 5;
|
|
||||||
return String.valueOf(unicode);
|
|
||||||
}
|
|
||||||
return "\\";
|
|
||||||
default:
|
|
||||||
return "\\";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reads one character of a key or plain array value, resolving backslash escapes.
|
|
||||||
* A backslash that does not escape anything is kept, as the old player config
|
|
||||||
* collapsed escaped backslashes into a single one.
|
|
||||||
*/
|
|
||||||
private char readChar() {
|
|
||||||
char c = input.charAt(index++);
|
|
||||||
if (c != '\\') return c;
|
|
||||||
if (index >= input.length()) throw error("Unterminated escape");
|
|
||||||
char escaped = input.charAt(index);
|
|
||||||
switch (escaped) {
|
|
||||||
case 'n':
|
|
||||||
index++;
|
|
||||||
return '\n';
|
|
||||||
case 't':
|
|
||||||
index++;
|
|
||||||
return '\t';
|
|
||||||
case 'r':
|
|
||||||
index++;
|
|
||||||
return '\r';
|
|
||||||
case 'u':
|
|
||||||
if (index + 5 <= input.length() && input.substring(index + 1, index + 5).matches("[0-9a-fA-F]{4}")) {
|
|
||||||
char unicode = (char) Integer.parseInt(input.substring(index + 1, index + 5), 16);
|
|
||||||
index += 5;
|
|
||||||
return unicode;
|
|
||||||
}
|
|
||||||
return '\\';
|
|
||||||
case '\\', ',', ' ', '(', ')', '{', '}', '[', ']', '<', '>', '"', ':', '@':
|
|
||||||
index++;
|
|
||||||
return escaped;
|
|
||||||
default:
|
|
||||||
return '\\';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Object typed(String value) {
|
|
||||||
if (value.equals("null")) return null;
|
|
||||||
if (value.equals("true")) return true;
|
|
||||||
if (value.equals("false")) return false;
|
|
||||||
if (value.length() >= 2 && value.startsWith("\"") && value.endsWith("\"")) {
|
|
||||||
return value.substring(1, value.length() - 1);
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
if (INTEGER.matcher(value).matches()) {
|
|
||||||
long l = Long.parseLong(value);
|
|
||||||
if (l >= Integer.MIN_VALUE && l <= Integer.MAX_VALUE) return (int) l;
|
|
||||||
return l;
|
|
||||||
}
|
|
||||||
if (value.length() > 1) {
|
|
||||||
String number = value.substring(0, value.length() - 1);
|
|
||||||
switch (value.charAt(value.length() - 1)) {
|
|
||||||
case 'L':
|
|
||||||
if (INTEGER.matcher(number).matches()) return Long.parseLong(number);
|
|
||||||
break;
|
|
||||||
case 'S':
|
|
||||||
if (INTEGER.matcher(number).matches()) return Short.parseShort(number);
|
|
||||||
break;
|
|
||||||
case 'B':
|
|
||||||
if (INTEGER.matcher(number).matches()) return Byte.parseByte(number);
|
|
||||||
break;
|
|
||||||
case 'F':
|
|
||||||
if (DECIMAL.matcher(number).matches()) return Float.parseFloat(number);
|
|
||||||
break;
|
|
||||||
case 'D':
|
|
||||||
if (DECIMAL.matcher(number).matches()) return Double.parseDouble(number);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (DECIMAL.matcher(value).matches()) return Double.parseDouble(value);
|
|
||||||
} catch (NumberFormatException e) {
|
|
||||||
// Not a number, fall through to String
|
|
||||||
}
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void skipWhitespace() {
|
|
||||||
while (index < input.length() && Character.isWhitespace(input.charAt(index))) {
|
|
||||||
index++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private char peek() {
|
|
||||||
if (index >= input.length()) throw error("Unexpected end of input");
|
|
||||||
return input.charAt(index);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void expect(char c) {
|
|
||||||
if (peek() != c) throw error("Expected '" + c + "'");
|
|
||||||
index++;
|
|
||||||
}
|
|
||||||
|
|
||||||
private IllegalArgumentException error(String message) {
|
|
||||||
return new IllegalArgumentException(message + " at index " + index);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-63
@@ -1,63 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of the SteamWar software.
|
|
||||||
*
|
|
||||||
* Copyright (C) 2026 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.serializer;
|
|
||||||
|
|
||||||
import com.google.gson.TypeAdapter;
|
|
||||||
import com.google.gson.stream.JsonReader;
|
|
||||||
import com.google.gson.stream.JsonToken;
|
|
||||||
import com.google.gson.stream.JsonWriter;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Base64;
|
|
||||||
import java.util.logging.Level;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Stores an {@link ItemStack} as Base64 of {@link ItemStack#serializeAsBytes()}, which
|
|
||||||
* contains the data version and gets upgraded on newer Minecraft versions.
|
|
||||||
* Empty items are stored as null, items that can't be read are deserialized as null.
|
|
||||||
*/
|
|
||||||
public class ItemStackTypeAdapter extends TypeAdapter<ItemStack> {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void write(JsonWriter out, ItemStack itemStack) throws IOException {
|
|
||||||
if (itemStack == null || itemStack.isEmpty()) {
|
|
||||||
out.nullValue();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
out.value(Base64.getEncoder().encodeToString(itemStack.serializeAsBytes()));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ItemStack read(JsonReader in) throws IOException {
|
|
||||||
if (in.peek() == JsonToken.NULL) {
|
|
||||||
in.nextNull();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
String value = in.nextString();
|
|
||||||
try {
|
|
||||||
return ItemStack.deserializeBytes(Base64.getDecoder().decode(value));
|
|
||||||
} catch (Exception e) {
|
|
||||||
Bukkit.getLogger().log(Level.WARNING, "Could not deserialize ItemStack", e);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* This file is a part of the SteamWar software.
|
* This file is a part of the SteamWar software.
|
||||||
*
|
*
|
||||||
* Copyright (C) 2026 SteamWar.de-Serverteam
|
* Copyright (C) 2025 SteamWar.de-Serverteam
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
@@ -19,77 +19,129 @@
|
|||||||
|
|
||||||
package de.steamwar.bausystem.configplayer;
|
package de.steamwar.bausystem.configplayer;
|
||||||
|
|
||||||
import com.google.gson.GsonBuilder;
|
import de.steamwar.bausystem.configplayer.serializer.ConfigurationSerializableSerializer;
|
||||||
import de.steamwar.bausystem.config.ConfigConverter;
|
import de.steamwar.linkage.Linked;
|
||||||
import de.steamwar.bausystem.config.ConfigStore;
|
import de.steamwar.sql.UserConfig;
|
||||||
import de.steamwar.bausystem.config.VersionedConfig;
|
|
||||||
import de.steamwar.bausystem.config.serializer.ItemStackTypeAdapter;
|
|
||||||
import de.steamwar.bausystem.configplayer.converter.ConfigV1ToV2Converter;
|
|
||||||
import de.steamwar.bausystem.features.hotbar.DefaultHotbar;
|
|
||||||
import lombok.AccessLevel;
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
|
import yapion.hierarchy.output.StringOutput;
|
||||||
|
import yapion.hierarchy.types.YAPIONObject;
|
||||||
|
import yapion.parser.YAPIONParser;
|
||||||
|
import yapion.serializing.SerializeManager;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
/**
|
@Linked
|
||||||
* The current player config. It is stored as JSON, fields missing in the
|
public class Config implements Listener {
|
||||||
* stored JSON keep the default value of their initializer, so adding a new
|
|
||||||
* field does not need a new version.
|
|
||||||
* <p>
|
|
||||||
* When a field gets removed, renamed or its meaning changes, copy this class
|
|
||||||
* to ConfigV{@link #VERSION} (without the {@link #STORE}), increase {@link #VERSION},
|
|
||||||
* write a {@link ConfigConverter} from the copy to this class and register it in the {@link #STORE}.
|
|
||||||
*/
|
|
||||||
@Getter
|
|
||||||
@Setter
|
|
||||||
public class Config implements VersionedConfig {
|
|
||||||
|
|
||||||
public static final int VERSION = 2;
|
static {
|
||||||
|
SerializeManager.add(new ConfigurationSerializableSerializer());
|
||||||
|
}
|
||||||
|
|
||||||
public static final ConfigStore<Config> STORE = new ConfigStore<>(Config.class, VERSION, Config::new)
|
@Getter
|
||||||
.gson(new GsonBuilder().registerTypeHierarchyAdapter(ItemStack.class, new ItemStackTypeAdapter()).create())
|
private static Config instance;
|
||||||
.legacy(s -> s.startsWith("{@version(1)"), ConfigV1::parse)
|
|
||||||
.converter(new ConfigV1ToV2Converter())
|
|
||||||
.userConfig("bausystem");
|
|
||||||
|
|
||||||
@Setter(AccessLevel.NONE)
|
{
|
||||||
protected int version = VERSION;
|
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());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* BauGui item id to inventory slot
|
* 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
|
||||||
*/
|
*/
|
||||||
protected Map<Integer, Integer> bauGui = defaultBauGui();
|
public YAPIONObject get(Player player) {
|
||||||
protected int bauGuiSize = 45;
|
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().replaceAll("\\+", "\\");
|
||||||
|
UserConfig.updatePlayerConfig(uuid, "bausystem", string);
|
||||||
|
});
|
||||||
|
playerConfigurations.clear();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Slots 0-8 are the hotbar, slots 9-12 the armor contents
|
* Save a PlayerConfig, this does not remove the key value mapping from the map.
|
||||||
|
*
|
||||||
|
* @param player the player to save the config.
|
||||||
*/
|
*/
|
||||||
protected ItemStack[] hotbar = DefaultHotbar.defaultHotbar();
|
public void save(Player player) {
|
||||||
|
UUID uuid = player.getUniqueId();
|
||||||
|
if (playerConfigurations.containsKey(uuid)) {
|
||||||
|
YAPIONObject yapionObject = playerConfigurations.get(uuid);
|
||||||
|
String string = yapionObject.toYAPION(new StringOutput()).getResult().replaceAll("\\\\+", "\\\\");
|
||||||
|
UserConfig.updatePlayerConfig(uuid, "bausystem", string);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected boolean nightVision = false;
|
private YAPIONObject update(YAPIONObject yapionObject) {
|
||||||
protected boolean tntClickDetails = true;
|
int version = yapionObject.getPlainValue("@version");
|
||||||
protected boolean detonatorAutostart = false;
|
while (version < ConfigCreator.currentVersion) {
|
||||||
protected boolean inventoryFill = false;
|
ConfigConverter configConverter = CONFIG_CONVERTER_MAP.getOrDefault(version, null);
|
||||||
protected boolean rayVisualizer = false;
|
if (configConverter == null) {
|
||||||
protected boolean smartPlace = false;
|
Bukkit.getLogger().log(Level.SEVERE, "No updater found for version " + version);
|
||||||
protected boolean blockCounter = false;
|
return ConfigCreator.createDefaultConfig();
|
||||||
protected boolean depthMessage = true;
|
}
|
||||||
|
try {
|
||||||
public static Map<Integer, Integer> defaultBauGui() {
|
configConverter.update(yapionObject);
|
||||||
// 0: ? | 1: ? | 2: 10 | 3: 3 | 4: 7 | 5: 17 | 6: 15 | 7: ? | 8: ?
|
} catch (Exception e) {
|
||||||
// 9: 5 | 10: ? | 11: ? | 12: ? | 13: ? | 14: ? | 15: ? | 16: ? | 17: 16
|
Bukkit.getLogger().log(Level.SEVERE, e.getMessage(), e);
|
||||||
// 18: 4 | 19: ? | 20: 19 | 21: 21 | 22: 9 | 23: 0 | 24: 1 | 25: ? | 26: 11
|
return ConfigCreator.createDefaultConfig();
|
||||||
// 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: ?
|
int newVersion = yapionObject.getPlainValue("@version");
|
||||||
Map<Integer, Integer> bauGui = new HashMap<>();
|
if (version == newVersion) {
|
||||||
bauGui.put(10, 2); bauGui.put(3, 3); bauGui.put(7, 4); bauGui.put(17, 5); bauGui.put(15, 6);
|
Bukkit.getLogger().log(Level.SEVERE, "Version Tag was the same after conversion");
|
||||||
bauGui.put(5, 9); bauGui.put(4, 18); bauGui.put(6, 27);
|
return ConfigCreator.createDefaultConfig();
|
||||||
bauGui.put(16, 17); bauGui.put(11, 26); bauGui.put(18, 35);
|
}
|
||||||
bauGui.put(19, 20); bauGui.put(21, 21); bauGui.put(9, 22); bauGui.put(0, 23); bauGui.put(1, 24);
|
if (newVersion < version) {
|
||||||
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);
|
Bukkit.getLogger().log(Level.SEVERE, "Version Tag was earlier after conversion");
|
||||||
return bauGui;
|
return ConfigCreator.createDefaultConfig();
|
||||||
|
}
|
||||||
|
version = newVersion;
|
||||||
|
}
|
||||||
|
return yapionObject;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,56 @@
|
|||||||
|
/*
|
||||||
|
* This file is a part of the SteamWar software.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2025 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 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);
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
/*
|
||||||
|
* This file is a part of the SteamWar software.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2025 SteamWar.de-Serverteam
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.steamwar.bausystem.configplayer;
|
||||||
|
|
||||||
|
import de.steamwar.bausystem.features.hotbar.DefaultHotbar;
|
||||||
|
import lombok.experimental.UtilityClass;
|
||||||
|
import yapion.hierarchy.types.YAPIONObject;
|
||||||
|
|
||||||
|
@UtilityClass
|
||||||
|
public class ConfigCreator {
|
||||||
|
|
||||||
|
public static final int currentVersion = 1;
|
||||||
|
|
||||||
|
public YAPIONObject createDefaultConfig() {
|
||||||
|
YAPIONObject yapionObject = new YAPIONObject();
|
||||||
|
// This call should never be touched
|
||||||
|
yapionObject.add("@version", currentVersion);
|
||||||
|
|
||||||
|
// Any initialising goes into here
|
||||||
|
yapionObject.add("baugui", defaultBauGui());
|
||||||
|
|
||||||
|
// Default Hotbar Gui
|
||||||
|
yapionObject.add("hotbar", DefaultHotbar.defaultHotbar());
|
||||||
|
return yapionObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
private YAPIONObject defaultBauGui() {
|
||||||
|
YAPIONObject yapionObject = new YAPIONObject();
|
||||||
|
|
||||||
|
// 0: ? | 1: ? | 2: 10 | 3: 3 | 4: 7 | 5: 17 | 6: 15 | 7: ? | 8: ?
|
||||||
|
// 9: 5 | 10: ? | 11: ? | 12: ? | 13: ? | 14: ? | 15: ? | 16: ? | 17: 16
|
||||||
|
// 18: 4 | 19: ? | 20: 19 | 21: 21 | 22: 9 | 23: 0 | 24: 1 | 25: ? | 26: 11
|
||||||
|
// 27: 6 | 28: ? | 29: ? | 30: ? | 31: ? | 32: ? | 33: ? | 34: ? | 35: 18
|
||||||
|
// 36: ? | 37: 23 | 38: 20 | 39: 8 | 40: 22 | 41: 26 | 42: 12 | 43: 14 | 44: ?
|
||||||
|
|
||||||
|
yapionObject.add("10", 2).add("3", 3).add("7", 4).add("17", 5).add("15", 6);
|
||||||
|
yapionObject.add("5", 9).add("4", 18).add("6", 27);
|
||||||
|
yapionObject.add("16", 17).add("11", 26).add("18", 35);
|
||||||
|
yapionObject.add("19", 20).add("21", 21).add("9", 22).add("0", 23).add("1", 24);
|
||||||
|
yapionObject.add("23", 37).add("20", 38).add("8", 39).add("22", 40).add("26", 41).add("12", 42).add("14", 43);
|
||||||
|
yapionObject.add("size", 45);
|
||||||
|
return yapionObject;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,104 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of the SteamWar software.
|
|
||||||
*
|
|
||||||
* Copyright (C) 2026 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.config.VersionedConfig;
|
|
||||||
import de.steamwar.bausystem.config.legacy.YapionReader;
|
|
||||||
import lombok.AccessLevel;
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.Setter;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The legacy config that was stored in the YAPION format.
|
|
||||||
*/
|
|
||||||
@Getter
|
|
||||||
@Setter
|
|
||||||
public class ConfigV1 implements VersionedConfig {
|
|
||||||
|
|
||||||
public static final int VERSION = 1;
|
|
||||||
|
|
||||||
@Setter(AccessLevel.NONE)
|
|
||||||
protected int version = VERSION;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* BauGui item id to inventory slot
|
|
||||||
*/
|
|
||||||
protected Map<Integer, Integer> bauGui = new HashMap<>();
|
|
||||||
protected int bauGuiSize = 45;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Minecraft version to the hotbar serialized by YAPION, read with {@link YapionReader}.
|
|
||||||
* Use {@link de.steamwar.bausystem.config.legacy.YapionItemDeserializer} to get the items.
|
|
||||||
*/
|
|
||||||
protected Map<Integer, List<?>> hotbars = new HashMap<>();
|
|
||||||
|
|
||||||
protected boolean nightVision = false;
|
|
||||||
protected boolean tntClickDetails = true;
|
|
||||||
protected boolean detonatorAutostart = false;
|
|
||||||
protected boolean inventoryFill = false;
|
|
||||||
protected boolean rayVisualizer = false;
|
|
||||||
protected boolean smartPlace = false;
|
|
||||||
protected boolean blockCounter = false;
|
|
||||||
protected boolean depthMessage = true;
|
|
||||||
|
|
||||||
public static ConfigV1 parse(String yapion) {
|
|
||||||
Map<String, Object> object = YapionReader.parse(yapion);
|
|
||||||
ConfigV1 config = new ConfigV1();
|
|
||||||
config.version = (Integer) object.get("@version");
|
|
||||||
|
|
||||||
if (object.get("baugui") instanceof Map<?, ?> bauGui) {
|
|
||||||
bauGui.forEach((key, value) -> {
|
|
||||||
if (key.equals("size")) {
|
|
||||||
config.bauGuiSize = (Integer) value;
|
|
||||||
} else {
|
|
||||||
config.bauGui.put(Integer.parseInt((String) key), (Integer) value);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
object.forEach((key, value) -> {
|
|
||||||
if (!(value instanceof List<?> hotbar)) return;
|
|
||||||
if (key.equals("hotbar")) {
|
|
||||||
// Hotbars were stored without version prior to 1.19
|
|
||||||
config.hotbars.putIfAbsent(19, hotbar);
|
|
||||||
} else if (key.startsWith("hotbar-")) {
|
|
||||||
config.hotbars.put(Integer.parseInt(key.substring("hotbar-".length())), hotbar);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
config.nightVision = getBoolean(object, "nightvision", config.nightVision);
|
|
||||||
config.tntClickDetails = getBoolean(object, "tnt_click_details", config.tntClickDetails);
|
|
||||||
config.detonatorAutostart = getBoolean(object, "detonator-autostart", config.detonatorAutostart);
|
|
||||||
config.inventoryFill = getBoolean(object, "inventoryfill", config.inventoryFill);
|
|
||||||
config.rayVisualizer = getBoolean(object, "rayvisualizer", config.rayVisualizer);
|
|
||||||
config.smartPlace = getBoolean(object, "smartPlace", config.smartPlace);
|
|
||||||
config.blockCounter = getBoolean(object, "blockCounter", config.blockCounter);
|
|
||||||
config.depthMessage = getBoolean(object, "depth_message", config.depthMessage);
|
|
||||||
return config;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean getBoolean(Map<String, Object> object, String key, boolean defaultValue) {
|
|
||||||
return object.get(key) instanceof Boolean value ? value : defaultValue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-75
@@ -1,75 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of the SteamWar software.
|
|
||||||
*
|
|
||||||
* Copyright (C) 2026 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.converter;
|
|
||||||
|
|
||||||
import de.steamwar.bausystem.config.ConfigConverter;
|
|
||||||
import de.steamwar.bausystem.config.legacy.YapionItemDeserializer;
|
|
||||||
import de.steamwar.bausystem.configplayer.Config;
|
|
||||||
import de.steamwar.bausystem.configplayer.ConfigV1;
|
|
||||||
import de.steamwar.core.Core;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.logging.Level;
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public class ConfigV1ToV2Converter implements ConfigConverter<ConfigV1, Config> {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int version() {
|
|
||||||
return ConfigV1.VERSION;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Config convert(ConfigV1 old) {
|
|
||||||
Config config = new Config();
|
|
||||||
config.setBauGui(new HashMap<>(old.getBauGui()));
|
|
||||||
config.setBauGuiSize(old.getBauGuiSize());
|
|
||||||
|
|
||||||
List<?> hotbar = old.getHotbars().get(Core.getVersion());
|
|
||||||
if (hotbar != null) {
|
|
||||||
config.setHotbar(convertHotbar(hotbar));
|
|
||||||
}
|
|
||||||
|
|
||||||
config.setNightVision(old.isNightVision());
|
|
||||||
config.setTntClickDetails(old.isTntClickDetails());
|
|
||||||
config.setDetonatorAutostart(old.isDetonatorAutostart());
|
|
||||||
config.setInventoryFill(old.isInventoryFill());
|
|
||||||
config.setRayVisualizer(old.isRayVisualizer());
|
|
||||||
config.setSmartPlace(old.isSmartPlace());
|
|
||||||
config.setBlockCounter(old.isBlockCounter());
|
|
||||||
config.setDepthMessage(old.isDepthMessage());
|
|
||||||
return config;
|
|
||||||
}
|
|
||||||
|
|
||||||
private ItemStack[] convertHotbar(List<?> hotbar) {
|
|
||||||
ItemStack[] items = new ItemStack[13];
|
|
||||||
for (int i = 0; i < Math.min(hotbar.size(), items.length); i++) {
|
|
||||||
try {
|
|
||||||
items[i] = YapionItemDeserializer.deserializeItem(hotbar.get(i));
|
|
||||||
} catch (Exception e) {
|
|
||||||
Bukkit.getLogger().log(Level.WARNING, "Could not convert hotbar item " + i, e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return items;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+90
@@ -0,0 +1,90 @@
|
|||||||
|
/*
|
||||||
|
* This file is a part of the SteamWar software.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2025 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -64,7 +64,7 @@ public class Depth {
|
|||||||
dimensions.setZ(Math.abs(dimensions.getZ()));
|
dimensions.setZ(Math.abs(dimensions.getZ()));
|
||||||
|
|
||||||
RegionUtils.message(region, player -> {
|
RegionUtils.message(region, player -> {
|
||||||
if (Config.STORE.get(player).isDepthMessage()) {
|
if (Config.getInstance().get(player).getPlainValueOrDefault("depth_message", true)) {
|
||||||
player.spigot().sendMessage(getMessage(player, dimensions.getBlockX() + 1, dimensions.getBlockY() + 1, dimensions.getBlockZ() + 1, tntCount));
|
player.spigot().sendMessage(getMessage(player, dimensions.getBlockX() + 1, dimensions.getBlockY() + 1, dimensions.getBlockZ() + 1, tntCount));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
+3
-3
@@ -34,11 +34,11 @@ public class DepthCommand extends SWCommand {
|
|||||||
|
|
||||||
@Register
|
@Register
|
||||||
public void toggle(Player player) {
|
public void toggle(Player player) {
|
||||||
if (Config.STORE.get(player).isDepthMessage()) {
|
if (Config.getInstance().get(player).getPlainValueOrDefault("depth_message", true)) {
|
||||||
Config.STORE.get(player).setDepthMessage(false);
|
Config.getInstance().get(player).put("depth_message", false);
|
||||||
BauSystem.MESSAGE.send("DEPTH_COUNTER_DISABLE", player);
|
BauSystem.MESSAGE.send("DEPTH_COUNTER_DISABLE", player);
|
||||||
} else {
|
} else {
|
||||||
Config.STORE.get(player).setDepthMessage(true);
|
Config.getInstance().get(player).put("depth_message", true);
|
||||||
BauSystem.MESSAGE.send("DEPTH_COUNTER_ENABLE", player);
|
BauSystem.MESSAGE.send("DEPTH_COUNTER_ENABLE", player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -95,7 +95,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.STORE.get(p).isDetonatorAutostart()) {
|
if (Config.getInstance().get(p).getPlainValueOrDefault("detonator-autostart", false)) {
|
||||||
AutostartListener.instance.activate(p);
|
AutostartListener.instance.activate(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -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.STORE.get(p).isDetonatorAutostart();
|
boolean current = Config.getInstance().get(p).getPlainValueOrDefault("detonator-autostart", false);
|
||||||
Config.STORE.get(p).setDetonatorAutostart(!current);
|
Config.getInstance().get(p).put("detonator-autostart", !current);
|
||||||
if (!current) {
|
if (!current) {
|
||||||
BauSystem.MESSAGE.send("DETONATOR_AUTOSTART_ENABLE", p);
|
BauSystem.MESSAGE.send("DETONATOR_AUTOSTART_ENABLE", p);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
+16
-15
@@ -28,6 +28,7 @@ import lombok.Setter;
|
|||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.scheduler.BukkitTask;
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
|
import yapion.hierarchy.types.YAPIONObject;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
@@ -51,15 +52,15 @@ public class BauGuiMapping {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private final Config config;
|
private final YAPIONObject object;
|
||||||
@Getter
|
@Getter
|
||||||
private final Player owner;
|
private final Player owner;
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
private boolean saved;
|
private boolean saved;
|
||||||
|
|
||||||
protected BauGuiMapping(Config config, Player p) {
|
protected BauGuiMapping(YAPIONObject object, Player p) {
|
||||||
this.config = config;
|
this.object = object;
|
||||||
this.owner = p;
|
this.owner = p;
|
||||||
fromUUID.put(p.getUniqueId(), this);
|
fromUUID.put(p.getUniqueId(), this);
|
||||||
mappings.add(this);
|
mappings.add(this);
|
||||||
@@ -69,18 +70,19 @@ public class BauGuiMapping {
|
|||||||
BauGuiMapping mapping = fromUUID.get(p.getUniqueId());
|
BauGuiMapping mapping = fromUUID.get(p.getUniqueId());
|
||||||
|
|
||||||
if (mapping == null) {
|
if (mapping == null) {
|
||||||
mapping = new BauGuiMapping(Config.STORE.get(p), p);
|
YAPIONObject yapionObject = Config.getInstance().get(p);
|
||||||
|
mapping = new BauGuiMapping(yapionObject.getObject("baugui"), p);
|
||||||
}
|
}
|
||||||
|
|
||||||
return mapping;
|
return mapping;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isShown(int id) {
|
public boolean isShown(int id) {
|
||||||
return config.getBauGui().getOrDefault(id, -1) >= 0;
|
return object.getPlainValueOrDefault(Integer.toString(id), -1) >= 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getSlot(int id) {
|
public int getSlot(int id) {
|
||||||
return config.getBauGui().get(id);
|
return object.getPlainValue(Integer.toString(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<Integer, Integer> getMapping() {
|
public Map<Integer, Integer> getMapping() {
|
||||||
@@ -92,7 +94,7 @@ public class BauGuiMapping {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int getSize() {
|
public int getSize() {
|
||||||
return config.getBauGuiSize();
|
return object.getPlainValueOrDefault("size", 45);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSize(int size) {
|
public void setSize(int size) {
|
||||||
@@ -100,7 +102,7 @@ public class BauGuiMapping {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
config.setBauGuiSize(size);
|
object.add("size", size);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void tick() {
|
private void tick() {
|
||||||
@@ -109,17 +111,16 @@ public class BauGuiMapping {
|
|||||||
|
|
||||||
public void save() {
|
public void save() {
|
||||||
if (saved) return;
|
if (saved) return;
|
||||||
Config current = Config.STORE.get(owner);
|
YAPIONObject config = Config.getInstance().get(owner);
|
||||||
current.setBauGui(config.getBauGui());
|
config.add("baugui", object);
|
||||||
current.setBauGuiSize(config.getBauGuiSize());
|
Config.getInstance().save(owner);
|
||||||
Config.STORE.save(owner);
|
|
||||||
saved = true;
|
saved = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<Integer, Integer> internalReadMap() {
|
private Map<Integer, Integer> internalReadMap() {
|
||||||
Map<Integer, Integer> map = new HashMap<>();
|
Map<Integer, Integer> map = new HashMap<>();
|
||||||
for (Map.Entry<Integer, BauGuiItem> e : BauGUI.getITEMS().entrySet()) {
|
for (Map.Entry<Integer, BauGuiItem> e : BauGUI.getITEMS().entrySet()) {
|
||||||
Integer value = config.getBauGui().getOrDefault(e.getKey(), -1);
|
Integer value = object.getPlainValueOrDefault(e.getKey().toString(), -1);
|
||||||
if (value == -1) continue;
|
if (value == -1) continue;
|
||||||
map.put(e.getKey(), value);
|
map.put(e.getKey(), value);
|
||||||
}
|
}
|
||||||
@@ -128,10 +129,10 @@ public class BauGuiMapping {
|
|||||||
|
|
||||||
private void internalWriteMap(Map<Integer, Integer> map) {
|
private void internalWriteMap(Map<Integer, Integer> map) {
|
||||||
for (Map.Entry<Integer, BauGuiItem> e : BauGUI.getITEMS().entrySet()) {
|
for (Map.Entry<Integer, BauGuiItem> e : BauGUI.getITEMS().entrySet()) {
|
||||||
config.getBauGui().remove(e.getKey());
|
object.remove(e.getKey().toString());
|
||||||
Integer value = map.getOrDefault(e.getKey(), -1);
|
Integer value = map.getOrDefault(e.getKey(), -1);
|
||||||
if (value == -1) continue;
|
if (value == -1) continue;
|
||||||
config.getBauGui().put(e.getKey(), value);
|
object.add(e.getKey().toString(), value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+40
-30
@@ -20,23 +20,39 @@
|
|||||||
package de.steamwar.bausystem.features.hotbar;
|
package de.steamwar.bausystem.features.hotbar;
|
||||||
|
|
||||||
import de.steamwar.bausystem.configplayer.Config;
|
import de.steamwar.bausystem.configplayer.Config;
|
||||||
|
import de.steamwar.core.Core;
|
||||||
import lombok.experimental.UtilityClass;
|
import lombok.experimental.UtilityClass;
|
||||||
import org.bukkit.Material;
|
|
||||||
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 yapion.hierarchy.types.YAPIONArray;
|
||||||
|
import yapion.hierarchy.types.YAPIONObject;
|
||||||
|
import yapion.hierarchy.types.YAPIONValue;
|
||||||
|
import yapion.parser.YAPIONParser;
|
||||||
|
import yapion.serializing.YAPIONDeserializer;
|
||||||
|
import yapion.serializing.YAPIONSerializer;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
@UtilityClass
|
@UtilityClass
|
||||||
public class DefaultHotbar {
|
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 void updateHotbar(Player p) {
|
public void updateHotbar(Player p) {
|
||||||
ItemStack[] hotbar = new ItemStack[13];
|
ItemStack[] hotbar = new ItemStack[13];
|
||||||
System.arraycopy(p.getInventory().getContents(), 0, hotbar, 0, 9);
|
System.arraycopy(p.getInventory().getContents(), 0, hotbar, 0, 9);
|
||||||
System.arraycopy(p.getInventory().getArmorContents(), 0, hotbar, 9, 4);
|
System.arraycopy(p.getInventory().getArmorContents(), 0, hotbar, 9, 4);
|
||||||
Config.STORE.get(p).setHotbar(copy(hotbar));
|
YAPIONArray yapionArray = new YAPIONArray();
|
||||||
Config.STORE.save(p);
|
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) {
|
public void setHotbar(Player p) {
|
||||||
@@ -50,34 +66,28 @@ public class DefaultHotbar {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ItemStack[] getItems(Player p) {
|
public ItemStack[] getItems(Player p) {
|
||||||
return copy(Config.STORE.get(p).getHotbar());
|
Config.getInstance().get(p).remap("hotbar", "hotbar-19");
|
||||||
}
|
YAPIONArray yapionArray = Config.getInstance().get(p).getYAPIONArrayOrSetDefault("hotbar-" + Core.getVersion(), defaultHotbar());
|
||||||
|
|
||||||
public ItemStack[] defaultHotbar() {
|
|
||||||
ItemStack[] hotbar = new ItemStack[13];
|
ItemStack[] hotbar = new ItemStack[13];
|
||||||
hotbar[0] = item(Material.WOODEN_AXE, "WorldEdit Wand", "Left click: select pos #1", "Right click: select pos #2");
|
Set<Integer> invalid = new HashSet<>();
|
||||||
hotbar[1] = item(Material.COMPASS, "Navigation Wand", "Left click: jump to location", "Right click: pass through walls");
|
yapionArray.forEach((integer, yapionAnyType) -> {
|
||||||
hotbar[8] = item(Material.NETHER_STAR, "§eBau GUI");
|
if (yapionAnyType instanceof YAPIONValue) {
|
||||||
hotbar[11] = new ItemStack(Material.ELYTRA);
|
hotbar[integer] = null;
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
hotbar[integer] = YAPIONDeserializer.deserialize((YAPIONObject) yapionAnyType);
|
||||||
|
} catch (Exception e) {
|
||||||
|
invalid.add(integer);
|
||||||
|
hotbar[integer] = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
invalid.forEach(i -> yapionArray.set(i, new YAPIONValue<>(null)));
|
||||||
|
if (!invalid.isEmpty()) Config.getInstance().save(p);
|
||||||
return hotbar;
|
return hotbar;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ItemStack item(Material material, String name, String... lore) {
|
public YAPIONArray defaultHotbar() {
|
||||||
ItemStack itemStack = new ItemStack(material);
|
return DEFAULT_HOTBAR;
|
||||||
ItemMeta meta = itemStack.getItemMeta();
|
|
||||||
meta.setDisplayName(name);
|
|
||||||
if (lore.length > 0) {
|
|
||||||
meta.setLore(List.of(lore));
|
|
||||||
}
|
|
||||||
itemStack.setItemMeta(meta);
|
|
||||||
return itemStack;
|
|
||||||
}
|
|
||||||
|
|
||||||
private ItemStack[] copy(ItemStack[] hotbar) {
|
|
||||||
ItemStack[] copy = new ItemStack[13];
|
|
||||||
for (int i = 0; i < Math.min(hotbar.length, copy.length); i++) {
|
|
||||||
copy[i] = hotbar[i] == null ? null : hotbar[i].clone();
|
|
||||||
}
|
|
||||||
return copy;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -49,7 +49,7 @@ public class InventoryFillBauGuiItem extends BauGuiItem {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStack getItem(Player player) {
|
public ItemStack getItem(Player player) {
|
||||||
String loreKey = Config.STORE.get(player).isInventoryFill() ? "OTHER_ITEMS_INVENTORY_FILL_LORE_ACTIVE" : "OTHER_ITEMS_INVENTORY_FILL_LORE_INACTIVE";
|
String loreKey = Config.getInstance().get(player).getPlainValueOrDefault("inventoryfill", false) ? "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 -> {
|
return new SWItem(Material.HOPPER, BauSystem.MESSAGE.parse("OTHER_ITEMS_INVENTORY_FILL_NAME", player), Collections.singletonList(BauSystem.MESSAGE.parse(loreKey, player)), false, clickType -> {
|
||||||
}).getItemStack();
|
}).getItemStack();
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -40,7 +40,7 @@ public class InventoryFiller implements Listener {
|
|||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerDropItem(PlayerDropItemEvent event) {
|
public void onPlayerDropItem(PlayerDropItemEvent event) {
|
||||||
if (!Permission.BUILD.hasPermission(event.getPlayer())) return;
|
if (!Permission.BUILD.hasPermission(event.getPlayer())) return;
|
||||||
if (!Config.STORE.get(event.getPlayer()).isInventoryFill()) return;
|
if (!Config.getInstance().get(event.getPlayer()).getPlainValueOrDefault("inventoryfill", false)) 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;
|
||||||
@@ -62,7 +62,7 @@ public class InventoryFiller implements Listener {
|
|||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerItemHeld(PlayerItemHeldEvent event) {
|
public void onPlayerItemHeld(PlayerItemHeldEvent event) {
|
||||||
if (!Permission.BUILD.hasPermission(event.getPlayer())) return;
|
if (!Permission.BUILD.hasPermission(event.getPlayer())) return;
|
||||||
if (!Config.STORE.get(event.getPlayer()).isInventoryFill()) return;
|
if (!Config.getInstance().get(event.getPlayer()).getPlainValueOrDefault("inventoryfill", false)) 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;
|
||||||
|
|||||||
+2
-2
@@ -68,8 +68,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.STORE.get(player).isInventoryFill();
|
boolean inventoryFill = Config.getInstance().get(player).getPlainValueOrDefault("inventoryfill", false);
|
||||||
Config.STORE.get(player).setInventoryFill(!inventoryFill);
|
Config.getInstance().get(player).put("inventoryfill", !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);
|
||||||
|
|||||||
+4
-4
@@ -167,7 +167,7 @@ public class RayVisualizerCommand extends SWCommand implements Listener {
|
|||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||||
if (!Permission.BUILD.hasPermission(event.getPlayer())) return;
|
if (!Permission.BUILD.hasPermission(event.getPlayer())) return;
|
||||||
boolean rayvisualizer = Config.STORE.get(event.getPlayer()).isRayVisualizer();
|
boolean rayvisualizer = Config.getInstance().get(event.getPlayer()).getPlainValueOrDefault("rayvisualizer", false);
|
||||||
if (rayvisualizer) server.addPlayer(event.getPlayer());
|
if (rayvisualizer) server.addPlayer(event.getPlayer());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -181,7 +181,7 @@ public class RayVisualizerCommand extends SWCommand implements Listener {
|
|||||||
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> {
|
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> {
|
||||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||||
if (Permission.BUILD.hasPermission(player)) {
|
if (Permission.BUILD.hasPermission(player)) {
|
||||||
boolean rayvisualizer = Config.STORE.get(player).isRayVisualizer();
|
boolean rayvisualizer = Config.getInstance().get(player).getPlainValueOrDefault("rayvisualizer", false);
|
||||||
if (rayvisualizer) server.addPlayer(player);
|
if (rayvisualizer) server.addPlayer(player);
|
||||||
} else {
|
} else {
|
||||||
server.removePlayer(player);
|
server.removePlayer(player);
|
||||||
@@ -192,8 +192,8 @@ public class RayVisualizerCommand extends SWCommand implements Listener {
|
|||||||
|
|
||||||
@Register
|
@Register
|
||||||
public void toggle(@Validator Player player) {
|
public void toggle(@Validator Player player) {
|
||||||
boolean rayvisualizer = Config.STORE.get(player).isRayVisualizer();
|
boolean rayvisualizer = Config.getInstance().get(player).getPlainValueOrDefault("rayvisualizer", false);
|
||||||
Config.STORE.get(player).setRayVisualizer(!rayvisualizer);
|
Config.getInstance().get(player).put("rayvisualizer", !rayvisualizer);
|
||||||
if (!rayvisualizer) {
|
if (!rayvisualizer) {
|
||||||
SWUtils.sendToActionbar(player, BauSystem.MESSAGE.parse("RAY_VISUALIZER_ENABLE", player));
|
SWUtils.sendToActionbar(player, BauSystem.MESSAGE.parse("RAY_VISUALIZER_ENABLE", player));
|
||||||
server.addPlayer(player);
|
server.addPlayer(player);
|
||||||
|
|||||||
+3
-3
@@ -21,7 +21,6 @@ package de.steamwar.bausystem.features.simulator.data;
|
|||||||
|
|
||||||
import de.steamwar.bausystem.features.simulator.execute.SimulatorAction;
|
import de.steamwar.bausystem.features.simulator.execute.SimulatorAction;
|
||||||
import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui;
|
import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui;
|
||||||
import de.steamwar.bausystem.features.simulator.storage.SimulatorConfig;
|
|
||||||
import de.steamwar.inventory.InvCallback;
|
import de.steamwar.inventory.InvCallback;
|
||||||
import de.steamwar.inventory.SWItem;
|
import de.steamwar.inventory.SWItem;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
@@ -29,6 +28,7 @@ import lombok.Setter;
|
|||||||
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.YAPIONObject;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
@@ -121,9 +121,9 @@ public abstract class SimulatorElement<T extends SimulatorPhase> {
|
|||||||
|
|
||||||
public abstract String getType();
|
public abstract String getType();
|
||||||
|
|
||||||
public void saveExtra(SimulatorConfig.Element element) {
|
public void saveExtra(YAPIONObject elementObject) {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadExtra(SimulatorConfig.Element element) {
|
public void loadExtra(YAPIONObject elementObject) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-3
@@ -20,10 +20,10 @@
|
|||||||
package de.steamwar.bausystem.features.simulator.data;
|
package de.steamwar.bausystem.features.simulator.data;
|
||||||
|
|
||||||
import de.steamwar.bausystem.features.simulator.execute.SimulatorAction;
|
import de.steamwar.bausystem.features.simulator.execute.SimulatorAction;
|
||||||
import de.steamwar.bausystem.features.simulator.storage.SimulatorConfig;
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
|
import yapion.hierarchy.types.YAPIONObject;
|
||||||
|
|
||||||
import java.util.function.BiConsumer;
|
import java.util.function.BiConsumer;
|
||||||
|
|
||||||
@@ -38,9 +38,9 @@ public abstract class SimulatorPhase {
|
|||||||
|
|
||||||
public abstract void toSimulatorActions(Vector position, BiConsumer<Integer, SimulatorAction> tickStart, BiConsumer<Integer, SimulatorAction> tickEnd);
|
public abstract void toSimulatorActions(Vector position, BiConsumer<Integer, SimulatorAction> tickStart, BiConsumer<Integer, SimulatorAction> tickEnd);
|
||||||
|
|
||||||
public void saveExtra(SimulatorConfig.Phase phase) {
|
public void saveExtra(YAPIONObject phaseObject) {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadExtra(SimulatorConfig.Phase phase) {
|
public void loadExtra(YAPIONObject phaseObject) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-5
@@ -21,7 +21,6 @@ package de.steamwar.bausystem.features.simulator.data.observer;
|
|||||||
|
|
||||||
import de.steamwar.bausystem.features.simulator.data.SimulatorPhase;
|
import de.steamwar.bausystem.features.simulator.data.SimulatorPhase;
|
||||||
import de.steamwar.bausystem.features.simulator.execute.SimulatorAction;
|
import de.steamwar.bausystem.features.simulator.execute.SimulatorAction;
|
||||||
import de.steamwar.bausystem.features.simulator.storage.SimulatorConfig;
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
@@ -32,6 +31,7 @@ import org.bukkit.block.BlockFace;
|
|||||||
import org.bukkit.block.BlockState;
|
import org.bukkit.block.BlockState;
|
||||||
import org.bukkit.block.data.type.Observer;
|
import org.bukkit.block.data.type.Observer;
|
||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
|
import yapion.hierarchy.types.YAPIONObject;
|
||||||
|
|
||||||
import java.util.function.BiConsumer;
|
import java.util.function.BiConsumer;
|
||||||
|
|
||||||
@@ -70,12 +70,12 @@ public final class ObserverPhase extends SimulatorPhase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void saveExtra(SimulatorConfig.Phase phase) {
|
public void saveExtra(YAPIONObject phaseObject) {
|
||||||
phase.setOrientation(orientation);
|
phaseObject.add("orientation", orientation.name());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void loadExtra(SimulatorConfig.Phase phase) {
|
public void loadExtra(YAPIONObject phaseObject) {
|
||||||
if (phase.getOrientation() != null) orientation = phase.getOrientation();
|
orientation = BlockFace.valueOf(phaseObject.getPlainValue("orientation"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+7
-7
@@ -24,13 +24,13 @@ import de.steamwar.bausystem.features.simulator.data.SimulatorElement;
|
|||||||
import de.steamwar.bausystem.features.simulator.data.SimulatorGroup;
|
import de.steamwar.bausystem.features.simulator.data.SimulatorGroup;
|
||||||
import de.steamwar.bausystem.features.simulator.gui.SimulatorTNTGui;
|
import de.steamwar.bausystem.features.simulator.gui.SimulatorTNTGui;
|
||||||
import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui;
|
import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui;
|
||||||
import de.steamwar.bausystem.features.simulator.storage.SimulatorConfig;
|
|
||||||
import de.steamwar.inventory.InvCallback;
|
import de.steamwar.inventory.InvCallback;
|
||||||
import de.steamwar.inventory.SWItem;
|
import de.steamwar.inventory.SWItem;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
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.YAPIONObject;
|
||||||
|
|
||||||
public final class TNTElement extends SimulatorElement<TNTPhase> {
|
public final class TNTElement extends SimulatorElement<TNTPhase> {
|
||||||
|
|
||||||
@@ -100,14 +100,14 @@ public final class TNTElement extends SimulatorElement<TNTPhase> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void saveExtra(SimulatorConfig.Element element) {
|
public void saveExtra(YAPIONObject elementObject) {
|
||||||
element.setAlignmentX(alignment.getX());
|
elementObject.add("alignmentX", alignment.getX());
|
||||||
element.setAlignmentZ(alignment.getZ());
|
elementObject.add("alignmentZ", alignment.getZ());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void loadExtra(SimulatorConfig.Element element) {
|
public void loadExtra(YAPIONObject elementObject) {
|
||||||
alignment.setX(element.getAlignmentX() != null ? element.getAlignmentX() : 0);
|
alignment.setX(elementObject.getDoubleOrSetDefault("alignmentX", 0));
|
||||||
alignment.setZ(element.getAlignmentZ() != null ? element.getAlignmentZ() : 0);
|
alignment.setZ(elementObject.getDoubleOrSetDefault("alignmentZ", 0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+11
-11
@@ -21,7 +21,6 @@ package de.steamwar.bausystem.features.simulator.data.tnt;
|
|||||||
|
|
||||||
import de.steamwar.bausystem.features.simulator.data.SimulatorPhase;
|
import de.steamwar.bausystem.features.simulator.data.SimulatorPhase;
|
||||||
import de.steamwar.bausystem.features.simulator.execute.SimulatorAction;
|
import de.steamwar.bausystem.features.simulator.execute.SimulatorAction;
|
||||||
import de.steamwar.bausystem.features.simulator.storage.SimulatorConfig;
|
|
||||||
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.FreezeMode;
|
import de.steamwar.bausystem.region.flags.FreezeMode;
|
||||||
@@ -32,6 +31,7 @@ import org.bukkit.Location;
|
|||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
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.function.BiConsumer;
|
import java.util.function.BiConsumer;
|
||||||
|
|
||||||
@@ -83,18 +83,18 @@ public final class TNTPhase extends SimulatorPhase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void saveExtra(SimulatorConfig.Phase phase) {
|
public void saveExtra(YAPIONObject phaseObject) {
|
||||||
phase.setCount(count);
|
phaseObject.add("count", count);
|
||||||
phase.setXJump(xJump);
|
phaseObject.add("xJump", xJump);
|
||||||
phase.setYJump(yJump);
|
phaseObject.add("yJump", yJump);
|
||||||
phase.setZJump(zJump);
|
phaseObject.add("zJump", zJump);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void loadExtra(SimulatorConfig.Phase phase) {
|
public void loadExtra(YAPIONObject phaseObject) {
|
||||||
if (phase.getCount() != null) count = phase.getCount();
|
count = phaseObject.getPlainValue("count");
|
||||||
if (phase.getXJump() != null) xJump = phase.getXJump();
|
xJump = phaseObject.getPlainValue("xJump");
|
||||||
if (phase.getYJump() != null) yJump = phase.getYJump();
|
yJump = phaseObject.getPlainValue("yJump");
|
||||||
if (phase.getZJump() != null) zJump = phase.getZJump();
|
zJump = phaseObject.getPlainValue("zJump");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+37
-29
@@ -19,7 +19,6 @@
|
|||||||
|
|
||||||
package de.steamwar.bausystem.features.simulator.storage;
|
package de.steamwar.bausystem.features.simulator.storage;
|
||||||
|
|
||||||
import com.google.gson.JsonParseException;
|
|
||||||
import de.steamwar.bausystem.features.simulator.data.Simulator;
|
import de.steamwar.bausystem.features.simulator.data.Simulator;
|
||||||
import de.steamwar.bausystem.features.simulator.data.SimulatorElement;
|
import de.steamwar.bausystem.features.simulator.data.SimulatorElement;
|
||||||
import de.steamwar.bausystem.features.simulator.data.SimulatorGroup;
|
import de.steamwar.bausystem.features.simulator.data.SimulatorGroup;
|
||||||
@@ -30,7 +29,12 @@ import de.steamwar.bausystem.features.simulator.data.redstone.RedstoneElement;
|
|||||||
import de.steamwar.bausystem.features.simulator.data.redstone.RedstonePhase;
|
import de.steamwar.bausystem.features.simulator.data.redstone.RedstonePhase;
|
||||||
import de.steamwar.bausystem.features.simulator.data.tnt.TNTElement;
|
import de.steamwar.bausystem.features.simulator.data.tnt.TNTElement;
|
||||||
import de.steamwar.bausystem.features.simulator.data.tnt.TNTPhase;
|
import de.steamwar.bausystem.features.simulator.data.tnt.TNTPhase;
|
||||||
|
import org.bukkit.Material;
|
||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
|
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;
|
||||||
@@ -47,41 +51,44 @@ public class SimFormatSimulatorLoader implements SimulatorLoader {
|
|||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
SimulatorConfig config;
|
YAPIONObject yapionObject;
|
||||||
try {
|
try {
|
||||||
config = SimulatorConfig.STORE.load(file);
|
yapionObject = YAPIONParser.parse(file);
|
||||||
} catch (JsonParseException | IllegalStateException | IOException e) {
|
} catch (YAPIONException | IOException e) {
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
String name = file.getName().substring(0, file.getName().length() - ".sim".length());
|
String name = file.getName().substring(0, file.getName().length() - ".sim".length());
|
||||||
|
|
||||||
Simulator simulator = new Simulator(name);
|
Simulator simulator = new Simulator(name);
|
||||||
loadSimulator(config, simulator);
|
loadSimulator(yapionObject, simulator);
|
||||||
return Optional.of(Collections.singletonList(simulator));
|
return Optional.of(Collections.singletonList(simulator));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadSimulator(SimulatorConfig config, Simulator simulator) {
|
private void loadSimulator(YAPIONObject simulatorObject, Simulator simulator) {
|
||||||
if (config.getMaterial() != null) simulator.setMaterial(config.getMaterial());
|
simulator.setMaterial(Material.valueOf(simulatorObject.getPlainValue("material")));
|
||||||
simulator.setAutoTrace(config.isAutoTrace());
|
simulator.setAutoTrace(simulatorObject.getPlainValue("autoTrace"));
|
||||||
simulator.setAutoTestblock(config.isAutoTestblock());
|
simulator.setAutoTestblock(simulatorObject.getPlainValueOrDefault("autoTestblock", false));
|
||||||
|
|
||||||
config.getGroups().forEach(groupConfig -> {
|
YAPIONArray groups = simulatorObject.getArray("groups");
|
||||||
|
groups.streamObject().forEach(groupObject -> {
|
||||||
SimulatorGroup simulatorGroup = new SimulatorGroup();
|
SimulatorGroup simulatorGroup = new SimulatorGroup();
|
||||||
loadGroup(groupConfig, simulatorGroup);
|
loadGroup(groupObject, simulatorGroup);
|
||||||
simulator.add(simulatorGroup);
|
simulator.add(simulatorGroup);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadGroup(SimulatorConfig.Group groupConfig, SimulatorGroup group) {
|
private void loadGroup(YAPIONObject groupObject, SimulatorGroup group) {
|
||||||
if (groupConfig.getMaterial() != null) group.setMaterial(groupConfig.getMaterial());
|
group.setMaterial(Material.valueOf(groupObject.getPlainValue("material")));
|
||||||
group.setDisabled(groupConfig.isDisabled());
|
group.setDisabled(groupObject.getPlainValue("disabled"));
|
||||||
|
|
||||||
groupConfig.getElements().forEach(elementConfig -> {
|
YAPIONArray elements = groupObject.getArray("elements");
|
||||||
|
elements.streamObject().forEach(elementObject -> {
|
||||||
SimulatorElement<?> element;
|
SimulatorElement<?> element;
|
||||||
Supplier<SimulatorPhase> phaseConstructor;
|
Supplier<SimulatorPhase> phaseConstructor;
|
||||||
Vector position = new Vector(elementConfig.getX(), elementConfig.getY(), elementConfig.getZ());
|
Vector position = new Vector(elementObject.getDouble("x"), elementObject.getDouble("y"), elementObject.getDouble("z"));
|
||||||
switch (String.valueOf(elementConfig.getType())) {
|
String type = elementObject.getPlainValue("type");
|
||||||
|
switch (type) {
|
||||||
case "TNT":
|
case "TNT":
|
||||||
element = new TNTElement(position);
|
element = new TNTElement(position);
|
||||||
phaseConstructor = TNTPhase::new;
|
phaseConstructor = TNTPhase::new;
|
||||||
@@ -102,27 +109,28 @@ public class SimFormatSimulatorLoader implements SimulatorLoader {
|
|||||||
if (element == null) {
|
if (element == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
loadElement(elementConfig, element, phaseConstructor);
|
loadElement(elementObject, element, phaseConstructor);
|
||||||
group.add(element);
|
group.add(element);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadElement(SimulatorConfig.Element elementConfig, SimulatorElement<?> element, Supplier<SimulatorPhase> phaseConstructor) {
|
private void loadElement(YAPIONObject elementObject, SimulatorElement<?> element, Supplier<SimulatorPhase> phaseConstructor) {
|
||||||
if (elementConfig.getMaterial() != null) element.setMaterial(elementConfig.getMaterial());
|
element.setMaterial(Material.valueOf(elementObject.getPlainValue("material")));
|
||||||
element.setDisabled(elementConfig.isDisabled());
|
element.setDisabled(elementObject.getPlainValue("disabled"));
|
||||||
element.loadExtra(elementConfig);
|
element.loadExtra(elementObject);
|
||||||
|
|
||||||
elementConfig.getPhases().forEach(phaseConfig -> {
|
YAPIONArray phases = elementObject.getArray("phases");
|
||||||
|
phases.streamObject().forEach(phaseObject -> {
|
||||||
SimulatorPhase phase = phaseConstructor.get();
|
SimulatorPhase phase = phaseConstructor.get();
|
||||||
loadPhase(phaseConfig, phase);
|
loadPhase(phaseObject, phase);
|
||||||
((SimulatorElement) element).add(phase);
|
((SimulatorElement) element).add(phase);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadPhase(SimulatorConfig.Phase phaseConfig, SimulatorPhase phase) {
|
private void loadPhase(YAPIONObject phaseObject, SimulatorPhase phase) {
|
||||||
phase.setTickOffset(phaseConfig.getTickOffset());
|
phase.setTickOffset(phaseObject.getPlainValue("tickOffset"));
|
||||||
phase.setLifetime(phaseConfig.getLifetime());
|
phase.setLifetime(phaseObject.getPlainValue("lifetime"));
|
||||||
phase.setOrder(phaseConfig.getOrder());
|
phase.setOrder(phaseObject.getPlainValue("order"));
|
||||||
phase.loadExtra(phaseConfig);
|
phase.loadExtra(phaseObject);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
-117
@@ -1,117 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of the SteamWar software.
|
|
||||||
*
|
|
||||||
* Copyright (C) 2026 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.features.simulator.storage;
|
|
||||||
|
|
||||||
import de.steamwar.bausystem.config.ConfigStore;
|
|
||||||
import de.steamwar.bausystem.config.VersionedConfig;
|
|
||||||
import lombok.AccessLevel;
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.Setter;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.block.BlockFace;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The current stored form of a simulator, saved as JSON in a .sim file. Files
|
|
||||||
* saved before the version was stored have no version and are version 1.
|
|
||||||
* Fields missing in the stored JSON keep the default value of their initializer,
|
|
||||||
* so adding a new field does not need a new version.
|
|
||||||
* <p>
|
|
||||||
* When a field gets removed, renamed or its meaning changes, copy this class
|
|
||||||
* to SimulatorConfigV{@link #VERSION} (without the {@link #STORE}), increase {@link #VERSION}, write a
|
|
||||||
* {@link de.steamwar.bausystem.config.ConfigConverter} from the copy to
|
|
||||||
* this class and register it in the {@link #STORE}.
|
|
||||||
*/
|
|
||||||
@Getter
|
|
||||||
@Setter
|
|
||||||
public class SimulatorConfig implements VersionedConfig {
|
|
||||||
|
|
||||||
public static final int VERSION = 1;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Files saved before the version was stored are version 1
|
|
||||||
*/
|
|
||||||
public static final ConfigStore<SimulatorConfig> STORE = new ConfigStore<>(SimulatorConfig.class, VERSION, SimulatorConfig::new)
|
|
||||||
.unversioned(1);
|
|
||||||
|
|
||||||
@Setter(AccessLevel.NONE)
|
|
||||||
protected int version = VERSION;
|
|
||||||
|
|
||||||
protected Material material = Material.BARREL;
|
|
||||||
protected boolean autoTrace = false;
|
|
||||||
protected boolean autoTestblock = false;
|
|
||||||
protected List<Group> groups = new ArrayList<>();
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
@Setter
|
|
||||||
public static class Group {
|
|
||||||
|
|
||||||
protected Material material = Material.CHEST;
|
|
||||||
protected boolean disabled = false;
|
|
||||||
protected List<Element> elements = new ArrayList<>();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
@Setter
|
|
||||||
public static class Element {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* One of "TNT", "Redstone" or "Observer"
|
|
||||||
*/
|
|
||||||
protected String type;
|
|
||||||
protected Material material;
|
|
||||||
protected boolean disabled = false;
|
|
||||||
protected double x;
|
|
||||||
protected double y;
|
|
||||||
protected double z;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Only used by TNT
|
|
||||||
*/
|
|
||||||
protected Double alignmentX;
|
|
||||||
protected Double alignmentZ;
|
|
||||||
|
|
||||||
protected List<Phase> phases = new ArrayList<>();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
@Setter
|
|
||||||
public static class Phase {
|
|
||||||
|
|
||||||
protected int tickOffset;
|
|
||||||
protected int lifetime;
|
|
||||||
protected int order;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Only used by TNT
|
|
||||||
*/
|
|
||||||
protected Integer count;
|
|
||||||
protected Boolean xJump;
|
|
||||||
protected Boolean yJump;
|
|
||||||
protected Boolean zJump;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Only used by Observer
|
|
||||||
*/
|
|
||||||
protected BlockFace orientation;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+35
-43
@@ -19,30 +19,24 @@
|
|||||||
|
|
||||||
package de.steamwar.bausystem.features.simulator.storage;
|
package de.steamwar.bausystem.features.simulator.storage;
|
||||||
|
|
||||||
import de.steamwar.bausystem.config.legacy.YapionReader;
|
|
||||||
import de.steamwar.bausystem.features.simulator.data.Simulator;
|
import de.steamwar.bausystem.features.simulator.data.Simulator;
|
||||||
import de.steamwar.bausystem.features.simulator.data.SimulatorGroup;
|
import de.steamwar.bausystem.features.simulator.data.SimulatorGroup;
|
||||||
import de.steamwar.bausystem.features.simulator.data.tnt.TNTElement;
|
import de.steamwar.bausystem.features.simulator.data.tnt.TNTElement;
|
||||||
import de.steamwar.bausystem.features.simulator.data.tnt.TNTPhase;
|
import de.steamwar.bausystem.features.simulator.data.tnt.TNTPhase;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
|
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;
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static de.steamwar.bausystem.config.legacy.YapionReader.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Loads the legacy .simulator files stored as YAPION, they are deleted after loading
|
|
||||||
* and saved in the current format by the {@link SimulatorSaver}.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public class SimulatorFormatSimulatorLoader implements SimulatorLoader {
|
public class SimulatorFormatSimulatorLoader implements SimulatorLoader {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -51,19 +45,20 @@ public class SimulatorFormatSimulatorLoader implements SimulatorLoader {
|
|||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, Object> yapionObject;
|
YAPIONObject yapionObject;
|
||||||
try {
|
try {
|
||||||
yapionObject = YapionReader.parse(Files.readString(file.toPath(), StandardCharsets.UTF_8));
|
yapionObject = YAPIONParser.parse(file);
|
||||||
} catch (IllegalArgumentException | IOException e) {
|
} catch (YAPIONException | IOException e) {
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
String name = file.getName().substring(0, file.getName().length() - ".simulator".length());
|
String name = file.getName().substring(0, file.getName().length() - ".simulator".length());
|
||||||
|
|
||||||
Simulator simulator = new Simulator(name);
|
Simulator simulator = new Simulator(name);
|
||||||
simulator.setMaterial(Material.valueOf(getString(yapionObject, "material", "BARREL")));
|
simulator.setMaterial(Material.valueOf(yapionObject.getStringOrDefault("material", "BARREL")));
|
||||||
|
|
||||||
for (Map<?, ?> element : getObjects(yapionObject, "tntElements")) {
|
YAPIONArray tntElements = yapionObject.getArrayOrDefault("tntElements", new YAPIONArray());
|
||||||
|
for (YAPIONObject element : tntElements.streamObject().collect(Collectors.toList())) {
|
||||||
if (element.containsKey("elements")) {
|
if (element.containsKey("elements")) {
|
||||||
simulator.add(loadGroup(element));
|
simulator.add(loadGroup(element));
|
||||||
} else {
|
} else {
|
||||||
@@ -75,26 +70,27 @@ public class SimulatorFormatSimulatorLoader implements SimulatorLoader {
|
|||||||
return Optional.of(Collections.singletonList(simulator));
|
return Optional.of(Collections.singletonList(simulator));
|
||||||
}
|
}
|
||||||
|
|
||||||
private SimulatorGroup loadGroup(Map<?, ?> element) {
|
private SimulatorGroup loadGroup(YAPIONObject element) {
|
||||||
double x = getDouble(element, "x", 0);
|
double x = element.getDoubleOrDefault("x", 0);
|
||||||
double y = getDouble(element, "y", 0);
|
double y = element.getDoubleOrDefault("y", 0);
|
||||||
double z = getDouble(element, "z", 0);
|
double z = element.getDoubleOrDefault("z", 0);
|
||||||
int tickOffset = getInt(element, "tickOffset", 0);
|
int tickOffset = element.getIntOrDefault("tickOffset", 0);
|
||||||
|
|
||||||
SimulatorGroup simulatorGroup = new SimulatorGroup();
|
SimulatorGroup simulatorGroup = new SimulatorGroup();
|
||||||
simulatorGroup.setDisabled(getBoolean(element, "disabled", false));
|
simulatorGroup.setDisabled(element.getBooleanOrDefault("disabled", false));
|
||||||
|
|
||||||
for (Map<?, ?> e : getObjects(element, "elements")) {
|
YAPIONArray elements = element.getArrayOrDefault("elements", new YAPIONArray());
|
||||||
|
for (YAPIONObject e : elements.streamObject().collect(Collectors.toList())) {
|
||||||
simulatorGroup.add(loadElement(e, x, y, z, tickOffset));
|
simulatorGroup.add(loadElement(e, x, y, z, tickOffset));
|
||||||
}
|
}
|
||||||
|
|
||||||
return simulatorGroup;
|
return simulatorGroup;
|
||||||
}
|
}
|
||||||
|
|
||||||
private TNTElement loadElement(Map<?, ?> element, double dx, double dy, double dz, int dTickOffset) {
|
private TNTElement loadElement(YAPIONObject element, double dx, double dy, double dz, int dTickOffset) {
|
||||||
TNTElement tntElement = new TNTElement(new Vector(requireDouble(element, "x") + dx, requireDouble(element, "y") + dy, requireDouble(element, "z") + dz));
|
TNTElement tntElement = new TNTElement(new Vector(element.getDouble("x") + dx, element.getDouble("y") + dy, element.getDouble("z") + dz));
|
||||||
tntElement.setDisabled(getBoolean(element, "disabled", false));
|
tntElement.setDisabled(element.getBooleanOrDefault("disabled", false));
|
||||||
tntElement.setMaterial(Material.valueOf(getString(element, "material", "TNT")));
|
tntElement.setMaterial(Material.valueOf(element.getStringOrDefault("material", "TNT")));
|
||||||
|
|
||||||
TNTPhase tntPhase = loadPhase(element);
|
TNTPhase tntPhase = loadPhase(element);
|
||||||
tntPhase.setTickOffset(tntPhase.getTickOffset() + dTickOffset);
|
tntPhase.setTickOffset(tntPhase.getTickOffset() + dTickOffset);
|
||||||
@@ -103,12 +99,12 @@ public class SimulatorFormatSimulatorLoader implements SimulatorLoader {
|
|||||||
return tntElement;
|
return tntElement;
|
||||||
}
|
}
|
||||||
|
|
||||||
private SimulatorGroup loadElement(Map<?, ?> element) {
|
private SimulatorGroup loadElement(YAPIONObject element) {
|
||||||
SimulatorGroup simulatorGroup = new SimulatorGroup();
|
SimulatorGroup simulatorGroup = new SimulatorGroup();
|
||||||
|
|
||||||
TNTElement tntElement = new TNTElement(new Vector(requireDouble(element, "x"), requireDouble(element, "y"), requireDouble(element, "z")));
|
TNTElement tntElement = new TNTElement(new Vector(element.getDouble("x"), element.getDouble("y"), element.getDouble("z")));
|
||||||
tntElement.setDisabled(getBoolean(element, "disabled", false));
|
tntElement.setDisabled(element.getBooleanOrDefault("disabled", false));
|
||||||
tntElement.setMaterial(Material.valueOf(getString(element, "material", "TNT")));
|
tntElement.setMaterial(Material.valueOf(element.getStringOrDefault("material", "TNT")));
|
||||||
simulatorGroup.add(tntElement);
|
simulatorGroup.add(tntElement);
|
||||||
|
|
||||||
tntElement.add(loadPhase(element));
|
tntElement.add(loadPhase(element));
|
||||||
@@ -116,15 +112,15 @@ public class SimulatorFormatSimulatorLoader implements SimulatorLoader {
|
|||||||
return simulatorGroup;
|
return simulatorGroup;
|
||||||
}
|
}
|
||||||
|
|
||||||
private TNTPhase loadPhase(Map<?, ?> element) {
|
private TNTPhase loadPhase(YAPIONObject element) {
|
||||||
TNTPhase tntPhase = new TNTPhase();
|
TNTPhase tntPhase = new TNTPhase();
|
||||||
tntPhase.setLifetime(getInt(element, "fuseTicks", 80));
|
tntPhase.setLifetime(element.getIntOrDefault("fuseTicks", 80));
|
||||||
tntPhase.setCount(getInt(element, "count", 1));
|
tntPhase.setCount(element.getIntOrDefault("count", 1));
|
||||||
tntPhase.setTickOffset(getInt(element, "tickOffset", 0));
|
tntPhase.setTickOffset(element.getIntOrDefault("tickOffset", 0));
|
||||||
tntPhase.setXJump(getBoolean(element, "xVelocity", false));
|
tntPhase.setXJump(element.getBooleanOrDefault("xVelocity", false));
|
||||||
tntPhase.setYJump(getBoolean(element, "yVelocity", false));
|
tntPhase.setYJump(element.getBooleanOrDefault("yVelocity", false));
|
||||||
tntPhase.setZJump(getBoolean(element, "zVelocity", false));
|
tntPhase.setZJump(element.getBooleanOrDefault("zVelocity", false));
|
||||||
switch (getString(element, "order", "REPEATER")) {
|
switch (element.getStringOrDefault("order", "REPEATER")) {
|
||||||
case "REPEATER":
|
case "REPEATER":
|
||||||
tntPhase.setOrder(0);
|
tntPhase.setOrder(0);
|
||||||
break;
|
break;
|
||||||
@@ -137,8 +133,4 @@ public class SimulatorFormatSimulatorLoader implements SimulatorLoader {
|
|||||||
}
|
}
|
||||||
return tntPhase;
|
return tntPhase;
|
||||||
}
|
}
|
||||||
|
|
||||||
private double requireDouble(Map<?, ?> element, String key) {
|
|
||||||
return ((Number) element.get(key)).doubleValue();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
+33
-24
@@ -21,6 +21,9 @@ package de.steamwar.bausystem.features.simulator.storage;
|
|||||||
|
|
||||||
import de.steamwar.bausystem.features.simulator.data.Simulator;
|
import de.steamwar.bausystem.features.simulator.data.Simulator;
|
||||||
import lombok.experimental.UtilityClass;
|
import lombok.experimental.UtilityClass;
|
||||||
|
import yapion.hierarchy.output.FileOutput;
|
||||||
|
import yapion.hierarchy.types.YAPIONArray;
|
||||||
|
import yapion.hierarchy.types.YAPIONObject;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -33,42 +36,48 @@ public class SimulatorSaver {
|
|||||||
directory.mkdirs();
|
directory.mkdirs();
|
||||||
}
|
}
|
||||||
|
|
||||||
SimulatorConfig config = new SimulatorConfig();
|
YAPIONObject simulatorObject = new YAPIONObject();
|
||||||
config.setMaterial(simulator.getMaterial());
|
simulatorObject.add("material", simulator.getMaterial().name());
|
||||||
config.setAutoTrace(simulator.isAutoTrace());
|
simulatorObject.add("autoTrace", simulator.isAutoTrace());
|
||||||
config.setAutoTestblock(simulator.isAutoTestblock());
|
simulatorObject.add("autoTestblock", simulator.isAutoTestblock());
|
||||||
|
|
||||||
|
YAPIONArray groups = new YAPIONArray();
|
||||||
simulator.getGroups().forEach(group -> {
|
simulator.getGroups().forEach(group -> {
|
||||||
SimulatorConfig.Group groupConfig = new SimulatorConfig.Group();
|
YAPIONObject groupObject = new YAPIONObject();
|
||||||
groupConfig.setMaterial(group.getMaterial());
|
groupObject.add("material", group.getMaterial().name());
|
||||||
groupConfig.setDisabled(group.isDisabled());
|
groupObject.add("disabled", group.isDisabled());
|
||||||
|
|
||||||
|
YAPIONArray elements = new YAPIONArray();
|
||||||
group.getElements().forEach(element -> {
|
group.getElements().forEach(element -> {
|
||||||
SimulatorConfig.Element elementConfig = new SimulatorConfig.Element();
|
YAPIONObject elementObject = new YAPIONObject();
|
||||||
elementConfig.setType(element.getType());
|
elementObject.add("type", element.getType());
|
||||||
elementConfig.setMaterial(element.getMaterial());
|
elementObject.add("material", element.getMaterial().name());
|
||||||
elementConfig.setDisabled(element.isDisabled());
|
elementObject.add("disabled", element.isDisabled());
|
||||||
elementConfig.setX(element.getPosition().getX());
|
elementObject.add("x", element.getPosition().getX());
|
||||||
elementConfig.setY(element.getPosition().getY());
|
elementObject.add("y", element.getPosition().getY());
|
||||||
elementConfig.setZ(element.getPosition().getZ());
|
elementObject.add("z", element.getPosition().getZ());
|
||||||
element.saveExtra(elementConfig);
|
element.saveExtra(elementObject);
|
||||||
|
|
||||||
|
YAPIONArray phases = new YAPIONArray();
|
||||||
element.getPhases().forEach(phase -> {
|
element.getPhases().forEach(phase -> {
|
||||||
SimulatorConfig.Phase phaseConfig = new SimulatorConfig.Phase();
|
YAPIONObject phaseObject = new YAPIONObject();
|
||||||
phaseConfig.setTickOffset(phase.getTickOffset());
|
phaseObject.add("tickOffset", phase.getTickOffset());
|
||||||
phaseConfig.setLifetime(phase.getLifetime());
|
phaseObject.add("lifetime", phase.getLifetime());
|
||||||
phaseConfig.setOrder(phase.getOrder());
|
phaseObject.add("order", phase.getOrder());
|
||||||
phase.saveExtra(phaseConfig);
|
phase.saveExtra(phaseObject);
|
||||||
elementConfig.getPhases().add(phaseConfig);
|
phases.add(phaseObject);
|
||||||
});
|
});
|
||||||
groupConfig.getElements().add(elementConfig);
|
elementObject.add("phases", phases);
|
||||||
|
elements.add(elementObject);
|
||||||
});
|
});
|
||||||
config.getGroups().add(groupConfig);
|
groupObject.add("elements", elements);
|
||||||
|
groups.add(groupObject);
|
||||||
});
|
});
|
||||||
|
simulatorObject.add("groups", groups);
|
||||||
|
|
||||||
File file = new File(directory, simulator.getName() + ".sim");
|
File file = new File(directory, simulator.getName() + ".sim");
|
||||||
try {
|
try {
|
||||||
SimulatorConfig.STORE.save(file, config);
|
simulatorObject.toJSONLossy(new FileOutput(file)).close();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
// Ignore
|
// Ignore
|
||||||
}
|
}
|
||||||
|
|||||||
+21
-31
@@ -19,7 +19,6 @@
|
|||||||
|
|
||||||
package de.steamwar.bausystem.features.simulator.storage;
|
package de.steamwar.bausystem.features.simulator.storage;
|
||||||
|
|
||||||
import de.steamwar.bausystem.config.legacy.YapionReader;
|
|
||||||
import de.steamwar.bausystem.features.simulator.data.Simulator;
|
import de.steamwar.bausystem.features.simulator.data.Simulator;
|
||||||
import de.steamwar.bausystem.features.simulator.data.SimulatorGroup;
|
import de.steamwar.bausystem.features.simulator.data.SimulatorGroup;
|
||||||
import de.steamwar.bausystem.features.simulator.data.tnt.TNTElement;
|
import de.steamwar.bausystem.features.simulator.data.tnt.TNTElement;
|
||||||
@@ -27,23 +26,18 @@ import de.steamwar.bausystem.features.simulator.data.tnt.TNTPhase;
|
|||||||
import de.steamwar.sql.SteamwarUser;
|
import de.steamwar.sql.SteamwarUser;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
|
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;
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static de.steamwar.bausystem.config.legacy.YapionReader.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Loads the legacy per player .yapion files containing multiple simulators, they are
|
|
||||||
* deleted after loading and saved in the current format by the {@link SimulatorSaver}.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public class YAPIONFormatSimulatorLoader implements SimulatorLoader {
|
public class YAPIONFormatSimulatorLoader implements SimulatorLoader {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -52,10 +46,10 @@ public class YAPIONFormatSimulatorLoader implements SimulatorLoader {
|
|||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, Object> yapionObject;
|
YAPIONObject yapionObject;
|
||||||
try {
|
try {
|
||||||
yapionObject = YapionReader.parse(Files.readString(file.toPath(), StandardCharsets.UTF_8));
|
yapionObject = YAPIONParser.parse(file);
|
||||||
} catch (IllegalArgumentException | IOException e) {
|
} catch (YAPIONException | IOException e) {
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,28 +57,28 @@ public class YAPIONFormatSimulatorLoader implements SimulatorLoader {
|
|||||||
SteamwarUser steamwarUser = SteamwarUser.byId(Integer.parseInt(name));
|
SteamwarUser steamwarUser = SteamwarUser.byId(Integer.parseInt(name));
|
||||||
|
|
||||||
List<Simulator> simulators = new ArrayList<>();
|
List<Simulator> simulators = new ArrayList<>();
|
||||||
for (String s : yapionObject.keySet()) {
|
for (String s : yapionObject.getKeys()) {
|
||||||
String newName = steamwarUser.getUserName() + (s.isEmpty() ? "" : "_" + s);
|
String newName = steamwarUser.getUserName() + (s.isEmpty() ? "" : "_" + s);
|
||||||
List<Map<?, ?>> content = getObjects(yapionObject, s);
|
YAPIONArray content = yapionObject.getArray(s);
|
||||||
if (content.isEmpty()) continue;
|
if (content.isEmpty()) continue;
|
||||||
Simulator simulator = new Simulator(newName);
|
Simulator simulator = new Simulator(newName);
|
||||||
for (Map<?, ?> element : content) {
|
for (YAPIONObject element : content.streamObject().collect(Collectors.toList())) {
|
||||||
SimulatorGroup simulatorGroup = new SimulatorGroup();
|
SimulatorGroup simulatorGroup = new SimulatorGroup();
|
||||||
simulator.add(simulatorGroup);
|
simulator.add(simulatorGroup);
|
||||||
|
|
||||||
TNTElement tntElement = new TNTElement(new Vector(requireDouble(element, "positionX"), requireDouble(element, "positionY"), requireDouble(element, "positionZ")));
|
TNTElement tntElement = new TNTElement(new Vector(element.getDouble("positionX"), element.getDouble("positionY"), element.getDouble("positionZ")));
|
||||||
tntElement.setDisabled(getBoolean(element, "disabled", false)); // IDK if this existed back then?
|
tntElement.setDisabled(element.getBooleanOrDefault("disabled", false)); // IDK if this existed back then?
|
||||||
tntElement.setMaterial(Material.valueOf(getString(element, "material", "TNT")));
|
tntElement.setMaterial(Material.valueOf(element.getStringOrDefault("material", "TNT")));
|
||||||
simulatorGroup.add(tntElement);
|
simulatorGroup.add(tntElement);
|
||||||
|
|
||||||
TNTPhase tntPhase = new TNTPhase();
|
TNTPhase tntPhase = new TNTPhase();
|
||||||
tntPhase.setLifetime(getInt(element, "fuseTicks", 80));
|
tntPhase.setLifetime(element.getIntOrDefault("fuseTicks", 80));
|
||||||
tntPhase.setCount(getInt(element, "count", 1));
|
tntPhase.setCount(element.getIntOrDefault("count", 1));
|
||||||
tntPhase.setTickOffset(getInt(element, "tickOffset", 0));
|
tntPhase.setTickOffset(element.getIntOrDefault("tickOffset", 0));
|
||||||
tntPhase.setXJump(getBoolean(element, "xVelocity", false));
|
tntPhase.setXJump(element.getBooleanOrDefault("xVelocity", false));
|
||||||
tntPhase.setYJump(getBoolean(element, "yVelocity", false));
|
tntPhase.setYJump(element.getBooleanOrDefault("yVelocity", false));
|
||||||
tntPhase.setZJump(getBoolean(element, "zVelocity", false));
|
tntPhase.setZJump(element.getBooleanOrDefault("zVelocity", false));
|
||||||
tntPhase.setOrder(getBoolean(element, "comparator", false) ? 2 : 0);
|
tntPhase.setOrder(element.getBooleanOrDefault("comparator", false) ? 2 : 0);
|
||||||
tntElement.add(tntPhase);
|
tntElement.add(tntPhase);
|
||||||
}
|
}
|
||||||
simulators.add(simulator);
|
simulators.add(simulator);
|
||||||
@@ -93,8 +87,4 @@ public class YAPIONFormatSimulatorLoader implements SimulatorLoader {
|
|||||||
file.delete();
|
file.delete();
|
||||||
return Optional.of(simulators);
|
return Optional.of(simulators);
|
||||||
}
|
}
|
||||||
|
|
||||||
private double requireDouble(Map<?, ?> element, String key) {
|
|
||||||
return ((Number) element.get(key)).doubleValue();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
-64
@@ -1,64 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of the SteamWar software.
|
|
||||||
*
|
|
||||||
* Copyright (C) 2026 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.features.slaves.laufbau;
|
|
||||||
|
|
||||||
import de.steamwar.bausystem.config.ConfigStore;
|
|
||||||
import de.steamwar.bausystem.config.VersionedConfig;
|
|
||||||
import de.steamwar.bausystem.features.slaves.laufbau.converter.LaufbauConfigV1ToV2Converter;
|
|
||||||
import lombok.AccessLevel;
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.Setter;
|
|
||||||
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The current laufbau config of a player. It is stored as JSON, fields missing
|
|
||||||
* in the stored JSON keep the default value of their initializer, so adding a
|
|
||||||
* new field does not need a new version.
|
|
||||||
* <p>
|
|
||||||
* When a field gets removed, renamed or its meaning changes, copy this class
|
|
||||||
* to LaufbauConfigV{@link #VERSION} (without the {@link #STORE}), increase {@link #VERSION}, write a
|
|
||||||
* {@link de.steamwar.bausystem.config.ConfigConverter} from the copy to
|
|
||||||
* this class and register it in the {@link #STORE}.
|
|
||||||
*/
|
|
||||||
@Getter
|
|
||||||
@Setter
|
|
||||||
public class LaufbauConfig implements VersionedConfig {
|
|
||||||
|
|
||||||
public static final int VERSION = 2;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* LaufbauConfigV1 is stored as Base64 of gzipped YAPION, the current version as JSON
|
|
||||||
*/
|
|
||||||
public static final ConfigStore<LaufbauConfig> STORE = new ConfigStore<>(LaufbauConfig.class, VERSION, LaufbauConfig::new)
|
|
||||||
.legacy(s -> !s.startsWith("{"), LaufbauConfigV1::parse)
|
|
||||||
.converter(new LaufbauConfigV1ToV2Converter())
|
|
||||||
.userConfig("bausystem-laufbau")
|
|
||||||
.removeIf(config -> config.getDeactivated().isEmpty());
|
|
||||||
|
|
||||||
@Setter(AccessLevel.NONE)
|
|
||||||
protected int version = VERSION;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Identifiers of the deactivated {@link BlockBoundingBox}es, see {@link LaufbauUtils#identifier(BlockBoundingBox)}
|
|
||||||
*/
|
|
||||||
protected Set<String> deactivated = new HashSet<>();
|
|
||||||
}
|
|
||||||
-65
@@ -1,65 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of the SteamWar software.
|
|
||||||
*
|
|
||||||
* Copyright (C) 2026 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.features.slaves.laufbau;
|
|
||||||
|
|
||||||
import de.steamwar.bausystem.config.VersionedConfig;
|
|
||||||
import de.steamwar.bausystem.config.legacy.YapionReader;
|
|
||||||
import lombok.AccessLevel;
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.Setter;
|
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.UncheckedIOException;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.util.Base64;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.zip.GZIPInputStream;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The legacy laufbau config that was stored as Base64 of the gzipped YAPION,
|
|
||||||
* an object with the deactivated identifiers as keys.
|
|
||||||
*/
|
|
||||||
@Getter
|
|
||||||
@Setter
|
|
||||||
@Deprecated
|
|
||||||
public class LaufbauConfigV1 implements VersionedConfig {
|
|
||||||
|
|
||||||
public static final int VERSION = 1;
|
|
||||||
|
|
||||||
@Setter(AccessLevel.NONE)
|
|
||||||
protected int version = VERSION;
|
|
||||||
|
|
||||||
protected Set<String> deactivated = new HashSet<>();
|
|
||||||
|
|
||||||
public static LaufbauConfigV1 parse(String base64) {
|
|
||||||
String yapion;
|
|
||||||
try (InputStream inputStream = new GZIPInputStream(new ByteArrayInputStream(Base64.getDecoder().decode(base64)))) {
|
|
||||||
yapion = new String(inputStream.readAllBytes(), StandardCharsets.UTF_8);
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new UncheckedIOException(e);
|
|
||||||
}
|
|
||||||
LaufbauConfigV1 config = new LaufbauConfigV1();
|
|
||||||
config.deactivated.addAll(YapionReader.parse(yapion).keySet());
|
|
||||||
return config;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+48
-5
@@ -20,22 +20,63 @@
|
|||||||
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.core.SWPlayer;
|
||||||
import de.steamwar.inventory.SWItem;
|
import de.steamwar.inventory.SWItem;
|
||||||
|
import de.steamwar.sql.UserConfig;
|
||||||
|
import lombok.Cleanup;
|
||||||
import lombok.SneakyThrows;
|
import lombok.SneakyThrows;
|
||||||
import lombok.experimental.UtilityClass;
|
import lombok.experimental.UtilityClass;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
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.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Base64;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.zip.GZIPInputStream;
|
||||||
|
import java.util.zip.GZIPOutputStream;
|
||||||
|
|
||||||
@UtilityClass
|
@UtilityClass
|
||||||
public class LaufbauUtils {
|
public class LaufbauUtils {
|
||||||
|
|
||||||
|
public static class LaufbauComponent implements SWPlayer.Component {
|
||||||
|
|
||||||
|
private YAPIONObject yapionObject = new YAPIONObject();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@SneakyThrows
|
||||||
|
public void onMount(SWPlayer player) {
|
||||||
|
String config = UserConfig.getConfig(player.getPlayer().getUniqueId(), "bausystem-laufbau");
|
||||||
|
if (config == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
byte[] bytes = Base64.getDecoder().decode(config);
|
||||||
|
@Cleanup GZIPInputStream gzipInputStream = new GZIPInputStream(new ByteArrayInputStream(bytes));
|
||||||
|
yapionObject = new YAPIONParser(gzipInputStream, new StreamOptions().stopOnStreamEnd(true)).parse().result();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@SneakyThrows
|
||||||
|
public void onUnmount(SWPlayer player) {
|
||||||
|
if (yapionObject.isEmpty()) {
|
||||||
|
UserConfig.removePlayerConfig(player.getPlayer().getUniqueId(), "bausystem-laufbau");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
@Cleanup ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
||||||
|
@Cleanup GZIPOutputStream gzipOutputStream = new GZIPOutputStream(byteArrayOutputStream);
|
||||||
|
yapionObject.toYAPION(new StreamOutput(gzipOutputStream)).close();
|
||||||
|
UserConfig.updatePlayerConfig(player.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) {
|
||||||
return new Cuboid(pixelToBlock(pixelX), pixelToBlock(pixelY), pixelToBlock(pixelZ), pixelToBlock(pixelDX), pixelToBlock(pixelDY), pixelToBlock(pixelDZ));
|
return new Cuboid(pixelToBlock(pixelX), pixelToBlock(pixelY), pixelToBlock(pixelZ), pixelToBlock(pixelDX), pixelToBlock(pixelDY), pixelToBlock(pixelDZ));
|
||||||
}
|
}
|
||||||
@@ -82,7 +123,7 @@ public class LaufbauUtils {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
String identifier = identifier(bb);
|
String identifier = identifier(bb);
|
||||||
return LaufbauConfig.STORE.get(p).getDeactivated().contains(identifier);
|
return SWPlayer.of(p).getComponentOrDefault(LaufbauComponent.class, LaufbauComponent::new).yapionObject.containsKey(identifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
@@ -91,9 +132,11 @@ public class LaufbauUtils {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String identifier = identifier(bb);
|
String identifier = identifier(bb);
|
||||||
Set<String> deactivated = LaufbauConfig.STORE.get(p).getDeactivated();
|
YAPIONObject yapionObject = SWPlayer.of(p).getComponentOrDefault(LaufbauComponent.class, LaufbauComponent::new).yapionObject;
|
||||||
if (!deactivated.remove(identifier)) {
|
if (yapionObject.containsKey(identifier)) {
|
||||||
deactivated.add(identifier);
|
yapionObject.remove(identifier);
|
||||||
|
} else {
|
||||||
|
yapionObject.put(identifier, new YAPIONObject());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
-40
@@ -1,40 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of the SteamWar software.
|
|
||||||
*
|
|
||||||
* Copyright (C) 2026 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.features.slaves.laufbau.converter;
|
|
||||||
|
|
||||||
import de.steamwar.bausystem.config.ConfigConverter;
|
|
||||||
import de.steamwar.bausystem.features.slaves.laufbau.LaufbauConfig;
|
|
||||||
import de.steamwar.bausystem.features.slaves.laufbau.LaufbauConfigV1;
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public class LaufbauConfigV1ToV2Converter implements ConfigConverter<LaufbauConfigV1, LaufbauConfig> {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int version() {
|
|
||||||
return LaufbauConfigV1.VERSION;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public LaufbauConfig convert(LaufbauConfigV1 old) {
|
|
||||||
LaufbauConfig config = new LaufbauConfig();
|
|
||||||
config.getDeactivated().addAll(old.getDeactivated());
|
|
||||||
return config;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+2
-2
@@ -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.STORE.get(p).isSmartPlace();
|
boolean smartPlace = Config.getInstance().get(p).getPlainValueOrDefault("smartPlace", false);
|
||||||
Config.STORE.get(p).setSmartPlace(!smartPlace);
|
Config.getInstance().get(p).put("smartPlace", !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);
|
||||||
|
|||||||
+77
-69
@@ -19,10 +19,12 @@
|
|||||||
|
|
||||||
package de.steamwar.bausystem.features.smartplace;
|
package de.steamwar.bausystem.features.smartplace;
|
||||||
|
|
||||||
|
import com.comphenix.tinyprotocol.TinyProtocol;
|
||||||
import de.steamwar.bausystem.BauSystem;
|
import de.steamwar.bausystem.BauSystem;
|
||||||
import de.steamwar.bausystem.Permission;
|
import de.steamwar.bausystem.Permission;
|
||||||
import de.steamwar.bausystem.configplayer.Config;
|
import de.steamwar.bausystem.configplayer.Config;
|
||||||
import de.steamwar.linkage.Linked;
|
import de.steamwar.linkage.Linked;
|
||||||
|
import net.minecraft.network.protocol.game.ServerboundUseItemOnPacket;
|
||||||
import org.bukkit.*;
|
import org.bukkit.*;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.BlockFace;
|
import org.bukkit.block.BlockFace;
|
||||||
@@ -32,98 +34,104 @@ import org.bukkit.block.data.*;
|
|||||||
import org.bukkit.block.data.type.*;
|
import org.bukkit.block.data.type.*;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.block.Action;
|
import org.bukkit.event.block.Action;
|
||||||
import org.bukkit.event.block.BlockPlaceEvent;
|
import org.bukkit.event.block.BlockPlaceEvent;
|
||||||
import org.bukkit.event.player.PlayerInteractEvent;
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.util.RayTraceResult;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Linked
|
@Linked
|
||||||
public class SmartPlaceListener implements Listener {
|
public class SmartPlaceListener implements Listener {
|
||||||
|
|
||||||
private static final Set<Material> IGNORED = Set.of(Material.TNT, Material.REDSTONE_ORE, Material.BEEHIVE, Material.SEA_PICKLE);
|
private static final Set<Material> CONTAINERS = new HashSet<>();
|
||||||
|
private static final Set<Material> IGNORED = new HashSet<>();
|
||||||
|
|
||||||
private static final Set<UUID> FAKED_SNEAK = new HashSet<>();
|
static {
|
||||||
|
World world = Bukkit.getWorlds().get(0);
|
||||||
private static boolean isContainer(Block block) {
|
Block block = world.getBlockAt(0, 0, 0);
|
||||||
if (block.getType() == Material.COMPARATOR) return false;
|
block.setType(Material.AIR);
|
||||||
if (block.getType() == Material.GRINDSTONE) return true;
|
BlockState state = block.getState();
|
||||||
return block.getState() instanceof TileState || block.getBlockData() instanceof Stairs;
|
for (Material material : Material.values()) {
|
||||||
}
|
if (material.isLegacy()) continue;
|
||||||
|
if (!material.isInteractable() && !material.isBlock()) continue;
|
||||||
private static boolean isReallySneaking(Player player) {
|
BlockData blockData = material.createBlockData();
|
||||||
return player.isSneaking() && !FAKED_SNEAK.contains(player.getUniqueId());
|
block.setBlockData(blockData);
|
||||||
}
|
if (block.getState() instanceof TileState) {
|
||||||
|
CONTAINERS.add(material);
|
||||||
private static boolean shouldSmartPlace(Block block, BlockFace blockFace, Material heldType) {
|
} else if (blockData instanceof Stairs) {
|
||||||
boolean smartPlace = false;
|
CONTAINERS.add(material);
|
||||||
if (block.getType().isInteractable() || block.getType() == Material.NOTE_BLOCK) {
|
}
|
||||||
smartPlace = true;
|
state.update(true, false);
|
||||||
}
|
}
|
||||||
if (isContainer(block)) {
|
CONTAINERS.add(Material.GRINDSTONE);
|
||||||
if (heldType == Material.TNT) {
|
CONTAINERS.remove(Material.COMPARATOR);
|
||||||
if (block.getType() == Material.CHEST || block.getType() == Material.BARREL || block.getType().name().endsWith("SHULKER_BOX")) {
|
state.update(true, false);
|
||||||
smartPlace = false;
|
|
||||||
|
IGNORED.add(Material.TNT);
|
||||||
|
IGNORED.add(Material.REDSTONE_ORE);
|
||||||
|
IGNORED.add(Material.BEEHIVE);
|
||||||
|
IGNORED.add(Material.SEA_PICKLE);
|
||||||
|
IGNORED.remove(Material.STONE);
|
||||||
|
IGNORED.remove(Material.BARRIER);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final Set<Player> SMART_PLACING = new HashSet<>();
|
||||||
|
private static final Set<Player> WAS_EXECUTED = new HashSet<>();
|
||||||
|
|
||||||
|
public SmartPlaceListener() {
|
||||||
|
TinyProtocol.instance.addFilter(ServerboundUseItemOnPacket.class, (player, packet) -> {
|
||||||
|
if (!Permission.BUILD.hasPermission(player)) return packet;
|
||||||
|
if (!Config.getInstance().get(player).getPlainValueOrDefault("smartPlace", false)) return packet;
|
||||||
|
RayTraceResult rayTraceResult = player.rayTraceBlocks(6);
|
||||||
|
Block block = rayTraceResult != null ? rayTraceResult.getHitBlock() : null;
|
||||||
|
BlockFace blockFace = rayTraceResult != null ? rayTraceResult.getHitBlockFace() : null;
|
||||||
|
boolean shouldSneak = false;
|
||||||
|
if (block != null) {
|
||||||
|
ItemStack itemStack = player.getInventory().getItemInMainHand();
|
||||||
|
if (block.getType().isInteractable() || block.getType() == Material.NOTE_BLOCK) {
|
||||||
|
shouldSneak = true;
|
||||||
|
}
|
||||||
|
if (CONTAINERS.contains(block.getType())) {
|
||||||
|
if (itemStack.getType() == Material.TNT) {
|
||||||
|
if (block.getType() == Material.CHEST || block.getType() == Material.BARREL || block.getType().name().endsWith("SHULKER_BOX")) {
|
||||||
|
shouldSneak = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
shouldSneak = false;
|
||||||
|
}
|
||||||
|
if (IGNORED.contains(block.getType())) {
|
||||||
|
shouldSneak = false;
|
||||||
|
}
|
||||||
|
if (blockFace == BlockFace.DOWN && (block.getType() == Material.REPEATER || block.getType() == Material.COMPARATOR) && itemStack.getType().isSolid()) {
|
||||||
|
shouldSneak = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
boolean sneaking = player.isSneaking();
|
||||||
smartPlace = false;
|
if (sneaking) SMART_PLACING.add(player);
|
||||||
}
|
player.setSneaking(shouldSneak || sneaking);
|
||||||
if (IGNORED.contains(block.getType())) {
|
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> {
|
||||||
smartPlace = false;
|
SMART_PLACING.remove(player);
|
||||||
}
|
player.setSneaking(sneaking);
|
||||||
if (blockFace == BlockFace.DOWN && (block.getType() == Material.REPEATER || block.getType() == Material.COMPARATOR) && heldType.isSolid()) {
|
}, 0);
|
||||||
smartPlace = true;
|
return packet;
|
||||||
}
|
|
||||||
return smartPlace;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean smartPlaceEnabled(Player player) {
|
|
||||||
return Config.STORE.get(player).isSmartPlace();
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOW)
|
|
||||||
public void onSmartPlace(PlayerInteractEvent event) {
|
|
||||||
if (event.getAction() != Action.RIGHT_CLICK_BLOCK) return;
|
|
||||||
Player player = event.getPlayer();
|
|
||||||
if (player.getGameMode() == GameMode.SPECTATOR) return;
|
|
||||||
if (!Permission.BUILD.hasPermission(player)) return;
|
|
||||||
if (!smartPlaceEnabled(player)) return;
|
|
||||||
if (player.isSneaking()) return;
|
|
||||||
|
|
||||||
ItemStack itemStack = event.getItem();
|
|
||||||
if (itemStack == null || itemStack.getType().isAir()) return;
|
|
||||||
if (!shouldSmartPlace(event.getClickedBlock(), event.getBlockFace(), itemStack.getType())) return;
|
|
||||||
|
|
||||||
player.setSneaking(true);
|
|
||||||
FAKED_SNEAK.add(player.getUniqueId());
|
|
||||||
Bukkit.getScheduler().runTask(BauSystem.getInstance(), () -> {
|
|
||||||
if (FAKED_SNEAK.remove(player.getUniqueId())) {
|
|
||||||
player.setSneaking(false);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onQuit(PlayerQuitEvent event) {
|
|
||||||
FAKED_SNEAK.remove(event.getPlayer().getUniqueId());
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||||
if (!Permission.BUILD.hasPermission(event.getPlayer())) return;
|
if (!Permission.BUILD.hasPermission(event.getPlayer())) return;
|
||||||
if (!smartPlaceEnabled(event.getPlayer())) return;
|
if (!Config.getInstance().get(event.getPlayer()).getPlainValueOrDefault("smartPlace", false)) return;
|
||||||
|
WAS_EXECUTED.add(event.getPlayer());
|
||||||
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;
|
||||||
if (!isReallySneaking(event.getPlayer())) return;
|
if (!event.getPlayer().isSneaking()) return;
|
||||||
if (event.getClickedBlock().getType() != Material.REPEATER) return;
|
if (event.getClickedBlock().getType() != Material.REPEATER) return;
|
||||||
if ((event.getItem() == null || event.getItem().getType() == Material.REPEATER)) {
|
if ((event.getItem() == null || event.getItem().getType() == Material.REPEATER)) {
|
||||||
Repeater repeater = (Repeater) event.getClickedBlock().getBlockData();
|
Repeater repeater = (Repeater) event.getClickedBlock().getBlockData();
|
||||||
@@ -138,9 +146,9 @@ public class SmartPlaceListener implements Listener {
|
|||||||
@EventHandler
|
@EventHandler
|
||||||
public void onBlockPlace(BlockPlaceEvent event) {
|
public void onBlockPlace(BlockPlaceEvent event) {
|
||||||
if (!Permission.BUILD.hasPermission(event.getPlayer())) return;
|
if (!Permission.BUILD.hasPermission(event.getPlayer())) return;
|
||||||
if (!smartPlaceEnabled(event.getPlayer())) return;
|
if (!Config.getInstance().get(event.getPlayer()).getPlainValueOrDefault("smartPlace", false)) return;
|
||||||
if (!isReallySneaking(event.getPlayer())) {
|
if (!SMART_PLACING.contains(event.getPlayer())) {
|
||||||
if (isContainer(event.getBlockAgainst())) {
|
if (CONTAINERS.contains(event.getBlockAgainst().getType())) {
|
||||||
SoundGroup soundGroup = event.getBlockPlaced().getBlockData().getSoundGroup();
|
SoundGroup soundGroup = event.getBlockPlaced().getBlockData().getSoundGroup();
|
||||||
event.getPlayer().playSound(event.getBlockPlaced().getLocation(), soundGroup.getPlaceSound(), soundGroup.getVolume() * 0.8F, soundGroup.getPitch() * 0.8F);
|
event.getPlayer().playSound(event.getBlockPlaced().getLocation(), soundGroup.getPlaceSound(), soundGroup.getVolume() * 0.8F, soundGroup.getPitch() * 0.8F);
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-3
@@ -35,15 +35,18 @@ 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) {
|
||||||
return Config.STORE.get(p).isBlockCounter();
|
if (!Config.getInstance().get(p).containsKey("blockCounter")) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return Config.getInstance().get(p).getPlainValue("blockCounter");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void enable(final Player p) {
|
public void enable(final Player p) {
|
||||||
Config.STORE.get(p).setBlockCounter(true);
|
Config.getInstance().get(p).put("blockCounter", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void disable(final Player p) {
|
public void disable(final Player p) {
|
||||||
Config.STORE.get(p).setBlockCounter(false);
|
Config.getInstance().get(p).put("blockCounter", 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) {
|
||||||
|
|||||||
+4
-1
@@ -36,10 +36,13 @@ import org.bukkit.entity.Player;
|
|||||||
import org.bukkit.util.Transformation;
|
import org.bukkit.util.Transformation;
|
||||||
import org.joml.Quaternionf;
|
import org.joml.Quaternionf;
|
||||||
import org.joml.Vector3f;
|
import org.joml.Vector3f;
|
||||||
|
import yapion.hierarchy.types.YAPIONValue;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import static de.steamwar.bausystem.features.util.TNTClickListener.TNT_CLICK_DETAILS;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wrapper for the rendering of a record bundle
|
* Wrapper for the rendering of a record bundle
|
||||||
*/
|
*/
|
||||||
@@ -99,7 +102,7 @@ public class TraceEntity extends RBlockDisplay {
|
|||||||
* @param player the player the message should be printed for
|
* @param player the player the message should be printed for
|
||||||
*/
|
*/
|
||||||
public void printIntoChat(Player player) {
|
public void printIntoChat(Player player) {
|
||||||
if (!Config.STORE.get(player).isTntClickDetails()) {
|
if (!Config.getInstance().get(player).getOrSetDefault(TNT_CLICK_DETAILS, new YAPIONValue<>(true)).asBoolean().orElse(true)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
TNTPoint representative = records.get(0);
|
TNTPoint representative = records.get(0);
|
||||||
|
|||||||
+5
-4
@@ -30,6 +30,7 @@ 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 {
|
||||||
@@ -40,15 +41,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) {
|
||||||
Config config = Config.STORE.get(p);
|
YAPIONObject yapionObject = Config.getInstance().get(p);
|
||||||
boolean value = !config.isNightVision();
|
boolean value = !yapionObject.getBooleanOrDefault("nightvision", false);
|
||||||
config.setNightVision(value);
|
yapionObject.put("nightvision", value);
|
||||||
setNightVision(p, value);
|
setNightVision(p, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||||
setNightVision(event.getPlayer(), Config.STORE.get(event.getPlayer()).isNightVision());
|
setNightVision(event.getPlayer(), Config.getInstance().get(event.getPlayer()).getBooleanOrDefault("nightvision", false));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setNightVision(Player p, boolean value) {
|
private void setNightVision(Player p, boolean value) {
|
||||||
|
|||||||
+87
-29
@@ -22,71 +22,122 @@ package de.steamwar.bausystem.features.util;
|
|||||||
import com.comphenix.tinyprotocol.TinyProtocol;
|
import com.comphenix.tinyprotocol.TinyProtocol;
|
||||||
import com.mojang.authlib.GameProfile;
|
import com.mojang.authlib.GameProfile;
|
||||||
import de.steamwar.bausystem.BauSystem;
|
import de.steamwar.bausystem.BauSystem;
|
||||||
|
import de.steamwar.bausystem.features.tpslimit.TPSUtils;
|
||||||
import de.steamwar.bausystem.utils.BauMemberUpdateEvent;
|
import de.steamwar.bausystem.utils.BauMemberUpdateEvent;
|
||||||
import de.steamwar.command.SWCommand;
|
import de.steamwar.command.SWCommand;
|
||||||
import de.steamwar.core.ProtocolWrapper;
|
import de.steamwar.core.ProtocolWrapper;
|
||||||
import de.steamwar.core.SWPlayer;
|
import de.steamwar.core.SWPlayer;
|
||||||
import de.steamwar.linkage.Linked;
|
import de.steamwar.linkage.Linked;
|
||||||
import io.papermc.paper.event.player.PlayerFailMoveEvent;
|
import net.minecraft.network.protocol.game.*;
|
||||||
import net.minecraft.network.protocol.game.ClientboundGameEventPacket;
|
import net.minecraft.world.entity.player.Abilities;
|
||||||
|
import net.minecraft.world.level.GameType;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
|
import org.bukkit.craftbukkit.entity.CraftPlayer;
|
||||||
|
import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
||||||
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.block.BlockCanBuildEvent;
|
import org.bukkit.event.block.BlockCanBuildEvent;
|
||||||
import org.bukkit.event.player.PlayerGameModeChangeEvent;
|
import org.bukkit.event.player.PlayerGameModeChangeEvent;
|
||||||
|
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||||
import org.bukkit.event.player.PlayerToggleFlightEvent;
|
import org.bukkit.event.player.PlayerToggleFlightEvent;
|
||||||
|
|
||||||
|
import java.util.function.BiFunction;
|
||||||
|
|
||||||
@Linked
|
@Linked
|
||||||
public class NoClipCommand extends SWCommand implements Listener {
|
public class NoClipCommand extends SWCommand implements Listener {
|
||||||
|
|
||||||
public static class NoClipData implements SWPlayer.Component {
|
public static class NoClipData implements SWPlayer.Component {
|
||||||
|
private long lastTick = -1;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onUnmount(SWPlayer swPlayer) {
|
public void onUnmount(SWPlayer player) {
|
||||||
Player player = swPlayer.getPlayer();
|
player.getPlayer().setGameMode(GameMode.CREATIVE);
|
||||||
showClientGameMode(player, GameMode.CREATIVE, GameMode.CREATIVE);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public NoClipCommand() {
|
public NoClipCommand() {
|
||||||
super("noclip", "nc");
|
super("noclip", "nc");
|
||||||
|
|
||||||
|
BiFunction<Player, ServerboundMovePlayerPacket, Object> first = (player, o) -> {
|
||||||
|
NoClipData noClipData = SWPlayer.of(player).getComponent(NoClipData.class).orElse(null);
|
||||||
|
if (noClipData == null) return o;
|
||||||
|
if (noClipData.lastTick == TPSUtils.currentTick.get()) return o;
|
||||||
|
setInternalGameMode(player, GameMode.SPECTATOR);
|
||||||
|
noClipData.lastTick = TPSUtils.currentTick.get();
|
||||||
|
return o;
|
||||||
|
};
|
||||||
|
TinyProtocol.instance.addFilter(ServerboundMovePlayerPacket.Pos.class, first);
|
||||||
|
TinyProtocol.instance.addFilter(ServerboundMovePlayerPacket.PosRot.class, first);
|
||||||
|
|
||||||
|
BiFunction<Player, Object, Object> second = (player, o) -> {
|
||||||
|
NoClipData noClipData = SWPlayer.of(player).getComponent(NoClipData.class).orElse(null);
|
||||||
|
if (noClipData == null) return o;
|
||||||
|
setInternalGameMode(player, GameMode.CREATIVE);
|
||||||
|
noClipData.lastTick = TPSUtils.currentTick.get();
|
||||||
|
return o;
|
||||||
|
};
|
||||||
|
TinyProtocol.instance.addFilter(ServerboundUseItemOnPacket.class, second);
|
||||||
|
TinyProtocol.instance.addFilter(ServerboundPlayerActionPacket.class, second);
|
||||||
|
TinyProtocol.instance.addFilter(ServerboundContainerClickPacket.class, second);
|
||||||
|
|
||||||
|
BiFunction<Player, ServerboundSetCreativeModeSlotPacket, Object> third = (player, o) -> {
|
||||||
|
if (SWPlayer.of(player).hasComponent(NoClipData.class)) {
|
||||||
|
int index = o.slotNum();
|
||||||
|
if (index >= 36 && index <= 44) {
|
||||||
|
index -= 36;
|
||||||
|
} else if (index > 44) {
|
||||||
|
index -= 5;
|
||||||
|
} else if (index <= 8) {
|
||||||
|
index = index - 8 + 36;
|
||||||
|
}
|
||||||
|
player.getInventory().setItem(index, CraftItemStack.asBukkitCopy(o.itemStack()));
|
||||||
|
if (index < 9) player.getInventory().setHeldItemSlot(index);
|
||||||
|
player.updateInventory();
|
||||||
|
}
|
||||||
|
return o;
|
||||||
|
};
|
||||||
|
TinyProtocol.instance.addFilter(ServerboundSetCreativeModeSlotPacket.class, third);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Register
|
private void setInternalGameMode(Player player, GameMode gameMode) {
|
||||||
|
((CraftPlayer) player).getHandle().gameMode.gameModeForPlayer = GameType.byId(gameMode.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Register(help = true)
|
||||||
public void genericCommand(@Validator Player player) {
|
public void genericCommand(@Validator Player player) {
|
||||||
SWPlayer swPlayer = SWPlayer.of(player);
|
SWPlayer swPlayer = SWPlayer.of(player);
|
||||||
if (swPlayer.hasComponent(NoClipData.class)) {
|
if (swPlayer.hasComponent(NoClipData.class)) {
|
||||||
swPlayer.removeComponent(NoClipData.class);
|
swPlayer.removeComponent(NoClipData.class);
|
||||||
} else {
|
} else {
|
||||||
player.setGameMode(GameMode.CREATIVE);
|
player.setGameMode(GameMode.SPECTATOR);
|
||||||
player.setAllowFlight(true);
|
Abilities abilities = (((CraftPlayer) player).getHandle()).getAbilities();
|
||||||
player.setFlying(true);
|
abilities.mayBuild = true;
|
||||||
|
abilities.mayfly = true;
|
||||||
|
|
||||||
swPlayer.setComponent(new NoClipData());
|
swPlayer.setComponent(new NoClipData());
|
||||||
BauSystem.MESSAGE.send("OTHER_NOCLIP_SLOT_INFO", player);
|
BauSystem.MESSAGE.send("OTHER_NOCLIP_SLOT_INFO", player);
|
||||||
showClientGameMode(player, GameMode.CREATIVE, GameMode.SPECTATOR);
|
TinyProtocol.instance.sendPacket(player, new ClientboundGameEventPacket(ClientboundGameEventPacket.CHANGE_GAME_MODE, 1F));
|
||||||
|
pseudoGameMode(player, GameMode.SPECTATOR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerFailMove(PlayerFailMoveEvent event) {
|
|
||||||
if (event.getFailReason() != PlayerFailMoveEvent.FailReason.CLIPPED_INTO_BLOCK) return;
|
|
||||||
if (!SWPlayer.of(event.getPlayer()).hasComponent(NoClipData.class)) return;
|
|
||||||
event.setAllowed(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onBauMemberUpdate(BauMemberUpdateEvent event) {
|
public void onBauMemberUpdate(BauMemberUpdateEvent event) {
|
||||||
event.getNewSpectator().forEach(player -> SWPlayer.of(player).removeComponent(NoClipData.class));
|
event.getNewSpectator().forEach(player -> {
|
||||||
|
SWPlayer.of(player).removeComponent(NoClipData.class);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler(ignoreCancelled = true)
|
||||||
public void onPlayerGameModeChange(PlayerGameModeChangeEvent event) {
|
public void onPlayerGameModeChange(PlayerGameModeChangeEvent event) {
|
||||||
if (SWPlayer.of(event.getPlayer()).hasComponent(NoClipData.class)) {
|
if (SWPlayer.of(event.getPlayer()).hasComponent(NoClipData.class)) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler(ignoreCancelled = true)
|
||||||
public void onBlock(BlockCanBuildEvent event) {
|
public void onBlock(BlockCanBuildEvent event) {
|
||||||
if (event.getPlayer() == null) return;
|
if (event.getPlayer() == null) return;
|
||||||
if (SWPlayer.of(event.getPlayer()).hasComponent(NoClipData.class)) {
|
if (SWPlayer.of(event.getPlayer()).hasComponent(NoClipData.class)) {
|
||||||
@@ -94,7 +145,7 @@ public class NoClipCommand extends SWCommand implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler(ignoreCancelled = true)
|
||||||
public void onPlayerToggleFlight(PlayerToggleFlightEvent event) {
|
public void onPlayerToggleFlight(PlayerToggleFlightEvent event) {
|
||||||
if (SWPlayer.of(event.getPlayer()).hasComponent(NoClipData.class)) {
|
if (SWPlayer.of(event.getPlayer()).hasComponent(NoClipData.class)) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
@@ -102,13 +153,20 @@ public class NoClipCommand extends SWCommand implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@EventHandler(ignoreCancelled = true)
|
||||||
* @param player player
|
public void onPlayerTeleport(PlayerTeleportEvent event) {
|
||||||
* @param localMode GameMode for breaking and placing
|
if (event.getCause() != PlayerTeleportEvent.TeleportCause.SPECTATE) {
|
||||||
* @param listedMode GameMode for noPhysics
|
return;
|
||||||
*/
|
}
|
||||||
private static void showClientGameMode(Player player, GameMode localMode, GameMode listedMode) {
|
if (SWPlayer.of(event.getPlayer()).hasComponent(NoClipData.class)) {
|
||||||
TinyProtocol.instance.sendPacket(player, new ClientboundGameEventPacket(ClientboundGameEventPacket.CHANGE_GAME_MODE, localMode.getValue()));
|
event.setCancelled(true);
|
||||||
TinyProtocol.instance.sendPacket(player, ProtocolWrapper.playerInfoPacketConstructor(ProtocolWrapper.PlayerInfoAction.GAMEMODE, new GameProfile(player.getUniqueId(), player.getName()), listedMode));
|
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> {
|
||||||
|
event.getPlayer().setSpectatorTarget(null);
|
||||||
|
}, 1L);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void pseudoGameMode(Player player, GameMode gameMode) {
|
||||||
|
TinyProtocol.instance.sendPacket(player, ProtocolWrapper.playerInfoPacketConstructor(ProtocolWrapper.PlayerInfoAction.GAMEMODE, new GameProfile(player.getUniqueId(), player.getName()), gameMode));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+9
-5
@@ -32,22 +32,26 @@ import org.bukkit.event.EventHandler;
|
|||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.player.PlayerInteractEntityEvent;
|
import org.bukkit.event.player.PlayerInteractEntityEvent;
|
||||||
import org.bukkit.inventory.EquipmentSlot;
|
import org.bukkit.inventory.EquipmentSlot;
|
||||||
|
import yapion.hierarchy.types.YAPIONObject;
|
||||||
|
import yapion.hierarchy.types.YAPIONValue;
|
||||||
|
|
||||||
@Linked
|
@Linked
|
||||||
public class TNTClickListener extends SWCommand implements Listener {
|
public class TNTClickListener extends SWCommand implements Listener {
|
||||||
|
|
||||||
|
public static final String TNT_CLICK_DETAILS = "tnt_click_details";
|
||||||
|
|
||||||
public TNTClickListener() {
|
public TNTClickListener() {
|
||||||
super("tntdetails");
|
super("tntdetails");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Register(description = "TNT_DETAILS_COMMAND")
|
@Register(description = "TNT_DETAILS_COMMAND")
|
||||||
public void toggle(Player player) {
|
public void toggle(Player player) {
|
||||||
Config config = Config.STORE.get(player);
|
YAPIONObject yapionObject = Config.getInstance().get(player);
|
||||||
if (config.isTntClickDetails()) {
|
if (yapionObject.getOrSetDefault(TNT_CLICK_DETAILS, new YAPIONValue<>(true)).asBoolean().orElse(true)) {
|
||||||
config.setTntClickDetails(false);
|
yapionObject.put(TNT_CLICK_DETAILS, false);
|
||||||
BauSystem.MESSAGE.send("TNT_DETAILS_OFF", player);
|
BauSystem.MESSAGE.send("TNT_DETAILS_OFF", player);
|
||||||
} else {
|
} else {
|
||||||
config.setTntClickDetails(true);
|
yapionObject.put(TNT_CLICK_DETAILS, true);
|
||||||
BauSystem.MESSAGE.send("TNT_DETAILS_ON", player);
|
BauSystem.MESSAGE.send("TNT_DETAILS_ON", player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -56,7 +60,7 @@ public class TNTClickListener extends SWCommand implements Listener {
|
|||||||
public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
|
public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
|
||||||
if (!Permission.BUILD.hasPermission(event.getPlayer())) return;
|
if (!Permission.BUILD.hasPermission(event.getPlayer())) return;
|
||||||
if (event.getHand() != EquipmentSlot.HAND) return;
|
if (event.getHand() != EquipmentSlot.HAND) return;
|
||||||
if (!Config.STORE.get(event.getPlayer()).isTntClickDetails()) {
|
if (!Config.getInstance().get(event.getPlayer()).getOrSetDefault(TNT_CLICK_DETAILS, new YAPIONValue<>(true)).asBoolean().orElse(true)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ import lombok.Getter;
|
|||||||
import org.bukkit.*;
|
import org.bukkit.*;
|
||||||
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.*;
|
||||||
|
|
||||||
@@ -55,22 +56,27 @@ public class Warp {
|
|||||||
warpMap.put(name, this);
|
warpMap.put(name, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Warp(String name, WorldData.WarpEntry warp) {
|
public Warp(String name, YAPIONObject object) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
location = new Location(Bukkit.getWorlds().get(0), warp.getX(), warp.getY(), warp.getZ(), warp.getYaw(), warp.getPitch());
|
double x = object.getPlainValue("x");
|
||||||
mat = Material.getMaterial(warp.getMaterial());
|
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);
|
warpMap.put(name, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public WorldData.WarpEntry output() {
|
public YAPIONObject output() {
|
||||||
WorldData.WarpEntry warp = new WorldData.WarpEntry();
|
YAPIONObject yapionObject = new YAPIONObject();
|
||||||
warp.setX(location.getX());
|
yapionObject.add("x", location.getX());
|
||||||
warp.setY(location.getY());
|
yapionObject.add("y", location.getY());
|
||||||
warp.setZ(location.getZ());
|
yapionObject.add("z", location.getZ());
|
||||||
warp.setYaw(location.getYaw());
|
yapionObject.add("yaw", location.getYaw());
|
||||||
warp.setPitch(location.getPitch());
|
yapionObject.add("pitch", location.getPitch());
|
||||||
warp.setMaterial(mat.toString());
|
yapionObject.add("material", mat.toString());
|
||||||
return warp;
|
return yapionObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Set<String> getWarpNames() {
|
public static Set<String> getWarpNames() {
|
||||||
@@ -95,7 +101,7 @@ public class Warp {
|
|||||||
|
|
||||||
public void delete() {
|
public void delete() {
|
||||||
warpMap.remove(name);
|
warpMap.remove(name);
|
||||||
WorldData.STORE.get().getWarps().remove(name);
|
WorldData.getWarpData().remove(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void teleport(Player player) {
|
public void teleport(Player player) {
|
||||||
|
|||||||
@@ -34,9 +34,9 @@ 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;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
@Linked
|
@Linked
|
||||||
public class WarpCommand extends SWCommand implements Disable, Enable {
|
public class WarpCommand extends SWCommand implements Disable, Enable {
|
||||||
@@ -135,15 +135,17 @@ public class WarpCommand extends SWCommand implements Disable, Enable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void enable() {
|
public void enable() {
|
||||||
WorldData.STORE.get().getWarps().forEach(Warp::new);
|
WorldData.getWarpData().forEach((name, yapionAnyType) -> {
|
||||||
|
new Warp(name, (YAPIONObject) yapionAnyType);
|
||||||
|
});
|
||||||
Warp.enable();
|
Warp.enable();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void disable() {
|
public void disable() {
|
||||||
Map<String, WorldData.WarpEntry> warps = WorldData.STORE.get().getWarps();
|
YAPIONObject yapionObject = WorldData.getWarpData();
|
||||||
for (Warp warp : Warp.getWarps()) {
|
for (Warp warp : Warp.getWarps()) {
|
||||||
warps.put(warp.getName(), warp.output());
|
yapionObject.add(warp.getName(), warp.output());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -131,7 +131,6 @@ public class BauScoreboard implements Listener {
|
|||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||||
SWScoreboard.impl.removeScoreboard(event.getPlayer());
|
|
||||||
ADDITIONAL_SCOREBOARD_LINES.remove(event.getPlayer());
|
ADDITIONAL_SCOREBOARD_LINES.remove(event.getPlayer());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,39 +20,78 @@
|
|||||||
package de.steamwar.bausystem.region;
|
package de.steamwar.bausystem.region;
|
||||||
|
|
||||||
import de.steamwar.bausystem.region.flags.Flag;
|
import de.steamwar.bausystem.region.flags.Flag;
|
||||||
import de.steamwar.bausystem.worlddata.WorldData;
|
|
||||||
import de.steamwar.sql.SchematicNode;
|
import de.steamwar.sql.SchematicNode;
|
||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
|
import yapion.hierarchy.types.YAPIONObject;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
public abstract class RegionData {
|
public abstract class RegionData {
|
||||||
|
|
||||||
protected final WorldData.RegionEntry data;
|
private final List<Property<?, ?>> properties = new ArrayList<>();
|
||||||
protected final Map<String, String> flagData;
|
|
||||||
|
protected final YAPIONObject data;
|
||||||
|
protected final YAPIONObject flagData;
|
||||||
protected final Runnable onChange;
|
protected final Runnable onChange;
|
||||||
protected final Map<Flag<?>, Flag.Value<?>> flagMap = new HashMap<>();
|
protected final Map<Flag<?>, Flag.Value<?>> flagMap = new HashMap<>();
|
||||||
|
|
||||||
private SchematicNode testblockSchematic;
|
private final class Property<T, K> {
|
||||||
|
private final String field;
|
||||||
|
private final Function<K, T> loader;
|
||||||
|
private final Function<T, K> writer;
|
||||||
|
|
||||||
protected RegionData(WorldData.RegionEntry data, Runnable onChange) {
|
private T value;
|
||||||
|
|
||||||
|
public Property(String field, Function<K, T> loader, Function<T, K> writer) {
|
||||||
|
this.field = field;
|
||||||
|
this.loader = loader;
|
||||||
|
this.writer = writer;
|
||||||
|
properties.add(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void load() {
|
||||||
|
if (flagData.containsKey(field)) {
|
||||||
|
value = loader.apply(flagData.getPlainValue(field));
|
||||||
|
} else {
|
||||||
|
value = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public T get() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void set(T value) {
|
||||||
|
this.value = value;
|
||||||
|
if (value == null) {
|
||||||
|
flagData.remove(field);
|
||||||
|
} else {
|
||||||
|
flagData.put(field, writer.apply(value));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Property<SchematicNode, Integer> testblockSchematic = new Property<>("testblockSchematic", SchematicNode::byId, SchematicNode::getId);
|
||||||
|
|
||||||
|
protected RegionData(YAPIONObject data, Runnable onChange) {
|
||||||
this.data = data;
|
this.data = data;
|
||||||
this.flagData = data.getFlags();
|
this.flagData = data.getObjectOrSetDefault("flagStorage", new YAPIONObject());
|
||||||
this.onChange = onChange;
|
this.onChange = onChange;
|
||||||
initialize();
|
initialize();
|
||||||
for (final Flag flag : Flag.getFlags()) {
|
for (final Flag flag : Flag.getFlags()) {
|
||||||
if (!has(flag).isWritable()) continue;
|
if (!has(flag).isWritable()) continue;
|
||||||
try {
|
try {
|
||||||
String s = flagData.get(flag.name());
|
String s = flagData.getPlainValue(flag.name());
|
||||||
flagMap.put(flag, flag.valueOfValue(s));
|
flagMap.put(flag, flag.valueOfValue(s));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
flagMap.put(flag, (Flag.Value<?>) flag.getDefaultValue());
|
flagMap.put(flag, (Flag.Value<?>) flag.getDefaultValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (data.getTestblockSchematic() != null) {
|
properties.forEach(Property::load);
|
||||||
testblockSchematic = SchematicNode.byId(data.getTestblockSchematic());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void initialize() {
|
protected void initialize() {
|
||||||
@@ -87,8 +126,7 @@ public abstract class RegionData {
|
|||||||
flagData.remove(flag.name());
|
flagData.remove(flag.name());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
testblockSchematic = null;
|
properties.forEach(property -> property.set(null));
|
||||||
data.setTestblockSchematic(null);
|
|
||||||
onChange.run();
|
onChange.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,12 +135,11 @@ public abstract class RegionData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public SchematicNode getTestblockSchematic() {
|
public SchematicNode getTestblockSchematic() {
|
||||||
return testblockSchematic;
|
return testblockSchematic.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTestblockSchematic(SchematicNode schematic) {
|
public void setTestblockSchematic(SchematicNode schematic) {
|
||||||
testblockSchematic = schematic;
|
testblockSchematic.set(schematic);
|
||||||
data.setTestblockSchematic(schematic == null ? null : schematic.getId());
|
|
||||||
onChange.run();
|
onChange.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,101 @@
|
|||||||
|
/*
|
||||||
|
* This file is a part of the SteamWar software.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2025 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");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* This file is a part of the SteamWar software.
|
* This file is a part of the SteamWar software.
|
||||||
*
|
*
|
||||||
* Copyright (C) 2026 SteamWar.de-Serverteam
|
* Copyright (C) 2025 SteamWar.de-Serverteam
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
@@ -19,83 +19,58 @@
|
|||||||
|
|
||||||
package de.steamwar.bausystem.worlddata;
|
package de.steamwar.bausystem.worlddata;
|
||||||
|
|
||||||
import com.google.gson.GsonBuilder;
|
import lombok.experimental.UtilityClass;
|
||||||
import de.steamwar.bausystem.config.ConfigStore;
|
|
||||||
import de.steamwar.bausystem.config.VersionedConfig;
|
|
||||||
import de.steamwar.bausystem.worlddata.converter.WorldDataV1ToV2Converter;
|
|
||||||
import lombok.AccessLevel;
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.Setter;
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import yapion.hierarchy.output.FileOutput;
|
||||||
|
import yapion.hierarchy.types.YAPIONObject;
|
||||||
|
import yapion.parser.InputStreamCharsets;
|
||||||
|
import yapion.parser.YAPIONParser;
|
||||||
|
import yapion.parser.options.StreamOptions;
|
||||||
|
|
||||||
|
import java.io.BufferedInputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.HashMap;
|
import java.io.FileInputStream;
|
||||||
import java.util.Map;
|
import java.io.IOException;
|
||||||
|
|
||||||
/**
|
@UtilityClass
|
||||||
* The current world data. It is stored as JSON, fields missing in the
|
public class WorldData {
|
||||||
* stored JSON keep the default value of their initializer, so adding a new
|
|
||||||
* field does not need a new version.
|
|
||||||
* <p>
|
|
||||||
* When a field gets removed, renamed or its meaning changes, copy this class
|
|
||||||
* to WorldDataV{@link #VERSION} (without the {@link #STORE}), increase {@link #VERSION}, write a
|
|
||||||
* {@link de.steamwar.bausystem.config.ConfigConverter} from the copy to this class and register it in the {@link #STORE}.
|
|
||||||
*/
|
|
||||||
@Getter
|
|
||||||
@Setter
|
|
||||||
public class WorldData implements VersionedConfig {
|
|
||||||
|
|
||||||
public static final int VERSION = 2;
|
private final File optionsFile = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "options.yapion");
|
||||||
|
private YAPIONObject worldData;
|
||||||
|
|
||||||
public static final ConfigStore<WorldData> STORE = new ConfigStore<>(WorldData.class, VERSION, WorldData::new)
|
public YAPIONObject getWorldData() {
|
||||||
.gson(new GsonBuilder().setPrettyPrinting().create())
|
if (worldData == null) {
|
||||||
.converter(new WorldDataV1ToV2Converter())
|
read();
|
||||||
.file(new File(Bukkit.getWorlds().get(0).getWorldFolder(), "options.json"))
|
}
|
||||||
.legacyFile(new File(Bukkit.getWorlds().get(0).getWorldFolder(), "options.yapion"), WorldDataV1::parse);
|
return worldData;
|
||||||
|
|
||||||
@Setter(AccessLevel.NONE)
|
|
||||||
protected int version = VERSION;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Region name to the data of the region
|
|
||||||
*/
|
|
||||||
protected Map<String, RegionEntry> regions = new HashMap<>();
|
|
||||||
protected RegionEntry globalRegion = new RegionEntry();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Warp name to warp
|
|
||||||
*/
|
|
||||||
protected Map<String, WarpEntry> warps = new HashMap<>();
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
@Setter
|
|
||||||
public static class RegionEntry {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Overrides the prototype of the region config, null if not overridden
|
|
||||||
*/
|
|
||||||
protected String prototype = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Flag name to flag value name
|
|
||||||
*/
|
|
||||||
protected Map<String, String> flags = new HashMap<>();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Id of the testblock SchematicNode, null if the default testblock is used
|
|
||||||
*/
|
|
||||||
protected Integer testblockSchematic = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Getter
|
public YAPIONObject getRegionsData() {
|
||||||
@Setter
|
return getWorldData().getYAPIONObjectOrSetDefault("regions", new YAPIONObject());
|
||||||
public static class WarpEntry {
|
}
|
||||||
|
|
||||||
protected double x;
|
public YAPIONObject getWarpData() {
|
||||||
protected double y;
|
return getWorldData().getYAPIONObjectOrSetDefault("warps", new YAPIONObject());
|
||||||
protected double z;
|
}
|
||||||
protected float yaw;
|
|
||||||
protected float pitch;
|
private void read() {
|
||||||
protected String material;
|
worldData = new YAPIONObject();
|
||||||
|
if (optionsFile.length() != 0) {
|
||||||
|
try (BufferedInputStream bufferedInputStream = new BufferedInputStream(new FileInputStream(optionsFile))) {
|
||||||
|
worldData = YAPIONParser.parse(bufferedInputStream, new StreamOptions().charset(InputStreamCharsets.UTF_8));
|
||||||
|
} catch (IOException e) {
|
||||||
|
// Ignored
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
write();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void write() {
|
||||||
|
try {
|
||||||
|
worldData.toYAPION(new FileOutput(optionsFile)).close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,111 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of the SteamWar software.
|
|
||||||
*
|
|
||||||
* Copyright (C) 2026 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.bausystem.config.VersionedConfig;
|
|
||||||
import de.steamwar.bausystem.config.legacy.YapionReader;
|
|
||||||
import lombok.AccessLevel;
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.Setter;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The legacy world data that was stored in the YAPION format in options.yapion.
|
|
||||||
*/
|
|
||||||
@Getter
|
|
||||||
@Setter
|
|
||||||
@Deprecated
|
|
||||||
public class WorldDataV1 implements VersionedConfig {
|
|
||||||
|
|
||||||
public static final int VERSION = 1;
|
|
||||||
|
|
||||||
@Setter(AccessLevel.NONE)
|
|
||||||
protected int version = VERSION;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Region name to the data of the region, the global region is stored with the name "global"
|
|
||||||
*/
|
|
||||||
protected Map<String, RegionEntry> regions = new HashMap<>();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Warp name to warp
|
|
||||||
*/
|
|
||||||
protected Map<String, WarpEntry> warps = new HashMap<>();
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
@Setter
|
|
||||||
public static class RegionEntry {
|
|
||||||
|
|
||||||
protected String prototype = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Flag name to flag value name and "testblockSchematic" to the SchematicNode id
|
|
||||||
*/
|
|
||||||
protected Map<String, Object> flagStorage = new HashMap<>();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
@Setter
|
|
||||||
public static class WarpEntry {
|
|
||||||
|
|
||||||
protected double x;
|
|
||||||
protected double y;
|
|
||||||
protected double z;
|
|
||||||
protected float yaw;
|
|
||||||
protected float pitch;
|
|
||||||
protected String material;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static WorldDataV1 parse(String yapion) {
|
|
||||||
Map<String, Object> object = YapionReader.parse(yapion);
|
|
||||||
WorldDataV1 worldData = new WorldDataV1();
|
|
||||||
|
|
||||||
if (object.get("regions") instanceof Map<?, ?> regions) {
|
|
||||||
regions.forEach((name, value) -> {
|
|
||||||
if (!(value instanceof Map<?, ?> region)) return;
|
|
||||||
RegionEntry entry = new RegionEntry();
|
|
||||||
if (region.get("prototype") instanceof String prototype) {
|
|
||||||
entry.prototype = prototype;
|
|
||||||
}
|
|
||||||
if (region.get("flagStorage") instanceof Map<?, ?> flagStorage) {
|
|
||||||
flagStorage.forEach((key, flag) -> entry.flagStorage.put((String) key, flag));
|
|
||||||
}
|
|
||||||
worldData.regions.put((String) name, entry);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (object.get("warps") instanceof Map<?, ?> warps) {
|
|
||||||
warps.forEach((name, value) -> {
|
|
||||||
if (!(value instanceof Map<?, ?> warp)) return;
|
|
||||||
WarpEntry entry = new WarpEntry();
|
|
||||||
entry.x = ((Number) warp.get("x")).doubleValue();
|
|
||||||
entry.y = ((Number) warp.get("y")).doubleValue();
|
|
||||||
entry.z = ((Number) warp.get("z")).doubleValue();
|
|
||||||
entry.yaw = ((Number) warp.get("yaw")).floatValue();
|
|
||||||
entry.pitch = ((Number) warp.get("pitch")).floatValue();
|
|
||||||
entry.material = (String) warp.get("material");
|
|
||||||
worldData.warps.put((String) name, entry);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return worldData;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-75
@@ -1,75 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of the SteamWar software.
|
|
||||||
*
|
|
||||||
* Copyright (C) 2026 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.converter;
|
|
||||||
|
|
||||||
import de.steamwar.bausystem.config.ConfigConverter;
|
|
||||||
import de.steamwar.bausystem.worlddata.WorldData;
|
|
||||||
import de.steamwar.bausystem.worlddata.WorldDataV1;
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public class WorldDataV1ToV2Converter implements ConfigConverter<WorldDataV1, WorldData> {
|
|
||||||
|
|
||||||
private static final String GLOBAL_REGION = "global";
|
|
||||||
private static final String TESTBLOCK_SCHEMATIC = "testblockSchematic";
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int version() {
|
|
||||||
return WorldDataV1.VERSION;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public WorldData convert(WorldDataV1 old) {
|
|
||||||
WorldData worldData = new WorldData();
|
|
||||||
old.getRegions().forEach((name, region) -> {
|
|
||||||
if (name.equals(GLOBAL_REGION)) {
|
|
||||||
worldData.setGlobalRegion(convert(region));
|
|
||||||
} else {
|
|
||||||
worldData.getRegions().put(name, convert(region));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
old.getWarps().forEach((name, warp) -> worldData.getWarps().put(name, convert(warp)));
|
|
||||||
return worldData;
|
|
||||||
}
|
|
||||||
|
|
||||||
private WorldData.RegionEntry convert(WorldDataV1.RegionEntry old) {
|
|
||||||
WorldData.RegionEntry region = new WorldData.RegionEntry();
|
|
||||||
region.setPrototype(old.getPrototype());
|
|
||||||
old.getFlagStorage().forEach((key, value) -> {
|
|
||||||
if (value == null) return;
|
|
||||||
if (key.equals(TESTBLOCK_SCHEMATIC)) {
|
|
||||||
region.setTestblockSchematic(((Number) value).intValue());
|
|
||||||
} else {
|
|
||||||
region.getFlags().put(key, value.toString());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return region;
|
|
||||||
}
|
|
||||||
|
|
||||||
private WorldData.WarpEntry convert(WorldDataV1.WarpEntry old) {
|
|
||||||
WorldData.WarpEntry warp = new WorldData.WarpEntry();
|
|
||||||
warp.setX(old.getX());
|
|
||||||
warp.setY(old.getY());
|
|
||||||
warp.setZ(old.getZ());
|
|
||||||
warp.setYaw(old.getYaw());
|
|
||||||
warp.setPitch(old.getPitch());
|
|
||||||
warp.setMaterial(old.getMaterial());
|
|
||||||
return warp;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+2
-2
@@ -25,12 +25,12 @@ import de.steamwar.bausystem.region.flags.ColorMode;
|
|||||||
import de.steamwar.bausystem.region.flags.Flag;
|
import de.steamwar.bausystem.region.flags.Flag;
|
||||||
import de.steamwar.bausystem.region.flags.ProtectMode;
|
import de.steamwar.bausystem.region.flags.ProtectMode;
|
||||||
import de.steamwar.bausystem.region.flags.TNTMode;
|
import de.steamwar.bausystem.region.flags.TNTMode;
|
||||||
import de.steamwar.bausystem.worlddata.WorldData;
|
|
||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
|
import yapion.hierarchy.types.YAPIONObject;
|
||||||
|
|
||||||
public class FixedGlobalRegionData extends RegionData {
|
public class FixedGlobalRegionData extends RegionData {
|
||||||
|
|
||||||
public FixedGlobalRegionData(WorldData.RegionEntry data, Runnable onChange) {
|
public FixedGlobalRegionData(YAPIONObject data, Runnable onChange) {
|
||||||
super(data, onChange);
|
super(data, onChange);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-3
@@ -26,7 +26,6 @@ import de.steamwar.bausystem.region.flags.Flag;
|
|||||||
import de.steamwar.bausystem.region.flags.TestblockMode;
|
import de.steamwar.bausystem.region.flags.TestblockMode;
|
||||||
import de.steamwar.bausystem.utils.FlatteningWrapper;
|
import de.steamwar.bausystem.utils.FlatteningWrapper;
|
||||||
import de.steamwar.bausystem.utils.PasteBuilder;
|
import de.steamwar.bausystem.utils.PasteBuilder;
|
||||||
import de.steamwar.bausystem.worlddata.WorldData;
|
|
||||||
import de.steamwar.core.Core;
|
import de.steamwar.core.Core;
|
||||||
import de.steamwar.sql.GameModeConfig;
|
import de.steamwar.sql.GameModeConfig;
|
||||||
import de.steamwar.sql.SchematicType;
|
import de.steamwar.sql.SchematicType;
|
||||||
@@ -140,7 +139,7 @@ public class FixedRegion implements Region {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public FixedRegion(String name, FixedRegionData flagStorage, Prototype prototype, YAPIONObject regionConfig, WorldData.RegionEntry regionData) {
|
public FixedRegion(String name, FixedRegionData flagStorage, Prototype prototype, YAPIONObject regionConfig, YAPIONObject regionData) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
uuid = UUID.nameUUIDFromBytes(name.getBytes(StandardCharsets.UTF_8));
|
uuid = UUID.nameUUIDFromBytes(name.getBytes(StandardCharsets.UTF_8));
|
||||||
this.flagStorage = flagStorage;
|
this.flagStorage = flagStorage;
|
||||||
@@ -326,7 +325,7 @@ public class FixedRegion implements Region {
|
|||||||
}
|
}
|
||||||
|
|
||||||
floorLevel = prototype.getFloorOffset() != 0 ? minPoint.getY() + prototype.getFloorOffset() : 0;
|
floorLevel = prototype.getFloorOffset() != 0 ? minPoint.getY() + prototype.getFloorOffset() : 0;
|
||||||
waterLevel = prototype.getWaterOffset() != 0 ? minPoint.getY() + prototype.getWaterOffset() : 0;
|
waterLevel = prototype.getWaterOffset() != 0 ? minPoint.getX() + prototype.getWaterOffset() : 0;
|
||||||
|
|
||||||
File found = null;
|
File found = null;
|
||||||
File baseFile = new File(BauSystem.getInstance().getDataFolder().getParentFile(), "FightSystem");
|
File baseFile = new File(BauSystem.getInstance().getDataFolder().getParentFile(), "FightSystem");
|
||||||
|
|||||||
+2
-2
@@ -22,12 +22,12 @@ package de.steamwar.bausystem.region.fixed;
|
|||||||
import de.steamwar.bausystem.region.RegionData;
|
import de.steamwar.bausystem.region.RegionData;
|
||||||
import de.steamwar.bausystem.region.RegionFlagPolicy;
|
import de.steamwar.bausystem.region.RegionFlagPolicy;
|
||||||
import de.steamwar.bausystem.region.flags.Flag;
|
import de.steamwar.bausystem.region.flags.Flag;
|
||||||
import de.steamwar.bausystem.worlddata.WorldData;
|
|
||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
|
import yapion.hierarchy.types.YAPIONObject;
|
||||||
|
|
||||||
public class FixedRegionData extends RegionData {
|
public class FixedRegionData extends RegionData {
|
||||||
|
|
||||||
public FixedRegionData(WorldData.RegionEntry data, Runnable onChange) {
|
public FixedRegionData(YAPIONObject data, Runnable onChange) {
|
||||||
super(data, onChange);
|
super(data, onChange);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+4
-4
@@ -210,14 +210,14 @@ public class Prototype {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void generateRegion(String name, YAPIONObject regionConfig, WorldData.RegionEntry regionData) {
|
public static void generateRegion(String name, YAPIONObject regionConfig, YAPIONObject regionData) {
|
||||||
Prototype prototype;
|
Prototype prototype;
|
||||||
if (regionData.getPrototype() != null) {
|
if (regionData.containsKey("prototype", String.class)) {
|
||||||
prototype = PROTOTYPE_MAP.get(regionData.getPrototype());
|
prototype = PROTOTYPE_MAP.get(regionData.getPlainValue("prototype"));
|
||||||
} else {
|
} else {
|
||||||
prototype = PROTOTYPE_MAP.get(regionConfig.getPlainValue("prototype"));
|
prototype = PROTOTYPE_MAP.get(regionConfig.getPlainValue("prototype"));
|
||||||
}
|
}
|
||||||
FixedRegionData flagStorage = new FixedRegionData(regionData, WorldData.STORE::save);
|
FixedRegionData flagStorage = new FixedRegionData(regionData, WorldData::write);
|
||||||
FixedRegionSystem.addRegion(new FixedRegion(name, flagStorage, prototype, regionConfig, regionData));
|
FixedRegionSystem.addRegion(new FixedRegion(name, flagStorage, prototype, regionConfig, regionData));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+15
-3
@@ -28,6 +28,7 @@ import org.bukkit.Bukkit;
|
|||||||
import yapion.hierarchy.diff.DiffChange;
|
import yapion.hierarchy.diff.DiffChange;
|
||||||
import yapion.hierarchy.diff.YAPIONDiff;
|
import yapion.hierarchy.diff.YAPIONDiff;
|
||||||
import yapion.hierarchy.types.YAPIONObject;
|
import yapion.hierarchy.types.YAPIONObject;
|
||||||
|
import yapion.hierarchy.types.YAPIONType;
|
||||||
import yapion.parser.YAPIONParser;
|
import yapion.parser.YAPIONParser;
|
||||||
|
|
||||||
import java.io.BufferedInputStream;
|
import java.io.BufferedInputStream;
|
||||||
@@ -54,7 +55,7 @@ public class RegionLoader {
|
|||||||
}
|
}
|
||||||
loaded = yapionObject;
|
loaded = yapionObject;
|
||||||
|
|
||||||
WorldData worldData = WorldData.STORE.get();
|
YAPIONObject optionsYapionObject = WorldData.getRegionsData();
|
||||||
yapionObject.forEach((key, yapionAnyType) -> {
|
yapionObject.forEach((key, yapionAnyType) -> {
|
||||||
if (key.equals("global")) {
|
if (key.equals("global")) {
|
||||||
return;
|
return;
|
||||||
@@ -64,10 +65,21 @@ public class RegionLoader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
YAPIONObject regionConfig = (YAPIONObject) yapionAnyType;
|
YAPIONObject regionConfig = (YAPIONObject) yapionAnyType;
|
||||||
WorldData.RegionEntry regionData = worldData.getRegions().computeIfAbsent(key, k -> new WorldData.RegionEntry());
|
YAPIONObject regionData = new YAPIONObject();
|
||||||
|
if (optionsYapionObject.containsKey(key, YAPIONType.OBJECT)) {
|
||||||
|
regionData = optionsYapionObject.getObject(key);
|
||||||
|
} else {
|
||||||
|
optionsYapionObject.add(key, regionData);
|
||||||
|
}
|
||||||
|
|
||||||
Prototype.generateRegion(key, regionConfig, regionData);
|
Prototype.generateRegion(key, regionConfig, regionData);
|
||||||
});
|
});
|
||||||
|
|
||||||
FixedGlobalRegion.setFLAG_STORAGE(new FixedGlobalRegionData(worldData.getGlobalRegion(), WorldData.STORE::save));
|
YAPIONObject globalOptions = optionsYapionObject.getObject("global");
|
||||||
|
if (globalOptions == null) {
|
||||||
|
globalOptions = new YAPIONObject();
|
||||||
|
optionsYapionObject.add("global", globalOptions);
|
||||||
|
}
|
||||||
|
FixedGlobalRegion.setFLAG_STORAGE(new FixedGlobalRegionData(globalOptions, WorldData::write));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -307,12 +307,12 @@ class SteamwarUser(id: EntityID<Int>) : IntEntity(id) {
|
|||||||
punishments[punishment] = Punishment.createPunishment(this@SteamwarUser.id.value, from, punishment, reason, time, perma)
|
punishments[punishment] = Punishment.createPunishment(this@SteamwarUser.id.value, from, punishment, reason, time, perma)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setLocale(locale: Locale?, manualLocale: Boolean) {
|
fun setLocale(locale: Locale?, manualeLocale: Boolean) {
|
||||||
if (locale == null || (this.manualLocale && !manualLocale)) return
|
if (locale == null || (this.manualLocale && !manualLocale)) return
|
||||||
|
|
||||||
useDb {
|
useDb {
|
||||||
this@SteamwarUser.locale = locale
|
this@SteamwarUser.locale = locale
|
||||||
this@SteamwarUser.manualLocale = manualLocale
|
this@SteamwarUser.manualLocale = manualeLocale
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,82 @@
|
|||||||
|
/*
|
||||||
|
* This file is a part of the SteamWar software.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2025 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.core.events;
|
||||||
|
|
||||||
|
import com.comphenix.tinyprotocol.TinyProtocol;
|
||||||
|
import de.steamwar.core.Core;
|
||||||
|
import de.steamwar.linkage.Linked;
|
||||||
|
import de.steamwar.sql.SWException;
|
||||||
|
import de.steamwar.techhider.ProtocolUtils;
|
||||||
|
import net.minecraft.core.BlockPos;
|
||||||
|
import net.minecraft.network.protocol.game.ServerboundPlayerActionPacket;
|
||||||
|
import net.minecraft.network.protocol.game.ServerboundUseItemOnPacket;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
@Linked
|
||||||
|
public class AntiNocom implements Listener {
|
||||||
|
|
||||||
|
private final Map<Player, Integer> flags = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
|
public AntiNocom() {
|
||||||
|
TinyProtocol.instance.addFilter(ServerboundPlayerActionPacket.class, this::onDig);
|
||||||
|
registerUseItem();
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onQuit(PlayerQuitEvent e) {
|
||||||
|
flags.remove(e.getPlayer());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void registerUseItem() {
|
||||||
|
TinyProtocol.instance.addFilter(ServerboundUseItemOnPacket.class, (player, packet) -> {
|
||||||
|
BlockPos pos = packet.getHitResult().getBlockPos();
|
||||||
|
return isValid(player, "UseItem", pos.getX(), pos.getZ()) ? packet : null;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private ServerboundPlayerActionPacket onDig(Player player, ServerboundPlayerActionPacket packet) {
|
||||||
|
BlockPos pos = packet.getPos();
|
||||||
|
return isValid(player, "Dig", pos.getX(), pos.getZ()) ? packet : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isValid(Player player, String type, int x, int z) {
|
||||||
|
if ((x == 0 && z == 0) || player.getWorld().isChunkLoaded(ProtocolUtils.posToChunk(x), ProtocolUtils.posToChunk(z))) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
int amount = flags.compute(player, (p, a) -> a == null ? 1 : a + 1);
|
||||||
|
if (amount % 8 == 0) { // Only after 8 and every 8 to reduce false flags and spam
|
||||||
|
if (amount == 8) {
|
||||||
|
// Schedule player kick only once
|
||||||
|
Bukkit.getScheduler().runTask(Core.getInstance(), () -> player.kickPlayer(null));
|
||||||
|
}
|
||||||
|
|
||||||
|
SWException.log(player.getName() + " kicked for potential NoCom-DOS attack", x + " " + z + " " + type + " " + amount);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
+117
@@ -0,0 +1,117 @@
|
|||||||
|
/*
|
||||||
|
* This file is a part of the SteamWar software.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2026 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.core.worldedit;
|
||||||
|
|
||||||
|
import com.sk89q.worldedit.math.BlockVector3;
|
||||||
|
import de.steamwar.core.Core;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.block.BlockFace;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
import java.util.LinkedHashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
public class SteamEditSelectAdjacent {
|
||||||
|
|
||||||
|
private static final BlockFace[] FACES = {
|
||||||
|
BlockFace.NORTH,
|
||||||
|
BlockFace.SOUTH,
|
||||||
|
BlockFace.EAST,
|
||||||
|
BlockFace.WEST,
|
||||||
|
BlockFace.UP,
|
||||||
|
BlockFace.DOWN,
|
||||||
|
};
|
||||||
|
|
||||||
|
private Location min;
|
||||||
|
private Location max;
|
||||||
|
|
||||||
|
private SteamEdit.AdjacentFilter filter;
|
||||||
|
|
||||||
|
private LinkedHashSet<Location> frontier = new LinkedHashSet<>();
|
||||||
|
|
||||||
|
public SteamEditSelectAdjacent(Location origin) {
|
||||||
|
// TODO: Fix the flood fill algorithm!
|
||||||
|
min = origin.clone();
|
||||||
|
max = origin.clone();
|
||||||
|
frontier.add(origin);
|
||||||
|
filter = SteamEdit.ADJACENT_FILTERS.apply(origin);
|
||||||
|
|
||||||
|
long time = System.currentTimeMillis();
|
||||||
|
for (int i = 0; i < 500_000 && !frontier.isEmpty(); i++) {
|
||||||
|
if (System.currentTimeMillis() - time > 1000) break;
|
||||||
|
expandNext();
|
||||||
|
}
|
||||||
|
|
||||||
|
Core.getInstance().getLogger().finer(System.currentTimeMillis() - time + "ms " + frontier.size() + " " + min + " to " + max);
|
||||||
|
}
|
||||||
|
|
||||||
|
public BlockVector3 pos1() {
|
||||||
|
return BlockVector3.at(min.getBlockX(), min.getBlockY(), min.getBlockZ());
|
||||||
|
}
|
||||||
|
|
||||||
|
public BlockVector3 pos2() {
|
||||||
|
return BlockVector3.at(max.getBlockX(), max.getBlockY(), max.getBlockZ());
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean inside(Location loc, int offset) {
|
||||||
|
return loc.getBlockX() >= min.getBlockX() + offset && loc.getBlockX() <= max.getBlockX() - offset &&
|
||||||
|
loc.getBlockY() >= min.getBlockY() + offset && loc.getBlockY() <= max.getBlockY() - offset &&
|
||||||
|
loc.getBlockZ() >= min.getBlockZ() + offset && loc.getBlockZ() <= max.getBlockZ() - offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void expandNext() {
|
||||||
|
Location location = frontier.removeFirst();
|
||||||
|
expand(location);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void expand(Location loc) {
|
||||||
|
for (BlockFace face : FACES) {
|
||||||
|
Vector direction = face.getDirection();
|
||||||
|
Location location = loc.clone().add(direction);
|
||||||
|
if (!filter.contains(location.getBlockX(), location.getBlockY(), location.getBlockZ())) continue;
|
||||||
|
if (inside(location, 0)) continue;
|
||||||
|
List<Location> layer = Stream.concat(selectFrontier(direction.getBlockX() == 0 ? null : loc.getBlockX(), direction.getBlockY() == 0 ? null : loc.getBlockY(), direction.getBlockZ() == 0 ? null : loc.getBlockZ())
|
||||||
|
.map(Location::clone)
|
||||||
|
.map(l -> l.add(direction)), Stream.of(location))
|
||||||
|
.filter(l -> !l.getBlock().isEmpty())
|
||||||
|
.filter(l -> !l.getBlock().isLiquid())
|
||||||
|
.toList();
|
||||||
|
if (layer.isEmpty()) continue;
|
||||||
|
|
||||||
|
if (direction.getBlockX() < 0 || direction.getBlockY() < 0 || direction.getBlockZ() < 0) {
|
||||||
|
min.add(direction);
|
||||||
|
} else {
|
||||||
|
max.add(direction);
|
||||||
|
}
|
||||||
|
layer.stream().filter(l -> !inside(l, 1))
|
||||||
|
.filter(l -> filter.contains(l.getBlockX(), l.getBlockY(), l.getBlockZ()))
|
||||||
|
.forEach(frontier::add);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Stream<Location> selectFrontier(Integer x, Integer y, Integer z) {
|
||||||
|
Stream<Location> stream = frontier.stream();
|
||||||
|
if (x != null) stream = stream.filter(loc -> loc.getBlockX() == x);
|
||||||
|
if (y != null) stream = stream.filter(loc -> loc.getBlockY() == y);
|
||||||
|
if (z != null) stream = stream.filter(loc -> loc.getBlockZ() == z);
|
||||||
|
return stream;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -19,34 +19,38 @@
|
|||||||
|
|
||||||
package de.steamwar.core.worldedit;
|
package de.steamwar.core.worldedit;
|
||||||
|
|
||||||
|
import com.comphenix.tinyprotocol.TinyProtocol;
|
||||||
|
import com.sk89q.worldedit.IncompleteRegionException;
|
||||||
import com.sk89q.worldedit.LocalSession;
|
import com.sk89q.worldedit.LocalSession;
|
||||||
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||||
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
|
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
|
||||||
import com.sk89q.worldedit.extension.platform.Actor;
|
|
||||||
import com.sk89q.worldedit.function.mask.Mask;
|
|
||||||
import com.sk89q.worldedit.function.operation.Operations;
|
|
||||||
import com.sk89q.worldedit.function.visitor.RecursiveVisitor;
|
|
||||||
import com.sk89q.worldedit.math.BlockVector3;
|
import com.sk89q.worldedit.math.BlockVector3;
|
||||||
import com.sk89q.worldedit.regions.RegionSelector;
|
import com.sk89q.worldedit.regions.RegionSelector;
|
||||||
import com.sk89q.worldedit.regions.selector.CuboidRegionSelector;
|
|
||||||
import com.sk89q.worldedit.regions.selector.limit.PermissiveSelectorLimits;
|
import com.sk89q.worldedit.regions.selector.limit.PermissiveSelectorLimits;
|
||||||
|
import com.sk89q.worldedit.world.World;
|
||||||
import de.steamwar.core.Core;
|
import de.steamwar.core.Core;
|
||||||
|
import de.steamwar.core.SWPlayer;
|
||||||
|
import de.steamwar.entity.CWireframe;
|
||||||
|
import de.steamwar.entity.REntityServer;
|
||||||
import de.steamwar.inventory.SWItem;
|
import de.steamwar.inventory.SWItem;
|
||||||
import io.papermc.paper.event.player.PlayerPickBlockEvent;
|
import net.minecraft.core.BlockPos;
|
||||||
import org.bukkit.*;
|
import net.minecraft.network.protocol.Packet;
|
||||||
import org.bukkit.attribute.Attribute;
|
import net.minecraft.network.protocol.game.*;
|
||||||
import org.bukkit.attribute.AttributeModifier;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.FluidCollisionMode;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
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.inventory.InventoryType;
|
||||||
import org.bukkit.event.player.PlayerInteractEvent;
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
import org.bukkit.event.player.PlayerSwapHandItemsEvent;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
|
import org.bukkit.util.RayTraceResult;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
public class SteamEditWand implements Listener {
|
public class SteamEditWand implements Listener {
|
||||||
|
|
||||||
@@ -61,23 +65,8 @@ public class SteamEditWand implements Listener {
|
|||||||
};
|
};
|
||||||
public static final ItemStack ITEM = new SWItem(MATERIAL, NAME).setLore(LORE).getItemStack();
|
public static final ItemStack ITEM = new SWItem(MATERIAL, NAME).setLore(LORE).getItemStack();
|
||||||
|
|
||||||
static {
|
private boolean noWand(Player player) {
|
||||||
ItemMeta itemMeta = ITEM.getItemMeta();
|
return player.getInventory().getItemInMainHand().getType() != SteamEditWand.MATERIAL;
|
||||||
itemMeta.addAttributeModifier(Attribute.BLOCK_INTERACTION_RANGE, new AttributeModifier(
|
|
||||||
NamespacedKey.fromString("range", Core.getInstance()),
|
|
||||||
35.0,
|
|
||||||
AttributeModifier.Operation.ADD_NUMBER
|
|
||||||
));
|
|
||||||
ITEM.setItemMeta(itemMeta);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final int MAX_CONNECTED_DEPTH = 256;
|
|
||||||
|
|
||||||
private boolean checkWand(Player player) {
|
|
||||||
ItemStack item = player.getInventory().getItemInMainHand();
|
|
||||||
if (item.getType() != MATERIAL) return false;
|
|
||||||
if (!ITEM.equals(item)) player.getInventory().setItemInMainHand(ITEM);
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private final WorldEditPlugin we;
|
private final WorldEditPlugin we;
|
||||||
@@ -85,195 +74,336 @@ public class SteamEditWand implements Listener {
|
|||||||
SteamEditWand() {
|
SteamEditWand() {
|
||||||
we = WorldEditWrapper.getWorldEditPlugin();
|
we = WorldEditWrapper.getWorldEditPlugin();
|
||||||
Bukkit.getPluginManager().registerEvents(this, Core.getInstance());
|
Bukkit.getPluginManager().registerEvents(this, Core.getInstance());
|
||||||
|
|
||||||
|
TinyProtocol.instance.addFilter(ServerboundSwingPacket.class, this::leftClick);
|
||||||
|
TinyProtocol.instance.addFilter(ServerboundInteractPacket.class, (player, packet) -> {
|
||||||
|
if (packet.isAttack()) {
|
||||||
|
return leftClick(player, packet);
|
||||||
|
} else {
|
||||||
|
return rightClick(player, packet);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
TinyProtocol.instance.addFilter(ServerboundUseItemPacket.class, this::rightClick);
|
||||||
|
TinyProtocol.instance.addFilter(ServerboundUseItemOnPacket.class, this::rightClick);
|
||||||
|
TinyProtocol.instance.addFilter(ServerboundPickItemFromBlockPacket.class, this::middleClick);
|
||||||
|
TinyProtocol.instance.addFilter(ServerboundPlayerActionPacket.class, this::swapHands);
|
||||||
|
TinyProtocol.instance.addFilter(ServerboundMovePlayerPacket.Pos.class, this::movePlayerPacket);
|
||||||
|
TinyProtocol.instance.addFilter(ServerboundMovePlayerPacket.Rot.class, this::movePlayerPacket);
|
||||||
|
TinyProtocol.instance.addFilter(ServerboundMovePlayerPacket.PosRot.class, this::movePlayerPacket);
|
||||||
|
|
||||||
|
Bukkit.getScheduler().runTaskTimer(Core.getInstance(), () -> {
|
||||||
|
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||||
|
if (noWand(player)) SWPlayer.of(player).removeComponent(SWEditCursor.class);
|
||||||
|
}
|
||||||
|
}, 1, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||||
Player player = event.getPlayer();
|
if (noWand(event.getPlayer())) return;
|
||||||
if (!checkWand(player)) return;
|
|
||||||
Block block = event.getClickedBlock();
|
|
||||||
if (block == null) return;
|
|
||||||
BlockVector3 clicked = BukkitAdapter.asBlockVector(block.getLocation());
|
|
||||||
switch (event.getAction()) {
|
|
||||||
case LEFT_CLICK_BLOCK -> {
|
|
||||||
setCorner(player, Corner.PRIMARY, clicked);
|
|
||||||
}
|
|
||||||
case RIGHT_CLICK_BLOCK -> {
|
|
||||||
if (player.isSneaking()) {
|
|
||||||
setPos2OrExpand(player, clicked);
|
|
||||||
} else {
|
|
||||||
setCorner(player, Corner.SECONDARY, clicked);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
default -> {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setCorner(Player player, Corner corner, BlockVector3 position) {
|
public static class SWEditCursor implements SWPlayer.Component {
|
||||||
LocalSession session = we.getSession(player);
|
private Player player;
|
||||||
select(corner, regionSelector(player, session), player, session, position);
|
private REntityServer entityServer = new REntityServer();
|
||||||
|
private CWireframe wireframe;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onMount(SWPlayer player) {
|
||||||
|
this.player = player.getPlayer();
|
||||||
|
entityServer.addPlayer(player.getPlayer());
|
||||||
|
wireframe = new CWireframe(entityServer);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onUnmount(SWPlayer player) {
|
||||||
|
entityServer.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLocation(Location location) {
|
||||||
|
wireframe.setPos1And2(location, location);
|
||||||
|
wireframe.setBlock(WorldEditRendererCUIEditor.Type.CURSOR.getMaterial(player).createBlockData());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static RegionSelector regionSelector(Player player, LocalSession session) {
|
private Packet<?> leftClick(Player player, Packet<?> packet) {
|
||||||
return session.getRegionSelector(BukkitAdapter.adapt(player.getWorld()));
|
if (noWand(player)) return packet;
|
||||||
|
if (player.getOpenInventory().getType() != InventoryType.CREATIVE) return packet;
|
||||||
|
double distance = WorldEditRendererCUIEditor.Type.CURSOR.getWidth(player).blocks;
|
||||||
|
RayTraceResult result = player.rayTraceBlocks(distance, FluidCollisionMode.NEVER);
|
||||||
|
if (result == null) return packet;
|
||||||
|
Block block = result.getHitBlock();
|
||||||
|
if (block == null) return packet;
|
||||||
|
BlockVector3 pos1 = BlockVector3.at(block.getX(), block.getY(), block.getZ());
|
||||||
|
setPos1(player, pos1);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setPos1(Player player, BlockVector3 pos1) {
|
||||||
|
LocalSession session = we.getSession(player);
|
||||||
|
World world = session.getSelectionWorld();
|
||||||
|
if (world == null) return;
|
||||||
|
selectPos1(session.getRegionSelector(world), player, session, pos1);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Packet<?> rightClick(Player player, Packet<?> packet) {
|
||||||
|
if (noWand(player)) return packet;
|
||||||
|
double distance = WorldEditRendererCUIEditor.Type.CURSOR.getWidth(player).blocks;
|
||||||
|
RayTraceResult result = player.rayTraceBlocks(distance, FluidCollisionMode.NEVER);
|
||||||
|
if (result == null) return packet;
|
||||||
|
Block block = result.getHitBlock();
|
||||||
|
if (block == null) return packet;
|
||||||
|
BlockVector3 pos2 = BlockVector3.at(block.getX(), block.getY(), block.getZ());
|
||||||
|
if (!player.isSneaking()) {
|
||||||
|
setPos2(player, pos2);
|
||||||
|
} else {
|
||||||
|
setPos2OrExpand(player, pos2);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setPos2(Player player, BlockVector3 pos2) {
|
||||||
|
LocalSession session = we.getSession(player);
|
||||||
|
World world = session.getSelectionWorld();
|
||||||
|
if (world == null) return;
|
||||||
|
selectPos2(session.getRegionSelector(world), player, session, pos2);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setPos2OrExpand(Player player, BlockVector3 expand) {
|
private void setPos2OrExpand(Player player, BlockVector3 expand) {
|
||||||
LocalSession session = we.getSession(player);
|
LocalSession session = we.getSession(player);
|
||||||
RegionSelector regionSelector = regionSelector(player, session);
|
World world = session.getSelectionWorld();
|
||||||
|
if (world == null) return;
|
||||||
|
RegionSelector regionSelector = session.getRegionSelector(world);
|
||||||
|
|
||||||
if (!(regionSelector instanceof CuboidRegionSelector cuboidSelector) || !cuboidSelector.isDefined()) {
|
// Only primary set for now
|
||||||
select(Corner.SECONDARY, regionSelector, player, session, expand);
|
if (!regionSelector.isDefined()) {
|
||||||
|
selectPos2(session.getRegionSelector(world), player, session, expand);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<BlockVector3> vertices = regionSelector.getVertices();
|
||||||
|
// Probably not a cuboid selection!
|
||||||
|
if (vertices.size() > 2) {
|
||||||
|
selectPos2(session.getRegionSelector(world), player, session, expand);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<BlockVector3> vertices = cuboidSelector.getVertices();
|
|
||||||
BlockVector3 pos1 = vertices.get(0);
|
BlockVector3 pos1 = vertices.get(0);
|
||||||
BlockVector3 pos2 = vertices.get(1);
|
BlockVector3 pos2 = vertices.get(1);
|
||||||
if (expand.containedWithin(pos1.getMinimum(pos2), pos1.getMaximum(pos2))) return;
|
|
||||||
|
|
||||||
int[][] corners = {toArray(pos1), toArray(pos2)};
|
BlockVector3 min = pos1.getMinimum(pos2);
|
||||||
int[] target = toArray(expand);
|
BlockVector3 max = pos1.getMaximum(pos2);
|
||||||
|
if (expand.containedWithin(pos1, pos2)) {
|
||||||
Corner[] closer = new Corner[3];
|
return;
|
||||||
for (int axis = 0; axis < 3; axis++) {
|
|
||||||
closer[axis] = Corner.closer(corners[0][axis], corners[1][axis], target[axis]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int axis = 0; axis < 3; axis++) {
|
Closer x = Closer.UNKNOWN;
|
||||||
Corner corner = closer[axis];
|
Closer y = Closer.UNKNOWN;
|
||||||
// Both corners share this coordinate, move the one the other axes agree on
|
Closer z = Closer.UNKNOWN;
|
||||||
if (corners[0][axis] == corners[1][axis] && corners[0][axis] != target[axis]) {
|
|
||||||
corner = Objects.requireNonNullElse(Corner.agree(closer[(axis + 1) % 3], closer[(axis + 2) % 3]), Corner.PRIMARY);
|
boolean insideX = min.x() < expand.x() && max.x() > expand.x();
|
||||||
}
|
boolean insideY = min.y() < expand.y() && max.y() > expand.y();
|
||||||
if (corner != null) corners[corner.ordinal()][axis] = target[axis];
|
boolean insideZ = min.z() < expand.z() && max.z() > expand.z();
|
||||||
|
|
||||||
|
if (insideX) {
|
||||||
|
// No Change needed
|
||||||
|
} else if (Math.abs(pos1.x() - expand.x()) > Math.abs(pos2.x() - expand.x())) {
|
||||||
|
x = Closer.POS2;
|
||||||
|
} else if (Math.abs(pos1.x() - expand.x()) < Math.abs(pos2.x() - expand.x())) {
|
||||||
|
x = Closer.POS1;
|
||||||
}
|
}
|
||||||
|
|
||||||
BlockVector3 newPos1 = BlockVector3.at(corners[0][0], corners[0][1], corners[0][2]);
|
if (insideY) {
|
||||||
BlockVector3 newPos2 = BlockVector3.at(corners[1][0], corners[1][1], corners[1][2]);
|
// No Change needed
|
||||||
if (!newPos1.equals(pos1)) select(Corner.PRIMARY, regionSelector, player, session, newPos1);
|
} else if (Math.abs(pos1.y() - expand.y()) > Math.abs(pos2.y() - expand.y())) {
|
||||||
if (!newPos2.equals(pos2)) select(Corner.SECONDARY, regionSelector, player, session, newPos2);
|
y = Closer.POS2;
|
||||||
|
} else if (Math.abs(pos1.y() - expand.y()) < Math.abs(pos2.y() - expand.y())) {
|
||||||
|
y = Closer.POS1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (insideZ) {
|
||||||
|
// No Change needed
|
||||||
|
} else if (Math.abs(pos1.z() - expand.z()) > Math.abs(pos2.z() - expand.z())) {
|
||||||
|
z = Closer.POS2;
|
||||||
|
} else if (Math.abs(pos1.z() - expand.z()) < Math.abs(pos2.z() - expand.z())) {
|
||||||
|
z = Closer.POS1;
|
||||||
|
}
|
||||||
|
|
||||||
|
Closer x1 = Closer.UNKNOWN;
|
||||||
|
Closer y1 = Closer.UNKNOWN;
|
||||||
|
Closer z1 = Closer.UNKNOWN;
|
||||||
|
|
||||||
|
if (!insideX && pos1.x() != expand.x() && pos2.x() != expand.x() && x == Closer.UNKNOWN) {
|
||||||
|
x1 = y.and(z).or(Closer.POS1);
|
||||||
|
}
|
||||||
|
if (!insideY && pos1.y() != expand.y() && pos2.y() != expand.y() && y == Closer.UNKNOWN) {
|
||||||
|
y1 = x.and(z).or(Closer.POS1);
|
||||||
|
}
|
||||||
|
if (!insideZ && pos1.z() != expand.z() && pos2.z() != expand.z() && z == Closer.UNKNOWN) {
|
||||||
|
z1 = x.and(y).or(Closer.POS1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (x1 != Closer.UNKNOWN) x = x1;
|
||||||
|
if (y1 != Closer.UNKNOWN) y = y1;
|
||||||
|
if (z1 != Closer.UNKNOWN) z = z1;
|
||||||
|
|
||||||
|
boolean p1updated = false;
|
||||||
|
boolean p2updated = false;
|
||||||
|
|
||||||
|
if (x == Closer.POS1) {
|
||||||
|
pos1 = pos1.withX(expand.x());
|
||||||
|
p1updated = true;
|
||||||
|
} else if (x == Closer.POS2) {
|
||||||
|
pos2 = pos2.withX(expand.x());
|
||||||
|
p2updated = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (y == Closer.POS1) {
|
||||||
|
pos1 = pos1.withY(expand.y());
|
||||||
|
p1updated = true;
|
||||||
|
} else if (y == Closer.POS2) {
|
||||||
|
pos2 = pos2.withY(expand.y());
|
||||||
|
p2updated = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (z == Closer.POS1) {
|
||||||
|
pos1 = pos1.withZ(expand.z());
|
||||||
|
p1updated = true;
|
||||||
|
} else if (z == Closer.POS2) {
|
||||||
|
pos2 = pos2.withZ(expand.z());
|
||||||
|
p2updated = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (p1updated) selectPos1(session.getRegionSelector(world), player, session, pos1);
|
||||||
|
if (p2updated) selectPos2(session.getRegionSelector(world), player, session, pos2);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int[] toArray(BlockVector3 vector) {
|
private enum Closer {
|
||||||
return new int[]{vector.x(), vector.y(), vector.z()};
|
POS1,
|
||||||
}
|
POS2,
|
||||||
|
UNKNOWN,
|
||||||
@EventHandler
|
|
||||||
public void onPickBlock(PlayerPickBlockEvent event) {
|
|
||||||
Player player = event.getPlayer();
|
|
||||||
if (!checkWand(player)) return;
|
|
||||||
event.setCancelled(true);
|
|
||||||
LocalSession session = we.getSession(player);
|
|
||||||
RegionSelector regionSelector = regionSelector(player, session);
|
|
||||||
BlockVector3[] bounds = connectedBounds(event.getBlock());
|
|
||||||
|
|
||||||
boolean primaryChanged = Corner.PRIMARY.changed(regionSelector, bounds[0]);
|
|
||||||
boolean secondaryChanged = Corner.SECONDARY.changed(regionSelector, bounds[1]);
|
|
||||||
Corner.PRIMARY.select(regionSelector, bounds[0]);
|
|
||||||
Corner.SECONDARY.select(regionSelector, bounds[1]);
|
|
||||||
Actor actor = BukkitAdapter.adapt(player);
|
|
||||||
if (primaryChanged) Corner.PRIMARY.explain(regionSelector, actor, session, bounds[0]);
|
|
||||||
if (secondaryChanged) Corner.SECONDARY.explain(regionSelector, actor, session, bounds[1]);
|
|
||||||
WorldEditRenderer.renderPlayer(player);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static BlockVector3[] connectedBounds(Block origin) {
|
|
||||||
World world = origin.getWorld();
|
|
||||||
SteamEdit.AdjacentFilter filter = SteamEdit.ADJACENT_FILTERS.apply(origin.getLocation());
|
|
||||||
BlockVector3 start = BukkitAdapter.asBlockVector(origin.getLocation());
|
|
||||||
BlockVector3[] bounds = {start, start};
|
|
||||||
|
|
||||||
Mask connected = new Mask() {
|
|
||||||
@Override
|
|
||||||
public boolean test(BlockVector3 position) {
|
|
||||||
int x = position.x();
|
|
||||||
int y = position.y();
|
|
||||||
int z = position.z();
|
|
||||||
if (!filter.contains(x, y, z)) return false;
|
|
||||||
Block block = world.getBlockAt(x, y, z);
|
|
||||||
return !block.isEmpty() && !block.isLiquid();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Mask copy() {
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
RecursiveVisitor visitor = new RecursiveVisitor(connected, position -> {
|
|
||||||
bounds[0] = bounds[0].getMinimum(position);
|
|
||||||
bounds[1] = bounds[1].getMaximum(position);
|
|
||||||
return true;
|
|
||||||
}, MAX_CONNECTED_DEPTH, world.getMinHeight(), world.getMaxHeight() - 1);
|
|
||||||
visitor.visit(start);
|
|
||||||
Operations.complete(visitor);
|
|
||||||
return bounds;
|
|
||||||
}
|
|
||||||
|
|
||||||
private enum Corner {
|
|
||||||
PRIMARY {
|
|
||||||
@Override
|
|
||||||
void select(RegionSelector regionSelector, BlockVector3 position) {
|
|
||||||
regionSelector.selectPrimary(position, PermissiveSelectorLimits.getInstance());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
void explain(RegionSelector regionSelector, Actor actor, LocalSession session, BlockVector3 position) {
|
|
||||||
regionSelector.explainPrimarySelection(actor, session, position);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
SECONDARY {
|
|
||||||
@Override
|
|
||||||
void select(RegionSelector regionSelector, BlockVector3 position) {
|
|
||||||
regionSelector.selectSecondary(position, PermissiveSelectorLimits.getInstance());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
void explain(RegionSelector regionSelector, Actor actor, LocalSession session, BlockVector3 position) {
|
|
||||||
regionSelector.explainSecondarySelection(actor, session, position);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
;
|
;
|
||||||
|
|
||||||
static Corner closer(int primary, int secondary, int target) {
|
public Closer and(Closer closer) {
|
||||||
if (Math.min(primary, secondary) < target && target < Math.max(primary, secondary)) return null;
|
if (this == closer) {
|
||||||
int difference = Math.abs(primary - target) - Math.abs(secondary - target);
|
return this;
|
||||||
if (difference < 0) return PRIMARY;
|
} else if (this == UNKNOWN) {
|
||||||
if (difference > 0) return SECONDARY;
|
return closer;
|
||||||
return null;
|
} else if (closer == UNKNOWN) {
|
||||||
|
return this;
|
||||||
|
} else {
|
||||||
|
return UNKNOWN;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static Corner agree(Corner a, Corner b) {
|
public Closer or(Closer closer) {
|
||||||
if (a == null) return b;
|
if (this == UNKNOWN) return closer;
|
||||||
if (b == null || a == b) return a;
|
return this;
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean changed(RegionSelector regionSelector, BlockVector3 position) {
|
|
||||||
BlockVector3 current = regionSelector instanceof CuboidRegionSelector cuboidSelector ? cuboidSelector.getVertices().get(ordinal()) : null;
|
|
||||||
return !position.equals(current);
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract void select(RegionSelector regionSelector, BlockVector3 position);
|
|
||||||
|
|
||||||
abstract void explain(RegionSelector regionSelector, Actor actor, LocalSession session, BlockVector3 position);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void select(Corner corner, RegionSelector regionSelector, Player player, LocalSession session, BlockVector3 position) {
|
private ServerboundPickItemFromBlockPacket middleClick(Player player, ServerboundPickItemFromBlockPacket packet) {
|
||||||
boolean changed = corner.changed(regionSelector, position);
|
if (noWand(player)) return packet;
|
||||||
corner.select(regionSelector, position);
|
LocalSession session = we.getSession(player);
|
||||||
if (changed) corner.explain(regionSelector, BukkitAdapter.adapt(player), session, position);
|
World world = session.getSelectionWorld();
|
||||||
|
if (world == null) return packet;
|
||||||
|
RegionSelector regionSelector = session.getRegionSelector(world);
|
||||||
|
BlockPos pos = packet.pos();
|
||||||
|
SteamEditSelectAdjacent selector = new SteamEditSelectAdjacent(new Location(player.getWorld(), pos.getX(), pos.getY(), pos.getZ()));
|
||||||
|
selectPos1(regionSelector, player, session, selector.pos1());
|
||||||
|
selectPos2(regionSelector, player, session, selector.pos2());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class Pos1Message implements SWPlayer.Component {
|
||||||
|
private BukkitTask task;
|
||||||
|
|
||||||
|
public Pos1Message(RegionSelector regionSelector, Player player, LocalSession session, BlockVector3 pos1) {
|
||||||
|
task = Bukkit.getScheduler().runTaskLater(Core.getInstance(), () -> {
|
||||||
|
regionSelector.explainPrimarySelection(BukkitAdapter.adapt(player), session, pos1);
|
||||||
|
SWPlayer.of(player).removeComponent(Pos1Message.class);
|
||||||
|
}, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onUnmount(SWPlayer player) {
|
||||||
|
task.cancel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void selectPos1(RegionSelector regionSelector, Player player, LocalSession session, BlockVector3 pos1) {
|
||||||
|
try {
|
||||||
|
if (!pos1.equals(regionSelector.getPrimaryPosition())) {
|
||||||
|
SWPlayer.of(player).setComponent(new Pos1Message(regionSelector, player, session, pos1));
|
||||||
|
}
|
||||||
|
} catch (IncompleteRegionException e) {
|
||||||
|
SWPlayer.of(player).setComponent(new Pos1Message(regionSelector, player, session, pos1));
|
||||||
|
}
|
||||||
|
regionSelector.selectPrimary(pos1, PermissiveSelectorLimits.getInstance());
|
||||||
WorldEditRenderer.renderPlayer(player);
|
WorldEditRenderer.renderPlayer(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
private static class Pos2Message implements SWPlayer.Component {
|
||||||
public void onSwapHands(PlayerSwapHandItemsEvent event) {
|
private BukkitTask task;
|
||||||
Player player = event.getPlayer();
|
|
||||||
if (!checkWand(player)) return;
|
public Pos2Message(RegionSelector regionSelector, Player player, LocalSession session, BlockVector3 pos2) {
|
||||||
event.setCancelled(true);
|
task = Bukkit.getScheduler().runTaskLater(Core.getInstance(), () -> {
|
||||||
WorldEditRendererCUIEditor.open(player, true);
|
regionSelector.explainSecondarySelection(BukkitAdapter.adapt(player), session, pos2);
|
||||||
|
SWPlayer.of(player).removeComponent(Pos1Message.class);
|
||||||
|
}, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onUnmount(SWPlayer player) {
|
||||||
|
task.cancel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void selectPos2(RegionSelector regionSelector, Player player, LocalSession session, BlockVector3 pos2) {
|
||||||
|
try {
|
||||||
|
if (regionSelector.getVertices().size() == 2 && !pos2.equals(regionSelector.getVertices().get(1))) {
|
||||||
|
SWPlayer.of(player).setComponent(new Pos2Message(regionSelector, player, session, pos2));
|
||||||
|
}
|
||||||
|
} catch (IncompleteRegionException e) {
|
||||||
|
SWPlayer.of(player).setComponent(new Pos2Message(regionSelector, player, session, pos2));
|
||||||
|
}
|
||||||
|
regionSelector.selectSecondary(pos2, PermissiveSelectorLimits.getInstance());
|
||||||
|
WorldEditRenderer.renderPlayer(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
private ServerboundPlayerActionPacket swapHands(Player player, ServerboundPlayerActionPacket packet) {
|
||||||
|
if (noWand(player)) return packet;
|
||||||
|
if (packet.getAction() != ServerboundPlayerActionPacket.Action.SWAP_ITEM_WITH_OFFHAND) return packet;
|
||||||
|
Bukkit.getScheduler().runTask(Core.getInstance(), () -> {
|
||||||
|
WorldEditRendererCUIEditor.open(player, true);
|
||||||
|
});
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ServerboundMovePlayerPacket movePlayerPacket(Player player, ServerboundMovePlayerPacket packet) {
|
||||||
|
SWPlayer swPlayer = SWPlayer.of(player);
|
||||||
|
|
||||||
|
if (noWand(player)) {
|
||||||
|
swPlayer.removeComponent(SWEditCursor.class);
|
||||||
|
return packet;
|
||||||
|
}
|
||||||
|
|
||||||
|
double distance = WorldEditRendererCUIEditor.Type.CURSOR.getWidth(player).blocks;
|
||||||
|
RayTraceResult result = player.rayTraceBlocks(distance, FluidCollisionMode.NEVER);
|
||||||
|
Block block = result == null ? null : result.getHitBlock();
|
||||||
|
if (result == null || block == null) {
|
||||||
|
swPlayer.removeComponent(SWEditCursor.class);
|
||||||
|
return packet;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!swPlayer.hasComponent(SWEditCursor.class)) {
|
||||||
|
swPlayer.setComponent(new SWEditCursor());
|
||||||
|
}
|
||||||
|
|
||||||
|
swPlayer.getComponent(SWEditCursor.class).ifPresent(cursor -> {
|
||||||
|
cursor.setLocation(block.getLocation());
|
||||||
|
});
|
||||||
|
return packet;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,20 @@
|
|||||||
package de.steamwar.cursor;
|
package de.steamwar.cursor;
|
||||||
|
|
||||||
|
import com.comphenix.tinyprotocol.TinyProtocol;
|
||||||
import de.steamwar.core.Core;
|
import de.steamwar.core.Core;
|
||||||
import de.steamwar.core.SWPlayer;
|
import de.steamwar.core.SWPlayer;
|
||||||
import de.steamwar.linkage.Linked;
|
import de.steamwar.linkage.Linked;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
import net.minecraft.network.protocol.Packet;
|
||||||
|
import net.minecraft.network.protocol.game.ServerboundMovePlayerPacket;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
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.PlayerInteractEvent;
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
|
||||||
@Linked
|
@Linked
|
||||||
public class CursorListener implements Listener {
|
public class CursorListener implements Listener {
|
||||||
@@ -20,6 +26,10 @@ public class CursorListener implements Listener {
|
|||||||
instance = this;
|
instance = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TinyProtocol.instance.addFilter(ServerboundMovePlayerPacket.Pos.class, this::updateCursorFromPacket);
|
||||||
|
TinyProtocol.instance.addFilter(ServerboundMovePlayerPacket.Rot.class, this::updateCursorFromPacket);
|
||||||
|
TinyProtocol.instance.addFilter(ServerboundMovePlayerPacket.PosRot.class, this::updateCursorFromPacket);
|
||||||
|
|
||||||
Bukkit.getScheduler().runTaskTimer(Core.getInstance(), () -> {
|
Bukkit.getScheduler().runTaskTimer(Core.getInstance(), () -> {
|
||||||
SWPlayer.allWithSingleComponent(Cursor.class)
|
SWPlayer.allWithSingleComponent(Cursor.class)
|
||||||
.map(SWPlayer.SWPlayerWithComponent::getComponent)
|
.map(SWPlayer.SWPlayerWithComponent::getComponent)
|
||||||
@@ -27,6 +37,15 @@ public class CursorListener implements Listener {
|
|||||||
}, 1, 1);
|
}, 1, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Packet<?> updateCursorFromPacket(Player player, Packet<?> packet) {
|
||||||
|
SWPlayer swPlayer = SWPlayer.of(player);
|
||||||
|
Optional<Cursor> activeCursor = swPlayer.getComponent(Cursor.class);
|
||||||
|
|
||||||
|
activeCursor.ifPresent(Cursor::renderDeduplicated);
|
||||||
|
|
||||||
|
return packet;
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||||
SWPlayer.of(event.getPlayer()).getComponent(Cursor.class).ifPresent(cursor -> {
|
SWPlayer.of(event.getPlayer()).getComponent(Cursor.class).ifPresent(cursor -> {
|
||||||
|
|||||||
@@ -67,9 +67,7 @@ public class SWScoreboard {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void removeScoreboard(Player player) {
|
public void removeScoreboard(Player player) {
|
||||||
if (player.getScoreboard().getObjective(SIDEBAR) != null) {
|
player.getScoreboard().getObjective(SIDEBAR).unregister();
|
||||||
player.getScoreboard().getObjective(SIDEBAR).unregister();
|
|
||||||
}
|
|
||||||
playerBoards.remove(player);
|
playerBoards.remove(player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ import net.kyori.adventure.text.Component;
|
|||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
@Linked
|
//@Linked
|
||||||
public class FML2 extends BasicListener {
|
public class FML2 extends BasicListener {
|
||||||
// FML2: https://wiki.vg/Minecraft_Forge_Handshake#FML2_protocol_.281.13_-_Current.29
|
// FML2: https://wiki.vg/Minecraft_Forge_Handshake#FML2_protocol_.281.13_-_Current.29
|
||||||
// FML3: https://github.com/adde0109/Ambassador/tree/non-api/src/main/java/org/adde0109/ambassador/forge
|
// FML3: https://github.com/adde0109/Ambassador/tree/non-api/src/main/java/org/adde0109/ambassador/forge
|
||||||
|
|||||||
Reference in New Issue
Block a user