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

@ -79,10 +79,7 @@ public class FactionsIndex
{
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)
@ -118,10 +115,7 @@ public class FactionsIndex
{
if (faction == null) throw new NullPointerException("faction");
for (MPlayer mplayer : this.getMPlayers(faction))
{
this.update(mplayer);
}
this.getMPlayers(faction).forEach(this::update);
}
// -------------------------------------------- //

View File

@ -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
{
@ -42,6 +46,8 @@ 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<MPlayer> predicateOnline = PredicateAnd.get(mp -> mp.getId() != null, SenderColl.PREDICATE_ONLINE, PredicateVisibleTo.get(sender));
// Pager Create
final Pager<Faction> pager = new Pager<>(this, "Faction List", page, (Stringifier<Faction>) (faction, index) -> {
if (faction.isNone())
@ -52,7 +58,7 @@ public class CmdFactionsList extends FactionsCommand
{
return Txt.parse("%s<i> %d/%d online, %d/%d/%d",
faction.getName(msender),
faction.getMPlayersWhereOnlineTo(sender).size(),
faction.getMPlayersWhere(predicateOnline).size(),
faction.getMPlayers().size(),
faction.getLandCount(),
faction.getPowerRounded(),

View File

@ -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<Faction> implements FactionsParticipator, MP
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);
}
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);
}