Archived
0

public variable to enum in BossBarPacket

This commit is contained in:
2018-08-12 19:36:50 +03:00
parent 86f22ffc76
commit d27228d640
2 changed files with 66 additions and 43 deletions

View File

@@ -4,9 +4,7 @@
*/
package mc.core.network.proto_1_12_2.packets;
import lombok.Data;
import lombok.Setter;
import lombok.ToString;
import lombok.*;
import mc.core.network.NetOutputStream;
import mc.core.network.SCPacket;
import mc.core.network.proto_1_12_2.serializers.TextMapper;
@@ -17,33 +15,58 @@ import java.util.UUID;
@Setter
@ToString
public class BossBarPacket implements SCPacket {
public static final int ACTION_ADD = 0,
ACTION_REMOVE = 1,
ACTION_UPDATE_HEALTH = 2,
ACTION_UPDATE_TITLE = 3,
ACTION_UPDATE_STYLE = 4,
ACTION_UPDATE_FLAGS = 5;
@RequiredArgsConstructor
public enum Action {
ADD(0),
REMOVE(1),
UPDATE_HEALTH(2),
UPDATE_TITLE(3),
UPDATE_STYLE(4),
UPDATE_FLAGS(5);
public static final int COLOR_PINK = 0,
COLOR_BLUE = 1,
COLOR_RED = 2,
COLOR_GREEN = 3,
COLOR_YELLOW = 4,
COLOR_PURPLE = 5,
COLOR_WHITE = 6;
@Getter
private final int id;
}
public static final int DIVISION_NO = 0,
DIVISION_0 = DIVISION_NO,
DIVISION_6 = 1,
DIVISION_10 = 2,
DIVISION_12 = 3,
DIVISION_20 = 4;
@RequiredArgsConstructor
public enum Color {
PINK(0),
BLUE(1),
RED(2),
GREEN(3),
YELLOW(4),
PURPLE(5),
WHITE(5);
public static final byte FLAG_NO = 0x00,
FLAG_DAKR_SKY = 0x01,
FLAG_DRAGON_BAR = 0x02;
@Getter
private final int id;
}
@Data
@RequiredArgsConstructor
public enum Division {
NO(0),
_0(0),
_6(1),
_10(2),
_12(3),
_20(4);
@Getter
private final int id;
}
@RequiredArgsConstructor
public enum Flag {
NO(0x00),
DAKR_SKY(0x01),
DRAGON_BAR(0x02);
@Getter
private final int id;
}
@Getter
@Setter
public static class BarData {
private Text title;
/*
@@ -53,39 +76,39 @@ public class BossBarPacket implements SCPacket {
* (https://i.johni0702.de/nA.png)
*/
private float health;
private int color;
private int division;
private byte flags;
private Color color;
private Division division;
private Flag flags;
}
private UUID uuid; // Unique ID for this bar
private int action;
private Action action;
private BarData barData;
@Override
public void writeSelf(NetOutputStream netStream) {
netStream.writeUUID(uuid);
netStream.writeVarInt(action);
netStream.writeVarInt(action.id);
if (action == ACTION_REMOVE) {
if (action == Action.REMOVE) {
return;
}
if (action == ACTION_ADD || action == ACTION_UPDATE_TITLE) {
if (action == Action.ADD || action == Action.UPDATE_TITLE) {
netStream.writeString(TextMapper.getInstance().mapping(barData.title));
}
if (action == ACTION_ADD || action == ACTION_UPDATE_HEALTH) {
if (action == Action.ADD || action == Action.UPDATE_HEALTH) {
netStream.writeFloat(barData.health);
}
if (action == ACTION_ADD || action == ACTION_UPDATE_STYLE) {
netStream.writeVarInt(barData.color);
netStream.writeVarInt(barData.division);
if (action == Action.ADD || action == Action.UPDATE_STYLE) {
netStream.writeVarInt(barData.color.id);
netStream.writeVarInt(barData.division.id);
}
if (action == ACTION_ADD || action == ACTION_UPDATE_FLAGS) {
netStream.writeUnsignedByte(barData.flags);
if (action == Action.ADD || action == Action.UPDATE_FLAGS) {
netStream.writeUnsignedByte(barData.flags.id);
}
}
}