diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/AbstractPacketHandler.java b/protocol/src/main/java/net/md_5/bungee/protocol/AbstractPacketHandler.java index d292ecd8..6f782c8f 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/AbstractPacketHandler.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/AbstractPacketHandler.java @@ -1,5 +1,6 @@ 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.ClientSettings; 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(BossBar bossBar) throws Exception + { + } } diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/Protocol.java b/protocol/src/main/java/net/md_5/bungee/protocol/Protocol.java index 26cf7c2b..23162561 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/Protocol.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/Protocol.java @@ -12,6 +12,7 @@ import java.util.Arrays; import java.util.List; import lombok.Getter; 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.ClientSettings; 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( 0x02, 0x0F, Chat.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( 0x3A, 0x0E, TabCompleteResponse.class ); TO_CLIENT.registerPacket( 0x3B, 0x3F, ScoreboardObjective.class ); @@ -165,6 +167,12 @@ public enum Protocol } protected final void registerPacket(int id, int newId, Class packetClass) + { + registerPacket( id, newId, packetClass, false ); + + } + + protected final void registerPacket(int id, int newId, Class packetClass, boolean newOnly) { try { @@ -176,8 +184,12 @@ public enum Protocol packetClasses[id] = packetClass; packetMap.put( packetClass, id ); - packetRemap.get( ProtocolConstants.MINECRAFT_1_8 ).put( id, id ); - packetRemapInv.get( ProtocolConstants.MINECRAFT_1_8 ).put( id, id ); + if ( !newOnly ) + { + packetRemap.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 ); packetRemapInv.get( ProtocolConstants.MINECRAFT_1_9 ).put( id, newId ); } diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/BossBar.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/BossBar.java new file mode 100644 index 00000000..6b78765d --- /dev/null +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/BossBar.java @@ -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 ); + } +} diff --git a/proxy/src/main/java/net/md_5/bungee/ServerConnector.java b/proxy/src/main/java/net/md_5/bungee/ServerConnector.java index 71f87793..dd00192c 100644 --- a/proxy/src/main/java/net/md_5/bungee/ServerConnector.java +++ b/proxy/src/main/java/net/md_5/bungee/ServerConnector.java @@ -1,13 +1,12 @@ package net.md_5.bungee; -import com.google.common.base.Objects; import com.google.common.base.Preconditions; import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBufAllocator; -import java.util.List; import java.util.Queue; import java.util.Set; +import java.util.UUID; import lombok.Getter; import lombok.RequiredArgsConstructor; 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.protocol.DefinedPacket; 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.Handshake; import net.md_5.bungee.protocol.packet.Kick; @@ -218,6 +217,13 @@ public class ServerConnector extends PacketHandler } 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.setServerEntityId( login.getEntityId() ); diff --git a/proxy/src/main/java/net/md_5/bungee/UserConnection.java b/proxy/src/main/java/net/md_5/bungee/UserConnection.java index 7139590a..6efd10a5 100644 --- a/proxy/src/main/java/net/md_5/bungee/UserConnection.java +++ b/proxy/src/main/java/net/md_5/bungee/UserConnection.java @@ -11,6 +11,7 @@ import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelOption; import io.netty.util.internal.PlatformDependent; import java.net.InetSocketAddress; +import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.HashSet; @@ -124,6 +125,8 @@ public final class UserConnection implements ProxiedPlayer private ClientSettings settings; @Getter private final Scoreboard serverSentScoreboard = new Scoreboard(); + @Getter + private final Collection sentBossBars = new HashSet<>(); /*========================================================================*/ @Getter private String displayName; diff --git a/proxy/src/main/java/net/md_5/bungee/connection/DownstreamBridge.java b/proxy/src/main/java/net/md_5/bungee/connection/DownstreamBridge.java index 974aeb25..cb9dbaf1 100644 --- a/proxy/src/main/java/net/md_5/bungee/connection/DownstreamBridge.java +++ b/proxy/src/main/java/net/md_5/bungee/connection/DownstreamBridge.java @@ -29,7 +29,7 @@ import net.md_5.bungee.netty.ChannelWrapper; import net.md_5.bungee.netty.PacketHandler; import net.md_5.bungee.protocol.DefinedPacket; 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.PlayerListItem; import net.md_5.bungee.protocol.packet.ScoreboardObjective; @@ -484,6 +484,22 @@ public class DownstreamBridge extends PacketHandler 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 public String toString() {