Add a keep-chunks-loaded setting, fix Player NPC movement code

This commit is contained in:
fullwall 2012-11-19 09:42:20 +08:00
parent 7701bb97c9
commit 8a1765873b
6 changed files with 18 additions and 23 deletions

View File

@ -62,7 +62,6 @@ public class Citizens extends JavaPlugin implements CitizensPlugin {
private boolean compatible; private boolean compatible;
private Settings config; private Settings config;
private ClassLoader contextClassLoader; private ClassLoader contextClassLoader;
private Metrics metrics;
private CitizensNPCRegistry npcRegistry; private CitizensNPCRegistry npcRegistry;
private NPCDataStore saves; private NPCDataStore saves;
private NPCSelector selector; private NPCSelector selector;
@ -181,8 +180,6 @@ public class Citizens extends JavaPlugin implements CitizensPlugin {
Bukkit.getPluginManager().callEvent(new CitizensDisableEvent()); Bukkit.getPluginManager().callEvent(new CitizensDisableEvent());
Editor.leaveAll(); Editor.leaveAll();
CitizensAPI.shutdown(); CitizensAPI.shutdown();
if (metrics != null)
metrics.stop();
tearDownScripting(); tearDownScripting();
// Don't bother with this part if MC versions are not compatible // Don't bother with this part if MC versions are not compatible
@ -326,7 +323,7 @@ public class Citizens extends JavaPlugin implements CitizensPlugin {
private void startMetrics() { private void startMetrics() {
try { try {
metrics = new Metrics(Citizens.this); Metrics metrics = new Metrics(Citizens.this);
if (metrics.isOptOut()) if (metrics.isOptOut())
return; return;
metrics.addCustomData(new Metrics.Plotter("Total NPCs") { metrics.addCustomData(new Metrics.Plotter("Total NPCs") {
@ -379,8 +376,11 @@ public class Citizens extends JavaPlugin implements CitizensPlugin {
} }
private void tearDownScripting() { private void tearDownScripting() {
if (contextClassLoader == null)
return;
if (Thread.currentThread().getContextClassLoader() == getClassLoader()) if (Thread.currentThread().getContextClassLoader() == getClassLoader())
Thread.currentThread().setContextClassLoader(contextClassLoader); Thread.currentThread().setContextClassLoader(contextClassLoader);
contextClassLoader = null;
} }
private static final String COMPATIBLE_MC_VERSION = "1.4"; private static final String COMPATIBLE_MC_VERSION = "1.4";

View File

@ -82,10 +82,13 @@ public class EventListen implements Listener {
@EventHandler(ignoreCancelled = true) @EventHandler(ignoreCancelled = true)
public void onChunkUnload(ChunkUnloadEvent event) { public void onChunkUnload(ChunkUnloadEvent event) {
ChunkCoord coord = toCoord(event.getChunk()); ChunkCoord coord = toCoord(event.getChunk());
boolean forceLoad = Setting.KEEP_CHUNKS_LOADED.asBoolean();
for (NPC npc : npcRegistry) { for (NPC npc : npcRegistry) {
if (!npc.isSpawned()) if (!npc.isSpawned())
continue; continue;
Location loc = npc.getBukkitEntity().getLocation(); Location loc = npc.getBukkitEntity().getLocation();
if (forceLoad && loc.getChunk().isLoaded())
continue; // location#getChunk() forces chunk to load
boolean sameChunkCoordinates = coord.z == loc.getBlockZ() >> 4 && coord.x == loc.getBlockX() >> 4; boolean sameChunkCoordinates = coord.z == loc.getBlockZ() >> 4 && coord.x == loc.getBlockX() >> 4;
if (event.getWorld().equals(loc.getWorld()) && sameChunkCoordinates) { if (event.getWorld().equals(loc.getWorld()) && sameChunkCoordinates) {
npc.despawn(); npc.despawn();

View File

@ -459,15 +459,6 @@ public class Metrics {
} }
} }
public void stop() {
synchronized (optOutLock) {
if (taskId > 0) {
plugin.getServer().getScheduler().cancelTask(taskId);
taskId = -1;
}
}
}
/** /**
* Represents a custom graph on the website * Represents a custom graph on the website
*/ */

View File

@ -84,7 +84,8 @@ public class Settings {
SUBPLUGIN_FOLDER("subplugins.folder", "plugins"), SUBPLUGIN_FOLDER("subplugins.folder", "plugins"),
TALK_CLOSE_MAXIMUM_COOLDOWN("npc.text.max-talk-cooldown", 60), TALK_CLOSE_MAXIMUM_COOLDOWN("npc.text.max-talk-cooldown", 60),
TALK_CLOSE_MINIMUM_COOLDOWN("npc.text.min-talk-cooldown", 30), TALK_CLOSE_MINIMUM_COOLDOWN("npc.text.min-talk-cooldown", 30),
TALK_ITEM("npc.text.talk-item", "340"); TALK_ITEM("npc.text.talk-item", "340"),
KEEP_CHUNKS_LOADED("npc.chunks.always-keep-loaded", false);
protected String path; protected String path;
protected Object value; protected Object value;

View File

@ -151,20 +151,20 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder {
if (inLiquid) { if (inLiquid) {
motY += 0.04; motY += 0.04;
} else //(handled elsewhere)*/ } else //(handled elsewhere)*/
if (onGround && bW == 0) { if (onGround && bU == 0) {
bf(); bi();
bW = 10; bU = 10;
} }
} else } else
bW = 0; bU = 0;
bD *= 0.98F; bB *= 0.98F;
bH *= 0.98F; bC *= 0.98F;
bF *= 0.9F; bD *= 0.9F;
float prev = aM; float prev = aM;
aM *= bB(); aM *= bB();
e(bD, bC); // movement method e(bB, bC); // movement method
aM = prev; aM = prev;
NMS.setHeadYaw(this, yaw); NMS.setHeadYaw(this, yaw);
} }

View File

@ -261,7 +261,7 @@ public class NMS {
entity.getNavigation().e(); entity.getNavigation().e();
entity.getControllerMove().c(); entity.getControllerMove().c();
entity.getControllerLook().a(); entity.getControllerLook().a();
entity.getControllerJump().b(); entity.getControllerJump().b();
} }
public static void updateNavigationWorld(org.bukkit.entity.Entity entity, org.bukkit.World world) { public static void updateNavigationWorld(org.bukkit.entity.Entity entity, org.bukkit.World world) {