mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-08-14 23:57:35 +00:00
Merge pull request #324 from rtm516/chat-limit-warning
Added warning message if chat message is longer than 256 characters.
This commit is contained in:
commit
f8c3cf1aac
3 changed files with 34 additions and 3 deletions
|
@ -34,6 +34,7 @@ import org.geysermc.connector.network.translators.Translator;
|
||||||
|
|
||||||
import com.github.steveice10.mc.protocol.packet.ingame.client.ClientChatPacket;
|
import com.github.steveice10.mc.protocol.packet.ingame.client.ClientChatPacket;
|
||||||
import com.nukkitx.protocol.bedrock.packet.CommandRequestPacket;
|
import com.nukkitx.protocol.bedrock.packet.CommandRequestPacket;
|
||||||
|
import org.geysermc.connector.utils.MessageUtils;
|
||||||
|
|
||||||
@Translator(packet = CommandRequestPacket.class)
|
@Translator(packet = CommandRequestPacket.class)
|
||||||
public class BedrockCommandRequestTranslator extends PacketTranslator<CommandRequestPacket> {
|
public class BedrockCommandRequestTranslator extends PacketTranslator<CommandRequestPacket> {
|
||||||
|
@ -45,7 +46,13 @@ public class BedrockCommandRequestTranslator extends PacketTranslator<CommandReq
|
||||||
if (session.getConnector().getPlatformType() == PlatformType.STANDALONE && command.startsWith("geyser ") && commandMap.getCommands().containsKey(command.split(" ")[1])) {
|
if (session.getConnector().getPlatformType() == PlatformType.STANDALONE && command.startsWith("geyser ") && commandMap.getCommands().containsKey(command.split(" ")[1])) {
|
||||||
commandMap.runCommand(session, command);
|
commandMap.runCommand(session, command);
|
||||||
} else {
|
} else {
|
||||||
ClientChatPacket chatPacket = new ClientChatPacket(packet.getCommand());
|
String message = packet.getCommand().trim();
|
||||||
|
|
||||||
|
if (MessageUtils.isTooLong(message, session)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ClientChatPacket chatPacket = new ClientChatPacket(message);
|
||||||
session.getDownstream().getSession().send(chatPacket);
|
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.github.steveice10.mc.protocol.packet.ingame.client.ClientChatPacket;
|
||||||
import com.nukkitx.protocol.bedrock.packet.TextPacket;
|
import com.nukkitx.protocol.bedrock.packet.TextPacket;
|
||||||
|
import org.geysermc.connector.utils.MessageUtils;
|
||||||
|
|
||||||
@Translator(packet = TextPacket.class)
|
@Translator(packet = TextPacket.class)
|
||||||
public class BedrockTextTranslator extends PacketTranslator<TextPacket> {
|
public class BedrockTextTranslator extends PacketTranslator<TextPacket> {
|
||||||
|
@ -38,12 +39,24 @@ public class BedrockTextTranslator extends PacketTranslator<TextPacket> {
|
||||||
@Override
|
@Override
|
||||||
public void translate(TextPacket packet, GeyserSession session) {
|
public void translate(TextPacket packet, GeyserSession session) {
|
||||||
if (packet.getMessage().charAt(0) == '.') {
|
if (packet.getMessage().charAt(0) == '.') {
|
||||||
ClientChatPacket chatPacket = new ClientChatPacket(packet.getMessage().replace(".", "/"));
|
String message = packet.getMessage().replace(".", "/").trim();
|
||||||
|
|
||||||
|
if (MessageUtils.isTooLong(message, session)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ClientChatPacket chatPacket = new ClientChatPacket(message);
|
||||||
session.getDownstream().getSession().send(chatPacket);
|
session.getDownstream().getSession().send(chatPacket);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ClientChatPacket chatPacket = new ClientChatPacket(packet.getMessage());
|
String message = packet.getMessage().trim();
|
||||||
|
|
||||||
|
if (MessageUtils.isTooLong(message, session)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ClientChatPacket chatPacket = new ClientChatPacket(message);
|
||||||
session.getDownstream().getSession().send(chatPacket);
|
session.getDownstream().getSession().send(chatPacket);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,7 @@ import com.google.gson.JsonElement;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import com.google.gson.JsonParser;
|
import com.google.gson.JsonParser;
|
||||||
import com.google.gson.JsonPrimitive;
|
import com.google.gson.JsonPrimitive;
|
||||||
|
import org.geysermc.connector.network.session.GeyserSession;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
|
@ -294,4 +295,14 @@ public class MessageUtils {
|
||||||
}
|
}
|
||||||
return "";
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue