fix: /msg outgoing message target fix
fix: forgor to merge the namespace remover with the one moved to StringUtilities lol
This commit is contained in:
@@ -11,6 +11,7 @@ import me.chayapak1.chomens_bot.data.player.PlayerEntry;
|
||||
import me.chayapak1.chomens_bot.data.team.Team;
|
||||
import me.chayapak1.chomens_bot.util.ComponentUtilities;
|
||||
import me.chayapak1.chomens_bot.util.IllegalCharactersUtilities;
|
||||
import me.chayapak1.chomens_bot.util.StringUtilities;
|
||||
import me.chayapak1.chomens_bot.util.UUIDUtilities;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import net.kyori.adventure.text.Component;
|
||||
@@ -154,24 +155,37 @@ public class ChatPlugin extends Bot.Listener {
|
||||
}
|
||||
}
|
||||
|
||||
private Component getComponentByChatType (int chatType, Component name, Component message) {
|
||||
private Component getComponentByChatType (int chatType, Component sender, Component content) {
|
||||
final Component type = chatTypes.get(chatType);
|
||||
if (type == null) return null;
|
||||
|
||||
final Team botTeam = bot.team.findTeamByMember(bot.profile.getName());
|
||||
final Component botTeamDisplayName = botTeam == null ?
|
||||
Component.empty() :
|
||||
Component
|
||||
.translatable("chat.square_brackets")
|
||||
.arguments(botTeam.displayName)
|
||||
.style(botTeam.colorToStyle());
|
||||
Component target;
|
||||
|
||||
// minecraft has the /msg target as the player target,
|
||||
// that actually makes sense but i don't know how to
|
||||
// properly implement this lol
|
||||
if (
|
||||
type instanceof TranslatableComponent translatableComponent &&
|
||||
translatableComponent.key().equals("commands.message.display.outgoing")
|
||||
) {
|
||||
target = sender;
|
||||
} else {
|
||||
final Team botTeam = bot.team.findTeamByMember(bot.profile.getName());
|
||||
|
||||
target = botTeam == null ?
|
||||
Component.empty() :
|
||||
Component
|
||||
.translatable("chat.square_brackets")
|
||||
.arguments(botTeam.displayName)
|
||||
.style(botTeam.colorToStyle());
|
||||
}
|
||||
|
||||
return CHAT_TYPE_COMPONENT_RENDERER.render(
|
||||
type,
|
||||
new ChatTypeContext(
|
||||
botTeamDisplayName,
|
||||
name,
|
||||
message
|
||||
target,
|
||||
sender,
|
||||
content
|
||||
)
|
||||
);
|
||||
}
|
||||
@@ -268,20 +282,12 @@ public class ChatPlugin extends Bot.Listener {
|
||||
if (message == null) return;
|
||||
|
||||
if (message.startsWith("/")) {
|
||||
String removedMessage = message.substring(1);
|
||||
final String slashRemoved = message.substring(1);
|
||||
|
||||
if (!bot.serverFeatures.hasNamespaces) {
|
||||
final String[] splittedSpace = removedMessage.split("\\s+"); // [minecraft:test, arg1, arg2, ...]
|
||||
final String[] splittedColon = splittedSpace[0].split(":"); // [minecraft, test]
|
||||
if (splittedColon.length >= 2) {
|
||||
removedMessage = String.join(":", Arrays.copyOfRange(splittedColon, 1, splittedColon.length));
|
||||
|
||||
if (splittedSpace.length > 1) {
|
||||
removedMessage += " ";
|
||||
removedMessage += String.join(" ", Arrays.copyOfRange(splittedSpace, 1, splittedSpace.length));
|
||||
}
|
||||
}
|
||||
}
|
||||
final String removedMessage =
|
||||
bot.serverFeatures.hasNamespaces ?
|
||||
slashRemoved :
|
||||
StringUtilities.removeNamespace(slashRemoved);
|
||||
|
||||
sendCommandInstantly(removedMessage);
|
||||
} else {
|
||||
|
||||
@@ -11,21 +11,22 @@ import java.util.Map;
|
||||
|
||||
public class StringUtilities {
|
||||
public static String removeNamespace (String command) {
|
||||
String removedCommand = command;
|
||||
final StringBuilder removedCommand = new StringBuilder(command);
|
||||
|
||||
final String[] splittedSpace = removedCommand.split("\\s+"); // [minecraft:test, arg1, arg2, ...]
|
||||
final String[] splittedColon = splittedSpace[0].split(":"); // [minecraft, test]
|
||||
final String[] splitSpace = command.split("\\s+"); // [minecraft:test, arg1, arg2, ...]
|
||||
final String[] splitColon = splitSpace[0].split(":"); // [minecraft, test]
|
||||
|
||||
if (splittedColon.length >= 2) {
|
||||
removedCommand = String.join(":", Arrays.copyOfRange(splittedColon, 1, splittedColon.length));
|
||||
if (splitColon.length >= 2) {
|
||||
removedCommand.setLength(0);
|
||||
removedCommand.append(String.join(":", Arrays.copyOfRange(splitColon, 1, splitColon.length)));
|
||||
|
||||
if (splittedSpace.length > 1) {
|
||||
removedCommand += " ";
|
||||
removedCommand += String.join(" ", Arrays.copyOfRange(splittedSpace, 1, splittedSpace.length));
|
||||
if (splitSpace.length > 1) {
|
||||
removedCommand.append(' ');
|
||||
removedCommand.append(String.join(" ", Arrays.copyOfRange(splitSpace, 1, splitSpace.length)));
|
||||
}
|
||||
}
|
||||
|
||||
return removedCommand;
|
||||
return removedCommand.toString();
|
||||
}
|
||||
|
||||
// https://stackoverflow.com/a/35148974/18518424
|
||||
|
||||
Reference in New Issue
Block a user