From 7b61aa7707fb702b38eab2c5725eb879677d205e Mon Sep 17 00:00:00 2001 From: DmitriyMX Date: Sun, 12 Aug 2018 19:42:56 +0300 Subject: [PATCH] public variable to enum in TitlePacket --- .../proto_1_12_2/packets/TitlePacket.java | 32 ++++++++++++------- .../netty/wrappers/WrapperNetChannel.java | 12 +++---- 2 files changed, 26 insertions(+), 18 deletions(-) diff --git a/proto_1.12.2/src/main/java/mc/core/network/proto_1_12_2/packets/TitlePacket.java b/proto_1.12.2/src/main/java/mc/core/network/proto_1_12_2/packets/TitlePacket.java index 26f51d9..9b357a8 100644 --- a/proto_1.12.2/src/main/java/mc/core/network/proto_1_12_2/packets/TitlePacket.java +++ b/proto_1.12.2/src/main/java/mc/core/network/proto_1_12_2/packets/TitlePacket.java @@ -4,6 +4,7 @@ */ package mc.core.network.proto_1_12_2.packets; +import lombok.Getter; import lombok.RequiredArgsConstructor; import lombok.Setter; import lombok.ToString; @@ -18,22 +19,29 @@ import mc.core.text.Text; public class TitlePacket implements SCPacket { private static final int TICKS_PER_SEC = 20, MIN_MS = (1000 / TICKS_PER_SEC); - public static final int SET_TITLE = 0, - SET_SUBTITLE = 1, - SET_ACTION_BAR = 2, - SET_DISPLAY_TIME = 3, - HIDE = 4, - RESET = 5; - private final int action; + @RequiredArgsConstructor + public enum Action { + SET_TITLE(0), + SET_SUBTITLE(1), + SET_ACTION_BAR(2), + SET_DISPLAY_TIME(3), + HIDE(4), + RESET(5); + + @Getter + private final int id; + } + + private final Action action; private Text text = null; private Integer fadeInTime = null; private Integer stayTime = null; private Integer fadeOutTime = null; - public TitlePacket(int action, Object... values) { - if (values.length == 0 && (action != HIDE && action != RESET)) { - this.action = HIDE; + public TitlePacket(Action action, Object... values) { + if (values.length == 0 && (action != Action.HIDE && action != Action.RESET)) { + this.action = Action.HIDE; return; } @@ -92,9 +100,9 @@ public class TitlePacket implements SCPacket { @Override public void writeSelf(NetOutputStream netStream) { - netStream.writeVarInt(this.action); + netStream.writeVarInt(action.id); - switch (this.action) { + switch (action) { case SET_TITLE: case SET_SUBTITLE: case SET_ACTION_BAR: diff --git a/proto_1.12.2_netty/src/main/java/mc/core/network/proto_1_12_2/netty/wrappers/WrapperNetChannel.java b/proto_1.12.2_netty/src/main/java/mc/core/network/proto_1_12_2/netty/wrappers/WrapperNetChannel.java index 50427e8..192edd6 100644 --- a/proto_1.12.2_netty/src/main/java/mc/core/network/proto_1_12_2/netty/wrappers/WrapperNetChannel.java +++ b/proto_1.12.2_netty/src/main/java/mc/core/network/proto_1_12_2/netty/wrappers/WrapperNetChannel.java @@ -41,26 +41,26 @@ public class WrapperNetChannel implements NetChannel { @Override public void sendTitle(Title title) { Text text = title.getTitle(); - if (text != null) write(new TitlePacket(TitlePacket.SET_TITLE, text)); + if (text != null) write(new TitlePacket(TitlePacket.Action.SET_TITLE, text)); text = title.getSubtitle(); - if (text != null) write(new TitlePacket(TitlePacket.SET_SUBTITLE, text)); + if (text != null) write(new TitlePacket(TitlePacket.Action.SET_SUBTITLE, text)); text = title.getTextActionBar(); - if (text != null) write(new TitlePacket(TitlePacket.SET_ACTION_BAR, text)); + if (text != null) write(new TitlePacket(TitlePacket.Action.SET_ACTION_BAR, text)); Integer fadeIn = title.getFadeInTime(); Integer stay = title.getStayTime(); Integer fadeOut = title.getFadeOutTime(); if (fadeIn != null && stay != null && fadeOut != null) { - write(new TitlePacket(TitlePacket.SET_DISPLAY_TIME, fadeIn, stay, fadeOut)); + write(new TitlePacket(TitlePacket.Action.SET_DISPLAY_TIME, fadeIn, stay, fadeOut)); } Boolean bool = title.getHide(); - if (bool != null && bool) write(new TitlePacket(TitlePacket.HIDE)); + if (bool != null && bool) write(new TitlePacket(TitlePacket.Action.HIDE)); bool = title.getReset(); - if (bool != null && bool) write(new TitlePacket(TitlePacket.RESET)); + if (bool != null && bool) write(new TitlePacket(TitlePacket.Action.RESET)); flush(); }