mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-04 23:47:59 +01:00
Ask for the flag directly in PlayerAbilitiesPacket
This commit is contained in:
parent
de76ac5aad
commit
b22d030a6f
@ -1769,8 +1769,7 @@ public class Player extends LivingEntity implements CommandSender, Localizable,
|
|||||||
*
|
*
|
||||||
* @return the modifiable statistic map
|
* @return the modifiable statistic map
|
||||||
*/
|
*/
|
||||||
@NotNull
|
public @NotNull Map<PlayerStatistic, Integer> getStatisticValueMap() {
|
||||||
public Map<PlayerStatistic, Integer> getStatisticValueMap() {
|
|
||||||
return statisticValueMap;
|
return statisticValueMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1779,8 +1778,7 @@ public class Player extends LivingEntity implements CommandSender, Localizable,
|
|||||||
*
|
*
|
||||||
* @return the player vehicle information
|
* @return the player vehicle information
|
||||||
*/
|
*/
|
||||||
@NotNull
|
public @NotNull PlayerVehicleInformation getVehicleInformation() {
|
||||||
public PlayerVehicleInformation getVehicleInformation() {
|
|
||||||
return vehicleInformation;
|
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.
|
* Sends to the player a {@link PlayerAbilitiesPacket} with all the updated fields.
|
||||||
*/
|
*/
|
||||||
protected void refreshAbilities() {
|
protected void refreshAbilities() {
|
||||||
PlayerAbilitiesPacket playerAbilitiesPacket = new PlayerAbilitiesPacket();
|
byte flags = 0;
|
||||||
playerAbilitiesPacket.invulnerable = invulnerable;
|
if (invulnerable)
|
||||||
playerAbilitiesPacket.flying = flying;
|
flags |= 0x01;
|
||||||
playerAbilitiesPacket.allowFlying = allowFlying;
|
if (flying)
|
||||||
playerAbilitiesPacket.instantBreak = instantBreak;
|
flags |= 0x02;
|
||||||
playerAbilitiesPacket.flyingSpeed = flyingSpeed;
|
if (allowFlying)
|
||||||
playerAbilitiesPacket.fieldViewModifier = fieldViewModifier;
|
flags |= 0x04;
|
||||||
|
if (instantBreak)
|
||||||
playerConnection.sendPacket(playerAbilitiesPacket);
|
flags |= 0x08;
|
||||||
|
playerConnection.sendPacket(new PlayerAbilitiesPacket(flags, flyingSpeed, fieldViewModifier));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -8,28 +8,22 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
|
|
||||||
public class PlayerAbilitiesPacket implements ServerPacket {
|
public class PlayerAbilitiesPacket implements ServerPacket {
|
||||||
|
|
||||||
// Flags
|
public byte flags;
|
||||||
public boolean invulnerable;
|
|
||||||
public boolean flying;
|
|
||||||
public boolean allowFlying;
|
|
||||||
public boolean instantBreak;
|
|
||||||
|
|
||||||
// Options
|
|
||||||
public float flyingSpeed;
|
public float flyingSpeed;
|
||||||
public float fieldViewModifier;
|
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
|
@Override
|
||||||
public void write(@NotNull BinaryWriter writer) {
|
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.writeByte(flags);
|
||||||
writer.writeFloat(flyingSpeed);
|
writer.writeFloat(flyingSpeed);
|
||||||
writer.writeFloat(fieldViewModifier);
|
writer.writeFloat(fieldViewModifier);
|
||||||
@ -37,14 +31,9 @@ public class PlayerAbilitiesPacket implements ServerPacket {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void read(@NotNull BinaryReader reader) {
|
public void read(@NotNull BinaryReader reader) {
|
||||||
byte flags = reader.readByte();
|
this.flags = reader.readByte();
|
||||||
invulnerable = (flags & 1) == 1;
|
this.flyingSpeed = reader.readFloat();
|
||||||
flying = (flags & 2) == 2;
|
this.fieldViewModifier = reader.readFloat();
|
||||||
allowFlying = (flags & 4) == 4;
|
|
||||||
instantBreak = (flags & 8) == 8;
|
|
||||||
|
|
||||||
flyingSpeed = reader.readFloat();
|
|
||||||
fieldViewModifier = reader.readFloat();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user