mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-11-22 10:36:10 +01:00
Cleanup, reduce number of packets per packet update cycle
This commit is contained in:
parent
a2208f0d32
commit
16c418415b
@ -168,14 +168,14 @@ public class CitizensNPC extends AbstractNPC {
|
||||
}
|
||||
|
||||
private void resetCachedCoord() {
|
||||
if (cachedCoord != null) {
|
||||
CHUNK_LOADERS.remove(NPC_METADATA_MARKER, CHUNK_LOADERS);
|
||||
CHUNK_LOADERS.remove(cachedCoord, this);
|
||||
if (CHUNK_LOADERS.get(cachedCoord).size() == 0) {
|
||||
cachedCoord.setForceLoaded(false);
|
||||
}
|
||||
cachedCoord = null;
|
||||
if (cachedCoord == null)
|
||||
return;
|
||||
CHUNK_LOADERS.remove(NPC_METADATA_MARKER, CHUNK_LOADERS);
|
||||
CHUNK_LOADERS.remove(cachedCoord, this);
|
||||
if (CHUNK_LOADERS.get(cachedCoord).size() == 0) {
|
||||
cachedCoord.setForceLoaded(false);
|
||||
}
|
||||
cachedCoord = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -344,7 +344,8 @@ public class CitizensNPC extends AbstractNPC {
|
||||
}
|
||||
}
|
||||
|
||||
if (!getNavigator().isNavigating() && updateCounter++ > Setting.PACKET_UPDATE_DELAY.asInt()) {
|
||||
boolean isLiving = getEntity() instanceof LivingEntity;
|
||||
if (updateCounter++ > Setting.PACKET_UPDATE_DELAY.asInt()) {
|
||||
if (Setting.KEEP_CHUNKS_LOADED.asBoolean()) {
|
||||
ChunkCoord currentCoord = new ChunkCoord(getStoredLocation());
|
||||
if (!currentCoord.equals(cachedCoord)) {
|
||||
@ -354,24 +355,18 @@ public class CitizensNPC extends AbstractNPC {
|
||||
cachedCoord = currentCoord;
|
||||
}
|
||||
}
|
||||
updateCounter = 0;
|
||||
|
||||
Player player = getEntity().getType() == EntityType.PLAYER ? (Player) getEntity() : null;
|
||||
NMS.sendPositionUpdate(player, getEntity(), getStoredLocation());
|
||||
}
|
||||
|
||||
if (getEntity() instanceof LivingEntity) {
|
||||
if (updateCounter == 0) {
|
||||
if (isLiving) {
|
||||
updateCustomName();
|
||||
}
|
||||
updateCounter = 0;
|
||||
}
|
||||
|
||||
if (isLiving) {
|
||||
String nameplateVisible = data().<Object> get(NPC.NAMEPLATE_VISIBLE_METADATA, true).toString();
|
||||
((LivingEntity) getEntity()).setCustomNameVisible(Boolean.parseBoolean(nameplateVisible));
|
||||
|
||||
if (data().get(NPC.DEFAULT_PROTECTED_METADATA, true)) {
|
||||
NMS.setKnockbackResistance((LivingEntity) getEntity(), 1D);
|
||||
} else {
|
||||
NMS.setKnockbackResistance((LivingEntity) getEntity(), 0D);
|
||||
}
|
||||
NMS.setKnockbackResistance((LivingEntity) getEntity(),
|
||||
data().get(NPC.DEFAULT_PROTECTED_METADATA, true) ? 1D : 0D);
|
||||
}
|
||||
|
||||
if (SUPPORT_SILENT && data().has(NPC.SILENT_METADATA)) {
|
||||
|
@ -51,13 +51,11 @@ import net.minecraft.server.v1_10_R1.EnumItemSlot;
|
||||
import net.minecraft.server.v1_10_R1.EnumProtocolDirection;
|
||||
import net.minecraft.server.v1_10_R1.GenericAttributes;
|
||||
import net.minecraft.server.v1_10_R1.IBlockData;
|
||||
import net.minecraft.server.v1_10_R1.MathHelper;
|
||||
import net.minecraft.server.v1_10_R1.MinecraftServer;
|
||||
import net.minecraft.server.v1_10_R1.NavigationAbstract;
|
||||
import net.minecraft.server.v1_10_R1.NetworkManager;
|
||||
import net.minecraft.server.v1_10_R1.Packet;
|
||||
import net.minecraft.server.v1_10_R1.PacketPlayOutEntityEquipment;
|
||||
import net.minecraft.server.v1_10_R1.PacketPlayOutEntityHeadRotation;
|
||||
import net.minecraft.server.v1_10_R1.PathType;
|
||||
import net.minecraft.server.v1_10_R1.PlayerInteractManager;
|
||||
import net.minecraft.server.v1_10_R1.WorldServer;
|
||||
@ -415,11 +413,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
|
||||
return;
|
||||
updateCounter = 0;
|
||||
Location current = getBukkitEntity().getLocation(packetLocationCache);
|
||||
Packet<?>[] packets = new Packet[navigating ? EnumItemSlot.values().length : EnumItemSlot.values().length + 1];
|
||||
if (!navigating) {
|
||||
packets[5] = new PacketPlayOutEntityHeadRotation(this,
|
||||
(byte) MathHelper.d(NMSImpl.getHeadYaw(this) * 256.0F / 360.0F));
|
||||
}
|
||||
Packet<?>[] packets = new Packet[EnumItemSlot.values().length];
|
||||
int i = 0;
|
||||
for (EnumItemSlot slot : EnumItemSlot.values()) {
|
||||
packets[i++] = new PacketPlayOutEntityEquipment(getId(), slot, getEquipment(slot));
|
||||
|
@ -53,13 +53,11 @@ import net.minecraft.server.v1_11_R1.EnumProtocolDirection;
|
||||
import net.minecraft.server.v1_11_R1.GenericAttributes;
|
||||
import net.minecraft.server.v1_11_R1.IBlockData;
|
||||
import net.minecraft.server.v1_11_R1.IChatBaseComponent;
|
||||
import net.minecraft.server.v1_11_R1.MathHelper;
|
||||
import net.minecraft.server.v1_11_R1.MinecraftServer;
|
||||
import net.minecraft.server.v1_11_R1.NavigationAbstract;
|
||||
import net.minecraft.server.v1_11_R1.NetworkManager;
|
||||
import net.minecraft.server.v1_11_R1.Packet;
|
||||
import net.minecraft.server.v1_11_R1.PacketPlayOutEntityEquipment;
|
||||
import net.minecraft.server.v1_11_R1.PacketPlayOutEntityHeadRotation;
|
||||
import net.minecraft.server.v1_11_R1.PathType;
|
||||
import net.minecraft.server.v1_11_R1.PlayerInteractManager;
|
||||
import net.minecraft.server.v1_11_R1.WorldServer;
|
||||
@ -427,11 +425,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
|
||||
|
||||
updateCounter = 0;
|
||||
Location current = getBukkitEntity().getLocation(packetLocationCache);
|
||||
Packet<?>[] packets = new Packet[navigating ? EnumItemSlot.values().length : EnumItemSlot.values().length + 1];
|
||||
if (!navigating) {
|
||||
packets[5] = new PacketPlayOutEntityHeadRotation(this,
|
||||
(byte) MathHelper.d(NMSImpl.getHeadYaw(this) * 256.0F / 360.0F));
|
||||
}
|
||||
Packet<?>[] packets = new Packet[EnumItemSlot.values().length];
|
||||
int i = 0;
|
||||
for (EnumItemSlot slot : EnumItemSlot.values()) {
|
||||
packets[i++] = new PacketPlayOutEntityEquipment(getId(), slot, getEquipment(slot));
|
||||
|
@ -55,13 +55,11 @@ import net.minecraft.server.v1_12_R1.EnumProtocolDirection;
|
||||
import net.minecraft.server.v1_12_R1.GenericAttributes;
|
||||
import net.minecraft.server.v1_12_R1.IBlockData;
|
||||
import net.minecraft.server.v1_12_R1.IChatBaseComponent;
|
||||
import net.minecraft.server.v1_12_R1.MathHelper;
|
||||
import net.minecraft.server.v1_12_R1.MinecraftServer;
|
||||
import net.minecraft.server.v1_12_R1.NavigationAbstract;
|
||||
import net.minecraft.server.v1_12_R1.NetworkManager;
|
||||
import net.minecraft.server.v1_12_R1.Packet;
|
||||
import net.minecraft.server.v1_12_R1.PacketPlayOutEntityEquipment;
|
||||
import net.minecraft.server.v1_12_R1.PacketPlayOutEntityHeadRotation;
|
||||
import net.minecraft.server.v1_12_R1.PathType;
|
||||
import net.minecraft.server.v1_12_R1.PlayerInteractManager;
|
||||
import net.minecraft.server.v1_12_R1.WorldServer;
|
||||
@ -444,11 +442,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
|
||||
|
||||
updateCounter = 0;
|
||||
Location current = getBukkitEntity().getLocation(packetLocationCache);
|
||||
Packet<?>[] packets = new Packet[navigating ? EnumItemSlot.values().length : EnumItemSlot.values().length + 1];
|
||||
if (!navigating) {
|
||||
packets[5] = new PacketPlayOutEntityHeadRotation(this,
|
||||
(byte) MathHelper.d(NMSImpl.getHeadYaw(this) * 256.0F / 360.0F));
|
||||
}
|
||||
Packet<?>[] packets = new Packet[EnumItemSlot.values().length];
|
||||
int i = 0;
|
||||
for (EnumItemSlot slot : EnumItemSlot.values()) {
|
||||
packets[i++] = new PacketPlayOutEntityEquipment(getId(), slot, getEquipment(slot));
|
||||
|
@ -55,13 +55,11 @@ import net.minecraft.server.v1_13_R2.EnumProtocolDirection;
|
||||
import net.minecraft.server.v1_13_R2.GenericAttributes;
|
||||
import net.minecraft.server.v1_13_R2.IBlockData;
|
||||
import net.minecraft.server.v1_13_R2.IChatBaseComponent;
|
||||
import net.minecraft.server.v1_13_R2.MathHelper;
|
||||
import net.minecraft.server.v1_13_R2.MinecraftServer;
|
||||
import net.minecraft.server.v1_13_R2.NavigationAbstract;
|
||||
import net.minecraft.server.v1_13_R2.NetworkManager;
|
||||
import net.minecraft.server.v1_13_R2.Packet;
|
||||
import net.minecraft.server.v1_13_R2.PacketPlayOutEntityEquipment;
|
||||
import net.minecraft.server.v1_13_R2.PacketPlayOutEntityHeadRotation;
|
||||
import net.minecraft.server.v1_13_R2.PathType;
|
||||
import net.minecraft.server.v1_13_R2.PlayerInteractManager;
|
||||
import net.minecraft.server.v1_13_R2.WorldServer;
|
||||
@ -435,11 +433,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
|
||||
|
||||
updateCounter = 0;
|
||||
Location current = getBukkitEntity().getLocation(packetLocationCache);
|
||||
Packet<?>[] packets = new Packet[navigating ? EnumItemSlot.values().length : EnumItemSlot.values().length + 1];
|
||||
if (!navigating) {
|
||||
packets[5] = new PacketPlayOutEntityHeadRotation(this,
|
||||
(byte) MathHelper.d(NMSImpl.getHeadYaw(this) * 256.0F / 360.0F));
|
||||
}
|
||||
Packet<?>[] packets = new Packet[EnumItemSlot.values().length];
|
||||
int i = 0;
|
||||
for (EnumItemSlot slot : EnumItemSlot.values()) {
|
||||
packets[i++] = new PacketPlayOutEntityEquipment(getId(), slot, getEquipment(slot));
|
||||
|
@ -54,13 +54,11 @@ import net.minecraft.server.v1_14_R1.EnumProtocolDirection;
|
||||
import net.minecraft.server.v1_14_R1.GenericAttributes;
|
||||
import net.minecraft.server.v1_14_R1.IBlockData;
|
||||
import net.minecraft.server.v1_14_R1.IChatBaseComponent;
|
||||
import net.minecraft.server.v1_14_R1.MathHelper;
|
||||
import net.minecraft.server.v1_14_R1.MinecraftServer;
|
||||
import net.minecraft.server.v1_14_R1.NavigationAbstract;
|
||||
import net.minecraft.server.v1_14_R1.NetworkManager;
|
||||
import net.minecraft.server.v1_14_R1.Packet;
|
||||
import net.minecraft.server.v1_14_R1.PacketPlayOutEntityEquipment;
|
||||
import net.minecraft.server.v1_14_R1.PacketPlayOutEntityHeadRotation;
|
||||
import net.minecraft.server.v1_14_R1.PathType;
|
||||
import net.minecraft.server.v1_14_R1.PlayerInteractManager;
|
||||
import net.minecraft.server.v1_14_R1.Vec3D;
|
||||
@ -440,11 +438,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
|
||||
|
||||
updateCounter = 0;
|
||||
Location current = getBukkitEntity().getLocation(packetLocationCache);
|
||||
Packet<?>[] packets = new Packet[navigating ? EnumItemSlot.values().length : EnumItemSlot.values().length + 1];
|
||||
if (!navigating) {
|
||||
packets[5] = new PacketPlayOutEntityHeadRotation(this,
|
||||
(byte) MathHelper.d(NMSImpl.getHeadYaw(this) * 256.0F / 360.0F));
|
||||
}
|
||||
Packet<?>[] packets = new Packet[EnumItemSlot.values().length];
|
||||
int i = 0;
|
||||
for (EnumItemSlot slot : EnumItemSlot.values()) {
|
||||
packets[i++] = new PacketPlayOutEntityEquipment(getId(), slot, getEquipment(slot));
|
||||
|
@ -54,13 +54,11 @@ import net.minecraft.server.v1_15_R1.EnumProtocolDirection;
|
||||
import net.minecraft.server.v1_15_R1.GenericAttributes;
|
||||
import net.minecraft.server.v1_15_R1.IBlockData;
|
||||
import net.minecraft.server.v1_15_R1.IChatBaseComponent;
|
||||
import net.minecraft.server.v1_15_R1.MathHelper;
|
||||
import net.minecraft.server.v1_15_R1.MinecraftServer;
|
||||
import net.minecraft.server.v1_15_R1.NavigationAbstract;
|
||||
import net.minecraft.server.v1_15_R1.NetworkManager;
|
||||
import net.minecraft.server.v1_15_R1.Packet;
|
||||
import net.minecraft.server.v1_15_R1.PacketPlayOutEntityEquipment;
|
||||
import net.minecraft.server.v1_15_R1.PacketPlayOutEntityHeadRotation;
|
||||
import net.minecraft.server.v1_15_R1.PathType;
|
||||
import net.minecraft.server.v1_15_R1.PlayerInteractManager;
|
||||
import net.minecraft.server.v1_15_R1.Vec3D;
|
||||
@ -450,11 +448,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
|
||||
|
||||
updateCounter = 0;
|
||||
Location current = getBukkitEntity().getLocation(packetLocationCache);
|
||||
Packet<?>[] packets = new Packet[navigating ? EnumItemSlot.values().length : EnumItemSlot.values().length + 1];
|
||||
if (!navigating) {
|
||||
packets[5] = new PacketPlayOutEntityHeadRotation(this,
|
||||
(byte) MathHelper.d(NMSImpl.getHeadYaw(this) * 256.0F / 360.0F));
|
||||
}
|
||||
Packet<?>[] packets = new Packet[EnumItemSlot.values().length];
|
||||
int i = 0;
|
||||
for (EnumItemSlot slot : EnumItemSlot.values()) {
|
||||
packets[i++] = new PacketPlayOutEntityEquipment(getId(), slot, getEquipment(slot));
|
||||
|
@ -46,13 +46,11 @@ import net.minecraft.server.v1_8_R3.Entity;
|
||||
import net.minecraft.server.v1_8_R3.EntityPlayer;
|
||||
import net.minecraft.server.v1_8_R3.EnumProtocolDirection;
|
||||
import net.minecraft.server.v1_8_R3.GenericAttributes;
|
||||
import net.minecraft.server.v1_8_R3.MathHelper;
|
||||
import net.minecraft.server.v1_8_R3.MinecraftServer;
|
||||
import net.minecraft.server.v1_8_R3.NavigationAbstract;
|
||||
import net.minecraft.server.v1_8_R3.NetworkManager;
|
||||
import net.minecraft.server.v1_8_R3.Packet;
|
||||
import net.minecraft.server.v1_8_R3.PacketPlayOutEntityEquipment;
|
||||
import net.minecraft.server.v1_8_R3.PacketPlayOutEntityHeadRotation;
|
||||
import net.minecraft.server.v1_8_R3.PlayerInteractManager;
|
||||
import net.minecraft.server.v1_8_R3.WorldServer;
|
||||
import net.minecraft.server.v1_8_R3.WorldSettings;
|
||||
@ -404,11 +402,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
|
||||
return;
|
||||
updateCounter = 0;
|
||||
Location current = getBukkitEntity().getLocation(packetLocationCache);
|
||||
Packet<?>[] packets = new Packet[navigating ? this.inventory.armor.length : this.inventory.armor.length + 1];
|
||||
if (!navigating) {
|
||||
packets[this.inventory.armor.length] = new PacketPlayOutEntityHeadRotation(this,
|
||||
(byte) MathHelper.d(NMSImpl.getHeadYaw(this) * 256.0F / 360.0F));
|
||||
}
|
||||
Packet<?>[] packets = new Packet[this.inventory.armor.length];
|
||||
for (int i = 0; i < this.inventory.armor.length; i++) {
|
||||
packets[i] = new PacketPlayOutEntityEquipment(getId(), i, getEquipment(i));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user