Try to avoid handling player properties twice if respawning in the same tick

This commit is contained in:
fullwall 2020-09-13 16:16:54 +08:00
parent d334d86f3d
commit ab16b50814
10 changed files with 48 additions and 24 deletions

View File

@ -60,7 +60,8 @@ public class HumanController extends AbstractEntityController {
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), new Runnable() {
@Override
public void run() {
if (getBukkitEntity() == null || !getBukkitEntity().isValid())
if (getBukkitEntity() == null || !getBukkitEntity().isValid()
|| getBukkitEntity() != handle.getBukkitEntity())
return;
boolean removeFromPlayerList = npc.data().get("removefromplayerlist",
Setting.REMOVE_PLAYERS_FROM_PLAYER_LIST.asBoolean());

View File

@ -60,7 +60,8 @@ public class HumanController extends AbstractEntityController {
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), new Runnable() {
@Override
public void run() {
if (getBukkitEntity() == null || !getBukkitEntity().isValid())
if (getBukkitEntity() == null || !getBukkitEntity().isValid()
|| getBukkitEntity() != handle.getBukkitEntity())
return;
boolean removeFromPlayerList = npc.data().get("removefromplayerlist",
Setting.REMOVE_PLAYERS_FROM_PLAYER_LIST.asBoolean());

View File

@ -60,7 +60,8 @@ public class HumanController extends AbstractEntityController {
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), new Runnable() {
@Override
public void run() {
if (getBukkitEntity() == null || !getBukkitEntity().isValid())
if (getBukkitEntity() == null || !getBukkitEntity().isValid()
|| getBukkitEntity() != handle.getBukkitEntity())
return;
boolean removeFromPlayerList = npc.data().get("removefromplayerlist",
Setting.REMOVE_PLAYERS_FROM_PLAYER_LIST.asBoolean());

View File

@ -60,7 +60,8 @@ public class HumanController extends AbstractEntityController {
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), new Runnable() {
@Override
public void run() {
if (getBukkitEntity() == null || !getBukkitEntity().isValid())
if (getBukkitEntity() == null || !getBukkitEntity().isValid()
|| getBukkitEntity() != handle.getBukkitEntity())
return;
boolean removeFromPlayerList = npc.data().get("removefromplayerlist",
Setting.REMOVE_PLAYERS_FROM_PLAYER_LIST.asBoolean());

View File

@ -60,7 +60,8 @@ public class HumanController extends AbstractEntityController {
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), new Runnable() {
@Override
public void run() {
if (getBukkitEntity() == null || !getBukkitEntity().isValid())
if (getBukkitEntity() == null || !getBukkitEntity().isValid()
|| getBukkitEntity() != handle.getBukkitEntity())
return;
boolean removeFromPlayerList = npc.data().get("removefromplayerlist",
Setting.REMOVE_PLAYERS_FROM_PLAYER_LIST.asBoolean());

View File

@ -60,7 +60,8 @@ public class HumanController extends AbstractEntityController {
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), new Runnable() {
@Override
public void run() {
if (getBukkitEntity() == null || !getBukkitEntity().isValid())
if (getBukkitEntity() == null || !getBukkitEntity().isValid()
|| getBukkitEntity() != handle.getBukkitEntity())
return;
boolean removeFromPlayerList = npc.data().get("removefromplayerlist",
Setting.REMOVE_PLAYERS_FROM_PLAYER_LIST.asBoolean());

View File

@ -60,7 +60,8 @@ public class HumanController extends AbstractEntityController {
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), new Runnable() {
@Override
public void run() {
if (getBukkitEntity() == null || !getBukkitEntity().isValid())
if (getBukkitEntity() == null || !getBukkitEntity().isValid()
|| getBukkitEntity() != handle.getBukkitEntity())
return;
boolean removeFromPlayerList = npc.data().get("removefromplayerlist",
Setting.REMOVE_PLAYERS_FROM_PLAYER_LIST.asBoolean());

View File

@ -1,8 +1,5 @@
package net.citizensnpcs.nms.v1_16_R2.entity.nonliving;
import net.citizensnpcs.nms.v1_16_R2.entity.MobEntityController;
import net.citizensnpcs.nms.v1_16_R2.util.NMSImpl;
import org.bukkit.Bukkit;
import org.bukkit.craftbukkit.v1_16_R2.CraftServer;
import org.bukkit.craftbukkit.v1_16_R2.entity.CraftEnderSignal;
@ -12,6 +9,8 @@ import org.bukkit.util.Vector;
import net.citizensnpcs.api.event.NPCPushEvent;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.nms.v1_16_R2.entity.MobEntityController;
import net.citizensnpcs.nms.v1_16_R2.util.NMSImpl;
import net.citizensnpcs.npc.CitizensNPC;
import net.citizensnpcs.npc.ai.NPCHolder;
import net.citizensnpcs.util.Util;
@ -71,6 +70,19 @@ public class EnderSignalController extends MobEntityController {
return npc == null ? super.d(save) : false;
}
@Override
public CraftEntity getBukkitEntity() {
if (npc != null && !(super.getBukkitEntity() instanceof NPCHolder)) {
NMSImpl.setBukkitEntity(this, new EnderSignalNPC(this));
}
return super.getBukkitEntity();
}
@Override
public NPC getNPC() {
return npc;
}
@Override
public void i(double x, double y, double z) {
if (npc == null) {
@ -93,19 +105,6 @@ public class EnderSignalController extends MobEntityController {
// cancelled.
}
@Override
public CraftEntity getBukkitEntity() {
if (npc != null && !(super.getBukkitEntity() instanceof NPCHolder)) {
NMSImpl.setBukkitEntity(this, new EnderSignalNPC(this));
}
return super.getBukkitEntity();
}
@Override
public NPC getNPC() {
return npc;
}
@Override
public void tick() {
if (npc != null) {

View File

@ -1628,6 +1628,15 @@ public class NMSImpl implements NMSBridge {
return null;
}
public static EntitySize getSize(Entity entity) {
try {
return (EntitySize) SIZE_FIELD_GETTER.invoke(entity);
} catch (Throwable e) {
e.printStackTrace();
}
return null;
}
public static SoundEffect getSoundEffect(NPC npc, SoundEffect snd, String meta) {
return npc == null || !npc.data().has(meta) ? snd
: IRegistry.SOUND_EVENT.get(new MinecraftKey(npc.data().get(meta, snd == null ? "" : snd.toString())));
@ -1777,6 +1786,14 @@ public class NMSImpl implements NMSBridge {
}
}
public static void setSize(Entity entity, EntitySize size) {
try {
SIZE_FIELD_SETTER.invoke(entity, size);
} catch (Throwable e) {
e.printStackTrace();
}
}
public static void stopNavigation(NavigationAbstract navigation) {
navigation.o();
}

View File

@ -61,7 +61,8 @@ public class HumanController extends AbstractEntityController {
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), new Runnable() {
@Override
public void run() {
if (getBukkitEntity() == null || !getBukkitEntity().isValid())
if (getBukkitEntity() == null || !getBukkitEntity().isValid()
|| getBukkitEntity() != handle.getBukkitEntity())
return;
boolean removeFromPlayerList = npc.data().get("removefromplayerlist",
Setting.REMOVE_PLAYERS_FROM_PLAYER_LIST.asBoolean());