Only randomly teleport to zones that are enabled

This commit is contained in:
Connor Monahan 2014-01-07 17:51:49 -06:00
parent dc764de258
commit bc07a60b51
2 changed files with 18 additions and 2 deletions

View File

@ -898,6 +898,20 @@ public class War extends JavaPlugin {
return this.warzones;
}
/**
* Get a list of warzones that are not disabled.
* @return List of enabled warzones.
*/
public List<Warzone> getEnabledWarzones() {
List<Warzone> enabledZones = new ArrayList<Warzone>(this.warzones.size());
for (Warzone zone : this.warzones) {
if (zone.getWarzoneConfig().getBoolean(WarzoneConfig.DISABLED) == false) {
enabledZones.add(zone);
}
}
return enabledZones;
}
public void msg(CommandSender sender, String str) {
if (sender instanceof Player) {
StringBuilder output = new StringBuilder(ChatColor.GRAY.toString())

View File

@ -304,8 +304,10 @@ public class WarPlayerListener implements Listener {
if (indicated != null) {
player.teleport(indicated.getTeleport());
} else if (sign.getLine(1).equalsIgnoreCase("$random")) {
int zone = random.nextInt(War.war.getWarzones().size());
Warzone random = War.war.getWarzones().get(zone);
List<Warzone> warzones = War.war.getEnabledWarzones();
if (warzones.size() == 0) return;
int zone = random.nextInt(warzones.size());
Warzone random = warzones.get(zone);
player.teleport(random.getTeleport());
}
}