我正在製作Mine Craft java服務器插件,並且我想向所有擁有權限或包含在數組中的玩家發送消息 - 名單。我有一個循環設置,但它似乎發送消息的次數與有線上玩家的次數相同。我如何防止/解決這個問題?提前致謝! :)Bukkit(Java)發送消息的次數與人在線差不多
public void checkStart() {
HashSet<Player> listToSet = new HashSet<Player>(this.plugin.pInGame);
ArrayList<Player> pInGameNoDup = new ArrayList<Player>(listToSet);
//^changing the ArrayList to a Hashset then back to Arraylist to avoid duplicates (maybe this is the issue?)
int sizeCheck = pInGameNoDup.size();
if (sizeCheck >= 2) {
for (Player p : Bukkit.getOnlinePlayers()) {
if (pInGameNoDup.contains(p) || p.isOp()) {
p.sendMessage(label + "The Game of DeathTag has begun! Now chosing who will be it...");
randomIt();
p.sendMessage(label + this.plugin.it.getName() + " has been randomly chosen to be it!");
}
}
} else {
for (Player p : Bukkit.getOnlinePlayers()) {
if (p.hasPermission("tag.join") || p.isOp()) {
p.sendMessage(label + "Not Enough People have joined, the game will not start");
setDefault();
}
}
}
}
你通過'Bukkit.getOnlinePlayers循環()的''而不是pInGameNoDup' – Squiddie
我改變了第一循環,但是我需要第二個循環遍歷所有的在線玩家,這樣每個人都可以看到遊戲不會開始 –