From 282a3e07524cec2c8f629d0bd334ead916aaccc5 Mon Sep 17 00:00:00 2001 From: Julian <53055251+NoJokeFNA@users.noreply.github.com> Date: Sun, 19 Jun 2022 18:12:47 +0200 Subject: [PATCH] change: unexposed enum values and added `getById` methods --- .../protocol/world/states/enums/Mirror.java | 6 +++++- .../protocol/world/states/enums/Mode.java | 6 +++++- .../protocol/world/states/enums/Rotation.java | 6 +++++- .../WrapperPlayClientUpdateStructureBlock.java | 14 +++++++++----- 4 files changed, 24 insertions(+), 8 deletions(-) diff --git a/api/src/main/java/com/github/retrooper/packetevents/protocol/world/states/enums/Mirror.java b/api/src/main/java/com/github/retrooper/packetevents/protocol/world/states/enums/Mirror.java index 4bb85e345e..410560d251 100644 --- a/api/src/main/java/com/github/retrooper/packetevents/protocol/world/states/enums/Mirror.java +++ b/api/src/main/java/com/github/retrooper/packetevents/protocol/world/states/enums/Mirror.java @@ -23,5 +23,9 @@ public enum Mirror { LEFT_RIGHT, FRONT_BACK; - public static final Mirror[] VALUES = values(); + private static final Mirror[] VALUES = values(); + + public static Mirror getById(int index) { + return VALUES[index]; + } } diff --git a/api/src/main/java/com/github/retrooper/packetevents/protocol/world/states/enums/Mode.java b/api/src/main/java/com/github/retrooper/packetevents/protocol/world/states/enums/Mode.java index bbd3fa12ec..a2bab25f7d 100644 --- a/api/src/main/java/com/github/retrooper/packetevents/protocol/world/states/enums/Mode.java +++ b/api/src/main/java/com/github/retrooper/packetevents/protocol/world/states/enums/Mode.java @@ -26,5 +26,9 @@ public enum Mode { COMPARE, SUBTRACT; - public static final Mode[] VALUES = values(); + private static final Mode[] VALUES = values(); + + public static Mode getById(int index) { + return VALUES[index]; + } } diff --git a/api/src/main/java/com/github/retrooper/packetevents/protocol/world/states/enums/Rotation.java b/api/src/main/java/com/github/retrooper/packetevents/protocol/world/states/enums/Rotation.java index 0a724b2051..c5bd77738e 100644 --- a/api/src/main/java/com/github/retrooper/packetevents/protocol/world/states/enums/Rotation.java +++ b/api/src/main/java/com/github/retrooper/packetevents/protocol/world/states/enums/Rotation.java @@ -24,5 +24,9 @@ public enum Rotation { CLOCKWISE_180, COUNTERCLOCKWISE_90; - public static final Rotation[] VALUES = values(); + private static final Rotation[] VALUES = values(); + + public static Rotation getById(int index) { + return VALUES[index]; + } } diff --git a/api/src/main/java/com/github/retrooper/packetevents/wrapper/play/client/WrapperPlayClientUpdateStructureBlock.java b/api/src/main/java/com/github/retrooper/packetevents/wrapper/play/client/WrapperPlayClientUpdateStructureBlock.java index c86a3d774b..02a97ed1bb 100644 --- a/api/src/main/java/com/github/retrooper/packetevents/wrapper/play/client/WrapperPlayClientUpdateStructureBlock.java +++ b/api/src/main/java/com/github/retrooper/packetevents/wrapper/play/client/WrapperPlayClientUpdateStructureBlock.java @@ -123,8 +123,8 @@ public void read() { int z = readInt(); this.position = new Vector3i(x, y, z); } - this.action = Action.VALUES[readVarInt()]; - this.mode = Mode.VALUES[readVarInt()]; + this.action = Action.getById(readVarInt()); + this.mode = Mode.getById(readVarInt()); this.name = readString(); this.offsetX = readByte(); this.offsetY = readByte(); @@ -132,8 +132,8 @@ public void read() { this.sizeX = readByte(); this.sizeY = readByte(); this.sizeZ = readByte(); - this.mirror = Mirror.VALUES[readVarInt()]; - this.rotation = Rotation.VALUES[readVarInt()]; + this.mirror = Mirror.getById(readVarInt()); + this.rotation = Rotation.getById(readVarInt()); this.metadata = readString(); if (serverVersion.isNewerThanOrEquals(ServerVersion.V_1_10)) { this.integrity = readFloat(); @@ -368,6 +368,10 @@ public enum Action { LOAD_THE_STRUCTURE, DETECT_SIZE; - public static final Action[] VALUES = values(); + private static final Action[] VALUES = values(); + + public static Action getById(int index) { + return VALUES[index]; + } } }