Run clientside player ticking at a different time

This commit is contained in:
fullwall 2020-04-29 20:56:39 +08:00
parent bbf3f281eb
commit 32429f140d
18 changed files with 183 additions and 110 deletions

View File

@ -47,6 +47,7 @@ import net.citizensnpcs.trait.ScoreboardTrait;
import net.citizensnpcs.util.ChunkCoord; import net.citizensnpcs.util.ChunkCoord;
import net.citizensnpcs.util.Messages; import net.citizensnpcs.util.Messages;
import net.citizensnpcs.util.NMS; import net.citizensnpcs.util.NMS;
import net.citizensnpcs.util.PlayerUpdateTask;
import net.citizensnpcs.util.Util; import net.citizensnpcs.util.Util;
public class CitizensNPC extends AbstractNPC { public class CitizensNPC extends AbstractNPC {
@ -87,6 +88,9 @@ public class CitizensNPC extends AbstractNPC {
if (!keepSelected) { if (!keepSelected) {
data().remove("selectors"); data().remove("selectors");
} }
if (getEntity() instanceof Player) {
PlayerUpdateTask.deregisterPlayer(getEntity());
}
navigator.onDespawn(); navigator.onDespawn();
if (reason == DespawnReason.RELOAD) { if (reason == DespawnReason.RELOAD) {
unloadEvents(); unloadEvents();
@ -304,6 +308,10 @@ public class CitizensNPC extends AbstractNPC {
} }
} }
if (getEntity() instanceof Player) {
PlayerUpdateTask.registerPlayer(getEntity());
}
updateFlyableState(); updateFlyableState();
return true; return true;

View File

@ -318,6 +318,10 @@ public class NMS {
BRIDGE.playAnimation(animation, player, radius); BRIDGE.playAnimation(animation, player, radius);
} }
public static void playerTick(Player entity) {
BRIDGE.playerTick(entity);
}
public static void registerEntityClass(Class<?> clazz) { public static void registerEntityClass(Class<?> clazz) {
BRIDGE.registerEntityClass(clazz); BRIDGE.registerEntityClass(clazz);
} }

View File

@ -95,6 +95,8 @@ public interface NMSBridge {
public void playAnimation(PlayerAnimation animation, Player player, int radius); public void playAnimation(PlayerAnimation animation, Player player, int radius);
public void playerTick(Player entity);
public void registerEntityClass(Class<?> clazz); public void registerEntityClass(Class<?> clazz);
public void remove(Entity entity); public void remove(Entity entity);

View File

@ -8,6 +8,7 @@ import java.util.Map;
import java.util.UUID; import java.util.UUID;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
public class PlayerUpdateTask extends BukkitRunnable { public class PlayerUpdateTask extends BukkitRunnable {
@ -37,6 +38,11 @@ public class PlayerUpdateTask extends BukkitRunnable {
itr.remove(); itr.remove();
} }
} }
for (Player entity : PLAYERS.values()) {
if (entity.isValid()) {
NMS.playerTick(entity);
}
}
} }
public static void addOrRemove(org.bukkit.entity.Entity entity, boolean remove) { public static void addOrRemove(org.bukkit.entity.Entity entity, boolean remove) {
@ -50,6 +56,15 @@ public class PlayerUpdateTask extends BukkitRunnable {
} }
} }
public static void deregisterPlayer(org.bukkit.entity.Entity entity) {
PLAYERS.remove(entity.getUniqueId());
}
public static void registerPlayer(org.bukkit.entity.Entity entity) {
PLAYERS.put(entity.getUniqueId(), (Player) entity);
}
private static Map<UUID, org.bukkit.entity.Player> PLAYERS = new HashMap<UUID, org.bukkit.entity.Player>();
private static Map<UUID, org.bukkit.entity.Entity> TICKERS = new HashMap<UUID, org.bukkit.entity.Entity>(); private static Map<UUID, org.bukkit.entity.Entity> TICKERS = new HashMap<UUID, org.bukkit.entity.Entity>();
private static List<org.bukkit.entity.Entity> TICKERS_PENDING_ADD = new ArrayList<org.bukkit.entity.Entity>(); private static List<org.bukkit.entity.Entity> TICKERS_PENDING_ADD = new ArrayList<org.bukkit.entity.Entity>();
private static List<org.bukkit.entity.Entity> TICKERS_PENDING_REMOVE = new ArrayList<org.bukkit.entity.Entity>(); private static List<org.bukkit.entity.Entity> TICKERS_PENDING_REMOVE = new ArrayList<org.bukkit.entity.Entity>();

View File

@ -281,7 +281,12 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
return npc.getNavigator().isNavigating(); return npc.getNavigator().isNavigating();
} }
public void livingEntityBaseTick() { @Override
public void k_() {
if (npc == null) {
super.k_();
return;
}
this.aD = this.aE; this.aD = this.aE;
this.aK = this.aL; this.aK = this.aL;
if (this.hurtTicks > 0) { if (this.hurtTicks > 0) {
@ -305,7 +310,6 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
} }
this.noclip = isSpectator(); this.noclip = isSpectator();
Bukkit.getServer().getPluginManager().unsubscribeFromPermission("bukkit.broadcast.user", bukkitEntity); Bukkit.getServer().getPluginManager().unsubscribeFromPermission("bukkit.broadcast.user", bukkitEntity);
livingEntityBaseTick();
boolean navigating = npc.getNavigator().isNavigating(); boolean navigating = npc.getNavigator().isNavigating();
updatePackets(navigating); updatePackets(navigating);

View File

@ -744,6 +744,11 @@ public class NMSImpl implements NMSBridge {
PlayerAnimationImpl.play(animation, player, radius); PlayerAnimationImpl.play(animation, player, radius);
} }
@Override
public void playerTick(Player entity) {
((EntityPlayer) getHandle(entity)).k_();
}
@Override @Override
public void registerEntityClass(Class<?> clazz) { public void registerEntityClass(Class<?> clazz) {
if (ENTITY_CLASS_TO_INT == null || ENTITY_CLASS_TO_INT.containsKey(clazz)) if (ENTITY_CLASS_TO_INT == null || ENTITY_CLASS_TO_INT.containsKey(clazz))

View File

@ -124,7 +124,6 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
updateEffects = true; updateEffects = true;
} }
Bukkit.getServer().getPluginManager().unsubscribeFromPermission("bukkit.broadcast.user", bukkitEntity); Bukkit.getServer().getPluginManager().unsubscribeFromPermission("bukkit.broadcast.user", bukkitEntity);
livingEntityBaseTick();
boolean navigating = npc.getNavigator().isNavigating(); boolean navigating = npc.getNavigator().isNavigating();
updatePackets(navigating); updatePackets(navigating);
@ -327,21 +326,6 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
return npc.getNavigator().isNavigating(); return npc.getNavigator().isNavigating();
} }
public void livingEntityBaseTick() {
cA();
this.aC = this.aD;
this.aJ = this.aK;
if (this.hurtTicks > 0) {
this.hurtTicks -= 1;
}
tickPotionEffects();
this.aZ = this.aY;
this.aO = this.aN;
this.aQ = this.aP;
this.lastYaw = this.yaw;
this.lastPitch = this.pitch;
}
@Override @Override
public boolean m_() { public boolean m_() {
if (npc == null || !npc.isFlyable()) { if (npc == null || !npc.isFlyable()) {
@ -370,6 +354,26 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
} }
} }
@Override
public void playerTick() {
if (npc == null) {
super.playerTick();
return;
}
cA();
this.aC = this.aD;
this.aJ = this.aK;
if (this.hurtTicks > 0) {
this.hurtTicks -= 1;
}
tickPotionEffects();
this.aZ = this.aY;
this.aO = this.aN;
this.aQ = this.aP;
this.lastYaw = this.yaw;
this.lastPitch = this.pitch;
}
public void setMoveDestination(double x, double y, double z, double speed) { public void setMoveDestination(double x, double y, double z, double speed) {
controllerMove.a(x, y, z, speed); controllerMove.a(x, y, z, speed);
} }

View File

@ -799,6 +799,11 @@ public class NMSImpl implements NMSBridge {
PlayerAnimationImpl.play(animation, player, radius); PlayerAnimationImpl.play(animation, player, radius);
} }
@Override
public void playerTick(Player entity) {
((EntityPlayer) getHandle(entity)).playerTick();
}
@Override @Override
public void registerEntityClass(Class<?> clazz) { public void registerEntityClass(Class<?> clazz) {
if (ENTITY_REGISTRY == null) if (ENTITY_REGISTRY == null)

View File

@ -135,7 +135,6 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
updateEffects = true; updateEffects = true;
} }
Bukkit.getServer().getPluginManager().unsubscribeFromPermission("bukkit.broadcast.user", bukkitEntity); Bukkit.getServer().getPluginManager().unsubscribeFromPermission("bukkit.broadcast.user", bukkitEntity);
livingEntityBaseTick();
boolean navigating = npc.getNavigator().isNavigating(); boolean navigating = npc.getNavigator().isNavigating();
updatePackets(navigating); updatePackets(navigating);
@ -344,21 +343,6 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
return npc.getNavigator().isNavigating(); return npc.getNavigator().isNavigating();
} }
public void livingEntityBaseTick() {
Y();
this.aC = this.aD;
this.aJ = this.aK;
if (this.hurtTicks > 0) {
this.hurtTicks -= 1;
}
tickPotionEffects();
this.aZ = this.aY;
this.aO = this.aN;
this.aQ = this.aP;
this.lastYaw = this.yaw;
this.lastPitch = this.pitch;
}
@Override @Override
public boolean m_() { public boolean m_() {
if (npc == null || !npc.isFlyable()) { if (npc == null || !npc.isFlyable()) {
@ -387,6 +371,26 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
} }
} }
@Override
public void playerTick() {
if (npc == null) {
super.playerTick();
return;
}
Y();
this.aC = this.aD;
this.aJ = this.aK;
if (this.hurtTicks > 0) {
this.hurtTicks -= 1;
}
tickPotionEffects();
this.aZ = this.aY;
this.aO = this.aN;
this.aQ = this.aP;
this.lastYaw = this.yaw;
this.lastPitch = this.pitch;
}
public void setMoveDestination(double x, double y, double z, double speed) { public void setMoveDestination(double x, double y, double z, double speed) {
controllerMove.a(x, y, z, speed); controllerMove.a(x, y, z, speed);
} }

View File

@ -807,6 +807,11 @@ public class NMSImpl implements NMSBridge {
PlayerAnimationImpl.play(animation, player, radius); PlayerAnimationImpl.play(animation, player, radius);
} }
@Override
public void playerTick(Player entity) {
((EntityPlayer) getHandle(entity)).playerTick();
}
@Override @Override
public void registerEntityClass(Class<?> clazz) { public void registerEntityClass(Class<?> clazz) {
if (ENTITY_REGISTRY == null) if (ENTITY_REGISTRY == null)

View File

@ -308,21 +308,6 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
return npc.getNavigator().isNavigating(); return npc.getNavigator().isNavigating();
} }
public void livingEntityBaseTick() {
W();
this.aF = this.aG;
this.aM = this.aN;
if (this.hurtTicks > 0) {
this.hurtTicks -= 1;
}
tickPotionEffects();
this.bc = this.bb;
this.aR = this.aQ;
this.aT = this.aS;
this.lastYaw = this.yaw;
this.lastPitch = this.pitch;
}
private void moveOnCurrentHeading() { private void moveOnCurrentHeading() {
if (bg) { if (bg) {
if (onGround && jumpTicks == 0) { if (onGround && jumpTicks == 0) {
@ -342,6 +327,26 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
} }
} }
@Override
public void playerTick() {
if (npc == null) {
super.playerTick();
return;
}
W();
this.aF = this.aG;
this.aM = this.aN;
if (this.hurtTicks > 0) {
this.hurtTicks -= 1;
}
tickPotionEffects();
this.bc = this.bb;
this.aR = this.aQ;
this.aT = this.aS;
this.lastYaw = this.yaw;
this.lastPitch = this.pitch;
}
public void setMoveDestination(double x, double y, double z, double speed) { public void setMoveDestination(double x, double y, double z, double speed) {
controllerMove.a(x, y, z, speed); controllerMove.a(x, y, z, speed);
} }
@ -393,7 +398,6 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
updateEffects = true; updateEffects = true;
} }
Bukkit.getServer().getPluginManager().unsubscribeFromPermission("bukkit.broadcast.user", bukkitEntity); Bukkit.getServer().getPluginManager().unsubscribeFromPermission("bukkit.broadcast.user", bukkitEntity);
livingEntityBaseTick();
boolean navigating = npc.getNavigator().isNavigating(); boolean navigating = npc.getNavigator().isNavigating();
updatePackets(navigating); updatePackets(navigating);

View File

@ -841,6 +841,11 @@ public class NMSImpl implements NMSBridge {
PlayerAnimationImpl.play(animation, player, radius); PlayerAnimationImpl.play(animation, player, radius);
} }
@Override
public void playerTick(Player entity) {
((EntityPlayer) getHandle(entity)).playerTick();
}
@Override @Override
public void registerEntityClass(Class<?> clazz) { public void registerEntityClass(Class<?> clazz) {
if (ENTITY_REGISTRY == null) if (ENTITY_REGISTRY == null)

View File

@ -313,20 +313,6 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
return npc.getNavigator().isNavigating(); return npc.getNavigator().isNavigating();
} }
public void livingEntityBaseTick() {
entityBaseTick();
this.aB = this.aC;
if (this.hurtTicks > 0) {
this.hurtTicks -= 1;
}
tickPotionEffects();
this.aW = this.aV;
this.aL = this.aK;
this.aN = this.aM;
this.lastYaw = this.yaw;
this.lastPitch = this.pitch;
}
private void moveOnCurrentHeading() { private void moveOnCurrentHeading() {
if (jumping) { if (jumping) {
if (onGround && jumpTicks == 0) { if (onGround && jumpTicks == 0) {
@ -346,6 +332,25 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
} }
} }
@Override
public void playerTick() {
if (npc == null) {
super.playerTick();
return;
}
entityBaseTick();
this.aB = this.aC;
if (this.hurtTicks > 0) {
this.hurtTicks -= 1;
}
tickPotionEffects();
this.aW = this.aV;
this.aL = this.aK;
this.aN = this.aM;
this.lastYaw = this.yaw;
this.lastPitch = this.pitch;
}
public void setMoveDestination(double x, double y, double z, double speed) { public void setMoveDestination(double x, double y, double z, double speed) {
controllerMove.a(x, y, z, speed); controllerMove.a(x, y, z, speed);
} }
@ -397,7 +402,6 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
updateEffects = true; updateEffects = true;
} }
Bukkit.getServer().getPluginManager().unsubscribeFromPermission("bukkit.broadcast.user", getBukkitEntity()); Bukkit.getServer().getPluginManager().unsubscribeFromPermission("bukkit.broadcast.user", getBukkitEntity());
livingEntityBaseTick();
boolean navigating = npc.getNavigator().isNavigating(); boolean navigating = npc.getNavigator().isNavigating();
updatePackets(navigating); updatePackets(navigating);

View File

@ -902,6 +902,11 @@ public class NMSImpl implements NMSBridge {
PlayerAnimationImpl.play(animation, player, radius); PlayerAnimationImpl.play(animation, player, radius);
} }
@Override
public void playerTick(Player entity) {
((EntityPlayer) getHandle(entity)).playerTick();
}
@Override @Override
public void registerEntityClass(Class<?> clazz) { public void registerEntityClass(Class<?> clazz) {
if (ENTITY_REGISTRY == null) if (ENTITY_REGISTRY == null)

View File

@ -11,7 +11,6 @@ import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_15_R1.CraftServer; import org.bukkit.craftbukkit.v1_15_R1.CraftServer;
import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer; import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
import org.bukkit.metadata.MetadataValue; import org.bukkit.metadata.MetadataValue;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
@ -46,7 +45,6 @@ import net.minecraft.server.v1_15_R1.AttributeInstance;
import net.minecraft.server.v1_15_R1.BlockPosition; import net.minecraft.server.v1_15_R1.BlockPosition;
import net.minecraft.server.v1_15_R1.ChatComponentText; import net.minecraft.server.v1_15_R1.ChatComponentText;
import net.minecraft.server.v1_15_R1.DamageSource; import net.minecraft.server.v1_15_R1.DamageSource;
import net.minecraft.server.v1_15_R1.DimensionManager;
import net.minecraft.server.v1_15_R1.Entity; import net.minecraft.server.v1_15_R1.Entity;
import net.minecraft.server.v1_15_R1.EntityHuman; import net.minecraft.server.v1_15_R1.EntityHuman;
import net.minecraft.server.v1_15_R1.EntityPlayer; import net.minecraft.server.v1_15_R1.EntityPlayer;
@ -80,7 +78,6 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
private final Location packetLocationCache = new Location(null, 0, 0, 0); private final Location packetLocationCache = new Location(null, 0, 0, 0);
private final SkinPacketTracker skinTracker; private final SkinPacketTracker skinTracker;
private int updateCounter = 0; private int updateCounter = 0;
private int yawUpdateRequiredTicks;
public EntityHumanNPC(MinecraftServer minecraftServer, WorldServer world, GameProfile gameProfile, public EntityHumanNPC(MinecraftServer minecraftServer, WorldServer world, GameProfile gameProfile,
PlayerInteractManager playerInteractManager, NPC npc) { PlayerInteractManager playerInteractManager, NPC npc) {
@ -317,35 +314,6 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
return npc.getNavigator().isNavigating(); return npc.getNavigator().isNavigating();
} }
public void livingEntityBaseTick() {
// doPortalTick code
boolean old = this.af;
if (af && ag + 1 > ab()) {
af = false;
Bukkit.getServer().getScheduler().runTask(CitizensAPI.getPlugin(), new Runnable() {
@Override
public void run() {
portalCooldown = ba();
a(world.worldProvider.getDimensionManager().getType() == DimensionManager.NETHER
? DimensionManager.OVERWORLD
: DimensionManager.NETHER, TeleportCause.NETHER_PORTAL);
}
});
}
entityBaseTick();
af = old;
this.az = this.aA;
if (this.hurtTicks > 0) {
this.hurtTicks -= 1;
}
tickPotionEffects();
this.aU = this.aT;
this.aJ = this.aI;
this.aL = this.aK;
this.lastYaw = this.yaw;
this.lastPitch = this.pitch;
}
private void moveOnCurrentHeading() { private void moveOnCurrentHeading() {
if (jumping) { if (jumping) {
if (onGround && jumpTicks == 0) { if (onGround && jumpTicks == 0) {
@ -364,6 +332,25 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
} }
} }
@Override
public void playerTick() {
if (npc == null) {
super.playerTick();
return;
}
entityBaseTick();
this.az = this.aA;
if (this.hurtTicks > 0) {
this.hurtTicks -= 1;
}
tickPotionEffects();
this.aU = this.aT;
this.aJ = this.aI;
this.aL = this.aK;
this.lastYaw = this.yaw;
this.lastPitch = this.pitch;
}
public void setMoveDestination(double x, double y, double z, double speed) { public void setMoveDestination(double x, double y, double z, double speed) {
controllerMove.a(x, y, z, speed); controllerMove.a(x, y, z, speed);
} }
@ -415,7 +402,6 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
updateEffects = true; updateEffects = true;
} }
Bukkit.getServer().getPluginManager().unsubscribeFromPermission("bukkit.broadcast.user", getBukkitEntity()); Bukkit.getServer().getPluginManager().unsubscribeFromPermission("bukkit.broadcast.user", getBukkitEntity());
livingEntityBaseTick();
boolean navigating = npc.getNavigator().isNavigating(); boolean navigating = npc.getNavigator().isNavigating();
updatePackets(navigating); updatePackets(navigating);

View File

@ -905,6 +905,11 @@ public class NMSImpl implements NMSBridge {
PlayerAnimationImpl.play(animation, player, radius); PlayerAnimationImpl.play(animation, player, radius);
} }
@Override
public void playerTick(Player entity) {
((EntityPlayer) getHandle(entity)).playerTick();
}
@Override @Override
public void registerEntityClass(Class<?> clazz) { public void registerEntityClass(Class<?> clazz) {
if (ENTITY_REGISTRY == null) if (ENTITY_REGISTRY == null)
@ -1819,7 +1824,6 @@ public class NMSImpl implements NMSBridge {
private static final MethodHandle SIZE_FIELD_GETTER = NMS.getGetter(Entity.class, "size"); private static final MethodHandle SIZE_FIELD_GETTER = NMS.getGetter(Entity.class, "size");
private static final MethodHandle SIZE_FIELD_SETTER = NMS.getSetter(Entity.class, "size"); private static final MethodHandle SIZE_FIELD_SETTER = NMS.getSetter(Entity.class, "size");
private static Field SKULL_PROFILE_FIELD; private static Field SKULL_PROFILE_FIELD;
private static MethodHandle TEAM_FIELD; private static MethodHandle TEAM_FIELD;
static { static {

View File

@ -276,7 +276,12 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
} }
} }
public void livingEntityBaseTick() { @Override
public void l() {
if (npc == null) {
super.l();
return;
}
if (!this.world.isClientSide) { if (!this.world.isClientSide) {
b(0, this.fireTicks > 0); b(0, this.fireTicks > 0);
} }
@ -363,7 +368,6 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
} }
this.noclip = isSpectator(); this.noclip = isSpectator();
Bukkit.getServer().getPluginManager().unsubscribeFromPermission("bukkit.broadcast.user", bukkitEntity); Bukkit.getServer().getPluginManager().unsubscribeFromPermission("bukkit.broadcast.user", bukkitEntity);
livingEntityBaseTick();
boolean navigating = npc.getNavigator().isNavigating(); boolean navigating = npc.getNavigator().isNavigating();
updatePackets(navigating); updatePackets(navigating);

View File

@ -671,6 +671,11 @@ public class NMSImpl implements NMSBridge {
PlayerAnimationImpl.play(animation, player, radius); PlayerAnimationImpl.play(animation, player, radius);
} }
@Override
public void playerTick(Player entity) {
((EntityPlayer) getHandle(entity)).l();
}
@Override @Override
public void registerEntityClass(Class<?> clazz) { public void registerEntityClass(Class<?> clazz) {
if (ENTITY_CLASS_TO_INT == null || ENTITY_CLASS_TO_INT.containsKey(clazz)) if (ENTITY_CLASS_TO_INT == null || ENTITY_CLASS_TO_INT.containsKey(clazz))