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

Commit

Permalink
Send titles once player has joined and loaded resource pack
Browse files Browse the repository at this point in the history
  • Loading branch information
esotericenderman committed Sep 3, 2024
1 parent df143a5 commit 3f2eb6e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 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.8"
version = "0.0.9"

val buildDirectoryString = buildDir.toString()

Expand Down
33 changes: 17 additions & 16 deletions src/main/java/net/slqmy/title_plugin/TitlePlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
@DefaultQualifier(NonNull.class)
public final class TitlePlugin extends JavaPlugin implements Listener {

private final List<UUID> alreadySentTitlePlayers = new ArrayList<>();;
private final List<UUID> resourcePackLoadedPlayers = new ArrayList<>();
private final List<UUID> joinedPlayers = new ArrayList<>();;

private Component titleComponent;
private List<TextComponent> changingSubtitleComponents;
Expand Down Expand Up @@ -62,33 +63,36 @@ public void onResourcePackLoad(PlayerJoinEvent event) {
Player player = event.getPlayer();
UUID playerUuid = player.getUniqueId();

if (alreadySentTitlePlayers.contains(playerUuid)) {
return;
}
joinedPlayers.add(playerUuid);

new TitleRunnable(this, player);

alreadySentTitlePlayers.add(playerUuid);
if (resourcePackLoadedPlayers.contains(playerUuid)) {
new TitleRunnable(this, player);
}
}

@EventHandler
public void onResourcePackLoad(PlayerResourcePackStatusEvent event) {
if (event.getStatus() != PlayerResourcePackStatusEvent.Status.SUCCESSFULLY_LOADED) {
return;
}

Player player = event.getPlayer();
UUID playerUuid = player.getUniqueId();

if (alreadySentTitlePlayers.contains(playerUuid)) {
return;
}
resourcePackLoadedPlayers.add(playerUuid);

if (event.getStatus() == PlayerResourcePackStatusEvent.Status.SUCCESSFULLY_LOADED) {
if (joinedPlayers.contains(playerUuid)) {
new TitleRunnable(this, player);
alreadySentTitlePlayers.add(playerUuid);
}
}

@EventHandler
public void onQuit(PlayerQuitEvent event) {
alreadySentTitlePlayers.remove(event.getPlayer().getUniqueId());
Player player = event.getPlayer();
UUID playerUuid = player.getUniqueId();

joinedPlayers.remove(playerUuid);
resourcePackLoadedPlayers.remove(playerUuid);
}

private final class TitleRunnable extends BukkitRunnable {
Expand All @@ -113,9 +117,6 @@ public void run() {
player.sendTitlePart(TitlePart.TITLE, titleComponent);
player.sendTitlePart(TitlePart.SUBTITLE, changingSubtitleComponents.get(subtitleIndex));
player.sendTitlePart(TitlePart.TIMES, Title.Times.times(Duration.ofSeconds(fadeInTime), Duration.ofSeconds(stayTime), Duration.ofSeconds(fadeOutTime)));
} catch (Exception exception) {
return;
}

subtitleIndex++;
if (subtitleIndex == changingSubtitleComponents.size()) {
Expand Down

0 comments on commit 3f2eb6e

Please sign in to comment.