diff --git a/pom.xml b/pom.xml index b8a5f6a1..6f5f9152 100644 --- a/pom.xml +++ b/pom.xml @@ -24,12 +24,12 @@ - 3.3.2 + 3.3.3 org.bukkit craftbukkit - 1.7.2-R0.3-SNAPSHOT + 1.7.2-R0.3 net.milkbowl.vault diff --git a/src/main/java/fr/xephi/authme/AuthMe.java b/src/main/java/fr/xephi/authme/AuthMe.java index cb5b34a3..03a96696 100644 --- a/src/main/java/fr/xephi/authme/AuthMe.java +++ b/src/main/java/fr/xephi/authme/AuthMe.java @@ -720,7 +720,7 @@ public class AuthMe extends JavaPlugin { ConsoleLogger.info("AutoPurgeDatabase : Remove " + i + " EssentialsFiles"); } - public Location getSpawnLocation(World world) { + public Location getSpawnLocation(String name, World world) { Location spawnLoc = world.getSpawnLocation(); if (multiverse != null && Settings.multiverse) { try { @@ -733,8 +733,10 @@ public class AuthMe extends JavaPlugin { if (essentialsSpawn != null) { spawnLoc = essentialsSpawn; } - if (Spawn.getInstance().getLocation() != null) - spawnLoc = Spawn.getInstance().getLocation(); + if (Spawn.getInstance().getSpawn() != null) + spawnLoc = Spawn.getInstance().getSpawn(); + if (!database.isAuthAvailable(name) && Spawn.getInstance().getFirstSpawn() != null) + spawnLoc = Spawn.getInstance().getFirstSpawn(); return spawnLoc; } diff --git a/src/main/java/fr/xephi/authme/Utils.java b/src/main/java/fr/xephi/authme/Utils.java index bb27414f..8f9eb309 100644 --- a/src/main/java/fr/xephi/authme/Utils.java +++ b/src/main/java/fr/xephi/authme/Utils.java @@ -19,60 +19,63 @@ import fr.xephi.authme.events.AuthMeTeleportEvent; import fr.xephi.authme.settings.Settings; public class Utils { - private String currentGroup; - private static Utils singleton; - int id; - public AuthMe plugin; + private String currentGroup; + private static Utils singleton; + int id; + public AuthMe plugin; - public Utils(AuthMe plugin) { - this.plugin = plugin; - } + public Utils(AuthMe plugin) { + this.plugin = plugin; + } - public void setGroup(Player player, groupType group) { - if (!player.isOnline()) - return; - if(!Settings.isPermissionCheckEnabled) - return; - if(plugin.permission == null) - return; - try { - currentGroup = plugin.permission.getPrimaryGroup(player); - } catch (UnsupportedOperationException e) { - ConsoleLogger.showError("Your permission system (" + plugin.permission.getName() + ") do not support Group system with that config... unhook!"); - plugin.permission = null; - return; - } - World world = null; - String name = player.getName(); - switch(group) { - case UNREGISTERED: { - plugin.permission.playerRemoveGroup(world, name, currentGroup); - plugin.permission.playerAddGroup(world, name, Settings.unRegisteredGroup); - break; - } - case REGISTERED: { - plugin.permission.playerRemoveGroup(world, name, currentGroup); - plugin.permission.playerAddGroup(world, name, Settings.getRegisteredGroup); - break; - } - case NOTLOGGEDIN: { - if(!useGroupSystem()) break; - plugin.permission.playerRemoveGroup(world, name, currentGroup); - plugin.permission.playerAddGroup(world, name, Settings.getUnloggedinGroup); - break; - } - case LOGGEDIN: { - if(!useGroupSystem()) break; - LimboPlayer limbo = LimboCache.getInstance().getLimboPlayer(player.getName().toLowerCase()); - if (limbo == null) break; - String realGroup = limbo.getGroup(); - plugin.permission.playerRemoveGroup(world, name, currentGroup); - plugin.permission.playerAddGroup(world, name, realGroup); - break; - } - } - return; - } + public void setGroup(Player player, groupType group) { + setGroup(player.getName(), group); + } + + public void setGroup(String player, groupType group) { + if(!Settings.isPermissionCheckEnabled) + return; + if(plugin.permission == null) + return; + try { + World world = null; + currentGroup = plugin.permission.getPrimaryGroup(world, player); + } catch (UnsupportedOperationException e) { + ConsoleLogger.showError("Your permission system (" + plugin.permission.getName() + ") do not support Group system with that config... unhook!"); + plugin.permission = null; + return; + } + World world = null; + String name = player; + switch(group) { + case UNREGISTERED: { + plugin.permission.playerRemoveGroup(world, name, currentGroup); + plugin.permission.playerAddGroup(world, name, Settings.unRegisteredGroup); + break; + } + case REGISTERED: { + plugin.permission.playerRemoveGroup(world, name, currentGroup); + plugin.permission.playerAddGroup(world, name, Settings.getRegisteredGroup); + break; + } + case NOTLOGGEDIN: { + if(!useGroupSystem()) break; + plugin.permission.playerRemoveGroup(world, name, currentGroup); + plugin.permission.playerAddGroup(world, name, Settings.getUnloggedinGroup); + break; + } + case LOGGEDIN: { + if(!useGroupSystem()) break; + LimboPlayer limbo = LimboCache.getInstance().getLimboPlayer(name.toLowerCase()); + if (limbo == null) break; + String realGroup = limbo.getGroup(); + plugin.permission.playerRemoveGroup(world, name, currentGroup); + plugin.permission.playerAddGroup(world, name, realGroup); + break; + } + } + return; + } public boolean addNormal(Player player, String group) { if(!useGroupSystem()){ diff --git a/src/main/java/fr/xephi/authme/cache/auth/PlayerAuth.java b/src/main/java/fr/xephi/authme/cache/auth/PlayerAuth.java index 657b3582..2f815636 100644 --- a/src/main/java/fr/xephi/authme/cache/auth/PlayerAuth.java +++ b/src/main/java/fr/xephi/authme/cache/auth/PlayerAuth.java @@ -98,7 +98,9 @@ public class PlayerAuth { } public String getIp() { - return ip; + if (ip == null || ip.isEmpty()) + ip = "127.0.0.1"; + return ip; } public String getNickname() { @@ -145,6 +147,12 @@ public class PlayerAuth { this.z = d; } public long getLastLogin() { + try { + if (Long.valueOf(lastLogin) == null) + lastLogin = 0L; + } catch (NullPointerException e) { + lastLogin = 0L; + } return lastLogin; } diff --git a/src/main/java/fr/xephi/authme/cache/limbo/LimboCache.java b/src/main/java/fr/xephi/authme/cache/limbo/LimboCache.java index 926d6d13..698560be 100644 --- a/src/main/java/fr/xephi/authme/cache/limbo/LimboCache.java +++ b/src/main/java/fr/xephi/authme/cache/limbo/LimboCache.java @@ -89,7 +89,7 @@ public class LimboCache { gameMode = GameMode.SURVIVAL; } if(player.isDead()) { - loc = plugin.getSpawnLocation(player.getWorld()); + loc = plugin.getSpawnLocation(player.getName().toLowerCase(), player.getWorld()); } cache.put(player.getName().toLowerCase(), new LimboPlayer(name, loc, inv, arm, gameMode, operator, playerGroup, flying)); } diff --git a/src/main/java/fr/xephi/authme/commands/AdminCommand.java b/src/main/java/fr/xephi/authme/commands/AdminCommand.java index 46ae03f7..8cf10313 100644 --- a/src/main/java/fr/xephi/authme/commands/AdminCommand.java +++ b/src/main/java/fr/xephi/authme/commands/AdminCommand.java @@ -13,6 +13,7 @@ import java.util.logging.Level; import java.util.logging.Logger; import org.bukkit.Bukkit; +import org.bukkit.Location; import org.bukkit.OfflinePlayer; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; @@ -22,13 +23,16 @@ import org.bukkit.command.ConsoleCommandSender; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.Player; import org.bukkit.plugin.java.JavaPlugin; +import org.bukkit.scheduler.BukkitScheduler; import fr.xephi.authme.AuthMe; import fr.xephi.authme.ConsoleLogger; import fr.xephi.authme.Utils; +import fr.xephi.authme.Utils.groupType; import fr.xephi.authme.api.API; import fr.xephi.authme.cache.auth.PlayerAuth; import fr.xephi.authme.cache.auth.PlayerCache; +import fr.xephi.authme.cache.limbo.LimboCache; import fr.xephi.authme.converter.FlatToSql; import fr.xephi.authme.converter.FlatToSqlite; import fr.xephi.authme.converter.RakamakConverter; @@ -36,11 +40,14 @@ import fr.xephi.authme.converter.RoyalAuthConverter; import fr.xephi.authme.converter.newxAuthToFlat; import fr.xephi.authme.converter.oldxAuthToFlat; import fr.xephi.authme.datasource.DataSource; +import fr.xephi.authme.events.SpawnTeleportEvent; import fr.xephi.authme.security.PasswordSecurity; import fr.xephi.authme.settings.Messages; import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.Spawn; import fr.xephi.authme.settings.SpoutCfg; +import fr.xephi.authme.task.MessageTask; +import fr.xephi.authme.task.TimeoutTask; public class AdminCommand implements CommandExecutor { @@ -385,6 +392,19 @@ public class AdminCommand implements CommandExecutor { ConsoleLogger.showError(ex.getMessage()); } return true; + } else if (args[0].equalsIgnoreCase("setfirstspawn")) { + try { + if (sender instanceof Player) { + if (Spawn.getInstance().setFirstSpawn(((Player) sender).getLocation())) + sender.sendMessage("[AuthMe] Correctly define new first spawn"); + else sender.sendMessage("[AuthMe] SetFirstSpawn fail , please retry"); + } else { + sender.sendMessage("[AuthMe] Please use that command in game"); + } + } catch (NullPointerException ex) { + ConsoleLogger.showError(ex.getMessage()); + } + return true; } else if (args[0].equalsIgnoreCase("purgebannedplayers")) { List bannedPlayers = new ArrayList(); for (OfflinePlayer off : plugin.getServer().getBannedPlayers()) { @@ -413,8 +433,8 @@ public class AdminCommand implements CommandExecutor { } else if (args[0].equalsIgnoreCase("spawn")) { try { if (sender instanceof Player) { - if (Spawn.getInstance().getLocation() != null) - ((Player) sender).teleport(Spawn.getInstance().getLocation()); + if (Spawn.getInstance().getSpawn() != null) + ((Player) sender).teleport(Spawn.getInstance().getSpawn()); else sender.sendMessage("[AuthMe] Spawn fail , please try to define the spawn"); } else { sender.sendMessage("[AuthMe] Please use that command in game"); @@ -423,6 +443,19 @@ public class AdminCommand implements CommandExecutor { ConsoleLogger.showError(ex.getMessage()); } return true; + } else if (args[0].equalsIgnoreCase("firstspawn")) { + try { + if (sender instanceof Player) { + if (Spawn.getInstance().getFirstSpawn() != null) + ((Player) sender).teleport(Spawn.getInstance().getFirstSpawn()); + else sender.sendMessage("[AuthMe] Spawn fail , please try to define the first spawn"); + } else { + sender.sendMessage("[AuthMe] Please use that command in game"); + } + } catch (NullPointerException ex) { + ConsoleLogger.showError(ex.getMessage()); + } + return true; } else if (args[0].equalsIgnoreCase("changepassword") || args[0].equalsIgnoreCase("cp")) { if (args.length != 3) { sender.sendMessage("Usage: /authme changepassword playername newpassword"); @@ -467,8 +500,36 @@ public class AdminCommand implements CommandExecutor { m._(sender, "error"); return true; } + Player target = Bukkit.getPlayer(name); PlayerCache.getInstance().removePlayer(name); - sender.sendMessage("unregistered"); + Utils.getInstance().setGroup(name, groupType.UNREGISTERED); + if (target != null) { + if (target.isOnline()) { + if (Settings.isTeleportToSpawnEnabled) { + Location spawn = plugin.getSpawnLocation(name, target.getWorld()); + SpawnTeleportEvent tpEvent = new SpawnTeleportEvent(target, target.getLocation(), spawn, false); + plugin.getServer().getPluginManager().callEvent(tpEvent); + if(!tpEvent.isCancelled()) { + target.teleport(tpEvent.getTo()); + } + } + LimboCache.getInstance().addLimboPlayer(target); + int delay = Settings.getRegistrationTimeout * 20; + int interval = Settings.getWarnMessageInterval; + BukkitScheduler sched = sender.getServer().getScheduler(); + if (delay != 0) { + int id = sched.scheduleSyncDelayedTask(plugin, new TimeoutTask(plugin, name), delay); + LimboCache.getInstance().getLimboPlayer(name).setTimeoutTaskId(id); + } + LimboCache.getInstance().getLimboPlayer(name).setMessageTaskId(sched.scheduleSyncDelayedTask(plugin, new MessageTask(plugin, name, m._("reg_msg"), interval))); + m._(target, "unregistered"); + } else { + // Player isn't online, do nothing else + } + } else { + // Player does not exist, do nothing else + } + m._(sender, "unregistered"); ConsoleLogger.info(args[1] + " unregistered"); return true; } else if (args[0].equalsIgnoreCase("purgelastpos")){ diff --git a/src/main/java/fr/xephi/authme/commands/EmailCommand.java b/src/main/java/fr/xephi/authme/commands/EmailCommand.java index 6b9c2aeb..08eb638a 100644 --- a/src/main/java/fr/xephi/authme/commands/EmailCommand.java +++ b/src/main/java/fr/xephi/authme/commands/EmailCommand.java @@ -59,6 +59,12 @@ public class EmailCommand implements CommandExecutor { m._(player, "usage_email_add"); return true; } + if(Settings.getmaxRegPerEmail > 0) { + if (!plugin.authmePermissible(sender, "authme.allow2accounts") && data.getAllAuthsByEmail(args[1]).size() >= Settings.getmaxRegPerEmail) { + m._(player, "max_reg"); + return true; + } + } if(args[1].equals(args[2]) && PlayerCache.getInstance().isAuthenticated(name)) { PlayerAuth auth = PlayerCache.getInstance().getAuth(name); if (auth.getEmail() == null || (!auth.getEmail().equals("your@email.com") && !auth.getEmail().isEmpty())) { @@ -87,6 +93,12 @@ public class EmailCommand implements CommandExecutor { } } } else if(args[0].equalsIgnoreCase("change") && args.length == 3 ) { + if(Settings.getmaxRegPerEmail > 0) { + if (!plugin.authmePermissible(sender, "authme.allow2accounts") && data.getAllAuthsByEmail(args[1]).size() >= Settings.getmaxRegPerEmail) { + m._(player, "max_reg"); + return true; + } + } if(PlayerCache.getInstance().isAuthenticated(name)) { PlayerAuth auth = PlayerCache.getInstance().getAuth(name); if (auth.getEmail() == null || auth.getEmail().equals("your@email.com") || auth.getEmail().isEmpty()) { diff --git a/src/main/java/fr/xephi/authme/commands/LogoutCommand.java b/src/main/java/fr/xephi/authme/commands/LogoutCommand.java index 5183a87a..b3763856 100644 --- a/src/main/java/fr/xephi/authme/commands/LogoutCommand.java +++ b/src/main/java/fr/xephi/authme/commands/LogoutCommand.java @@ -23,7 +23,6 @@ import fr.xephi.authme.events.AuthMeTeleportEvent; import fr.xephi.authme.settings.Messages; import fr.xephi.authme.settings.PlayersLogs; import fr.xephi.authme.settings.Settings; -import fr.xephi.authme.settings.Spawn; import fr.xephi.authme.task.MessageTask; import fr.xephi.authme.task.TimeoutTask; @@ -73,12 +72,7 @@ public class LogoutCommand implements CommandExecutor { PlayerCache.getInstance().removePlayer(name); if (Settings.isTeleportToSpawnEnabled) { - Location spawnLoc = player.getWorld().getSpawnLocation(); - if (plugin.essentialsSpawn != null) { - spawnLoc = plugin.essentialsSpawn; - } - if (Spawn.getInstance().getLocation() != null) - spawnLoc = Spawn.getInstance().getLocation(); + Location spawnLoc = plugin.getSpawnLocation(name, player.getWorld()); AuthMeTeleportEvent tpEvent = new AuthMeTeleportEvent(player, spawnLoc); plugin.getServer().getPluginManager().callEvent(tpEvent); if(!tpEvent.isCancelled()) { diff --git a/src/main/java/fr/xephi/authme/commands/UnregisterCommand.java b/src/main/java/fr/xephi/authme/commands/UnregisterCommand.java index 146fc04b..a14d3e05 100644 --- a/src/main/java/fr/xephi/authme/commands/UnregisterCommand.java +++ b/src/main/java/fr/xephi/authme/commands/UnregisterCommand.java @@ -72,12 +72,21 @@ public class UnregisterCommand implements CommandExecutor { return true; } if(Settings.isForcedRegistrationEnabled) { + if (Settings.isTeleportToSpawnEnabled) { + Location spawn = plugin.getSpawnLocation(name, player.getWorld()); + SpawnTeleportEvent tpEvent = new SpawnTeleportEvent(player, player.getLocation(), spawn, false); + plugin.getServer().getPluginManager().callEvent(tpEvent); + if(!tpEvent.isCancelled()) { + player.teleport(tpEvent.getTo()); + } + } player.getInventory().setContents(new ItemStack[36]); player.getInventory().setArmorContents(new ItemStack[4]); player.saveData(); PlayerCache.getInstance().removePlayer(player.getName().toLowerCase()); + if (!Settings.getRegisteredGroup.isEmpty()) + Utils.getInstance().setGroup(player, groupType.UNREGISTERED); LimboCache.getInstance().addLimboPlayer(player); - Utils.getInstance().setGroup(player, groupType.UNREGISTERED); int delay = Settings.getRegistrationTimeout * 20; int interval = Settings.getWarnMessageInterval; BukkitScheduler sched = sender.getServer().getScheduler(); @@ -86,14 +95,11 @@ public class UnregisterCommand implements CommandExecutor { LimboCache.getInstance().getLimboPlayer(name).setTimeoutTaskId(id); } LimboCache.getInstance().getLimboPlayer(name).setMessageTaskId(sched.scheduleSyncDelayedTask(plugin, new MessageTask(plugin, name, m._("reg_msg"), interval))); - if(!Settings.unRegisteredGroup.isEmpty()){ - Utils.getInstance().setGroup(player, Utils.groupType.UNREGISTERED); - } - m._(player, "unregistered"); - ConsoleLogger.info(player.getDisplayName() + " unregistered himself"); - if(plugin.notifications != null) { - plugin.notifications.showNotification(new Notification("[AuthMe] " + player.getName() + " unregistered himself!")); - } + m._(player, "unregistered"); + ConsoleLogger.info(player.getDisplayName() + " unregistered himself"); + if(plugin.notifications != null) { + plugin.notifications.showNotification(new Notification("[AuthMe] " + player.getName() + " unregistered himself!")); + } return true; } if(!Settings.unRegisteredGroup.isEmpty()){ @@ -114,7 +120,7 @@ public class UnregisterCommand implements CommandExecutor { plugin.notifications.showNotification(new Notification("[AuthMe] " + player.getName() + " unregistered himself!")); } if (Settings.isTeleportToSpawnEnabled) { - Location spawn = plugin.getSpawnLocation(player.getWorld()); + Location spawn = plugin.getSpawnLocation(name, player.getWorld()); SpawnTeleportEvent tpEvent = new SpawnTeleportEvent(player, player.getLocation(), spawn, false); plugin.getServer().getPluginManager().callEvent(tpEvent); if(!tpEvent.isCancelled()) { diff --git a/src/main/java/fr/xephi/authme/datasource/CacheDataSource.java b/src/main/java/fr/xephi/authme/datasource/CacheDataSource.java index ac5e5d01..c3d4fbe5 100644 --- a/src/main/java/fr/xephi/authme/datasource/CacheDataSource.java +++ b/src/main/java/fr/xephi/authme/datasource/CacheDataSource.java @@ -14,7 +14,7 @@ public class CacheDataSource implements DataSource { private DataSource source; public AuthMe plugin; - private final HashMap cache = new HashMap(); + private HashMap cache = new HashMap(); public CacheDataSource(AuthMe plugin, DataSource source) { this.plugin = plugin; @@ -23,16 +23,18 @@ public class CacheDataSource implements DataSource { @Override public synchronized boolean isAuthAvailable(String user) { - return cache.containsKey(user) ? true : source.isAuthAvailable(user); + if (cache.containsKey(user.toLowerCase())) return true; + return source.isAuthAvailable(user.toLowerCase()); } @Override public synchronized PlayerAuth getAuth(String user) { - if(cache.containsKey(user)) { - return cache.get(user); + if(cache.containsKey(user.toLowerCase())) { + return cache.get(user.toLowerCase()); } else { - PlayerAuth auth = source.getAuth(user); - cache.put(user, auth); + PlayerAuth auth = source.getAuth(user.toLowerCase()); + if (auth != null) + cache.put(user.toLowerCase(), auth); return auth; } } @@ -49,7 +51,8 @@ public class CacheDataSource implements DataSource { @Override public synchronized boolean updatePassword(PlayerAuth auth) { if (source.updatePassword(auth)) { - cache.get(auth.getNickname()).setHash(auth.getHash()); + if (cache.containsKey(auth.getNickname().toLowerCase())) + cache.get(auth.getNickname()).setHash(auth.getHash()); return true; } return false; @@ -58,8 +61,10 @@ public class CacheDataSource implements DataSource { @Override public boolean updateSession(PlayerAuth auth) { if (source.updateSession(auth)) { - cache.get(auth.getNickname()).setIp(auth.getIp()); - cache.get(auth.getNickname()).setLastLogin(auth.getLastLogin()); + if (cache.containsKey(auth.getNickname().toLowerCase())) { + cache.get(auth.getNickname()).setIp(auth.getIp()); + cache.get(auth.getNickname()).setLastLogin(auth.getLastLogin()); + } return true; } return false; @@ -68,10 +73,12 @@ public class CacheDataSource implements DataSource { @Override public boolean updateQuitLoc(PlayerAuth auth) { if (source.updateQuitLoc(auth)) { - cache.get(auth.getNickname()).setQuitLocX(auth.getQuitLocX()); - cache.get(auth.getNickname()).setQuitLocY(auth.getQuitLocY()); - cache.get(auth.getNickname()).setQuitLocZ(auth.getQuitLocZ()); - cache.get(auth.getNickname()).setWorld(auth.getWorld()); + if (cache.containsKey(auth.getNickname().toLowerCase())) { + cache.get(auth.getNickname()).setQuitLocX(auth.getQuitLocX()); + cache.get(auth.getNickname()).setQuitLocY(auth.getQuitLocY()); + cache.get(auth.getNickname()).setQuitLocZ(auth.getQuitLocZ()); + cache.get(auth.getNickname()).setWorld(auth.getWorld()); + } return true; } return false; @@ -110,8 +117,8 @@ public class CacheDataSource implements DataSource { @Override public synchronized boolean removeAuth(String user) { - if (source.removeAuth(user)) { - cache.remove(user); + if (source.removeAuth(user.toLowerCase())) { + cache.remove(user.toLowerCase()); return true; } return false; @@ -125,6 +132,7 @@ public class CacheDataSource implements DataSource { @Override public void reload() { cache.clear(); + source.reload(); for (Player player : plugin.getServer().getOnlinePlayers()) { String user = player.getName().toLowerCase(); if (PlayerCache.getInstance().isAuthenticated(user)) { @@ -141,7 +149,8 @@ public class CacheDataSource implements DataSource { @Override public synchronized boolean updateEmail(PlayerAuth auth) { if(source.updateEmail(auth)) { - cache.get(auth.getNickname()).setEmail(auth.getEmail()); + if (cache.containsKey(auth.getNickname().toLowerCase())) + cache.get(auth.getNickname()).setEmail(auth.getEmail()); return true; } return false; @@ -150,7 +159,8 @@ public class CacheDataSource implements DataSource { @Override public synchronized boolean updateSalt(PlayerAuth auth) { if(source.updateSalt(auth)) { - cache.get(auth.getNickname()).setSalt(auth.getSalt()); + if (cache.containsKey(auth.getNickname().toLowerCase())) + cache.get(auth.getNickname()).setSalt(auth.getSalt()); return true; } return false; diff --git a/src/main/java/fr/xephi/authme/datasource/MySQLDataSource.java b/src/main/java/fr/xephi/authme/datasource/MySQLDataSource.java index 88cc2b0e..ae543aba 100644 --- a/src/main/java/fr/xephi/authme/datasource/MySQLDataSource.java +++ b/src/main/java/fr/xephi/authme/datasource/MySQLDataSource.java @@ -604,6 +604,17 @@ public class MySQLDataSource implements DataSource { @Override public void reload() { + try { + reconnect(true); + } catch (Exception e) { + ConsoleLogger.showError(e.getMessage()); + if (Settings.isStopEnabled) { + ConsoleLogger.showError("Can't reconnect to MySQL database... Please check your MySQL informations ! SHUTDOWN..."); + AuthMe.getInstance().getServer().shutdown(); + } + if (!Settings.isStopEnabled) + AuthMe.getInstance().getServer().getPluginManager().disablePlugin(AuthMe.getInstance()); + } } private void close(Statement st) { @@ -749,7 +760,7 @@ public class MySQLDataSource implements DataSource { } catch (Exception te) { try { con = null; - reconnect(); + reconnect(false); } catch (Exception e) { ConsoleLogger.showError(e.getMessage()); if (Settings.isStopEnabled) { @@ -765,7 +776,7 @@ public class MySQLDataSource implements DataSource { throw new AssertionError(ae.getMessage()); try { con = null; - reconnect(); + reconnect(false); } catch (Exception e) { ConsoleLogger.showError(e.getMessage()); if (Settings.isStopEnabled) { @@ -781,7 +792,7 @@ public class MySQLDataSource implements DataSource { return con; } - private synchronized void reconnect() throws ClassNotFoundException, SQLException, TimeoutException { + private synchronized void reconnect(boolean reload) throws ClassNotFoundException, SQLException, TimeoutException { conPool.dispose(); Class.forName("com.mysql.jdbc.Driver"); MysqlConnectionPoolDataSource dataSource = new MysqlConnectionPoolDataSource(); @@ -791,7 +802,8 @@ public class MySQLDataSource implements DataSource { dataSource.setUser(username); dataSource.setPassword(password); conPool = new MiniConnectionPoolManager(dataSource, 10); - ConsoleLogger.info("ConnectionPool was unavailable... Reconnected!"); + if(!reload) + ConsoleLogger.info("ConnectionPool was unavailable... Reconnected!"); } } diff --git a/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener.java b/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener.java index aed8036c..5cca514a 100644 --- a/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener.java +++ b/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener.java @@ -366,7 +366,7 @@ public class AuthMePlayerListener implements Listener { } int radius = Settings.getMovementRadius; - Location spawn = plugin.getSpawnLocation(player.getWorld()); + Location spawn = plugin.getSpawnLocation(name, player.getWorld()); if (!event.getPlayer().getWorld().equals(spawn.getWorld())) { event.getPlayer().teleport(spawn); @@ -542,9 +542,9 @@ public class AuthMePlayerListener implements Listener { } Player player = event.getPlayer(); World world = player.getWorld(); - Location spawnLoc = plugin.getSpawnLocation(world); - gm = player.getGameMode(); final String name = player.getName().toLowerCase(); + Location spawnLoc = plugin.getSpawnLocation(name, world); + gm = player.getGameMode(); gameMode.put(name, gm); BukkitScheduler sched = plugin.getServer().getScheduler(); @@ -588,6 +588,8 @@ public class AuthMePlayerListener implements Listener { PlayerCache.getInstance().addPlayer(auth); } m._(player, "valid_session"); + // Restore Permission Group + utils.setGroup(player, Utils.groupType.LOGGEDIN); return; } else if (!Settings.sessionExpireOnIpChange){ GameMode gM = gameMode.get(name); @@ -646,9 +648,20 @@ public class AuthMePlayerListener implements Listener { if(!Settings.unRegisteredGroup.isEmpty()){ utils.setGroup(player, Utils.groupType.UNREGISTERED); } + if (Settings.isTeleportToSpawnEnabled || (Settings.isForceSpawnLocOnJoinEnabled && Settings.getForcedWorlds.contains(player.getWorld().getName()))) { + SpawnTeleportEvent tpEvent = new SpawnTeleportEvent(player, player.getLocation(), spawnLoc, PlayerCache.getInstance().isAuthenticated(name)); + plugin.getServer().getPluginManager().callEvent(tpEvent); + if(!tpEvent.isCancelled()) { + if (!tpEvent.getTo().getWorld().getChunkAt(tpEvent.getTo()).isLoaded()) { + tpEvent.getTo().getWorld().getChunkAt(tpEvent.getTo()).load(); + } + player.teleport(tpEvent.getTo()); + } + } if (!Settings.isForcedRegistrationEnabled) { return; } + } if(Settings.protectInventoryBeforeLogInEnabled) { try { @@ -763,8 +776,8 @@ public class AuthMePlayerListener implements Listener { playerBackup.removeCache(name); } } + PlayerCache.getInstance().removePlayer(name); try { - PlayerCache.getInstance().removePlayer(name); PlayersLogs.players.remove(player.getName()); PlayersLogs.getInstance().save(); player.getVehicle().eject(); @@ -1086,7 +1099,7 @@ public class AuthMePlayerListener implements Listener { if (!Settings.isForcedRegistrationEnabled) return; - Location spawn = plugin.getSpawnLocation(player.getWorld()); + Location spawn = plugin.getSpawnLocation(name, player.getWorld()); if(Settings.isSaveQuitLocationEnabled && data.isAuthAvailable(name)) { final PlayerAuth auth = new PlayerAuth(name,spawn.getX(),spawn.getY(),spawn.getZ(),spawn.getWorld().getName()); try { diff --git a/src/main/java/fr/xephi/authme/process/login/AsyncronousLogin.java b/src/main/java/fr/xephi/authme/process/login/AsyncronousLogin.java index d41d6600..1c09087c 100644 --- a/src/main/java/fr/xephi/authme/process/login/AsyncronousLogin.java +++ b/src/main/java/fr/xephi/authme/process/login/AsyncronousLogin.java @@ -194,19 +194,19 @@ public class AsyncronousLogin { if (auth == null) { return; } - if (this.database.getAllAuthsByName(auth).isEmpty() || this.database.getAllAuthsByName(auth) == null) { + List auths = this.database.getAllAuthsByName(auth); + if (auths.isEmpty() || auths == null) { return; } - if (this.database.getAllAuthsByName(auth).size() == 1) { + if (auths.size() == 1) { return; } - List accountList = this.database.getAllAuthsByName(auth); String message = "[AuthMe] "; int i = 0; - for (String account : accountList) { + for (String account : auths) { i++; message = message + account; - if (i != accountList.size()) { + if (i != auths.size()) { message = message + ", "; } else { message = message + "."; @@ -215,7 +215,7 @@ public class AsyncronousLogin { for (Player player : plugin.getServer().getOnlinePlayers()) { if (plugin.authmePermissible(player, "authme.seeOtherAccounts")) { player.sendMessage("[AuthMe] The player " + auth.getNickname() + " has " - + accountList.size() + " accounts"); + + auths.size() + " accounts"); player.sendMessage(message); } } diff --git a/src/main/java/fr/xephi/authme/process/login/ProcessSyncronousPlayerLogin.java b/src/main/java/fr/xephi/authme/process/login/ProcessSyncronousPlayerLogin.java index 14257771..b33dc1f5 100644 --- a/src/main/java/fr/xephi/authme/process/login/ProcessSyncronousPlayerLogin.java +++ b/src/main/java/fr/xephi/authme/process/login/ProcessSyncronousPlayerLogin.java @@ -68,7 +68,7 @@ public class ProcessSyncronousPlayerLogin implements Runnable { } } protected void teleportToSpawn() { - Location spawnL = plugin.getSpawnLocation(player.getWorld()); + Location spawnL = plugin.getSpawnLocation(name, player.getWorld()); SpawnTeleportEvent tpEvent = new SpawnTeleportEvent(player, player.getLocation(), spawnL, true); pm.callEvent(tpEvent); if (!tpEvent.isCancelled()) { @@ -187,7 +187,7 @@ public class ProcessSyncronousPlayerLogin implements Runnable { if(Settings.useWelcomeMessage) if(Settings.broadcastWelcomeMessage) { for (String s : Settings.welcomeMsg) { - Bukkit.getServer().broadcastMessage(s); + Bukkit.getServer().broadcastMessage(plugin.replaceAllInfos(s, player)); } } else { for (String s : Settings.welcomeMsg) { diff --git a/src/main/java/fr/xephi/authme/process/register/AsyncronousRegister.java b/src/main/java/fr/xephi/authme/process/register/AsyncronousRegister.java index df0d23ad..2c6f6fc8 100644 --- a/src/main/java/fr/xephi/authme/process/register/AsyncronousRegister.java +++ b/src/main/java/fr/xephi/authme/process/register/AsyncronousRegister.java @@ -66,17 +66,24 @@ public class AsyncronousRegister { } if(Settings.getmaxRegPerIp > 0 ){ - if(!plugin.authmePermissible(player, "authme.allow2accounts") && database.getAllAuthsByIp(getIp()).size() >= Settings.getmaxRegPerIp) { + if(!plugin.authmePermissible(player, "authme.allow2accounts") && database.getAllAuthsByIp(getIp()).size() >= Settings.getmaxRegPerIp && !getIp().equalsIgnoreCase("127.0.0.1") && !getIp().equalsIgnoreCase("localhost")) { m._(player, "max_reg"); allowRegister = false; } } + } public void process() { preRegister(); if(!allowRegister) return; if(!email.isEmpty() && email != "") { + if(Settings.getmaxRegPerEmail > 0) { + if (!plugin.authmePermissible(player, "authme.allow2accounts") && database.getAllAuthsByEmail(email).size() >= Settings.getmaxRegPerEmail) { + m._(player, "max_reg"); + return; + } + } emailRegister(); return; } diff --git a/src/main/java/fr/xephi/authme/process/register/ProcessSyncronousEmailRegister.java b/src/main/java/fr/xephi/authme/process/register/ProcessSyncronousEmailRegister.java index f8b778b7..6ae9fa1e 100644 --- a/src/main/java/fr/xephi/authme/process/register/ProcessSyncronousEmailRegister.java +++ b/src/main/java/fr/xephi/authme/process/register/ProcessSyncronousEmailRegister.java @@ -49,7 +49,7 @@ public class ProcessSyncronousEmailRegister implements Runnable { if (Settings.isTeleportToSpawnEnabled) { World world = player.getWorld(); - Location loca = plugin.getSpawnLocation(world); + Location loca = plugin.getSpawnLocation(name, world); RegisterTeleportEvent tpEvent = new RegisterTeleportEvent(player, loca); plugin.getServer().getPluginManager().callEvent(tpEvent); if(!tpEvent.isCancelled()) { diff --git a/src/main/java/fr/xephi/authme/process/register/ProcessSyncronousPasswordRegister.java b/src/main/java/fr/xephi/authme/process/register/ProcessSyncronousPasswordRegister.java index 1482c968..3462b2cf 100644 --- a/src/main/java/fr/xephi/authme/process/register/ProcessSyncronousPasswordRegister.java +++ b/src/main/java/fr/xephi/authme/process/register/ProcessSyncronousPasswordRegister.java @@ -44,7 +44,7 @@ public class ProcessSyncronousPasswordRegister implements Runnable { player.setGameMode(limbo.getGameMode()); if (Settings.isTeleportToSpawnEnabled) { World world = player.getWorld(); - Location loca = plugin.getSpawnLocation(world); + Location loca = plugin.getSpawnLocation(name, world); RegisterTeleportEvent tpEvent = new RegisterTeleportEvent(player, loca); plugin.getServer().getPluginManager().callEvent(tpEvent); if(!tpEvent.isCancelled()) { diff --git a/src/main/java/fr/xephi/authme/settings/Spawn.java b/src/main/java/fr/xephi/authme/settings/Spawn.java index 4223a672..b346ce60 100644 --- a/src/main/java/fr/xephi/authme/settings/Spawn.java +++ b/src/main/java/fr/xephi/authme/settings/Spawn.java @@ -1,9 +1,6 @@ package fr.xephi.authme.settings; import java.io.File; -import java.util.ArrayList; -import java.util.List; - import org.bukkit.Bukkit; import org.bukkit.Location; @@ -14,7 +11,6 @@ import org.bukkit.Location; public class Spawn extends CustomConfiguration { private static Spawn spawn; - private static List emptyList = new ArrayList(); public Spawn() { super(new File("./plugins/AuthMe/spawn.yml")); @@ -26,7 +22,6 @@ public class Spawn extends CustomConfiguration { private void saveDefault() { if (!contains("spawn")) { - set("spawn", emptyList); set("spawn.world", ""); set("spawn.x", ""); set("spawn.y", ""); @@ -35,6 +30,15 @@ public class Spawn extends CustomConfiguration { set("spawn.pitch", ""); save(); } + if (!contains("firstspawn")) { + set("firstspawn.world", ""); + set("firstspawn.x", ""); + set("firstspawn.y", ""); + set("firstspawn.z", ""); + set("firstspawn.yaw", ""); + set("firstspawn.pitch", ""); + save(); + } } public static Spawn getInstance() { @@ -59,7 +63,27 @@ public class Spawn extends CustomConfiguration { } } + public boolean setFirstSpawn(Location location) { + try { + set("firstspawn.world", location.getWorld().getName()); + set("firstspawn.x", location.getX()); + set("firstspawn.y", location.getY()); + set("firstspawn.z", location.getZ()); + set("firstspawn.yaw", location.getYaw()); + set("firstspawn.pitch", location.getPitch()); + save(); + return true; + } catch (NullPointerException npe) { + return false; + } + } + + @Deprecated public Location getLocation() { + return getSpawn(); + } + + public Location getSpawn() { try { if (this.getString("spawn.world").isEmpty() || this.getString("spawn.world") == "") return null; Location location = new Location(Bukkit.getWorld(this.getString("spawn.world")), this.getDouble("spawn.x"), this.getDouble("spawn.y"), this.getDouble("spawn.z"), Float.parseFloat(this.getString("spawn.yaw")), Float.parseFloat(this.getString("spawn.pitch"))); @@ -70,5 +94,17 @@ public class Spawn extends CustomConfiguration { return null; } } + + public Location getFirstSpawn() { + try { + if (this.getString("firstspawn.world").isEmpty() || this.getString("firstspawn.world") == "") return null; + Location location = new Location(Bukkit.getWorld(this.getString("firstspawn.world")), this.getDouble("firstspawn.x"), this.getDouble("firstspawn.y"), this.getDouble("firstspawn.z"), Float.parseFloat(this.getString("firstspawn.yaw")), Float.parseFloat(this.getString("firstspawn.pitch"))); + return location; + } catch (NullPointerException npe) { + return null; + } catch (NumberFormatException nfe) { + return null; + } + } } diff --git a/src/main/java/fr/xephi/authme/threads/MySQLThread.java b/src/main/java/fr/xephi/authme/threads/MySQLThread.java index 617c3a61..98fab821 100644 --- a/src/main/java/fr/xephi/authme/threads/MySQLThread.java +++ b/src/main/java/fr/xephi/authme/threads/MySQLThread.java @@ -64,7 +64,6 @@ public class MySQLThread extends Thread implements DataSource { this.columnEmail = Settings.getMySQLColumnEmail; this.columnOthers = Settings.getMySQLOtherUsernameColumn; this.columnID = Settings.getMySQLColumnId; - try { this.connect(); this.setup(); @@ -635,6 +634,17 @@ public class MySQLThread extends Thread implements DataSource { @Override public void reload() { + try { + reconnect(true); + } catch (Exception e) { + ConsoleLogger.showError(e.getMessage()); + if (Settings.isStopEnabled) { + ConsoleLogger.showError("Can't reconnect to MySQL database... Please check your MySQL informations ! SHUTDOWN..."); + AuthMe.getInstance().getServer().shutdown(); + } + if (!Settings.isStopEnabled) + AuthMe.getInstance().getServer().getPluginManager().disablePlugin(AuthMe.getInstance()); + } } private void close(Statement st) { @@ -780,7 +790,7 @@ public class MySQLThread extends Thread implements DataSource { } catch (Exception te) { try { con = null; - reconnect(); + reconnect(false); } catch (Exception e) { ConsoleLogger.showError(e.getMessage()); if (Settings.isStopEnabled) { @@ -796,7 +806,7 @@ public class MySQLThread extends Thread implements DataSource { throw new AssertionError(ae.getMessage()); try { con = null; - reconnect(); + reconnect(false); } catch (Exception e) { ConsoleLogger.showError(e.getMessage()); if (Settings.isStopEnabled) { @@ -812,7 +822,7 @@ public class MySQLThread extends Thread implements DataSource { return con; } - private synchronized void reconnect() throws ClassNotFoundException, SQLException, TimeoutException { + private synchronized void reconnect(boolean reload) throws ClassNotFoundException, SQLException, TimeoutException { conPool.dispose(); Class.forName("com.mysql.jdbc.Driver"); MysqlConnectionPoolDataSource dataSource = new MysqlConnectionPoolDataSource(); @@ -822,7 +832,8 @@ public class MySQLThread extends Thread implements DataSource { dataSource.setUser(username); dataSource.setPassword(password); conPool = new MiniConnectionPoolManager(dataSource, 10); - ConsoleLogger.info("ConnectionPool was unavailable... Reconnected!"); + if (!reload) + ConsoleLogger.info("ConnectionPool was unavailable... Reconnected!"); } } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 68d631ae..04b3a930 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -3,7 +3,7 @@ author: Xephi59 website: http://dev.bukkit.org/bukkit-plugins/authme-reloaded/ description: AuthMe prevents people, which aren't logged in, from doing stuff like placing blocks, moving, typing commands or seeing the inventory of the current player. main: fr.xephi.authme.AuthMe -version: 3.3.2 +version: 3.3.3 softdepend: [Vault, ChestShop, Spout, Multiverse-Core, Notifications, Citizens, CombatTag, Essentials, EssentialsSpawn] commands: register: @@ -158,4 +158,10 @@ permissions: default: op authme.admin.royalauth: description: Import RoyalAuth database into AuthMe + default: op + authme.admin.setfirstspawn: + description: Set the AuthMe First Spawn Point + default: op + authme.admin.firstspawn: + description: Teleport to AuthMe First Spawn Point default: op \ No newline at end of file diff --git a/src/main/resources/spawn.yml b/src/main/resources/spawn.yml index 8da3ca23..5191803c 100644 --- a/src/main/resources/spawn.yml +++ b/src/main/resources/spawn.yml @@ -1,4 +1,11 @@ spawn: + world: '' + x: '' + y: '' + z: '' + yaw: '' + pitch: '' +firstspawn: world: '' x: '' y: ''