mirror of
https://github.com/MassiveCraft/Factions.git
synced 2024-11-10 12:30:29 +01:00
Check player visibility in CmdFactionsList
This commit is contained in:
parent
2b7a505a7c
commit
bc02fe5949
35
src/com/massivecraft/factions/PredicateRole.java
Normal file
35
src/com/massivecraft/factions/PredicateRole.java
Normal file
@ -0,0 +1,35 @@
|
||||
package com.massivecraft.factions;
|
||||
|
||||
import com.massivecraft.factions.entity.MPlayer;
|
||||
import com.massivecraft.massivecore.Predicate;
|
||||
|
||||
public class PredicateRole implements Predicate<MPlayer>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// FIELDS
|
||||
// -------------------------------------------- //
|
||||
|
||||
private final Rel role;
|
||||
public Rel getRole() { return this.role; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE AND CONTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public static PredicateRole get(Rel role) { return new PredicateRole(role); }
|
||||
public PredicateRole(Rel role)
|
||||
{
|
||||
this.role = role;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public boolean apply(MPlayer mplayer)
|
||||
{
|
||||
if (mplayer == null) return false;
|
||||
return mplayer.getRole() == this.role;
|
||||
}
|
||||
}
|
@ -11,10 +11,14 @@ import com.massivecraft.factions.entity.Faction;
|
||||
import com.massivecraft.factions.entity.FactionColl;
|
||||
import com.massivecraft.factions.entity.MPlayer;
|
||||
import com.massivecraft.massivecore.MassiveException;
|
||||
import com.massivecraft.massivecore.Predicate;
|
||||
import com.massivecraft.massivecore.PredicateAnd;
|
||||
import com.massivecraft.massivecore.PredicateVisibleTo;
|
||||
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.store.SenderColl;
|
||||
import com.massivecraft.massivecore.util.Txt;
|
||||
|
||||
public class CmdFactionsList extends FactionsCommand
|
||||
@ -45,6 +49,7 @@ public class CmdFactionsList extends FactionsCommand
|
||||
// Args
|
||||
int page = this.readArg();
|
||||
final MPlayer msender = this.msender;
|
||||
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.
|
||||
@ -62,7 +67,7 @@ public class CmdFactionsList extends FactionsCommand
|
||||
{
|
||||
return Txt.parse("%s<i> %d/%d online, %d/%d/%d",
|
||||
faction.getName(msender),
|
||||
faction.getMPlayersWhereOnline(true).size(),
|
||||
faction.getMPlayersWhere(onlinePredicate).size(),
|
||||
faction.getMPlayers().size(),
|
||||
faction.getLandCount(),
|
||||
faction.getPowerRounded(),
|
||||
|
@ -1,7 +1,17 @@
|
||||
package com.massivecraft.factions.entity;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@ -11,17 +21,21 @@ import com.massivecraft.factions.EconomyParticipator;
|
||||
import com.massivecraft.factions.FactionEqualsPredicate;
|
||||
import com.massivecraft.factions.Factions;
|
||||
import com.massivecraft.factions.Lang;
|
||||
import com.massivecraft.factions.PredicateRole;
|
||||
import com.massivecraft.factions.Rel;
|
||||
import com.massivecraft.factions.RelationParticipator;
|
||||
import com.massivecraft.factions.util.*;
|
||||
import com.massivecraft.factions.util.MiscUtil;
|
||||
import com.massivecraft.factions.util.RelationUtil;
|
||||
import com.massivecraft.massivecore.CaseInsensitiveComparator;
|
||||
import com.massivecraft.massivecore.Named;
|
||||
import com.massivecraft.massivecore.Predicate;
|
||||
import com.massivecraft.massivecore.collections.MassiveMapDef;
|
||||
import com.massivecraft.massivecore.collections.MassiveTreeSetDef;
|
||||
import com.massivecraft.massivecore.mixin.Mixin;
|
||||
import com.massivecraft.massivecore.money.Money;
|
||||
import com.massivecraft.massivecore.ps.PS;
|
||||
import com.massivecraft.massivecore.store.Entity;
|
||||
import com.massivecraft.massivecore.store.SenderColl;
|
||||
import com.massivecraft.massivecore.util.IdUtil;
|
||||
import com.massivecraft.massivecore.util.MUtil;
|
||||
import com.massivecraft.massivecore.util.Txt;
|
||||
@ -1038,49 +1052,31 @@ public class Faction extends Entity<Faction> implements EconomyParticipator, Nam
|
||||
return new ArrayList<MPlayer>(this.mplayers);
|
||||
}
|
||||
|
||||
public List<MPlayer> getMPlayersWhereOnline(boolean online)
|
||||
public List<MPlayer> getMPlayersWhere(Predicate<? super MPlayer> predicate)
|
||||
{
|
||||
List<MPlayer> ret = this.getMPlayers();
|
||||
Iterator<MPlayer> iter = ret.iterator();
|
||||
while (iter.hasNext())
|
||||
for (Iterator<MPlayer> it = ret.iterator(); it.hasNext();)
|
||||
{
|
||||
MPlayer mplayer = iter.next();
|
||||
if (mplayer.isOnline() != online)
|
||||
{
|
||||
iter.remove();
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public List<MPlayer> getMPlayersWhereRole(Rel role)
|
||||
{
|
||||
List<MPlayer> ret = this.getMPlayers();
|
||||
Iterator<MPlayer> iter = ret.iterator();
|
||||
while (iter.hasNext())
|
||||
{
|
||||
MPlayer mplayer = iter.next();
|
||||
if (mplayer.getRole() != role)
|
||||
{
|
||||
iter.remove();
|
||||
}
|
||||
if ( ! predicate.apply(it.next())) it.remove();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public List<MPlayer> getMPlayersWhereOnline(boolean online)
|
||||
{
|
||||
return this.getMPlayersWhere(online ? SenderColl.PREDICATE_ONLINE : SenderColl.PREDICATE_OFFLINE);
|
||||
}
|
||||
|
||||
public List<MPlayer> getMPlayersWhereRole(Rel role)
|
||||
{
|
||||
return this.getMPlayersWhere(PredicateRole.get(role));
|
||||
}
|
||||
|
||||
public MPlayer getLeader()
|
||||
{
|
||||
List<MPlayer> ret = this.getMPlayers();
|
||||
Iterator<MPlayer> iter = ret.iterator();
|
||||
while (iter.hasNext())
|
||||
{
|
||||
MPlayer mplayer = iter.next();
|
||||
if (mplayer.getRole() == Rel.LEADER)
|
||||
{
|
||||
return mplayer;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
List<MPlayer> ret = this.getMPlayersWhereRole(Rel.LEADER);
|
||||
if (ret.size() == 0) return null;
|
||||
return ret.get(0);
|
||||
}
|
||||
|
||||
public List<CommandSender> getOnlineCommandSenders()
|
||||
|
Loading…
Reference in New Issue
Block a user