mirror of
https://github.com/Nan1t/NanoLimbo.git
synced 2025-07-09 19:40:14 +02:00
Added join title
This commit is contained in:
parent
24ccfd9050
commit
790a1b414b
@ -27,8 +27,10 @@ public final class LimboConfig {
|
|||||||
|
|
||||||
private boolean useJoinMessage;
|
private boolean useJoinMessage;
|
||||||
private boolean useBossBar;
|
private boolean useBossBar;
|
||||||
|
private boolean useTitle;
|
||||||
private String joinMessage;
|
private String joinMessage;
|
||||||
private BossBar bossBar;
|
private BossBar bossBar;
|
||||||
|
private Title title;
|
||||||
|
|
||||||
private InfoForwarding infoForwarding;
|
private InfoForwarding infoForwarding;
|
||||||
private long readTimeout;
|
private long readTimeout;
|
||||||
@ -59,6 +61,7 @@ public final class LimboConfig {
|
|||||||
gameMode = conf.node("gameMode").getInt();
|
gameMode = conf.node("gameMode").getInt();
|
||||||
useJoinMessage = conf.node("joinMessage", "enable").getBoolean();
|
useJoinMessage = conf.node("joinMessage", "enable").getBoolean();
|
||||||
useBossBar = conf.node("bossBar", "enable").getBoolean();
|
useBossBar = conf.node("bossBar", "enable").getBoolean();
|
||||||
|
useTitle = conf.node("title", "enable").getBoolean();
|
||||||
|
|
||||||
if (useJoinMessage)
|
if (useJoinMessage)
|
||||||
joinMessage = Colors.of(conf.node("joinMessage", "text").getString(""));
|
joinMessage = Colors.of(conf.node("joinMessage", "text").getString(""));
|
||||||
@ -66,6 +69,9 @@ public final class LimboConfig {
|
|||||||
if (useBossBar)
|
if (useBossBar)
|
||||||
bossBar = conf.node("bossBar").get(BossBar.class);
|
bossBar = conf.node("bossBar").get(BossBar.class);
|
||||||
|
|
||||||
|
if (useTitle)
|
||||||
|
title = conf.node("title").get(Title.class);
|
||||||
|
|
||||||
infoForwarding = conf.node("infoForwarding").get(InfoForwarding.class);
|
infoForwarding = conf.node("infoForwarding").get(InfoForwarding.class);
|
||||||
readTimeout = conf.node("readTimeout").getLong();
|
readTimeout = conf.node("readTimeout").getLong();
|
||||||
debugLevel = conf.node("debugLevel").getInt();
|
debugLevel = conf.node("debugLevel").getInt();
|
||||||
@ -97,6 +103,7 @@ public final class LimboConfig {
|
|||||||
.register(InfoForwarding.class, new InfoForwarding.Serializer())
|
.register(InfoForwarding.class, new InfoForwarding.Serializer())
|
||||||
.register(PingData.class, new PingData.Serializer())
|
.register(PingData.class, new PingData.Serializer())
|
||||||
.register(BossBar.class, new BossBar.Serializer())
|
.register(BossBar.class, new BossBar.Serializer())
|
||||||
|
.register(Title.class, new Title.Serializer())
|
||||||
.register(Position.class, new Position.Serializer())
|
.register(Position.class, new Position.Serializer())
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
@ -145,6 +152,10 @@ public final class LimboConfig {
|
|||||||
return useBossBar;
|
return useBossBar;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isUseTitle() {
|
||||||
|
return useTitle;
|
||||||
|
}
|
||||||
|
|
||||||
public String getJoinMessage() {
|
public String getJoinMessage() {
|
||||||
return joinMessage;
|
return joinMessage;
|
||||||
}
|
}
|
||||||
@ -153,6 +164,10 @@ public final class LimboConfig {
|
|||||||
return bossBar;
|
return bossBar;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Title getTitle() {
|
||||||
|
return title;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isUseEpoll() {
|
public boolean isUseEpoll() {
|
||||||
return useEpoll;
|
return useEpoll;
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,7 @@ import ru.nanit.limbo.protocol.packets.status.PacketStatusResponse;
|
|||||||
import ru.nanit.limbo.protocol.registry.State;
|
import ru.nanit.limbo.protocol.registry.State;
|
||||||
import ru.nanit.limbo.protocol.registry.Version;
|
import ru.nanit.limbo.protocol.registry.Version;
|
||||||
import ru.nanit.limbo.server.LimboServer;
|
import ru.nanit.limbo.server.LimboServer;
|
||||||
|
import ru.nanit.limbo.server.data.Title;
|
||||||
import ru.nanit.limbo.util.Logger;
|
import ru.nanit.limbo.util.Logger;
|
||||||
import ru.nanit.limbo.util.UuidUtil;
|
import ru.nanit.limbo.util.UuidUtil;
|
||||||
|
|
||||||
@ -43,6 +44,14 @@ public class ClientConnection extends ChannelInboundHandlerAdapter {
|
|||||||
private static PreEncodedPacket PACKET_JOIN_MESSAGE;
|
private static PreEncodedPacket PACKET_JOIN_MESSAGE;
|
||||||
private static PreEncodedPacket PACKET_BOSS_BAR;
|
private static PreEncodedPacket PACKET_BOSS_BAR;
|
||||||
|
|
||||||
|
private static PreEncodedPacket PACKET_TITLE_TITLE;
|
||||||
|
private static PreEncodedPacket PACKET_TITLE_SUBTITLE;
|
||||||
|
private static PreEncodedPacket PACKET_TITLE_TIMES;
|
||||||
|
|
||||||
|
private static PreEncodedPacket PACKET_TITLE_LEGACY_TITLE;
|
||||||
|
private static PreEncodedPacket PACKET_TITLE_LEGACY_SUBTITLE;
|
||||||
|
private static PreEncodedPacket PACKET_TITLE_LEGACY_TIMES;
|
||||||
|
|
||||||
private final LimboServer server;
|
private final LimboServer server;
|
||||||
private final Channel channel;
|
private final Channel channel;
|
||||||
private final GameProfile gameProfile;
|
private final GameProfile gameProfile;
|
||||||
@ -211,6 +220,9 @@ public class ClientConnection extends ChannelInboundHandlerAdapter {
|
|||||||
if (PACKET_JOIN_MESSAGE != null)
|
if (PACKET_JOIN_MESSAGE != null)
|
||||||
writePacket(PACKET_JOIN_MESSAGE);
|
writePacket(PACKET_JOIN_MESSAGE);
|
||||||
|
|
||||||
|
if (PACKET_TITLE_TITLE != null)
|
||||||
|
sendTitle();
|
||||||
|
|
||||||
sendKeepAlive();
|
sendKeepAlive();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -222,6 +234,18 @@ public class ClientConnection extends ChannelInboundHandlerAdapter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void sendTitle() {
|
||||||
|
if (clientVersion.moreOrEqual(Version.V1_17)) {
|
||||||
|
writePacket(PACKET_TITLE_TITLE);
|
||||||
|
writePacket(PACKET_TITLE_SUBTITLE);
|
||||||
|
sendPacket(PACKET_TITLE_TIMES);
|
||||||
|
} else {
|
||||||
|
writePacket(PACKET_TITLE_LEGACY_TITLE);
|
||||||
|
writePacket(PACKET_TITLE_LEGACY_SUBTITLE);
|
||||||
|
sendPacket(PACKET_TITLE_LEGACY_TIMES);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void sendKeepAlive() {
|
public void sendKeepAlive() {
|
||||||
if (state.equals(State.PLAY)) {
|
if (state.equals(State.PLAY)) {
|
||||||
PacketKeepAlive keepAlive = new PacketKeepAlive();
|
PacketKeepAlive keepAlive = new PacketKeepAlive();
|
||||||
@ -352,5 +376,35 @@ public class ClientConnection extends ChannelInboundHandlerAdapter {
|
|||||||
bossBar.setUuid(UUID.randomUUID());
|
bossBar.setUuid(UUID.randomUUID());
|
||||||
PACKET_BOSS_BAR = PreEncodedPacket.of(bossBar);
|
PACKET_BOSS_BAR = PreEncodedPacket.of(bossBar);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (server.getConfig().isUseTitle()) {
|
||||||
|
Title title = server.getConfig().getTitle();
|
||||||
|
|
||||||
|
PacketTitleSetTitle packetTitle = new PacketTitleSetTitle();
|
||||||
|
PacketTitleSetSubTitle packetSubtitle = new PacketTitleSetSubTitle();
|
||||||
|
PacketTitleTimes packetTimes = new PacketTitleTimes();
|
||||||
|
|
||||||
|
PacketTitleLegacy legacyTitle = new PacketTitleLegacy();
|
||||||
|
PacketTitleLegacy legacySubtitle = new PacketTitleLegacy();
|
||||||
|
PacketTitleLegacy legacyTimes = new PacketTitleLegacy();
|
||||||
|
|
||||||
|
packetTitle.setTitle(title.getTitle());
|
||||||
|
packetSubtitle.setSubtitle(title.getSubtitle());
|
||||||
|
packetTimes.setFadeIn(title.getFadeIn());
|
||||||
|
packetTimes.setStay(title.getStay());
|
||||||
|
packetTimes.setFadeOut(title.getFadeOut());
|
||||||
|
|
||||||
|
legacyTitle.setTitle(title);
|
||||||
|
legacySubtitle.setTitle(title);
|
||||||
|
legacyTimes.setTitle(title);
|
||||||
|
|
||||||
|
PACKET_TITLE_TITLE = PreEncodedPacket.of(packetTitle);
|
||||||
|
PACKET_TITLE_SUBTITLE = PreEncodedPacket.of(packetSubtitle);
|
||||||
|
PACKET_TITLE_TIMES = PreEncodedPacket.of(packetTimes);
|
||||||
|
|
||||||
|
PACKET_TITLE_LEGACY_TITLE = PreEncodedPacket.of(legacyTitle);
|
||||||
|
PACKET_TITLE_LEGACY_SUBTITLE = PreEncodedPacket.of(legacySubtitle);
|
||||||
|
PACKET_TITLE_LEGACY_TIMES = PreEncodedPacket.of(legacyTimes);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,65 @@
|
|||||||
|
package ru.nanit.limbo.protocol.packets.play;
|
||||||
|
|
||||||
|
import ru.nanit.limbo.protocol.ByteMessage;
|
||||||
|
import ru.nanit.limbo.protocol.PacketOut;
|
||||||
|
import ru.nanit.limbo.protocol.registry.Version;
|
||||||
|
import ru.nanit.limbo.server.data.Title;
|
||||||
|
|
||||||
|
public class PacketTitleLegacy implements PacketOut {
|
||||||
|
|
||||||
|
private Action action;
|
||||||
|
private final PacketTitleSetTitle title;
|
||||||
|
private final PacketTitleSetSubTitle subtitle;
|
||||||
|
private final PacketTitleTimes times;
|
||||||
|
|
||||||
|
public PacketTitleLegacy() {
|
||||||
|
this.title = new PacketTitleSetTitle();
|
||||||
|
this.subtitle = new PacketTitleSetSubTitle();
|
||||||
|
this.times = new PacketTitleTimes();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAction(Action action) {
|
||||||
|
this.action = action;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTitle(Title title) {
|
||||||
|
this.title.setTitle(title.getTitle());
|
||||||
|
this.subtitle.setSubtitle(title.getSubtitle());
|
||||||
|
this.times.setFadeIn(title.getFadeIn());
|
||||||
|
this.times.setStay(title.getStay());
|
||||||
|
this.times.setFadeOut(title.getFadeOut());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void encode(ByteMessage msg, Version version) {
|
||||||
|
msg.writeVarInt(action.getId(version));
|
||||||
|
|
||||||
|
switch (action) {
|
||||||
|
case SET_TITLE:
|
||||||
|
title.encode(msg, version);
|
||||||
|
break;
|
||||||
|
case SET_SUBTITLE:
|
||||||
|
subtitle.encode(msg, version);
|
||||||
|
break;
|
||||||
|
case SET_TIMES_AND_DISPLAY:
|
||||||
|
times.encode(msg, version);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum Action {
|
||||||
|
SET_TITLE(0),
|
||||||
|
SET_SUBTITLE(1),
|
||||||
|
SET_TIMES_AND_DISPLAY(3);
|
||||||
|
|
||||||
|
private final int id;
|
||||||
|
|
||||||
|
Action(int id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getId(Version version) {
|
||||||
|
return version.moreOrEqual(Version.V1_11) && id > 2 ? id - 1 : id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,20 @@
|
|||||||
|
package ru.nanit.limbo.protocol.packets.play;
|
||||||
|
|
||||||
|
import ru.nanit.limbo.protocol.ByteMessage;
|
||||||
|
import ru.nanit.limbo.protocol.PacketOut;
|
||||||
|
import ru.nanit.limbo.protocol.registry.Version;
|
||||||
|
|
||||||
|
public class PacketTitleSetSubTitle implements PacketOut {
|
||||||
|
|
||||||
|
private String subtitle;
|
||||||
|
|
||||||
|
public void setSubtitle(String subtitle) {
|
||||||
|
this.subtitle = subtitle;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void encode(ByteMessage msg, Version version) {
|
||||||
|
msg.writeString(subtitle);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,20 @@
|
|||||||
|
package ru.nanit.limbo.protocol.packets.play;
|
||||||
|
|
||||||
|
import ru.nanit.limbo.protocol.ByteMessage;
|
||||||
|
import ru.nanit.limbo.protocol.PacketOut;
|
||||||
|
import ru.nanit.limbo.protocol.registry.Version;
|
||||||
|
|
||||||
|
public class PacketTitleSetTitle implements PacketOut {
|
||||||
|
|
||||||
|
private String title;
|
||||||
|
|
||||||
|
public void setTitle(String title) {
|
||||||
|
this.title = title;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void encode(ByteMessage msg, Version version) {
|
||||||
|
msg.writeString(title);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,32 @@
|
|||||||
|
package ru.nanit.limbo.protocol.packets.play;
|
||||||
|
|
||||||
|
import ru.nanit.limbo.protocol.ByteMessage;
|
||||||
|
import ru.nanit.limbo.protocol.PacketOut;
|
||||||
|
import ru.nanit.limbo.protocol.registry.Version;
|
||||||
|
|
||||||
|
public class PacketTitleTimes implements PacketOut {
|
||||||
|
|
||||||
|
private int fadeIn;
|
||||||
|
private int stay;
|
||||||
|
private int fadeOut;
|
||||||
|
|
||||||
|
public void setFadeIn(int fadeIn) {
|
||||||
|
this.fadeIn = fadeIn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStay(int stay) {
|
||||||
|
this.stay = stay;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFadeOut(int fadeOut) {
|
||||||
|
this.fadeOut = fadeOut;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void encode(ByteMessage msg, Version version) {
|
||||||
|
msg.writeInt(fadeIn);
|
||||||
|
msg.writeInt(stay);
|
||||||
|
msg.writeInt(fadeOut);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
77
src/main/java/ru/nanit/limbo/server/data/Title.java
Normal file
77
src/main/java/ru/nanit/limbo/server/data/Title.java
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
package ru.nanit.limbo.server.data;
|
||||||
|
|
||||||
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
import org.spongepowered.configurate.ConfigurationNode;
|
||||||
|
import org.spongepowered.configurate.serialize.SerializationException;
|
||||||
|
import org.spongepowered.configurate.serialize.TypeSerializer;
|
||||||
|
import ru.nanit.limbo.util.Colors;
|
||||||
|
|
||||||
|
import java.lang.reflect.Type;
|
||||||
|
|
||||||
|
public class Title {
|
||||||
|
|
||||||
|
private String title;
|
||||||
|
private String subtitle;
|
||||||
|
private int fadeIn;
|
||||||
|
private int stay;
|
||||||
|
private int fadeOut;
|
||||||
|
|
||||||
|
public String getTitle() {
|
||||||
|
return title;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSubtitle() {
|
||||||
|
return subtitle;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getFadeIn() {
|
||||||
|
return fadeIn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getStay() {
|
||||||
|
return stay;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getFadeOut() {
|
||||||
|
return fadeOut;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTitle(String title) {
|
||||||
|
this.title = title;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSubtitle(String subtitle) {
|
||||||
|
this.subtitle = subtitle;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFadeIn(int fadeIn) {
|
||||||
|
this.fadeIn = fadeIn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStay(int stay) {
|
||||||
|
this.stay = stay;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFadeOut(int fadeOut) {
|
||||||
|
this.fadeOut = fadeOut;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Serializer implements TypeSerializer<Title> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Title deserialize(Type type, ConfigurationNode node) {
|
||||||
|
Title title = new Title();
|
||||||
|
title.setTitle(Colors.of(node.node("title").getString("")));
|
||||||
|
title.setSubtitle(Colors.of(node.node("subtitle").getString("")));
|
||||||
|
title.setFadeIn(node.node("fadeIn").getInt(10));
|
||||||
|
title.setStay(node.node("stay").getInt(100));
|
||||||
|
title.setFadeOut(node.node("fadeOut").getInt(10));
|
||||||
|
return title;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void serialize(Type type, @Nullable Title obj, ConfigurationNode node) {
|
||||||
|
// Not used
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -8,6 +8,7 @@ public final class Colors {
|
|||||||
private Colors() {}
|
private Colors() {}
|
||||||
|
|
||||||
public static String of(String text) {
|
public static String of(String text) {
|
||||||
|
if (text == null) return null;
|
||||||
return text.replace(CHAR_FROM, CHAR_TO);
|
return text.replace(CHAR_FROM, CHAR_TO);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,6 +49,20 @@ bossBar:
|
|||||||
# Available divisions: SOLID, DASHES_6, DASHES_10, DASHES_12, DASHES_20
|
# Available divisions: SOLID, DASHES_6, DASHES_10, DASHES_12, DASHES_20
|
||||||
division: SOLID
|
division: SOLID
|
||||||
|
|
||||||
|
# Display title and subtitle
|
||||||
|
title:
|
||||||
|
enable: true
|
||||||
|
# Set title text value empty, if you need only subtitle
|
||||||
|
title: '{"text": "&6&lWelcome to the Limbo!"}'
|
||||||
|
# Set subtitle text value empty, if you need only title
|
||||||
|
subtitle: '{"text": ""}'
|
||||||
|
# Fade in time in ticks (1 sec = 20 ticks)
|
||||||
|
fadeIn: 10
|
||||||
|
# Stay time in ticks
|
||||||
|
stay: 100
|
||||||
|
# Fade out time in ticks
|
||||||
|
fadeOut: 10
|
||||||
|
|
||||||
# Player info forwarding support.
|
# Player info forwarding support.
|
||||||
# Available types:
|
# Available types:
|
||||||
# - NONE
|
# - NONE
|
||||||
|
Loading…
x
Reference in New Issue
Block a user