Skip to content

Commit

Permalink
Reimplement settings system
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexProgrammerDE committed Nov 15, 2024
1 parent 5a0b32f commit 9e76846
Show file tree
Hide file tree
Showing 43 changed files with 1,404 additions and 1,371 deletions.
3 changes: 2 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down
372 changes: 201 additions & 171 deletions client/src/main/java/com/soulfiremc/client/cli/CLIManager.java

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
88 changes: 44 additions & 44 deletions proto/src/main/proto/soulfire/config.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand All @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions server/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
55 changes: 32 additions & 23 deletions server/src/main/java/com/soulfiremc/server/plugins/AIChatBot.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -94,38 +95,46 @@ 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.
You must not say anything that is not safe for work.
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();
}
}
79 changes: 37 additions & 42 deletions server/src/main/java/com/soulfiremc/server/plugins/AntiAFK.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
}
51 changes: 25 additions & 26 deletions server/src/main/java/com/soulfiremc/server/plugins/AutoArmor.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
}
Loading

0 comments on commit 9e76846

Please sign in to comment.