Add player list header / footer API.

This commit is contained in:
Minecrell 2014-09-05 16:52:11 +02:00 committed by Thinkofdeath
parent bc48ab3fb8
commit d6b7157c1c
5 changed files with 103 additions and 0 deletions

View File

@ -3,6 +3,7 @@ package net.md_5.bungee.api.connection;
import java.util.Locale; import java.util.Locale;
import net.md_5.bungee.api.Callback; import net.md_5.bungee.api.Callback;
import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.api.config.ServerInfo; import net.md_5.bungee.api.config.ServerInfo;
import java.util.UUID; import java.util.UUID;
@ -121,4 +122,23 @@ public interface ProxiedPlayer extends Connection, CommandSender
* @return the locale * @return the locale
*/ */
Locale getLocale(); Locale getLocale();
/**
* Set the header and footer displayed in the tab player list.
* @param header The header for the tab player list, null to clear it.
* @param footer The footer for the tab player list, null to clear it.
*/
void setTabHeader(BaseComponent header, BaseComponent footer);
/**
* Set the header and footer displayed in the tab player list.
* @param header The header for the tab player list, null to clear it.
* @param footer The footer for the tab player list, null to clear it.
*/
void setTabHeader(BaseComponent[] header, BaseComponent[] footer);
/**
* Clears the header and footer displayed in the tab player list.
*/
void resetTabHeader();
} }

View File

@ -6,6 +6,7 @@ import net.md_5.bungee.protocol.packet.ClientStatus;
import net.md_5.bungee.protocol.packet.Login; import net.md_5.bungee.protocol.packet.Login;
import net.md_5.bungee.protocol.packet.Chat; import net.md_5.bungee.protocol.packet.Chat;
import net.md_5.bungee.protocol.packet.EncryptionRequest; import net.md_5.bungee.protocol.packet.EncryptionRequest;
import net.md_5.bungee.protocol.packet.PlayerListHeaderFooter;
import net.md_5.bungee.protocol.packet.PlayerListItem; import net.md_5.bungee.protocol.packet.PlayerListItem;
import net.md_5.bungee.protocol.packet.SetCompression; import net.md_5.bungee.protocol.packet.SetCompression;
import net.md_5.bungee.protocol.packet.TabCompleteRequest; import net.md_5.bungee.protocol.packet.TabCompleteRequest;
@ -86,6 +87,10 @@ public abstract class AbstractPacketHandler
{ {
} }
public void handle(PlayerListHeaderFooter playerListHeaderFooter) throws Exception
{
}
public void handle(TabCompleteRequest tabComplete) throws Exception public void handle(TabCompleteRequest tabComplete) throws Exception
{ {
} }

View File

@ -19,6 +19,7 @@ import net.md_5.bungee.protocol.packet.Login;
import net.md_5.bungee.protocol.packet.LoginRequest; import net.md_5.bungee.protocol.packet.LoginRequest;
import net.md_5.bungee.protocol.packet.LoginSuccess; import net.md_5.bungee.protocol.packet.LoginSuccess;
import net.md_5.bungee.protocol.packet.PingPacket; import net.md_5.bungee.protocol.packet.PingPacket;
import net.md_5.bungee.protocol.packet.PlayerListHeaderFooter;
import net.md_5.bungee.protocol.packet.PlayerListItem; import net.md_5.bungee.protocol.packet.PlayerListItem;
import net.md_5.bungee.protocol.packet.PluginMessage; import net.md_5.bungee.protocol.packet.PluginMessage;
import net.md_5.bungee.protocol.packet.Respawn; import net.md_5.bungee.protocol.packet.Respawn;
@ -61,6 +62,7 @@ public enum Protocol
TO_CLIENT.registerPacket( 0x3F, PluginMessage.class ); TO_CLIENT.registerPacket( 0x3F, PluginMessage.class );
TO_CLIENT.registerPacket( 0x40, Kick.class ); TO_CLIENT.registerPacket( 0x40, Kick.class );
TO_CLIENT.registerPacket( 0x46, SetCompression.class ); TO_CLIENT.registerPacket( 0x46, SetCompression.class );
TO_CLIENT.registerPacket( 0x47, PlayerListHeaderFooter.class );
TO_SERVER.registerPacket( 0x00, KeepAlive.class ); TO_SERVER.registerPacket( 0x00, KeepAlive.class );
TO_SERVER.registerPacket( 0x01, Chat.class ); TO_SERVER.registerPacket( 0x01, Chat.class );

View File

@ -0,0 +1,41 @@
package net.md_5.bungee.protocol.packet;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import io.netty.buffer.ByteBuf;
import net.md_5.bungee.protocol.AbstractPacketHandler;
import net.md_5.bungee.protocol.DefinedPacket;
import net.md_5.bungee.protocol.ProtocolConstants;
@Data
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = false)
public class PlayerListHeaderFooter extends DefinedPacket
{
private String header;
private String footer;
@Override
public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion)
{
header = readString( buf );
footer = readString( buf );
}
@Override
public void write(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion)
{
writeString( header, buf );
writeString( footer, buf );
}
@Override
public void handle(AbstractPacketHandler handler) throws Exception
{
handler.handle( this );
}
}

View File

@ -41,8 +41,10 @@ import net.md_5.bungee.protocol.DefinedPacket;
import net.md_5.bungee.protocol.MinecraftDecoder; import net.md_5.bungee.protocol.MinecraftDecoder;
import net.md_5.bungee.protocol.MinecraftEncoder; import net.md_5.bungee.protocol.MinecraftEncoder;
import net.md_5.bungee.protocol.Protocol; import net.md_5.bungee.protocol.Protocol;
import net.md_5.bungee.protocol.ProtocolConstants;
import net.md_5.bungee.protocol.packet.Chat; import net.md_5.bungee.protocol.packet.Chat;
import net.md_5.bungee.protocol.packet.ClientSettings; import net.md_5.bungee.protocol.packet.ClientSettings;
import net.md_5.bungee.protocol.packet.PlayerListHeaderFooter;
import net.md_5.bungee.protocol.packet.PluginMessage; import net.md_5.bungee.protocol.packet.PluginMessage;
import net.md_5.bungee.protocol.packet.Kick; import net.md_5.bungee.protocol.packet.Kick;
import net.md_5.bungee.protocol.packet.SetCompression; import net.md_5.bungee.protocol.packet.SetCompression;
@ -469,6 +471,39 @@ public final class UserConnection implements ProxiedPlayer
return ( locale == null && settings != null ) ? locale = Locale.forLanguageTag( settings.getLocale().replaceAll( "_", "-" ) ) : locale; return ( locale == null && settings != null ) ? locale = Locale.forLanguageTag( settings.getLocale().replaceAll( "_", "-" ) ) : locale;
} }
private static final String EMPTY_TEXT = ComponentSerializer.toString( new TextComponent( "" ) );
@Override
public void setTabHeader(BaseComponent header, BaseComponent footer)
{
if ( pendingConnection.getVersion() >= ProtocolConstants.MINECRAFT_SNAPSHOT )
{
unsafe().sendPacket( new PlayerListHeaderFooter(
( header != null ) ? ComponentSerializer.toString( header ) : EMPTY_TEXT,
( footer != null ) ? ComponentSerializer.toString( footer ) : EMPTY_TEXT
) );
}
}
@Override
public void setTabHeader(BaseComponent[] header, BaseComponent[] footer)
{
if ( pendingConnection.getVersion() >= ProtocolConstants.MINECRAFT_SNAPSHOT )
{
unsafe().sendPacket( new PlayerListHeaderFooter(
( header != null ) ? ComponentSerializer.toString( header ) : EMPTY_TEXT,
( footer != null ) ? ComponentSerializer.toString( footer ) : EMPTY_TEXT
) );
}
}
@Override
public void resetTabHeader()
{
// Mojang did not add a way to remove the header / footer completely, we can only set it to empty
setTabHeader( (BaseComponent) null, null );
}
public void setCompressionThreshold(int compressionThreshold) public void setCompressionThreshold(int compressionThreshold)
{ {
if ( this.compressionThreshold == -1 ) if ( this.compressionThreshold == -1 )