diff --git a/src/main/java/fr/xephi/authme/cache/backup/FileCache.java b/src/main/java/fr/xephi/authme/cache/backup/FileCache.java index 429b9fcf3..be8eef292 100644 --- a/src/main/java/fr/xephi/authme/cache/backup/FileCache.java +++ b/src/main/java/fr/xephi/authme/cache/backup/FileCache.java @@ -3,6 +3,7 @@ package fr.xephi.authme.cache.backup; import java.io.File; import java.io.FileWriter; import java.util.ArrayList; +import java.util.Iterator; import java.util.List; import java.util.Scanner; import java.util.UUID; @@ -51,7 +52,7 @@ public class FileCache { File file = new File(plugin.getDataFolder() + File.separator + "cache" + File.separator + path + File.separator + "playerdatas.cache"); if (!file.getParentFile().exists()) - file.getParentFile().mkdir(); + file.getParentFile().mkdirs(); if (file.exists()) { return; } @@ -68,7 +69,7 @@ public class FileCache { file = new File(plugin.getDataFolder() + File.separator + "cache" + File.separator + path + File.separator + "inventory"); - file.mkdir(); + file.mkdirs(); ItemStack[] inv = playerData.getInventory(); for (int i = 0; i < inv.length; i++) { ItemStack item = inv[i]; @@ -108,14 +109,20 @@ public class FileCache { if (Settings.customAttributes) { try { Attributes attributes = new Attributes(item); - if (attributes != null) - while (attributes.values().iterator().hasNext()) { - Attribute a = attributes.values().iterator().next(); + if (attributes != null) { + Iterator iter = attributes.values().iterator(); + Attribute a = null; + while (iter.hasNext()) { + Attribute b = iter.next(); + if (a != null && a == b) + break; + a = b; if (a != null) { if (a.getName() != null && a.getAttributeType() != null && a.getOperation() != null && a.getUUID() != null) writer.write("attribute=" + a.getName() + ";" + a.getAttributeType().getMinecraftId() + ";" + a.getAmount() + ";" + a.getOperation().getId() + ";" + a.getUUID().toString()); } } + } } catch (Exception e) { } catch (Error e) { } @@ -128,8 +135,8 @@ public class FileCache { file = new File(plugin.getDataFolder() + File.separator + "cache" + File.separator + path + File.separator + "armours"); if (!file.getParentFile().exists()) - file.getParentFile().mkdir(); - file.mkdir(); + file.getParentFile().mkdirs(); + file.mkdirs(); ItemStack[] armors = playerData.getArmour(); for (int i = 0; i < armors.length; i++) { @@ -393,8 +400,7 @@ public class FileCache { line = line.substring(8); item.addEnchantment(Enchantment.getByName(line.split(":")[0]), Integer.parseInt(line.split(":")[1])); } - if (Settings.customAttributes) - { + if (Settings.customAttributes) { if (line.startsWith("attribute=")) { if (attributes == null) attributes = new Attributes(item); @@ -468,8 +474,7 @@ public class FileCache { line = line.substring(8); item.addEnchantment(Enchantment.getByName(line.split(":")[0]), Integer.parseInt(line.split(":")[1])); } - if (Settings.customAttributes) - { + if (Settings.customAttributes) { if (line.startsWith("attribute=")) { if (attributes == null) attributes = new Attributes(item); diff --git a/src/main/java/fr/xephi/authme/commands/ChangePasswordCommand.java b/src/main/java/fr/xephi/authme/commands/ChangePasswordCommand.java index 24fc46f81..7ca904d15 100644 --- a/src/main/java/fr/xephi/authme/commands/ChangePasswordCommand.java +++ b/src/main/java/fr/xephi/authme/commands/ChangePasswordCommand.java @@ -53,6 +53,11 @@ public class ChangePasswordCommand implements CommandExecutor { return true; } + String lowpass = args[1].toLowerCase(); + if ((lowpass.contains("delete") || lowpass.contains("where") || lowpass.contains("insert") || lowpass.contains("modify") || lowpass.contains("from") || lowpass.contains("select") || lowpass.contains(";") || lowpass.contains("null")) || !lowpass.matches(Settings.getPassRegex)) { + m.send(player, "password_error"); + return true; + } try { String hashnew = PasswordSecurity.getHash(Settings.getPasswordHash, args[1], name); diff --git a/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener.java b/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener.java index 73115a9d8..1d2776f5b 100644 --- a/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener.java +++ b/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener.java @@ -29,6 +29,7 @@ import org.bukkit.event.player.PlayerInteractEntityEvent; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerKickEvent; +import org.bukkit.event.player.PlayerLoginEvent; import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.player.PlayerPickupItemEvent; import org.bukkit.event.player.PlayerQuitEvent; @@ -353,6 +354,12 @@ public class AuthMePlayerListener implements Listener { return; } + if (!data.isAuthAvailable(name)) { + if (!Settings.isForcedRegistrationEnabled) { + return; + } + } + if (!Settings.isForcedRegistrationEnabled) { return; } @@ -400,7 +407,7 @@ public class AuthMePlayerListener implements Listener { return; } - if (!Settings.countriesBlacklist.isEmpty()) { + if (Settings.enablePasspartu && !Settings.countriesBlacklist.isEmpty()) { String code = plugin.getCountryCode(event.getAddress().getHostAddress()); if (((code == null) || (Settings.countriesBlacklist.contains(code) && !API.isRegistered(name))) && !plugin.authmePermissible(player, "authme.bypassantibot")) { event.setKickMessage(m.send("country_banned")[0]); @@ -566,6 +573,58 @@ public class AuthMePlayerListener implements Listener { }, 300); } + @EventHandler(priority = EventPriority.HIGHEST) + public void onPlayerLogin(PlayerLoginEvent event) { + if (event.getPlayer() == null) + return; + + Player player = event.getPlayer(); + String name = player.getName(); + String regex = Settings.getNickRegex; + if (Settings.enableProtection && !Settings.countriesBlacklist.isEmpty()) { + String code = plugin.getCountryCode(event.getAddress().getHostAddress()); + if (((code == null) || (Settings.countriesBlacklist.contains(code) && !API.isRegistered(name))) && !plugin.authmePermissible(player, "authme.bypassantibot")) { + event.setKickMessage(m.send("country_banned")[0]); + event.setResult(PlayerLoginEvent.Result.KICK_OTHER); + return; + } + } + if (Settings.enableProtection && !Settings.countries.isEmpty()) { + String code = plugin.getCountryCode(event.getAddress().getHostAddress()); + if (((code == null) || (!Settings.countries.contains(code) && !API.isRegistered(name))) && !plugin.authmePermissible(player, "authme.bypassantibot")) { + event.setKickMessage(m.send("country_banned")[0]); + event.setResult(PlayerLoginEvent.Result.KICK_OTHER); + return; + } + } + try { + if (!player.getName().matches(regex) || name.equals("Player")) { + try { + event.setKickMessage(m.send("regex")[0].replace("REG_EX", regex)); + event.setResult(PlayerLoginEvent.Result.KICK_OTHER); + } catch (Exception exc) { + event.setKickMessage("allowed char : " + regex); + event.setResult(PlayerLoginEvent.Result.KICK_OTHER); + } + return; + } + } catch (PatternSyntaxException pse) { + if (regex == null || regex.isEmpty()) { + event.setKickMessage("Your nickname do not match"); + event.setResult(PlayerLoginEvent.Result.KICK_OTHER); + return; + } + try { + event.setKickMessage(m.send("regex")[0].replace("REG_EX", regex)); + event.setResult(PlayerLoginEvent.Result.KICK_OTHER); + } catch (Exception exc) { + event.setKickMessage("allowed char : " + regex); + event.setResult(PlayerLoginEvent.Result.KICK_OTHER); + } + return; + } + } + @EventHandler(priority = EventPriority.HIGHEST) public void onPlayerJoin(PlayerJoinEvent event) { if (event.getPlayer() == null) { @@ -829,8 +888,10 @@ public class AuthMePlayerListener implements Listener { player.setAllowFlight(limbo.isFlying()); player.setFlying(limbo.isFlying()); } - limbo.getTimeoutTaskId().cancel(); - limbo.getMessageTaskId().cancel(); + if (limbo.getTimeoutTaskId() != null) + limbo.getTimeoutTaskId().cancel(); + if (limbo.getMessageTaskId() != null) + limbo.getMessageTaskId().cancel(); LimboCache.getInstance().deleteLimboPlayer(name); if (playerBackup.doesCacheExist(player)) { playerBackup.removeCache(player); @@ -916,8 +977,10 @@ public class AuthMePlayerListener implements Listener { player.setAllowFlight(limbo.isFlying()); player.setFlying(limbo.isFlying()); } - limbo.getTimeoutTaskId().cancel(); - limbo.getMessageTaskId().cancel(); + if (limbo.getTimeoutTaskId() != null) + limbo.getTimeoutTaskId().cancel(); + if (limbo.getMessageTaskId() != null) + limbo.getMessageTaskId().cancel(); LimboCache.getInstance().deleteLimboPlayer(name); if (this.playerBackup.doesCacheExist(player)) { this.playerBackup.removeCache(player); diff --git a/src/main/java/fr/xephi/authme/process/Management.java b/src/main/java/fr/xephi/authme/process/Management.java index bdcd1de5a..4207b5655 100644 --- a/src/main/java/fr/xephi/authme/process/Management.java +++ b/src/main/java/fr/xephi/authme/process/Management.java @@ -1,5 +1,6 @@ package fr.xephi.authme.process; +import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.plugin.PluginManager; @@ -34,11 +35,21 @@ public class Management extends Thread { public void performLogin(final Player player, final String password, final boolean forceLogin) { - new AsyncronousLogin(player, password, forceLogin, plugin, database).process(); + Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable(){ + @Override + public void run() { + new AsyncronousLogin(player, password, forceLogin, plugin, database).process(); + } + }); } public void performRegister(final Player player, final String password, final String email) { - new AsyncronousRegister(player, password, email, plugin, database).process(); + Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable(){ + @Override + public void run() { + new AsyncronousRegister(player, password, email, plugin, database).process(); + } + }); } } 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 4842dd057..a4a91e96c 100644 --- a/src/main/java/fr/xephi/authme/process/login/AsyncronousLogin.java +++ b/src/main/java/fr/xephi/authme/process/login/AsyncronousLogin.java @@ -169,8 +169,10 @@ public class AsyncronousLogin { // processed in other order. ProcessSyncronousPlayerLogin syncronousPlayerLogin = new ProcessSyncronousPlayerLogin(player, plugin, database); if (syncronousPlayerLogin.getLimbo() != null) { - syncronousPlayerLogin.getLimbo().getTimeoutTaskId().cancel(); - syncronousPlayerLogin.getLimbo().getMessageTaskId().cancel(); + if (syncronousPlayerLogin.getLimbo().getTimeoutTaskId() != null) + syncronousPlayerLogin.getLimbo().getTimeoutTaskId().cancel(); + if (syncronousPlayerLogin.getLimbo().getMessageTaskId() != null) + syncronousPlayerLogin.getLimbo().getMessageTaskId().cancel(); } Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, syncronousPlayerLogin); } else if (player.isOnline()) {