mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2025-01-24 17:11:31 +01:00
Only listen to EntitiesLoad/UnloadEvent
This commit is contained in:
parent
74df4818e4
commit
5e9f04f141
@ -130,7 +130,7 @@ public class EventListen implements Listener {
|
|||||||
skinUpdateTracker = new SkinUpdateTracker();
|
skinUpdateTracker = new SkinUpdateTracker();
|
||||||
try {
|
try {
|
||||||
Class.forName("org.bukkit.event.world.EntitiesLoadEvent");
|
Class.forName("org.bukkit.event.world.EntitiesLoadEvent");
|
||||||
Bukkit.getPluginManager().registerEvents(new Listener() {
|
Bukkit.getPluginManager().registerEvents(chunkEventListener = new Listener() {
|
||||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||||
public void onEntitiesLoad(EntitiesLoadEvent event) {
|
public void onEntitiesLoad(EntitiesLoadEvent event) {
|
||||||
loadNPCs(event);
|
loadNPCs(event);
|
||||||
@ -253,15 +253,6 @@ public class EventListen implements Listener {
|
|||||||
new double[] { (event.getChunk().getX() << 4) - 0.5, 0, (event.getChunk().getZ() << 4) - 0.5 },
|
new double[] { (event.getChunk().getX() << 4) - 0.5, 0, (event.getChunk().getZ() << 4) - 0.5 },
|
||||||
new double[] { (event.getChunk().getX() + 1 << 4) + 0.5, 256,
|
new double[] { (event.getChunk().getX() + 1 << 4) + 0.5, 256,
|
||||||
(event.getChunk().getZ() + 1 << 4) + 0.5 }));
|
(event.getChunk().getZ() + 1 << 4) + 0.5 }));
|
||||||
if (SUPPORTS_UNLOAD_CHUNK_ENTITIES == null) {
|
|
||||||
try {
|
|
||||||
event.getChunk().getEntities();
|
|
||||||
SUPPORTS_UNLOAD_CHUNK_ENTITIES = true;
|
|
||||||
} catch (Throwable t) {
|
|
||||||
SUPPORTS_UNLOAD_CHUNK_ENTITIES = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (SUPPORTS_UNLOAD_CHUNK_ENTITIES) {
|
|
||||||
for (Entity entity : event.getChunk().getEntities()) {
|
for (Entity entity : event.getChunk().getEntities()) {
|
||||||
NPC npc = CitizensAPI.getNPCRegistry().getNPC(entity);
|
NPC npc = CitizensAPI.getNPCRegistry().getNPC(entity);
|
||||||
// XXX npc#isSpawned() checks valid status which is now inconsistent on chunk unload
|
// XXX npc#isSpawned() checks valid status which is now inconsistent on chunk unload
|
||||||
@ -271,7 +262,6 @@ public class EventListen implements Listener {
|
|||||||
|
|
||||||
toDespawn.add(npc);
|
toDespawn.add(npc);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (toDespawn.isEmpty())
|
if (toDespawn.isEmpty())
|
||||||
return;
|
return;
|
||||||
unloadNPCs(event, toDespawn);
|
unloadNPCs(event, toDespawn);
|
||||||
@ -966,6 +956,4 @@ public class EventListen implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static boolean SUPPORT_STOP_USE_ITEM = true;
|
private static boolean SUPPORT_STOP_USE_ITEM = true;
|
||||||
|
|
||||||
private static Boolean SUPPORTS_UNLOAD_CHUNK_ENTITIES;
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user