Files
Project-CrankedPvP/CagePvP/src/main/java/net/crankedpvp/wildpvp/immune/Immune.java
T
2026-10-12 13:57:05 -03:00

64 lines
3.2 KiB
Java

package net.crankedpvp.wildpvp.immune;
import net.crankedpvp.wildpvp.CagePvPPlugin;
import net.crankedpvp.wildpvp.utils.TitleManager;
import org.bukkit.ChatColor;
import org.bukkit.Sound;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
public class Immune {
private final CagePvPPlugin instance;
private final Player player;
private boolean cancelled = false;
public Immune(CagePvPPlugin instance, Player player) {
this.instance = instance;
this.player = player;
}
public Player getPlayer() {
return this.player;
}
public void setCancelled(boolean cancelled) {
this.cancelled = cancelled;
}
public boolean isCancelled() {
return this.cancelled;
}
public void start() {
final ImmuneManager immuneManager = this.instance.getImmuneManager();
final FileConfiguration configLoad = this.instance.getConfig();
this.player.sendMessage(ChatColor.translateAlternateColorCodes('&', configLoad.getString("Immune.Countdown.Started.Message")));
(new BukkitRunnable() {
int countdown = 20;
public void run() {
if (!Immune.this.cancelled && Immune.this.player.isOnline() && this.countdown >= 0) {
if (this.countdown == 15 || this.countdown == 10 || this.countdown > 0 && this.countdown <= 5) {
Immune.this.player.sendMessage(ChatColor.translateAlternateColorCodes('&', configLoad.getString("Immune.Countdown.Ending.Message").replace("%countdown", String.valueOf(this.countdown))));
TitleManager.sendTitle(Immune.this.player, ChatColor.translateAlternateColorCodes('&', configLoad.getString("Immune.Countdown.Ending.Title.Title").replace("%countdown", String.valueOf(this.countdown))), ChatColor.translateAlternateColorCodes('&', configLoad.getString("Immune.Countdown.Ending.Title.SubTitle").replace("%countdown", String.valueOf(this.countdown))), 0, 30, 0);
Immune.this.player.playSound(Immune.this.player.getLocation(), Sound.NOTE_STICKS, 1.0F, 1.0F);
} else if (this.countdown == 0) {
Immune.this.cancelled = true;
this.cancel();
immuneManager.removeImmune(Immune.this.player);
Immune.this.player.sendMessage(ChatColor.translateAlternateColorCodes('&', configLoad.getString("Immune.Countdown.Ended.Message").replace("%countdown", String.valueOf(this.countdown))));
TitleManager.sendTitle(Immune.this.player, ChatColor.translateAlternateColorCodes('&', configLoad.getString("Immune.Countdown.Ended.Title.Title").replace("%countdown", String.valueOf(this.countdown))), ChatColor.translateAlternateColorCodes('&', configLoad.getString("Immune.Countdown.Ended.Title.SubTitle").replace("%countdown", String.valueOf(this.countdown))), 0, 30, 10);
Immune.this.player.playSound(Immune.this.player.getLocation(), Sound.FIZZ, 1.0F, 1.0F);
}
--this.countdown;
} else {
immuneManager.removeImmune(Immune.this.player);
this.cancel();
}
}
}).runTaskTimerAsynchronously(this.instance, 0L, 20L);
}
}