私は Minecraft サーバーへのプラグインとして Java でコードを書いていますが、論理原則は本質的に一般的です。
public void doReviewMember(CommandSender playerSent) {
if (!reviewsMember.isEmpty()) {
Review doThis = null;
ArrayList<Review> players = new ArrayList<Review>();
ArrayList<Review> playersVIP = new ArrayList<Review>();
ArrayList<Review> playersVIPplus = new ArrayList<Review>();
for (int c1 = 0; c1 < reviewsMember.size(); c1++) {
if (Bukkit.getPlayer(reviewsMember.get(c1).getName()).hasPermission("reviewplugin.vipplus"))
playersVIPplus.add(reviewsMember.get(c1));
else if (Bukkit.getPlayer(reviewsMember.get(c1).getName()).hasPermission("reviewplugin.vip"))
playersVIP.add(reviewsMember.get(c1));
else players.add(reviewsMember.get(c1));
}
if (playersVIPplus.size() > 0)
doThis = playersVIPplus.get(0);
else if (playersVIP.size() > 0)
doThis = playersVIP.get(0);
else doThis = players.get(0);
Bukkit.getPlayer(playerSent.getName()).sendMessage("§4[§6ReviewPlugin§4] §eThis review is for §b" + doThis.getName());
Bukkit.getPlayer(playerSent.getName()).teleport(doThis.getLocation());
reviewsMember.remove(doThis);
if (reviewsMember.size() > 1)
Bukkit.getPlayer(playerSent.getName()).sendMessage("§4[§6ReviewPlugin§4] §eThere are " + reviewsMember.size() + " member reviews left to do.");
else if (reviewsMember.size() == 1)
Bukkit.getPlayer(playerSent.getName()).sendMessage("§4[§6ReviewPlugin§4] §eThere is " + reviewsMember.size() + " member review left to do.");
else
Bukkit.getPlayer(playerSent.getName()).sendMessage("§4[§6ReviewPlugin§4] §eThere are no more Member reviews to do at this time!");
}
else {
Bukkit.getPlayer(playerSent.getName()).sendMessage("§4[§6ReviewPlugin§4] §eThere are no more Member reviews to do at this time!");
}
}
for ループで index out of bounds エラーが発生していたので、どこが間違っているのかわかりません。これは、Windows 8 マシンでエラーなしでテストされましたが、Linux に実装すると、インデックスが範囲外エラーで毎回失敗しました。