2011-10-09 21:57:43 +02:00
|
|
|
package com.massivecraft.factions.cmd;
|
2011-03-22 15:45:41 +01:00
|
|
|
|
|
|
|
import java.util.ArrayList;
|
2013-04-16 12:04:12 +02:00
|
|
|
import java.util.List;
|
2011-03-22 15:45:41 +01:00
|
|
|
|
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;
|
2013-04-16 12:04:12 +02:00
|
|
|
import com.massivecraft.factions.FactionListComparator;
|
2013-04-09 12:56:29 +02:00
|
|
|
import com.massivecraft.factions.Perm;
|
2013-04-16 12:04:12 +02:00
|
|
|
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
|
|
|
|
2011-03-22 15:45:41 +01:00
|
|
|
|
2013-04-10 13:12:22 +02:00
|
|
|
public class CmdFactionsList extends FCommand
|
2011-10-09 14:53:38 +02:00
|
|
|
{
|
2011-03-22 15:45:41 +01:00
|
|
|
|
2013-04-10 13:12:22 +02:00
|
|
|
public CmdFactionsList()
|
2011-10-09 14:53:38 +02:00
|
|
|
{
|
2013-04-16 10:11:59 +02:00
|
|
|
this.addAliases("ls", "list");
|
2011-03-22 18:48:09 +01:00
|
|
|
|
2013-04-16 10:30:21 +02:00
|
|
|
this.addOptionalArg("page", "1");
|
2011-06-30 12:56:02 +02:00
|
|
|
|
2013-04-16 10:11:59 +02:00
|
|
|
this.addRequirements(ReqHasPerm.get(Perm.LIST.node));
|
2011-03-23 17:39:56 +01:00
|
|
|
}
|
|
|
|
|
2011-06-21 07:38:31 +02:00
|
|
|
@Override
|
2011-10-09 14:53:38 +02:00
|
|
|
public void perform()
|
|
|
|
{
|
2013-04-16 12:04:12 +02:00
|
|
|
Integer pageHumanBased = this.arg(0, ARInteger.get(), 1);
|
|
|
|
if (pageHumanBased == null) return;
|
|
|
|
|
|
|
|
// Create Messages
|
|
|
|
List<String> lines = new ArrayList<String>();
|
2011-10-09 14:53:38 +02:00
|
|
|
|
2013-04-16 12:04:12 +02:00
|
|
|
ArrayList<Faction> factionList = new ArrayList<Faction>(FactionColl.get().getAll(null, FactionListComparator.get()));
|
2012-11-06 16:43:27 +01:00
|
|
|
|
|
|
|
final int pageheight = 9;
|
2013-04-16 12:04:12 +02:00
|
|
|
|
2012-11-06 16:43:27 +01:00
|
|
|
int pagecount = (factionList.size() / pageheight) + 1;
|
2013-04-16 12:04:12 +02:00
|
|
|
if (pageHumanBased > pagecount)
|
|
|
|
pageHumanBased = pagecount;
|
|
|
|
else if (pageHumanBased < 1)
|
|
|
|
pageHumanBased = 1;
|
|
|
|
int start = (pageHumanBased - 1) * pageheight;
|
2012-11-06 16:43:27 +01:00
|
|
|
int end = start + pageheight;
|
|
|
|
if (end > factionList.size())
|
|
|
|
end = factionList.size();
|
|
|
|
|
2013-04-16 12:04:12 +02:00
|
|
|
lines.add(Txt.titleize("Faction List "+pageHumanBased+"/"+pagecount));
|
2012-11-06 16:43:27 +01:00
|
|
|
|
|
|
|
for (Faction faction : factionList.subList(start, end))
|
|
|
|
{
|
|
|
|
if (faction.isNone())
|
|
|
|
{
|
2013-04-12 09:47:43 +02:00
|
|
|
lines.add(Txt.parse("<i>Factionless<i> %d online", FactionColl.get().getNone().getFPlayersWhereOnline(true).size()));
|
2012-11-06 16:43:27 +01:00
|
|
|
continue;
|
|
|
|
}
|
2013-04-10 10:32:04 +02:00
|
|
|
lines.add(Txt.parse("%s<i> %d/%d online, %d/%d/%d",
|
2012-11-06 16:43:27 +01:00
|
|
|
faction.getTag(fme),
|
|
|
|
faction.getFPlayersWhereOnline(true).size(),
|
|
|
|
faction.getFPlayers().size(),
|
2013-04-17 08:49:43 +02:00
|
|
|
faction.getLandCount(),
|
2012-11-06 16:43:27 +01:00
|
|
|
faction.getPowerRounded(),
|
|
|
|
faction.getPowerMaxRounded())
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
sendMessage(lines);
|
2011-03-22 15:45:41 +01:00
|
|
|
}
|
|
|
|
}
|