Vasnished staff should not affect /f list, order
This commit is contained in:
		@@ -1,18 +1,32 @@
 | 
				
			|||||||
package com.massivecraft.factions;
 | 
					package com.massivecraft.factions;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import java.lang.ref.WeakReference;
 | 
				
			||||||
import java.util.Comparator;
 | 
					import java.util.Comparator;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import org.bukkit.command.CommandSender;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import com.massivecraft.factions.entity.Faction;
 | 
					import com.massivecraft.factions.entity.Faction;
 | 
				
			||||||
import com.massivecraft.massivecore.comparator.ComparatorComparable;
 | 
					import com.massivecraft.massivecore.comparator.ComparatorComparable;
 | 
				
			||||||
 | 
					import com.massivecraft.massivecore.util.IdUtil;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class FactionListComparator implements Comparator<Faction>
 | 
					public class FactionListComparator implements Comparator<Faction>
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
						// -------------------------------------------- //
 | 
				
			||||||
 | 
						// FIELDS
 | 
				
			||||||
 | 
						// -------------------------------------------- //
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						private final WeakReference<CommandSender> watcher;
 | 
				
			||||||
 | 
						public CommandSender getWatcher() { return this.watcher.get(); }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// -------------------------------------------- //
 | 
						// -------------------------------------------- //
 | 
				
			||||||
	// INSTANCE & CONSTRUCT
 | 
						// INSTANCE & CONSTRUCT
 | 
				
			||||||
	// -------------------------------------------- //
 | 
						// -------------------------------------------- //
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	private static FactionListComparator i = new FactionListComparator();
 | 
						public static FactionListComparator get(Object watcherObject) { return new FactionListComparator(watcherObject); }
 | 
				
			||||||
	public static FactionListComparator get() { return i; }
 | 
						public FactionListComparator(Object watcherObject)
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							this.watcher = new WeakReference<>(IdUtil.getSender(watcherObject));
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// -------------------------------------------- //
 | 
						// -------------------------------------------- //
 | 
				
			||||||
	// OVERRIDE: COMPARATOR
 | 
						// OVERRIDE: COMPARATOR
 | 
				
			||||||
@@ -36,7 +50,7 @@ public class FactionListComparator implements Comparator<Faction>
 | 
				
			|||||||
		if (ret != 0) return ret;
 | 
							if (ret != 0) return ret;
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		// Players Online
 | 
							// 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;
 | 
							if (ret != 0) return ret;
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		// Players Total
 | 
							// Players Total
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -3,6 +3,7 @@ package com.massivecraft.factions.cmd;
 | 
				
			|||||||
import java.util.List;
 | 
					import java.util.List;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import org.bukkit.Bukkit;
 | 
					import org.bukkit.Bukkit;
 | 
				
			||||||
 | 
					import org.bukkit.command.CommandSender;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import com.massivecraft.factions.FactionListComparator;
 | 
					import com.massivecraft.factions.FactionListComparator;
 | 
				
			||||||
import com.massivecraft.factions.Factions;
 | 
					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.command.requirement.RequirementHasPerm;
 | 
				
			||||||
import com.massivecraft.massivecore.pager.Pager;
 | 
					import com.massivecraft.massivecore.pager.Pager;
 | 
				
			||||||
import com.massivecraft.massivecore.pager.Stringifier;
 | 
					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;
 | 
					import com.massivecraft.massivecore.util.Txt;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class CmdFactionsList extends FactionsCommand
 | 
					public class CmdFactionsList extends FactionsCommand
 | 
				
			||||||
@@ -48,26 +45,26 @@ public class CmdFactionsList extends FactionsCommand
 | 
				
			|||||||
	{
 | 
						{
 | 
				
			||||||
		// Args
 | 
							// Args
 | 
				
			||||||
		int page = this.readArg();
 | 
							int page = this.readArg();
 | 
				
			||||||
 | 
							final CommandSender sender = this.sender;
 | 
				
			||||||
		final MPlayer msender = this.msender;
 | 
							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.
 | 
							// NOTE: The faction list is quite slow and mostly thread safe.
 | 
				
			||||||
		// We run it asynchronously to spare the primary server thread.
 | 
							// We run it asynchronously to spare the primary server thread.
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		// Pager Create
 | 
							// 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
 | 
								@Override
 | 
				
			||||||
			public String toString(Faction faction, int index)
 | 
								public String toString(Faction faction, int index)
 | 
				
			||||||
			{
 | 
								{
 | 
				
			||||||
				if (faction.isNone())
 | 
									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
 | 
									else
 | 
				
			||||||
				{
 | 
									{
 | 
				
			||||||
					return Txt.parse("%s<i> %d/%d online, %d/%d/%d",
 | 
										return Txt.parse("%s<i> %d/%d online, %d/%d/%d",
 | 
				
			||||||
						faction.getName(msender),
 | 
											faction.getName(msender),
 | 
				
			||||||
						faction.getMPlayersWhere(onlinePredicate).size(),
 | 
											faction.getMPlayersWhereOnlineTo(sender).size(),
 | 
				
			||||||
						faction.getMPlayers().size(),
 | 
											faction.getMPlayers().size(),
 | 
				
			||||||
						faction.getLandCount(),
 | 
											faction.getLandCount(),
 | 
				
			||||||
						faction.getPowerRounded(),
 | 
											faction.getPowerRounded(),
 | 
				
			||||||
@@ -83,7 +80,7 @@ public class CmdFactionsList extends FactionsCommand
 | 
				
			|||||||
			public void run()
 | 
								public void run()
 | 
				
			||||||
			{
 | 
								{
 | 
				
			||||||
				// Pager Items
 | 
									// 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.setItems(factions);
 | 
				
			||||||
				
 | 
									
 | 
				
			||||||
				// Pager Message
 | 
									// Pager Message
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -35,6 +35,8 @@ import com.massivecraft.massivecore.comparator.ComparatorCaseInsensitive;
 | 
				
			|||||||
import com.massivecraft.massivecore.mixin.MixinMessage;
 | 
					import com.massivecraft.massivecore.mixin.MixinMessage;
 | 
				
			||||||
import com.massivecraft.massivecore.money.Money;
 | 
					import com.massivecraft.massivecore.money.Money;
 | 
				
			||||||
import com.massivecraft.massivecore.predicate.Predicate;
 | 
					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.ps.PS;
 | 
				
			||||||
import com.massivecraft.massivecore.store.Entity;
 | 
					import com.massivecraft.massivecore.store.Entity;
 | 
				
			||||||
import com.massivecraft.massivecore.store.SenderColl;
 | 
					import com.massivecraft.massivecore.store.SenderColl;
 | 
				
			||||||
@@ -1064,6 +1066,11 @@ public class Faction extends Entity<Faction> implements EconomyParticipator, Nam
 | 
				
			|||||||
		return this.getMPlayersWhere(online ? SenderColl.PREDICATE_ONLINE : SenderColl.PREDICATE_OFFLINE);
 | 
							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)
 | 
						public List<MPlayer> getMPlayersWhereRole(Rel role)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		return this.getMPlayersWhere(PredicateRole.get(role));
 | 
							return this.getMPlayersWhere(PredicateRole.get(role));
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user