From 2e79421d49b71429d91acb328b3562d5e7aede08 Mon Sep 17 00:00:00 2001 From: OptimisticDev <173472493+OptimisticDeving@users.noreply.github.com> Date: Thu, 1 Aug 2024 08:38:47 +0000 Subject: [PATCH] Fix Adventure usage for join title & subtitle (#358) --- .../modules/player/PlayerConnection.java | 31 +++++++++++++------ 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/src/main/java/pw/kaboom/extras/modules/player/PlayerConnection.java b/src/main/java/pw/kaboom/extras/modules/player/PlayerConnection.java index 6f1ee1d..186ef21 100644 --- a/src/main/java/pw/kaboom/extras/modules/player/PlayerConnection.java +++ b/src/main/java/pw/kaboom/extras/modules/player/PlayerConnection.java @@ -4,6 +4,7 @@ import com.destroystokyo.paper.event.profile.PreLookupProfileEvent; import com.destroystokyo.paper.profile.ProfileProperty; import com.google.common.base.Charsets; import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; import net.kyori.adventure.title.Title; import org.bukkit.Bukkit; import org.bukkit.Location; @@ -29,8 +30,22 @@ import java.util.concurrent.ThreadLocalRandom; public final class PlayerConnection implements Listener { private static final FileConfiguration CONFIG = JavaPlugin.getPlugin(Main.class).getConfig(); - private static final String TITLE = CONFIG.getString("playerJoinTitle"); - private static final String SUBTITLE = CONFIG.getString("playerJoinSubtitle"); + private static final Component TITLE = + LegacyComponentSerializer.legacySection() + .deserialize( + CONFIG.getString( + "playerJoinTitle", + "" + ) + ); + private static final Component SUBTITLE = + LegacyComponentSerializer.legacySection() + .deserialize( + CONFIG.getString( + "playerJoinSubtitle", + "" + ) + ); private static final Duration FADE_IN = Duration.ofMillis(50); private static final Duration STAY = Duration.ofMillis(8000); private static final Duration FADE_OUT = Duration.ofMillis(250); @@ -70,13 +85,11 @@ public final class PlayerConnection implements Listener { void onPlayerJoin(final PlayerJoinEvent event) { final Player player = event.getPlayer(); - if (TITLE != null || SUBTITLE != null) { - player.showTitle(Title.title( - Component.text(TITLE), - Component.text(SUBTITLE), - Title.Times.times(FADE_IN, STAY, FADE_OUT) - )); - } + player.showTitle(Title.title( + TITLE, + SUBTITLE, + Title.Times.times(FADE_IN, STAY, FADE_OUT) + )); ServerTabComplete.getLoginNameList().put(player.getUniqueId(), player.getName()); }