Attempt to fix #31

But the real question is why some MPlayers had no id. I really have no clue why.
This commit is contained in:
Magnus Ulf 2019-05-03 09:59:10 +02:00
parent 61bea411f5
commit 51135db452
3 changed files with 15 additions and 16 deletions

View File

@ -78,11 +78,8 @@ public class FactionsIndex
public synchronized void updateAll() public synchronized void updateAll()
{ {
if (!MPlayerColl.get().isActive()) throw new IllegalStateException("The MPlayerColl is not yet fully activated."); if (!MPlayerColl.get().isActive()) throw new IllegalStateException("The MPlayerColl is not yet fully activated.");
for (MPlayer mplayer : MPlayerColl.get().getAll()) MPlayerColl.get().getAll().forEach(this::update);
{
this.update(mplayer);
}
} }
public synchronized void update(MPlayer mplayer) public synchronized void update(MPlayer mplayer)
@ -117,11 +114,8 @@ public class FactionsIndex
public synchronized void update(Faction faction) public synchronized void update(Faction faction)
{ {
if (faction == null) throw new NullPointerException("faction"); if (faction == null) throw new NullPointerException("faction");
for (MPlayer mplayer : this.getMPlayers(faction)) this.getMPlayers(faction).forEach(this::update);
{
this.update(mplayer);
}
} }
// -------------------------------------------- // // -------------------------------------------- //

View File

@ -1,7 +1,7 @@
package com.massivecraft.factions.cmd; package com.massivecraft.factions.cmd;
import com.massivecraft.factions.comparator.ComparatorFactionList;
import com.massivecraft.factions.Factions; import com.massivecraft.factions.Factions;
import com.massivecraft.factions.comparator.ComparatorFactionList;
import com.massivecraft.factions.entity.Faction; import com.massivecraft.factions.entity.Faction;
import com.massivecraft.factions.entity.FactionColl; import com.massivecraft.factions.entity.FactionColl;
import com.massivecraft.factions.entity.MPlayer; 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.command.Parameter;
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.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;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import java.util.List; import java.util.List;
import java.util.function.Predicate;
public class CmdFactionsList extends FactionsCommand 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. // 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.
Predicate<MPlayer> predicateOnline = PredicateAnd.get(mp -> mp.getId() != null, SenderColl.PREDICATE_ONLINE, PredicateVisibleTo.get(sender));
// Pager Create // Pager Create
final Pager<Faction> pager = new Pager<>(this, "Faction List", page, (Stringifier<Faction>) (faction, index) -> { final Pager<Faction> pager = new Pager<>(this, "Faction List", page, (Stringifier<Faction>) (faction, index) -> {
if (faction.isNone()) if (faction.isNone())
@ -52,7 +58,7 @@ public class CmdFactionsList extends FactionsCommand
{ {
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.getMPlayersWhereOnlineTo(sender).size(), faction.getMPlayersWhere(predicateOnline).size(),
faction.getMPlayers().size(), faction.getMPlayers().size(),
faction.getLandCount(), faction.getLandCount(),
faction.getPowerRounded(), faction.getPowerRounded(),

View File

@ -17,7 +17,6 @@ import com.massivecraft.massivecore.collections.MassiveMapDef;
import com.massivecraft.massivecore.collections.MassiveSet; import com.massivecraft.massivecore.collections.MassiveSet;
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.PredicateAnd; import com.massivecraft.massivecore.predicate.PredicateAnd;
import com.massivecraft.massivecore.predicate.PredicateVisibleTo; import com.massivecraft.massivecore.predicate.PredicateVisibleTo;
import com.massivecraft.massivecore.ps.PS; import com.massivecraft.massivecore.ps.PS;
@ -1079,12 +1078,12 @@ public class Faction extends Entity<Faction> implements FactionsParticipator, MP
return new MassiveList<>(FactionsIndex.get().getMPlayers(this)); return new MassiveList<>(FactionsIndex.get().getMPlayers(this));
} }
public List<MPlayer> getMPlayers(Predicate<? super MPlayer> where, Comparator<? super MPlayer> orderby, Integer limit, Integer offset) public List<MPlayer> getMPlayers(java.util.function.Predicate<? super MPlayer> where, Comparator<? super MPlayer> orderby, Integer limit, Integer offset)
{ {
return MUtil.transform(this.getMPlayers(), where, orderby, limit, offset); return MUtil.transform(this.getMPlayers(), where, orderby, limit, offset);
} }
public List<MPlayer> getMPlayersWhere(Predicate<? super MPlayer> predicate) public List<MPlayer> getMPlayersWhere(java.util.function.Predicate<? super MPlayer> predicate)
{ {
return this.getMPlayers(predicate, null, null, null); return this.getMPlayers(predicate, null, null, null);
} }