From a30b62ee2b40df8c381827099c9c8f448f1ec292 Mon Sep 17 00:00:00 2001 From: Esoteric Enderman <90862990+EsotericEnderman@users.noreply.github.com> Date: Mon, 2 Sep 2024 23:46:00 +0100 Subject: [PATCH] Implement fading --- build.gradle.kts | 2 +- src/main/java/net/slqmy/title_plugin/TitlePlugin.java | 10 +++++++++- src/main/resources/config.yml | 10 ++++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 6b494d8..057d0df 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -48,7 +48,7 @@ val topLevelDomain = "net" val projectNameString = rootProject.name group = topLevelDomain + groupStringSeparator + mainProjectAuthor.lowercase() + groupStringSeparator + snakecase(projectNameString) -version = "0.0.5" +version = "0.0.6" val buildDirectoryString = buildDir.toString() diff --git a/src/main/java/net/slqmy/title_plugin/TitlePlugin.java b/src/main/java/net/slqmy/title_plugin/TitlePlugin.java index 6d587cc..e15709e 100644 --- a/src/main/java/net/slqmy/title_plugin/TitlePlugin.java +++ b/src/main/java/net/slqmy/title_plugin/TitlePlugin.java @@ -28,6 +28,10 @@ public final class TitlePlugin extends JavaPlugin implements Listener { private List changingSubtitleComponents; private long secondsBeforeChanging; + private long fadeInTime; + private long stayTime; + private long fadeOutTime; + @Override public void onEnable() { getDataFolder().mkdir(); @@ -40,6 +44,10 @@ public void onEnable() { titleComponent = Component.text(ChatColor.translateAlternateColorCodes('&', configuration.getString("title", "Title (can be changed in config.yml)"))); changingSubtitleComponents = (List) Stream.of((configuration.getList("subtitle", List.of())).toArray(String[]::new)).map((string) -> Component.text(ChatColor.translateAlternateColorCodes('&', string))).toList(); secondsBeforeChanging = configuration.getLong("seconds-before-changing", 5L); + + fadeInTime = configuration.getLong("fade-in-time", 0L); + stayTime = configuration.getLong("stay-time", 10L); + fadeOutTime = configuration.getLong("fade-out-time", 0L); } @EventHandler @@ -54,7 +62,7 @@ public void onResourcePackLoad(PlayerJoinEvent event) { public void run() { player.sendTitlePart(TitlePart.TITLE, titleComponent); player.sendTitlePart(TitlePart.SUBTITLE, changingSubtitleComponents.get(subtitleIndex)); - player.sendTitlePart(TitlePart.TIMES, Title.Times.times(Duration.ZERO, Duration.ofSeconds(10L), Duration.ZERO)); + player.sendTitlePart(TitlePart.TIMES, Title.Times.times(Duration.ofSeconds(fadeInTime), Duration.ofSeconds(stayTime), Duration.ofSeconds(fadeOutTime))); getLogger().info(changingSubtitleComponents.get(subtitleIndex).toString()); diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index e4fda31..4b7a925 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -9,3 +9,13 @@ subtitle: # The time in between subtitles displaying. seconds-before-changing: 5 + +# Fading config +# How long it takes for the title/subtitle to appear on screen. +fade-in-time: 1 + +# How long it stays without fading. +stay-time: 1 + +# How long it takes for the title/subtitle to fade out. +fade-out-time: 1