2011-10-09 21:57:43 +02:00
|
|
|
package com.massivecraft.factions.cmd;
|
2011-03-22 15:45:41 +01:00
|
|
|
|
2013-04-16 12:04:12 +02:00
|
|
|
import java.util.List;
|
2011-03-22 15:45:41 +01:00
|
|
|
|
2015-01-08 10:00:38 +01:00
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
|
2013-04-16 12:04:12 +02:00
|
|
|
import com.massivecraft.factions.FactionListComparator;
|
2015-01-08 10:00:38 +01:00
|
|
|
import com.massivecraft.factions.Factions;
|
2013-04-09 12:56:29 +02:00
|
|
|
import com.massivecraft.factions.Perm;
|
2013-04-22 09:37:53 +02:00
|
|
|
import com.massivecraft.factions.entity.Faction;
|
2014-09-17 13:17:33 +02:00
|
|
|
import com.massivecraft.factions.entity.FactionColl;
|
2015-12-21 23:11:30 +01:00
|
|
|
import com.massivecraft.factions.entity.MPlayer;
|
2015-02-12 12:00:55 +01:00
|
|
|
import com.massivecraft.massivecore.MassiveException;
|
2015-11-06 02:10:29 +01:00
|
|
|
import com.massivecraft.massivecore.command.Parameter;
|
|
|
|
import com.massivecraft.massivecore.command.requirement.RequirementHasPerm;
|
2015-09-05 13:44:24 +02:00
|
|
|
import com.massivecraft.massivecore.pager.Pager;
|
2015-01-08 10:00:38 +01:00
|
|
|
import com.massivecraft.massivecore.pager.Stringifier;
|
2016-02-03 05:06:49 +01:00
|
|
|
import com.massivecraft.massivecore.predicate.Predicate;
|
|
|
|
import com.massivecraft.massivecore.predicate.PredicateAnd;
|
|
|
|
import com.massivecraft.massivecore.predicate.PredicateVisibleTo;
|
2016-01-25 09:49:43 +01:00
|
|
|
import com.massivecraft.massivecore.store.SenderColl;
|
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
|
2011-10-09 14:53:38 +02:00
|
|
|
{
|
2013-11-11 09:31:04 +01:00
|
|
|
// -------------------------------------------- //
|
|
|
|
// CONSTRUCT
|
|
|
|
// -------------------------------------------- //
|
|
|
|
|
2013-04-10 13:12:22 +02:00
|
|
|
public CmdFactionsList()
|
2011-10-09 14:53:38 +02:00
|
|
|
{
|
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
|
|
|
|
2015-10-21 19:35:41 +02:00
|
|
|
// Parameters
|
|
|
|
this.addParameter(Parameter.getPage());
|
2013-11-11 09:31:04 +01:00
|
|
|
|
|
|
|
// Requirements
|
2016-05-26 10:17:44 +02:00
|
|
|
this.addRequirements(RequirementHasPerm.get(Perm.LIST));
|
2011-03-23 17:39:56 +01:00
|
|
|
}
|
|
|
|
|
2013-11-11 09:31:04 +01:00
|
|
|
// -------------------------------------------- //
|
|
|
|
// OVERRIDE
|
|
|
|
// -------------------------------------------- //
|
|
|
|
|
2011-06-21 07:38:31 +02:00
|
|
|
@Override
|
2015-02-12 12:00:55 +01:00
|
|
|
public void perform() throws MassiveException
|
2011-10-09 14:53:38 +02:00
|
|
|
{
|
2015-01-08 10:00:38 +01:00
|
|
|
// Args
|
2015-09-05 13:44:24 +02:00
|
|
|
int page = this.readArg();
|
2015-12-21 23:11:30 +01:00
|
|
|
final MPlayer msender = this.msender;
|
2016-01-25 15:36:20 +01:00
|
|
|
final Predicate<MPlayer> onlinePredicate = PredicateAnd.get(SenderColl.PREDICATE_ONLINE, PredicateVisibleTo.get(sender));
|
2013-04-16 12:04:12 +02:00
|
|
|
|
2015-01-08 10:00:38 +01:00
|
|
|
// NOTE: The faction list is quite slow and mostly thread safe.
|
|
|
|
// We run it asynchronously to spare the primary server thread.
|
2015-09-05 13:44:24 +02:00
|
|
|
|
|
|
|
// Pager Create
|
|
|
|
final Pager<Faction> pager = new Pager<Faction>(this, "Faction List", page, new Stringifier<Faction>() {
|
|
|
|
@Override
|
|
|
|
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),
|
2016-01-25 09:49:43 +01:00
|
|
|
faction.getMPlayersWhere(onlinePredicate).size(),
|
2015-09-05 13:44:24 +02:00
|
|
|
faction.getMPlayers().size(),
|
|
|
|
faction.getLandCount(),
|
|
|
|
faction.getPowerRounded(),
|
|
|
|
faction.getPowerMaxRounded()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-01-08 10:00:38 +01:00
|
|
|
Bukkit.getScheduler().runTaskAsynchronously(Factions.get(), new Runnable()
|
2012-11-06 16:43:27 +01:00
|
|
|
{
|
2015-01-08 10:00:38 +01:00
|
|
|
@Override
|
|
|
|
public void run()
|
2012-11-06 16:43:27 +01:00
|
|
|
{
|
2015-09-05 13:44:24 +02:00
|
|
|
// Pager Items
|
2015-08-03 16:17:38 +02:00
|
|
|
final List<Faction> factions = FactionColl.get().getAll(FactionListComparator.get());
|
2015-09-05 13:44:24 +02:00
|
|
|
pager.setItems(factions);
|
2015-01-08 10:00:38 +01:00
|
|
|
|
2015-09-05 13:44:24 +02:00
|
|
|
// Pager Message
|
|
|
|
pager.message();
|
2012-11-06 16:43:27 +01:00
|
|
|
}
|
2015-01-08 10:00:38 +01:00
|
|
|
});
|
2011-03-22 15:45:41 +01:00
|
|
|
}
|
2013-11-11 09:31:04 +01:00
|
|
|
|
2011-03-22 15:45:41 +01:00
|
|
|
}
|