Skip to content

Commit

Permalink
Merge pull request #93 from AlbertoRutigliano/bug-fixes
Browse files Browse the repository at this point in the history
Bug fixes
  • Loading branch information
AlbertoRutigliano authored Jun 29, 2024
2 parents f8bd8df + 1c3c28e commit 0e355c5
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/main/java/lar/minecraft/hg/managers/PlayerManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.SkullMeta;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;

import lar.minecraft.hg.SpigotPlugin;
import lar.minecraft.hg.entities.PlayerExtra;
Expand All @@ -35,7 +37,7 @@ public class PlayerManager implements Listener {

public static Map<UUID, PlayerExtra> playerExtras = new HashMap<>();

private int winnerParticleEffectTaskId = 0;
private int winnerParticleEffectTaskId = -1;

@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
Expand All @@ -62,7 +64,8 @@ public void onPlayerJoin(PlayerJoinEvent event) {
winnerParticleEffectTaskId = SpigotPlugin.server.getScheduler().scheduleSyncRepeatingTask(SpigotPlugin.getPlugin(SpigotPlugin.class), new Runnable() {
@Override
public void run() {
if (PlayerManager.playerExtras.get(player.getUniqueId()).isLastWinner()) {
PotionEffect invisibilityPotionEffect = player.getPotionEffect(PotionEffectType.INVISIBILITY);
if (invisibilityPotionEffect == null && PlayerManager.playerExtras.get(player.getUniqueId()) != null && PlayerManager.playerExtras.get(player.getUniqueId()).isLastWinner()) {
SpigotPlugin.server.getWorld(player.getWorld().getName()).spawnParticle(Particle.DRAGON_BREATH, player.getLocation().getX(), player.getLocation().getY(), player.getLocation().getZ(), 40, -0.5, 0.5, -0.5, 0.01);
}
}
Expand Down Expand Up @@ -140,19 +143,19 @@ public void onPlayerDeath(PlayerDeathEvent event){
@EventHandler
public void onPlayerQuit(PlayerQuitEvent event){
event.setQuitMessage(null);
if (SpigotPlugin.isWinning() || SpigotPlugin.isLobby()) {
// Stop reproducing particles of the winner player
PlayerExtra playerExtra = PlayerManager.playerExtras.getOrDefault(event.getPlayer().getUniqueId(), null);
if (playerExtra != null && playerExtra.isLastWinner()) {
SpigotPlugin.server.getScheduler().cancelTask(winnerParticleEffectTaskId);
}
if (SpigotPlugin.isWaitingForStart() || SpigotPlugin.isLobby() || SpigotPlugin.isWinning()) {
PlayerManager.playerExtras.remove(event.getPlayer().getUniqueId());
}
if (SpigotPlugin.isSafeArea() || SpigotPlugin.isWinning() || SpigotPlugin.isPlaying()) {
if (SpigotPlugin.isSafeArea() || SpigotPlugin.isPlaying() || SpigotPlugin.isWinning()) {
Player player = event.getPlayer();
player.getWorld().strikeLightningEffect(player.getLocation());
ServerManager.sendSound(Sound.ENTITY_LIGHTNING_BOLT_THUNDER);
}
// Stop reproducing particles of the winner player
PlayerExtra playerExtra = PlayerManager.playerExtras.getOrDefault(event.getPlayer().getUniqueId(), null);
if (playerExtra != null && playerExtra.isLastWinner()) {
SpigotPlugin.server.getScheduler().cancelTask(winnerParticleEffectTaskId);
}
}

/**
Expand Down

0 comments on commit 0e355c5

Please sign in to comment.