public variable to enum in PlayerListItemPacket
This commit is contained in:
@@ -4,10 +4,7 @@
|
|||||||
*/
|
*/
|
||||||
package mc.core.network.proto_1_12_2.packets;
|
package mc.core.network.proto_1_12_2.packets;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.*;
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.Setter;
|
|
||||||
import lombok.ToString;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import mc.core.network.NetOutputStream;
|
import mc.core.network.NetOutputStream;
|
||||||
import mc.core.network.SCPacket;
|
import mc.core.network.SCPacket;
|
||||||
@@ -22,11 +19,17 @@ import java.util.*;
|
|||||||
@Setter
|
@Setter
|
||||||
@ToString
|
@ToString
|
||||||
public class PlayerListItemPacket implements SCPacket {
|
public class PlayerListItemPacket implements SCPacket {
|
||||||
public static final int ACTION_ADD_PLAYER = 0,
|
@RequiredArgsConstructor
|
||||||
ACTION_UPDATE_GAMEMODE = 1,
|
public enum Action {
|
||||||
ACTION_UPDATE_LATENCY = 2,
|
ADD_PLAYER(0),
|
||||||
ACTION_UPDATE_DISPLAY_NAME = 3,
|
UPDATE_GAMEMODE(1),
|
||||||
ACTION_REMOVE_PLAYER = 4;
|
UPDATE_LATENCY(2),
|
||||||
|
UPDATE_DISPLAY_NAME(3),
|
||||||
|
REMOVE_PLAYER(4);
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
private final int id;
|
||||||
|
}
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@ToString
|
@ToString
|
||||||
@@ -40,18 +43,18 @@ public class PlayerListItemPacket implements SCPacket {
|
|||||||
private Text displayName;
|
private Text displayName;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int action;
|
private Action action;
|
||||||
private List<PlayerData> listPlayers = new ArrayList<>();
|
private List<PlayerData> listPlayers = new ArrayList<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeSelf(NetOutputStream netStream) {
|
public void writeSelf(NetOutputStream netStream) {
|
||||||
netStream.writeVarInt(action);
|
netStream.writeVarInt(action.id);
|
||||||
netStream.writeVarInt(listPlayers.size());
|
netStream.writeVarInt(listPlayers.size());
|
||||||
|
|
||||||
for (PlayerData playerData : listPlayers) {
|
for (PlayerData playerData : listPlayers) {
|
||||||
netStream.writeUUID(playerData.uuid);
|
netStream.writeUUID(playerData.uuid);
|
||||||
|
|
||||||
if (action == ACTION_ADD_PLAYER) {
|
if (action == Action.ADD_PLAYER) {
|
||||||
netStream.writeString(playerData.name);
|
netStream.writeString(playerData.name);
|
||||||
netStream.writeVarInt(playerData.properties.size());
|
netStream.writeVarInt(playerData.properties.size());
|
||||||
|
|
||||||
@@ -62,15 +65,15 @@ public class PlayerListItemPacket implements SCPacket {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (action == ACTION_ADD_PLAYER || action == ACTION_UPDATE_GAMEMODE) {
|
if (action == Action.ADD_PLAYER || action == Action.UPDATE_GAMEMODE) {
|
||||||
netStream.writeVarInt(playerData.gameMode.getId());
|
netStream.writeVarInt(playerData.gameMode.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (action == ACTION_ADD_PLAYER || action == ACTION_UPDATE_LATENCY) {
|
if (action == Action.ADD_PLAYER || action == Action.UPDATE_LATENCY) {
|
||||||
netStream.writeVarInt(playerData.ping);
|
netStream.writeVarInt(playerData.ping);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (action == ACTION_ADD_PLAYER || action == ACTION_UPDATE_DISPLAY_NAME) {
|
if (action == Action.ADD_PLAYER || action == Action.UPDATE_DISPLAY_NAME) {
|
||||||
netStream.writeBoolean(playerData.hasDisplayName);
|
netStream.writeBoolean(playerData.hasDisplayName);
|
||||||
if (playerData.hasDisplayName) {
|
if (playerData.hasDisplayName) {
|
||||||
netStream.writeString(TextMapper.getInstance().mapping(playerData.displayName));
|
netStream.writeString(TextMapper.getInstance().mapping(playerData.displayName));
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ public class LoginHandler extends AbstractStateHandler implements LoginStateHand
|
|||||||
|
|
||||||
// Send <Tab> items
|
// Send <Tab> items
|
||||||
PlayerListItemPacket pkt5 = new PlayerListItemPacket();
|
PlayerListItemPacket pkt5 = new PlayerListItemPacket();
|
||||||
pkt5.setAction(PlayerListItemPacket.ACTION_ADD_PLAYER);
|
pkt5.setAction(PlayerListItemPacket.Action.ADD_PLAYER);
|
||||||
PlayerListItemPacket.PlayerData playerData = new PlayerListItemPacket.PlayerData();
|
PlayerListItemPacket.PlayerData playerData = new PlayerListItemPacket.PlayerData();
|
||||||
playerData.setUuid(player.getUUID());
|
playerData.setUuid(player.getUUID());
|
||||||
playerData.setName(player.getName());
|
playerData.setName(player.getName());
|
||||||
|
|||||||
Reference in New Issue
Block a user