Mirror von
https://github.com/GeyserMC/Geyser.git
synchronisiert 2024-12-27 08:30:12 +01:00
Centeralised message length checking and added TODO for localization
Dieser Commit ist enthalten in:
Ursprung
79a7258fd1
Commit
55608a2a48
@ -34,6 +34,7 @@ import org.geysermc.connector.network.translators.Translator;
|
||||
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.client.ClientChatPacket;
|
||||
import com.nukkitx.protocol.bedrock.packet.CommandRequestPacket;
|
||||
import org.geysermc.connector.utils.MessageUtils;
|
||||
|
||||
@Translator(packet = CommandRequestPacket.class)
|
||||
public class BedrockCommandRequestTranslator extends PacketTranslator<CommandRequestPacket> {
|
||||
@ -47,10 +48,7 @@ public class BedrockCommandRequestTranslator extends PacketTranslator<CommandReq
|
||||
} else {
|
||||
String message = packet.getCommand().trim();
|
||||
|
||||
if (message.length() > 256) {
|
||||
session.sendMessage("Your message is bigger than 256 characters (" + message.length() + ") so it has not been sent.");
|
||||
return;
|
||||
}
|
||||
if (MessageUtils.isTooLong(message, session)) { return; }
|
||||
|
||||
ClientChatPacket chatPacket = new ClientChatPacket(message);
|
||||
session.getDownstream().getSession().send(chatPacket);
|
||||
|
@ -31,6 +31,7 @@ import org.geysermc.connector.network.translators.Translator;
|
||||
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.client.ClientChatPacket;
|
||||
import com.nukkitx.protocol.bedrock.packet.TextPacket;
|
||||
import org.geysermc.connector.utils.MessageUtils;
|
||||
|
||||
@Translator(packet = TextPacket.class)
|
||||
public class BedrockTextTranslator extends PacketTranslator<TextPacket> {
|
||||
@ -40,10 +41,7 @@ public class BedrockTextTranslator extends PacketTranslator<TextPacket> {
|
||||
if (packet.getMessage().charAt(0) == '.') {
|
||||
String message = packet.getMessage().replace(".", "/").trim();
|
||||
|
||||
if (message.length() > 256) {
|
||||
session.sendMessage("Your message is bigger than 256 characters (" + message.length() + ") so it has not been sent.");
|
||||
return;
|
||||
}
|
||||
if (MessageUtils.isTooLong(message, session)) { return; }
|
||||
|
||||
ClientChatPacket chatPacket = new ClientChatPacket(message);
|
||||
session.getDownstream().getSession().send(chatPacket);
|
||||
@ -52,10 +50,7 @@ public class BedrockTextTranslator extends PacketTranslator<TextPacket> {
|
||||
|
||||
String message = packet.getMessage().trim();
|
||||
|
||||
if (message.length() > 256) {
|
||||
session.sendMessage("Your message is bigger than 256 characters (" + message.length() + ") so it has not been sent.");
|
||||
return;
|
||||
}
|
||||
if (MessageUtils.isTooLong(message, session)) { return; }
|
||||
|
||||
ClientChatPacket chatPacket = new ClientChatPacket(message);
|
||||
session.getDownstream().getSession().send(chatPacket);
|
||||
|
@ -32,6 +32,7 @@ import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
import org.geysermc.connector.network.session.GeyserSession;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.regex.Matcher;
|
||||
@ -290,4 +291,14 @@ public class MessageUtils {
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public static boolean isTooLong(String message, GeyserSession session) {
|
||||
if (message.length() > 256) {
|
||||
// TODO: Add Geyser localization and translate this based on language
|
||||
session.sendMessage("Your message is bigger than 256 characters (" + message.length() + ") so it has not been sent.");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren