Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
74a9066a04
|
@@ -59,7 +59,8 @@ public enum State {
|
||||
SpawnPositionPacket.class, 0x46,
|
||||
ChunkDataPacket.class, 0x20,
|
||||
PlayerAbilitiesPacket.class,0x2C,
|
||||
SPlayerPositionAndLookPacket.class, 0x2F
|
||||
SPlayerPositionAndLookPacket.class, 0x2F,
|
||||
TitlePacket.class, 0x48
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
package mc.protocol.packets.server;
|
||||
|
||||
import lombok.Data;
|
||||
import mc.protocol.io.NetByteBuf;
|
||||
import mc.protocol.model.text.Text;
|
||||
import mc.protocol.model.text.TextColor;
|
||||
import mc.protocol.model.text.TextStyle;
|
||||
import mc.protocol.packets.ServerSidePacket;
|
||||
import mc.protocol.serializer.TextSerializer;
|
||||
import mc.protocol.utils.TitleAction;
|
||||
|
||||
/**
|
||||
* Title packet.
|
||||
*
|
||||
* <p>Структура пакета</p>
|
||||
* <pre>
|
||||
* | FIELD | TYPE | NOTES |
|
||||
* |-------------|-------------|----------------------------------|
|
||||
* | Action | VarInt | Определяет остальные поля пакета |
|
||||
* | Data fields | - | зависят от "Action" |
|
||||
* </pre>
|
||||
*
|
||||
* <p>Варианты "Action"</p>
|
||||
* <pre>
|
||||
* | ACTION | FIELD | TYPE | NOTES |
|
||||
* | VALUE | DESCRIPTION | | | |
|
||||
* |-------|-----------------------|-----------------|---------|-------------------------------------------------|
|
||||
* | 0 | set title | Title Text | Text | |
|
||||
* | 1 | set subtitle | Subtitle Text | Text | |
|
||||
* | 2 | set action bar | Action bar text | Text | [*] |
|
||||
* | 3 | set times and display | Fade In | Integer | Время (в тиках (tick)) на эфект появления |
|
||||
* | | | Stay | Integer | Время (в тиках (tick)) на отображение на экране |
|
||||
* | | | Fade Out | Integer | Время (в тиках (tick)) на эфект исчезания |
|
||||
* | 4 | hide | - | - | |
|
||||
* | 5 | reset | - | - | |
|
||||
* </pre>
|
||||
*
|
||||
* <p>
|
||||
* * - стоит обратить внимание, что {@link TextColor} и {@link TextStyle} не работают: клиент не применяет
|
||||
* стилистику в таком виде. Однако метод через символ "§" (\<span>u00a7</span>) работает.
|
||||
* </p>
|
||||
*
|
||||
* @see <a href="https://wiki.vg/index.php?title=Protocol&oldid=14204#Title">Title</a>
|
||||
*/
|
||||
@Data
|
||||
public class TitlePacket implements ServerSidePacket {
|
||||
|
||||
private TitleAction action;
|
||||
|
||||
private Text title;
|
||||
private Text subtitle;
|
||||
private Text actionbar;
|
||||
private Integer fadeIn;
|
||||
private Integer stay;
|
||||
private Integer fadeOut;
|
||||
|
||||
@Override
|
||||
public void writeSelf(NetByteBuf netByteBuf) {
|
||||
netByteBuf.writeVarInt(this.action.getCode());
|
||||
|
||||
switch (this.action) {
|
||||
case SET_TITLE:
|
||||
netByteBuf.writeString(TextSerializer.toJsonObject(this.title).toString());
|
||||
break;
|
||||
case SET_SUBTITLE:
|
||||
netByteBuf.writeString(TextSerializer.toJsonObject(this.subtitle).toString());
|
||||
break;
|
||||
case SET_ACTIONBAR:
|
||||
netByteBuf.writeString(TextSerializer.toJsonObject(this.actionbar).toString());
|
||||
break;
|
||||
case SET_TIMES_AND_DISPLAY:
|
||||
netByteBuf.writeInt(fadeIn);
|
||||
netByteBuf.writeInt(stay);
|
||||
netByteBuf.writeInt(fadeOut);
|
||||
break;
|
||||
case HIDE:
|
||||
case RESET:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
17
protocol/src/main/java/mc/protocol/utils/TitleAction.java
Normal file
17
protocol/src/main/java/mc/protocol/utils/TitleAction.java
Normal file
@@ -0,0 +1,17 @@
|
||||
package mc.protocol.utils;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public enum TitleAction {
|
||||
SET_TITLE(0),
|
||||
SET_SUBTITLE(1),
|
||||
SET_ACTIONBAR(2),
|
||||
SET_TIMES_AND_DISPLAY(3),
|
||||
HIDE(4),
|
||||
RESET(5);
|
||||
|
||||
@Getter
|
||||
private final int code;
|
||||
}
|
||||
@@ -7,6 +7,7 @@ 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.packets.PingPacket;
|
||||
import mc.protocol.packets.client.HandshakePacket;
|
||||
import mc.protocol.packets.client.LoginStartPacket;
|
||||
@@ -16,6 +17,7 @@ import mc.protocol.serializer.TextSerializer;
|
||||
import mc.protocol.utils.Difficulty;
|
||||
import mc.protocol.utils.GameMode;
|
||||
import mc.protocol.utils.LevelType;
|
||||
import mc.protocol.utils.TitleAction;
|
||||
import mc.server.config.Config;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
|
||||
@@ -122,6 +124,14 @@ public class PacketHandler {
|
||||
context.send(pingPacket);
|
||||
|
||||
context.flushSending();
|
||||
|
||||
// -- Эксперименты -- //
|
||||
|
||||
var titlePacket = new TitlePacket();
|
||||
titlePacket.setAction(TitleAction.SET_TITLE);
|
||||
titlePacket.setTitle(Text.of("HELLO"));
|
||||
|
||||
context.sendNow(titlePacket);
|
||||
}
|
||||
|
||||
private static String faviconToBase64(Path iconPath) {
|
||||
|
||||
Reference in New Issue
Block a user