玩家似乎已登记进入Arraylist

时间:2017-03-25 09:21:47

标签: bukkit

我遇到这个问题,当我的倒计时到0并且其他球队没有球员时,球员所在的球队获胜。但事实并非如此,当倒计时为0时,两支球队都会获胜。为什么呢?

倒计时课程:

for(Player all2 : Bukkit.getOnlinePlayers()) {

            if(main.innocent.size() == 0) {
                Bukkit.broadcastMessage(Main.prefix + "§c§lTRAITORS §6has won the game with all innocents eliminated.");
                GameState.setGamestate(GameState.RESTARTING);

                TitleManager.sendTitle(all2, "§cGame. §c§lOVER!", "§eThanks for playing!", 40);

                for(Player all : Bukkit.getOnlinePlayers()) {
                    all.getInventory().clear();
                }
            }

            if(main.traitor.size() == 0) {
                Bukkit.broadcastMessage(Main.prefix + "§a§lINNOCENTS §6has won the game with all traitors eliminated.");
                GameState.setGamestate(GameState.RESTARTING);

                TitleManager.sendTitle(all2, "§cGame. §c§lOVER!", "§eThanks for playing!", 40);


            }

Arraylist class:

public static ArrayList<String> innocent = new ArrayList<String>();
public static ArrayList<String> traitor = new ArrayList<String>();

1 个答案:

答案 0 :(得分:1)

有点难以理解你的要求。如评论中所述,如果将播放器添加到ArrayLists是一个问题,那么您需要向我们展示该代码。

至于您发布的代码,效率相当低。尝试将其更改为

//Check if your countdown is 0 first? I don't have your class... can't help
if(main.innocent.size() == 0){
    Bukkit.broadcastMessage("Traitor win message");
    GameState.setGamestate(GameState.RESTARTING);
}else if(main.traitor.size() == 0){
    Bukkit.broadcastMessage("Innocent win message");
    GameState.setGamestate(GameState.RESTARTING);
}
...
if(GameState.isRestarting()){ //again, i dont have your class, you'll have to change this
    for(Player p : Bukkit.getOnlinePlayers()){
        TitleManager.sendTitle(all2, "§cGame. §c§lOVER!", "§eThanks for playing!", 40);
        p.getInventory().clear();
    }
}

这应该阻止两个团队获胜,并摆脱之前代码似乎产生的聊天垃圾邮件。如果您能够将剩下的代码交给我,我将非常乐意为您提供进一步的帮助。