I want to make a plugin which gives a player night vision efect after typing a command and it is working but i also want to add if player is on this arraylist its giving an efect after dying, but it looks like after EventHandler its not loading players from arraylist.
public class Gamma implements CommandExecutor, Listener {
private ArrayList<Player> gammaList = new ArrayList<>();
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
Player player = (Player) sender;
PotionEffect potionEffect = player.getPotionEffect(PotionEffectType.NIGHT_VISION);
if (gammaList.contains(player)) {
gammaList.remove(player);
player.sendMessage(ChatColor.GREEN + "Pomyslnie" + ChatColor.RED + " usunieto" + ChatColor.GREEN + " efekt gammy!");
player.removePotionEffect(PotionEffectType.NIGHT_VISION);
} else if (!gammaList.contains(player)) {
gammaList.add(player);
player.sendMessage(ChatColor.GREEN + "Pomyslnie" + ChatColor.DARK_GREEN + " nadano" + ChatColor.GREEN + " efekt gammy!");
player.addPotionEffect(new PotionEffect(PotionEffectType.NIGHT_VISION, Integer.MAX_VALUE, 1));
}
return true;
}
@EventHandler
public void onPlayerDie(EntityResurrectEvent event) {
Player player = (Player) event.getEntity();
if (gammaList.contains(player)) {
player.addPotionEffect(new PotionEffect(PotionEffectType.NIGHT_VISION, Integer.MAX_VALUE, 1));
}
}
}
Sb know what should I change in this code?