Factions3/src/com/massivecraft/factions/cmd/CmdFactionsList.java

76 lines
2.1 KiB
Java
Raw Normal View History

2011-10-09 21:57:43 +02:00
package com.massivecraft.factions.cmd;
import java.util.ArrayList;
import java.util.List;
2013-04-09 13:15:25 +02:00
import com.massivecraft.factions.ConfServer;
2011-07-18 22:06:02 +02:00
import com.massivecraft.factions.Faction;
2013-04-09 12:58:39 +02:00
import com.massivecraft.factions.FactionColl;
import com.massivecraft.factions.FactionListComparator;
import com.massivecraft.factions.Perm;
import com.massivecraft.mcore.cmd.arg.ARInteger;
2013-04-16 10:11:59 +02:00
import com.massivecraft.mcore.cmd.req.ReqHasPerm;
2013-04-10 10:32:04 +02:00
import com.massivecraft.mcore.util.Txt;
2011-03-23 17:39:56 +01:00
2013-04-10 13:12:22 +02:00
public class CmdFactionsList extends FCommand
{
2013-04-10 13:12:22 +02:00
public CmdFactionsList()
{
2013-04-16 10:11:59 +02:00
this.addAliases("ls", "list");
this.addOptionalArg("page", "1");
2013-04-16 10:11:59 +02:00
this.addRequirements(ReqHasPerm.get(Perm.LIST.node));
2011-03-23 17:39:56 +01:00
}
@Override
public void perform()
{
Integer pageHumanBased = this.arg(0, ARInteger.get(), 1);
if (pageHumanBased == null) return;
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay
2013-04-09 13:15:25 +02:00
if ( ! payForCommand(ConfServer.econCostList, "to list the factions", "for listing the factions")) return;
// Create Messages
List<String> lines = new ArrayList<String>();
ArrayList<Faction> factionList = new ArrayList<Faction>(FactionColl.get().getAll(null, FactionListComparator.get()));
final int pageheight = 9;
int pagecount = (factionList.size() / pageheight) + 1;
if (pageHumanBased > pagecount)
pageHumanBased = pagecount;
else if (pageHumanBased < 1)
pageHumanBased = 1;
int start = (pageHumanBased - 1) * pageheight;
int end = start + pageheight;
if (end > factionList.size())
end = factionList.size();
lines.add(Txt.titleize("Faction List "+pageHumanBased+"/"+pagecount));
for (Faction faction : factionList.subList(start, end))
{
if (faction.isNone())
{
lines.add(Txt.parse("<i>Factionless<i> %d online", FactionColl.get().getNone().getFPlayersWhereOnline(true).size()));
continue;
}
2013-04-10 10:32:04 +02:00
lines.add(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(lines);
}
}