ScoreboardObjectivePacket
This commit is contained in:
@@ -57,6 +57,7 @@ public enum State {
|
|||||||
PingPacket.class, 0x1F,
|
PingPacket.class, 0x1F,
|
||||||
JoinGamePacket.class, 0x23,
|
JoinGamePacket.class, 0x23,
|
||||||
ScoreboardDisplayPacket.class, 0x3B,
|
ScoreboardDisplayPacket.class, 0x3B,
|
||||||
|
ScoreboardObjectivePacket.class, 0x42,
|
||||||
TeamsPacket.class, 0x44,
|
TeamsPacket.class, 0x44,
|
||||||
SpawnPositionPacket.class, 0x46,
|
SpawnPositionPacket.class, 0x46,
|
||||||
ChunkDataPacket.class, 0x20,
|
ChunkDataPacket.class, 0x20,
|
||||||
|
|||||||
@@ -0,0 +1,44 @@
|
|||||||
|
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 name;
|
||||||
|
private ScoreboardObjectiveMode mode;
|
||||||
|
private String value;
|
||||||
|
private ScoreboardObjectiveType type;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeSelf(NetByteBuf netByteBuf) {
|
||||||
|
netByteBuf.writeString(this.name);
|
||||||
|
netByteBuf.writeByte(this.mode.getCode());
|
||||||
|
|
||||||
|
if (ScoreboardObjectiveMode.CREATE.equals(this.mode) || ScoreboardObjectiveMode.UPDATE.equals(this.mode)) {
|
||||||
|
netByteBuf.writeString(this.value);
|
||||||
|
netByteBuf.writeString(this.type.name().toLowerCase());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
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;
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
package mc.protocol.utils;
|
||||||
|
|
||||||
|
public enum ScoreboardObjectiveType {
|
||||||
|
INTEGER,
|
||||||
|
HEARTS
|
||||||
|
}
|
||||||
@@ -127,23 +127,41 @@ public class PacketHandler {
|
|||||||
|
|
||||||
// --- Эксперименты --- //
|
// --- Эксперименты --- //
|
||||||
|
|
||||||
TeamsPacket teamsPacket = new TeamsPacket();
|
var scoreboardObjectivePacket = new ScoreboardObjectivePacket();
|
||||||
teamsPacket.setName("Score::List");
|
scoreboardObjectivePacket.setName(playerName);
|
||||||
teamsPacket.setMode(TeamsMode.CREATE);
|
scoreboardObjectivePacket.setMode(ScoreboardObjectiveMode.CREATE);
|
||||||
teamsPacket.setDisplayName(teamsPacket.getName());
|
scoreboardObjectivePacket.setValue("Score::List");
|
||||||
teamsPacket.setNameTagVisibility(TeamsNameTagVisibility.NEVER);
|
scoreboardObjectivePacket.setType(ScoreboardObjectiveType.INTEGER);
|
||||||
teamsPacket.setCollisionRule(TeamsCollisionRule.NEVER);
|
|
||||||
teamsPacket.setColor(-1/*no color*/);
|
|
||||||
teamsPacket.getMembers().add(playerName);
|
|
||||||
|
|
||||||
context.send(teamsPacket);
|
context.send(scoreboardObjectivePacket);
|
||||||
|
|
||||||
ScoreboardDisplayPacket scoreboardDisplayPacket = new ScoreboardDisplayPacket();
|
var scoreboardDisplayPacket = new ScoreboardDisplayPacket();
|
||||||
scoreboardDisplayPacket.setPosition(ScoreboardPosition.LIST);
|
scoreboardDisplayPacket.setPosition(ScoreboardPosition.LIST);
|
||||||
scoreboardDisplayPacket.setName(teamsPacket.getName());
|
scoreboardDisplayPacket.setName(playerName);
|
||||||
|
|
||||||
context.send(scoreboardDisplayPacket);
|
context.send(scoreboardDisplayPacket);
|
||||||
|
|
||||||
|
@SuppressWarnings("java:S117")
|
||||||
|
var teamsPacket_Create = new TeamsPacket();
|
||||||
|
teamsPacket_Create.setMode(TeamsMode.CREATE);
|
||||||
|
teamsPacket_Create.setName("__fakeScore0");
|
||||||
|
teamsPacket_Create.setDisplayName(teamsPacket_Create.getName());
|
||||||
|
teamsPacket_Create.setPrefix("");
|
||||||
|
teamsPacket_Create.setSuffix("");
|
||||||
|
teamsPacket_Create.setNameTagVisibility(TeamsNameTagVisibility.ALWAYS);
|
||||||
|
teamsPacket_Create.setCollisionRule(TeamsCollisionRule.ALWAYS);
|
||||||
|
teamsPacket_Create.setColor(-1/*no color*/);
|
||||||
|
|
||||||
|
context.send(teamsPacket_Create);
|
||||||
|
|
||||||
|
@SuppressWarnings("java:S117")
|
||||||
|
var teamsPacket_Add = new TeamsPacket();
|
||||||
|
teamsPacket_Add.setMode(TeamsMode.ADD_MEMBER);
|
||||||
|
teamsPacket_Add.setName(teamsPacket_Create.getName());
|
||||||
|
teamsPacket_Add.getMembers().add(playerName);
|
||||||
|
|
||||||
|
context.send(teamsPacket_Add);
|
||||||
|
|
||||||
context.flushSending();
|
context.flushSending();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user