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

Commit

Permalink
Finishing touches
Browse files Browse the repository at this point in the history
  • Loading branch information
EsotericEnderman committed Sep 2, 2024
1 parent c21218e commit a4b082c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 24 deletions.
8 changes: 2 additions & 6 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ fun pascalcase(kebabcaseString: String): String {
return pascalCaseString
}

description = "A plugin for displaying titles."
description = "A plugin to display a title and a changing subtitle."

val mainProjectAuthor = "Slqmy"
val projectAuthors = listOfNotNull(mainProjectAuthor)
Expand All @@ -48,7 +48,7 @@ val topLevelDomain = "net"
val projectNameString = rootProject.name

group = topLevelDomain + groupStringSeparator + mainProjectAuthor.lowercase() + groupStringSeparator + snakecase(projectNameString)
version = "0.0.3"
version = "0.0.4"

val buildDirectoryString = buildDir.toString()

Expand All @@ -72,10 +72,6 @@ repositories {

dependencies {
paperweight.paperDevBundle(paperApiVersion + "-R0.1-SNAPSHOT")

implementation("dev.jorel" , "commandapi-bukkit-shade-mojang-mapped" , "9.5.1")

implementation("net.lingala.zip4j", "zip4j", "2.11.5")
}

tasks {
Expand Down
22 changes: 9 additions & 13 deletions src/main/java/net/slqmy/title_plugin/TitlePlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,8 @@
public final class TitlePlugin extends JavaPlugin implements Listener {

private Component titleComponent;

private List<TextComponent> changingSubtitleComponents;

private long secondsBeforeChaning;
private long secondsBeforeChanging;

@Override
public void onEnable() {
Expand All @@ -39,11 +37,9 @@ public void onEnable() {

FileConfiguration configuration = getConfig();

titleComponent = Component.text(ChatColor.translateAlternateColorCodes('&', configuration.getString("title", "Title")));

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();

secondsBeforeChaning = configuration.getLong("seconds-before-changing", 5L);
secondsBeforeChanging = configuration.getLong("seconds-before-changing", 5L);
}

@EventHandler
Expand All @@ -52,19 +48,19 @@ public void onResourcePackLoad(PlayerJoinEvent event) {

new BukkitRunnable() {

private int subTitleIndex = 0;
private int subtitleIndex = 0;

@Override
public void run() {
player.sendTitlePart(TitlePart.TITLE, titleComponent);
player.sendTitlePart(TitlePart.SUBTITLE, changingSubtitleComponents.get(subTitleIndex));
player.sendTitlePart(TitlePart.SUBTITLE, changingSubtitleComponents.get(subtitleIndex));
player.sendTitlePart(TitlePart.TIMES, Title.Times.times(Duration.ZERO, Duration.ofSeconds(10L), Duration.ZERO));

getLogger().info(changingSubtitleComponents.get(subTitleIndex).toString());
getLogger().info(changingSubtitleComponents.get(subtitleIndex).toString());

subTitleIndex++;
subTitleIndex %= changingSubtitleComponents.size();
subtitleIndex++;
subtitleIndex %= changingSubtitleComponents.size();
}
}.runTaskTimer(this, 0L, secondsBeforeChaning * 20L);
}.runTaskTimer(this, 0L, secondsBeforeChanging * 20L);
}
}
10 changes: 5 additions & 5 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# This is the title that will be displayed once a player joins.
title: "&atitle"
title: "&aTitle"

# The subtitles that will be displayed.
# The subtitles that will be displayed periodically as defined with 'seconds-before-changing'.
subtitle:
- "&asub1"
- "&asub2"
- "&asub3"
- "&aSubtitle 1"
- "&aSubtitle 2"
- "&aSubtitle 3"

# The time in between subtitles displaying.
seconds-before-changing: 5

0 comments on commit a4b082c

Please sign in to comment.