Clear scoreboards on reconnect.

This commit is contained in:
md_5 2013-03-16 20:13:01 +11:00
parent 70c73211a0
commit 6bb089074e
9 changed files with 80 additions and 3 deletions

View File

@ -0,0 +1,17 @@
package net.md_5.bungee.api.scoreboard;
import lombok.Data;
@Data
public class Scoreboard
{
/**
* Unique name for this scoreboard.
*/
private final String name;
/**
* Text to be displayed with this scoreboard.
*/
private final String text;
}

View File

@ -13,9 +13,9 @@ import net.md_5.bungee.connection.DownstreamBridge;
import net.md_5.bungee.netty.HandlerBoss;
import net.md_5.bungee.packet.DefinedPacket;
import net.md_5.bungee.packet.Packet1Login;
import net.md_5.bungee.packet.Packet2Handshake;
import net.md_5.bungee.packet.Packet9Respawn;
import net.md_5.bungee.packet.PacketCDClientStatus;
import net.md_5.bungee.packet.PacketCESetScoreboard;
import net.md_5.bungee.packet.PacketFDEncryptionRequest;
import net.md_5.bungee.packet.PacketFFKick;
import net.md_5.bungee.packet.PacketHandler;
@ -90,6 +90,11 @@ public class ServerConnector extends PacketHandler
} else
{
bungee.getTabListHandler().onServerChange( user );
if ( user.serverSentScoreboard != null )
{
user.sendPacket( new PacketCESetScoreboard( user.serverSentScoreboard.getName(), user.serverSentScoreboard.getText(), (byte) 1 ) );
}
user.sendPacket( Packet9Respawn.DIM1_SWITCH );
user.sendPacket( Packet9Respawn.DIM2_SWITCH );

View File

@ -24,6 +24,7 @@ import net.md_5.bungee.api.config.ServerInfo;
import net.md_5.bungee.api.connection.PendingConnection;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.event.ServerConnectEvent;
import net.md_5.bungee.api.scoreboard.Scoreboard;
import net.md_5.bungee.netty.HandlerBoss;
import net.md_5.bungee.netty.PipelineUtils;
import net.md_5.bungee.packet.*;
@ -61,6 +62,7 @@ public final class UserConnection implements ProxiedPlayer
@Getter
private final Object switchMutex = new Object();
public PacketCCSettings settings;
public Scoreboard serverSentScoreboard;
public UserConnection(BungeeCord bungee, Channel channel, PendingConnection pendingConnection, Packet2Handshake handshake, Packet1Login forgeLogin, List<PacketFAPluginMessage> loginMessages)
{

View File

@ -14,9 +14,11 @@ import net.md_5.bungee.api.config.ServerInfo;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.event.ChatEvent;
import net.md_5.bungee.api.event.PluginMessageEvent;
import net.md_5.bungee.api.scoreboard.Scoreboard;
import net.md_5.bungee.packet.Packet0KeepAlive;
import net.md_5.bungee.packet.Packet3Chat;
import net.md_5.bungee.packet.PacketC9PlayerListItem;
import net.md_5.bungee.packet.PacketCESetScoreboard;
import net.md_5.bungee.packet.PacketFAPluginMessage;
import net.md_5.bungee.packet.PacketFFKick;
import net.md_5.bungee.packet.PacketHandler;
@ -73,6 +75,12 @@ public class DownstreamBridge extends PacketHandler
}
}
@Override
public void handle(PacketCESetScoreboard scoreboard) throws Exception
{
con.serverSentScoreboard = new Scoreboard( scoreboard.name, scoreboard.text );
}
@Override
public void handle(PacketC9PlayerListItem playerList) throws Exception
{

View File

@ -226,6 +226,7 @@ public abstract class DefinedPacket implements DataOutput
classes[0x09] = Packet9Respawn.class;
classes[0xC9] = PacketC9PlayerListItem.class;
classes[0xCD] = PacketCDClientStatus.class;
classes[0xCE] = PacketCESetScoreboard.class;
classes[0xFA] = PacketFAPluginMessage.class;
classes[0xFC] = PacketFCEncryptionResponse.class;
classes[0xFD] = PacketFDEncryptionRequest.class;

View File

@ -1,6 +1,5 @@
package net.md_5.bungee.packet;
import io.netty.buffer.ByteBuf;
import lombok.EqualsAndHashCode;
import lombok.ToString;

View File

@ -1,6 +1,5 @@
package net.md_5.bungee.packet;
import io.netty.buffer.ByteBuf;
import lombok.EqualsAndHashCode;
import lombok.ToString;

View File

@ -0,0 +1,42 @@
package net.md_5.bungee.packet;
import lombok.EqualsAndHashCode;
import lombok.ToString;
@ToString
@EqualsAndHashCode(callSuper = false)
public class PacketCESetScoreboard extends DefinedPacket
{
public String name;
public String text;
/**
* 0 to create, 1 to remove.
*/
public byte status;
public PacketCESetScoreboard(String name, String text, byte status)
{
super( 0xCE );
writeUTF( name );
writeUTF( text );
writeByte( status );
this.name = name;
this.text = text;
this.status = status;
}
PacketCESetScoreboard(byte[] buf)
{
super( 0xCE, buf );
this.name = readUTF();
this.text = readUTF();
this.status = readByte();
}
@Override
public void handle(PacketHandler handler) throws Exception
{
handler.handle( this );
}
}

View File

@ -56,6 +56,10 @@ public abstract class PacketHandler
{
}
public void handle(PacketCESetScoreboard scoreboard) throws Exception
{
}
public void handle(PacketFAPluginMessage pluginMessage) throws Exception
{
}