diff options
author | snowleo <schneeleo@gmail.com> | 2011-12-06 14:39:52 +0100 |
---|---|---|
committer | snowleo <schneeleo@gmail.com> | 2011-12-06 14:39:52 +0100 |
commit | 51390a969809f779bd867d697e3b7950fdf2740c (patch) | |
tree | 023ac08ce3eb88e6a3c457fd7191305ccfdb1d4e /EssentialsSpawn/src/com/earth2me/essentials/spawn | |
parent | 019b49ef11b453026e63b9e683d7827b85c81ab9 (diff) | |
download | Essentials-51390a969809f779bd867d697e3b7950fdf2740c.tar Essentials-51390a969809f779bd867d697e3b7950fdf2740c.tar.gz Essentials-51390a969809f779bd867d697e3b7950fdf2740c.tar.lz Essentials-51390a969809f779bd867d697e3b7950fdf2740c.tar.xz Essentials-51390a969809f779bd867d697e3b7950fdf2740c.zip |
Prevent some rare cases of NPE and Deadlocks, better error handling on yaml load
Diffstat (limited to 'EssentialsSpawn/src/com/earth2me/essentials/spawn')
-rw-r--r-- | EssentialsSpawn/src/com/earth2me/essentials/spawn/EssentialsSpawn.java | 1 | ||||
-rw-r--r-- | EssentialsSpawn/src/com/earth2me/essentials/spawn/SpawnStorage.java | 22 |
2 files changed, 21 insertions, 2 deletions
diff --git a/EssentialsSpawn/src/com/earth2me/essentials/spawn/EssentialsSpawn.java b/EssentialsSpawn/src/com/earth2me/essentials/spawn/EssentialsSpawn.java index 6f6244f25..ad42f9dee 100644 --- a/EssentialsSpawn/src/com/earth2me/essentials/spawn/EssentialsSpawn.java +++ b/EssentialsSpawn/src/com/earth2me/essentials/spawn/EssentialsSpawn.java @@ -35,6 +35,7 @@ public class EssentialsSpawn extends JavaPlugin } spawns = new SpawnStorage(ess); + ess.addReloadListener(spawns); final EssentialsSpawnPlayerListener playerListener = new EssentialsSpawnPlayerListener(ess, spawns); pluginManager.registerEvent(Type.PLAYER_RESPAWN, playerListener, Priority.Low, this); diff --git a/EssentialsSpawn/src/com/earth2me/essentials/spawn/SpawnStorage.java b/EssentialsSpawn/src/com/earth2me/essentials/spawn/SpawnStorage.java index ac98b5921..02fb26c9b 100644 --- a/EssentialsSpawn/src/com/earth2me/essentials/spawn/SpawnStorage.java +++ b/EssentialsSpawn/src/com/earth2me/essentials/spawn/SpawnStorage.java @@ -6,12 +6,14 @@ import com.earth2me.essentials.IEssentialsModule; import com.earth2me.essentials.settings.Spawns; import com.earth2me.essentials.storage.AbstractDelayedYamlFileReader; import com.earth2me.essentials.storage.AbstractDelayedYamlFileWriter; +import com.earth2me.essentials.storage.ObjectLoadException; import com.earth2me.essentials.storage.StorageObject; import java.io.File; import java.util.HashMap; import java.util.Locale; import java.util.Map; import java.util.concurrent.locks.ReentrantReadWriteLock; +import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.World; @@ -35,6 +37,10 @@ public class SpawnStorage implements IConf, IEssentialsModule rwl.writeLock().lock(); try { + if (spawns == null) + { + spawns = new Spawns(); + } if (spawns.getSpawns() == null) { spawns.setSpawns(new HashMap<String, Location>()); @@ -136,9 +142,21 @@ public class SpawnStorage implements IConf, IEssentialsModule } @Override - public void onFinish(final Spawns object) + public void onSuccess(final Spawns object) + { + if (object != null) + { + spawns = object; + } + rwl.writeLock().unlock(); + } + + @Override + public void onException() { - spawns = object; + if (spawns == null) { + spawns = new Spawns(); + } rwl.writeLock().unlock(); } } |