Compare commits
5 Commits
dev/scoreb
...
dev/tablis
| Author | SHA1 | Date | |
|---|---|---|---|
|
47ccc3252a
|
|||
|
0d72a8a29c
|
|||
|
c6669af651
|
|||
|
3984ab3fca
|
|||
|
bc2d5a7e75
|
@@ -50,20 +50,19 @@ public enum State {
|
||||
0x0B, PingPacket.class,
|
||||
0x0D, PlayerPositionPacket.class,
|
||||
0x0E, CPlayerPositionAndLookPacket.class,
|
||||
0x0F, PlayerLookPacket.class
|
||||
0x0F, PlayerLookPacket.class,
|
||||
0x15, EntityActionPacket.class
|
||||
),
|
||||
// client bound
|
||||
Map.of(
|
||||
PingPacket.class, 0x1F,
|
||||
JoinGamePacket.class, 0x23,
|
||||
ScoreboardDisplayPacket.class, 0x3B,
|
||||
ScoreboardObjectivePacket.class, 0x42,
|
||||
TeamsPacket.class, 0x44,
|
||||
ScoreboardUpdateScorePacket.class, 0x45,
|
||||
SpawnPositionPacket.class, 0x46,
|
||||
ChunkDataPacket.class, 0x20,
|
||||
JoinGamePacket.class, 0x23,
|
||||
PlayerAbilitiesPacket.class,0x2C,
|
||||
SPlayerPositionAndLookPacket.class, 0x2F
|
||||
PlayerListItemPacket.class,0x2E,
|
||||
SPlayerPositionAndLookPacket.class, 0x2F,
|
||||
SpawnPositionPacket.class, 0x46,
|
||||
PlayerListHeaderAndFooterPacket.class,0x4A
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
@@ -99,11 +99,6 @@ public class NetByteBuf extends ByteBuf {
|
||||
}
|
||||
|
||||
public void writeString(String string) {
|
||||
if (string == null) {
|
||||
writeVarInt(0);
|
||||
return;
|
||||
}
|
||||
|
||||
byte[] buf = string.getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
if (buf.length > Short.MAX_VALUE) {
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
package mc.protocol.packets.client;
|
||||
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.ToString;
|
||||
import mc.protocol.io.NetByteBuf;
|
||||
import mc.protocol.packets.ClientSidePacket;
|
||||
import mc.protocol.utils.EntityActionAction;
|
||||
|
||||
/**
|
||||
* Entity Action packet.
|
||||
*
|
||||
* <p>Структура пакета</p>
|
||||
* <pre>
|
||||
* | FIELD | TYPE | NOTES |
|
||||
* |------------|--------|-------------------------------------------|
|
||||
* | Entity ID | VarInt | ID игрока |
|
||||
* | Action ID | VarInt | ID действия |
|
||||
* | Jump Boost | VarInt | Используется только при "Action ID" = 5. |
|
||||
* | | | В этом случае значение будет от 0 до 100. |
|
||||
* | | | В остальных случаях значение 0. |
|
||||
* </pre>
|
||||
*
|
||||
* @see <a href="https://wiki.vg/index.php?title=Protocol&oldid=14204#Entity_Action" target="_top">Entity Action</a>
|
||||
*/
|
||||
@NoArgsConstructor
|
||||
@Getter
|
||||
@EqualsAndHashCode
|
||||
@ToString
|
||||
public class EntityActionPacket implements ClientSidePacket {
|
||||
|
||||
private Integer entityId;
|
||||
private EntityActionAction action;
|
||||
private Integer jumpBoost;
|
||||
|
||||
@Override
|
||||
public void readSelf(NetByteBuf netByteBuf) {
|
||||
this.entityId = netByteBuf.readVarInt();
|
||||
int actionId = netByteBuf.readVarInt();
|
||||
this.jumpBoost = netByteBuf.readVarInt();
|
||||
|
||||
this.action = EntityActionAction.valueOfCode(actionId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void passivate() {
|
||||
this.entityId = null;
|
||||
this.action = null;
|
||||
this.jumpBoost = null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package mc.protocol.packets.server;
|
||||
|
||||
import lombok.Data;
|
||||
import mc.protocol.io.NetByteBuf;
|
||||
import mc.protocol.model.text.Text;
|
||||
import mc.protocol.packets.ServerSidePacket;
|
||||
import mc.protocol.serializer.TextSerializer;
|
||||
|
||||
/**
|
||||
* Установка текста для "шапки" и "подвала" Tab-листа.
|
||||
*
|
||||
* <p>Структура пакета</p>
|
||||
* <pre>
|
||||
* | FIELD | TYPE | NOTES |
|
||||
* |--------|------|-------|
|
||||
* | Header | Text | |
|
||||
* | Footer | Text | |
|
||||
* </pre>
|
||||
*
|
||||
* <p>Для удаления "шапки" и/или "подвала", нужно отправить следующий {@link Text} компонент:</p>
|
||||
* <pre>
|
||||
* {"translate":""}
|
||||
* </pre>
|
||||
*
|
||||
* @see <a href="https://wiki.vg/index.php?title=Protocol&oldid=14204#Player_List_Header_And_Footer">Player List Header And Footer</a>
|
||||
* @see PlayerListItemPacket
|
||||
*/
|
||||
@Data
|
||||
public class PlayerListHeaderAndFooterPacket implements ServerSidePacket {
|
||||
|
||||
private static final String REMOVE_COMPONENT = "{\"translate\":\"\"}";
|
||||
|
||||
private Text header;
|
||||
private Text foother;
|
||||
|
||||
@Override
|
||||
public void writeSelf(NetByteBuf netByteBuf) {
|
||||
if (this.header == null) {
|
||||
netByteBuf.writeString(REMOVE_COMPONENT);
|
||||
} else {
|
||||
netByteBuf.writeString(TextSerializer.toJsonObject(this.header).toString());
|
||||
}
|
||||
|
||||
if (this.foother == null) {
|
||||
netByteBuf.writeString(REMOVE_COMPONENT);
|
||||
} else {
|
||||
netByteBuf.writeString(TextSerializer.toJsonObject(this.foother).toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,172 @@
|
||||
package mc.protocol.packets.server;
|
||||
|
||||
import lombok.*;
|
||||
import mc.protocol.io.NetByteBuf;
|
||||
import mc.protocol.packets.ServerSidePacket;
|
||||
import mc.protocol.utils.GameMode;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
/**
|
||||
* Player List Item packet.
|
||||
*
|
||||
* <p>Обновление списка игроков, по кнопке TAB.</p>
|
||||
*
|
||||
* <p>Структура пакета</p>
|
||||
* <pre>
|
||||
* | FIELD | TYPE | NOTES |
|
||||
* |-------------------|-------------|-------------------------------------------------|
|
||||
* | Action | VarInt | Определяет поля для секции "Player" |
|
||||
* | Number of players | VarInt | Количество элементов в секции "Players" |
|
||||
* | Players | Array | Перечисление полей для каждого игрока (player). |
|
||||
* | | | Поля определяются по "Action" |
|
||||
* </pre>
|
||||
*
|
||||
* <p>Варианты "Action"</p>
|
||||
* <pre>
|
||||
* | ACTION | PLAYER FIELD | TYPE | NOTES |
|
||||
* | VALUE | DESCRIPTION | | | |
|
||||
* |-------|---------------------|----------------------|-------------|----------------------------------------------------|
|
||||
* | 0 | add player | UUID | UUID | |
|
||||
* | | | Name | String (16) | |
|
||||
* | | | Number Of Properties | VarInt | Количество элементов "Properties" |
|
||||
* | | | Properties | - | см. поля ниже |
|
||||
* | | | Gamemode | VarInt | |
|
||||
* | | | Ping | VarInt | в милисекундах |
|
||||
* | | | Has Display Name | Boolean | |
|
||||
* | | | Display Name | Text | Опционально. Только если "Has Display Name" = true |
|
||||
* | 1 | update gamemode | UUID | UUID | |
|
||||
* | | | Gamemode | VarInt | |
|
||||
* | 2 | update latency | UUID | UUID | |
|
||||
* | | | Ping | VarInt | (см. выше) |
|
||||
* | 3 | update display name | UUID | UUID | |
|
||||
* | | | Has Display Name | Boolean | |
|
||||
* | | | Display Name | Text | (см. выше) |
|
||||
* | 4 | remove player | UUID | UUID | |
|
||||
* </pre>
|
||||
*
|
||||
* <p>Поля секции "Properties"</p>
|
||||
* <pre>
|
||||
* | FIELD | TYPE | NOTES |
|
||||
* |-----------|------------- |---------------------------------------------|
|
||||
* | Name | String (32767) | |
|
||||
* | Value | String (32767) | |
|
||||
* | Is Signed | Boolean | |
|
||||
* | Signature | String (32767) | Опционально. Только если "Is Signed" = true |
|
||||
* </pre>
|
||||
*
|
||||
* @see <a href="https://wiki.vg/index.php?title=Protocol&oldid=14204#Player_List_Item">Player List Item</a>
|
||||
* @see PlayerListHeaderAndFooterPacket
|
||||
*/
|
||||
@Data
|
||||
public class PlayerListItemPacket implements ServerSidePacket {
|
||||
|
||||
private final List<PlayerItem> playerItems = new ArrayList<>();
|
||||
|
||||
private Action action;
|
||||
|
||||
@Override
|
||||
public void writeSelf(NetByteBuf netByteBuf) {
|
||||
netByteBuf.writeVarInt(this.action.getCode());
|
||||
netByteBuf.writeVarInt(playerItems.size());
|
||||
|
||||
BiConsumer<NetByteBuf, PlayerItem> consumer = null;
|
||||
switch (this.action) {
|
||||
//@formatter:off
|
||||
case ADD_PLAYER: consumer = this::addPlayer; break;
|
||||
case UPDATE_GAMEMODE: consumer = this::updateGamemode; break;
|
||||
case UPDATE_LATENCY: consumer = this::updateLatency; break;
|
||||
case UPDATE_DISPLAY_NAME: consumer = this::updateDisplayName; break;
|
||||
case REMOVE_PLAYER: consumer = this::removePlayer; break;
|
||||
//@formatter:on
|
||||
}
|
||||
|
||||
Objects.requireNonNull(consumer);
|
||||
|
||||
for (PlayerItem playerItem : playerItems) {
|
||||
consumer.accept(netByteBuf, playerItem);
|
||||
}
|
||||
}
|
||||
|
||||
private void addPlayer(NetByteBuf netByteBuf, PlayerItem playerItem) {
|
||||
netByteBuf.writeUUID(playerItem.getUuid());
|
||||
netByteBuf.writeString(playerItem.getName());
|
||||
netByteBuf.writeVarInt(playerItem.getProperties().size());
|
||||
|
||||
for (PlayerProperties property : playerItem.getProperties()) {
|
||||
netByteBuf.writeString(property.getName());
|
||||
netByteBuf.writeString(property.getValue());
|
||||
netByteBuf.writeBoolean(property.getIsSigned());
|
||||
if (property.getIsSigned()) {
|
||||
netByteBuf.writeString(property.getSignature());
|
||||
}
|
||||
}
|
||||
|
||||
netByteBuf.writeVarInt(playerItem.getGamemode().getId());
|
||||
netByteBuf.writeVarInt(playerItem.getPing());
|
||||
netByteBuf.writeBoolean(playerItem.getHasDisplayName());
|
||||
if (playerItem.getHasDisplayName()) {
|
||||
netByteBuf.writeString(playerItem.getDisplayName());
|
||||
}
|
||||
}
|
||||
|
||||
private void updateGamemode(NetByteBuf netByteBuf, PlayerItem playerItem) {
|
||||
netByteBuf.writeUUID(playerItem.getUuid());
|
||||
netByteBuf.writeVarInt(playerItem.getGamemode().getId());
|
||||
}
|
||||
|
||||
private void updateLatency(NetByteBuf netByteBuf, PlayerItem playerItem) {
|
||||
netByteBuf.writeUUID(playerItem.getUuid());
|
||||
netByteBuf.writeVarInt(playerItem.getPing());
|
||||
}
|
||||
|
||||
private void updateDisplayName(NetByteBuf netByteBuf, PlayerItem playerItem) {
|
||||
netByteBuf.writeUUID(playerItem.getUuid());
|
||||
netByteBuf.writeBoolean(playerItem.getHasDisplayName());
|
||||
if (playerItem.getHasDisplayName()) {
|
||||
netByteBuf.writeString(playerItem.getDisplayName());
|
||||
}
|
||||
}
|
||||
|
||||
private void removePlayer(NetByteBuf netByteBuf, PlayerItem playerItem) {
|
||||
netByteBuf.writeUUID(playerItem.getUuid());
|
||||
}
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public enum Action {
|
||||
ADD_PLAYER(0),
|
||||
UPDATE_GAMEMODE(1),
|
||||
UPDATE_LATENCY(2),
|
||||
UPDATE_DISPLAY_NAME(3),
|
||||
REMOVE_PLAYER(4);
|
||||
|
||||
@Getter
|
||||
private final int code;
|
||||
}
|
||||
|
||||
@Builder(builderClassName = "Builder")
|
||||
@Value
|
||||
public static class PlayerItem {
|
||||
List<PlayerProperties> properties = new ArrayList<>();
|
||||
|
||||
UUID uuid;
|
||||
String name;
|
||||
GameMode gamemode;
|
||||
Integer ping;
|
||||
Boolean hasDisplayName;
|
||||
String displayName;
|
||||
}
|
||||
|
||||
@Builder(builderClassName = "Builder")
|
||||
@Value
|
||||
public static class PlayerProperties {
|
||||
String name;
|
||||
String value;
|
||||
Boolean isSigned;
|
||||
String signature;
|
||||
}
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
package mc.protocol.packets.server;
|
||||
|
||||
import lombok.Data;
|
||||
import mc.protocol.io.NetByteBuf;
|
||||
import mc.protocol.packets.ServerSidePacket;
|
||||
|
||||
/**
|
||||
* Отображение Scoreboard.
|
||||
*
|
||||
* <p>Структура пакета</p>
|
||||
* <pre>
|
||||
* | FIELD | TYPE | NOTES |
|
||||
* |------------|-------------|--------------------------------|
|
||||
* | Position | Byte | Положение: |
|
||||
* | | | 0 - list |
|
||||
* | | | 1 - sidebar |
|
||||
* | | | 2 - below name |
|
||||
* | | | 3-18 - team specific sidebar |
|
||||
* | Score Name | String (16) | Уникальное название Scoreboard |
|
||||
* </pre>
|
||||
*
|
||||
* @see <a href="https://wiki.vg/index.php?title=Protocol&oldid=14204#Display_Scoreboard" target="_top">Display Scoreboard</a>
|
||||
*/
|
||||
@Data
|
||||
public class ScoreboardDisplayPacket implements ServerSidePacket {
|
||||
|
||||
private int position;
|
||||
private String scoreName;
|
||||
|
||||
public void setPosition(int position) {
|
||||
this.position = (position < 0) ? 0 : (Math.min(position, 18));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeSelf(NetByteBuf netByteBuf) {
|
||||
netByteBuf.writeByte(this.position);
|
||||
netByteBuf.writeString(this.scoreName);
|
||||
}
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
package mc.protocol.packets.server;
|
||||
|
||||
import lombok.Data;
|
||||
import mc.protocol.io.NetByteBuf;
|
||||
import mc.protocol.packets.ServerSidePacket;
|
||||
import mc.protocol.utils.ScoreboardObjectiveMode;
|
||||
import mc.protocol.utils.ScoreboardObjectiveType;
|
||||
|
||||
/**
|
||||
* Scoreboard objective packet.
|
||||
*
|
||||
* <p>Структура пакета</p>
|
||||
* <pre>
|
||||
* | FIELD | TYPE | NOTES |
|
||||
* |-----------------|-------------|---------------------------------------------------|
|
||||
* | Objective Name | String (16) | Уникальное наименование цели (objective) |
|
||||
* | Mode | Byte | 0 - создание Scoreboard |
|
||||
* | | | 1 - удаление Scoreboard |
|
||||
* | | | 2 - обновление Scoreboard |
|
||||
* | Objective Value | String (32) | Если "Mode" равен 0 или 2. Отображаемый текст |
|
||||
* | Type | String (16) | Если "Mode" равен 0 или 2. "integer" или "hearts" |
|
||||
* </pre>
|
||||
*
|
||||
* @see <a href="https://wiki.vg/index.php?title=Protocol&oldid=14204#Scoreboard_Objective" target="_top">Scoreboard Objective</a>
|
||||
*/
|
||||
@Data
|
||||
public class ScoreboardObjectivePacket implements ServerSidePacket {
|
||||
|
||||
private String objectiveName;
|
||||
private ScoreboardObjectiveMode mode;
|
||||
private String objectiveValue;
|
||||
private ScoreboardObjectiveType type;
|
||||
|
||||
@Override
|
||||
public void writeSelf(NetByteBuf netByteBuf) {
|
||||
netByteBuf.writeString(this.objectiveName);
|
||||
netByteBuf.writeByte(this.mode.getCode());
|
||||
|
||||
if (ScoreboardObjectiveMode.CREATE.equals(this.mode) || ScoreboardObjectiveMode.UPDATE.equals(this.mode)) {
|
||||
netByteBuf.writeString(this.objectiveValue);
|
||||
netByteBuf.writeString(this.type.name().toLowerCase());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
package mc.protocol.packets.server;
|
||||
|
||||
import lombok.Data;
|
||||
import mc.protocol.io.NetByteBuf;
|
||||
import mc.protocol.packets.ServerSidePacket;
|
||||
import mc.protocol.utils.ScoreboardUpdateScoreAction;
|
||||
|
||||
/**
|
||||
* Update score packet.
|
||||
*
|
||||
* <p>Структура пакета</p>
|
||||
* <pre>
|
||||
* | FIELD | TYPE | NOTES |
|
||||
* |-----------------|-------------|--------------------------------------------------- |
|
||||
* | Entity Name | String (40) | Сущность, которой принадлежит счет (score). |
|
||||
* | | | Для Игроков - это ник |
|
||||
* | | | Для других сущностей - это UUID |
|
||||
* | Action | Byte | 0 - создать или обновить счет (score); 1 - удалить |
|
||||
* | Objective Name | String (16) | Имя сущности, которой принадлежит счет (score) |
|
||||
* | Value | VarInt | Если "Action" = 0. Значение счета (score) |
|
||||
* </pre>
|
||||
*
|
||||
* @see <a href="https://wiki.vg/index.php?title=Protocol&oldid=14204#Update_Score" target="_top">Update Score</a>
|
||||
*/
|
||||
@Data
|
||||
public class ScoreboardUpdateScorePacket implements ServerSidePacket {
|
||||
|
||||
private String entityName;
|
||||
private ScoreboardUpdateScoreAction action;
|
||||
private String objective;
|
||||
private int value;
|
||||
|
||||
@Override
|
||||
public void writeSelf(NetByteBuf netByteBuf) {
|
||||
netByteBuf.writeString(this.entityName);
|
||||
netByteBuf.writeByte(this.action.getCode());
|
||||
netByteBuf.writeString(this.objective);
|
||||
|
||||
if (ScoreboardUpdateScoreAction.CREATE_OR_UPDATE.equals(this.action)) {
|
||||
netByteBuf.writeVarInt(this.value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,119 +0,0 @@
|
||||
package mc.protocol.packets.server;
|
||||
|
||||
import lombok.Data;
|
||||
import mc.protocol.io.NetByteBuf;
|
||||
import mc.protocol.packets.ServerSidePacket;
|
||||
import mc.protocol.utils.TeamsCollisionRule;
|
||||
import mc.protocol.utils.TeamsMode;
|
||||
import mc.protocol.utils.TeamsNameTagVisibility;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Teams packet.
|
||||
*
|
||||
* <p>Структура пакета</p>
|
||||
* <pre>
|
||||
* | FIELD | TYPE | NOTES |
|
||||
* |------------ |-------------|-------------------------------------------------------|
|
||||
* | Team Name | String (16) | Уникальное название команды (совместно со scoreboard) |
|
||||
* | Mode | Byte | Режим. Определяет остальые поля пакета |
|
||||
* | Data Fields | - | Определяется "Mode" |
|
||||
* </pre>
|
||||
*
|
||||
* <p>Варианты "Mode"</p>
|
||||
* <pre>
|
||||
* | MODE | DATA FIELD | TYPE | NOTES |
|
||||
* | VALUE | DESCRIPTION | | | |
|
||||
* |-------|--------------------------|---------------------|----------------------|---------------------------------------------------|
|
||||
* | 0 | create team | Team Display Name | String (32) | |
|
||||
* | | | Team Prefix | String (16) | Отображается перед именем игроков текущей команды |
|
||||
* | | | Team Suffix | String (16) | Отображается после имени игроков текущей команды |
|
||||
* | | | Friendly Flags | Byte | Битовая маска: |
|
||||
* | | | | | 0x01 - разрешён friendly fire |
|
||||
* | | | | | 0x02 - могут видеть невидимок своей команды |
|
||||
* | | | Name Tag Visibility | String (32) | фиксированные значения: |
|
||||
* | | | | | - always |
|
||||
* | | | | | - hideForOtherTeams |
|
||||
* | | | | | - hideForOwnTeam |
|
||||
* | | | | | - never |
|
||||
* | | | Collision Rule | String (32) | фиксированные значения: |
|
||||
* | | | | | - always |
|
||||
* | | | | | - pushOtherTeams |
|
||||
* | | | | | - pushOwnTeam |
|
||||
* | | | | | - never |
|
||||
* | | | Color | Byte | For colors, the same Chat colors (0-15). |
|
||||
* | | | | | -1 indicates RESET/no color. |
|
||||
* | | | Entity Count | VarInt | Количество элементов в поле "Entities" |
|
||||
* | | | Entities | Array of String (40) | Уникальные идентификаторы участников команды. |
|
||||
* | | | | | Для Игроков - это Имена |
|
||||
* | | | | | Для любых других сущностей - это UUID |
|
||||
* | 1 | remove team | - | - | удаление текущей команды |
|
||||
* | 2 | update team info | Team Display Name | String (32) | |
|
||||
* | | | Team Prefix | String (16) | (см. выше) |
|
||||
* | | | Team Suffix | String (16) | (см. выше) |
|
||||
* | | | Friendly Flags | Byte | (см. выше) |
|
||||
* | | | Name Tag Visibility | String (32) | (см. выше) |
|
||||
* | | | Collision Rule | String (32) | (см. выше) |
|
||||
* | | | Color | Byte | (см. выше) |
|
||||
* | 3 | add players to team | Entity Count | VarInt | (см. выше) |
|
||||
* | | | Entities | Array of String (40) | (см. выше) |
|
||||
* | 4 | remove players from team | Entity Count | VarInt | (см. выше) |
|
||||
* | | | Entities | Array of String (40) | (см. выше) |
|
||||
* </pre>
|
||||
*
|
||||
* @see <a href="https://wiki.vg/index.php?title=Protocol&oldid=14204#Teams" target="_top">Teams</a>
|
||||
*/
|
||||
@Data
|
||||
public class TeamsPacket implements ServerSidePacket {
|
||||
|
||||
private final List<String> members = new ArrayList<>();
|
||||
|
||||
private String name;
|
||||
private TeamsMode mode;
|
||||
|
||||
private String displayName;
|
||||
private String prefix;
|
||||
private String suffix;
|
||||
private TeamsNameTagVisibility nameTagVisibility;
|
||||
private TeamsCollisionRule collisionRule;
|
||||
private int color;
|
||||
|
||||
@Override
|
||||
public void writeSelf(NetByteBuf netByteBuf) {
|
||||
netByteBuf.writeString(this.name);
|
||||
netByteBuf.writeByte(this.mode.getCode());
|
||||
|
||||
switch (this.mode) {
|
||||
case CREATE:
|
||||
netByteBuf.writeString(this.displayName);
|
||||
netByteBuf.writeString(this.prefix);
|
||||
netByteBuf.writeString(this.suffix);
|
||||
netByteBuf.writeByte(0); // Friendly Flags
|
||||
netByteBuf.writeString(this.nameTagVisibility.getCode());
|
||||
netByteBuf.writeString(this.collisionRule.getCode());
|
||||
netByteBuf.writeByte(this.color);
|
||||
netByteBuf.writeVarInt(this.members.size());
|
||||
this.members.forEach(netByteBuf::writeString);
|
||||
break;
|
||||
case UPDATE:
|
||||
netByteBuf.writeString(this.displayName);
|
||||
netByteBuf.writeString(this.prefix);
|
||||
netByteBuf.writeString(this.suffix);
|
||||
netByteBuf.writeByte(0); // Friendly Flags
|
||||
netByteBuf.writeString(this.nameTagVisibility.getCode());
|
||||
netByteBuf.writeString(this.collisionRule.getCode());
|
||||
netByteBuf.writeByte(this.color);
|
||||
break;
|
||||
case ADD_MEMBER:
|
||||
case REMOVE_MEMBER:
|
||||
netByteBuf.writeVarInt(this.members.size());
|
||||
this.members.forEach(netByteBuf::writeString);
|
||||
break;
|
||||
case REMOVE:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package mc.protocol.utils;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public enum EntityActionAction {
|
||||
START_SNEAKING(0),
|
||||
STOP_SNEAKING(1),
|
||||
LEAVE_BED(2),
|
||||
START_SPRINTING(3),
|
||||
STOP_SPRINTING(4),
|
||||
START_JUMP_WITH_HORSE(5),
|
||||
STOP_JUMP_WITH_HORSE(6),
|
||||
OPEN_HORSE_INVENTORY(7),
|
||||
START_FLYING_WITH_ELYTRA(8);
|
||||
|
||||
@Nullable
|
||||
public static EntityActionAction valueOfCode(int code) {
|
||||
for (EntityActionAction action : EntityActionAction.values()) {
|
||||
if (action.code == code) {
|
||||
return action;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Getter
|
||||
private final int code;
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
package mc.protocol.utils;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public enum ScoreboardObjectiveMode {
|
||||
CREATE(0),
|
||||
REMOVE(1),
|
||||
UPDATE(2);
|
||||
|
||||
@Getter
|
||||
private final int code;
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
package mc.protocol.utils;
|
||||
|
||||
public enum ScoreboardObjectiveType {
|
||||
INTEGER,
|
||||
HEARTS
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
package mc.protocol.utils;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
|
||||
@UtilityClass
|
||||
public class ScoreboardPosition {
|
||||
public final int LIST = 0;
|
||||
public final int SIDEBAR = 1;
|
||||
public final int BELOW_NAME = 2;
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
package mc.protocol.utils;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public enum ScoreboardUpdateScoreAction {
|
||||
CREATE_OR_UPDATE(0),
|
||||
REMOVE(1);
|
||||
|
||||
@Getter
|
||||
private final int code;
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
package mc.protocol.utils;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public enum TeamsCollisionRule {
|
||||
ALWAYS("always"),
|
||||
PUSH_OTHER_TEAMS("pushOtherTeams"),
|
||||
PUSH_OWN_TEAM("pushOwnTeam"),
|
||||
NEVER("never");
|
||||
|
||||
@Getter
|
||||
private final String code;
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
package mc.protocol.utils;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public enum TeamsMode {
|
||||
CREATE(0),
|
||||
REMOVE(1),
|
||||
UPDATE(2),
|
||||
ADD_MEMBER(3),
|
||||
REMOVE_MEMBER(4);
|
||||
|
||||
@Getter
|
||||
private final int code;
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
package mc.protocol.utils;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public enum TeamsNameTagVisibility {
|
||||
ALWAYS("always"),
|
||||
HIDE_FOR_OTHER_TEAMS("hideForOtherTeams"),
|
||||
HIDE_FOR_OWN_TEAM("hideForOwnTeam"),
|
||||
NEVER("never");
|
||||
|
||||
@Getter
|
||||
private final String code;
|
||||
}
|
||||
@@ -7,13 +7,17 @@ import mc.protocol.api.ConnectionContext;
|
||||
import mc.protocol.model.Location;
|
||||
import mc.protocol.model.Look;
|
||||
import mc.protocol.model.ServerInfo;
|
||||
import mc.protocol.model.text.Text;
|
||||
import mc.protocol.model.text.TextColor;
|
||||
import mc.protocol.packets.PingPacket;
|
||||
import mc.protocol.packets.client.HandshakePacket;
|
||||
import mc.protocol.packets.client.LoginStartPacket;
|
||||
import mc.protocol.packets.client.StatusServerRequestPacket;
|
||||
import mc.protocol.packets.server.*;
|
||||
import mc.protocol.serializer.TextSerializer;
|
||||
import mc.protocol.utils.*;
|
||||
import mc.protocol.utils.Difficulty;
|
||||
import mc.protocol.utils.GameMode;
|
||||
import mc.protocol.utils.LevelType;
|
||||
import mc.server.config.Config;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
|
||||
@@ -66,9 +70,9 @@ public class PacketHandler {
|
||||
}
|
||||
|
||||
public void onLoginStart(ConnectionContext context, LoginStartPacket loginStartPacket) {
|
||||
UUID playerUuid = UUID.randomUUID();
|
||||
int playerEid = random.nextInt();
|
||||
String playerName = loginStartPacket.getName();
|
||||
var playerUuid = UUID.randomUUID();
|
||||
var playerName = loginStartPacket.getName();
|
||||
var playerGamemode = GameMode.SURVIVAL;
|
||||
|
||||
var loginSuccessPacket = new LoginSuccessPacket();
|
||||
loginSuccessPacket.setUuid(playerUuid);
|
||||
@@ -78,15 +82,15 @@ public class PacketHandler {
|
||||
context.setState(State.PLAY);
|
||||
|
||||
var joinGamePacket = new JoinGamePacket();
|
||||
joinGamePacket.setEntityId(playerEid);
|
||||
joinGamePacket.setGameMode(GameMode.SPECTATOR);
|
||||
joinGamePacket.setEntityId(random.nextInt());
|
||||
joinGamePacket.setGameMode(playerGamemode);
|
||||
joinGamePacket.setDimension(0/*Overworld*/);
|
||||
joinGamePacket.setDifficulty(Difficulty.PEACEFUL);
|
||||
joinGamePacket.setLevelType(LevelType.FLAT);
|
||||
|
||||
context.send(joinGamePacket);
|
||||
|
||||
Location spawnLocation = new Location(0d, 63d, 0d);
|
||||
Location spawnLocation = new Location(7d, 130d, 7d);
|
||||
|
||||
var spawnPositionPacket = new SpawnPositionPacket();
|
||||
spawnPositionPacket.setSpawn(spawnLocation);
|
||||
@@ -125,31 +129,30 @@ public class PacketHandler {
|
||||
|
||||
context.flushSending();
|
||||
|
||||
// --- Эксперименты --- //
|
||||
// -- Эксперименты -- //
|
||||
|
||||
String scoreboardName = "Score::List";
|
||||
var playerListItemPacket = new PlayerListItemPacket();
|
||||
playerListItemPacket.setAction(PlayerListItemPacket.Action.ADD_PLAYER);
|
||||
playerListItemPacket.getPlayerItems().add(PlayerListItemPacket.PlayerItem.builder()
|
||||
.uuid(playerUuid)
|
||||
.name(playerName)
|
||||
.gamemode(playerGamemode)
|
||||
.ping(100)
|
||||
.hasDisplayName(false)
|
||||
.build());
|
||||
|
||||
var scoreboardObjectivePacket = new ScoreboardObjectivePacket();
|
||||
scoreboardObjectivePacket.setObjectiveName(scoreboardName);
|
||||
scoreboardObjectivePacket.setMode(ScoreboardObjectiveMode.CREATE);
|
||||
scoreboardObjectivePacket.setObjectiveValue(scoreboardName);
|
||||
scoreboardObjectivePacket.setType(ScoreboardObjectiveType.INTEGER);
|
||||
context.send(playerListItemPacket);
|
||||
|
||||
context.send(scoreboardObjectivePacket);
|
||||
var playerListHeaderAndFooterPacket = new PlayerListHeaderAndFooterPacket();
|
||||
playerListHeaderAndFooterPacket.setHeader(Text.builder()
|
||||
.append("") //TODO bug component
|
||||
.append(Text.of(TextColor.GREEN, "==="))
|
||||
.append(Text.of(TextColor.RED, " MC-PROJECT "))
|
||||
.append(Text.of(TextColor.GREEN, "==="))
|
||||
.build());
|
||||
playerListHeaderAndFooterPacket.setFoother(Text.of(TextColor.GRAY, "develop by DmitriyMX"));
|
||||
|
||||
var scoreboardDisplayPacket = new ScoreboardDisplayPacket();
|
||||
scoreboardDisplayPacket.setPosition(ScoreboardPosition.SIDEBAR);
|
||||
scoreboardDisplayPacket.setScoreName(scoreboardName);
|
||||
|
||||
context.send(scoreboardDisplayPacket);
|
||||
|
||||
var scoreboardUpdateScorePacket = new ScoreboardUpdateScorePacket();
|
||||
scoreboardUpdateScorePacket.setEntityName(playerName);
|
||||
scoreboardUpdateScorePacket.setAction(ScoreboardUpdateScoreAction.CREATE_OR_UPDATE);
|
||||
scoreboardUpdateScorePacket.setObjective(scoreboardName);
|
||||
scoreboardUpdateScorePacket.setValue(100500);
|
||||
|
||||
context.send(scoreboardUpdateScorePacket);
|
||||
context.send(playerListHeaderAndFooterPacket);
|
||||
|
||||
context.flushSending();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user