mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-11-24 03:25:13 +01:00
Add a keep-chunks-loaded setting, fix Player NPC movement code
This commit is contained in:
parent
7701bb97c9
commit
8a1765873b
@ -62,7 +62,6 @@ public class Citizens extends JavaPlugin implements CitizensPlugin {
|
||||
private boolean compatible;
|
||||
private Settings config;
|
||||
private ClassLoader contextClassLoader;
|
||||
private Metrics metrics;
|
||||
private CitizensNPCRegistry npcRegistry;
|
||||
private NPCDataStore saves;
|
||||
private NPCSelector selector;
|
||||
@ -181,8 +180,6 @@ public class Citizens extends JavaPlugin implements CitizensPlugin {
|
||||
Bukkit.getPluginManager().callEvent(new CitizensDisableEvent());
|
||||
Editor.leaveAll();
|
||||
CitizensAPI.shutdown();
|
||||
if (metrics != null)
|
||||
metrics.stop();
|
||||
|
||||
tearDownScripting();
|
||||
// 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() {
|
||||
try {
|
||||
metrics = new Metrics(Citizens.this);
|
||||
Metrics metrics = new Metrics(Citizens.this);
|
||||
if (metrics.isOptOut())
|
||||
return;
|
||||
metrics.addCustomData(new Metrics.Plotter("Total NPCs") {
|
||||
@ -379,8 +376,11 @@ public class Citizens extends JavaPlugin implements CitizensPlugin {
|
||||
}
|
||||
|
||||
private void tearDownScripting() {
|
||||
if (contextClassLoader == null)
|
||||
return;
|
||||
if (Thread.currentThread().getContextClassLoader() == getClassLoader())
|
||||
Thread.currentThread().setContextClassLoader(contextClassLoader);
|
||||
contextClassLoader = null;
|
||||
}
|
||||
|
||||
private static final String COMPATIBLE_MC_VERSION = "1.4";
|
||||
|
@ -82,10 +82,13 @@ public class EventListen implements Listener {
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onChunkUnload(ChunkUnloadEvent event) {
|
||||
ChunkCoord coord = toCoord(event.getChunk());
|
||||
boolean forceLoad = Setting.KEEP_CHUNKS_LOADED.asBoolean();
|
||||
for (NPC npc : npcRegistry) {
|
||||
if (!npc.isSpawned())
|
||||
continue;
|
||||
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;
|
||||
if (event.getWorld().equals(loc.getWorld()) && sameChunkCoordinates) {
|
||||
npc.despawn();
|
||||
|
@ -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
|
||||
*/
|
||||
|
@ -84,7 +84,8 @@ public class Settings {
|
||||
SUBPLUGIN_FOLDER("subplugins.folder", "plugins"),
|
||||
TALK_CLOSE_MAXIMUM_COOLDOWN("npc.text.max-talk-cooldown", 60),
|
||||
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 Object value;
|
||||
|
@ -151,20 +151,20 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder {
|
||||
if (inLiquid) {
|
||||
motY += 0.04;
|
||||
} else //(handled elsewhere)*/
|
||||
if (onGround && bW == 0) {
|
||||
bf();
|
||||
bW = 10;
|
||||
if (onGround && bU == 0) {
|
||||
bi();
|
||||
bU = 10;
|
||||
}
|
||||
} else
|
||||
bW = 0;
|
||||
bU = 0;
|
||||
|
||||
bD *= 0.98F;
|
||||
bH *= 0.98F;
|
||||
bF *= 0.9F;
|
||||
bB *= 0.98F;
|
||||
bC *= 0.98F;
|
||||
bD *= 0.9F;
|
||||
|
||||
float prev = aM;
|
||||
aM *= bB();
|
||||
e(bD, bC); // movement method
|
||||
e(bB, bC); // movement method
|
||||
aM = prev;
|
||||
NMS.setHeadYaw(this, yaw);
|
||||
}
|
||||
|
@ -261,7 +261,7 @@ public class NMS {
|
||||
entity.getNavigation().e();
|
||||
entity.getControllerMove().c();
|
||||
entity.getControllerLook().a();
|
||||
entity.getControllerJump().b();
|
||||
entity.getControllerJump().b();
|
||||
}
|
||||
|
||||
public static void updateNavigationWorld(org.bukkit.entity.Entity entity, org.bukkit.World world) {
|
||||
|
Loading…
Reference in New Issue
Block a user