Change isSpawned API to use old valid logic. May fix spawning issues.

This commit is contained in:
fullwall 2019-10-03 13:14:20 +08:00
parent 95e9aa1389
commit d72b6ef9e8
11 changed files with 56 additions and 0 deletions

View File

@ -621,6 +621,13 @@ public class EventListen implements Listener {
List<NPC> ids = toRespawn.get(coord);
for (int i = 0; i < ids.size(); i++) {
NPC npc = ids.get(i);
if (npc.getOwningRegistry().getById(npc.getId()) != npc) {
ids.remove(i--);
if (Messaging.isDebugging()) {
Messaging.debug("Prevented deregistered NPC from respawning", npc.getId());
}
continue;
}
boolean success = spawn(npc);
if (!success) {
if (Messaging.isDebugging()) {

View File

@ -140,6 +140,11 @@ public class CitizensNPC extends AbstractNPC {
return super.isFlyable();
}
@Override
public boolean isSpawned() {
return getEntity() != null && NMS.isValid(getEntity());
}
@Override
public void load(final DataKey root) {
super.load(root);

View File

@ -272,6 +272,10 @@ public class NMS {
return BRIDGE.isOnGround(entity);
}
public static boolean isValid(Entity entity) {
return BRIDGE.isValid(entity);
}
public static void load(CommandManager commands) {
BRIDGE.load(commands);
}

View File

@ -74,6 +74,8 @@ public interface NMSBridge {
public boolean isOnGround(Entity entity);
public boolean isValid(Entity entity);
public void load(CommandManager commands);
public void loadPlugins();

View File

@ -509,6 +509,12 @@ public class NMSImpl implements NMSBridge {
return NMSImpl.getHandle(entity).onGround;
}
@Override
public boolean isValid(org.bukkit.entity.Entity entity) {
Entity handle = getHandle(entity);
return handle.valid && handle.isAlive();
}
@Override
public void load(CommandManager commands) {
CitizensAPI.getTraitFactory().registerTrait(TraitInfo.create(BossBarTrait.class));

View File

@ -549,6 +549,12 @@ public class NMSImpl implements NMSBridge {
return NMSImpl.getHandle(entity).onGround;
}
@Override
public boolean isValid(org.bukkit.entity.Entity entity) {
Entity handle = getHandle(entity);
return handle.valid && handle.isAlive();
}
@Override
public void load(CommandManager manager) {
CitizensAPI.getTraitFactory().registerTrait(TraitInfo.create(BossBarTrait.class));

View File

@ -552,6 +552,12 @@ public class NMSImpl implements NMSBridge {
return NMSImpl.getHandle(entity).onGround;
}
@Override
public boolean isValid(org.bukkit.entity.Entity entity) {
Entity handle = getHandle(entity);
return handle.valid && handle.isAlive();
}
@Override
public void load(CommandManager manager) {
CitizensAPI.getTraitFactory().registerTrait(TraitInfo.create(LlamaTrait.class));

View File

@ -45,7 +45,9 @@ public class HorseController extends MobEntityController {
public static class EntityHorseNPC extends EntityHorse implements NPCHolder {
private double baseMovementSpeed;
private final CitizensNPC npc;
private boolean riding;
public EntityHorseNPC(World world) {

View File

@ -566,6 +566,12 @@ public class NMSImpl implements NMSBridge {
return NMSImpl.getHandle(entity).onGround;
}
@Override
public boolean isValid(org.bukkit.entity.Entity entity) {
Entity handle = getHandle(entity);
return handle.valid && handle.isAlive();
}
@Override
public void load(CommandManager manager) {
CitizensAPI.getTraitFactory().registerTrait(TraitInfo.create(LlamaTrait.class));

View File

@ -596,6 +596,12 @@ public class NMSImpl implements NMSBridge {
return NMSImpl.getHandle(entity).onGround;
}
@Override
public boolean isValid(org.bukkit.entity.Entity entity) {
Entity handle = getHandle(entity);
return handle.valid && handle.isAlive();
}
@Override
public void load(CommandManager manager) {
CitizensAPI.getTraitFactory().registerTrait(TraitInfo.create(CatTrait.class));

View File

@ -478,6 +478,12 @@ public class NMSImpl implements NMSBridge {
return NMSImpl.getHandle(entity).onGround;
}
@Override
public boolean isValid(org.bukkit.entity.Entity entity) {
Entity handle = getHandle(entity);
return handle.valid && handle.isAlive();
}
@Override
public void load(CommandManager commands) {
}