Add packet update delay setting

This commit is contained in:
fullwall 2014-02-18 20:29:21 +08:00
parent e248d3f7f9
commit f897ab728d
4 changed files with 261 additions and 261 deletions

View File

@ -96,6 +96,7 @@ public class Settings {
MESSAGE_COLOUR("general.color-scheme.message", "<a>"),
NPC_ATTACK_DISTANCE("npc.pathfinding.attack-range", 1.75 * 1.75),
NPC_COST("economy.npc.cost", 100D),
PACKET_UPDATE_DELAY("npc.packets.update-delay", 30),
QUICK_SELECT("npc.selection.quick-select", false),
REMOVE_PLAYERS_FROM_PLAYER_LIST("npc.player.remove-from-list", true),
SAVE_TASK_DELAY("storage.save-task.delay", 20 * 60 * 60),

View File

@ -217,7 +217,8 @@ public class CitizensNPC extends AbstractNPC {
}
navigator.run();
if (!getNavigator().isNavigating() && getEntity().getWorld().getTime() % 30 == 0) {
if (!getNavigator().isNavigating()
&& getEntity().getWorld().getTime() % Setting.PACKET_UPDATE_DELAY.asInt() == 0) {
Player player = getEntity() instanceof Player ? (Player) getEntity() : null;
NMS.sendPacketNearby(player, getStoredLocation(),
new PacketPlayOutEntityTeleport(NMS.getHandle(getEntity())));

View File

@ -52,7 +52,6 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder {
private PlayerNavigation navigation;
private final CitizensNPC npc;
private final Location packetLocationCache = new Location(null, 0, 0, 0);
private int packetUpdateCount;
private int useListName = -1;
public EntityHumanNPC(MinecraftServer minecraftServer, WorldServer world, GameProfile gameProfile,
@ -258,7 +257,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder {
}
private void updatePackets(boolean navigating) {
if (++packetUpdateCount >= 30) {
if (world.getWorld().getTime() % Setting.PACKET_UPDATE_DELAY.asInt() == 0) {
Location current = getBukkitEntity().getLocation(packetLocationCache);
Packet[] packets = new Packet[navigating ? 6 : 7];
if (!navigating) {
@ -278,7 +277,6 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder {
removeFromPlayerList ? 9999 : ping);
}
NMS.sendPacketsNearby(getBukkitEntity(), current, packets);
packetUpdateCount = 0;
}
}