From 51135db452c791d26249d5381476657a4cc8dccb Mon Sep 17 00:00:00 2001 From: Magnus Ulf Date: Fri, 3 May 2019 09:59:10 +0200 Subject: [PATCH] Attempt to fix #31 But the real question is why some MPlayers had no id. I really have no clue why. --- src/com/massivecraft/factions/FactionsIndex.java | 14 ++++---------- .../massivecraft/factions/cmd/CmdFactionsList.java | 12 +++++++++--- src/com/massivecraft/factions/entity/Faction.java | 5 ++--- 3 files changed, 15 insertions(+), 16 deletions(-) diff --git a/src/com/massivecraft/factions/FactionsIndex.java b/src/com/massivecraft/factions/FactionsIndex.java index 62441ddd..045dbff7 100644 --- a/src/com/massivecraft/factions/FactionsIndex.java +++ b/src/com/massivecraft/factions/FactionsIndex.java @@ -78,11 +78,8 @@ public class FactionsIndex public synchronized void updateAll() { if (!MPlayerColl.get().isActive()) throw new IllegalStateException("The MPlayerColl is not yet fully activated."); - - for (MPlayer mplayer : MPlayerColl.get().getAll()) - { - this.update(mplayer); - } + + MPlayerColl.get().getAll().forEach(this::update); } public synchronized void update(MPlayer mplayer) @@ -117,11 +114,8 @@ public class FactionsIndex public synchronized void update(Faction faction) { if (faction == null) throw new NullPointerException("faction"); - - for (MPlayer mplayer : this.getMPlayers(faction)) - { - this.update(mplayer); - } + + this.getMPlayers(faction).forEach(this::update); } // -------------------------------------------- // diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsList.java b/src/com/massivecraft/factions/cmd/CmdFactionsList.java index 0b99ed99..baca489c 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsList.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsList.java @@ -1,7 +1,7 @@ package com.massivecraft.factions.cmd; -import com.massivecraft.factions.comparator.ComparatorFactionList; import com.massivecraft.factions.Factions; +import com.massivecraft.factions.comparator.ComparatorFactionList; import com.massivecraft.factions.entity.Faction; import com.massivecraft.factions.entity.FactionColl; import com.massivecraft.factions.entity.MPlayer; @@ -9,11 +9,15 @@ import com.massivecraft.massivecore.MassiveException; import com.massivecraft.massivecore.command.Parameter; 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; import com.massivecraft.massivecore.util.Txt; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; import java.util.List; +import java.util.function.Predicate; public class CmdFactionsList extends FactionsCommand { @@ -41,7 +45,9 @@ public class CmdFactionsList extends FactionsCommand // NOTE: The faction list is quite slow and mostly thread safe. // We run it asynchronously to spare the primary server thread. - + + Predicate predicateOnline = PredicateAnd.get(mp -> mp.getId() != null, SenderColl.PREDICATE_ONLINE, PredicateVisibleTo.get(sender)); + // Pager Create final Pager pager = new Pager<>(this, "Faction List", page, (Stringifier) (faction, index) -> { if (faction.isNone()) @@ -52,7 +58,7 @@ public class CmdFactionsList extends FactionsCommand { return Txt.parse("%s %d/%d online, %d/%d/%d", faction.getName(msender), - faction.getMPlayersWhereOnlineTo(sender).size(), + faction.getMPlayersWhere(predicateOnline).size(), faction.getMPlayers().size(), faction.getLandCount(), faction.getPowerRounded(), diff --git a/src/com/massivecraft/factions/entity/Faction.java b/src/com/massivecraft/factions/entity/Faction.java index 87b5af99..a2910d5e 100644 --- a/src/com/massivecraft/factions/entity/Faction.java +++ b/src/com/massivecraft/factions/entity/Faction.java @@ -17,7 +17,6 @@ import com.massivecraft.massivecore.collections.MassiveMapDef; import com.massivecraft.massivecore.collections.MassiveSet; 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; @@ -1079,12 +1078,12 @@ public class Faction extends Entity implements FactionsParticipator, MP return new MassiveList<>(FactionsIndex.get().getMPlayers(this)); } - public List getMPlayers(Predicate where, Comparator orderby, Integer limit, Integer offset) + public List getMPlayers(java.util.function.Predicate where, Comparator orderby, Integer limit, Integer offset) { return MUtil.transform(this.getMPlayers(), where, orderby, limit, offset); } - public List getMPlayersWhere(Predicate predicate) + public List getMPlayersWhere(java.util.function.Predicate predicate) { return this.getMPlayers(predicate, null, null, null); }