From 1711223b0225db88008f4cfcb04315521d89c372 Mon Sep 17 00:00:00 2001 From: md_5 Date: Mon, 22 Dec 2014 19:59:14 +1100 Subject: [PATCH] Use string lists in preference to string arrays. --- .../net/md_5/bungee/protocol/DefinedPacket.java | 14 ++++++++------ .../protocol/packet/TabCompleteResponse.java | 3 ++- .../net/md_5/bungee/connection/UpstreamBridge.java | 8 ++++---- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/DefinedPacket.java b/protocol/src/main/java/net/md_5/bungee/protocol/DefinedPacket.java index 32b7554f..1afa6737 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/DefinedPacket.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/DefinedPacket.java @@ -3,6 +3,8 @@ package net.md_5.bungee.protocol; import com.google.common.base.Charsets; import com.google.common.base.Preconditions; import io.netty.buffer.ByteBuf; +import java.util.ArrayList; +import java.util.List; import lombok.RequiredArgsConstructor; import java.util.UUID; @@ -74,22 +76,22 @@ public abstract class DefinedPacket return ret; } - public static void writeStringArray(String[] s, ByteBuf buf) + public static void writeStringArray(List s, ByteBuf buf) { - writeVarInt( s.length, buf ); + writeVarInt( s.size(), buf ); for ( String str : s ) { writeString( str, buf ); } } - public static String[] readStringArray(ByteBuf buf) + public static List readStringArray(ByteBuf buf) { int len = readVarInt( buf ); - String[] ret = new String[ len ]; - for ( int i = 0; i < ret.length; i++ ) + List ret = new ArrayList<>( len ); + for ( int i = 0; i < len; i++ ) { - ret[i] = readString( buf ); + ret.add( readString( buf ) ); } return ret; } diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/TabCompleteResponse.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/TabCompleteResponse.java index 0027b989..ebce9a6a 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/packet/TabCompleteResponse.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/TabCompleteResponse.java @@ -2,6 +2,7 @@ package net.md_5.bungee.protocol.packet; import net.md_5.bungee.protocol.DefinedPacket; import io.netty.buffer.ByteBuf; +import java.util.List; import lombok.AllArgsConstructor; import lombok.Data; import lombok.EqualsAndHashCode; @@ -15,7 +16,7 @@ import net.md_5.bungee.protocol.AbstractPacketHandler; public class TabCompleteResponse extends DefinedPacket { - private String[] commands; + private List commands; @Override public void read(ByteBuf buf) diff --git a/proxy/src/main/java/net/md_5/bungee/connection/UpstreamBridge.java b/proxy/src/main/java/net/md_5/bungee/connection/UpstreamBridge.java index 2a42ab0f..2b58cc29 100644 --- a/proxy/src/main/java/net/md_5/bungee/connection/UpstreamBridge.java +++ b/proxy/src/main/java/net/md_5/bungee/connection/UpstreamBridge.java @@ -22,7 +22,6 @@ import net.md_5.bungee.protocol.packet.PluginMessage; import java.util.ArrayList; import java.util.List; import net.md_5.bungee.forge.ForgeConstants; -import net.md_5.bungee.protocol.ProtocolConstants; import net.md_5.bungee.protocol.packet.TabCompleteResponse; public class UpstreamBridge extends PacketHandler @@ -68,8 +67,9 @@ public class UpstreamBridge extends PacketHandler packet.setAction( PlayerListItem.Action.REMOVE_PLAYER ); PlayerListItem.Item item = new PlayerListItem.Item(); item.setUuid( con.getUniqueId() ); - packet.setItems( new PlayerListItem.Item[]{ - item + packet.setItems( new PlayerListItem.Item[] + { + item } ); for ( ProxiedPlayer player : con.getServer().getInfo().getPlayers() ) { @@ -133,7 +133,7 @@ public class UpstreamBridge extends PacketHandler List results = tabCompleteEvent.getSuggestions(); if ( !results.isEmpty() ) { - con.unsafe().sendPacket( new TabCompleteResponse( results.toArray( new String[ results.size() ] ) ) ); + con.unsafe().sendPacket( new TabCompleteResponse( results ) ); throw CancelSendSignal.INSTANCE; }