Title
This commit is contained in:
@@ -62,6 +62,7 @@ public enum State {
|
||||
.put(JoinGamePacket.class, 0x23)
|
||||
.put(SpawnPositionPacket.class, 0x46)
|
||||
.put(TimeUpdatePacket.class, 0x47)
|
||||
.put(TitlePacket.class, 0x48)
|
||||
.put(PlayerAbilitiesPacket.class, 0x2C)
|
||||
.put(PlayerPositionAndLookPacket.class, 0x2F)
|
||||
.build()
|
||||
|
||||
@@ -0,0 +1,109 @@
|
||||
/*
|
||||
* DmitriyMX <dimon550@gmail.com>
|
||||
* 2018-06-24
|
||||
*/
|
||||
package mc.core.network.proto_1_12_2.packets;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import mc.core.network.NetStream;
|
||||
import mc.core.network.SCPacket;
|
||||
import mc.core.network.proto_1_12_2.serializers.TextSerializer;
|
||||
import mc.core.text.Text;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
@Setter
|
||||
@ToString
|
||||
public class TitlePacket implements SCPacket {
|
||||
private static final int TICKS_PER_SEC = 20,
|
||||
MIN_MS = (1000 / TICKS_PER_SEC);
|
||||
public static final int SET_TITLE = 0,
|
||||
SET_SUBTITLE = 1,
|
||||
SET_ACTION_BAR = 2,
|
||||
SET_DISPLAY_TIME = 3,
|
||||
HIDE = 4,
|
||||
RESET = 5;
|
||||
|
||||
private final int action;
|
||||
private Text text = null;
|
||||
private Integer fadeInTime = null;
|
||||
private Integer stayTime = null;
|
||||
private Integer fadeOutTime = null;
|
||||
|
||||
public TitlePacket(int action, Object... values) {
|
||||
if (values.length == 0 && (action != HIDE && action != RESET)) {
|
||||
this.action = HIDE;
|
||||
return;
|
||||
}
|
||||
|
||||
this.action = action;
|
||||
|
||||
switch (this.action) {
|
||||
case SET_TITLE:
|
||||
case SET_SUBTITLE:
|
||||
case SET_ACTION_BAR:
|
||||
if (values[0] == null) {
|
||||
this.text = Text.of();
|
||||
} else if (values[0] instanceof Text) {
|
||||
this.text = (Text) values[0];
|
||||
} else {
|
||||
this.text = Text.of(values[0].toString());
|
||||
}
|
||||
break;
|
||||
case SET_DISPLAY_TIME:
|
||||
if (values.length < 3) {
|
||||
this.fadeInTime = 0;
|
||||
this.stayTime = 0;
|
||||
this.fadeOutTime = 0;
|
||||
} else {
|
||||
if (values[0] instanceof Integer) {
|
||||
if (((Integer) values[0]) < MIN_MS) {
|
||||
this.fadeInTime = 1;
|
||||
} else {
|
||||
this.fadeInTime = ((Integer) values[0]) / MIN_MS;
|
||||
}
|
||||
} else {
|
||||
this.fadeInTime = 0;
|
||||
}
|
||||
|
||||
if (values[1] instanceof Integer) {
|
||||
if (((Integer) values[1]) < MIN_MS) {
|
||||
this.stayTime = 1;
|
||||
} else {
|
||||
this.stayTime = ((Integer) values[1]) / MIN_MS;
|
||||
}
|
||||
} else {
|
||||
this.stayTime = 0;
|
||||
}
|
||||
|
||||
if (values[2] instanceof Integer) {
|
||||
if (((Integer) values[2]) < MIN_MS) {
|
||||
this.fadeOutTime = 1;
|
||||
} else {
|
||||
this.fadeOutTime = ((Integer) values[2]) / MIN_MS;
|
||||
}
|
||||
} else {
|
||||
this.fadeOutTime = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeSelf(NetStream netStream) {
|
||||
netStream.writeVarInt(this.action);
|
||||
|
||||
switch (this.action) {
|
||||
case SET_TITLE:
|
||||
case SET_SUBTITLE:
|
||||
case SET_ACTION_BAR:
|
||||
netStream.writeString(TextSerializer.serialize(this.text).toString());
|
||||
break;
|
||||
case SET_DISPLAY_TIME:
|
||||
netStream.writeInt(this.fadeInTime);
|
||||
netStream.writeInt(this.stayTime);
|
||||
netStream.writeInt(this.fadeOutTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user