Commit c6eb9ac9 by Jonathan Thomas

Adding commands to set server settings:

/creaturechat key set <key>
/creaturechat url set "<url>"
/creaturechat model set <model>
/creaturechat help
parent e69a6c45
Pipeline #11982 passed with stage
in 25 seconds
......@@ -2,6 +2,7 @@ package com.owlmaddie;
import com.owlmaddie.chat.ChatDataManager;
import com.owlmaddie.chat.ChatDataSaverScheduler;
import com.owlmaddie.commands.CreatureChatCommands;
import com.owlmaddie.goals.EntityBehaviorManager;
import com.owlmaddie.goals.GoalPriority;
import com.owlmaddie.goals.TalkPlayerGoal;
......@@ -53,6 +54,9 @@ public class ModInit implements ModInitializer {
// However, some things (like resources) may still be uninitialized.
// Proceed with mild caution.
// Register server commands
CreatureChatCommands.register();
// Handle packet for Greeting
ServerPlayNetworking.registerGlobalReceiver(PACKET_C2S_GREETING, (server, player, handler, buf, responseSender) -> {
UUID entityId = UUID.fromString(buf.readString());
......
package com.owlmaddie.commands;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
import net.minecraft.server.command.CommandManager;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.text.Text;
/**
* The {@code CreatureChatCommands} class registers custom commands to set new API key, model, and url.
* Permission level set to 4 (server owner), since this deals with API keys and potential costs.
*/
public class CreatureChatCommands {
public static void register() {
ServerLifecycleEvents.SERVER_STARTING.register(server -> {
CommandDispatcher<ServerCommandSource> dispatcher = server.getCommandManager().getDispatcher();
registerBaseCommand(dispatcher);
});
}
private static void registerBaseCommand(CommandDispatcher<ServerCommandSource> dispatcher) {
dispatcher.register(CommandManager.literal("creaturechat")
.then(registerSetKeyCommand())
.then(registerSetUrlCommand())
.then(registerSetModelCommand())
.then(registerHelpCommand()));
}
private static LiteralArgumentBuilder<ServerCommandSource> registerSetKeyCommand() {
return CommandManager.literal("key").then(CommandManager.literal("set").then(CommandManager.argument("key", StringArgumentType.word())
.requires(source -> source.hasPermissionLevel(4))
.executes(context -> {
String key = StringArgumentType.getString(context, "key");
context.getSource().sendFeedback(() -> Text.literal("API key set to: " + key), false);
return 1;
})));
}
private static LiteralArgumentBuilder<ServerCommandSource> registerSetUrlCommand() {
return CommandManager.literal("url").then(CommandManager.literal("set").then(CommandManager.argument("url", StringArgumentType.string())
.requires(source -> source.hasPermissionLevel(4))
.executes(context -> {
String url = StringArgumentType.getString(context, "url");
context.getSource().sendFeedback(() -> Text.literal("URL set to: " + url), false);
return 1;
})));
}
private static LiteralArgumentBuilder<ServerCommandSource> registerSetModelCommand() {
return CommandManager.literal("model").then(CommandManager.literal("set").then(CommandManager.argument("model", StringArgumentType.word())
.requires(source -> source.hasPermissionLevel(4))
.executes(context -> {
String model = StringArgumentType.getString(context, "model");
context.getSource().sendFeedback(() -> Text.literal("Model set to: " + model), false);
return 1;
})));
}
private static LiteralArgumentBuilder<ServerCommandSource> registerHelpCommand() {
return CommandManager.literal("help")
.requires(source -> source.hasPermissionLevel(4))
.executes(context -> {
context.getSource().sendFeedback(() -> Text.literal("Usage:\n/creaturechat key set <key>\n/creaturechat url set <url>\n/creaturechat model set <model>"), false);
return 1;
});
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment