From 9e76846de7dd01d468fcddc02c7583772313bd11 Mon Sep 17 00:00:00 2001 From: AlexProgrammerDE <40795980+AlexProgrammerDE@users.noreply.github.com> Date: Fri, 15 Nov 2024 14:47:50 +0100 Subject: [PATCH] Reimplement settings system --- build.gradle.kts | 3 +- .../com/soulfiremc/client/cli/CLIManager.java | 372 ++++++++++-------- gradle/libs.versions.toml | 1 + proto/src/main/proto/soulfire/config.proto | 88 ++--- server/build.gradle.kts | 2 + .../soulfiremc/server/plugins/AIChatBot.java | 55 +-- .../soulfiremc/server/plugins/AntiAFK.java | 79 ++-- .../soulfiremc/server/plugins/AutoArmor.java | 51 ++- .../server/plugins/AutoChatMessage.java | 63 ++- .../soulfiremc/server/plugins/AutoEat.java | 51 ++- .../soulfiremc/server/plugins/AutoJump.java | 51 ++- .../server/plugins/AutoReconnect.java | 51 ++- .../server/plugins/AutoRegister.java | 65 +-- .../server/plugins/AutoRespawn.java | 51 ++- .../soulfiremc/server/plugins/AutoTotem.java | 50 ++- .../server/plugins/ChatControl.java | 29 +- .../server/plugins/ChatMessageLogger.java | 16 +- .../server/plugins/ClientBrand.java | 29 +- .../server/plugins/ClientSettings.java | 209 +++++----- .../server/plugins/FakeVirtualHost.java | 51 +-- .../server/plugins/ForwardingBypass.java | 31 +- .../soulfiremc/server/plugins/KillAura.java | 133 ++++--- .../server/plugins/ModLoaderSupport.java | 18 +- .../soulfiremc/server/plugins/POVServer.java | 61 +-- .../server/plugins/ServerListBypass.java | 50 ++- .../server/settings/AISettings.java | 87 ++-- .../server/settings/AccountSettings.java | 31 +- .../server/settings/BotSettings.java | 186 +++++---- .../server/settings/DevSettings.java | 66 ++-- .../server/settings/ProxySettings.java | 37 +- .../settings/lib/ServerSettingsRegistry.java | 218 +++++----- .../server/settings/lib/SettingsSource.java | 13 +- .../settings/property/BooleanProperty.java | 20 +- .../settings/property/ComboProperty.java | 68 ++-- .../settings/property/DoubleProperty.java | 36 +- .../server/settings/property/IntProperty.java | 36 +- .../settings/property/MinMaxProperty.java | 56 +++ .../settings/property/MinMaxPropertyLink.java | 30 -- .../server/settings/property/Property.java | 132 +------ .../settings/property/SingleProperty.java | 25 -- .../settings/property/StringListProperty.java | 20 +- .../settings/property/StringProperty.java | 26 +- .../server/util/BuiltinSettingsConstants.java | 28 -- 43 files changed, 1404 insertions(+), 1371 deletions(-) create mode 100644 server/src/main/java/com/soulfiremc/server/settings/property/MinMaxProperty.java delete mode 100644 server/src/main/java/com/soulfiremc/server/settings/property/MinMaxPropertyLink.java delete mode 100644 server/src/main/java/com/soulfiremc/server/settings/property/SingleProperty.java delete mode 100644 server/src/main/java/com/soulfiremc/server/util/BuiltinSettingsConstants.java diff --git a/build.gradle.kts b/build.gradle.kts index abd31016e..262d3bd1e 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -6,10 +6,11 @@ plugins { dependencies { javadocClasspath("org.projectlombok:lombok:1.18.36") + javadocClasspath(libs.immutables) rootProject.subprojects.forEach { subproject -> if (subproject.name == "data-generator") { - return@forEach; + return@forEach } subproject.plugins.withId("java") { diff --git a/client/src/main/java/com/soulfiremc/client/cli/CLIManager.java b/client/src/main/java/com/soulfiremc/client/cli/CLIManager.java index cb9d6f523..60f87e6ef 100644 --- a/client/src/main/java/com/soulfiremc/client/cli/CLIManager.java +++ b/client/src/main/java/com/soulfiremc/client/cli/CLIManager.java @@ -22,6 +22,7 @@ import com.google.common.util.concurrent.AtomicDouble; import com.google.gson.JsonArray; import com.google.gson.JsonElement; +import com.google.gson.JsonObject; import com.google.gson.JsonPrimitive; import com.soulfiremc.client.ClientCommandManager; import com.soulfiremc.client.grpc.RPCClient; @@ -98,181 +99,210 @@ private void registerOptions(CommandLine.Model.CommandSpec targetCommandSpec) { .getClientData(ClientDataRequest.getDefaultInstance()) .getSettingsList()) { for (var entry : page.getEntriesList()) { - switch (entry.getValueCase()) { - case SINGLE -> { - var singleEntry = entry.getSingle(); - var description = escapeFormatSpecifiers(singleEntry.getDescription()); - - var propertyKey = new PropertyKey(page.getNamespace(), singleEntry.getKey()); - - var args = new String[]{"--%s-%s".formatted(page.getNamespace(), singleEntry.getKey())}; - var settingType = singleEntry.getType(); - targetCommandSpec.addOption( - switch (settingType.getValueCase()) { - case STRING -> { - var stringEntry = settingType.getString(); - var reference = new AtomicReference(); - var optionSpec = - CommandLine.Model.OptionSpec.builder(args) - .description(description) - .type(String.class) - .initialValue(stringEntry.getDef()) - .hasInitialValue(true) - .setter( - new CommandLine.Model.ISetter() { - @Override - public T set(T value) { - return (T) reference.getAndSet((String) value); - } - }) - .build(); - - clientSettingsManager.registerListener( - propertyKey, s -> reference.set(s.getAsString())); - clientSettingsManager.registerProvider( - propertyKey, () -> new JsonPrimitive(reference.get())); - - yield optionSpec; - } - case INT -> { - var intEntry = settingType.getInt(); - yield addIntSetting( - propertyKey, - clientSettingsManager, - description, - args, - intEntry); - } - case DOUBLE -> { - var doubleEntry = settingType.getDouble(); - yield addDoubleSetting( - propertyKey, - clientSettingsManager, - description, - args, - doubleEntry); - } - case BOOL -> { - var boolEntry = settingType.getBool(); - var reference = new AtomicReference(); - var optionSpec = - CommandLine.Model.OptionSpec.builder(args) - .description(description) - .type(boolean.class) - .initialValue(boolEntry.getDef()) - .hasInitialValue(true) - .setter( - new CommandLine.Model.ISetter() { - @Override - public T set(T value) { - return (T) reference.getAndSet((boolean) value); - } - }) - .build(); - - clientSettingsManager.registerListener( - propertyKey, s -> reference.set(s.getAsBoolean())); - clientSettingsManager.registerProvider( - propertyKey, () -> new JsonPrimitive(reference.get())); - - yield optionSpec; - } - case COMBO -> { - var comboEntry = settingType.getCombo(); - var reference = new AtomicReference(); - - var optionSpec = - CommandLine.Model.OptionSpec.builder(args) - .description(description) - .type(String.class) - .initialValue( - comboEntry.getOptionsList().get(comboEntry.getDef()).getId()) - .hasInitialValue(true) - .completionCandidates( - comboEntry.getOptionsList().stream().map(ComboOption::getId) - ::iterator) - .setter( - new CommandLine.Model.ISetter() { - @Override - public T set(T value) { - return (T) reference.getAndSet((String) value); - } - }) - .build(); - - clientSettingsManager.registerListener( - propertyKey, s -> reference.set(s.getAsString())); - clientSettingsManager.registerProvider( - propertyKey, () -> new JsonPrimitive(reference.get())); - - yield optionSpec; - } - case STRINGLIST -> { - var stringListEntry = settingType.getStringList(); - var reference = new AtomicReference(); - var optionSpec = - CommandLine.Model.OptionSpec.builder(args) - .description(description) - .type(String[].class) - .initialValue(stringListEntry.getDefList().toArray(new String[0])) - .hasInitialValue(true) - .setter( - new CommandLine.Model.ISetter() { - @Override - public T set(T value) { - return (T) reference.getAndSet((String[]) value); - } - }) - .build(); - - clientSettingsManager.registerListener( - propertyKey, s -> reference.set(s.getAsJsonArray() - .asList() - .stream() - .map(JsonElement::getAsString) - .toArray(String[]::new))); - clientSettingsManager.registerProvider( - propertyKey, () -> { - var array = new JsonArray(); - for (var element : reference.get()) { - array.add(new JsonPrimitive(element)); - } - - return array; - }); - - yield optionSpec; + var propertyKey = new PropertyKey(page.getNamespace(), entry.getKey()); + + var baseArg = "--%s-%s".formatted(page.getNamespace(), entry.getKey()); + var settingType = entry.getType(); + switch (settingType.getValueCase()) { + case STRING -> { + var stringEntry = settingType.getString(); + var description = escapeFormatSpecifiers(stringEntry.getDescription()); + + var reference = new AtomicReference(); + var optionSpec = + CommandLine.Model.OptionSpec.builder(new String[]{baseArg}) + .description(description) + .type(String.class) + .initialValue(stringEntry.getDef()) + .hasInitialValue(true) + .setter( + new CommandLine.Model.ISetter() { + @Override + public T set(T value) { + return (T) reference.getAndSet((String) value); + } + }) + .build(); + + clientSettingsManager.registerListener( + propertyKey, s -> reference.set(s.getAsString())); + clientSettingsManager.registerProvider( + propertyKey, () -> new JsonPrimitive(reference.get())); + + targetCommandSpec.addOption(optionSpec); + } + case INT -> { + var intEntry = settingType.getInt(); + var description = escapeFormatSpecifiers(intEntry.getDescription()); + + targetCommandSpec.addOption(addIntSetting( + propertyKey, + clientSettingsManager, + description, + new String[]{baseArg}, + intEntry)); + } + case DOUBLE -> { + var doubleEntry = settingType.getDouble(); + var description = escapeFormatSpecifiers(doubleEntry.getDescription()); + + targetCommandSpec.addOption(addDoubleSetting( + propertyKey, + clientSettingsManager, + description, + new String[]{baseArg}, + doubleEntry)); + } + case BOOL -> { + var boolEntry = settingType.getBool(); + var description = escapeFormatSpecifiers(boolEntry.getDescription()); + + var reference = new AtomicReference(); + var optionSpec = + CommandLine.Model.OptionSpec.builder(new String[]{baseArg}) + .description(description) + .type(boolean.class) + .initialValue(boolEntry.getDef()) + .hasInitialValue(true) + .setter( + new CommandLine.Model.ISetter() { + @Override + public T set(T value) { + return (T) reference.getAndSet((boolean) value); + } + }) + .build(); + + clientSettingsManager.registerListener( + propertyKey, s -> reference.set(s.getAsBoolean())); + clientSettingsManager.registerProvider( + propertyKey, () -> new JsonPrimitive(reference.get())); + + targetCommandSpec.addOption(optionSpec); + } + case COMBO -> { + var comboEntry = settingType.getCombo(); + var description = escapeFormatSpecifiers(comboEntry.getDescription()); + + var reference = new AtomicReference(); + var optionSpec = + CommandLine.Model.OptionSpec.builder(new String[]{baseArg}) + .description(description) + .type(String.class) + .initialValue(comboEntry.getDef()) + .hasInitialValue(true) + .completionCandidates( + comboEntry.getOptionsList().stream().map(ComboOption::getId) + ::iterator) + .setter( + new CommandLine.Model.ISetter() { + @Override + public T set(T value) { + return (T) reference.getAndSet((String) value); + } + }) + .build(); + + clientSettingsManager.registerListener( + propertyKey, s -> reference.set(s.getAsString())); + clientSettingsManager.registerProvider( + propertyKey, () -> new JsonPrimitive(reference.get())); + + targetCommandSpec.addOption(optionSpec); + } + case STRINGLIST -> { + var stringListEntry = settingType.getStringList(); + var description = escapeFormatSpecifiers(stringListEntry.getDescription()); + + var reference = new AtomicReference(); + var optionSpec = + CommandLine.Model.OptionSpec.builder(new String[]{baseArg}) + .description(description) + .type(String[].class) + .initialValue(stringListEntry.getDefList().toArray(new String[0])) + .hasInitialValue(true) + .setter( + new CommandLine.Model.ISetter() { + @Override + public T set(T value) { + return (T) reference.getAndSet((String[]) value); + } + }) + .build(); + + clientSettingsManager.registerListener( + propertyKey, s -> reference.set(s.getAsJsonArray() + .asList() + .stream() + .map(JsonElement::getAsString) + .toArray(String[]::new))); + clientSettingsManager.registerProvider( + propertyKey, () -> { + var array = new JsonArray(); + for (var element : reference.get()) { + array.add(new JsonPrimitive(element)); } - case VALUE_NOT_SET -> throw new IllegalStateException( - "Unexpected value: " + settingType.getValueCase()); + + return array; }); + + targetCommandSpec.addOption(optionSpec); } - case MINMAXPAIR -> { - var minMaxEntry = entry.getMinMaxPair(); - - var min = minMaxEntry.getMin(); - var minDescription = escapeFormatSpecifiers(min.getDescription()); - var minPropertyKey = new PropertyKey(page.getNamespace(), min.getKey()); - targetCommandSpec.addOption( - addIntSetting( - minPropertyKey, - clientSettingsManager, - minDescription, - new String[]{"--%s-%s".formatted(page.getNamespace(), min.getKey())}, - min.getIntSetting())); - - var max = minMaxEntry.getMax(); - var maxDescription = escapeFormatSpecifiers(max.getDescription()); - var maxPropertyKey = new PropertyKey(page.getNamespace(), max.getKey()); - targetCommandSpec.addOption( - addIntSetting( - maxPropertyKey, - clientSettingsManager, - maxDescription, - new String[]{"--%s-%s".formatted(page.getNamespace(), max.getKey())}, - max.getIntSetting())); + case MINMAX -> { + var minMaxEntry = settingType.getMinMax(); + + var minRef = new AtomicInteger(); + var minDescription = escapeFormatSpecifiers(minMaxEntry.getMinDescription()); + var minOptionSpec = + CommandLine.Model.OptionSpec.builder(new String[]{baseArg + "-min"}) + .description(minDescription) + .type(int.class) + .initialValue(minMaxEntry.getMinDef()) + .hasInitialValue(true) + .setter( + new CommandLine.Model.ISetter() { + @Override + @SuppressWarnings("unchecked") + public T set(T value) { + return (T) (Integer) minRef.getAndSet((int) value); + } + }) + .build(); + + var maxRef = new AtomicInteger(); + var maxDescription = escapeFormatSpecifiers(minMaxEntry.getMaxDescription()); + var maxOptionSpec = + CommandLine.Model.OptionSpec.builder(new String[]{baseArg + "-max"}) + .description(maxDescription) + .type(int.class) + .initialValue(minMaxEntry.getMaxDef()) + .hasInitialValue(true) + .setter( + new CommandLine.Model.ISetter() { + @Override + @SuppressWarnings("unchecked") + public T set(T value) { + return (T) (Integer) maxRef.getAndSet((int) value); + } + }) + .build(); + + clientSettingsManager.registerListener(propertyKey, s -> { + minRef.set(s.getAsJsonObject().get("min").getAsInt()); + maxRef.set(s.getAsJsonObject().get("max").getAsInt()); + }); + clientSettingsManager.registerProvider(propertyKey, () -> { + var obj = new JsonObject(); + obj.addProperty("min", minRef.get()); + obj.addProperty("max", maxRef.get()); + return obj; + }); + + targetCommandSpec.addOption(minOptionSpec); + targetCommandSpec.addOption(maxOptionSpec); } - case VALUE_NOT_SET -> throw new IllegalStateException("Unexpected value: " + entry.getValueCase()); + case VALUE_NOT_SET -> throw new IllegalStateException( + "Unexpected value: " + settingType.getValueCase()); } } } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 9241fb3c6..3343cd248 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -90,6 +90,7 @@ reactor-netty-core = { module = "io.projectreactor.netty:reactor-netty-core", ve reactor-netty-http = { module = "io.projectreactor.netty:reactor-netty-http", version.ref = "reactor" } spark = "com.github.AlexProgrammerDE.spark:spark-common:2ba922a171" ollama4j = "io.github.ollama4j:ollama4j:1.0.89" +immutables = "org.immutables:value:2.10.1 " javax-annotations = "javax.annotation:javax.annotation-api:1.3.2" junit = "org.junit.jupiter:junit-jupiter:5.11.3" diff --git a/proto/src/main/proto/soulfire/config.proto b/proto/src/main/proto/soulfire/config.proto index 1600ea506..cfc19466e 100644 --- a/proto/src/main/proto/soulfire/config.proto +++ b/proto/src/main/proto/soulfire/config.proto @@ -11,28 +11,36 @@ message ClientDataRequest { } message StringSetting { - string def = 1; - bool secret = 2; + string uiName = 1; + string description = 2; + string def = 3; + bool secret = 4; } message IntSetting { - int32 def = 1; - int32 min = 2; - int32 max = 3; - int32 step = 4; - optional string format = 5; + string uiName = 1; + string description = 2; + int32 def = 3; + int32 min = 4; + int32 max = 5; + int32 step = 6; + optional string format = 7; } message DoubleSetting { - double def = 1; - double min = 2; - double max = 3; - double step = 4; - optional string format = 5; + string uiName = 1; + string description = 2; + double def = 3; + double min = 4; + double max = 5; + double step = 6; + optional string format = 7; } message BoolSetting { - bool def = 1; + string uiName = 1; + string description = 2; + bool def = 3; } message ComboOption { @@ -43,13 +51,30 @@ message ComboOption { } message ComboSetting { + string uiName = 1; + string description = 2; // List of options - repeated ComboOption options = 1; - int32 def = 2; + repeated ComboOption options = 3; + string def = 4; } message StringListSetting { - repeated string def = 1; + string uiName = 1; + string description = 2; + repeated string def = 3; +} + +message MinMaxSetting { + string minUiName = 1; + string maxUiName = 2; + string minDescription = 3; + string maxDescription = 4; + int32 minDef = 5; + int32 maxDef = 6; + int32 min = 7; + int32 max = 8; + int32 step = 9; + optional string format = 10; } // A single setting type with optional default value @@ -61,42 +86,17 @@ message SettingType { BoolSetting bool = 4; ComboSetting combo = 5; StringListSetting stringList = 6; + MinMaxSetting minMax = 7; } } -// A single option in the settings page -message SettingEntrySingle { +// A entry in the settings page +message SettingEntry { // Basically we only send a kv map to the server with every setting entry string key = 1; - string uiName = 2; - string description = 3; SettingType type = 4; } -message SettingEntryMinMaxPairSingle { - // Basically we only send a kv map to the server with every setting entry - string key = 1; - string uiName = 2; - string description = 3; - IntSetting intSetting = 4; -} - -// A paired option in the settings page -message SettingEntryMinMaxPair { - // Required to be IntSetting - SettingEntryMinMaxPairSingle min = 1; - // Required to be IntSetting - SettingEntryMinMaxPairSingle max = 2; -} - -// A entry in the settings page -message SettingEntry { - oneof value { - SettingEntrySingle single = 1; - SettingEntryMinMaxPair minMaxPair = 2; - } -} - message SettingsPage { enum Type { SERVER = 0; diff --git a/server/build.gradle.kts b/server/build.gradle.kts index 47630a0fd..a6a319f88 100644 --- a/server/build.gradle.kts +++ b/server/build.gradle.kts @@ -74,6 +74,8 @@ dependencies { api(libs.fastutil) api(libs.caffeine) api(libs.jetbrains.annotations) + compileOnly(libs.immutables) + annotationProcessor(libs.immutables) api(libs.bundles.armeria) api(libs.bundles.reactor.netty) diff --git a/server/src/main/java/com/soulfiremc/server/plugins/AIChatBot.java b/server/src/main/java/com/soulfiremc/server/plugins/AIChatBot.java index a29ccd8a1..167c036a4 100644 --- a/server/src/main/java/com/soulfiremc/server/plugins/AIChatBot.java +++ b/server/src/main/java/com/soulfiremc/server/plugins/AIChatBot.java @@ -25,7 +25,8 @@ import com.soulfiremc.server.settings.AISettings; import com.soulfiremc.server.settings.lib.SettingsObject; import com.soulfiremc.server.settings.property.BooleanProperty; -import com.soulfiremc.server.settings.property.Property; +import com.soulfiremc.server.settings.property.ImmutableBooleanProperty; +import com.soulfiremc.server.settings.property.ImmutableStringProperty; import com.soulfiremc.server.settings.property.StringProperty; import io.github.ollama4j.models.chat.OllamaChatMessageRole; import io.github.ollama4j.models.chat.OllamaChatRequestBuilder; @@ -94,19 +95,22 @@ public void onSettingsRegistryInit(InstanceSettingsRegistryInitEvent event) { @NoArgsConstructor(access = AccessLevel.PRIVATE) private static class AIChatBotSettings implements SettingsObject { - private static final Property.Builder BUILDER = Property.builder("ai-chat-bot"); + private static final String NAMESPACE = "ai-chat-bot"; public static final BooleanProperty ENABLED = - BUILDER.ofBoolean( - "enabled", - "Enable AI Chat Bot", - "Enable the AI Chat Bot", - false); + ImmutableBooleanProperty.builder() + .namespace(NAMESPACE) + .key("enabled") + .uiName("Enable AI Chat Bot") + .description("Enable the AI Chat Bot") + .defaultValue(false) + .build(); public static final StringProperty PROMPT = - BUILDER.ofString( - "prompt", - "AI System prompt", - "What the bot is instructed to say", - """ + ImmutableStringProperty.builder() + .namespace(NAMESPACE) + .key("prompt") + .uiName("AI System prompt") + .description("What the bot is instructed to say") + .defaultValue(""" You are a Minecraft chat bot, you chat with players. You must not say more than 128 characters or more than 2 sentences per response. Keep responses short, but conversational. @@ -114,18 +118,23 @@ private static class AIChatBotSettings implements SettingsObject { You will take any roleplay seriously and follow the player's lead. You cannot interact with the Minecraft world except by chatting. Use prefixes to express emotions, do not put names as prefixes. - """.replace("\n", " ")); + """.replace("\n", " ")) + .build(); public static final StringProperty MODEL = - BUILDER.ofString( - "model", - "AI Model", - "What AI model should be used for inference", - "nemotron-mini"); + ImmutableStringProperty.builder() + .namespace(NAMESPACE) + .key("model") + .uiName("AI Model") + .description("What AI model should be used for inference") + .defaultValue("nemotron-mini") + .build(); public static final StringProperty KEYWORD = - BUILDER.ofString( - "keyword", - "Keyword", - "Only respond to messages containing this keyword", - "!ai"); + ImmutableStringProperty.builder() + .namespace(NAMESPACE) + .key("keyword") + .uiName("Keyword") + .description("Only respond to messages containing this keyword") + .defaultValue("!ai") + .build(); } } diff --git a/server/src/main/java/com/soulfiremc/server/plugins/AntiAFK.java b/server/src/main/java/com/soulfiremc/server/plugins/AntiAFK.java index 6d7331ed3..66a8e0b0e 100644 --- a/server/src/main/java/com/soulfiremc/server/plugins/AntiAFK.java +++ b/server/src/main/java/com/soulfiremc/server/plugins/AntiAFK.java @@ -27,8 +27,9 @@ import com.soulfiremc.server.pathfinding.graph.PathConstraint; import com.soulfiremc.server.settings.lib.SettingsObject; import com.soulfiremc.server.settings.property.BooleanProperty; -import com.soulfiremc.server.settings.property.MinMaxPropertyLink; -import com.soulfiremc.server.settings.property.Property; +import com.soulfiremc.server.settings.property.ImmutableBooleanProperty; +import com.soulfiremc.server.settings.property.ImmutableMinMaxProperty; +import com.soulfiremc.server.settings.property.MinMaxProperty; import lombok.AccessLevel; import lombok.NoArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -83,46 +84,40 @@ public void onSettingsRegistryInit(InstanceSettingsRegistryInitEvent event) { @NoArgsConstructor(access = AccessLevel.NONE) private static class AntiAFKSettings implements SettingsObject { - private static final Property.Builder BUILDER = Property.builder("anti-afk"); + private static final String NAMESPACE = "anti-afk"; public static final BooleanProperty ENABLED = - BUILDER.ofBoolean( - "enabled", - "Enable Anti AFK", - "Enable the Anti AFK feature", - false); - public static final MinMaxPropertyLink DISTANCE = new MinMaxPropertyLink( - BUILDER.ofInt( - "min-distance", - "Min distance (blocks)", - "Minimum distance to walk", - 10, - 1, - Integer.MAX_VALUE, - 1), - BUILDER.ofInt( - "max-distance", - "Max distance (blocks)", - "Maximum distance to walk", - 30, - 1, - Integer.MAX_VALUE, - 1)); - public static final MinMaxPropertyLink DELAY = new MinMaxPropertyLink( - BUILDER.ofInt( - "min-delay", - "Min delay (seconds)", - "Minimum delay between moves", - 15, - 0, - Integer.MAX_VALUE, - 1), - BUILDER.ofInt( - "max-delay", - "Max delay (seconds)", - "Maximum delay between moves", - 45, - 0, - Integer.MAX_VALUE, - 1)); + ImmutableBooleanProperty.builder() + .namespace(NAMESPACE) + .key("enabled") + .uiName("Enable Anti AFK") + .description("Enable the Anti AFK feature") + .defaultValue(false) + .build(); + public static final MinMaxProperty DISTANCE = ImmutableMinMaxProperty.builder() + .namespace(NAMESPACE) + .key("distance") + .minUiName("Min distance (blocks)") + .maxUiName("Max distance (blocks)") + .minDescription("Minimum distance to walk") + .maxDescription("Maximum distance to walk") + .minDefaultValue(10) + .maxDefaultValue(30) + .minValue(1) + .maxValue(Integer.MAX_VALUE) + .stepValue(1) + .build(); + public static final MinMaxProperty DELAY = ImmutableMinMaxProperty.builder() + .namespace(NAMESPACE) + .key("delay") + .minUiName("Min delay (seconds)") + .maxUiName("Max delay (seconds)") + .minDescription("Minimum delay between moves") + .maxDescription("Maximum delay between moves") + .minDefaultValue(15) + .maxDefaultValue(30) + .minValue(0) + .maxValue(Integer.MAX_VALUE) + .stepValue(1) + .build(); } } diff --git a/server/src/main/java/com/soulfiremc/server/plugins/AutoArmor.java b/server/src/main/java/com/soulfiremc/server/plugins/AutoArmor.java index f853f6861..19e5a1f0a 100644 --- a/server/src/main/java/com/soulfiremc/server/plugins/AutoArmor.java +++ b/server/src/main/java/com/soulfiremc/server/plugins/AutoArmor.java @@ -25,8 +25,9 @@ import com.soulfiremc.server.protocol.bot.container.InventoryManager; import com.soulfiremc.server.settings.lib.SettingsObject; import com.soulfiremc.server.settings.property.BooleanProperty; -import com.soulfiremc.server.settings.property.MinMaxPropertyLink; -import com.soulfiremc.server.settings.property.Property; +import com.soulfiremc.server.settings.property.ImmutableBooleanProperty; +import com.soulfiremc.server.settings.property.ImmutableMinMaxProperty; +import com.soulfiremc.server.settings.property.MinMaxProperty; import com.soulfiremc.server.util.TimeUtil; import lombok.AccessLevel; import lombok.NoArgsConstructor; @@ -141,30 +142,28 @@ public void onSettingsRegistryInit(InstanceSettingsRegistryInitEvent event) { @NoArgsConstructor(access = AccessLevel.NONE) private static class AutoArmorSettings implements SettingsObject { - private static final Property.Builder BUILDER = Property.builder("auto-armor"); + private static final String NAMESPACE = "auto-armor"; public static final BooleanProperty ENABLED = - BUILDER.ofBoolean( - "enabled", - "Enable Auto Armor", - "Put on best armor automatically", - true); - public static final MinMaxPropertyLink DELAY = - new MinMaxPropertyLink( - BUILDER.ofInt( - "min-delay", - "Min delay (seconds)", - "Minimum delay between putting on armor", - 1, - 0, - Integer.MAX_VALUE, - 1), - BUILDER.ofInt( - "max-delay", - "Max delay (seconds)", - "Maximum delay between putting on armor", - 2, - 0, - Integer.MAX_VALUE, - 1)); + ImmutableBooleanProperty.builder() + .namespace(NAMESPACE) + .key("enabled") + .uiName("Enable Auto Armor") + .description("Put on best armor automatically") + .defaultValue(true) + .build(); + public static final MinMaxProperty DELAY = + ImmutableMinMaxProperty.builder() + .namespace(NAMESPACE) + .key("delay") + .minUiName("Min delay (seconds)") + .maxUiName("Max delay (seconds)") + .minDescription("Minimum delay between putting on armor") + .maxDescription("Maximum delay between putting on armor") + .minDefaultValue(1) + .maxDefaultValue(2) + .minValue(0) + .maxValue(Integer.MAX_VALUE) + .stepValue(1) + .build(); } } diff --git a/server/src/main/java/com/soulfiremc/server/plugins/AutoChatMessage.java b/server/src/main/java/com/soulfiremc/server/plugins/AutoChatMessage.java index 0c4c0748f..1039d096f 100644 --- a/server/src/main/java/com/soulfiremc/server/plugins/AutoChatMessage.java +++ b/server/src/main/java/com/soulfiremc/server/plugins/AutoChatMessage.java @@ -22,10 +22,7 @@ import com.soulfiremc.server.api.event.bot.BotJoinedEvent; import com.soulfiremc.server.api.event.lifecycle.InstanceSettingsRegistryInitEvent; import com.soulfiremc.server.settings.lib.SettingsObject; -import com.soulfiremc.server.settings.property.BooleanProperty; -import com.soulfiremc.server.settings.property.MinMaxPropertyLink; -import com.soulfiremc.server.settings.property.Property; -import com.soulfiremc.server.settings.property.StringListProperty; +import com.soulfiremc.server.settings.property.*; import com.soulfiremc.server.util.SFHelpers; import lombok.AccessLevel; import lombok.NoArgsConstructor; @@ -71,36 +68,36 @@ public void onSettingsRegistryInit(InstanceSettingsRegistryInitEvent event) { @NoArgsConstructor(access = AccessLevel.NONE) private static class AutoChatMessageSettings implements SettingsObject { - private static final Property.Builder BUILDER = Property.builder("auto-chat-message"); + private static final String NAMESPACE = "auto-chat-message"; public static final BooleanProperty ENABLED = - BUILDER.ofBoolean( - "enabled", - "Enable Auto Chat Message", - "Attempt to send chat messages automatically in random intervals", - false); - public static final MinMaxPropertyLink DELAY = - new MinMaxPropertyLink( - BUILDER.ofInt( - "min-delay", - "Min delay (seconds)", - "Minimum delay between chat messages", - 2, - 0, - Integer.MAX_VALUE, - 1), - BUILDER.ofInt( - "max-delay", - "Max delay (seconds)", - "Maximum delay between chat messages", - 5, - 0, - Integer.MAX_VALUE, - 1)); + ImmutableBooleanProperty.builder() + .namespace(NAMESPACE) + .key("enabled") + .uiName("Enable Auto Chat Message") + .description("Attempt to send chat messages automatically in random intervals") + .defaultValue(false) + .build(); + public static final MinMaxProperty DELAY = + ImmutableMinMaxProperty.builder() + .namespace(NAMESPACE) + .key("delay") + .minUiName("Min delay (seconds)") + .maxUiName("Max delay (seconds)") + .minDescription("Minimum delay between chat messages") + .maxDescription("Maximum delay between chat messages") + .minDefaultValue(2) + .maxDefaultValue(5) + .minValue(0) + .maxValue(Integer.MAX_VALUE) + .stepValue(1) + .build(); public static final StringListProperty MESSAGES = - BUILDER.ofStringList( - "messages", - "Chat Messages", - "List of chat messages to send", - List.of("Hello", "Hi", "Hey", "How are you?")); + ImmutableStringListProperty.builder() + .namespace(NAMESPACE) + .key("messages") + .uiName("Chat Messages") + .description("List of chat messages to send") + .addAllDefaultValue(List.of("Hello", "Hi", "Hey", "How are you?")) + .build(); } } diff --git a/server/src/main/java/com/soulfiremc/server/plugins/AutoEat.java b/server/src/main/java/com/soulfiremc/server/plugins/AutoEat.java index ceabef661..c30df1b65 100644 --- a/server/src/main/java/com/soulfiremc/server/plugins/AutoEat.java +++ b/server/src/main/java/com/soulfiremc/server/plugins/AutoEat.java @@ -23,8 +23,9 @@ import com.soulfiremc.server.api.event.lifecycle.InstanceSettingsRegistryInitEvent; import com.soulfiremc.server.settings.lib.SettingsObject; import com.soulfiremc.server.settings.property.BooleanProperty; -import com.soulfiremc.server.settings.property.MinMaxPropertyLink; -import com.soulfiremc.server.settings.property.Property; +import com.soulfiremc.server.settings.property.ImmutableBooleanProperty; +import com.soulfiremc.server.settings.property.ImmutableMinMaxProperty; +import com.soulfiremc.server.settings.property.MinMaxProperty; import com.soulfiremc.server.util.ItemTypeHelper; import com.soulfiremc.server.util.TimeUtil; import lombok.AccessLevel; @@ -111,30 +112,28 @@ public void onSettingsRegistryInit(InstanceSettingsRegistryInitEvent event) { @NoArgsConstructor(access = AccessLevel.PRIVATE) private static class AutoEatSettings implements SettingsObject { - public static final Property.Builder BUILDER = Property.builder("auto-eat"); + private static final String NAMESPACE = "auto-eat"; public static final BooleanProperty ENABLED = - BUILDER.ofBoolean( - "enabled", - "Enable Auto Eat", - "Eat available food automatically when hungry", - true); - public static final MinMaxPropertyLink DELAY = - new MinMaxPropertyLink( - BUILDER.ofInt( - "min-delay", - "Min delay (seconds)", - "Minimum delay between eating", - 1, - 0, - Integer.MAX_VALUE, - 1), - BUILDER.ofInt( - "max-delay", - "Max delay (seconds)", - "Maximum delay between eating", - 2, - 0, - Integer.MAX_VALUE, - 1)); + ImmutableBooleanProperty.builder() + .namespace(NAMESPACE) + .key("enabled") + .uiName("Enable Auto Eat") + .description("Eat available food automatically when hungry") + .defaultValue(true) + .build(); + public static final MinMaxProperty DELAY = + ImmutableMinMaxProperty.builder() + .namespace(NAMESPACE) + .key("delay") + .minUiName("Min delay (seconds)") + .maxUiName("Max delay (seconds)") + .minDescription("Minimum delay between eating") + .maxDescription("Maximum delay between eating") + .minDefaultValue(1) + .maxDefaultValue(2) + .minValue(0) + .maxValue(Integer.MAX_VALUE) + .stepValue(1) + .build(); } } diff --git a/server/src/main/java/com/soulfiremc/server/plugins/AutoJump.java b/server/src/main/java/com/soulfiremc/server/plugins/AutoJump.java index 124c4bfa7..bc3356921 100644 --- a/server/src/main/java/com/soulfiremc/server/plugins/AutoJump.java +++ b/server/src/main/java/com/soulfiremc/server/plugins/AutoJump.java @@ -23,8 +23,9 @@ import com.soulfiremc.server.api.event.lifecycle.InstanceSettingsRegistryInitEvent; import com.soulfiremc.server.settings.lib.SettingsObject; import com.soulfiremc.server.settings.property.BooleanProperty; -import com.soulfiremc.server.settings.property.MinMaxPropertyLink; -import com.soulfiremc.server.settings.property.Property; +import com.soulfiremc.server.settings.property.ImmutableBooleanProperty; +import com.soulfiremc.server.settings.property.ImmutableMinMaxProperty; +import com.soulfiremc.server.settings.property.MinMaxProperty; import lombok.AccessLevel; import lombok.NoArgsConstructor; import net.lenni0451.lambdaevents.EventHandler; @@ -74,30 +75,28 @@ public void onSettingsRegistryInit(InstanceSettingsRegistryInitEvent event) { @NoArgsConstructor(access = AccessLevel.NONE) private static class AutoJumpSettings implements SettingsObject { - private static final Property.Builder BUILDER = Property.builder("auto-jump"); + private static final String NAMESPACE = "auto-jump"; public static final BooleanProperty ENABLED = - BUILDER.ofBoolean( - "enabled", - "Enable Auto Jump", - "Attempt to jump automatically in random intervals", - false); - public static final MinMaxPropertyLink DELAY = - new MinMaxPropertyLink( - BUILDER.ofInt( - "min-delay", - "Min delay (seconds)", - "Minimum delay between jumps", - 2, - 0, - Integer.MAX_VALUE, - 1), - BUILDER.ofInt( - "max-delay", - "Max delay (seconds)", - "Maximum delay between jumps", - 5, - 0, - Integer.MAX_VALUE, - 1)); + ImmutableBooleanProperty.builder() + .namespace(NAMESPACE) + .key("enabled") + .uiName("Enable Auto Jump") + .description("Attempt to jump automatically in random intervals") + .defaultValue(false) + .build(); + public static final MinMaxProperty DELAY = + ImmutableMinMaxProperty.builder() + .namespace(NAMESPACE) + .key("delay") + .minUiName("Min delay (seconds)") + .maxUiName("Max delay (seconds)") + .minDescription("Minimum delay between jumps") + .maxDescription("Maximum delay between jumps") + .minDefaultValue(2) + .maxDefaultValue(5) + .minValue(0) + .maxValue(Integer.MAX_VALUE) + .stepValue(1) + .build(); } } diff --git a/server/src/main/java/com/soulfiremc/server/plugins/AutoReconnect.java b/server/src/main/java/com/soulfiremc/server/plugins/AutoReconnect.java index a1c91fafc..bfee76320 100644 --- a/server/src/main/java/com/soulfiremc/server/plugins/AutoReconnect.java +++ b/server/src/main/java/com/soulfiremc/server/plugins/AutoReconnect.java @@ -23,8 +23,9 @@ import com.soulfiremc.server.api.event.lifecycle.InstanceSettingsRegistryInitEvent; import com.soulfiremc.server.settings.lib.SettingsObject; import com.soulfiremc.server.settings.property.BooleanProperty; -import com.soulfiremc.server.settings.property.MinMaxPropertyLink; -import com.soulfiremc.server.settings.property.Property; +import com.soulfiremc.server.settings.property.ImmutableBooleanProperty; +import com.soulfiremc.server.settings.property.ImmutableMinMaxProperty; +import com.soulfiremc.server.settings.property.MinMaxProperty; import lombok.AccessLevel; import lombok.NoArgsConstructor; import net.lenni0451.lambdaevents.EventHandler; @@ -94,30 +95,28 @@ public void onAttackTick(AttackTickEvent event) { @NoArgsConstructor(access = AccessLevel.PRIVATE) private static class AutoReconnectSettings implements SettingsObject { - private static final Property.Builder BUILDER = Property.builder("auto-reconnect"); + private static final String NAMESPACE = "auto-reconnect"; public static final BooleanProperty ENABLED = - BUILDER.ofBoolean( - "enabled", - "Enable Auto Reconnect", - "Reconnect a bot when it times out/is kicked", - true); - public static final MinMaxPropertyLink DELAY = - new MinMaxPropertyLink( - BUILDER.ofInt( - "min-delay", - "Min delay (seconds)", - "Minimum delay between reconnects", - 1, - 0, - Integer.MAX_VALUE, - 1), - BUILDER.ofInt( - "max-delay", - "Max delay (seconds)", - "Maximum delay between reconnects", - 5, - 0, - Integer.MAX_VALUE, - 1)); + ImmutableBooleanProperty.builder() + .namespace(NAMESPACE) + .key("enabled") + .uiName("Enable Auto Reconnect") + .description("Reconnect a bot when it times out/is kicked") + .defaultValue(true) + .build(); + public static final MinMaxProperty DELAY = + ImmutableMinMaxProperty.builder() + .namespace(NAMESPACE) + .key("delay") + .minUiName("Min delay (seconds)") + .maxUiName("Max delay (seconds)") + .minDescription("Minimum delay between reconnects") + .maxDescription("Maximum delay between reconnects") + .minDefaultValue(1) + .maxDefaultValue(5) + .minValue(0) + .maxValue(Integer.MAX_VALUE) + .stepValue(1) + .build(); } } diff --git a/server/src/main/java/com/soulfiremc/server/plugins/AutoRegister.java b/server/src/main/java/com/soulfiremc/server/plugins/AutoRegister.java index c8c99246d..cc0dc9ae0 100644 --- a/server/src/main/java/com/soulfiremc/server/plugins/AutoRegister.java +++ b/server/src/main/java/com/soulfiremc/server/plugins/AutoRegister.java @@ -23,7 +23,8 @@ import com.soulfiremc.server.api.event.lifecycle.InstanceSettingsRegistryInitEvent; import com.soulfiremc.server.settings.lib.SettingsObject; import com.soulfiremc.server.settings.property.BooleanProperty; -import com.soulfiremc.server.settings.property.Property; +import com.soulfiremc.server.settings.property.ImmutableBooleanProperty; +import com.soulfiremc.server.settings.property.ImmutableStringProperty; import com.soulfiremc.server.settings.property.StringProperty; import lombok.AccessLevel; import lombok.NoArgsConstructor; @@ -79,36 +80,46 @@ public void onSettingsRegistryInit(InstanceSettingsRegistryInitEvent event) { @NoArgsConstructor(access = AccessLevel.NONE) private static class AutoRegisterSettings implements SettingsObject { - private static final Property.Builder BUILDER = Property.builder("auto-register"); + private static final String NAMESPACE = "auto-register"; public static final BooleanProperty ENABLED = - BUILDER.ofBoolean( - "enabled", - "Enable Auto Register", - "Make bots run the /register and /login command after joining", - false); + ImmutableBooleanProperty.builder() + .namespace(NAMESPACE) + .key("enabled") + .uiName("Enable Auto Register") + .description("Make bots run the /register and /login command after joining") + .defaultValue(false) + .build(); public static final StringProperty REGISTER_COMMAND = - BUILDER.ofString( - "register-command", - "Register Command", - "Command to be executed to register", - "/register %password% %password%"); + ImmutableStringProperty.builder() + .namespace(NAMESPACE) + .key("register-command") + .uiName("Register Command") + .description("Command to be executed to register") + .defaultValue("/register %password% %password%") + .build(); public static final StringProperty LOGIN_COMMAND = - BUILDER.ofString( - "login-command", - "Login Command", - "Command to be executed to log in", - "/login %password%"); + ImmutableStringProperty.builder() + .namespace(NAMESPACE) + .key("login-command") + .uiName("Login Command") + .description("Command to be executed to log in") + .defaultValue("/login %password%") + .build(); public static final StringProperty CAPTCHA_COMMAND = - BUILDER.ofString( - "captcha-command", - "Captcha Command", - "Command to be executed to confirm a captcha", - "/captcha %captcha%"); + ImmutableStringProperty.builder() + .namespace(NAMESPACE) + .key("captcha-command") + .uiName("Captcha Command") + .description("Command to be executed to confirm a captcha") + .defaultValue("/captcha %captcha%") + .build(); public static final StringProperty PASSWORD_FORMAT = - BUILDER.ofString( - "password-format", - "Password Format", - "The password for registering", - "SoulFire"); + ImmutableStringProperty.builder() + .namespace(NAMESPACE) + .key("password-format") + .uiName("Password Format") + .description("The password for registering") + .defaultValue("SoulFire") + .build(); } } diff --git a/server/src/main/java/com/soulfiremc/server/plugins/AutoRespawn.java b/server/src/main/java/com/soulfiremc/server/plugins/AutoRespawn.java index f302706ea..259e3a342 100644 --- a/server/src/main/java/com/soulfiremc/server/plugins/AutoRespawn.java +++ b/server/src/main/java/com/soulfiremc/server/plugins/AutoRespawn.java @@ -24,8 +24,9 @@ import com.soulfiremc.server.api.event.lifecycle.InstanceSettingsRegistryInitEvent; import com.soulfiremc.server.settings.lib.SettingsObject; import com.soulfiremc.server.settings.property.BooleanProperty; -import com.soulfiremc.server.settings.property.MinMaxPropertyLink; -import com.soulfiremc.server.settings.property.Property; +import com.soulfiremc.server.settings.property.ImmutableBooleanProperty; +import com.soulfiremc.server.settings.property.ImmutableMinMaxProperty; +import com.soulfiremc.server.settings.property.MinMaxProperty; import lombok.AccessLevel; import lombok.NoArgsConstructor; import net.lenni0451.lambdaevents.EventHandler; @@ -88,30 +89,28 @@ public void onSettingsRegistryInit(InstanceSettingsRegistryInitEvent event) { @NoArgsConstructor(access = AccessLevel.NONE) private static class AutoRespawnSettings implements SettingsObject { - private static final Property.Builder BUILDER = Property.builder("auto-respawn"); + private static final String NAMESPACE = "auto-respawn"; public static final BooleanProperty ENABLED = - BUILDER.ofBoolean( - "enabled", - "Enable Auto Respawn", - "Respawn automatically after death", - true); - public static final MinMaxPropertyLink DELAY = - new MinMaxPropertyLink( - BUILDER.ofInt( - "min-delay", - "Min delay (seconds)", - "Minimum delay between respawns", - 1, - 0, - Integer.MAX_VALUE, - 1), - BUILDER.ofInt( - "max-delay", - "Max delay (seconds)", - "Maximum delay between respawns", - 3, - 0, - Integer.MAX_VALUE, - 1)); + ImmutableBooleanProperty.builder() + .namespace(NAMESPACE) + .key("enabled") + .uiName("Enable Auto Respawn") + .description("Respawn automatically after death") + .defaultValue(true) + .build(); + public static final MinMaxProperty DELAY = + ImmutableMinMaxProperty.builder() + .namespace(NAMESPACE) + .key("delay") + .minUiName("Min delay (seconds)") + .maxUiName("Max delay (seconds)") + .minDescription("Minimum delay between respawns") + .maxDescription("Maximum delay between respawns") + .minDefaultValue(1) + .maxDefaultValue(3) + .minValue(0) + .maxValue(Integer.MAX_VALUE) + .stepValue(1) + .build(); } } diff --git a/server/src/main/java/com/soulfiremc/server/plugins/AutoTotem.java b/server/src/main/java/com/soulfiremc/server/plugins/AutoTotem.java index c66067bba..21601aab5 100644 --- a/server/src/main/java/com/soulfiremc/server/plugins/AutoTotem.java +++ b/server/src/main/java/com/soulfiremc/server/plugins/AutoTotem.java @@ -24,8 +24,9 @@ import com.soulfiremc.server.data.ItemType; import com.soulfiremc.server.settings.lib.SettingsObject; import com.soulfiremc.server.settings.property.BooleanProperty; -import com.soulfiremc.server.settings.property.MinMaxPropertyLink; -import com.soulfiremc.server.settings.property.Property; +import com.soulfiremc.server.settings.property.ImmutableBooleanProperty; +import com.soulfiremc.server.settings.property.ImmutableMinMaxProperty; +import com.soulfiremc.server.settings.property.MinMaxProperty; import com.soulfiremc.server.util.TimeUtil; import lombok.AccessLevel; import lombok.NoArgsConstructor; @@ -104,30 +105,27 @@ public void onSettingsRegistryInit(InstanceSettingsRegistryInitEvent event) { @NoArgsConstructor(access = AccessLevel.PRIVATE) private static class AutoTotemSettings implements SettingsObject { - private static final Property.Builder BUILDER = Property.builder("auto-totem"); + private static final String NAMESPACE = "auto-totem"; public static final BooleanProperty ENABLED = - BUILDER.ofBoolean( - "enabled", - "Enable Auto Totem", - "Always put available totems in the offhand slot", - true); - public static final MinMaxPropertyLink DELAY = - new MinMaxPropertyLink( - BUILDER.ofInt( - "min-delay", - "Min delay (seconds)", - "Minimum delay between using totems", - 1, - 0, - Integer.MAX_VALUE, - 1), - BUILDER.ofInt( - "max-delay", - "Max delay (seconds)", - "Maximum delay between using totems", - 2, - 0, - Integer.MAX_VALUE, - 1)); + ImmutableBooleanProperty.builder() + .namespace(NAMESPACE) + .key("enabled") + .uiName("Enable Auto Totem") + .description("Always put available totems in the offhand slot") + .defaultValue(true) + .build(); + public static final MinMaxProperty DELAY = ImmutableMinMaxProperty.builder() + .namespace(NAMESPACE) + .key("delay") + .minUiName("Min delay (seconds)") + .maxUiName("Max delay (seconds)") + .minDescription("Minimum delay between using totems") + .maxDescription("Maximum delay between using totems") + .minDefaultValue(1) + .maxDefaultValue(2) + .minValue(0) + .maxValue(Integer.MAX_VALUE) + .stepValue(1) + .build(); } } diff --git a/server/src/main/java/com/soulfiremc/server/plugins/ChatControl.java b/server/src/main/java/com/soulfiremc/server/plugins/ChatControl.java index 464cab285..9e4e2c77f 100644 --- a/server/src/main/java/com/soulfiremc/server/plugins/ChatControl.java +++ b/server/src/main/java/com/soulfiremc/server/plugins/ChatControl.java @@ -25,7 +25,8 @@ import com.soulfiremc.server.brigadier.ServerConsoleCommandSource; import com.soulfiremc.server.settings.lib.SettingsObject; import com.soulfiremc.server.settings.property.BooleanProperty; -import com.soulfiremc.server.settings.property.Property; +import com.soulfiremc.server.settings.property.ImmutableBooleanProperty; +import com.soulfiremc.server.settings.property.ImmutableStringProperty; import com.soulfiremc.server.settings.property.StringProperty; import lombok.AccessLevel; import lombok.NoArgsConstructor; @@ -78,18 +79,22 @@ public void onSettingsRegistryInit(InstanceSettingsRegistryInitEvent event) { @NoArgsConstructor(access = AccessLevel.NONE) private static class ChatControlSettings implements SettingsObject { - private static final Property.Builder BUILDER = Property.builder("chat-control"); + private static final String NAMESPACE = "chat-control"; public static final BooleanProperty ENABLED = - BUILDER.ofBoolean( - "enabled", - "Enable Chat Control", - "Enable controlling the bot with chat messages", - false); + ImmutableBooleanProperty.builder() + .namespace(NAMESPACE) + .key("enabled") + .uiName("Enable Chat Control") + .description("Enable controlling the bot with chat messages") + .defaultValue(false) + .build(); public static final StringProperty COMMAND_PREFIX = - BUILDER.ofString( - "command-prefix", - "Command Prefix", - "Word to put before a command to make the bot execute it", - "$"); + ImmutableStringProperty.builder() + .namespace(NAMESPACE) + .key("command-prefix") + .uiName("Command Prefix") + .description("Word to put before a command to make the bot execute it") + .defaultValue("$") + .build(); } } diff --git a/server/src/main/java/com/soulfiremc/server/plugins/ChatMessageLogger.java b/server/src/main/java/com/soulfiremc/server/plugins/ChatMessageLogger.java index 0ef7aadff..d14e3bda5 100644 --- a/server/src/main/java/com/soulfiremc/server/plugins/ChatMessageLogger.java +++ b/server/src/main/java/com/soulfiremc/server/plugins/ChatMessageLogger.java @@ -24,7 +24,7 @@ import com.soulfiremc.server.api.event.lifecycle.InstanceSettingsRegistryInitEvent; import com.soulfiremc.server.settings.lib.SettingsObject; import com.soulfiremc.server.settings.property.BooleanProperty; -import com.soulfiremc.server.settings.property.Property; +import com.soulfiremc.server.settings.property.ImmutableBooleanProperty; import com.soulfiremc.server.util.structs.ExpiringSet; import lombok.AccessLevel; import lombok.NoArgsConstructor; @@ -94,12 +94,14 @@ public void onSettingsRegistryInit(InstanceSettingsRegistryInitEvent event) { @NoArgsConstructor(access = AccessLevel.PRIVATE) private static class ChatMessageSettings implements SettingsObject { - private static final Property.Builder BUILDER = Property.builder("chat-message-logger"); + private static final String NAMESPACE = "chat-message-logger"; public static final BooleanProperty ENABLED = - BUILDER.ofBoolean( - "enabled", - "Log chat to terminal", - "Log all received chat messages to the terminal", - true); + ImmutableBooleanProperty.builder() + .namespace(NAMESPACE) + .key("enabled") + .uiName("Log chat to terminal") + .description("Log all received chat messages to the terminal") + .defaultValue(true) + .build(); } } diff --git a/server/src/main/java/com/soulfiremc/server/plugins/ClientBrand.java b/server/src/main/java/com/soulfiremc/server/plugins/ClientBrand.java index dc358898c..90a80a0b6 100644 --- a/server/src/main/java/com/soulfiremc/server/plugins/ClientBrand.java +++ b/server/src/main/java/com/soulfiremc/server/plugins/ClientBrand.java @@ -24,7 +24,8 @@ import com.soulfiremc.server.protocol.SFProtocolConstants; import com.soulfiremc.server.settings.lib.SettingsObject; import com.soulfiremc.server.settings.property.BooleanProperty; -import com.soulfiremc.server.settings.property.Property; +import com.soulfiremc.server.settings.property.ImmutableBooleanProperty; +import com.soulfiremc.server.settings.property.ImmutableStringProperty; import com.soulfiremc.server.settings.property.StringProperty; import io.netty.buffer.ByteBufUtil; import io.netty.buffer.Unpooled; @@ -76,18 +77,22 @@ public void onSettingsRegistryInit(InstanceSettingsRegistryInitEvent event) { @NoArgsConstructor(access = AccessLevel.PRIVATE) private static class ClientBrandSettings implements SettingsObject { - private static final Property.Builder BUILDER = Property.builder("client-brand"); + private static final String NAMESPACE = "client-brand"; public static final BooleanProperty ENABLED = - BUILDER.ofBoolean( - "enabled", - "Send client brand", - "Send client brand to the server", - true); + ImmutableBooleanProperty.builder() + .namespace(NAMESPACE) + .key("enabled") + .uiName("Send client brand") + .description("Send client brand to the server") + .defaultValue(true) + .build(); public static final StringProperty CLIENT_BRAND = - BUILDER.ofString( - "client-brand", - "Client brand", - "The client brand to send to the server", - "vanilla"); + ImmutableStringProperty.builder() + .namespace(NAMESPACE) + .key("client-brand") + .uiName("Client brand") + .description("The client brand to send to the server") + .defaultValue("vanilla") + .build(); } } diff --git a/server/src/main/java/com/soulfiremc/server/plugins/ClientSettings.java b/server/src/main/java/com/soulfiremc/server/plugins/ClientSettings.java index ab3cd778b..038b6bff6 100644 --- a/server/src/main/java/com/soulfiremc/server/plugins/ClientSettings.java +++ b/server/src/main/java/com/soulfiremc/server/plugins/ClientSettings.java @@ -104,111 +104,140 @@ public void onSettingsRegistryInit(InstanceSettingsRegistryInitEvent event) { @NoArgsConstructor(access = AccessLevel.NONE) private static class ClientSettingsSettings implements SettingsObject { - private static final Property.Builder BUILDER = Property.builder("client-settings"); + private static final String NAMESPACE = "client-settings"; public static final BooleanProperty ENABLED = - BUILDER.ofBoolean( - "enabled", - "Send client settings", - "Send client settings to the server when joining", - true); + ImmutableBooleanProperty.builder() + .namespace(NAMESPACE) + .key("enabled") + .uiName("Send client settings") + .description("Send client settings to the server when joining") + .defaultValue(true) + .build(); public static final StringProperty CLIENT_LOCALE = - BUILDER.ofString( - "client-locale", - "Client locale", - "The locale the client uses for translations", - "en_gb"); + ImmutableStringProperty.builder() + .namespace(NAMESPACE) + .key("client-locale") + .uiName("Client locale") + .description("The locale the client uses for translations") + .defaultValue("en_gb") + .build(); public static final IntProperty RENDER_DISTANCE = - BUILDER.ofInt( - "render-distance", - "Render distance", - "How far the client renders chunks. (Use this to load more or less chunks from the server)", - 8, - 2, - 32, - 1); + ImmutableIntProperty.builder() + .namespace(NAMESPACE) + .key("render-distance") + .uiName("Render distance") + .description("How far the client renders chunks. (Use this to load more or less chunks from the server)") + .defaultValue(8) + .minValue(2) + .maxValue(32) + .stepValue(1) + .build(); public static final ComboProperty CHAT_VISIBILITY = - BUILDER.ofEnumMapped( - "chat-visibility", - "Chat visibility", - "What type of chat messages the client will receive", - ChatVisibility.values(), - ChatVisibility.FULL, - ComboProperty::capitalizeEnum); + ImmutableComboProperty.builder() + .namespace(NAMESPACE) + .key("chat-visibility") + .uiName("Chat visibility") + .description("What type of chat messages the client will receive") + .defaultValue(ChatVisibility.FULL.name()) + .addOptions(ComboProperty.optionsFromEnum(ChatVisibility.values(), ComboProperty::capitalizeEnum)) + .build(); public static final BooleanProperty USE_CHAT_COLORS = - BUILDER.ofBoolean( - "use-chat-colors", - "Use chat colors", - "Whether the client will use chat colors", - true); + ImmutableBooleanProperty.builder() + .namespace(NAMESPACE) + .key("use-chat-colors") + .uiName("Use chat colors") + .description("Whether the client will use chat colors") + .defaultValue(true) + .build(); public static final BooleanProperty CAPE_ENABLED = - BUILDER.ofBoolean( - "cape-enabled", - "Cape enabled", - "Whether to display the bots cape if it has one", - true); + ImmutableBooleanProperty.builder() + .namespace(NAMESPACE) + .key("cape-enabled") + .uiName("Cape enabled") + .description("Whether to display the bots cape if it has one") + .defaultValue(true) + .build(); public static final BooleanProperty JACKET_ENABLED = - BUILDER.ofBoolean( - "jacket-enabled", - "Jacket enabled", - "Whether to render the jacket overlay skin layer", - true); + ImmutableBooleanProperty.builder() + .namespace(NAMESPACE) + .key("jacket-enabled") + .uiName("Jacket enabled") + .description("Whether to render the jacket overlay skin layer") + .defaultValue(true) + .build(); public static final BooleanProperty LEFT_SLEEVE_ENABLED = - BUILDER.ofBoolean( - "left-sleeve-enabled", - "Left sleeve enabled", - "Whether to render the left overlay skin layer", - true); + ImmutableBooleanProperty.builder() + .namespace(NAMESPACE) + .key("left-sleeve-enabled") + .uiName("Left sleeve enabled") + .description("Whether to render the left overlay skin layer") + .defaultValue(true) + .build(); public static final BooleanProperty RIGHT_SLEEVE_ENABLED = - BUILDER.ofBoolean( - "right-sleeve-enabled", - "Right sleeve enabled", - "Whether to render the right overlay skin layer", - true); + ImmutableBooleanProperty.builder() + .namespace(NAMESPACE) + .key("right-sleeve-enabled") + .uiName("Right sleeve enabled") + .description("Whether to render the right overlay skin layer") + .defaultValue(true) + .build(); public static final BooleanProperty LEFT_PANTS_LEG_ENABLED = - BUILDER.ofBoolean( - "left-pants-leg-enabled", - "Left pants leg enabled", - "Whether to render the left pants leg overlay skin layer", - true); + ImmutableBooleanProperty.builder() + .namespace(NAMESPACE) + .key("left-pants-leg-enabled") + .uiName("Left pants leg enabled") + .description("Whether to render the left pants leg overlay skin layer") + .defaultValue(true) + .build(); public static final BooleanProperty RIGHT_PANTS_LEG_ENABLED = - BUILDER.ofBoolean( - "right-pants-leg-enabled", - "Right pants leg enabled", - "Whether to render the right pants leg overlay skin layer", - true); + ImmutableBooleanProperty.builder() + .namespace(NAMESPACE) + .key("right-pants-leg-enabled") + .uiName("Right pants leg enabled") + .description("Whether to render the right pants leg overlay skin layer") + .defaultValue(true) + .build(); public static final BooleanProperty HAT_ENABLED = - BUILDER.ofBoolean( - "hat-enabled", - "Hat enabled", - "Whether to render the hat overlay skin layer", - true); + ImmutableBooleanProperty.builder() + .namespace(NAMESPACE) + .key("hat-enabled") + .uiName("Hat enabled") + .description("Whether to render the hat overlay skin layer") + .defaultValue(true) + .build(); public static final ComboProperty HAND_PREFERENCE = - BUILDER.ofEnumMapped( - "hand-preference", - "Hand preference", - "What hand the client prefers to use for items", - HandPreference.values(), - HandPreference.RIGHT_HAND, - ComboProperty::capitalizeEnum); + ImmutableComboProperty.builder() + .namespace(NAMESPACE) + .key("hand-preference") + .uiName("Hand preference") + .description("What hand the client prefers to use for items") + .defaultValue(HandPreference.RIGHT_HAND.name()) + .addOptions(ComboProperty.optionsFromEnum(HandPreference.values(), ComboProperty::capitalizeEnum)) + .build(); public static final BooleanProperty TEXT_FILTERING_ENABLED = - BUILDER.ofBoolean( - "text-filtering-enabled", - "Text filtering enabled", - "Whether to filter chat messages from the server", - true); + ImmutableBooleanProperty.builder() + .namespace(NAMESPACE) + .key("text-filtering-enabled") + .uiName("Text filtering enabled") + .description("Whether to filter chat messages from the server") + .defaultValue(true) + .build(); public static final BooleanProperty ALLOWS_LISTING = - BUILDER.ofBoolean( - "allows-listing", - "Allows listing", - "Whether the client wants their username to be shown in the server list", - true); + ImmutableBooleanProperty.builder() + .namespace(NAMESPACE) + .key("allows-listing") + .uiName("Allows listing") + .description("Whether the client wants their username to be shown in the server list") + .defaultValue(true) + .build(); public static final ComboProperty PARTICLE_STATUS = - BUILDER.ofEnumMapped( - "particle-status", - "Particle Status", - "How many particles the client will render", - ParticleStatus.values(), - ParticleStatus.ALL, - ComboProperty::capitalizeEnum); + ImmutableComboProperty.builder() + .namespace(NAMESPACE) + .key("particle-status") + .uiName("Particle Status") + .description("How many particles the client will render") + .defaultValue(ParticleStatus.ALL.name()) + .addOptions(ComboProperty.optionsFromEnum(ParticleStatus.values(), ComboProperty::capitalizeEnum)) + .build(); } } diff --git a/server/src/main/java/com/soulfiremc/server/plugins/FakeVirtualHost.java b/server/src/main/java/com/soulfiremc/server/plugins/FakeVirtualHost.java index 0eac8d0e3..ebcb73069 100644 --- a/server/src/main/java/com/soulfiremc/server/plugins/FakeVirtualHost.java +++ b/server/src/main/java/com/soulfiremc/server/plugins/FakeVirtualHost.java @@ -22,10 +22,7 @@ import com.soulfiremc.server.api.event.bot.SFPacketSendingEvent; import com.soulfiremc.server.api.event.lifecycle.InstanceSettingsRegistryInitEvent; import com.soulfiremc.server.settings.lib.SettingsObject; -import com.soulfiremc.server.settings.property.BooleanProperty; -import com.soulfiremc.server.settings.property.IntProperty; -import com.soulfiremc.server.settings.property.Property; -import com.soulfiremc.server.settings.property.StringProperty; +import com.soulfiremc.server.settings.property.*; import lombok.AccessLevel; import lombok.NoArgsConstructor; import net.lenni0451.lambdaevents.EventHandler; @@ -67,28 +64,34 @@ public void onSettingsRegistryInit(InstanceSettingsRegistryInitEvent event) { @NoArgsConstructor(access = AccessLevel.PRIVATE) private static class FakeVirtualHostSettings implements SettingsObject { - private static final Property.Builder BUILDER = Property.builder("fake-virtual-host"); + private static final String NAMESPACE = "fake-virtual-host"; public static final BooleanProperty ENABLED = - BUILDER.ofBoolean( - "enabled", - "Fake virtual host", - "Whether to fake the virtual host or not", - false); + ImmutableBooleanProperty.builder() + .namespace(NAMESPACE) + .key("enabled") + .uiName("Fake virtual host") + .description("Whether to fake the virtual host or not") + .defaultValue(false) + .build(); public static final StringProperty HOSTNAME = - BUILDER.ofString( - "hostname", - "Hostname", - "The hostname to fake", - "localhost"); + ImmutableStringProperty.builder() + .namespace(NAMESPACE) + .key("hostname") + .uiName("Hostname") + .description("The hostname to fake") + .defaultValue("localhost") + .build(); public static final IntProperty PORT = - BUILDER.ofInt( - "port", - "Port", - "The port to fake", - 25565, - 1, - 65535, - 1, - "#"); + ImmutableIntProperty.builder() + .namespace(NAMESPACE) + .key("port") + .uiName("Port") + .description("The port to fake") + .defaultValue(25565) + .minValue(1) + .maxValue(65535) + .stepValue(1) + .format("#") + .build(); } } diff --git a/server/src/main/java/com/soulfiremc/server/plugins/ForwardingBypass.java b/server/src/main/java/com/soulfiremc/server/plugins/ForwardingBypass.java index c66ab7894..baa912029 100644 --- a/server/src/main/java/com/soulfiremc/server/plugins/ForwardingBypass.java +++ b/server/src/main/java/com/soulfiremc/server/plugins/ForwardingBypass.java @@ -27,7 +27,8 @@ import com.soulfiremc.server.protocol.IdentifiedKey; import com.soulfiremc.server.settings.lib.SettingsObject; import com.soulfiremc.server.settings.property.ComboProperty; -import com.soulfiremc.server.settings.property.Property; +import com.soulfiremc.server.settings.property.ImmutableComboProperty; +import com.soulfiremc.server.settings.property.ImmutableStringProperty; import com.soulfiremc.server.settings.property.StringProperty; import com.soulfiremc.server.util.UUIDHelper; import com.soulfiremc.server.util.VelocityConstants; @@ -276,20 +277,24 @@ private String createBungeeGuardForwardingAddress( @NoArgsConstructor(access = AccessLevel.PRIVATE) private static class ForwardingBypassSettings implements SettingsObject { - private static final Property.Builder BUILDER = Property.builder("forwarding-bypass"); + private static final String NAMESPACE = "forwarding-bypass"; public static final ComboProperty FORWARDING_MODE = - BUILDER.ofEnum( - "forwarding-mode", - "Forwarding mode", - "What type of forwarding to use", - ForwardingMode.values(), - ForwardingMode.NONE); + ImmutableComboProperty.builder() + .namespace(NAMESPACE) + .key("forwarding-mode") + .uiName("Forwarding mode") + .description("What type of forwarding to use") + .defaultValue(ForwardingMode.NONE.name()) + .addOptions(ComboProperty.optionsFromEnum(ForwardingMode.values(), ForwardingMode::toString)) + .build(); public static final StringProperty SECRET = - BUILDER.ofStringSecret( - "secret", - "Secret", - "Secret key used for forwarding. (Not needed for legacy mode)", - "forwarding secret"); + ImmutableStringProperty.builder() + .namespace(NAMESPACE) + .key("secret") + .uiName("Secret") + .description("Secret key used for forwarding. (Not needed for legacy mode)") + .defaultValue("forwarding secret") + .build(); @RequiredArgsConstructor enum ForwardingMode { diff --git a/server/src/main/java/com/soulfiremc/server/plugins/KillAura.java b/server/src/main/java/com/soulfiremc/server/plugins/KillAura.java index fa30e17a0..f4ca69216 100644 --- a/server/src/main/java/com/soulfiremc/server/plugins/KillAura.java +++ b/server/src/main/java/com/soulfiremc/server/plugins/KillAura.java @@ -133,73 +133,86 @@ public void onSettingsRegistryInit(InstanceSettingsRegistryInitEvent event) { @NoArgsConstructor(access = AccessLevel.NONE) private static class KillAuraSettings implements SettingsObject { - private static final Property.Builder BUILDER = Property.builder("kill-aura"); + private static final String NAMESPACE = "kill-aura"; public static final BooleanProperty ENABLE = - BUILDER.ofBoolean( - "enable", "Enable", "Enable KillAura", false); + ImmutableBooleanProperty.builder() + .namespace(NAMESPACE) + .key("enable") + .uiName("Enable") + .description("Enable KillAura") + .defaultValue(false) + .build(); public static final StringProperty WHITELISTED_USER = - BUILDER.ofString( - "whitelisted-user", - "Whitelisted User", - "This user will be ignored by the kill aura", - "Pansexuel"); + ImmutableStringProperty.builder() + .namespace(NAMESPACE) + .key("whitelisted-user") + .uiName("Whitelisted User") + .description("This user will be ignored by the kill aura") + .defaultValue("Pansexuel") + .build(); public static final DoubleProperty HIT_RANGE = - BUILDER.ofDouble( - "hit-range", - "Hit Range", - "Range for the kill aura where the bot will start hitting the entity", - 3.0d, - 0.5d, - 6.0d, - 0.1d); + ImmutableDoubleProperty.builder() + .namespace(NAMESPACE) + .key("hit-range") + .uiName("Hit Range") + .description("Range for the kill aura where the bot will start hitting the entity") + .defaultValue(3.0d) + .minValue(0.5d) + .maxValue(6.0d) + .stepValue(0.1d) + .build(); public static final DoubleProperty SWING_RANGE = - BUILDER.ofDouble( - "swing-range", - "Swing Range", - "Range for the kill aura where the bot will start swinging arm, set to 0 to disable", - 3.5d, - 0.0d, - 10.0d, - 0.1d); + ImmutableDoubleProperty.builder() + .namespace(NAMESPACE) + .key("swing-range") + .uiName("Swing Range") + .description("Range for the kill aura where the bot will start swinging arm, set to 0 to disable") + .defaultValue(3.5d) + .minValue(0.0d) + .maxValue(10.0d) + .stepValue(0.1d) + .build(); public static final DoubleProperty LOOK_RANGE = - BUILDER.ofDouble( - "look-range", - "Look Range", - "Range for the kill aura where the bot will start looking at the entity, set to 0 to disable", - 4.8d, - 0.0d, - 25.0d, - 0.1d); + ImmutableDoubleProperty.builder() + .namespace(NAMESPACE) + .key("look-range") + .uiName("Look Range") + .description("Range for the kill aura where the bot will start looking at the entity, set to 0 to disable") + .defaultValue(4.8d) + .minValue(0.0d) + .maxValue(25.0d) + .stepValue(0.1d) + .build(); public static final BooleanProperty CHECK_WALLS = - BUILDER.ofBoolean( - "check-walls", - "Check Walls", - "Check if the entity is behind a wall", - true); + ImmutableBooleanProperty.builder() + .namespace(NAMESPACE) + .key("check-walls") + .uiName("Check Walls") + .description("Check if the entity is behind a wall") + .defaultValue(true) + .build(); public static final BooleanProperty IGNORE_COOLDOWN = - BUILDER.ofBoolean( - "ignore-cooldown", - "Ignore Cooldown", - "Ignore the 1.9+ attack cooldown to act like a 1.8 kill aura", - false); - public static final MinMaxPropertyLink ATTACK_DELAY_TICKS = - new MinMaxPropertyLink( - BUILDER.ofInt( - "attack-delay-ticks-min", - "Attack Delay Ticks Min", - "Minimum tick delay between attacks on pre-1.9 versions", - 8, - 1, - 20, - 1), - BUILDER.ofInt( - "attack-delay-ticks-max", - "Attack Delay Ticks Max", - "Maximum tick delay between attacks on pre-1.9 versions", - 12, - 1, - 20, - 1)); + ImmutableBooleanProperty.builder() + .namespace(NAMESPACE) + .key("ignore-cooldown") + .uiName("Ignore Cooldown") + .description("Ignore the 1.9+ attack cooldown to act like a 1.8 kill aura") + .defaultValue(false) + .build(); + public static final MinMaxProperty ATTACK_DELAY_TICKS = + ImmutableMinMaxProperty.builder() + .namespace(NAMESPACE) + .key("attack-delay-ticks") + .minUiName("Attack Delay Ticks Min") + .maxUiName("Attack Delay Ticks Max") + .minDescription("Minimum tick delay between attacks on pre-1.9 versions") + .maxDescription("Maximum tick delay between attacks on pre-1.9 versions") + .minDefaultValue(8) + .maxDefaultValue(12) + .minValue(1) + .maxValue(20) + .stepValue(1) + .build(); } private record AttackEntity(Entity attackEntity, double distance) {} diff --git a/server/src/main/java/com/soulfiremc/server/plugins/ModLoaderSupport.java b/server/src/main/java/com/soulfiremc/server/plugins/ModLoaderSupport.java index 4c5763924..a24c49291 100644 --- a/server/src/main/java/com/soulfiremc/server/plugins/ModLoaderSupport.java +++ b/server/src/main/java/com/soulfiremc/server/plugins/ModLoaderSupport.java @@ -25,7 +25,7 @@ import com.soulfiremc.server.protocol.BotConnection; import com.soulfiremc.server.settings.lib.SettingsObject; import com.soulfiremc.server.settings.property.ComboProperty; -import com.soulfiremc.server.settings.property.Property; +import com.soulfiremc.server.settings.property.ImmutableComboProperty; import io.netty.buffer.Unpooled; import lombok.AccessLevel; import lombok.NoArgsConstructor; @@ -241,14 +241,16 @@ private void sendFML2HandshakeResponse( @NoArgsConstructor(access = AccessLevel.PRIVATE) private static class ModLoaderSettings implements SettingsObject { - private static final Property.Builder BUILDER = Property.builder("mod-loader"); + private static final String NAMESPACE = "mod-loader"; public static final ComboProperty FORGE_MODE = - BUILDER.ofEnum( - "mod-loader-mode", - "Mod Loader mode", - "What mod loader to use", - ModLoaderMode.values(), - ModLoaderMode.NONE); + ImmutableComboProperty.builder() + .namespace(NAMESPACE) + .key("mod-loader-mode") + .uiName("Mod Loader mode") + .description("What mod loader to use") + .defaultValue(ModLoaderMode.NONE.name()) + .addOptions(ComboProperty.optionsFromEnum(ModLoaderMode.values(), ModLoaderMode::toString)) + .build(); @RequiredArgsConstructor enum ModLoaderMode { diff --git a/server/src/main/java/com/soulfiremc/server/plugins/POVServer.java b/server/src/main/java/com/soulfiremc/server/plugins/POVServer.java index ab6e9ba81..e9af12ac9 100644 --- a/server/src/main/java/com/soulfiremc/server/plugins/POVServer.java +++ b/server/src/main/java/com/soulfiremc/server/plugins/POVServer.java @@ -40,10 +40,7 @@ import com.soulfiremc.server.settings.BotSettings; import com.soulfiremc.server.settings.lib.SettingsObject; import com.soulfiremc.server.settings.lib.SettingsSource; -import com.soulfiremc.server.settings.property.BooleanProperty; -import com.soulfiremc.server.settings.property.IntProperty; -import com.soulfiremc.server.settings.property.Property; -import com.soulfiremc.server.settings.property.StringProperty; +import com.soulfiremc.server.settings.property.*; import com.soulfiremc.server.user.Permission; import com.soulfiremc.server.user.ServerCommandSource; import com.soulfiremc.server.util.PortHelper; @@ -1023,34 +1020,42 @@ public void onAttackEnded(AttackEndedEvent event) { @NoArgsConstructor(access = AccessLevel.NONE) private static class POVServerSettings implements SettingsObject { - private static final Property.Builder BUILDER = Property.builder("pov-server"); + private static final String NAMESPACE = "pov-server"; public static final BooleanProperty ENABLED = - BUILDER.ofBoolean( - "enabled", - "Enable POV server", - "Host a POV server for the bots", - false); + ImmutableBooleanProperty.builder() + .namespace(NAMESPACE) + .key("enabled") + .uiName("Enable POV server") + .description("Host a POV server for the bots") + .defaultValue(false) + .build(); public static final IntProperty PORT_START = - BUILDER.ofInt( - "port-start", - "Port Start", - "What port to start with to host the POV server", - 31765, - 1, - 65535, - 1); + ImmutableIntProperty.builder() + .namespace(NAMESPACE) + .key("port-start") + .uiName("Port Start") + .description("What port to start with to host the POV server") + .defaultValue(31765) + .minValue(1) + .maxValue(65535) + .stepValue(1) + .build(); public static final BooleanProperty ENABLE_COMMANDS = - BUILDER.ofBoolean( - "enable-commands", - "Enable commands", - "Allow users connected to the POV server to execute commands in the SF server shell", - true); + ImmutableBooleanProperty.builder() + .namespace(NAMESPACE) + .key("enable-commands") + .uiName("Enable commands") + .description("Allow users connected to the POV server to execute commands in the SF server shell") + .defaultValue(true) + .build(); public static final StringProperty COMMAND_PREFIX = - BUILDER.ofString( - "command-prefix", - "Command Prefix", - "The prefix to use for commands executed in the SF server shell", - "#"); + ImmutableStringProperty.builder() + .namespace(NAMESPACE) + .key("command-prefix") + .uiName("Command Prefix") + .description("The prefix to use for commands executed in the SF server shell") + .defaultValue("#") + .build(); } private record PovServerUser(Session session, String username) implements ServerCommandSource { diff --git a/server/src/main/java/com/soulfiremc/server/plugins/ServerListBypass.java b/server/src/main/java/com/soulfiremc/server/plugins/ServerListBypass.java index ce8ba27f1..0370d6a8c 100644 --- a/server/src/main/java/com/soulfiremc/server/plugins/ServerListBypass.java +++ b/server/src/main/java/com/soulfiremc/server/plugins/ServerListBypass.java @@ -23,8 +23,9 @@ import com.soulfiremc.server.api.event.lifecycle.InstanceSettingsRegistryInitEvent; import com.soulfiremc.server.settings.lib.SettingsObject; import com.soulfiremc.server.settings.property.BooleanProperty; -import com.soulfiremc.server.settings.property.MinMaxPropertyLink; -import com.soulfiremc.server.settings.property.Property; +import com.soulfiremc.server.settings.property.ImmutableBooleanProperty; +import com.soulfiremc.server.settings.property.ImmutableMinMaxProperty; +import com.soulfiremc.server.settings.property.MinMaxProperty; import com.soulfiremc.server.util.TimeUtil; import lombok.AccessLevel; import lombok.NoArgsConstructor; @@ -72,30 +73,27 @@ public void onSettingsRegistryInit(InstanceSettingsRegistryInitEvent event) { @NoArgsConstructor(access = AccessLevel.NONE) private static class ServerListBypassSettings implements SettingsObject { - private static final Property.Builder BUILDER = Property.builder("server-list-bypass"); + private static final String NAMESPACE = "server-list-bypass"; public static final BooleanProperty ENABLED = - BUILDER.ofBoolean( - "enabled", - "Enable Server List Bypass", - "Whether to ping the server list before connecting. (Bypasses anti-bots like EpicGuard)", - false); - public static final MinMaxPropertyLink DELAY = - new MinMaxPropertyLink( - BUILDER.ofInt( - "min-delay", - "Min delay (seconds)", - "Minimum delay between joining the server", - 1, - 0, - Integer.MAX_VALUE, - 1), - BUILDER.ofInt( - "max-delay", - "Max delay (seconds)", - "Maximum delay between joining the server", - 3, - 0, - Integer.MAX_VALUE, - 1)); + ImmutableBooleanProperty.builder() + .namespace(NAMESPACE) + .key("enabled") + .uiName("Enable Server List Bypass") + .description("Whether to ping the server list before connecting. (Bypasses anti-bots like EpicGuard)") + .defaultValue(false) + .build(); + public static final MinMaxProperty DELAY = ImmutableMinMaxProperty.builder() + .namespace(NAMESPACE) + .key("delay") + .minUiName("Min delay (seconds)") + .maxUiName("Max delay (seconds)") + .minDescription("Minimum delay between joining the server") + .maxDescription("Maximum delay between joining the server") + .minDefaultValue(1) + .maxDefaultValue(3) + .minValue(0) + .maxValue(Integer.MAX_VALUE) + .stepValue(1) + .build(); } } diff --git a/server/src/main/java/com/soulfiremc/server/settings/AISettings.java b/server/src/main/java/com/soulfiremc/server/settings/AISettings.java index 049fad711..80cb863ad 100644 --- a/server/src/main/java/com/soulfiremc/server/settings/AISettings.java +++ b/server/src/main/java/com/soulfiremc/server/settings/AISettings.java @@ -19,11 +19,7 @@ import com.soulfiremc.server.settings.lib.SettingsObject; import com.soulfiremc.server.settings.lib.SettingsSource; -import com.soulfiremc.server.settings.property.BooleanProperty; -import com.soulfiremc.server.settings.property.IntProperty; -import com.soulfiremc.server.settings.property.Property; -import com.soulfiremc.server.settings.property.StringProperty; -import com.soulfiremc.server.util.BuiltinSettingsConstants; +import com.soulfiremc.server.settings.property.*; import io.github.ollama4j.OllamaAPI; import lombok.AccessLevel; import lombok.NoArgsConstructor; @@ -32,47 +28,58 @@ @Slf4j @NoArgsConstructor(access = AccessLevel.PRIVATE) public class AISettings implements SettingsObject { - public static final Property.Builder BUILDER = - Property.builder(BuiltinSettingsConstants.AI_SETTINGS_ID); + private static final String NAMESPACE = "ai"; public static final StringProperty API_ENDPOINT = - BUILDER.ofString( - "api-endpoint", - "API Endpoint", - "Ollama API server endpoint", - "http://127.0.0.1:11434"); + ImmutableStringProperty.builder() + .namespace(NAMESPACE) + .key("api-endpoint") + .uiName("API Endpoint") + .description("Ollama API server endpoint") + .defaultValue("http://127.0.0.1:11434") + .build(); public static final StringProperty API_USERNAME = - BUILDER.ofString( - "api-username", - "API Username", - "Ollama API server username (if required)", - ""); + ImmutableStringProperty.builder() + .namespace(NAMESPACE) + .key("api-username") + .uiName("API Username") + .description("Ollama API server username (if required)") + .defaultValue("") + .build(); public static final StringProperty API_PASSWORD = - BUILDER.ofString( - "api-password", - "API Password", - "Ollama API server password (if required)", - ""); + ImmutableStringProperty.builder() + .namespace(NAMESPACE) + .key("api-password") + .uiName("API Password") + .description("Ollama API server password (if required)") + .defaultValue("") + .build(); public static final IntProperty REQUEST_TIMEOUT = - BUILDER.ofInt( - "api-request-timeout", - "API Request Timeout", - "Ollama API request timeout (seconds)", - 5, - 1, - 6, - 1); + ImmutableIntProperty.builder() + .namespace(NAMESPACE) + .key("api-request-timeout") + .uiName("API Request Timeout") + .description("Ollama API request timeout (seconds)") + .defaultValue(5) + .minValue(1) + .maxValue(6) + .stepValue(1) + .build(); public static final BooleanProperty PULL_MODELS = - BUILDER.ofBoolean( - "pull-models", - "Pull Models", - "Whether to pull models if not found already installed", - true); + ImmutableBooleanProperty.builder() + .namespace(NAMESPACE) + .key("pull-models") + .uiName("Pull Models") + .description("Whether to pull models if not found already installed") + .defaultValue(true) + .build(); public static final BooleanProperty VERBOSE = - BUILDER.ofBoolean( - "verbose", - "Verbose", - "Enable verbose extra logging", - false); + ImmutableBooleanProperty.builder() + .namespace(NAMESPACE) + .key("verbose") + .uiName("Verbose") + .description("Enable verbose extra logging") + .defaultValue(false) + .build(); public static OllamaAPI create(SettingsSource source) { var api = new OllamaAPI(source.get(AISettings.API_ENDPOINT)); diff --git a/server/src/main/java/com/soulfiremc/server/settings/AccountSettings.java b/server/src/main/java/com/soulfiremc/server/settings/AccountSettings.java index b1718a302..434aa5448 100644 --- a/server/src/main/java/com/soulfiremc/server/settings/AccountSettings.java +++ b/server/src/main/java/com/soulfiremc/server/settings/AccountSettings.java @@ -19,26 +19,29 @@ import com.soulfiremc.server.settings.lib.SettingsObject; import com.soulfiremc.server.settings.property.BooleanProperty; -import com.soulfiremc.server.settings.property.Property; +import com.soulfiremc.server.settings.property.ImmutableBooleanProperty; +import com.soulfiremc.server.settings.property.ImmutableStringProperty; import com.soulfiremc.server.settings.property.StringProperty; -import com.soulfiremc.server.util.BuiltinSettingsConstants; import lombok.AccessLevel; import lombok.NoArgsConstructor; @NoArgsConstructor(access = AccessLevel.NONE) public class AccountSettings implements SettingsObject { - private static final Property.Builder BUILDER = - Property.builder(BuiltinSettingsConstants.ACCOUNT_SETTINGS_ID); + private static final String NAMESPACE = "account"; public static final StringProperty NAME_FORMAT = - BUILDER.ofString( - "name-format", - "Name format", - "The format of the bot names. %d will be replaced with the bot number.", - "Bot_%d"); + ImmutableStringProperty.builder() + .namespace(NAMESPACE) + .key("name-format") + .uiName("Name format") + .description("The format of the bot names. %d will be replaced with the bot number.") + .defaultValue("Bot_%d") + .build(); public static final BooleanProperty SHUFFLE_ACCOUNTS = - BUILDER.ofBoolean( - "shuffle-accounts", - "Shuffle accounts", - "Should the accounts order be random when connecting bots?", - false); + ImmutableBooleanProperty.builder() + .namespace(NAMESPACE) + .key("shuffle-accounts") + .uiName("Shuffle accounts") + .description("Should the accounts order be random when connecting bots?") + .defaultValue(false) + .build(); } diff --git a/server/src/main/java/com/soulfiremc/server/settings/BotSettings.java b/server/src/main/java/com/soulfiremc/server/settings/BotSettings.java index 1e510351d..aedaa904e 100644 --- a/server/src/main/java/com/soulfiremc/server/settings/BotSettings.java +++ b/server/src/main/java/com/soulfiremc/server/settings/BotSettings.java @@ -19,7 +19,6 @@ import com.soulfiremc.server.settings.lib.SettingsObject; import com.soulfiremc.server.settings.property.*; -import com.soulfiremc.server.util.BuiltinSettingsConstants; import com.soulfiremc.server.viaversion.SFVersionConstants; import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; import com.viaversion.viaversion.api.protocol.version.VersionType; @@ -31,6 +30,7 @@ @NoArgsConstructor(access = AccessLevel.PRIVATE) public class BotSettings implements SettingsObject { + private static final String NAMESPACE = "bot"; public static final Function PROTOCOL_VERSION_PARSER = version -> { var split = version.split("\\|"); @@ -41,105 +41,119 @@ public class BotSettings implements SettingsObject { return ProtocolVersion.getProtocol(VersionType.valueOf(split[0]), Integer.parseInt(split[1])); }; - private static final Property.Builder BUILDER = - Property.builder(BuiltinSettingsConstants.BOT_SETTINGS_ID); public static final StringProperty ADDRESS = - BUILDER.ofString( - "address", - "Address", - "Address to connect to", - "127.0.0.1:25565"); + ImmutableStringProperty.builder() + .namespace(NAMESPACE) + .key("address") + .uiName("Address") + .description("Address to connect to") + .defaultValue("127.0.0.1:25565") + .build(); public static final IntProperty AMOUNT = - BUILDER.ofInt( - "amount", - "Amount", - "Amount of bots to connect", - 1, - 1, - Integer.MAX_VALUE, - 1); - public static final MinMaxPropertyLink JOIN_DELAY = - new MinMaxPropertyLink( - BUILDER.ofInt( - "join-min-delay", - "Min Join Delay (ms)", - "Minimum delay between joins in milliseconds", - 1000, - 0, - Integer.MAX_VALUE, - 1), - BUILDER.ofInt( - "join-max-delay", - "Max Join Delay (ms)", - "Maximum delay between joins in milliseconds", - 3000, - 0, - Integer.MAX_VALUE, - 1)); + ImmutableIntProperty.builder() + .namespace(NAMESPACE) + .key("amount") + .uiName("Amount") + .description("Amount of bots to connect") + .defaultValue(1) + .minValue(1) + .maxValue(Integer.MAX_VALUE) + .stepValue(1) + .build(); + public static final MinMaxProperty JOIN_DELAY = ImmutableMinMaxProperty.builder() + .namespace(NAMESPACE) + .key("join-delay") + .minUiName("Min Join Delay (ms)") + .maxUiName("Max Join Delay (ms)") + .minDescription("Minimum delay between joins in milliseconds") + .maxDescription("Maximum delay between joins in milliseconds") + .minDefaultValue(1000) + .maxDefaultValue(3000) + .minValue(0) + .maxValue(Integer.MAX_VALUE) + .stepValue(1) + .build(); public static final ComboProperty PROTOCOL_VERSION = - BUILDER.ofCombo( - "protocol-version", - "Protocol Version", - "Minecraft protocol version to use", - getProtocolVersionOptions(), - getLatestProtocolVersionIndex()); + ImmutableComboProperty.builder() + .namespace(NAMESPACE) + .key("protocol-version") + .uiName("Protocol Version") + .description("Minecraft protocol version to use") + .defaultValue(getLatestProtocolVersionId()) + .addOptions(getProtocolVersionOptions()) + .build(); public static final IntProperty READ_TIMEOUT = - BUILDER.ofInt( - "read-timeout", - "Read Timeout", - "Read timeout in seconds", - 30, - 0, - Integer.MAX_VALUE, - 1); + ImmutableIntProperty.builder() + .namespace(NAMESPACE) + .key("read-timeout") + .uiName("Read Timeout") + .description("Read timeout in seconds") + .defaultValue(30) + .minValue(0) + .maxValue(Integer.MAX_VALUE) + .stepValue(1) + .build(); public static final IntProperty WRITE_TIMEOUT = - BUILDER.ofInt( - "write-timeout", - "Write Timeout", - "Write timeout in seconds", - 0, - 0, - Integer.MAX_VALUE, - 1); + ImmutableIntProperty.builder() + .namespace(NAMESPACE) + .key("write-timeout") + .uiName("Write Timeout") + .description("Write timeout in seconds") + .defaultValue(0) + .minValue(0) + .maxValue(Integer.MAX_VALUE) + .stepValue(1) + .build(); public static final IntProperty CONNECT_TIMEOUT = - BUILDER.ofInt( - "connect-timeout", - "Connect Timeout", - "Connect timeout in seconds", - 30, - 0, - Integer.MAX_VALUE, - 1); + ImmutableIntProperty.builder() + .namespace(NAMESPACE) + .key("connect-timeout") + .uiName("Connect Timeout") + .description("Connect timeout in seconds") + .defaultValue(30) + .minValue(0) + .maxValue(Integer.MAX_VALUE) + .stepValue(1) + .build(); public static final BooleanProperty RESOLVE_SRV = - BUILDER.ofBoolean( - "resolve-srv", - "Resolve SRV", - "Try to resolve SRV records from the address", - true); + ImmutableBooleanProperty.builder() + .namespace(NAMESPACE) + .key("resolve-srv") + .uiName("Resolve SRV") + .description("Try to resolve SRV records from the address") + .defaultValue(true) + .build(); public static final IntProperty CONCURRENT_CONNECTS = - BUILDER.ofInt( - "concurrent-connects", - "Concurrent Connects", - "Max amount of bots attempting to connect at once", - 1, - 1, - Integer.MAX_VALUE, - 1); + ImmutableIntProperty.builder() + .namespace(NAMESPACE) + .key("concurrent-connects") + .uiName("Concurrent Connects") + .description("Max amount of bots attempting to connect at once") + .defaultValue(1) + .minValue(1) + .maxValue(Integer.MAX_VALUE) + .stepValue(1) + .build(); public static final BooleanProperty RESTORE_ON_REBOOT = - BUILDER.ofBoolean( - "restore-on-reboot", - "Restore on Reboot", - "Whether the attack should be restored after a reboot of the SoulFire machine. If turned off, the attack will not be restored after a reboot.", - true); + ImmutableBooleanProperty.builder() + .namespace(NAMESPACE) + .key("restore-on-reboot") + .uiName("Restore on Reboot") + .description("Whether the attack should be restored after a reboot of the SoulFire machine. If turned off, the attack will not be restored after a reboot.") + .defaultValue(true) + .build(); + + private static String formatVersion(ProtocolVersion version) { + return "%s|%d".formatted(version.getVersionType().name(), version.getOriginalVersion()); + } private static ComboProperty.ComboOption[] getProtocolVersionOptions() { return ProtocolVersionList.getProtocolsNewToOld().stream() - .map(version -> new ComboProperty.ComboOption("%s|%d".formatted(version.getVersionType().name(), version.getOriginalVersion()), version.getName())) + .map(version -> new ComboProperty.ComboOption(formatVersion(version), version.getName())) .toArray(ComboProperty.ComboOption[]::new); } - private static int getLatestProtocolVersionIndex() { - return ProtocolVersionList.getProtocolsNewToOld() - .indexOf(SFVersionConstants.CURRENT_PROTOCOL_VERSION); + private static String getLatestProtocolVersionId() { + return formatVersion(SFVersionConstants.CURRENT_PROTOCOL_VERSION); } } diff --git a/server/src/main/java/com/soulfiremc/server/settings/DevSettings.java b/server/src/main/java/com/soulfiremc/server/settings/DevSettings.java index d849532ce..b006a8bf5 100644 --- a/server/src/main/java/com/soulfiremc/server/settings/DevSettings.java +++ b/server/src/main/java/com/soulfiremc/server/settings/DevSettings.java @@ -19,43 +19,51 @@ import com.soulfiremc.server.settings.lib.SettingsObject; import com.soulfiremc.server.settings.property.BooleanProperty; -import com.soulfiremc.server.settings.property.Property; -import com.soulfiremc.server.util.BuiltinSettingsConstants; +import com.soulfiremc.server.settings.property.ImmutableBooleanProperty; import lombok.AccessLevel; import lombok.NoArgsConstructor; @NoArgsConstructor(access = AccessLevel.PRIVATE) public class DevSettings implements SettingsObject { - public static final Property.Builder BUILDER = - Property.builder(BuiltinSettingsConstants.DEV_SETTINGS_ID); + private static final String NAMESPACE = "dev"; public static final BooleanProperty CORE_DEBUG = - BUILDER.ofBoolean( - "core-debug", - "Core debug", - "Enable core code debug logging", - false); + ImmutableBooleanProperty.builder() + .namespace(NAMESPACE) + .key("core-debug") + .uiName("Core debug") + .description("Enable core code debug logging") + .defaultValue(false) + .build(); public static final BooleanProperty VIA_DEBUG = - BUILDER.ofBoolean( - "via-debug", - "Via debug", - "Enable Via* code debug logging", - false); + ImmutableBooleanProperty.builder() + .namespace(NAMESPACE) + .key("via-debug") + .uiName("Via debug") + .description("Enable Via* code debug logging") + .defaultValue(false) + .build(); public static final BooleanProperty NETTY_DEBUG = - BUILDER.ofBoolean( - "netty-debug", - "Netty debug", - "Enable Netty debug logging", - false); + ImmutableBooleanProperty.builder() + .namespace(NAMESPACE) + .key("netty-debug") + .uiName("Netty debug") + .description("Enable Netty debug logging") + .defaultValue(false) + .build(); public static final BooleanProperty GRPC_DEBUG = - BUILDER.ofBoolean( - "grpc-debug", - "gRPC debug", - "Enable gRPC debug logging", - false); + ImmutableBooleanProperty.builder() + .namespace(NAMESPACE) + .key("grpc-debug") + .uiName("gRPC debug") + .description("Enable gRPC debug logging") + .defaultValue(false) + .build(); public static final BooleanProperty MCPROTOCOLLIB_DEBUG = - BUILDER.ofBoolean( - "mcprotocollib-debug", - "MCProtocolLib debug", - "Enable MCProtocolLib debug logging", - false); + ImmutableBooleanProperty.builder() + .namespace(NAMESPACE) + .key("mcprotocollib-debug") + .uiName("MCProtocolLib debug") + .description("Enable MCProtocolLib debug logging") + .defaultValue(false) + .build(); } diff --git a/server/src/main/java/com/soulfiremc/server/settings/ProxySettings.java b/server/src/main/java/com/soulfiremc/server/settings/ProxySettings.java index f9a4df5e3..d985430f5 100644 --- a/server/src/main/java/com/soulfiremc/server/settings/ProxySettings.java +++ b/server/src/main/java/com/soulfiremc/server/settings/ProxySettings.java @@ -19,29 +19,32 @@ import com.soulfiremc.server.settings.lib.SettingsObject; import com.soulfiremc.server.settings.property.BooleanProperty; +import com.soulfiremc.server.settings.property.ImmutableBooleanProperty; +import com.soulfiremc.server.settings.property.ImmutableIntProperty; import com.soulfiremc.server.settings.property.IntProperty; -import com.soulfiremc.server.settings.property.Property; -import com.soulfiremc.server.util.BuiltinSettingsConstants; import lombok.AccessLevel; import lombok.NoArgsConstructor; @NoArgsConstructor(access = AccessLevel.PRIVATE) public class ProxySettings implements SettingsObject { - private static final Property.Builder BUILDER = - Property.builder(BuiltinSettingsConstants.PROXY_SETTINGS_ID); + private static final String NAMESPACE = "proxy"; public static final IntProperty BOTS_PER_PROXY = - BUILDER.ofInt( - "bots-per-proxy", - "Bots per proxy", - "Amount of bots that can be on a single proxy", - -1, - -1, - Integer.MAX_VALUE, - 1); + ImmutableIntProperty.builder() + .namespace(NAMESPACE) + .key("bots-per-proxy") + .uiName("Bots per proxy") + .description("Amount of bots that can be on a single proxy") + .defaultValue(-1) + .minValue(-1) + .maxValue(Integer.MAX_VALUE) + .stepValue(1) + .build(); public static final BooleanProperty SHUFFLE_PROXIES = - BUILDER.ofBoolean( - "shuffle-proxies", - "Shuffle proxies", - "Should the proxy order be random when connecting bots?", - false); + ImmutableBooleanProperty.builder() + .namespace(NAMESPACE) + .key("shuffle-proxies") + .uiName("Shuffle proxies") + .description("Should the proxy order be random when connecting bots?") + .defaultValue(false) + .build(); } diff --git a/server/src/main/java/com/soulfiremc/server/settings/lib/ServerSettingsRegistry.java b/server/src/main/java/com/soulfiremc/server/settings/lib/ServerSettingsRegistry.java index d0c956cc7..35bec727f 100644 --- a/server/src/main/java/com/soulfiremc/server/settings/lib/ServerSettingsRegistry.java +++ b/server/src/main/java/com/soulfiremc/server/settings/lib/ServerSettingsRegistry.java @@ -40,14 +40,14 @@ public class ServerSettingsRegistry { private static IntSetting createIntSetting(IntProperty property) { var builder = IntSetting.newBuilder() + .setUiName(property.uiName()) + .setDescription(property.description()) .setDef(property.defaultValue()) .setMin(property.minValue()) .setMax(property.maxValue()) .setStep(property.stepValue()); - if (property.format() != null) { - builder = builder.setFormat(property.format()); - } + property.format().ifPresent(builder::setFormat); return builder.build(); } @@ -55,14 +55,32 @@ private static IntSetting createIntSetting(IntProperty property) { private static DoubleSetting createDoubleSetting(DoubleProperty property) { var builder = DoubleSetting.newBuilder() + .setUiName(property.uiName()) + .setDescription(property.description()) .setDef(property.defaultValue()) .setMin(property.minValue()) .setMax(property.maxValue()) .setStep(property.stepValue()); - if (property.format() != null) { - builder = builder.setFormat(property.format()); - } + property.format().ifPresent(builder::setFormat); + + return builder.build(); + } + + private static MinMaxSetting createMinMaxSetting(MinMaxProperty property) { + var builder = + MinMaxSetting.newBuilder() + .setMinUiName(property.minUiName()) + .setMaxUiName(property.maxUiName()) + .setMinDescription(property.minDescription()) + .setMaxDescription(property.maxDescription()) + .setMinDef(property.minValue()) + .setMaxDef(property.maxValue()) + .setMin(property.minValue()) + .setMax(property.maxValue()) + .setStep(property.stepValue()); + + property.format().ifPresent(builder::setFormat); return builder.build(); } @@ -80,7 +98,7 @@ private static DoubleSetting createDoubleSetting(DoubleProperty property) { @This @ApiStatus.Internal public ServerSettingsRegistry addClass(Class clazz, String pageName, String iconId) { - return addClass(clazz, pageName, null, iconId); + return addClassInternal(clazz, pageName, null, iconId); } /** @@ -96,6 +114,12 @@ public ServerSettingsRegistry addClass(Class clazz, St */ @This public ServerSettingsRegistry addClass( + Class clazz, String pageName, Plugin owningPlugin, String iconId) { + return addClassInternal(clazz, pageName, owningPlugin, iconId); + } + + @This + private ServerSettingsRegistry addClassInternal( Class clazz, String pageName, @Nullable Plugin owningPlugin, String iconId) { for (var field : clazz.getDeclaredFields()) { if (Modifier.isPublic(field.getModifiers()) @@ -110,12 +134,10 @@ public ServerSettingsRegistry addClass( throw new IllegalStateException("Property is null!"); } - var registry = namespaceMap.get(property.namespace()); - if (registry == null) { + var registry = namespaceMap.computeIfAbsent(property.namespace(), k -> { var pluginInfo = owningPlugin != null ? owningPlugin.pluginInfo() : null; - registry = new NamespaceRegistry(pluginInfo, pageName, new ArrayList<>(), iconId); - namespaceMap.put(property.namespace(), registry); - } + return new NamespaceRegistry(pluginInfo, pageName, new ArrayList<>(), iconId); + }); registry.properties.add(property); } catch (IllegalAccessException e) { @@ -134,72 +156,42 @@ public List exportSettingsMeta() { var namespaceRegistry = namespaceEntry.getValue(); var entries = new ArrayList(); for (var property : namespaceRegistry.properties) { - switch (property) { - case BooleanProperty booleanProperty -> entries.add( - SettingEntry.newBuilder() - .setSingle( - fillSingleProperties(booleanProperty) - .setType( - SettingType.newBuilder() - .setBool( - BoolSetting.newBuilder() - .setDef(booleanProperty.defaultValue()) - .build()) - .build()) - .build()) - .build()); - case IntProperty intProperty -> entries.add( - SettingEntry.newBuilder() - .setSingle( - fillSingleProperties(intProperty) - .setType( - SettingType.newBuilder() - .setInt(createIntSetting(intProperty)) - .build()) - .build()) - .build()); - case DoubleProperty doubleProperty -> entries.add( - SettingEntry.newBuilder() - .setSingle( - fillSingleProperties(doubleProperty) - .setType( - SettingType.newBuilder() - .setDouble(createDoubleSetting(doubleProperty)) - .build()) - .build()) - .build()); - case MinMaxPropertyLink minMaxPropertyLink -> { - var minProperty = minMaxPropertyLink.min(); - var maxProperty = minMaxPropertyLink.max(); - entries.add( - SettingEntry.newBuilder() - .setMinMaxPair( - SettingEntryMinMaxPair.newBuilder() - .setMin( - fillMultiProperties(minProperty) - .setIntSetting(createIntSetting(minProperty)) - .build()) - .setMax( - fillMultiProperties(maxProperty) - .setIntSetting(createIntSetting(maxProperty)) - .build()) + entries.add(switch (property) { + case BooleanProperty booleanProperty -> fillProperties(booleanProperty) + .setType( + SettingType.newBuilder() + .setBool( + BoolSetting.newBuilder() + .setUiName(booleanProperty.uiName()) + .setDescription(booleanProperty.description()) + .setDef(booleanProperty.defaultValue()) .build()) - .build()); - } - case StringProperty stringProperty -> entries.add( - SettingEntry.newBuilder() - .setSingle( - fillSingleProperties(stringProperty) - .setType( - SettingType.newBuilder() - .setString( - StringSetting.newBuilder() - .setDef(stringProperty.defaultValue()) - .setSecret(stringProperty.secret()) - .build()) - .build()) - .build()) - .build()); + .build()) + .build(); + case IntProperty intProperty -> fillProperties(intProperty) + .setType( + SettingType.newBuilder() + .setInt(createIntSetting(intProperty)) + .build()) + .build(); + case DoubleProperty doubleProperty -> fillProperties(doubleProperty) + .setType( + SettingType.newBuilder() + .setDouble(createDoubleSetting(doubleProperty)) + .build()) + .build(); + case StringProperty stringProperty -> fillProperties(stringProperty) + .setType( + SettingType.newBuilder() + .setString( + StringSetting.newBuilder() + .setUiName(stringProperty.uiName()) + .setDescription(stringProperty.description()) + .setDef(stringProperty.defaultValue()) + .setSecret(stringProperty.secret()) + .build()) + .build()) + .build(); case ComboProperty comboProperty -> { var options = new ArrayList(); for (var option : comboProperty.options()) { @@ -209,35 +201,37 @@ public List exportSettingsMeta() { .setDisplayName(option.displayName()) .build()); } - entries.add( - SettingEntry.newBuilder() - .setSingle( - fillSingleProperties(comboProperty) - .setType( - SettingType.newBuilder() - .setCombo( - ComboSetting.newBuilder() - .setDef(comboProperty.defaultValue()) - .addAllOptions(options) - .build()) - .build()) - .build()) - .build()); - } - case StringListProperty stringListProperty -> entries.add( - SettingEntry.newBuilder() - .setSingle( - fillSingleProperties(stringListProperty) - .setType( - SettingType.newBuilder() - .setStringList( - StringListSetting.newBuilder() - .addAllDef(stringListProperty.defaultValue()) - .build()) + yield fillProperties(comboProperty) + .setType( + SettingType.newBuilder() + .setCombo( + ComboSetting.newBuilder() + .setUiName(comboProperty.uiName()) + .setDescription(comboProperty.description()) + .setDef(comboProperty.defaultValue()) + .addAllOptions(options) .build()) .build()) - .build()); - } + .build(); + } + case StringListProperty stringListProperty -> fillProperties(stringListProperty) + .setType( + SettingType.newBuilder() + .setStringList( + StringListSetting.newBuilder() + .setUiName(stringListProperty.uiName()) + .setDescription(stringListProperty.description()) + .addAllDef(stringListProperty.defaultValue()) + .build()) + .build()) + .build(); + case MinMaxProperty minMaxProperty -> fillProperties(minMaxProperty) + .setType( + SettingType.newBuilder() + .setMinMax(createMinMaxSetting(minMaxProperty)) + .build()) + .build(); + }); } var settingsPageBuilder = SettingsPage.newBuilder() @@ -257,19 +251,9 @@ public List exportSettingsMeta() { return list; } - private SettingEntrySingle.Builder fillSingleProperties(SingleProperty property) { - return SettingEntrySingle.newBuilder() - .setKey(property.key()) - .setUiName(property.uiName()) - .setDescription(property.description()); - } - - private SettingEntryMinMaxPairSingle.Builder fillMultiProperties( - SingleProperty property) { - return SettingEntryMinMaxPairSingle.newBuilder() - .setKey(property.key()) - .setUiName(property.uiName()) - .setDescription(property.description()); + private SettingEntry.Builder fillProperties(Property property) { + return SettingEntry.newBuilder() + .setKey(property.key()); } private record NamespaceRegistry(@Nullable PluginInfo owningPlugin, String pageName, List properties, String iconId) {} diff --git a/server/src/main/java/com/soulfiremc/server/settings/lib/SettingsSource.java b/server/src/main/java/com/soulfiremc/server/settings/lib/SettingsSource.java index fadf02f1e..8a94e45e9 100644 --- a/server/src/main/java/com/soulfiremc/server/settings/lib/SettingsSource.java +++ b/server/src/main/java/com/soulfiremc/server/settings/lib/SettingsSource.java @@ -53,7 +53,7 @@ default String get(StringProperty property) { } default T get(ComboProperty property, Function converter) { - return converter.apply(getAsType(property.propertyKey(), property.options()[property.defaultValue()].id(), String.class)); + return converter.apply(getAsType(property.propertyKey(), property.defaultValue(), String.class)); } default > T get(ComboProperty property, Class clazz) { @@ -64,8 +64,15 @@ default List get(StringListProperty property) { return List.of(getAsType(property.propertyKey(), property.defaultValue().toArray(new String[0]), String[].class)); } - default CustomIntSupplier getRandom(MinMaxPropertyLink property) { - return () -> SFHelpers.getRandomInt(get(property.min()), get(property.max())); + default MinMaxProperty.DataLayout get(MinMaxProperty property) { + return getAsType(property.propertyKey(), property.defaultDataLayout(), MinMaxProperty.DataLayout.class); + } + + default CustomIntSupplier getRandom(MinMaxProperty property) { + return () -> { + var layout = get(property); + return SFHelpers.getRandomInt(layout.min(), layout.max()); + }; } default T getAsType(PropertyKey key, T defaultValue, Class clazz) { diff --git a/server/src/main/java/com/soulfiremc/server/settings/property/BooleanProperty.java b/server/src/main/java/com/soulfiremc/server/settings/property/BooleanProperty.java index 7b2a68eec..88f795095 100644 --- a/server/src/main/java/com/soulfiremc/server/settings/property/BooleanProperty.java +++ b/server/src/main/java/com/soulfiremc/server/settings/property/BooleanProperty.java @@ -17,10 +17,16 @@ */ package com.soulfiremc.server.settings.property; -public record BooleanProperty( - String namespace, - String key, - String uiName, - String description, - boolean defaultValue) - implements SingleProperty {} +import org.immutables.value.Value; + +@Value.Immutable +@Value.Style(stagedBuilder = true) +public non-sealed abstract class BooleanProperty implements Property { + public abstract String key(); + + public abstract String uiName(); + + public abstract String description(); + + public abstract boolean defaultValue(); +} diff --git a/server/src/main/java/com/soulfiremc/server/settings/property/ComboProperty.java b/server/src/main/java/com/soulfiremc/server/settings/property/ComboProperty.java index a09fc88a8..8966c5460 100644 --- a/server/src/main/java/com/soulfiremc/server/settings/property/ComboProperty.java +++ b/server/src/main/java/com/soulfiremc/server/settings/property/ComboProperty.java @@ -17,28 +17,45 @@ */ package com.soulfiremc.server.settings.property; +import org.immutables.value.Value; + import java.util.Arrays; +import java.util.List; import java.util.Locale; import java.util.function.Function; -public record ComboProperty( - String namespace, - String key, - String uiName, - String description, - ComboOption[] options, - int defaultValue) - implements SingleProperty { - public ComboProperty { - if (options.length == 0) { - throw new IllegalArgumentException("Options must not be empty!"); - } +@Value.Immutable +@Value.Style(stagedBuilder = true) +public non-sealed abstract class ComboProperty implements Property { + public static > String[] capitalizeEnum(T[] enumValue) { + return Arrays.stream(enumValue) + .map(ComboProperty::capitalizeEnum) + .toArray(String[]::new); + } - if (defaultValue < 0 || defaultValue >= options.length) { - throw new IllegalArgumentException("Default value must be in range of options!"); + public static > ComboOption[] optionsFromEnum( + T[] values, Function mapper) { + var options = new ComboOption[values.length]; + + for (var i = 0; i < values.length; i++) { + options[i] = new ComboOption(values[i].name(), mapper.apply(values[i])); } + + return options; + } + + private static String capitalizeString(String str) { + return str.substring(0, 1).toUpperCase(Locale.ROOT) + str.substring(1).toLowerCase(Locale.ROOT); } + public abstract String key(); + + public abstract String uiName(); + + public abstract String description(); + + public abstract List options(); + public static > String capitalizeEnum(T enumValue) { return String.join( " ", @@ -47,20 +64,19 @@ public static > String capitalizeEnum(T enumValue) { .toArray(String[]::new)); } - public static String capitalizeString(String str) { - return str.substring(0, 1).toUpperCase(Locale.ROOT) + str.substring(1).toLowerCase(Locale.ROOT); - } - - public record ComboOption(String id, String displayName) { - public static > ComboOption[] fromEnum( - T[] values, Function mapper) { - var options = new ComboOption[values.length]; + public abstract String defaultValue(); - for (var i = 0; i < values.length; i++) { - options[i] = new ComboOption(values[i].name(), mapper.apply(values[i])); - } + @Value.Check + protected void check() { + if (options().isEmpty()) { + throw new IllegalArgumentException("Options must not be empty!"); + } - return options; + if (options().stream().noneMatch(option -> option.id().equals(defaultValue()))) { + throw new IllegalArgumentException("Default value must be in range of options!"); } } + + public record ComboOption(String id, String displayName) { + } } diff --git a/server/src/main/java/com/soulfiremc/server/settings/property/DoubleProperty.java b/server/src/main/java/com/soulfiremc/server/settings/property/DoubleProperty.java index 8d84da788..42a680a6a 100644 --- a/server/src/main/java/com/soulfiremc/server/settings/property/DoubleProperty.java +++ b/server/src/main/java/com/soulfiremc/server/settings/property/DoubleProperty.java @@ -17,16 +17,26 @@ */ package com.soulfiremc.server.settings.property; -import javax.annotation.Nullable; - -public record DoubleProperty( - String namespace, - String key, - String uiName, - String description, - double defaultValue, - double minValue, - double maxValue, - double stepValue, - @Nullable String format) - implements SingleProperty {} +import org.immutables.value.Value; + +import java.util.Optional; + +@Value.Immutable +@Value.Style(stagedBuilder = true) +public non-sealed abstract class DoubleProperty implements Property { + public abstract String key(); + + public abstract String uiName(); + + public abstract String description(); + + public abstract double defaultValue(); + + public abstract double minValue(); + + public abstract double maxValue(); + + public abstract double stepValue(); + + public abstract Optional format(); +} diff --git a/server/src/main/java/com/soulfiremc/server/settings/property/IntProperty.java b/server/src/main/java/com/soulfiremc/server/settings/property/IntProperty.java index 571b402b9..d640bf7e7 100644 --- a/server/src/main/java/com/soulfiremc/server/settings/property/IntProperty.java +++ b/server/src/main/java/com/soulfiremc/server/settings/property/IntProperty.java @@ -17,16 +17,26 @@ */ package com.soulfiremc.server.settings.property; -import javax.annotation.Nullable; - -public record IntProperty( - String namespace, - String key, - String uiName, - String description, - int defaultValue, - int minValue, - int maxValue, - int stepValue, - @Nullable String format) - implements SingleProperty {} +import org.immutables.value.Value; + +import java.util.Optional; + +@Value.Immutable +@Value.Style(stagedBuilder = true) +public non-sealed abstract class IntProperty implements Property { + public abstract String key(); + + public abstract String uiName(); + + public abstract String description(); + + public abstract int defaultValue(); + + public abstract int minValue(); + + public abstract int maxValue(); + + public abstract int stepValue(); + + public abstract Optional format(); +} diff --git a/server/src/main/java/com/soulfiremc/server/settings/property/MinMaxProperty.java b/server/src/main/java/com/soulfiremc/server/settings/property/MinMaxProperty.java new file mode 100644 index 000000000..5e1cbc02d --- /dev/null +++ b/server/src/main/java/com/soulfiremc/server/settings/property/MinMaxProperty.java @@ -0,0 +1,56 @@ +/* + * SoulFire + * Copyright (C) 2024 AlexProgrammerDE + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.soulfiremc.server.settings.property; + +import org.immutables.value.Value; + +import java.util.Optional; + +@Value.Immutable +@Value.Style(stagedBuilder = true) +public non-sealed abstract class MinMaxProperty implements Property { + public abstract String namespace(); + + public abstract String key(); + + public abstract String minUiName(); + + public abstract String maxUiName(); + + public abstract String minDescription(); + + public abstract String maxDescription(); + + public abstract int minDefaultValue(); + + public abstract int maxDefaultValue(); + + public abstract int minValue(); + + public abstract int maxValue(); + + public abstract int stepValue(); + + public abstract Optional format(); + + public DataLayout defaultDataLayout() { + return new DataLayout(minDefaultValue(), maxDefaultValue()); + } + + public record DataLayout(int min, int max) {} +} diff --git a/server/src/main/java/com/soulfiremc/server/settings/property/MinMaxPropertyLink.java b/server/src/main/java/com/soulfiremc/server/settings/property/MinMaxPropertyLink.java deleted file mode 100644 index f93a19f63..000000000 --- a/server/src/main/java/com/soulfiremc/server/settings/property/MinMaxPropertyLink.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * SoulFire - * Copyright (C) 2024 AlexProgrammerDE - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package com.soulfiremc.server.settings.property; - -public record MinMaxPropertyLink(IntProperty min, IntProperty max) implements Property { - @Override - public String namespace() { - return min.namespace(); - } - - @Override - public String key() { - throw new UnsupportedOperationException("This is a link!"); - } -} diff --git a/server/src/main/java/com/soulfiremc/server/settings/property/Property.java b/server/src/main/java/com/soulfiremc/server/settings/property/Property.java index 619720bb1..1c4faf4d2 100644 --- a/server/src/main/java/com/soulfiremc/server/settings/property/Property.java +++ b/server/src/main/java/com/soulfiremc/server/settings/property/Property.java @@ -19,14 +19,7 @@ import com.soulfiremc.server.settings.PropertyKey; -import java.util.List; -import java.util.function.Function; - -public sealed interface Property permits SingleProperty, MinMaxPropertyLink { - static Builder builder(String namespace) { - return new Builder(namespace); - } - +public sealed interface Property permits BooleanProperty, ComboProperty, DoubleProperty, IntProperty, MinMaxProperty, StringListProperty, StringProperty { String namespace(); String key(); @@ -34,127 +27,4 @@ static Builder builder(String namespace) { default PropertyKey propertyKey() { return new PropertyKey(namespace(), key()); } - - record Builder(String namespace) { - public BooleanProperty ofBoolean( - String key, String uiName, String description, boolean defaultValue) { - return new BooleanProperty(namespace, key, uiName, description, defaultValue); - } - - public IntProperty ofInt( - String key, - String uiName, - String description, - int defaultValue, - int minValue, - int maxValue, - int stepValue) { - return ofInt( - key, uiName, description, defaultValue, minValue, maxValue, stepValue, null); - } - - public IntProperty ofInt( - String key, - String uiName, - String description, - int defaultValue, - int minValue, - int maxValue, - int stepValue, - String format) { - return new IntProperty( - namespace, - key, - uiName, - description, - defaultValue, - minValue, - maxValue, - stepValue, - format); - } - - public DoubleProperty ofDouble( - String key, - String uiName, - String description, - double defaultValue, - double minValue, - double maxValue, - double stepValue) { - return ofDouble( - key, uiName, description, defaultValue, minValue, maxValue, stepValue, null); - } - - public DoubleProperty ofDouble( - String key, - String uiName, - String description, - double defaultValue, - double minValue, - double maxValue, - double stepValue, - String format) { - return new DoubleProperty( - namespace, - key, - uiName, - description, - defaultValue, - minValue, - maxValue, - stepValue, - format); - } - - public StringProperty ofString( - String key, String uiName, String description, String defaultValue) { - return new StringProperty(namespace, key, uiName, description, defaultValue, false); - } - - public StringProperty ofStringSecret( - String key, String uiName, String description, String defaultValue) { - return new StringProperty(namespace, key, uiName, description, defaultValue, true); - } - - public ComboProperty ofCombo( - String key, - String uiName, - String description, - ComboProperty.ComboOption[] values, - int defaultValue) { - return new ComboProperty(namespace, key, uiName, description, values, defaultValue); - } - - public > ComboProperty ofEnum( - String key, - String uiName, - String description, - T[] values, - T defaultValue) { - return ofEnumMapped( - key, uiName, description, values, defaultValue, Object::toString); - } - - public > ComboProperty ofEnumMapped( - String key, - String uiName, - String description, - T[] values, - T defaultValue, - Function mapper) { - return new ComboProperty( - namespace, - key, - uiName, - description, - ComboProperty.ComboOption.fromEnum(values, mapper), - defaultValue.ordinal()); - } - - public StringListProperty ofStringList( - String key, String uiName, String description, List defaultValue) { - return new StringListProperty(namespace, key, uiName, description, defaultValue); - } - } } diff --git a/server/src/main/java/com/soulfiremc/server/settings/property/SingleProperty.java b/server/src/main/java/com/soulfiremc/server/settings/property/SingleProperty.java deleted file mode 100644 index 5c2544af6..000000000 --- a/server/src/main/java/com/soulfiremc/server/settings/property/SingleProperty.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * SoulFire - * Copyright (C) 2024 AlexProgrammerDE - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package com.soulfiremc.server.settings.property; - -public sealed interface SingleProperty extends Property - permits BooleanProperty, ComboProperty, DoubleProperty, IntProperty, StringListProperty, StringProperty { - String uiName(); - - String description(); -} diff --git a/server/src/main/java/com/soulfiremc/server/settings/property/StringListProperty.java b/server/src/main/java/com/soulfiremc/server/settings/property/StringListProperty.java index 8c752836f..37e377c0e 100644 --- a/server/src/main/java/com/soulfiremc/server/settings/property/StringListProperty.java +++ b/server/src/main/java/com/soulfiremc/server/settings/property/StringListProperty.java @@ -17,12 +17,18 @@ */ package com.soulfiremc.server.settings.property; +import org.immutables.value.Value; + import java.util.List; -public record StringListProperty( - String namespace, - String key, - String uiName, - String description, - List defaultValue) - implements SingleProperty {} +@Value.Immutable +@Value.Style(stagedBuilder = true) +public non-sealed abstract class StringListProperty implements Property { + public abstract String key(); + + public abstract String uiName(); + + public abstract String description(); + + public abstract List defaultValue(); +} diff --git a/server/src/main/java/com/soulfiremc/server/settings/property/StringProperty.java b/server/src/main/java/com/soulfiremc/server/settings/property/StringProperty.java index 3346616f9..9628d9717 100644 --- a/server/src/main/java/com/soulfiremc/server/settings/property/StringProperty.java +++ b/server/src/main/java/com/soulfiremc/server/settings/property/StringProperty.java @@ -17,11 +17,21 @@ */ package com.soulfiremc.server.settings.property; -public record StringProperty( - String namespace, - String key, - String uiName, - String description, - String defaultValue, - boolean secret) - implements SingleProperty {} +import org.immutables.value.Value; + +@Value.Immutable +@Value.Style(stagedBuilder = true) +public non-sealed abstract class StringProperty implements Property { + public abstract String key(); + + public abstract String uiName(); + + public abstract String description(); + + public abstract String defaultValue(); + + @Value.Default + public boolean secret() { + return false; + } +} diff --git a/server/src/main/java/com/soulfiremc/server/util/BuiltinSettingsConstants.java b/server/src/main/java/com/soulfiremc/server/util/BuiltinSettingsConstants.java deleted file mode 100644 index 993ce8cd5..000000000 --- a/server/src/main/java/com/soulfiremc/server/util/BuiltinSettingsConstants.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * SoulFire - * Copyright (C) 2024 AlexProgrammerDE - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package com.soulfiremc.server.util; - -public class BuiltinSettingsConstants { - public static final String BOT_SETTINGS_ID = "bot"; - public static final String ACCOUNT_SETTINGS_ID = "account"; - public static final String PROXY_SETTINGS_ID = "proxy"; - public static final String DEV_SETTINGS_ID = "dev"; - public static final String AI_SETTINGS_ID = "ai"; - - private BuiltinSettingsConstants() {} -}