Change from HashMap to ConcurrentHashMap, need to be available from

other threads !
This commit is contained in:
Xephi 2015-05-28 18:56:57 +02:00
parent 96925a580a
commit dc3a8c1f06
2 changed files with 32 additions and 35 deletions

View File

@ -1,8 +1,7 @@
package fr.xephi.authme.datasource;
import java.util.HashMap;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import org.bukkit.entity.Player;
import fr.xephi.authme.AuthMe;
@ -13,7 +12,7 @@ public class CacheDataSource extends Thread implements DataSource {
private DataSource source;
public AuthMe plugin;
private HashMap<String, PlayerAuth> cache = new HashMap<String, PlayerAuth>();
private ConcurrentHashMap<String, PlayerAuth> cache = new ConcurrentHashMap<String, PlayerAuth>();
public CacheDataSource(AuthMe plugin, DataSource source) {
this.plugin = plugin;

View File

@ -370,10 +370,10 @@ public class AuthMePlayerListener implements Listener {
Location spawn = plugin.getSpawnLocation(player);
if (spawn != null && spawn.getWorld() != null)
if (!event.getPlayer().getWorld().equals(spawn.getWorld())) {
event.getPlayer().teleport(spawn);
return;
}
if (!event.getPlayer().getWorld().equals(spawn.getWorld())) {
event.getPlayer().teleport(spawn);
return;
}
if ((spawn.distance(player.getLocation()) > radius) && spawn.getWorld() != null) {
event.getPlayer().teleport(spawn);
return;
@ -381,21 +381,19 @@ public class AuthMePlayerListener implements Listener {
}
@EventHandler(priority = EventPriority.HIGHEST)
public void onAsyncLogin(AsyncPlayerPreLoginEvent event)
{
Player player = null;
try {
player = Bukkit.getPlayer(event.getUniqueId());
} catch (Exception e) {
try {
player = Bukkit.getOfflinePlayer(event.getUniqueId()).getPlayer();
} catch (Exception ex)
{
return;
}
}
if (player == null)
return;
public void onAsyncLogin(AsyncPlayerPreLoginEvent event) {
Player player = null;
try {
player = Bukkit.getPlayer(event.getUniqueId());
} catch (Exception e) {
try {
player = Bukkit.getOfflinePlayer(event.getUniqueId()).getPlayer();
} catch (Exception ex) {
return;
}
}
if (player == null)
return;
final String name = player.getName().toLowerCase();
if (plugin.getCitizensCommunicator().isNPC(player, plugin) || Utils.getInstance().isUnrestricted(player) || CombatTagComunicator.isNPC(player)) {
@ -534,7 +532,8 @@ public class AuthMePlayerListener implements Listener {
}
}
private void checkAntiBotMod(final AsyncPlayerPreLoginEvent event, final Player player) {
private void checkAntiBotMod(final AsyncPlayerPreLoginEvent event,
final Player player) {
if (plugin.delayedAntiBot || plugin.antibotMod)
return;
if (plugin.authmePermissible(player, "authme.bypassantibot"))
@ -669,8 +668,8 @@ public class AuthMePlayerListener implements Listener {
plugin.getServer().getPluginManager().callEvent(tpEvent);
if (!tpEvent.isCancelled()) {
if (player != null && player.isOnline() && tpEvent.getTo() != null) {
if (tpEvent.getTo().getWorld() != null)
player.teleport(tpEvent.getTo());
if (tpEvent.getTo().getWorld() != null)
player.teleport(tpEvent.getTo());
}
}
}
@ -679,9 +678,8 @@ public class AuthMePlayerListener implements Listener {
try {
DataFileCache dataFile = new DataFileCache(LimboCache.getInstance().getLimboPlayer(name).getInventory(), LimboCache.getInstance().getLimboPlayer(name).getArmour());
playerBackup.createCache(player, dataFile, LimboCache.getInstance().getLimboPlayer(name).getGroup(), LimboCache.getInstance().getLimboPlayer(name).getOperator(), LimboCache.getInstance().getLimboPlayer(name).isFlying());
} catch (Exception e)
{
ConsoleLogger.showError("Error on creating an inventory cache for " + name + ", maybe inventory wipe in preparation...");
} catch (Exception e) {
ConsoleLogger.showError("Error on creating an inventory cache for " + name + ", maybe inventory wipe in preparation...");
}
} else {
if (Settings.isForceSurvivalModeEnabled && !Settings.forceOnlyAfterLogin) {
@ -701,8 +699,8 @@ public class AuthMePlayerListener implements Listener {
plugin.getServer().getPluginManager().callEvent(tpEvent);
if (!tpEvent.isCancelled()) {
if (player != null && player.isOnline() && tpEvent.getTo() != null) {
if (tpEvent.getTo().getWorld() != null)
player.teleport(tpEvent.getTo());
if (tpEvent.getTo().getWorld() != null)
player.teleport(tpEvent.getTo());
}
}
}
@ -773,14 +771,14 @@ public class AuthMePlayerListener implements Listener {
if (b.getType() == Material.PORTAL || b.getType() == Material.ENDER_PORTAL || b.getType() == Material.LAVA || b.getType() == Material.STATIONARY_LAVA) {
m.send(player, "unsafe_spawn");
if (spawnLoc.getWorld() != null)
player.teleport(spawnLoc);
player.teleport(spawnLoc);
return;
}
Block c = player.getLocation().add(0D, 1D, 0D).getBlock();
if (c.getType() == Material.PORTAL || c.getType() == Material.ENDER_PORTAL || c.getType() == Material.LAVA || c.getType() == Material.STATIONARY_LAVA) {
m.send(player, "unsafe_spawn");
if (spawnLoc.getWorld() != null)
player.teleport(spawnLoc);
player.teleport(spawnLoc);
return;
}
}
@ -906,8 +904,8 @@ public class AuthMePlayerListener implements Listener {
plugin.getServer().getPluginManager().callEvent(tpEvent);
if (!tpEvent.isCancelled()) {
if (player != null && player.isOnline() && tpEvent.getTo() != null) {
if (tpEvent.getTo().getWorld() != null)
player.teleport(tpEvent.getTo());
if (tpEvent.getTo().getWorld() != null)
player.teleport(tpEvent.getTo());
}
}
} catch (NullPointerException npe) {
@ -1178,7 +1176,7 @@ public class AuthMePlayerListener implements Listener {
}
}
if (spawn != null && spawn.getWorld() != null)
event.setRespawnLocation(spawn);
event.setRespawnLocation(spawn);
}
@EventHandler(priority = EventPriority.HIGHEST)