Ask for the flag directly in PlayerAbilitiesPacket

This commit is contained in:
TheMode 2021-07-27 07:44:06 +02:00
parent de76ac5aad
commit b22d030a6f
2 changed files with 26 additions and 38 deletions

View File

@ -1769,8 +1769,7 @@ public class Player extends LivingEntity implements CommandSender, Localizable,
*
* @return the modifiable statistic map
*/
@NotNull
public Map<PlayerStatistic, Integer> getStatisticValueMap() {
public @NotNull Map<PlayerStatistic, Integer> getStatisticValueMap() {
return statisticValueMap;
}
@ -1779,8 +1778,7 @@ public class Player extends LivingEntity implements CommandSender, Localizable,
*
* @return the player vehicle information
*/
@NotNull
public PlayerVehicleInformation getVehicleInformation() {
public @NotNull PlayerVehicleInformation getVehicleInformation() {
return vehicleInformation;
}
@ -1788,15 +1786,16 @@ public class Player extends LivingEntity implements CommandSender, Localizable,
* Sends to the player a {@link PlayerAbilitiesPacket} with all the updated fields.
*/
protected void refreshAbilities() {
PlayerAbilitiesPacket playerAbilitiesPacket = new PlayerAbilitiesPacket();
playerAbilitiesPacket.invulnerable = invulnerable;
playerAbilitiesPacket.flying = flying;
playerAbilitiesPacket.allowFlying = allowFlying;
playerAbilitiesPacket.instantBreak = instantBreak;
playerAbilitiesPacket.flyingSpeed = flyingSpeed;
playerAbilitiesPacket.fieldViewModifier = fieldViewModifier;
playerConnection.sendPacket(playerAbilitiesPacket);
byte flags = 0;
if (invulnerable)
flags |= 0x01;
if (flying)
flags |= 0x02;
if (allowFlying)
flags |= 0x04;
if (instantBreak)
flags |= 0x08;
playerConnection.sendPacket(new PlayerAbilitiesPacket(flags, flyingSpeed, fieldViewModifier));
}
/**

View File

@ -8,28 +8,22 @@ import org.jetbrains.annotations.NotNull;
public class PlayerAbilitiesPacket implements ServerPacket {
// Flags
public boolean invulnerable;
public boolean flying;
public boolean allowFlying;
public boolean instantBreak;
// Options
public byte flags;
public float flyingSpeed;
public float fieldViewModifier;
public PlayerAbilitiesPacket(byte flags, float flyingSpeed, float fieldViewModifier) {
this.flags = flags;
this.flyingSpeed = flyingSpeed;
this.fieldViewModifier = fieldViewModifier;
}
public PlayerAbilitiesPacket() {
this((byte) 0, 0f, 0f);
}
@Override
public void write(@NotNull BinaryWriter writer) {
byte flags = 0;
if (invulnerable)
flags |= 0x01;
if (flying)
flags |= 0x02;
if (allowFlying)
flags |= 0x04;
if (instantBreak)
flags |= 0x08;
writer.writeByte(flags);
writer.writeFloat(flyingSpeed);
writer.writeFloat(fieldViewModifier);
@ -37,14 +31,9 @@ public class PlayerAbilitiesPacket implements ServerPacket {
@Override
public void read(@NotNull BinaryReader reader) {
byte flags = reader.readByte();
invulnerable = (flags & 1) == 1;
flying = (flags & 2) == 2;
allowFlying = (flags & 4) == 4;
instantBreak = (flags & 8) == 8;
flyingSpeed = reader.readFloat();
fieldViewModifier = reader.readFloat();
this.flags = reader.readByte();
this.flyingSpeed = reader.readFloat();
this.fieldViewModifier = reader.readFloat();
}
@Override