
NPCs count as players for calculation
Xericore opened this issue ยท 6 comments
Version: Better Beds 0.6.1
Hi,
I have the latest Citizens installed and when trying to sleep, the NPCs are counted as players. I made sure that no NPCs have the playerlist flag set to true (http://wiki.citizensnpcs.co/Commands see: /npc playerlist). Also in the Citizens config:
player:
remove-from-list: true
My Better Beds config (rest is default):
minPlayers: 1
sleepPercentage: 0.49
Message in console when three normal players are on the server:
Xericore is now sleeping 1/30 (3.00%)
It looks like the NPCs that are present in the currently loaded chunks count as players when sleeping. We have more NPCs on the server, but I guess these chunks and thus the NPCs aren't loaded.
No NPCs are listed when pressing TAB ingame to check the online players.
Best regards
@Phoenix616 They /don't/ appear in the Bukkit getPlayers() method though.
@mcmonkey4eva Bukkit.getPlayers() is not the method I use. I only use World.getPlayers() (as stated before) and if my plugin somehow registers Citizens' NPCs they have to appear in this method.
@Phoenix616 Here's the source code for World.getPlayers() in Bukkit:
public List<Player> getPlayers() {
List<Player> list = new ArrayList<Player>();
for (Object o : world.entityList) {
if (o instanceof net.minecraft.server.Entity) {
net.minecraft.server.Entity mcEnt = (net.minecraft.server.Entity) o;
Entity bukkitEntity = mcEnt.getBukkitEntity();
if ((bukkitEntity != null) && (bukkitEntity instanceof Player)) {
list.add((Player) bukkitEntity);
}
}
}
return list;
}
It literally scans the entire world entity list for players, rather than, y'know, anything remotely logical.
It's also entirely impossible for us to remove NPCs from this list.
I recommend switching to Bukkit.getPlayers() which is theoretically more efficient (a few thousand fold) for both efficiency and compatibility. You could easily filter that list based on world if needed.
Welp, that method really doesn't look nice. I guess that's another thing I get to fix in foreign projects -.-
I guess I have to migrate to the other method for now.
Sounds like an issue with how Citizens implements their NPCs. Imo such fake players should not appear in the Bukkit API's World.getPlayers() method. Really sounds like a design flaw of that plugin to me.
If they are not willing to fix it I might take a look into how I can combat this.