Skip to content

Commit

Permalink
remove player from started music on join
Browse files Browse the repository at this point in the history
this should help prevent pack delays from
muting nextbots
  • Loading branch information
TehBrian committed Nov 23, 2023
1 parent 8da787e commit c3bb96a
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions src/main/java/city/thefloating/floatyplugin/nextbot/Nate.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.PlayerLeashEntityEvent;
import org.bukkit.event.player.PlayerChangedWorldEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
Expand Down Expand Up @@ -309,28 +310,39 @@ private void startMusicTask(final Nextbot nextbot) {

@EventHandler
public void onPlayerRespawn(final PlayerPostRespawnEvent event) {
this.removeFromActiveMusic(event.getPlayer());
this.removeFromAllMusicLater(event.getPlayer());
}

@EventHandler
public void onPlayerChangedWorld(final PlayerChangedWorldEvent event) {
this.removeFromActiveMusic(event.getPlayer());
this.removeFromAllMusicLater(event.getPlayer());
}

@EventHandler
public void onPlayerQuit(final PlayerQuitEvent event) {
this.removeFromActiveMusic(event.getPlayer());
this.removeFromAllMusicLater(event.getPlayer());
}

private void removeFromActiveMusic(final Player player) {
@EventHandler
public void onPlayerJoin(final PlayerJoinEvent event) {
this.removeFromAllMusicLater(event.getPlayer());
}

private void removeFromAllMusic(final Player player) {
for (final Nextbot nextbot : this.nextbots) {
nextbot.startedMusic().remove(player);
}
}

private void removeFromAllMusicLater(final Player player) {
this.removeFromAllMusicLater(player, Duration.ofSeconds(2));
}

private void removeFromAllMusicLater(final Player player, final Duration delay) {
this.floatyPlugin.getServer().getScheduler().runTaskLater(
this.floatyPlugin,
() -> {
for (final Nextbot nextbot : this.nextbots) {
nextbot.startedMusic().remove(player);
}
},
Ticks.in(Duration.ofSeconds(2))
() -> this.removeFromAllMusic(player),
Ticks.in(delay)
);
}
//</editor-fold>
Expand Down

0 comments on commit c3bb96a

Please sign in to comment.