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

Commit

Permalink
Fix sending title
Browse files Browse the repository at this point in the history
  • Loading branch information
EsotericEnderman committed Sep 2, 2024
1 parent 9bad038 commit c21218e
Showing 1 changed file with 17 additions and 19 deletions.
36 changes: 17 additions & 19 deletions src/main/java/net/slqmy/title_plugin/TitlePlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,21 @@
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerResourcePackStatusEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.framework.qual.DefaultQualifier;

import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.title.Title;
import net.kyori.adventure.title.TitlePart;
import net.md_5.bungee.api.ChatColor;

import java.util.List;
import java.util.stream.Stream;
import java.time.Duration;

@DefaultQualifier(NonNull.class)
public final class TitlePlugin extends JavaPlugin implements Listener {
Expand Down Expand Up @@ -45,28 +47,24 @@ public void onEnable() {
}

@EventHandler
public void onResourcePackLoad(PlayerResourcePackStatusEvent event) {
PlayerResourcePackStatusEvent.Status status = event.getStatus();
public void onResourcePackLoad(PlayerJoinEvent event) {
Player player = event.getPlayer();

if (status.equals(PlayerResourcePackStatusEvent.Status.SUCCESSFULLY_LOADED)) {
Player player = event.getPlayer();
new BukkitRunnable() {

player.sendTitlePart(TitlePart.TITLE, titleComponent);
private int subTitleIndex = 0;

new BukkitRunnable() {
@Override
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));

private int subTitleIndex = 0;
getLogger().info(changingSubtitleComponents.get(subTitleIndex).toString());

@Override
public void run() {

player.sendTitlePart(TitlePart.SUBTITLE, changingSubtitleComponents.get(subTitleIndex));

subTitleIndex++;
subTitleIndex %= changingSubtitleComponents.size();
}

}.runTaskTimer(this, secondsBeforeChaning * 20L, secondsBeforeChaning * 20L);
}
subTitleIndex++;
subTitleIndex %= changingSubtitleComponents.size();
}
}.runTaskTimer(this, 0L, secondsBeforeChaning * 20L);
}
}

0 comments on commit c21218e

Please sign in to comment.