Пробовал так:
Пробовал ещё 2 способа.
Через Bukkit.getScheduler() - НЕЛЬЗЯ ОТМЕНИТЬ.
Timer timer = new Timer(); - НЕЛЬЗЯ ВЫДАВАТЬ ЭФФЕКТЫ В АСИНК ПОТОКЕ
Java:
private static BukkitRunnable runnable;
public static void startInfection(Player player, Survival main) {
if(EntityDamageListener.infected.containsKey(player.getUniqueId())) {
int amount = EntityDamageListener.infected.get(player.getUniqueId());
if(amount < 2) {
return;
}
runnable = new BukkitRunnable() {
@Override
public void run() {
if(amount >= 6) {
player.addPotionEffect(PotionEffectType.WITHER.createEffect(60, 9));
player.addPotionEffect(PotionEffectType.CONFUSION.createEffect(60, 1));
player.addPotionEffect(PotionEffectType.BLINDNESS.createEffect(60, 1));
player.addPotionEffect(PotionEffectType.HUNGER.createEffect(60, 10));
} else if(amount == 5) {
player.addPotionEffect(PotionEffectType.WITHER.createEffect(60, 2));
}else if (amount >= 3) {
player.addPotionEffect(PotionEffectType.WITHER.createEffect(60, 0));
} else {
player.removePotionEffect(PotionEffectType.WITHER);
runnable.cancel();
}
}
};
runnable.runTaskTimer(main, 0, 20);
}
}
Пробовал ещё 2 способа.
Через Bukkit.getScheduler() - НЕЛЬЗЯ ОТМЕНИТЬ.
Timer timer = new Timer(); - НЕЛЬЗЯ ВЫДАВАТЬ ЭФФЕКТЫ В АСИНК ПОТОКЕ