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

91 lines
2.6 KiB
Java
Raw Normal View History

2011-10-09 21:57:43 +02:00
package com.massivecraft.factions.cmd;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import com.massivecraft.factions.FactionListComparator;
import com.massivecraft.factions.Factions;
import com.massivecraft.factions.Perm;
2013-04-22 09:37:53 +02:00
import com.massivecraft.factions.entity.Faction;
import com.massivecraft.factions.entity.FactionColl;
2015-02-12 12:00:55 +01:00
import com.massivecraft.massivecore.MassiveException;
2015-05-13 23:00:53 +02:00
import com.massivecraft.massivecore.cmd.ArgSetting;
2014-06-04 14:02:23 +02:00
import com.massivecraft.massivecore.cmd.req.ReqHasPerm;
import com.massivecraft.massivecore.mixin.Mixin;
import com.massivecraft.massivecore.pager.PagerSimple;
import com.massivecraft.massivecore.pager.Stringifier;
2014-06-04 14:02:23 +02:00
import com.massivecraft.massivecore.util.Txt;
2011-03-23 17:39:56 +01:00
2014-09-18 13:41:20 +02:00
public class CmdFactionsList extends FactionsCommand
{
2013-11-11 09:31:04 +01:00
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
2013-04-10 13:12:22 +02:00
public CmdFactionsList()
{
2013-11-11 09:31:04 +01:00
// Aliases
2013-04-25 16:02:37 +02:00
this.addAliases("l", "list");
2013-11-11 09:31:04 +01:00
// Args
2015-05-13 23:00:53 +02:00
this.addArg(ArgSetting.getPage());
2013-11-11 09:31:04 +01:00
// Requirements
2013-04-16 10:11:59 +02:00
this.addRequirements(ReqHasPerm.get(Perm.LIST.node));
2011-03-23 17:39:56 +01:00
}
2013-11-11 09:31:04 +01:00
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
2015-02-12 12:00:55 +01:00
public void perform() throws MassiveException
{
// Args
2015-05-13 23:00:53 +02:00
final int page = this.readArg();
// NOTE: The faction list is quite slow and mostly thread safe.
// We run it asynchronously to spare the primary server thread.
final CommandSender sender = this.sender;
Bukkit.getScheduler().runTaskAsynchronously(Factions.get(), new Runnable()
{
@Override
public void run()
{
// Create Pager
2015-08-03 16:17:38 +02:00
final List<Faction> factions = FactionColl.get().getAll(FactionListComparator.get());
final PagerSimple<Faction> pager = new PagerSimple<Faction>(factions, sender);
// Use Pager
2015-05-13 23:00:53 +02:00
List<String> messages = pager.getPageTxt(page, "Faction List", new Stringifier<Faction>() {
@Override
2015-02-17 10:40:15 +01:00
public String toString(Faction faction, int index)
{
if (faction.isNone())
{
return Txt.parse("<i>Factionless<i> %d online", FactionColl.get().getNone().getMPlayersWhereOnline(true).size());
}
else
{
return Txt.parse("%s<i> %d/%d online, %d/%d/%d",
faction.getName(msender),
faction.getMPlayersWhereOnline(true).size(),
faction.getMPlayers().size(),
faction.getLandCount(),
faction.getPowerRounded(),
faction.getPowerMaxRounded()
);
}
}
});
// Send Messages
Mixin.messageOne(sender, messages);
}
});
}
2013-11-11 09:31:04 +01:00
}