mirror of
https://github.com/EssentialsX/Essentials.git
synced 2025-02-21 23:01:28 +01:00
Add spawn location cache to reduce blocking on player respawn.
This commit is contained in:
parent
c54e9b5dba
commit
7804516793
@ -8,18 +8,29 @@ 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);
|
||||
reloadConfig();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void reloadConfig()
|
||||
{
|
||||
super.reloadConfig();
|
||||
spawns = new ConcurrentHashMap<String, Location>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getStorageFile()
|
||||
{
|
||||
@ -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))
|
||||
{
|
||||
groupName = "default";
|
||||
}
|
||||
if (!spawnMap.containsKey(groupName))
|
||||
{
|
||||
return getWorldSpawn();
|
||||
}
|
||||
return spawnMap.get(groupName);
|
||||
spawnLocation = spawns.get(group);
|
||||
}
|
||||
finally
|
||||
else
|
||||
{
|
||||
unlock();
|
||||
acquireReadLock();
|
||||
try
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
unlock();
|
||||
}
|
||||
|
||||
spawns.put(group, spawnLocation);
|
||||
}
|
||||
return spawnLocation;
|
||||
}
|
||||
|
||||
private Location getWorldSpawn()
|
||||
|
Loading…
Reference in New Issue
Block a user