Saber-Factions/src/org/mcteam/factions/commands/FCommandList.java
Brettflan b490c5f196 Laundry list of changes for 1.2.0 release:
/f map now has a nifty faction name key  (LexManos)
There are now War Zones; these work similar to Safe Zones, except PvP is enabled and monsters are not blocked  (Brettflan)
Players now only regenerate power while actually online  (Brettflan)
New command available to prevent power loss in specific worlds  (Brettflan)
New command available to prevent faction land claims in specific worlds (doesn't affect safezone and warzone claims)  (Brettflan)
New command to unclaim all safezone areas  (Brettflan)
Players are now prevented from using /f home if an enemy is nearby, and the players isn't in a safezone or their own faction territory  (Brettflan)
New option to make membership default to closed for newly created factions  (Brettflan)
When an admin has bypass mode enabled (/f bypass), they can now unclaim any faction land they're standing on  (Brettflan)
2011-05-29 16:28:29 -05:00

94 lines
2.7 KiB
Java

package org.mcteam.factions.commands;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import org.bukkit.command.CommandSender;
import org.mcteam.factions.Conf;
import org.mcteam.factions.Faction;
import org.mcteam.factions.util.TextUtil;
public class FCommandList extends FBaseCommand {
public FCommandList() {
aliases.add("list");
aliases.add("ls");
optionalParameters.add("page");
helpDescription = "Show a list of the factions";
}
@Override
public boolean hasPermission(CommandSender sender) {
return true;
}
public void perform() {
ArrayList<Faction> FactionList = new ArrayList<Faction>(Faction.getAll());
FactionList.remove(Faction.getNone());
FactionList.remove(Faction.getSafeZone());
FactionList.remove(Faction.getWarZone());
int page = 1;
if (parameters.size() > 0) {
try {
page = Integer.parseInt(parameters.get(0));
} catch (NumberFormatException e) {
// wasn't an integer
}
}
page -= 1;
// Sort by total followers first
Collections.sort(FactionList, new Comparator<Faction>(){
@Override
public int compare(Faction f1, Faction f2) {
if (f1.getFPlayers().size() < f2.getFPlayers().size())
return 1;
else if (f1.getFPlayers().size() > f2.getFPlayers().size())
return -1;
return 0;
}
});
// Then sort by how many members are online now
Collections.sort(FactionList, new Comparator<Faction>(){
@Override
public int compare(Faction f1, Faction f2) {
if (f1.getFPlayersWhereOnline(true).size() < f2.getFPlayersWhereOnline(true).size())
return 1;
else if (f1.getFPlayersWhereOnline(true).size() > f2.getFPlayersWhereOnline(true).size())
return -1;
return 0;
}
});
FactionList.add(0, Faction.getNone());
int maxPage = (int)Math.floor((double)FactionList.size() / 9D);
if (page < 0 || page > maxPage) {
sendMessage("The faction list is only " + (maxPage+1) + " page(s) long");
return;
}
String header = "Faction List";
if (maxPage > 1) header += " (page " + (page+1) + " of " + (maxPage+1) + ")";
sendMessage(TextUtil.titleize(header));
int maxPos = (page+1) * 9;
if (maxPos > FactionList.size()) maxPos = FactionList.size();
for (int pos = page * 9; pos < maxPos; pos++) {
Faction faction = FactionList.get(pos);
if (faction.getId() == 0) {
sendMessage(faction.getTag(me)+Conf.colorSystem+" "+faction.getFPlayersWhereOnline(true).size() + " online");
} else {
sendMessage(faction.getTag(me)+Conf.colorSystem+" "+faction.getFPlayersWhereOnline(true).size()+"/"+faction.getFPlayers().size()+" online, "+faction.getLandRounded()+"/"+faction.getPowerRounded()+"/"+faction.getPowerMaxRounded());
}
}
}
}