forked from GeyserMC/Geyser
Update Message system
This commit is contained in:
parent
d6119375b2
commit
ad4c1ff0c7
8 changed files with 45 additions and 38 deletions
|
@ -25,15 +25,17 @@
|
||||||
|
|
||||||
package org.geysermc.connector.network;
|
package org.geysermc.connector.network;
|
||||||
|
|
||||||
import com.github.steveice10.mc.protocol.data.message.Message;
|
import com.github.steveice10.mc.protocol.data.message.MessageSerializer;
|
||||||
import com.nukkitx.protocol.bedrock.*;
|
import com.nukkitx.protocol.bedrock.BedrockPong;
|
||||||
|
import com.nukkitx.protocol.bedrock.BedrockServerEventHandler;
|
||||||
|
import com.nukkitx.protocol.bedrock.BedrockServerSession;
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
import io.netty.channel.socket.DatagramPacket;
|
import io.netty.channel.socket.DatagramPacket;
|
||||||
import org.geysermc.common.ping.GeyserPingInfo;
|
import org.geysermc.common.ping.GeyserPingInfo;
|
||||||
import org.geysermc.connector.ping.IGeyserPingPassthrough;
|
|
||||||
import org.geysermc.connector.configuration.GeyserConfiguration;
|
|
||||||
import org.geysermc.connector.GeyserConnector;
|
import org.geysermc.connector.GeyserConnector;
|
||||||
|
import org.geysermc.connector.configuration.GeyserConfiguration;
|
||||||
import org.geysermc.connector.network.session.GeyserSession;
|
import org.geysermc.connector.network.session.GeyserSession;
|
||||||
|
import org.geysermc.connector.ping.IGeyserPingPassthrough;
|
||||||
import org.geysermc.connector.utils.MessageUtils;
|
import org.geysermc.connector.utils.MessageUtils;
|
||||||
|
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
|
@ -73,7 +75,7 @@ public class ConnectorServerEventHandler implements BedrockServerEventHandler {
|
||||||
pong.setIpv4Port(config.getBedrock().getPort());
|
pong.setIpv4Port(config.getBedrock().getPort());
|
||||||
|
|
||||||
if (config.isPassthroughMotd() && pingInfo != null && pingInfo.motd != null) {
|
if (config.isPassthroughMotd() && pingInfo != null && pingInfo.motd != null) {
|
||||||
String[] motd = MessageUtils.getBedrockMessage(Message.fromString(pingInfo.motd)).split("\n");
|
String[] motd = MessageUtils.getBedrockMessage(MessageSerializer.fromString(pingInfo.motd)).split("\n");
|
||||||
String mainMotd = motd[0]; // First line of the motd.
|
String mainMotd = motd[0]; // First line of the motd.
|
||||||
String subMotd = (motd.length != 1) ? motd[1] : ""; // Second line of the motd if present, otherwise blank.
|
String subMotd = (motd.length != 1) ? motd[1] : ""; // Second line of the motd if present, otherwise blank.
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
|
|
||||||
package org.geysermc.connector.network;
|
package org.geysermc.connector.network;
|
||||||
|
|
||||||
import com.github.steveice10.mc.protocol.data.message.Message;
|
import com.github.steveice10.mc.protocol.data.message.MessageSerializer;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.ByteBufAllocator;
|
import io.netty.buffer.ByteBufAllocator;
|
||||||
import org.geysermc.common.ping.GeyserPingInfo;
|
import org.geysermc.common.ping.GeyserPingInfo;
|
||||||
|
@ -148,7 +148,7 @@ public class QueryPacketHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (connector.getConfig().isPassthroughMotd() && pingInfo != null) {
|
if (connector.getConfig().isPassthroughMotd() && pingInfo != null) {
|
||||||
String[] javaMotd = MessageUtils.getBedrockMessage(Message.fromString(pingInfo.motd)).split("\n");
|
String[] javaMotd = MessageUtils.getBedrockMessage(MessageSerializer.fromString(pingInfo.motd)).split("\n");
|
||||||
motd = javaMotd[0].trim(); // First line of the motd.
|
motd = javaMotd[0].trim(); // First line of the motd.
|
||||||
} else {
|
} else {
|
||||||
motd = connector.getConfig().getBedrock().getMotd1();
|
motd = connector.getConfig().getBedrock().getMotd1();
|
||||||
|
|
|
@ -27,6 +27,7 @@ package org.geysermc.connector.network.translators.inventory;
|
||||||
|
|
||||||
import com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack;
|
import com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack;
|
||||||
import com.github.steveice10.mc.protocol.data.message.Message;
|
import com.github.steveice10.mc.protocol.data.message.Message;
|
||||||
|
import com.github.steveice10.mc.protocol.data.message.MessageSerializer;
|
||||||
import com.github.steveice10.mc.protocol.packet.ingame.client.window.ClientRenameItemPacket;
|
import com.github.steveice10.mc.protocol.packet.ingame.client.window.ClientRenameItemPacket;
|
||||||
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
||||||
import com.nukkitx.protocol.bedrock.data.ContainerId;
|
import com.nukkitx.protocol.bedrock.data.ContainerId;
|
||||||
|
@ -129,8 +130,8 @@ public class AnvilInventoryTranslator extends BlockInventoryTranslator {
|
||||||
CompoundTag displayTag = tag.get("display");
|
CompoundTag displayTag = tag.get("display");
|
||||||
if (displayTag != null) {
|
if (displayTag != null) {
|
||||||
String itemName = displayTag.get("Name").getValue().toString();
|
String itemName = displayTag.get("Name").getValue().toString();
|
||||||
Message message = Message.fromString(itemName);
|
Message message = MessageSerializer.fromString(itemName);
|
||||||
rename = message.getText();
|
rename = message.toString();
|
||||||
} else {
|
} else {
|
||||||
rename = "";
|
rename = "";
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,7 @@
|
||||||
package org.geysermc.connector.network.translators.item;
|
package org.geysermc.connector.network.translators.item;
|
||||||
|
|
||||||
import com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack;
|
import com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack;
|
||||||
import com.github.steveice10.mc.protocol.data.message.Message;
|
import com.github.steveice10.mc.protocol.data.message.MessageSerializer;
|
||||||
import com.github.steveice10.opennbt.tag.builtin.*;
|
import com.github.steveice10.opennbt.tag.builtin.*;
|
||||||
import com.nukkitx.nbt.CompoundTagBuilder;
|
import com.nukkitx.nbt.CompoundTagBuilder;
|
||||||
import com.nukkitx.nbt.tag.CompoundTag;
|
import com.nukkitx.nbt.tag.CompoundTag;
|
||||||
|
@ -159,7 +159,7 @@ public abstract class ItemTranslator {
|
||||||
// Check if its a message to translate
|
// Check if its a message to translate
|
||||||
if (MessageUtils.isMessage(name)) {
|
if (MessageUtils.isMessage(name)) {
|
||||||
// Get the translated name
|
// Get the translated name
|
||||||
name = MessageUtils.getTranslatedBedrockMessage(Message.fromString(name), session.getClientData().getLanguageCode());
|
name = MessageUtils.getTranslatedBedrockMessage(MessageSerializer.fromString(name), session.getClientData().getLanguageCode());
|
||||||
|
|
||||||
// Build the new display tag
|
// Build the new display tag
|
||||||
CompoundTagBuilder displayBuilder = display.toBuilder();
|
CompoundTagBuilder displayBuilder = display.toBuilder();
|
||||||
|
|
|
@ -66,7 +66,7 @@ public class JavaChatTranslator extends PacketTranslator<ServerChatPacket> {
|
||||||
textPacket.setType(TextPacket.Type.TRANSLATION);
|
textPacket.setType(TextPacket.Type.TRANSLATION);
|
||||||
textPacket.setNeedsTranslation(true);
|
textPacket.setNeedsTranslation(true);
|
||||||
|
|
||||||
List<String> paramsTranslated = MessageUtils.getTranslationParams(((TranslationMessage) packet.getMessage()).getTranslationParams(), locale);
|
List<String> paramsTranslated = MessageUtils.getTranslationParams(((TranslationMessage) packet.getMessage()).getWith(), locale);
|
||||||
textPacket.setParameters(paramsTranslated);
|
textPacket.setParameters(paramsTranslated);
|
||||||
|
|
||||||
textPacket.setMessage(MessageUtils.insertParams(MessageUtils.getTranslatedBedrockMessage(packet.getMessage(), locale, true), paramsTranslated));
|
textPacket.setMessage(MessageUtils.insertParams(MessageUtils.getTranslatedBedrockMessage(packet.getMessage(), locale, true), paramsTranslated));
|
||||||
|
|
|
@ -25,12 +25,11 @@
|
||||||
|
|
||||||
package org.geysermc.connector.network.translators.world.block.entity;
|
package org.geysermc.connector.network.translators.world.block.entity;
|
||||||
|
|
||||||
import com.github.steveice10.mc.protocol.data.message.Message;
|
import com.github.steveice10.mc.protocol.data.message.MessageSerializer;
|
||||||
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
||||||
import com.nukkitx.nbt.CompoundTagBuilder;
|
import com.nukkitx.nbt.CompoundTagBuilder;
|
||||||
import com.nukkitx.nbt.tag.StringTag;
|
import com.nukkitx.nbt.tag.StringTag;
|
||||||
import com.nukkitx.nbt.tag.Tag;
|
import com.nukkitx.nbt.tag.Tag;
|
||||||
import io.netty.util.internal.StringUtil;
|
|
||||||
import org.geysermc.connector.utils.MessageUtils;
|
import org.geysermc.connector.utils.MessageUtils;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -47,7 +46,7 @@ public class SignBlockEntityTranslator extends BlockEntityTranslator {
|
||||||
for(int i = 0; i < 4; i++) {
|
for(int i = 0; i < 4; i++) {
|
||||||
int currentLine = i+1;
|
int currentLine = i+1;
|
||||||
String signLine = getOrDefault(tag.getValue().get("Text" + currentLine), "");
|
String signLine = getOrDefault(tag.getValue().get("Text" + currentLine), "");
|
||||||
signLine = MessageUtils.getBedrockMessage(Message.fromString(signLine));
|
signLine = MessageUtils.getBedrockMessage(MessageSerializer.fromString(signLine));
|
||||||
|
|
||||||
//Java allows up to 16+ characters on certain symbols.
|
//Java allows up to 16+ characters on certain symbols.
|
||||||
if(signLine.length() >= 15 && (signLine.contains("-") || signLine.contains("="))) {
|
if(signLine.length() >= 15 && (signLine.contains("-") || signLine.contains("="))) {
|
||||||
|
@ -58,7 +57,7 @@ public class SignBlockEntityTranslator extends BlockEntityTranslator {
|
||||||
signText.append("\n");
|
signText.append("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
tags.add(new StringTag("Text", MessageUtils.getBedrockMessage(Message.fromString(signText.toString()))));
|
tags.add(new StringTag("Text", MessageUtils.getBedrockMessage(MessageSerializer.fromString(signText.toString()))));
|
||||||
return tags;
|
return tags;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -77,7 +77,7 @@ public class GeyserLegacyPingPassthrough implements IGeyserPingPassthrough, Runn
|
||||||
try {
|
try {
|
||||||
this.client = new Client(connector.getConfig().getRemote().getAddress(), connector.getConfig().getRemote().getPort(), new MinecraftProtocol(SubProtocol.STATUS), new TcpSessionFactory());
|
this.client = new Client(connector.getConfig().getRemote().getAddress(), connector.getConfig().getRemote().getPort(), new MinecraftProtocol(SubProtocol.STATUS), new TcpSessionFactory());
|
||||||
this.client.getSession().setFlag(MinecraftConstants.SERVER_INFO_HANDLER_KEY, (ServerInfoHandler) (session, info) -> {
|
this.client.getSession().setFlag(MinecraftConstants.SERVER_INFO_HANDLER_KEY, (ServerInfoHandler) (session, info) -> {
|
||||||
this.pingInfo = new GeyserPingInfo(info.getDescription().getFullText(), info.getPlayerInfo().getOnlinePlayers(), info.getPlayerInfo().getMaxPlayers());
|
this.pingInfo = new GeyserPingInfo(info.getDescription().toString(), info.getPlayerInfo().getOnlinePlayers(), info.getPlayerInfo().getMaxPlayers());
|
||||||
this.client.getSession().disconnect(null);
|
this.client.getSession().disconnect(null);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,12 @@
|
||||||
package org.geysermc.connector.utils;
|
package org.geysermc.connector.utils;
|
||||||
|
|
||||||
import com.github.steveice10.mc.protocol.data.game.scoreboard.TeamColor;
|
import com.github.steveice10.mc.protocol.data.game.scoreboard.TeamColor;
|
||||||
import com.github.steveice10.mc.protocol.data.message.*;
|
import com.github.steveice10.mc.protocol.data.message.Message;
|
||||||
|
import com.github.steveice10.mc.protocol.data.message.MessageSerializer;
|
||||||
|
import com.github.steveice10.mc.protocol.data.message.TranslationMessage;
|
||||||
|
import com.github.steveice10.mc.protocol.data.message.style.ChatColor;
|
||||||
|
import com.github.steveice10.mc.protocol.data.message.style.ChatFormat;
|
||||||
|
import com.github.steveice10.mc.protocol.data.message.style.MessageStyle;
|
||||||
import com.google.gson.*;
|
import com.google.gson.*;
|
||||||
import net.kyori.text.Component;
|
import net.kyori.text.Component;
|
||||||
import net.kyori.text.serializer.gson.GsonComponentSerializer;
|
import net.kyori.text.serializer.gson.GsonComponentSerializer;
|
||||||
|
@ -41,28 +46,28 @@ import java.util.regex.Pattern;
|
||||||
|
|
||||||
public class MessageUtils {
|
public class MessageUtils {
|
||||||
|
|
||||||
public static List<String> getTranslationParams(Message[] messages, String locale) {
|
public static List<String> getTranslationParams(List<Message> messages, String locale) {
|
||||||
List<String> strings = new ArrayList<>();
|
List<String> strings = new ArrayList<>();
|
||||||
for (Message message : messages) {
|
for (Message message : messages) {
|
||||||
if (message instanceof TranslationMessage) {
|
if (message instanceof TranslationMessage) {
|
||||||
TranslationMessage translation = (TranslationMessage) message;
|
TranslationMessage translation = (TranslationMessage) message;
|
||||||
|
|
||||||
if (locale == null) {
|
if (locale == null) {
|
||||||
String builder = "%" + translation.getTranslationKey();
|
String builder = "%" + translation.getKey();
|
||||||
strings.add(builder);
|
strings.add(builder);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (translation.getTranslationKey().equals("commands.gamemode.success.other")) {
|
if (translation.getKey().equals("commands.gamemode.success.other")) {
|
||||||
strings.add("");
|
strings.add("");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (translation.getTranslationKey().equals("command.context.here")) {
|
if (translation.getKey().equals("command.context.here")) {
|
||||||
strings.add(" - no permission or invalid command!");
|
strings.add(" - no permission or invalid command!");
|
||||||
}
|
}
|
||||||
|
|
||||||
List<String> furtherParams = getTranslationParams(translation.getTranslationParams(), locale);
|
List<String> furtherParams = getTranslationParams(translation.getWith(), locale);
|
||||||
if (locale != null) {
|
if (locale != null) {
|
||||||
strings.add(insertParams(LocaleUtils.getLocaleString(translation.getTranslationKey(), locale), furtherParams));
|
strings.add(insertParams(LocaleUtils.getLocaleString(translation.getKey(), locale), furtherParams));
|
||||||
} else {
|
} else {
|
||||||
strings.addAll(furtherParams);
|
strings.addAll(furtherParams);
|
||||||
}
|
}
|
||||||
|
@ -77,23 +82,23 @@ public class MessageUtils {
|
||||||
return strings;
|
return strings;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<String> getTranslationParams(Message[] messages) {
|
public static List<String> getTranslationParams(List<Message> messages) {
|
||||||
return getTranslationParams(messages, null);
|
return getTranslationParams(messages, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getTranslationText(TranslationMessage message) {
|
public static String getTranslationText(TranslationMessage message) {
|
||||||
return getFormat(message.getStyle().getFormats()) + getColorOrParent(message.getStyle())
|
return getFormat(message.getStyle().getFormats()) + getColorOrParent(message.getStyle())
|
||||||
+ "%" + message.getTranslationKey();
|
+ "%" + message.getKey();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getTranslatedBedrockMessage(Message message, String locale, boolean shouldTranslate) {
|
public static String getTranslatedBedrockMessage(Message message, String locale, boolean shouldTranslate) {
|
||||||
JsonParser parser = new JsonParser();
|
JsonParser parser = new JsonParser();
|
||||||
if (isMessage(message.getText())) {
|
if (isMessage(message.toString())) {
|
||||||
JsonObject object = parser.parse(message.getText()).getAsJsonObject();
|
JsonObject object = parser.parse(message.toString()).getAsJsonObject();
|
||||||
message = Message.fromJson(formatJson(object));
|
message = MessageSerializer.fromJson(formatJson(object));
|
||||||
}
|
}
|
||||||
|
|
||||||
String messageText = message.getText();
|
String messageText = message.toString();
|
||||||
if (locale != null && shouldTranslate) {
|
if (locale != null && shouldTranslate) {
|
||||||
messageText = LocaleUtils.getLocaleString(messageText, locale);
|
messageText = LocaleUtils.getLocaleString(messageText, locale);
|
||||||
}
|
}
|
||||||
|
@ -106,12 +111,12 @@ public class MessageUtils {
|
||||||
for (Message msg : message.getExtra()) {
|
for (Message msg : message.getExtra()) {
|
||||||
builder.append(getFormat(msg.getStyle().getFormats()));
|
builder.append(getFormat(msg.getStyle().getFormats()));
|
||||||
builder.append(getColorOrParent(msg.getStyle()));
|
builder.append(getColorOrParent(msg.getStyle()));
|
||||||
if (!(msg.getText() == null)) {
|
if (!(msg.toString() == null)) {
|
||||||
boolean isTranslationMessage = (msg instanceof TranslationMessage);
|
boolean isTranslationMessage = (msg instanceof TranslationMessage);
|
||||||
String extraText = "";
|
String extraText = "";
|
||||||
|
|
||||||
if (isTranslationMessage) {
|
if (isTranslationMessage) {
|
||||||
List<String> paramsTranslated = getTranslationParams(((TranslationMessage) msg).getTranslationParams(), locale);
|
List<String> paramsTranslated = getTranslationParams(((TranslationMessage) msg).getWith(), locale);
|
||||||
extraText = insertParams(getTranslatedBedrockMessage(msg, locale, isTranslationMessage), paramsTranslated);
|
extraText = insertParams(getTranslatedBedrockMessage(msg, locale, isTranslationMessage), paramsTranslated);
|
||||||
} else {
|
} else {
|
||||||
extraText = getTranslatedBedrockMessage(msg, locale, isTranslationMessage);
|
extraText = getTranslatedBedrockMessage(msg, locale, isTranslationMessage);
|
||||||
|
@ -130,10 +135,10 @@ public class MessageUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getBedrockMessage(Message message) {
|
public static String getBedrockMessage(Message message) {
|
||||||
if (isMessage(message.getText())) {
|
if (isMessage(message.toString())) {
|
||||||
return getBedrockMessage(message.getText());
|
return getBedrockMessage(message.toString());
|
||||||
} else {
|
} else {
|
||||||
return getBedrockMessage(message.toJsonString());
|
return getBedrockMessage(MessageSerializer.toJsonString(message));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -206,9 +211,9 @@ public class MessageUtils {
|
||||||
private static String getColorOrParent(MessageStyle style) {
|
private static String getColorOrParent(MessageStyle style) {
|
||||||
ChatColor chatColor = style.getColor();
|
ChatColor chatColor = style.getColor();
|
||||||
|
|
||||||
if (chatColor == ChatColor.NONE && style.getParent() != null) {
|
/*if (chatColor == ChatColor.NONE && style.getParent() != null) {
|
||||||
return getColorOrParent(style.getParent());
|
return getColorOrParent(style.getParent());
|
||||||
}
|
}*/
|
||||||
|
|
||||||
return getColor(chatColor);
|
return getColor(chatColor);
|
||||||
}
|
}
|
||||||
|
@ -328,7 +333,7 @@ public class MessageUtils {
|
||||||
try {
|
try {
|
||||||
JsonObject object = parser.parse(text).getAsJsonObject();
|
JsonObject object = parser.parse(text).getAsJsonObject();
|
||||||
try {
|
try {
|
||||||
Message.fromJson(formatJson(object));
|
MessageSerializer.fromJson(formatJson(object));
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue