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

72 lines
1.9 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;
import com.massivecraft.factions.FactionListComparator;
import com.massivecraft.factions.Perm;
2013-04-22 09:37:53 +02:00
import com.massivecraft.factions.entity.Faction;
2013-04-22 13:03:21 +02:00
import com.massivecraft.factions.entity.FactionColls;
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;
// Create Messages
List<String> lines = new ArrayList<String>();
2013-04-22 13:03:21 +02:00
ArrayList<Faction> factionList = new ArrayList<Faction>(FactionColls.get().get(sender).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", FactionColls.get().get(sender).getNone().getUPlayersWhereOnline(true).size()));
continue;
}
2013-04-10 10:32:04 +02:00
lines.add(Txt.parse("%s<i> %d/%d online, %d/%d/%d",
faction.getName(fme),
faction.getUPlayersWhereOnline(true).size(),
faction.getUPlayers().size(),
faction.getLandCount(),
faction.getPowerRounded(),
faction.getPowerMaxRounded())
);
}
sendMessage(lines);
}
}