From 3715756be7da8ab62494f2db4c28e8abb01e3e5b Mon Sep 17 00:00:00 2001 From: md_5 Date: Wed, 16 Apr 2014 10:48:40 +1000 Subject: [PATCH] Update packets for MINECRAFT_14_11_a --- .../java/net/md_5/bungee/api/score/Team.java | 2 +- .../net/md_5/bungee/protocol/packet/Chat.java | 1 - .../protocol/packet/ClientSettings.java | 12 ++++---- .../bungee/protocol/packet/KeepAlive.java | 21 ++++++++++--- .../protocol/packet/PlayerListItem.java | 23 ++++++++++---- .../protocol/packet/ScoreboardObjective.java | 30 +++++++++++++++---- .../net/md_5/bungee/protocol/packet/Team.java | 18 +++++++++-- .../java/net/md_5/bungee/ServerConnector.java | 2 +- .../bungee/connection/DownstreamBridge.java | 4 +-- 9 files changed, 84 insertions(+), 29 deletions(-) diff --git a/api/src/main/java/net/md_5/bungee/api/score/Team.java b/api/src/main/java/net/md_5/bungee/api/score/Team.java index 3b9b0c89..6d9193f0 100644 --- a/api/src/main/java/net/md_5/bungee/api/score/Team.java +++ b/api/src/main/java/net/md_5/bungee/api/score/Team.java @@ -16,7 +16,7 @@ public class Team private String displayName; private String prefix; private String suffix; - private boolean friendlyFire; + private byte friendlyFire; private Set players = new HashSet<>(); public Collection getPlayers() diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/Chat.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/Chat.java index 910b2057..8fe3e0b8 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/packet/Chat.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/Chat.java @@ -7,7 +7,6 @@ import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; import net.md_5.bungee.protocol.AbstractPacketHandler; -import net.md_5.bungee.protocol.Protocol; import net.md_5.bungee.protocol.ProtocolConstants; @Data diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/ClientSettings.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/ClientSettings.java index af9c6b67..c73e5fdc 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/packet/ClientSettings.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/ClientSettings.java @@ -19,9 +19,9 @@ public class ClientSettings extends DefinedPacket private String locale; private byte viewDistance; private byte chatFlags; - private boolean unknown; + private boolean chatColours; private byte difficulty; - private byte showCape; + private byte skinParts; @Override public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) @@ -29,12 +29,12 @@ public class ClientSettings extends DefinedPacket locale = readString( buf ); viewDistance = buf.readByte(); chatFlags = buf.readByte(); - unknown = buf.readBoolean(); + chatColours = buf.readBoolean(); if ( protocolVersion <= ProtocolConstants.MINECRAFT_1_7_6 ) { difficulty = buf.readByte(); } - showCape = buf.readByte(); + skinParts = buf.readByte(); } @Override @@ -43,12 +43,12 @@ public class ClientSettings extends DefinedPacket writeString( locale, buf ); buf.writeByte( viewDistance ); buf.writeByte( chatFlags ); - buf.writeBoolean( unknown ); + buf.writeBoolean( chatColours ); if ( protocolVersion <= ProtocolConstants.MINECRAFT_1_7_6 ) { buf.writeByte( difficulty ); } - buf.writeByte( showCape ); + buf.writeByte( skinParts ); } @Override diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/KeepAlive.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/KeepAlive.java index 12065ac4..c9156723 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/packet/KeepAlive.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/KeepAlive.java @@ -7,6 +7,7 @@ import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; import net.md_5.bungee.protocol.AbstractPacketHandler; +import net.md_5.bungee.protocol.ProtocolConstants; @Data @NoArgsConstructor @@ -18,15 +19,27 @@ public class KeepAlive extends DefinedPacket private int randomId; @Override - public void read(ByteBuf buf) + public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) { - randomId = buf.readInt(); + if ( direction == ProtocolConstants.Direction.TO_SERVER && protocolVersion >= ProtocolConstants.MINECRAFT_14_11_a ) + { + randomId = readVarInt( buf ); + } else + { + randomId = buf.readInt(); + } } @Override - public void write(ByteBuf buf) + public void write(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) { - buf.writeInt( randomId ); + if ( direction == ProtocolConstants.Direction.TO_SERVER && protocolVersion >= ProtocolConstants.MINECRAFT_14_11_a ) + { + writeVarInt( randomId, buf ); + } else + { + buf.writeInt( randomId ); + } } @Override diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/PlayerListItem.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/PlayerListItem.java index 9182c1cc..e1770537 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/packet/PlayerListItem.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/PlayerListItem.java @@ -7,6 +7,7 @@ import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; import net.md_5.bungee.protocol.AbstractPacketHandler; +import net.md_5.bungee.protocol.ProtocolConstants; @Data @NoArgsConstructor @@ -17,22 +18,34 @@ public class PlayerListItem extends DefinedPacket private String username; private boolean online; - private short ping; + private int ping; @Override - public void read(ByteBuf buf) + public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) { username = readString( buf ); online = buf.readBoolean(); - ping = buf.readShort(); + if ( protocolVersion >= ProtocolConstants.MINECRAFT_14_11_a ) + { + ping = readVarInt( buf ); + } else + { + ping = buf.readShort(); + } } @Override - public void write(ByteBuf buf) + public void write(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) { writeString( username, buf ); buf.writeBoolean( online ); - buf.writeShort( ping ); + if ( protocolVersion >= ProtocolConstants.MINECRAFT_14_11_a ) + { + writeVarInt( ping, buf ); + } else + { + buf.writeShort( ping ); + } } @Override diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/ScoreboardObjective.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/ScoreboardObjective.java index e2b61e48..1e850e8d 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/packet/ScoreboardObjective.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/ScoreboardObjective.java @@ -7,6 +7,7 @@ import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; import net.md_5.bungee.protocol.AbstractPacketHandler; +import net.md_5.bungee.protocol.ProtocolConstants; @Data @NoArgsConstructor @@ -16,26 +17,43 @@ public class ScoreboardObjective extends DefinedPacket { private String name; - private String text; + private String value; + private String type; /** - * 0 to create, 1 to remove. + * 0 to create, 1 to remove, 2 to update display text. */ private byte action; @Override - public void read(ByteBuf buf) + public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) { name = readString( buf ); - text = readString( buf ); + if ( protocolVersion <= ProtocolConstants.MINECRAFT_1_7_6 ) + { + value = readString( buf ); + } action = buf.readByte(); + if ( protocolVersion >= ProtocolConstants.MINECRAFT_14_11_a && ( action == 0 || action == 2 ) ) + { + value = readString( buf ); + type = readString( buf ); + } } @Override - public void write(ByteBuf buf) + public void write(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) { writeString( name, buf ); - writeString( text, buf ); + if ( protocolVersion <= ProtocolConstants.MINECRAFT_1_7_6 ) + { + writeString( value, buf ); + } buf.writeByte( action ); + if ( protocolVersion >= ProtocolConstants.MINECRAFT_14_11_a && ( action == 0 || action == 2 ) ) + { + writeString( value, buf ); + writeString( type, buf ); + } } @Override diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/Team.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/Team.java index ec1a0d3e..f355419b 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/packet/Team.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/Team.java @@ -24,7 +24,9 @@ public class Team extends DefinedPacket private String displayName; private String prefix; private String suffix; - private boolean friendlyFire; + private String unknown; + private byte unknown2; + private byte friendlyFire; private String[] players; /** @@ -49,7 +51,12 @@ public class Team extends DefinedPacket displayName = readString( buf ); prefix = readString( buf ); suffix = readString( buf ); - friendlyFire = buf.readBoolean(); + friendlyFire = buf.readByte(); + if ( protocolVersion >= ProtocolConstants.MINECRAFT_14_11_a ) + { + unknown = readString( buf ); + unknown2 = buf.readByte(); + } } if ( mode == 0 || mode == 3 || mode == 4 ) { @@ -72,7 +79,12 @@ public class Team extends DefinedPacket writeString( displayName, buf ); writeString( prefix, buf ); writeString( suffix, buf ); - buf.writeBoolean( friendlyFire ); + buf.writeByte( friendlyFire ); + if ( protocolVersion >= ProtocolConstants.MINECRAFT_14_11_a ) + { + writeString( unknown, buf ); + buf.writeByte( unknown2 ); + } } if ( mode == 0 || mode == 3 || mode == 4 ) { 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 ca72ed58..8162d2f4 100644 --- a/proxy/src/main/java/net/md_5/bungee/ServerConnector.java +++ b/proxy/src/main/java/net/md_5/bungee/ServerConnector.java @@ -153,7 +153,7 @@ public class ServerConnector extends PacketHandler Scoreboard serverScoreboard = user.getServerSentScoreboard(); for ( Objective objective : serverScoreboard.getObjectives() ) { - user.unsafe().sendPacket( new ScoreboardObjective( objective.getName(), objective.getValue(), (byte) 1 ) ); + user.unsafe().sendPacket( new ScoreboardObjective( objective.getName(), objective.getValue(), "integer", (byte) 1 ) ); // TODO: } for ( Team team : serverScoreboard.getTeams() ) { 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 cd573bab..30255c05 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 @@ -114,7 +114,7 @@ public class DownstreamBridge extends PacketHandler switch ( objective.getAction() ) { case 0: - serverScoreboard.addObjective( new Objective( objective.getName(), objective.getText() ) ); + serverScoreboard.addObjective( new Objective( objective.getName(), objective.getValue() ) ); break; case 1: serverScoreboard.removeObjective( objective.getName() ); @@ -176,7 +176,7 @@ public class DownstreamBridge extends PacketHandler t.setDisplayName( team.getDisplayName() ); t.setPrefix( team.getPrefix() ); t.setSuffix( team.getSuffix() ); - t.setFriendlyFire( team.isFriendlyFire() ); + t.setFriendlyFire( team.getFriendlyFire() ); } if ( team.getPlayers() != null ) {