mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2025-02-17 04:41:31 +01:00
Add a keep-chunks-loaded setting, fix Player NPC movement code
This commit is contained in:
parent
28af4655fa
commit
7675620594
@ -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";
|
||||||
|
@ -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();
|
||||||
|
@ -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
|
||||||
*/
|
*/
|
||||||
|
@ -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;
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user