Solved Not multiple players getting infected, just one

Discussion in 'Plugin Development' started by voltywolty, Nov 28, 2021.

  1. Offline

    voltywolty

    I've created a plague that players get infected with. However, rather than half of the lobby getting the plague, only one person gets the plague and gets the same message over and over depending on how many players there are.

    The goal of this is to have 4 monsters in total if the lobby count is greater than 7. If there are less than 7, it just takes half of the lobby and infect them. However, rather than infecting half of the lobby, it just infects one person and sends them the message that they're infected x amount of times. Not too sure where I'm going wrong, but if someone could help me out, that'd be great.

    Code (open)

    Code:
    package main.me.volt.dvz.events;
    
    import com.nisovin.magicspells.MagicSpells;
    import com.nisovin.magicspells.mana.ManaChangeReason;
    import main.me.volt.dvz.DvZ;
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.entity.Player;
    import org.bukkit.potion.PotionEffect;
    import org.bukkit.potion.PotionEffectType;
    
    import java.util.*;
    
    public class PlagueEvent extends GameEvent {
        private Set<Player> plagued = new HashSet<>();
    
        public PlagueEvent(DvZ plugin) {
            super(plugin);
        }
    
        public String getName() {
            return "plague";
        }
    
        public void run() {
            List<UUID> players = new ArrayList<>();
            for (Player p : Bukkit.getOnlinePlayers()) {
                players.add(p.getUniqueId());
                p.sendMessage("You feel others around you start to feel " + ChatColor.GREEN + "ill...");
            }
    
            int monsterCount = this.plugin.monsters.size();
            int monstersWanted = 4;
    
            if (Bukkit.getOnlinePlayers().size() <= 7) {
                monstersWanted = Bukkit.getOnlinePlayers().size() / 2;
            }
            System.out.println("Monster Count: " + monsterCount + " | Monsters Wanted: " + monstersWanted);
    
            if (monsterCount < monstersWanted) {
                for (int i = monsterCount; i < monstersWanted; i++) {
                    System.out.println("Monsters not full. Finding more victims.");
    
                    for (UUID uuid : players) {
                        Player player = Bukkit.getPlayer(uuid);
    
                        if (player == null)
                            continue;
    
                        if (!this.plugin.dwarves.contains(player.getPlayer())) {
                            System.out.println("Tried to infect " + player.getName() + ", but that player is not a dwarf!");
                            continue;
                        }
                        if (this.plagued.contains(player.getPlayer())) {
                            System.out.println("Tried to infect " + player.getName() + ", but that player already has the plague!");
                        }
    
                        System.out.println("Player " + player.getName() + " has been given the plague!");
                        plaguePlayer(player);
                        break;
                    }
                }
            }
            this.plugin.releaseMonsters();
        }
    
        private void plaguePlayer(final Player player) {
            this.plagued.add(player.getPlayer());
    
            player.addPotionEffect(new PotionEffect(PotionEffectType.WITHER, Integer.MAX_VALUE, 3));
            player.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, Integer.MAX_VALUE, 1));
            player.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, Integer.MAX_VALUE, 2));
            player.addPotionEffect(new PotionEffect(PotionEffectType.WEAKNESS, Integer.MAX_VALUE, 4));
            player.addPotionEffect(new PotionEffect(PotionEffectType.SLOW_DIGGING, Integer.MAX_VALUE, 2));
    
            if (player.getHealth() > 20.0D) {
                player.setHealth(20.0D);
            }
            MagicSpells.getManaHandler().addMana(player, -1000, ManaChangeReason.OTHER);
    
            player.sendMessage(ChatColor.DARK_RED + "You have contracted the " + ChatColor.GREEN + "Zombie Plague" + ChatColor.DARK_RED + "!");
            Bukkit.getScheduler().scheduleSyncDelayedTask(this.plugin, new Runnable() {
                public void run() {
                    if (player.isValid() && PlagueEvent.this.plugin.dwarves.contains(player.getPlayer())) {
                        player.setHealth(0.0D);
                    }
                }
            }, 600L);
        }
    
        public void setDwarf(Player paramPlayer) {
            this.plagued.remove(paramPlayer);
        }
    
        public boolean deathCountsAsKillForMonsterTeam(Player paramPlayer) {
            return !this.plagued.contains(paramPlayer);
        }
    
        public DamageResult checkDamage(Player attacker, Player defender) {
            if (this.plugin.dwarves.contains(attacker) && this.plugin.dwarves.contains(defender) && this.plagued.contains(defender)) {
                return DamageResult.ALLOW;
            }
            return DamageResult.NORMAL;
        }
    }
    
     
  2. Offline

    timtower Administrator Administrator Moderator

    @voltywolty You have a break without a check for it
     
  3. Offline

    voltywolty

    You’re right.
     

Share This Page