Archived
0

Scoreboard works

This commit is contained in:
2021-05-08 17:58:15 +03:00
parent 6dbf785d22
commit c705a2090d
4 changed files with 18 additions and 36 deletions

View File

@@ -25,7 +25,7 @@ import mc.protocol.packets.ServerSidePacket;
public class ScoreboardDisplayPacket implements ServerSidePacket { public class ScoreboardDisplayPacket implements ServerSidePacket {
private int position; private int position;
private String name; private String scoreName;
public void setPosition(int position) { public void setPosition(int position) {
this.position = (position < 0) ? 0 : (Math.min(position, 18)); this.position = (position < 0) ? 0 : (Math.min(position, 18));
@@ -33,7 +33,7 @@ public class ScoreboardDisplayPacket implements ServerSidePacket {
@Override @Override
public void writeSelf(NetByteBuf netByteBuf) { public void writeSelf(NetByteBuf netByteBuf) {
netByteBuf.writeByte(position); netByteBuf.writeByte(this.position);
netByteBuf.writeString(name); netByteBuf.writeString(this.scoreName);
} }
} }

View File

@@ -26,18 +26,18 @@ import mc.protocol.utils.ScoreboardObjectiveType;
@Data @Data
public class ScoreboardObjectivePacket implements ServerSidePacket { public class ScoreboardObjectivePacket implements ServerSidePacket {
private String name; private String objectiveName;
private ScoreboardObjectiveMode mode; private ScoreboardObjectiveMode mode;
private String value; private String objectiveValue;
private ScoreboardObjectiveType type; private ScoreboardObjectiveType type;
@Override @Override
public void writeSelf(NetByteBuf netByteBuf) { public void writeSelf(NetByteBuf netByteBuf) {
netByteBuf.writeString(this.name); netByteBuf.writeString(this.objectiveName);
netByteBuf.writeByte(this.mode.getCode()); netByteBuf.writeByte(this.mode.getCode());
if (ScoreboardObjectiveMode.CREATE.equals(this.mode) || ScoreboardObjectiveMode.UPDATE.equals(this.mode)) { if (ScoreboardObjectiveMode.CREATE.equals(this.mode) || ScoreboardObjectiveMode.UPDATE.equals(this.mode)) {
netByteBuf.writeString(this.value); netByteBuf.writeString(this.objectiveValue);
netByteBuf.writeString(this.type.name().toLowerCase()); netByteBuf.writeString(this.type.name().toLowerCase());
} }
} }

View File

@@ -27,14 +27,14 @@ public class ScoreboardUpdateScorePacket implements ServerSidePacket {
private String entityName; private String entityName;
private ScoreboardUpdateScoreAction action; private ScoreboardUpdateScoreAction action;
private String entityDisplayName; private String objective;
private int value; private int value;
@Override @Override
public void writeSelf(NetByteBuf netByteBuf) { public void writeSelf(NetByteBuf netByteBuf) {
netByteBuf.writeString(this.entityName); netByteBuf.writeString(this.entityName);
netByteBuf.writeByte(this.action.getCode()); netByteBuf.writeByte(this.action.getCode());
netByteBuf.writeString(this.entityDisplayName); netByteBuf.writeString(this.objective);
if (ScoreboardUpdateScoreAction.CREATE_OR_UPDATE.equals(this.action)) { if (ScoreboardUpdateScoreAction.CREATE_OR_UPDATE.equals(this.action)) {
netByteBuf.writeVarInt(this.value); netByteBuf.writeVarInt(this.value);

View File

@@ -127,45 +127,27 @@ public class PacketHandler {
// --- Эксперименты --- // // --- Эксперименты --- //
String scoreboardName = "Score::List";
var scoreboardObjectivePacket = new ScoreboardObjectivePacket(); var scoreboardObjectivePacket = new ScoreboardObjectivePacket();
scoreboardObjectivePacket.setName(playerName); scoreboardObjectivePacket.setObjectiveName(scoreboardName);
scoreboardObjectivePacket.setMode(ScoreboardObjectiveMode.CREATE); scoreboardObjectivePacket.setMode(ScoreboardObjectiveMode.CREATE);
scoreboardObjectivePacket.setValue("Score::List"); scoreboardObjectivePacket.setObjectiveValue(scoreboardName);
scoreboardObjectivePacket.setType(ScoreboardObjectiveType.INTEGER); scoreboardObjectivePacket.setType(ScoreboardObjectiveType.INTEGER);
context.send(scoreboardObjectivePacket); context.send(scoreboardObjectivePacket);
var scoreboardDisplayPacket = new ScoreboardDisplayPacket(); var scoreboardDisplayPacket = new ScoreboardDisplayPacket();
scoreboardDisplayPacket.setPosition(ScoreboardPosition.LIST); scoreboardDisplayPacket.setPosition(ScoreboardPosition.SIDEBAR);
scoreboardDisplayPacket.setName(playerName); scoreboardDisplayPacket.setScoreName(scoreboardName);
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);
var scoreboardUpdateScorePacket = new ScoreboardUpdateScorePacket(); var scoreboardUpdateScorePacket = new ScoreboardUpdateScorePacket();
scoreboardUpdateScorePacket.setEntityName(teamsPacket_Create.getPrefix() + playerName + teamsPacket_Create.getSuffix()); scoreboardUpdateScorePacket.setEntityName(playerName);
scoreboardUpdateScorePacket.setEntityDisplayName(playerName);
scoreboardUpdateScorePacket.setAction(ScoreboardUpdateScoreAction.CREATE_OR_UPDATE); scoreboardUpdateScorePacket.setAction(ScoreboardUpdateScoreAction.CREATE_OR_UPDATE);
scoreboardUpdateScorePacket.setObjective(scoreboardName);
scoreboardUpdateScorePacket.setValue(100500);
context.send(scoreboardUpdateScorePacket); context.send(scoreboardUpdateScorePacket);