1
0
mirror of https://github.com/essentials/Essentials.git synced 2025-08-17 20:11:21 +02:00

Prevent some rare cases of NPE and Deadlocks, better error handling on yaml load

This commit is contained in:
snowleo
2011-12-06 14:39:52 +01:00
parent 4c2b9b8d0f
commit 166dfbd532
8 changed files with 145 additions and 105 deletions

View File

@@ -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);

View File

@@ -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)
{
spawns = object;
if (object != null)
{
spawns = object;
}
rwl.writeLock().unlock();
}
@Override
public void onException()
{
if (spawns == null) {
spawns = new Spawns();
}
rwl.writeLock().unlock();
}
}