New active sign, gets random warzone with players

This commit is contained in:
Connor Monahan 2014-01-07 17:59:08 -06:00
parent bc07a60b51
commit b011d3a46f
2 changed files with 22 additions and 0 deletions

View File

@ -912,6 +912,21 @@ public class War extends JavaPlugin {
return enabledZones;
}
/**
* Get a list of warzones that have players in them.
* @return List of enabled warzones with players.
*/
public List<Warzone> getActiveWarzones() {
List<Warzone> activeZones = new ArrayList<Warzone>(this.warzones.size());
for (Warzone zone : this.warzones) {
if (zone.getWarzoneConfig().getBoolean(WarzoneConfig.DISABLED) == false
&& zone.getPlayerCount() > 0) {
activeZones.add(zone);
}
}
return activeZones;
}
public void msg(CommandSender sender, String str) {
if (sender instanceof Player) {
StringBuilder output = new StringBuilder(ChatColor.GRAY.toString())

View File

@ -309,6 +309,13 @@ public class WarPlayerListener implements Listener {
int zone = random.nextInt(warzones.size());
Warzone random = warzones.get(zone);
player.teleport(random.getTeleport());
} else if (sign.getLine(1).equalsIgnoreCase("$active")) {
List<Warzone> warzones = War.war.getActiveWarzones();
if (warzones.size() == 0) warzones = War.war.getEnabledWarzones();
if (warzones.size() == 0) return;
int zone = random.nextInt(warzones.size());
Warzone random = warzones.get(zone);
player.teleport(random.getTeleport());
}
}
}