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

81 lines
2.5 KiB
Java
Raw Normal View History

2011-10-09 21:57:43 +02:00
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Factions;
import com.massivecraft.factions.comparator.ComparatorFactionList;
2013-04-22 09:37:53 +02:00
import com.massivecraft.factions.entity.Faction;
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;
2015-09-05 13:44:24 +02:00
import com.massivecraft.massivecore.pager.Pager;
import com.massivecraft.massivecore.pager.Stringifier;
import com.massivecraft.massivecore.predicate.PredicateAnd;
import com.massivecraft.massivecore.predicate.PredicateVisibleTo;
import com.massivecraft.massivecore.store.SenderColl;
2014-06-04 14:02:23 +02:00
import com.massivecraft.massivecore.util.Txt;
2017-03-24 13:05:58 +01:00
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import java.util.List;
import java.util.function.Predicate;
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()
{
// Parameters
this.addParameter(Parameter.getPage());
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-09-05 13:44:24 +02:00
int page = this.readArg();
final CommandSender sender = this.sender;
2015-12-21 23:11:30 +01:00
final MPlayer msender = this.msender;
// NOTE: The faction list is quite slow and mostly thread safe.
// We run it asynchronously to spare the primary server thread.
Predicate<MPlayer> predicateOnline = PredicateAnd.get(mp -> mp.getId() != null, SenderColl.PREDICATE_ONLINE, PredicateVisibleTo.get(sender));
2015-09-05 13:44:24 +02:00
// Pager Create
2019-05-03 09:25:18 +02:00
final Pager<Faction> pager = new Pager<>(this, "Faction List", page, (Stringifier<Faction>) (faction, index) -> {
if (faction.isNone())
2015-09-05 13:44:24 +02:00
{
2019-05-03 09:25:18 +02:00
return Txt.parse("<i>Factionless<i> %d online", FactionColl.get().getNone().getMPlayersWhereOnlineTo(sender).size());
2015-09-05 13:44:24 +02:00
}
2019-05-03 09:25:18 +02:00
else
{
2019-05-03 09:25:18 +02:00
return Txt.parse("%s<i> %d/%d online, %d/%d/%d",
faction.getName(msender),
faction.getMPlayersWhere(predicateOnline).size(),
2019-05-03 09:25:18 +02:00
faction.getMPlayers().size(),
faction.getLandCount(),
faction.getPowerRounded(),
faction.getPowerMaxRounded()
);
}
});
2019-05-03 09:25:18 +02:00
Bukkit.getScheduler().runTaskAsynchronously(Factions.get(), () -> {
// Pager Items
final List<Faction> factions = FactionColl.get().getAll(ComparatorFactionList.get(sender));
pager.setItems(factions);
// Pager Message
pager.message();
});
}
2013-11-11 09:31:04 +01:00
}