Commit 99daf973 by Jonathan Thomas

New command `/creaturechat chatbubbles set <on | off>` to show or hide player…

New command `/creaturechat chatbubbles set <on | off>` to show or hide player chat messages in bubbles
parent b210e7c4
Pipeline #13274 passed with stages
in 2 minutes 19 seconds
......@@ -11,6 +11,7 @@ All notable changes to **CreatureChat** are documented in this file. The format
- New Step-by-Step **Icon** Tutorial: [ICON.md](ICONS.md)
- New mixin to extend PlayerSkinTexture to make a copy of the NativeImage + pixel toggle to enable
- Chat messages are now displayed in chat bubbles above players heads
- New command `/creaturechat chatbubbles set <on | off>` to show or hide player chat messages in bubbles
- Improved LLM Unit tests (to prevent rate limit issues from certain providers when running all tests)
- Check friendship direction (+ or -) in LLM unit tests (to verify friendship direction is output correctly)
......
......@@ -71,6 +71,7 @@ public class ConfigurationHandler {
private int maxOutputTokens = 200;
private double percentOfContext = 0.75;
private int timeout = 10;
private boolean chatBubbles = true;
private List<String> whitelist = new ArrayList<>();
private List<String> blacklist = new ArrayList<>();
private String story = "";
......@@ -114,5 +115,9 @@ public class ConfigurationHandler {
public String getStory() { return story; }
public void setStory(String story) { this.story = story; }
// Add getter and setter
public boolean getChatBubbles() { return chatBubbles; }
public void setChatBubbles(boolean chatBubblesEnabled) { this.chatBubbles = chatBubblesEnabled; }
}
}
......@@ -49,6 +49,7 @@ public class CreatureChatCommands {
.then(registerStoryCommand())
.then(registerWhitelistCommand())
.then(registerBlacklistCommand())
.then(registerChatBubbleCommand())
.then(registerHelpCommand()));
}
......@@ -95,6 +96,35 @@ public class CreatureChatCommands {
.map(Identifier::toString)
.collect(Collectors.toList());
}
private static LiteralArgumentBuilder<ServerCommandSource> registerChatBubbleCommand() {
return CommandManager.literal("chatbubble")
.requires(source -> source.hasPermissionLevel(4))
.then(CommandManager.literal("set")
.then(CommandManager.literal("on")
.then(addConfigArgs((context, useServerConfig) -> setChatBubbleEnabled(context, true, useServerConfig)))
.executes(context -> setChatBubbleEnabled(context, true, false)))
.then(CommandManager.literal("off")
.then(addConfigArgs((context, useServerConfig) -> setChatBubbleEnabled(context, false, useServerConfig)))
.executes(context -> setChatBubbleEnabled(context, false, false))));
}
private static int setChatBubbleEnabled(CommandContext<ServerCommandSource> context, boolean enabled, boolean useServerConfig) {
ServerCommandSource source = context.getSource();
ConfigurationHandler configHandler = new ConfigurationHandler(source.getServer());
ConfigurationHandler.Config config = configHandler.loadConfig();
config.setChatBubbles(enabled);
if (configHandler.saveConfig(config, useServerConfig)) {
Text feedbackMessage = Text.literal("Player chat bubbles have been " + (enabled ? "enabled" : "disabled") + ".").formatted(Formatting.GREEN);
source.sendFeedback(() -> feedbackMessage, true);
return 1;
} else {
Text feedbackMessage = Text.literal("Failed to update player chat bubble setting.").formatted(Formatting.RED);
source.sendFeedback(() -> feedbackMessage, false);
return 0;
}
}
private static LiteralArgumentBuilder<ServerCommandSource> registerWhitelistCommand() {
return CommandManager.literal("whitelist")
......@@ -135,6 +165,7 @@ public class CreatureChatCommands {
+ "/creaturechat model set <model> - Sets the model\n"
+ "/creaturechat timeout set <seconds> - Sets the API timeout\n"
+ "/creaturechat story set \"<story>\" - Sets a custom story\n"
+ "/creaturechat chatbubbles set <on | off> - Show player chat bubbles\n"
+ "/creaturechat whitelist <entityType | all | clear> - Show chat bubbles\n"
+ "/creaturechat blacklist <entityType | all | clear> - Hide chat bubbles\n"
+ "\n"
......@@ -151,43 +182,42 @@ public class CreatureChatCommands {
.requires(source -> source.hasPermissionLevel(4))
.then(CommandManager.literal("set")
.then(CommandManager.argument("value", StringArgumentType.string())
.executes(context -> {
.then(addConfigArgs((context, useServerConfig) -> {
String story = StringArgumentType.getString(context, "value");
ConfigurationHandler.Config config = new ConfigurationHandler(context.getSource().getServer()).loadConfig();
config.setStory(story); // Assuming Config has a `setStory` method
if (new ConfigurationHandler(context.getSource().getServer()).saveConfig(config, true)) {
config.setStory(story);
if (new ConfigurationHandler(context.getSource().getServer()).saveConfig(config, useServerConfig)) {
context.getSource().sendFeedback(() -> Text.literal("Story set successfully: " + story).formatted(Formatting.GREEN), true);
return 1;
} else {
context.getSource().sendFeedback(() -> Text.literal("Failed to set story!").formatted(Formatting.RED), false);
return 0;
}
})
))
}))))
.then(CommandManager.literal("clear")
.executes(context -> {
.then(addConfigArgs((context, useServerConfig) -> {
ConfigurationHandler.Config config = new ConfigurationHandler(context.getSource().getServer()).loadConfig();
config.setStory(""); // Clear the story
if (new ConfigurationHandler(context.getSource().getServer()).saveConfig(config, true)) {
config.setStory("");
if (new ConfigurationHandler(context.getSource().getServer()).saveConfig(config, useServerConfig)) {
context.getSource().sendFeedback(() -> Text.literal("Story cleared successfully!").formatted(Formatting.GREEN), true);
return 1;
} else {
context.getSource().sendFeedback(() -> Text.literal("Failed to clear story!").formatted(Formatting.RED), false);
return 0;
}
}))
})))
.then(CommandManager.literal("display")
.executes(context -> {
ConfigurationHandler.Config config = new ConfigurationHandler(context.getSource().getServer()).loadConfig();
String story = config.getStory(); // Assuming Config has a `getStory` method
if (story == null || story.isEmpty()) {
context.getSource().sendFeedback(() -> Text.literal("No story is currently set.").formatted(Formatting.RED), false);
return 0;
} else {
context.getSource().sendFeedback(() -> Text.literal("Current story: " + story).formatted(Formatting.AQUA), false);
return 1;
}
}));
.executes(context -> {
ConfigurationHandler.Config config = new ConfigurationHandler(context.getSource().getServer()).loadConfig();
String story = config.getStory();
if (story == null || story.isEmpty()) {
context.getSource().sendFeedback(() -> Text.literal("No story is currently set.").formatted(Formatting.RED), false);
return 0;
} else {
context.getSource().sendFeedback(() -> Text.literal("Current story: " + story).formatted(Formatting.AQUA), false);
return 1;
}
}));
}
private static <T> int setConfig(ServerCommandSource source, String settingName, T value, boolean useServerConfig, String settingDescription) {
......
package com.owlmaddie.mixin;
import com.owlmaddie.chat.EntityChatData;
import com.owlmaddie.commands.ConfigurationHandler;
import com.owlmaddie.network.ServerPackets;
import net.minecraft.network.packet.c2s.play.ChatMessageC2SPacket;
import net.minecraft.server.network.ServerPlayNetworkHandler;
import net.minecraft.server.network.ServerPlayerEntity;
......@@ -19,19 +21,23 @@ public abstract class MixinOnChat {
@Inject(method = "onChatMessage", at = @At("HEAD"), cancellable = true)
private void onChatMessage(ChatMessageC2SPacket packet, CallbackInfo ci) {
// Get the player who sent the message
ServerPlayNetworkHandler handler = (ServerPlayNetworkHandler) (Object) this;
ServerPlayerEntity player = handler.player;
ConfigurationHandler.Config config = new ConfigurationHandler(ServerPackets.serverInstance).loadConfig();
if (config.getChatBubbles()) {
// Get the chat message
String chatMessage = packet.chatMessage();
// Get the player who sent the message
ServerPlayNetworkHandler handler = (ServerPlayNetworkHandler) (Object) this;
ServerPlayerEntity player = handler.player;
// Example: Call your broadcast function
EntityChatData chatData = new EntityChatData(player.getUuidAsString());
chatData.currentMessage = chatMessage;
BroadcastPlayerMessage(chatData, player);
// Get the chat message
String chatMessage = packet.chatMessage();
// Optionally, cancel the event to prevent the default behavior
//ci.cancel();
// Example: Call your broadcast function
EntityChatData chatData = new EntityChatData(player.getUuidAsString());
chatData.currentMessage = chatMessage;
BroadcastPlayerMessage(chatData, player);
// Optionally, cancel the event to prevent the default behavior
//ci.cancel();
}
}
}
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