diff --git a/src/main/java/net/citizensnpcs/Citizens.java b/src/main/java/net/citizensnpcs/Citizens.java index 60fd9ab3a..b7e159c0f 100644 --- a/src/main/java/net/citizensnpcs/Citizens.java +++ b/src/main/java/net/citizensnpcs/Citizens.java @@ -159,6 +159,8 @@ public class Citizens extends JavaPlugin implements CitizensPlugin { @Override public void onDisable() { Bukkit.getPluginManager().callEvent(new CitizensDisableEvent()); + Editor.leaveAll(); + CitizensAPI.shutdown(); tearDownScripting(); // Don't bother with this part if MC versions are not compatible @@ -177,8 +179,8 @@ public class Citizens extends JavaPlugin implements CitizensPlugin { String mcVersion = ((CraftServer) getServer()).getServer().getVersion(); compatible = mcVersion.startsWith(COMPATIBLE_MC_VERSION); if (!compatible) { - Messaging.severeF("v%s is not compatible with Minecraft v%s. Disabling.", getDescription().getVersion(), - mcVersion); + Messaging.severeF("v%s is not compatible with Minecraft v%s. Disabling.", getDescription() + .getVersion(), mcVersion); getServer().getPluginManager().disablePlugin(this); return; } @@ -270,7 +272,8 @@ public class Citizens extends JavaPlugin implements CitizensPlugin { try { type = EntityType.valueOf(unparsedEntityType); } catch (IllegalArgumentException ex) { - Messaging.logF("NPC type '%s' was not recognized. Did you spell it correctly?", unparsedEntityType); + Messaging.logF("NPC type '%s' was not recognized. Did you spell it correctly?", + unparsedEntityType); continue; } } @@ -298,8 +301,9 @@ public class Citizens extends JavaPlugin implements CitizensPlugin { String type = Setting.STORAGE_TYPE.asString(); if (type.equalsIgnoreCase("db") || type.equalsIgnoreCase("database")) { try { - saves = new DatabaseStorage(Setting.DATABASE_DRIVER.asString(), Setting.DATABASE_URL.asString(), - Setting.DATABASE_USERNAME.asString(), Setting.DATABASE_PASSWORD.asString()); + saves = new DatabaseStorage(Setting.DATABASE_DRIVER.asString(), + Setting.DATABASE_URL.asString(), Setting.DATABASE_USERNAME.asString(), + Setting.DATABASE_PASSWORD.asString()); } catch (SQLException e) { e.printStackTrace(); Messaging.log("Unable to connect to database, falling back to YAML"); @@ -359,7 +363,8 @@ public class Citizens extends JavaPlugin implements CitizensPlugin { } private void tearDownScripting() { - Thread.currentThread().setContextClassLoader(contextClassLoader); + if (Thread.currentThread().getContextClassLoader() == getClassLoader()) + Thread.currentThread().setContextClassLoader(contextClassLoader); } private static final String COMPATIBLE_MC_VERSION = "1.2.5"; diff --git a/src/main/java/net/citizensnpcs/EventListen.java b/src/main/java/net/citizensnpcs/EventListen.java index f54464188..672b1fd0c 100644 --- a/src/main/java/net/citizensnpcs/EventListen.java +++ b/src/main/java/net/citizensnpcs/EventListen.java @@ -132,6 +132,11 @@ public class EventListen implements Listener { // undesirable as player NPCs are not real players and confuse plugins. } + @EventHandler(ignoreCancelled = true) + public void onPlayerQuit(PlayerQuitEvent event) { + Editor.leave(event.getPlayer()); + } + @EventHandler(ignoreCancelled = true) public void onPlayerInteractEntity(PlayerInteractEntityEvent event) { if (!npcRegistry.isNPC(event.getRightClicked())) @@ -142,11 +147,6 @@ public class EventListen implements Listener { new EntityTargetEvent(event.getRightClicked(), event.getPlayer(), TargetReason.CUSTOM)); } - @EventHandler(ignoreCancelled = true) - public void onPlayerQuit(PlayerQuitEvent event) { - Editor.leave(event.getPlayer()); - } - /* * World events */ @@ -186,19 +186,13 @@ public class EventListen implements Listener { private final int x; private final int z; - private ChunkCoord(int x, int z) { - this.x = x; - this.z = z; - } - private ChunkCoord(Chunk chunk) { this(chunk.getX(), chunk.getZ()); } - @Override - public int hashCode() { - final int prime = 31; - return prime * (prime + x) + z; + private ChunkCoord(int x, int z) { + this.x = x; + this.z = z; } @Override @@ -212,5 +206,11 @@ public class EventListen implements Listener { ChunkCoord other = (ChunkCoord) obj; return x == other.x && z == other.z; } + + @Override + public int hashCode() { + final int prime = 31; + return prime * (prime + x) + z; + } } } \ No newline at end of file diff --git a/src/main/java/net/citizensnpcs/editor/Editor.java b/src/main/java/net/citizensnpcs/editor/Editor.java index 643a8e0b9..8905673e9 100644 --- a/src/main/java/net/citizensnpcs/editor/Editor.java +++ b/src/main/java/net/citizensnpcs/editor/Editor.java @@ -2,6 +2,7 @@ package net.citizensnpcs.editor; import java.util.HashMap; import java.util.Map; +import java.util.Map.Entry; import net.citizensnpcs.util.Messaging; @@ -46,6 +47,10 @@ public abstract class Editor implements Listener { } public static void leaveAll() { + for (Entry entry : editing.entrySet()) { + entry.getValue().end(); + HandlerList.unregisterAll(entry.getValue()); + } editing.clear(); } } \ No newline at end of file diff --git a/src/main/java/net/citizensnpcs/npc/CitizensTraitFactory.java b/src/main/java/net/citizensnpcs/npc/CitizensTraitFactory.java index 17077fcea..7fceddbba 100644 --- a/src/main/java/net/citizensnpcs/npc/CitizensTraitFactory.java +++ b/src/main/java/net/citizensnpcs/npc/CitizensTraitFactory.java @@ -59,8 +59,6 @@ public class CitizensTraitFactory implements TraitFactory { INTERNAL_TRAITS.add(trait); } - private static final Set INTERNAL_TRAITS = Sets.newHashSet(); - public void addPlotters(Graph graph) { for (Map.Entry> entry : registered.entrySet()) { if (INTERNAL_TRAITS.contains(entry.getKey())) @@ -110,4 +108,6 @@ public class CitizensTraitFactory implements TraitFactory { Preconditions.checkNotNull(info, "info cannot be null"); registered.put(info.getTraitName(), info.getTraitClass()); } + + private static final Set INTERNAL_TRAITS = Sets.newHashSet(); } \ No newline at end of file diff --git a/src/main/java/net/citizensnpcs/npc/ai/CitizensNavigator.java b/src/main/java/net/citizensnpcs/npc/ai/CitizensNavigator.java index 49c5c1574..3436385c7 100644 --- a/src/main/java/net/citizensnpcs/npc/ai/CitizensNavigator.java +++ b/src/main/java/net/citizensnpcs/npc/ai/CitizensNavigator.java @@ -80,6 +80,11 @@ public class CitizensNavigator implements Navigator { return executing != null; } + public void onSpawn() { + if (speed == -1) + this.speed = getSpeedFor(npc.getHandle()); + } + @Override public void setSpeed(float speed) { this.speed = speed; @@ -108,11 +113,6 @@ public class CitizensNavigator implements Navigator { Bukkit.getPluginManager().callEvent(new NavigationBeginEvent(this)); } - public void onSpawn() { - if (speed == -1) - this.speed = getSpeedFor(npc.getHandle()); - } - public void update() { if (executing == null) return;