From e2e32100cd950c39f2d7cda64a642f0b77123d02 Mon Sep 17 00:00:00 2001 From: md_5 Date: Fri, 25 Oct 2013 20:39:06 +1100 Subject: [PATCH] Common method to wrap text. Thanks @lazertester --- proxy/src/main/java/net/md_5/bungee/BungeeCord.java | 6 +----- proxy/src/main/java/net/md_5/bungee/UserConnection.java | 5 ++--- proxy/src/main/java/net/md_5/bungee/Util.java | 6 ++++++ .../java/net/md_5/bungee/connection/InitialHandler.java | 2 +- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/proxy/src/main/java/net/md_5/bungee/BungeeCord.java b/proxy/src/main/java/net/md_5/bungee/BungeeCord.java index 8001582ef..fd71b8cdb 100644 --- a/proxy/src/main/java/net/md_5/bungee/BungeeCord.java +++ b/proxy/src/main/java/net/md_5/bungee/BungeeCord.java @@ -23,8 +23,6 @@ import java.io.IOException; import java.io.PrintStream; import java.net.InetSocketAddress; import java.text.MessageFormat; -import java.text.SimpleDateFormat; -import java.util.Calendar; import java.util.Collection; import java.util.Collections; import java.util.HashSet; @@ -44,7 +42,6 @@ import jline.internal.Log; import lombok.Getter; import lombok.Setter; import lombok.Synchronized; -import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.ReconnectHandler; @@ -492,8 +489,7 @@ public class BungeeCord extends ProxyServer { getConsole().sendMessage( message ); // TODO: Here too - String encoded = BungeeCord.getInstance().gson.toJson( message ); - broadcast( new Chat( "{\"text\":" + encoded + "}" ) ); + broadcast( new Chat( Util.stupify( message ) ) ); } public void addConnection(UserConnection con) diff --git a/proxy/src/main/java/net/md_5/bungee/UserConnection.java b/proxy/src/main/java/net/md_5/bungee/UserConnection.java index 1afb3995c..6e26354a6 100644 --- a/proxy/src/main/java/net/md_5/bungee/UserConnection.java +++ b/proxy/src/main/java/net/md_5/bungee/UserConnection.java @@ -255,7 +255,7 @@ public final class UserConnection implements ProxiedPlayer if ( ch.getHandle().isActive() ) { bungee.getLogger().log( Level.INFO, "[" + getName() + "] disconnected with: " + reason ); - unsafe().sendPacket( new Kick( BungeeCord.getInstance().gson.toJson( reason ) ) ); + unsafe().sendPacket( new Kick( Util.stupify( reason ) ) ); ch.close(); if ( server != null ) { @@ -275,8 +275,7 @@ public final class UserConnection implements ProxiedPlayer public void sendMessage(String message) { // TODO: Fix this - String encoded = BungeeCord.getInstance().gson.toJson( message ); - unsafe().sendPacket( new Chat( "{\"text\":" + encoded + "}" ) ); + unsafe().sendPacket( new Chat( Util.stupify( message ) ) ); } @Override diff --git a/proxy/src/main/java/net/md_5/bungee/Util.java b/proxy/src/main/java/net/md_5/bungee/Util.java index b42808f82..cd8b6df27 100644 --- a/proxy/src/main/java/net/md_5/bungee/Util.java +++ b/proxy/src/main/java/net/md_5/bungee/Util.java @@ -70,4 +70,10 @@ public class Util return ( ret.length() == 0 ) ? "" : ret.substring( 0, ret.length() - separators.length() ); } + + public static String stupify(String text) + { + // TODO: Colour text wrapper to work around 1.7 client bug with section sign + return "{\"text\":" + BungeeCord.getInstance().gson.toJson( text ) + "}"; + } } diff --git a/proxy/src/main/java/net/md_5/bungee/connection/InitialHandler.java b/proxy/src/main/java/net/md_5/bungee/connection/InitialHandler.java index a8aff99d8..8190d6c84 100644 --- a/proxy/src/main/java/net/md_5/bungee/connection/InitialHandler.java +++ b/proxy/src/main/java/net/md_5/bungee/connection/InitialHandler.java @@ -396,7 +396,7 @@ public class InitialHandler extends PacketHandler implements PendingConnection { if ( !ch.isClosed() ) { - unsafe().sendPacket( new Kick( BungeeCord.getInstance().gson.toJson( reason ) ) ); + unsafe().sendPacket( new Kick( Util.stupify( reason ) ) ); ch.close(); } }