Skip to content
This repository has been archived by the owner on Dec 7, 2024. It is now read-only.

Commit

Permalink
Implement fading
Browse files Browse the repository at this point in the history
  • Loading branch information
esotericenderman committed Sep 2, 2024
1 parent 4c09ef9 commit a30b62e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
10 changes: 9 additions & 1 deletion src/main/java/net/slqmy/title_plugin/TitlePlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ public final class TitlePlugin extends JavaPlugin implements Listener {
private List<TextComponent> changingSubtitleComponents;
private long secondsBeforeChanging;

private long fadeInTime;
private long stayTime;
private long fadeOutTime;

@Override
public void onEnable() {
getDataFolder().mkdir();
Expand All @@ -40,6 +44,10 @@ public void onEnable() {
titleComponent = Component.text(ChatColor.translateAlternateColorCodes('&', configuration.getString("title", "Title (can be changed in config.yml)")));
changingSubtitleComponents = (List<TextComponent>) 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
Expand All @@ -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());

Expand Down
10 changes: 10 additions & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit a30b62e

Please sign in to comment.