Saber-Factions/src/com/massivecraft/factions/commands/CmdList.java

86 lines
2.4 KiB
Java
Raw Normal View History

2011-07-18 22:06:02 +02:00
package com.massivecraft.factions.commands;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
2011-07-18 22:06:02 +02:00
import com.massivecraft.factions.Conf;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.Factions;
import com.massivecraft.factions.struct.Permission;
2011-03-23 17:39:56 +01:00
2011-10-09 20:10:19 +02:00
public class CmdList extends FCommand
{
2011-10-09 20:10:19 +02:00
public CmdList()
{
super();
this.aliases.add("list");
this.aliases.add("ls");
//this.requiredArgs.add("");
this.optionalArgs.put("page", "1");
this.permission = Permission.COMMAND_LIST.node;
senderMustBePlayer = false;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeAdmin = false;
2011-03-23 17:39:56 +01:00
}
@Override
public void perform()
{
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay
if ( ! payForCommand(Conf.econCostList)) return;
ArrayList<Faction> factionList = new ArrayList<Faction>(Factions.i.get());
factionList.remove(Factions.i.getNone());
factionList.remove(Factions.i.getSafeZone());
factionList.remove(Factions.i.getWarZone());
// Sort by total followers first
Collections.sort(factionList, new Comparator<Faction>(){
@Override
public int compare(Faction f1, Faction f2) {
2011-03-22 19:25:11 +01:00
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;
}
});
2011-03-22 19:25:11 +01:00
ArrayList<String> lines = new ArrayList<String>();
lines.add(p.txt.parse("Factionless <i> %d online", Factions.i.getNone().getFPlayersWhereOnline(true).size()));
for (Faction faction : factionList)
{
lines.add(p.txt.parse("%s<i> %d/%d online, %d/%d/%d",
faction.getTag(fme),
faction.getFPlayersWhereOnline(true).size(),
faction.getFPlayers().size(),
faction.getLandRounded(),
faction.getPowerRounded(),
faction.getPowerMaxRounded())
);
}
sendMessage(p.txt.getPage(lines, this.argAsInt(0, 1), "Faction List"));
}
}