public variable to enum in TitlePacket
This commit is contained in:
@@ -4,6 +4,7 @@
|
|||||||
*/
|
*/
|
||||||
package mc.core.network.proto_1_12_2.packets;
|
package mc.core.network.proto_1_12_2.packets;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
import lombok.ToString;
|
import lombok.ToString;
|
||||||
@@ -18,22 +19,29 @@ import mc.core.text.Text;
|
|||||||
public class TitlePacket implements SCPacket {
|
public class TitlePacket implements SCPacket {
|
||||||
private static final int TICKS_PER_SEC = 20,
|
private static final int TICKS_PER_SEC = 20,
|
||||||
MIN_MS = (1000 / TICKS_PER_SEC);
|
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 Text text = null;
|
||||||
private Integer fadeInTime = null;
|
private Integer fadeInTime = null;
|
||||||
private Integer stayTime = null;
|
private Integer stayTime = null;
|
||||||
private Integer fadeOutTime = null;
|
private Integer fadeOutTime = null;
|
||||||
|
|
||||||
public TitlePacket(int action, Object... values) {
|
public TitlePacket(Action action, Object... values) {
|
||||||
if (values.length == 0 && (action != HIDE && action != RESET)) {
|
if (values.length == 0 && (action != Action.HIDE && action != Action.RESET)) {
|
||||||
this.action = HIDE;
|
this.action = Action.HIDE;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -92,9 +100,9 @@ public class TitlePacket implements SCPacket {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeSelf(NetOutputStream netStream) {
|
public void writeSelf(NetOutputStream netStream) {
|
||||||
netStream.writeVarInt(this.action);
|
netStream.writeVarInt(action.id);
|
||||||
|
|
||||||
switch (this.action) {
|
switch (action) {
|
||||||
case SET_TITLE:
|
case SET_TITLE:
|
||||||
case SET_SUBTITLE:
|
case SET_SUBTITLE:
|
||||||
case SET_ACTION_BAR:
|
case SET_ACTION_BAR:
|
||||||
|
|||||||
@@ -41,26 +41,26 @@ public class WrapperNetChannel implements NetChannel {
|
|||||||
@Override
|
@Override
|
||||||
public void sendTitle(Title title) {
|
public void sendTitle(Title title) {
|
||||||
Text text = title.getTitle();
|
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();
|
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();
|
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 fadeIn = title.getFadeInTime();
|
||||||
Integer stay = title.getStayTime();
|
Integer stay = title.getStayTime();
|
||||||
Integer fadeOut = title.getFadeOutTime();
|
Integer fadeOut = title.getFadeOutTime();
|
||||||
if (fadeIn != null && stay != null && fadeOut != null) {
|
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();
|
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();
|
bool = title.getReset();
|
||||||
if (bool != null && bool) write(new TitlePacket(TitlePacket.RESET));
|
if (bool != null && bool) write(new TitlePacket(TitlePacket.Action.RESET));
|
||||||
|
|
||||||
flush();
|
flush();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user