Archived
0

ScoreboardDisplayPacket

This commit is contained in:
2021-05-06 17:05:20 +03:00
parent 2521860bb4
commit fda80d9f9d
4 changed files with 59 additions and 0 deletions

View File

@@ -56,6 +56,7 @@ public enum State {
Map.of( Map.of(
PingPacket.class, 0x1F, PingPacket.class, 0x1F,
JoinGamePacket.class, 0x23, JoinGamePacket.class, 0x23,
ScoreboardDisplayPacket.class, 0x3B,
SpawnPositionPacket.class, 0x46, SpawnPositionPacket.class, 0x46,
ChunkDataPacket.class, 0x20, ChunkDataPacket.class, 0x20,
PlayerAbilitiesPacket.class,0x2C, PlayerAbilitiesPacket.class,0x2C,

View File

@@ -0,0 +1,39 @@
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 name;
public void setPosition(int position) {
this.position = (position < 0) ? 0 : (Math.min(position, 18));
}
@Override
public void writeSelf(NetByteBuf netByteBuf) {
netByteBuf.writeByte(position);
netByteBuf.writeString(name);
}
}

View File

@@ -0,0 +1,10 @@
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;
}

View File

@@ -16,6 +16,7 @@ import mc.protocol.serializer.TextSerializer;
import mc.protocol.utils.Difficulty; import mc.protocol.utils.Difficulty;
import mc.protocol.utils.GameMode; import mc.protocol.utils.GameMode;
import mc.protocol.utils.LevelType; import mc.protocol.utils.LevelType;
import mc.protocol.utils.ScoreboardPosition;
import mc.server.config.Config; import mc.server.config.Config;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
@@ -122,6 +123,14 @@ public class PacketHandler {
context.send(pingPacket); context.send(pingPacket);
context.flushSending(); context.flushSending();
// --- Эксперименты --- //
ScoreboardDisplayPacket scoreboardDisplayPacket = new ScoreboardDisplayPacket();
scoreboardDisplayPacket.setPosition(ScoreboardPosition.LIST);
scoreboardDisplayPacket.setName("Score::List");
context.sendNow(scoreboardDisplayPacket);
} }
private static String faviconToBase64(Path iconPath) { private static String faviconToBase64(Path iconPath) {