Remove any tracked bossbars when a client switches servers.

This commit is contained in:
Youri Kersten 2016-03-03 18:36:56 +11:00 committed by md_5
parent 0294fc5f20
commit a7664a5559
6 changed files with 158 additions and 6 deletions

View File

@ -1,5 +1,6 @@
package net.md_5.bungee.protocol; package net.md_5.bungee.protocol;
import net.md_5.bungee.protocol.packet.BossBar;
import net.md_5.bungee.protocol.packet.KeepAlive; import net.md_5.bungee.protocol.packet.KeepAlive;
import net.md_5.bungee.protocol.packet.ClientSettings; import net.md_5.bungee.protocol.packet.ClientSettings;
import net.md_5.bungee.protocol.packet.ClientStatus; import net.md_5.bungee.protocol.packet.ClientStatus;
@ -143,4 +144,8 @@ public abstract class AbstractPacketHandler
public void handle(SetCompression setCompression) throws Exception public void handle(SetCompression setCompression) throws Exception
{ {
} }
public void handle(BossBar bossBar) throws Exception
{
}
} }

View File

@ -12,6 +12,7 @@ import java.util.Arrays;
import java.util.List; import java.util.List;
import lombok.Getter; import lombok.Getter;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import net.md_5.bungee.protocol.packet.BossBar;
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.EncryptionRequest; import net.md_5.bungee.protocol.packet.EncryptionRequest;
@ -58,6 +59,7 @@ public enum Protocol
TO_CLIENT.registerPacket( 0x01, 0x23, Login.class ); TO_CLIENT.registerPacket( 0x01, 0x23, Login.class );
TO_CLIENT.registerPacket( 0x02, 0x0F, Chat.class ); TO_CLIENT.registerPacket( 0x02, 0x0F, Chat.class );
TO_CLIENT.registerPacket( 0x07, 0x33, Respawn.class ); TO_CLIENT.registerPacket( 0x07, 0x33, Respawn.class );
TO_CLIENT.registerPacket( 0x0C, 0x0C, BossBar.class, true );
TO_CLIENT.registerPacket( 0x38, 0x2D, PlayerListItem.class ); // PlayerInfo TO_CLIENT.registerPacket( 0x38, 0x2D, PlayerListItem.class ); // PlayerInfo
TO_CLIENT.registerPacket( 0x3A, 0x0E, TabCompleteResponse.class ); TO_CLIENT.registerPacket( 0x3A, 0x0E, TabCompleteResponse.class );
TO_CLIENT.registerPacket( 0x3B, 0x3F, ScoreboardObjective.class ); TO_CLIENT.registerPacket( 0x3B, 0x3F, ScoreboardObjective.class );
@ -165,6 +167,12 @@ public enum Protocol
} }
protected final void registerPacket(int id, int newId, Class<? extends DefinedPacket> packetClass) protected final void registerPacket(int id, int newId, Class<? extends DefinedPacket> packetClass)
{
registerPacket( id, newId, packetClass, false );
}
protected final void registerPacket(int id, int newId, Class<? extends DefinedPacket> packetClass, boolean newOnly)
{ {
try try
{ {
@ -176,8 +184,12 @@ public enum Protocol
packetClasses[id] = packetClass; packetClasses[id] = packetClass;
packetMap.put( packetClass, id ); packetMap.put( packetClass, id );
if ( !newOnly )
{
packetRemap.get( ProtocolConstants.MINECRAFT_1_8 ).put( id, id ); packetRemap.get( ProtocolConstants.MINECRAFT_1_8 ).put( id, id );
packetRemapInv.get( ProtocolConstants.MINECRAFT_1_8 ).put( id, id ); packetRemapInv.get( ProtocolConstants.MINECRAFT_1_8 ).put( id, id );
}
packetRemap.get( ProtocolConstants.MINECRAFT_1_9 ).put( newId, id ); packetRemap.get( ProtocolConstants.MINECRAFT_1_9 ).put( newId, id );
packetRemapInv.get( ProtocolConstants.MINECRAFT_1_9 ).put( id, newId ); packetRemapInv.get( ProtocolConstants.MINECRAFT_1_9 ).put( id, newId );
} }

View File

@ -0,0 +1,110 @@
package net.md_5.bungee.protocol.packet;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import io.netty.buffer.ByteBuf;
import java.util.UUID;
import net.md_5.bungee.protocol.AbstractPacketHandler;
import net.md_5.bungee.protocol.DefinedPacket;
import net.md_5.bungee.protocol.ProtocolConstants;
@Data
@NoArgsConstructor
@EqualsAndHashCode(callSuper = false)
public class BossBar extends DefinedPacket
{
private UUID uuid;
private int action;
private String title;
private float health;
private int color;
private int division;
private byte flags;
public BossBar(UUID uuid, int action)
{
this.uuid = uuid;
this.action = action;
}
@Override
public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion)
{
uuid = readUUID( buf );
action = readVarInt( buf );
switch ( action )
{
// Add
case 0:
title = readString( buf );
health = buf.readFloat();
color = readVarInt( buf );
division = readVarInt( buf );
flags = buf.readByte();
break;
// Health
case 2:
health = buf.readFloat();
break;
// Title
case 3:
title = readString( buf );
break;
// Style
case 4:
color = readVarInt( buf );
division = readVarInt( buf );
break;
// Flags
case 5:
flags = buf.readByte();
break;
}
}
@Override
public void write(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion)
{
writeUUID( uuid, buf );
writeVarInt( action, buf );
switch ( action )
{
// Add
case 0:
writeString( title, buf );
buf.writeFloat( health );
writeVarInt( color, buf );
writeVarInt( division, buf );
buf.writeByte( flags );
break;
// Health
case 2:
buf.writeFloat( health );
break;
// Title
case 3:
writeString( title, buf );
break;
// Style
case 4:
writeVarInt( color, buf );
writeVarInt( division, buf );
break;
// Flags
case 5:
buf.writeByte( flags );
break;
}
}
@Override
public void handle(AbstractPacketHandler handler) throws Exception
{
handler.handle( this );
}
}

View File

@ -1,13 +1,12 @@
package net.md_5.bungee; package net.md_5.bungee;
import com.google.common.base.Objects;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator; import io.netty.buffer.ByteBufAllocator;
import java.util.List;
import java.util.Queue; import java.util.Queue;
import java.util.Set; import java.util.Set;
import java.util.UUID;
import lombok.Getter; import lombok.Getter;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.ChatColor;
@ -31,7 +30,7 @@ import net.md_5.bungee.netty.HandlerBoss;
import net.md_5.bungee.netty.PacketHandler; import net.md_5.bungee.netty.PacketHandler;
import net.md_5.bungee.protocol.DefinedPacket; import net.md_5.bungee.protocol.DefinedPacket;
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.BossBar;
import net.md_5.bungee.protocol.packet.EncryptionRequest; import net.md_5.bungee.protocol.packet.EncryptionRequest;
import net.md_5.bungee.protocol.packet.Handshake; import net.md_5.bungee.protocol.packet.Handshake;
import net.md_5.bungee.protocol.packet.Kick; import net.md_5.bungee.protocol.packet.Kick;
@ -218,6 +217,13 @@ public class ServerConnector extends PacketHandler
} }
serverScoreboard.clear(); serverScoreboard.clear();
for ( UUID bossbar : user.getSentBossBars() )
{
// Send remove bossbar packet
user.unsafe().sendPacket( new net.md_5.bungee.protocol.packet.BossBar( bossbar, 1 ) );
}
user.getSentBossBars().clear();
user.sendDimensionSwitch(); user.sendDimensionSwitch();
user.setServerEntityId( login.getEntityId() ); user.setServerEntityId( login.getEntityId() );

View File

@ -11,6 +11,7 @@ import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelOption; import io.netty.channel.ChannelOption;
import io.netty.util.internal.PlatformDependent; import io.netty.util.internal.PlatformDependent;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
@ -124,6 +125,8 @@ public final class UserConnection implements ProxiedPlayer
private ClientSettings settings; private ClientSettings settings;
@Getter @Getter
private final Scoreboard serverSentScoreboard = new Scoreboard(); private final Scoreboard serverSentScoreboard = new Scoreboard();
@Getter
private final Collection<UUID> sentBossBars = new HashSet<>();
/*========================================================================*/ /*========================================================================*/
@Getter @Getter
private String displayName; private String displayName;

View File

@ -29,7 +29,7 @@ import net.md_5.bungee.netty.ChannelWrapper;
import net.md_5.bungee.netty.PacketHandler; import net.md_5.bungee.netty.PacketHandler;
import net.md_5.bungee.protocol.DefinedPacket; import net.md_5.bungee.protocol.DefinedPacket;
import net.md_5.bungee.protocol.PacketWrapper; import net.md_5.bungee.protocol.PacketWrapper;
import net.md_5.bungee.protocol.ProtocolConstants; import net.md_5.bungee.protocol.packet.BossBar;
import net.md_5.bungee.protocol.packet.KeepAlive; import net.md_5.bungee.protocol.packet.KeepAlive;
import net.md_5.bungee.protocol.packet.PlayerListItem; import net.md_5.bungee.protocol.packet.PlayerListItem;
import net.md_5.bungee.protocol.packet.ScoreboardObjective; import net.md_5.bungee.protocol.packet.ScoreboardObjective;
@ -484,6 +484,22 @@ public class DownstreamBridge extends PacketHandler
throw CancelSendSignal.INSTANCE; throw CancelSendSignal.INSTANCE;
} }
@Override
public void handle(BossBar bossBar)
{
switch ( bossBar.getAction() )
{
// Handle add bossbar
case 0:
con.getSentBossBars().add( bossBar.getUuid() );
break;
// Handle remove bossbar
case 1:
con.getSentBossBars().remove( bossBar.getUuid() );
break;
}
}
@Override @Override
public String toString() public String toString()
{ {