diff options
author | KHobbits <rob@khobbits.co.uk> | 2014-06-16 19:55:34 +0100 |
---|---|---|
committer | KHobbits <rob@khobbits.co.uk> | 2014-06-16 19:55:34 +0100 |
commit | 7804516793148becfe648c4491fea60829460957 (patch) | |
tree | f51807ba73993f04408c8f11fd874456d1b22edf /EssentialsSpawn/src/com/earth2me | |
parent | c54e9b5dbac119c124d46665640c0bff413eaa4a (diff) | |
download | Essentials-7804516793148becfe648c4491fea60829460957.tar Essentials-7804516793148becfe648c4491fea60829460957.tar.gz Essentials-7804516793148becfe648c4491fea60829460957.tar.lz Essentials-7804516793148becfe648c4491fea60829460957.tar.xz Essentials-7804516793148becfe648c4491fea60829460957.zip |
Add spawn location cache to reduce blocking on player respawn.
Diffstat (limited to 'EssentialsSpawn/src/com/earth2me')
-rw-r--r-- | EssentialsSpawn/src/com/earth2me/essentials/spawn/SpawnStorage.java | 61 |
1 files changed, 44 insertions, 17 deletions
diff --git a/EssentialsSpawn/src/com/earth2me/essentials/spawn/SpawnStorage.java b/EssentialsSpawn/src/com/earth2me/essentials/spawn/SpawnStorage.java index 36b6f9662..c8e12563c 100644 --- a/EssentialsSpawn/src/com/earth2me/essentials/spawn/SpawnStorage.java +++ b/EssentialsSpawn/src/com/earth2me/essentials/spawn/SpawnStorage.java @@ -8,12 +8,16 @@ import java.io.File; import java.util.HashMap; import java.util.Locale; import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; import org.bukkit.Location; import org.bukkit.World; public class SpawnStorage extends AsyncStorageObjectHolder<Spawns> implements IEssentialsModule { + private ConcurrentMap<String, Location> spawns; + public SpawnStorage(final IEssentials ess) { super(ess, Spawns.class); @@ -21,6 +25,13 @@ public class SpawnStorage extends AsyncStorageObjectHolder<Spawns> implements IE } @Override + public final void reloadConfig() + { + super.reloadConfig(); + spawns = new ConcurrentHashMap<String, Location>(); + } + + @Override public File getStorageFile() { return new File(ess.getDataFolder(), "spawn.yml"); @@ -52,6 +63,8 @@ public class SpawnStorage extends AsyncStorageObjectHolder<Spawns> implements IE unlock(); } + spawns.clear(); + if ("default".equalsIgnoreCase(group)) { loc.getWorld().setSpawnLocation(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()); @@ -60,29 +73,43 @@ public class SpawnStorage extends AsyncStorageObjectHolder<Spawns> implements IE public Location getSpawn(final String group) { - acquireReadLock(); - try + Location spawnLocation; + if (spawns.containsKey(group)) { - if (getData().getSpawns() == null || group == null) - { - return getWorldSpawn(); - } - final Map<String, Location> spawnMap = getData().getSpawns(); - String groupName = group.toLowerCase(Locale.ENGLISH); - if (!spawnMap.containsKey(groupName)) + spawnLocation = spawns.get(group); + } + else + { + acquireReadLock(); + try { - groupName = "default"; + if (getData().getSpawns() == null || group == null) + { + return getWorldSpawn(); + } + final Map<String, Location> spawnMap = getData().getSpawns(); + String groupName = group.toLowerCase(Locale.ENGLISH); + if (!spawnMap.containsKey(groupName)) + { + groupName = "default"; + } + if (!spawnMap.containsKey(groupName)) + { + spawnLocation = getWorldSpawn(); + } + else + { + spawnLocation = spawnMap.get(groupName); + } } - if (!spawnMap.containsKey(groupName)) + finally { - return getWorldSpawn(); + unlock(); } - return spawnMap.get(groupName); - } - finally - { - unlock(); + + spawns.put(group, spawnLocation); } + return spawnLocation; } private Location getWorldSpawn() |