Update ChatConverter
This commit is contained in:
parent
18db187347
commit
81e43aab98
@ -488,7 +488,9 @@ public class BungeeCord extends ProxyServer
|
||||
{
|
||||
getConsole().sendMessage( message );
|
||||
// TODO: Here too
|
||||
broadcast( new Chat( ChatConverter.toJSONChat( message ) ) );
|
||||
for (String msg : ChatConverter.toJSONChat( message )) {
|
||||
broadcast( new Chat( msg ) );
|
||||
}
|
||||
}
|
||||
|
||||
public void addConnection(UserConnection con)
|
||||
|
@ -14,9 +14,10 @@ public class ChatConverter {
|
||||
private static final char COLOR_CHAR = '\u00A7';
|
||||
private static final Pattern url = Pattern.compile("^(?:(https?)://)?([-\\w_\\.]{2,}\\.[a-z]{2,4})(/\\S*)?$");
|
||||
|
||||
public static String toJSONChat(String txt) {
|
||||
public static String[] toJSONChat(String txt) {
|
||||
Message msg = new Message();
|
||||
ArrayList<Message> parts = new ArrayList<Message>();
|
||||
ArrayList<String> parts = new ArrayList<String>();
|
||||
StringBuilder outBuffer = new StringBuilder("[");
|
||||
StringBuilder buf = new StringBuilder();
|
||||
Matcher matcher = url.matcher(txt);
|
||||
for (int i = 0; i < txt.length(); i++) {
|
||||
@ -27,7 +28,7 @@ public class ChatConverter {
|
||||
if (matcher.region(i, pos).find()) { //Web link handling
|
||||
msg.text = buf.toString();
|
||||
buf = new StringBuilder();
|
||||
parts.add(msg);
|
||||
outBuffer = append(parts, outBuffer, msg);
|
||||
Message old = msg;
|
||||
msg = new Message(old);
|
||||
msg.clickEvent = new ClickEvent();
|
||||
@ -39,7 +40,7 @@ public class ChatConverter {
|
||||
msg.text = urlString;
|
||||
msg.clickEvent.value = "http://" + urlString;
|
||||
}
|
||||
parts.add(msg);
|
||||
outBuffer = append(parts, outBuffer, msg);
|
||||
i += pos - i - 1;
|
||||
msg = new Message(old);
|
||||
continue;
|
||||
@ -54,7 +55,7 @@ public class ChatConverter {
|
||||
}
|
||||
msg.text = buf.toString();
|
||||
buf = new StringBuilder();
|
||||
parts.add(msg);
|
||||
outBuffer = append(parts, outBuffer, msg);
|
||||
msg = new Message(msg);
|
||||
switch(c) {
|
||||
case 'k':
|
||||
@ -87,8 +88,26 @@ public class ChatConverter {
|
||||
}
|
||||
}
|
||||
msg.text = buf.toString();
|
||||
parts.add(msg);
|
||||
return gson.toJson(parts);
|
||||
append(parts, outBuffer, msg);
|
||||
|
||||
parts.add(outBuffer.append("]").toString());
|
||||
String[] pArray = new String[parts.size()];
|
||||
parts.toArray(pArray);
|
||||
return pArray;
|
||||
}
|
||||
|
||||
private static StringBuilder append(ArrayList<String> parts, StringBuilder outBuffer, Message part) {
|
||||
String p = gson.toJson(part);
|
||||
if (p.length() + outBuffer.length() + 1 >= Short.MAX_VALUE - 20) {
|
||||
outBuffer.append("]");
|
||||
parts.add(outBuffer.toString());
|
||||
outBuffer = new StringBuilder("[");
|
||||
}
|
||||
if (outBuffer.length() != 1) {
|
||||
outBuffer.append(",");
|
||||
}
|
||||
outBuffer.append(p);
|
||||
return outBuffer;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -256,7 +256,7 @@ public final class UserConnection implements ProxiedPlayer
|
||||
@Override
|
||||
public synchronized void disconnect(String reason)
|
||||
{
|
||||
disconnect0( ChatConverter.toJSONChat( reason ) );
|
||||
disconnect0( ChatConverter.toJSONChat( reason )[0] );
|
||||
}
|
||||
|
||||
public synchronized void disconnect0(String reason)
|
||||
@ -283,7 +283,9 @@ public final class UserConnection implements ProxiedPlayer
|
||||
@Override
|
||||
public void sendMessage(String message)
|
||||
{
|
||||
unsafe().sendPacket( new Chat( ChatConverter.toJSONChat( message ) ) );
|
||||
for(String msg : ChatConverter.toJSONChat( message )) {
|
||||
unsafe().sendPacket( new Chat( msg ) );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -397,7 +397,7 @@ public class InitialHandler extends PacketHandler implements PendingConnection
|
||||
{
|
||||
if ( !ch.isClosed() )
|
||||
{
|
||||
unsafe().sendPacket( new Kick( ChatConverter.toJSONChat( reason ) ) );
|
||||
unsafe().sendPacket( new Kick( ChatConverter.toJSONChat( reason )[0] ) );
|
||||
ch.close();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user