Fix Adventure usage for join title & subtitle (#358)

This commit is contained in:
OptimisticDev 2024-08-01 08:38:47 +00:00 committed by GitHub
parent e20467b7af
commit 2e79421d49
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -4,6 +4,7 @@ import com.destroystokyo.paper.event.profile.PreLookupProfileEvent;
import com.destroystokyo.paper.profile.ProfileProperty; import com.destroystokyo.paper.profile.ProfileProperty;
import com.google.common.base.Charsets; import com.google.common.base.Charsets;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import net.kyori.adventure.title.Title; import net.kyori.adventure.title.Title;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
@ -29,8 +30,22 @@ import java.util.concurrent.ThreadLocalRandom;
public final class PlayerConnection implements Listener { public final class PlayerConnection implements Listener {
private static final FileConfiguration CONFIG = JavaPlugin.getPlugin(Main.class).getConfig(); private static final FileConfiguration CONFIG = JavaPlugin.getPlugin(Main.class).getConfig();
private static final String TITLE = CONFIG.getString("playerJoinTitle"); private static final Component TITLE =
private static final String SUBTITLE = CONFIG.getString("playerJoinSubtitle"); 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 FADE_IN = Duration.ofMillis(50);
private static final Duration STAY = Duration.ofMillis(8000); private static final Duration STAY = Duration.ofMillis(8000);
private static final Duration FADE_OUT = Duration.ofMillis(250); private static final Duration FADE_OUT = Duration.ofMillis(250);
@ -70,13 +85,11 @@ public final class PlayerConnection implements Listener {
void onPlayerJoin(final PlayerJoinEvent event) { void onPlayerJoin(final PlayerJoinEvent event) {
final Player player = event.getPlayer(); final Player player = event.getPlayer();
if (TITLE != null || SUBTITLE != null) { player.showTitle(Title.title(
player.showTitle(Title.title( TITLE,
Component.text(TITLE), SUBTITLE,
Component.text(SUBTITLE), Title.Times.times(FADE_IN, STAY, FADE_OUT)
Title.Times.times(FADE_IN, STAY, FADE_OUT) ));
));
}
ServerTabComplete.getLoginNameList().put(player.getUniqueId(), player.getName()); ServerTabComplete.getLoginNameList().put(player.getUniqueId(), player.getName());
} }