Respect canSee in online fplayer count

This commit is contained in:
Trent Hensler 2018-03-04 17:40:36 -08:00
parent 07eb3756e4
commit e95ecbd2a9
4 changed files with 36 additions and 2 deletions

View File

@ -217,6 +217,8 @@ public interface Faction extends EconomyParticipator {
public Set<FPlayer> getFPlayersWhereOnline(boolean online);
public Set<FPlayer> getFPlayersWhereOnline(boolean online, FPlayer viewer);
public FPlayer getFPlayerAdmin();
public ArrayList<FPlayer> getFPlayersWhereRole(Role role);

View File

@ -696,6 +696,33 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator {
return ret;
}
public Set<FPlayer> getFPlayersWhereOnline(boolean online, FPlayer viewer) {
Set<FPlayer> ret = new HashSet<>();
if (!this.isNormal()) {
return ret;
}
for (FPlayer viewed : fplayers) {
// Add if their online status is what we want
if (viewed.isOnline() == online) {
// If we want online, check to see if we are able to see this player
// This checks if they are in vanish.
if (online
&& viewed.getPlayer() != null
&& viewer.getPlayer() != null
&& viewer.getPlayer().canSee(viewed.getPlayer())) {
ret.add(viewed);
// If we want offline, just add them.
// Prob a better way to do this but idk.
} else if (!online) {
ret.add(viewed);
}
}
}
return ret;
}
public FPlayer getFPlayerAdmin() {
if (!this.isNormal()) {
return null;

View File

@ -225,7 +225,12 @@ public enum TagReplacer {
case TRUCES_COUNT:
return String.valueOf(fac.getRelationCount(Relation.TRUCE));
case ONLINE_COUNT:
return String.valueOf(fac.getOnlinePlayers().size());
if (fp != null && fp.isOnline()) {
return String.valueOf(fac.getFPlayersWhereOnline(true, fp).size());
} else {
// Only console should ever get here.
return String.valueOf(fac.getFPlayers().size());
}
case OFFLINE_COUNT:
return String.valueOf(fac.getFPlayers().size() - fac.getOnlinePlayers().size());
case FACTION_SIZE:

View File

@ -199,7 +199,7 @@ public class TagUtil {
case ONLINE_LIST:
FancyMessage currentOnline = P.p.txt.parseFancy(prefix);
boolean firstOnline = true;
for (FPlayer p : MiscUtil.rankOrder(target.getFPlayersWhereOnline(true))) {
for (FPlayer p : MiscUtil.rankOrder(target.getFPlayersWhereOnline(true, fme))) {
if (fme.getPlayer() != null && !fme.getPlayer().canSee(p.getPlayer())) {
continue; // skip
}