@Override public void handle(ScoreboardObjective objective) throws Exception { Scoreboard serverScoreboard = con.getServerSentScoreboard(); switch ( objective.getAction() ) { case 0: serverScoreboard.addObjective( new Objective( objective.getName(), objective.getValue(), objective.getType().toString() ) ); break; case 1: serverScoreboard.removeObjective( objective.getName() ); break; case 2: Objective oldObjective = serverScoreboard.getObjective( objective.getName() ); if ( oldObjective != null ) { oldObjective.setValue( objective.getValue() ); oldObjective.setType( objective.getType().toString() ); } break; default: throw new IllegalArgumentException( "Unknown objective action: " + objective.getAction() ); } }
@Override public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) { name = readString( buf ); action = buf.readByte(); if ( action == 0 || action == 2 ) { value = readString( buf ); if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_13 ) { type = HealthDisplay.values()[readVarInt( buf )]; } else { type = HealthDisplay.fromString( readString( buf ) ); } } }
@Override public void write(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) { writeString( name, buf ); buf.writeByte( action ); if ( action == 0 || action == 2 ) { writeString( value, buf ); if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_13 ) { writeVarInt( type.ordinal(), buf ); } else { writeString( type.toString(), buf ); } } }
for ( Objective objective : serverScoreboard.getObjectives() ) user.unsafe().sendPacket( new ScoreboardObjective( objective.getName(), objective.getValue(), ScoreboardObjective.HealthDisplay.fromString( objective.getType() ), (byte) 1 ) );
@Override public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) { name = readString( buf ); if ( protocolVersion <= ProtocolConstants.MINECRAFT_1_7_6 ) { value = readString( buf ); } action = buf.readByte(); if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_8 && ( action == 0 || action == 2 ) ) { value = readString( buf ); type = readString( buf ); } }
@Override public void write(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) { writeString( name, buf ); if ( protocolVersion <= ProtocolConstants.MINECRAFT_1_7_6 ) { writeString( value, buf ); } buf.writeByte( action ); if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_8 && ( action == 0 || action == 2 ) ) { writeString( value, buf ); writeString( type, buf ); } }
for ( Objective objective : serverScoreboard.getObjectives() ) user.unsafe().sendPacket( new ScoreboardObjective( objective.getName(), objective.getValue(), "integer", (byte) 1 ) ); // TODO:
@Override public void handle(ScoreboardObjective objective) throws Exception { Scoreboard serverScoreboard = con.getServerSentScoreboard(); switch ( objective.getAction() ) { case 0: serverScoreboard.addObjective( new Objective( objective.getName(), objective.getValue(), objective.getType() ) ); break; case 1: serverScoreboard.removeObjective( objective.getName() ); break; case 2: Objective oldObjective = serverScoreboard.getObjective( objective.getName() ); if ( oldObjective != null ) { oldObjective.setValue( objective.getValue() ); } break; default: throw new IllegalArgumentException( "Unknown objective action: " + objective.getAction() ); } }