From a6c6944e56a4a01e802cfa9076cca4bc261980bc Mon Sep 17 00:00:00 2001 From: MrGazdag <44264503+MrGazdag@users.noreply.github.com> Date: Tue, 27 Jul 2021 11:56:51 +0200 Subject: [PATCH 1/4] Update PlayerAbilitiesPacket --- .../server/play/PlayerAbilitiesPacket.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/main/java/net/minestom/server/network/packet/server/play/PlayerAbilitiesPacket.java b/src/main/java/net/minestom/server/network/packet/server/play/PlayerAbilitiesPacket.java index 23b2d278e..92e527643 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/PlayerAbilitiesPacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/PlayerAbilitiesPacket.java @@ -7,6 +7,10 @@ import net.minestom.server.utils.binary.BinaryWriter; import org.jetbrains.annotations.NotNull; public class PlayerAbilitiesPacket implements ServerPacket { + public static final byte FLAG_INVULNERABLE = 0x01; + public static final byte FLAG_FLYING = 0x02; + public static final byte FLAG_ALLOW_FLYING = 0x04; + public static final byte FLAG_INSTANT_BREAK = 0x08; public byte flags; public float flyingSpeed; @@ -21,6 +25,30 @@ public class PlayerAbilitiesPacket implements ServerPacket { public PlayerAbilitiesPacket() { this((byte) 0, 0f, 0f); } + + /** + * Adds a flag to the 'flags' byte. + * + * @see PlayerAbilitiesPacket#FLAG_INVULNERABLE + * @see PlayerAbilitiesPacket#FLAG_FLYING + * @see PlayerAbilitiesPacket#FLAG_ALLOW_FLYING + * @see PlayerAbilitiesPacket#FLAG_INSTANT_BREAK + */ + public void addFlag(byte flag) { + flags |= flag; + } + + /** + * Removes a flag from the 'flags' byte. + * + * @see PlayerAbilitiesPacket#FLAG_INVULNERABLE + * @see PlayerAbilitiesPacket#FLAG_FLYING + * @see PlayerAbilitiesPacket#FLAG_ALLOW_FLYING + * @see PlayerAbilitiesPacket#FLAG_INSTANT_BREAK + */ + public void removeFlag(byte flag) { + flags &= ~(flag); + } @Override public void write(@NotNull BinaryWriter writer) { From 5b1e06de040067656db27ca4abdd5b492aebb820 Mon Sep 17 00:00:00 2001 From: MrGazdag <44264503+MrGazdag@users.noreply.github.com> Date: Tue, 27 Jul 2021 12:08:13 +0200 Subject: [PATCH 2/4] use static fields in Player --- src/main/java/net/minestom/server/entity/Player.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/net/minestom/server/entity/Player.java b/src/main/java/net/minestom/server/entity/Player.java index 2bd400e02..d0350d542 100644 --- a/src/main/java/net/minestom/server/entity/Player.java +++ b/src/main/java/net/minestom/server/entity/Player.java @@ -1787,13 +1787,13 @@ public class Player extends LivingEntity implements CommandSender, Localizable, protected void refreshAbilities() { byte flags = 0; if (invulnerable) - flags |= 0x01; + flags |= PlayerAbilitiesPacket.FLAG_INVULNERABLE; if (flying) - flags |= 0x02; + flags |= PlayerAbilitiesPacket.FLAG_FLYING; if (allowFlying) - flags |= 0x04; + flags |= PlayerAbilitiesPacket.FLAG_ALLOW_FLYING; if (instantBreak) - flags |= 0x08; + flags |= PlayerAbilitiesPacket.FLAG_INSTANT_BREAK; playerConnection.sendPacket(new PlayerAbilitiesPacket(flags, flyingSpeed, fieldViewModifier)); } From a20fb32ef529f44e8e094c9df2e3393ff9a74c69 Mon Sep 17 00:00:00 2001 From: MrGazdag <44264503+MrGazdag@users.noreply.github.com> Date: Tue, 27 Jul 2021 12:11:30 +0200 Subject: [PATCH 3/4] fix documentation and add hasFlag --- .../server/play/PlayerAbilitiesPacket.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/main/java/net/minestom/server/network/packet/server/play/PlayerAbilitiesPacket.java b/src/main/java/net/minestom/server/network/packet/server/play/PlayerAbilitiesPacket.java index 92e527643..8e90f300f 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/PlayerAbilitiesPacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/PlayerAbilitiesPacket.java @@ -29,6 +29,8 @@ public class PlayerAbilitiesPacket implements ServerPacket { /** * Adds a flag to the 'flags' byte. * + * @param flag the flag + * * @see PlayerAbilitiesPacket#FLAG_INVULNERABLE * @see PlayerAbilitiesPacket#FLAG_FLYING * @see PlayerAbilitiesPacket#FLAG_ALLOW_FLYING @@ -41,6 +43,8 @@ public class PlayerAbilitiesPacket implements ServerPacket { /** * Removes a flag from the 'flags' byte. * + * @param flag the flag + * * @see PlayerAbilitiesPacket#FLAG_INVULNERABLE * @see PlayerAbilitiesPacket#FLAG_FLYING * @see PlayerAbilitiesPacket#FLAG_ALLOW_FLYING @@ -49,6 +53,19 @@ public class PlayerAbilitiesPacket implements ServerPacket { public void removeFlag(byte flag) { flags &= ~(flag); } + + /** + * @param flag the flag + * @returns true if the 'flags' byte contains the specified flag + * + * @see PlayerAbilitiesPacket#FLAG_INVULNERABLE + * @see PlayerAbilitiesPacket#FLAG_FLYING + * @see PlayerAbilitiesPacket#FLAG_ALLOW_FLYING + * @see PlayerAbilitiesPacket#FLAG_INSTANT_BREAK + */ + public boolean hasFlag(byte flag) { + return (flags & flag) > 0; + } @Override public void write(@NotNull BinaryWriter writer) { From d3cacb0f254311b2ecfb3f9be157ff7dcfb018fe Mon Sep 17 00:00:00 2001 From: MrGazdag <44264503+MrGazdag@users.noreply.github.com> Date: Tue, 27 Jul 2021 12:24:25 +0200 Subject: [PATCH 4/4] remove methods --- .../server/play/PlayerAbilitiesPacket.java | 41 ------------------- 1 file changed, 41 deletions(-) diff --git a/src/main/java/net/minestom/server/network/packet/server/play/PlayerAbilitiesPacket.java b/src/main/java/net/minestom/server/network/packet/server/play/PlayerAbilitiesPacket.java index 8e90f300f..4035c86ad 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/PlayerAbilitiesPacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/PlayerAbilitiesPacket.java @@ -25,47 +25,6 @@ public class PlayerAbilitiesPacket implements ServerPacket { public PlayerAbilitiesPacket() { this((byte) 0, 0f, 0f); } - - /** - * Adds a flag to the 'flags' byte. - * - * @param flag the flag - * - * @see PlayerAbilitiesPacket#FLAG_INVULNERABLE - * @see PlayerAbilitiesPacket#FLAG_FLYING - * @see PlayerAbilitiesPacket#FLAG_ALLOW_FLYING - * @see PlayerAbilitiesPacket#FLAG_INSTANT_BREAK - */ - public void addFlag(byte flag) { - flags |= flag; - } - - /** - * Removes a flag from the 'flags' byte. - * - * @param flag the flag - * - * @see PlayerAbilitiesPacket#FLAG_INVULNERABLE - * @see PlayerAbilitiesPacket#FLAG_FLYING - * @see PlayerAbilitiesPacket#FLAG_ALLOW_FLYING - * @see PlayerAbilitiesPacket#FLAG_INSTANT_BREAK - */ - public void removeFlag(byte flag) { - flags &= ~(flag); - } - - /** - * @param flag the flag - * @returns true if the 'flags' byte contains the specified flag - * - * @see PlayerAbilitiesPacket#FLAG_INVULNERABLE - * @see PlayerAbilitiesPacket#FLAG_FLYING - * @see PlayerAbilitiesPacket#FLAG_ALLOW_FLYING - * @see PlayerAbilitiesPacket#FLAG_INSTANT_BREAK - */ - public boolean hasFlag(byte flag) { - return (flags & flag) > 0; - } @Override public void write(@NotNull BinaryWriter writer) {