mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2025-01-24 17:11:31 +01:00
Better threading - stop memory leak
This commit is contained in:
parent
94e366ff31
commit
b73afa92d6
@ -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";
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
@ -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<String, Editor> entry : editing.entrySet()) {
|
||||
entry.getValue().end();
|
||||
HandlerList.unregisterAll(entry.getValue());
|
||||
}
|
||||
editing.clear();
|
||||
}
|
||||
}
|
@ -59,8 +59,6 @@ public class CitizensTraitFactory implements TraitFactory {
|
||||
INTERNAL_TRAITS.add(trait);
|
||||
}
|
||||
|
||||
private static final Set<String> INTERNAL_TRAITS = Sets.newHashSet();
|
||||
|
||||
public void addPlotters(Graph graph) {
|
||||
for (Map.Entry<String, Class<? extends Trait>> 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<String> INTERNAL_TRAITS = Sets.newHashSet();
|
||||
}
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user