Use string lists in preference to string arrays.

This commit is contained in:
md_5 2014-12-22 19:59:14 +11:00
parent cd15b82361
commit 1711223b02
3 changed files with 14 additions and 11 deletions

View File

@ -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<String> 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<String> readStringArray(ByteBuf buf)
{
int len = readVarInt( buf );
String[] ret = new String[ len ];
for ( int i = 0; i < ret.length; i++ )
List<String> ret = new ArrayList<>( len );
for ( int i = 0; i < len; i++ )
{
ret[i] = readString( buf );
ret.add( readString( buf ) );
}
return ret;
}

View File

@ -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<String> commands;
@Override
public void read(ByteBuf buf)

View File

@ -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,7 +67,8 @@ 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[]{
packet.setItems( new PlayerListItem.Item[]
{
item
} );
for ( ProxiedPlayer player : con.getServer().getInfo().getPlayers() )
@ -133,7 +133,7 @@ public class UpstreamBridge extends PacketHandler
List<String> 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;
}