diff --git a/api/src/main/java/net/md_5/bungee/api/scoreboard/Team.java b/api/src/main/java/net/md_5/bungee/api/scoreboard/Team.java index cf63a875..baf5708f 100644 --- a/api/src/main/java/net/md_5/bungee/api/scoreboard/Team.java +++ b/api/src/main/java/net/md_5/bungee/api/scoreboard/Team.java @@ -21,4 +21,14 @@ public class Team { return Collections.unmodifiableSet( players ); } + + public void addPlayer(String name) + { + players.add( name ); + } + + public void removePlayer(String name) + { + players.remove( name ); + } } 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 2faac879..97a1afdb 100644 --- a/proxy/src/main/java/net/md_5/bungee/ServerConnector.java +++ b/proxy/src/main/java/net/md_5/bungee/ServerConnector.java @@ -14,6 +14,7 @@ import net.md_5.bungee.api.event.ServerConnectedEvent; import net.md_5.bungee.api.event.ServerKickEvent; import net.md_5.bungee.api.scoreboard.Objective; import net.md_5.bungee.api.scoreboard.Score; +import net.md_5.bungee.api.scoreboard.Team; import net.md_5.bungee.connection.CancelSendSignal; import net.md_5.bungee.connection.DownstreamBridge; import net.md_5.bungee.netty.HandlerBoss; @@ -23,6 +24,7 @@ import net.md_5.bungee.packet.Packet9Respawn; import net.md_5.bungee.packet.PacketCDClientStatus; import net.md_5.bungee.packet.PacketCEScoreboardObjective; import net.md_5.bungee.packet.PacketCFScoreboardScore; +import net.md_5.bungee.packet.PacketD1Team; import net.md_5.bungee.packet.PacketFAPluginMessage; import net.md_5.bungee.packet.PacketFDEncryptionRequest; import net.md_5.bungee.packet.PacketFFKick; @@ -122,6 +124,10 @@ public class ServerConnector extends PacketHandler { user.ch.write( new PacketCFScoreboardScore( score.getItemName(), (byte) 1, null, 0 ) ); } + for ( Team team : user.serverSentScoreboard.getTeams() ) + { + user.ch.write( PacketD1Team.destroy( team.getName() ) ); + } user.serverSentScoreboard = null; } 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 9b0b4c80..431f78ac 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 @@ -20,6 +20,7 @@ import net.md_5.bungee.api.scoreboard.Objective; import net.md_5.bungee.api.scoreboard.Position; import net.md_5.bungee.api.scoreboard.Score; import net.md_5.bungee.api.scoreboard.Scoreboard; +import net.md_5.bungee.api.scoreboard.Team; import net.md_5.bungee.packet.Packet0KeepAlive; import net.md_5.bungee.packet.Packet3Chat; import net.md_5.bungee.packet.Packet9Respawn; @@ -27,6 +28,7 @@ import net.md_5.bungee.packet.PacketC9PlayerListItem; import net.md_5.bungee.packet.PacketCEScoreboardObjective; import net.md_5.bungee.packet.PacketCFScoreboardScore; import net.md_5.bungee.packet.PacketD0DisplayScoreboard; +import net.md_5.bungee.packet.PacketD1Team; import net.md_5.bungee.packet.PacketFAPluginMessage; import net.md_5.bungee.packet.PacketFFKick; import net.md_5.bungee.packet.PacketHandler; @@ -141,6 +143,43 @@ public class DownstreamBridge extends PacketHandler con.serverSentScoreboard = new Scoreboard( displayScoreboard.name, Position.values()[displayScoreboard.position] ); } + @Override + public void handle(PacketD1Team team) throws Exception + { + if ( con.serverSentScoreboard != null ) + { + // Remove team and move on + if ( team.mode == 1 ) + { + con.serverSentScoreboard.removeTeam( team.name ); + return; + } + + // Create or get old team + Team t = ( team.mode == 0 ) ? new Team( team.name ) : con.serverSentScoreboard.getTeam( team.name ); + if ( t != null ) + { + if ( team.mode == 0 || team.mode == 2 ) + { + t.setDisplayName( team.displayName ); + t.setPrefix( team.prefix ); + t.setSuffix( team.suffix ); + t.setFriendlyMode( team.friendlyFire ); + } + for ( String s : team.players ) + { + if ( team.mode == 0 || team.mode == 3 ) + { + t.addPlayer( s ); + } else + { + t.removePlayer( s ); + } + } + } + } + } + @Override public void handle(PacketFAPluginMessage pluginMessage) throws Exception { diff --git a/proxy/src/main/java/net/md_5/bungee/packet/PacketD1Team.java b/proxy/src/main/java/net/md_5/bungee/packet/PacketD1Team.java index 1417f9f9..28b70e39 100644 --- a/proxy/src/main/java/net/md_5/bungee/packet/PacketD1Team.java +++ b/proxy/src/main/java/net/md_5/bungee/packet/PacketD1Team.java @@ -42,6 +42,19 @@ public class PacketD1Team extends DefinedPacket } } + public PacketD1Team() + { + super( 0xD1 ); + } + + public static PacketD1Team destroy(String name) + { + PacketD1Team packet = new PacketD1Team(); + packet.writeUTF( name ); + packet.writeByte( 1 ); + return packet; + } + @Override public void handle(PacketHandler handler) throws Exception {