Vasnished staff should not affect /f list, order

This commit is contained in:
Magnus Ulf Jørgensen 2017-01-20 09:32:23 +01:00
parent 9d74ecfe64
commit ad4ad7307f
3 changed files with 33 additions and 15 deletions

View File

@ -1,19 +1,33 @@
package com.massivecraft.factions;
import java.lang.ref.WeakReference;
import java.util.Comparator;
import org.bukkit.command.CommandSender;
import com.massivecraft.factions.entity.Faction;
import com.massivecraft.massivecore.comparator.ComparatorComparable;
import com.massivecraft.massivecore.util.IdUtil;
public class FactionListComparator implements Comparator<Faction>
{
// -------------------------------------------- //
// FIELDS
// -------------------------------------------- //
private final WeakReference<CommandSender> watcher;
public CommandSender getWatcher() { return this.watcher.get(); }
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static FactionListComparator i = new FactionListComparator();
public static FactionListComparator get() { return i; }
public static FactionListComparator get(Object watcherObject) { return new FactionListComparator(watcherObject); }
public FactionListComparator(Object watcherObject)
{
this.watcher = new WeakReference<>(IdUtil.getSender(watcherObject));
}
// -------------------------------------------- //
// OVERRIDE: COMPARATOR
// -------------------------------------------- //
@ -36,7 +50,7 @@ public class FactionListComparator implements Comparator<Faction>
if (ret != 0) return ret;
// Players Online
ret = f2.getMPlayersWhereOnline(true).size() - f1.getMPlayersWhereOnline(true).size();
ret = f2.getMPlayersWhereOnlineTo(this.getWatcher()).size() - f1.getMPlayersWhereOnlineTo(this.getWatcher()).size();
if (ret != 0) return ret;
// Players Total

View File

@ -3,6 +3,7 @@ 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;
@ -15,10 +16,6 @@ import com.massivecraft.massivecore.command.Parameter;
import com.massivecraft.massivecore.command.requirement.RequirementHasPerm;
import com.massivecraft.massivecore.pager.Pager;
import com.massivecraft.massivecore.pager.Stringifier;
import com.massivecraft.massivecore.predicate.Predicate;
import com.massivecraft.massivecore.predicate.PredicateAnd;
import com.massivecraft.massivecore.predicate.PredicateVisibleTo;
import com.massivecraft.massivecore.store.SenderColl;
import com.massivecraft.massivecore.util.Txt;
public class CmdFactionsList extends FactionsCommand
@ -48,26 +45,26 @@ public class CmdFactionsList extends FactionsCommand
{
// Args
int page = this.readArg();
final CommandSender sender = this.sender;
final MPlayer msender = this.msender;
final Predicate<MPlayer> onlinePredicate = PredicateAnd.get(SenderColl.PREDICATE_ONLINE, PredicateVisibleTo.get(sender));
// NOTE: The faction list is quite slow and mostly thread safe.
// We run it asynchronously to spare the primary server thread.
// Pager Create
final Pager<Faction> pager = new Pager<Faction>(this, "Faction List", page, new Stringifier<Faction>() {
final Pager<Faction> pager = new Pager<>(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());
return Txt.parse("<i>Factionless<i> %d online", FactionColl.get().getNone().getMPlayersWhereOnlineTo(sender).size());
}
else
{
return Txt.parse("%s<i> %d/%d online, %d/%d/%d",
faction.getName(msender),
faction.getMPlayersWhere(onlinePredicate).size(),
faction.getMPlayersWhereOnlineTo(sender).size(),
faction.getMPlayers().size(),
faction.getLandCount(),
faction.getPowerRounded(),
@ -83,7 +80,7 @@ public class CmdFactionsList extends FactionsCommand
public void run()
{
// Pager Items
final List<Faction> factions = FactionColl.get().getAll(FactionListComparator.get());
final List<Faction> factions = FactionColl.get().getAll(FactionListComparator.get(sender));
pager.setItems(factions);
// Pager Message

View File

@ -35,6 +35,8 @@ import com.massivecraft.massivecore.comparator.ComparatorCaseInsensitive;
import com.massivecraft.massivecore.mixin.MixinMessage;
import com.massivecraft.massivecore.money.Money;
import com.massivecraft.massivecore.predicate.Predicate;
import com.massivecraft.massivecore.predicate.PredicateAnd;
import com.massivecraft.massivecore.predicate.PredicateVisibleTo;
import com.massivecraft.massivecore.ps.PS;
import com.massivecraft.massivecore.store.Entity;
import com.massivecraft.massivecore.store.SenderColl;
@ -1062,7 +1064,12 @@ public class Faction extends Entity<Faction> implements EconomyParticipator, Nam
public List<MPlayer> getMPlayersWhereOnline(boolean online)
{
return this.getMPlayersWhere(online ? SenderColl.PREDICATE_ONLINE : SenderColl.PREDICATE_OFFLINE);
}
}
public List<MPlayer> getMPlayersWhereOnlineTo(Object senderObject)
{
return this.getMPlayersWhere(PredicateAnd.get(SenderColl.PREDICATE_ONLINE, PredicateVisibleTo.get(senderObject)));
}
public List<MPlayer> getMPlayersWhereRole(Rel role)
{