Messages are send in wrong order

Discussion in 'Plugin Development' started by jbeck18, May 14, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    jbeck18

    I am fairly new to bukkit and am trying to make a plugin that runs a simple version of hunger games. I have custom death msgs and a msg that appears when a player wins, however they are sent in the wrong order and I can't figure out why. I know this is a really minor thing, but it just bothers me that I cant fix it heres the code:

    Code:
    public void onPlayerDeath(PlayerDeathEvent e) {
           
            Player dead = (Player) e.getEntity().getPlayer();
            Player killer = (Player) e.getEntity().getKiller();
            int remaining = 0;
           
            if (inGame.get(dead) == true) {
                       
                World w = dead.getWorld();
                Location deathloc = dead.getLocation();
                w.strikeLightningEffect(deathloc);
           
                if(killer instanceof Player) {
                    e.setDeathMessage(ChatColor.DARK_RED + dead.getName() + ChatColor.AQUA + " was killed by " + ChatColor.DARK_RED + killer.getName());
                }
                else {
                    e.setDeathMessage(ChatColor.DARK_RED + dead.getName() + ChatColor.AQUA + " was killed");
                }
               
                inGame.put(dead, false);
               
                for (Player r : Bukkit.getOnlinePlayers()) {
                    if (inGame.get(r) == true) {
                        remaining++;
                    }
                    else{}
                }
               
                for (Player p : Bukkit.getOnlinePlayers()) {
                    p.sendMessage(ChatColor.AQUA + "There are " + ChatColor.DARK_RED + remaining + ChatColor.AQUA + " players remaining");
                }
               
                if(remaining == 1) {
                    Player winner1 = null;
                    String winner = "";
                    for (Player contestants : Bukkit.getOnlinePlayers()) {
                        if (inGame.get(contestants) == true) {
                            winner1 = contestants;
                            winner = winner1.getDisplayName();
                        }
                        else {}
                    }
                   
                    for (Player p : Bukkit.getOnlinePlayers()) {
                        p.sendMessage(ChatColor.LIGHT_PURPLE + winner + ChatColor.LIGHT_PURPLE + " has won the game!");
                    }
                    inGame.put(winner1,false);
                }
            }
            else {}
        }
    
    Sorry if its really messy, like I said previously, im fairly new to it. Any feedback is appreciated :)
     
  2. Offline

    Iroh

    Moved to plugin dev.
     
  3. Offline

    Nghtmr9999

    When you say the messages "are sent in the wrong order", could you clarify what order that is? From what it sounds like from your post, you want the death message to play before the victory message. Would that be correct?
     
Thread Status:
Not open for further replies.

Share This Page