From 88530542ace896bdd75c084030245f4ff6ff6807 Mon Sep 17 00:00:00 2001 From: Gabriele C Date: Tue, 28 Jul 2015 17:06:54 +0200 Subject: [PATCH] Fixes --- src/main/java/fr/xephi/authme/Utils.java | 21 ++++++----- .../xephi/authme/cache/backup/FileCache.java | 35 ++++++++++--------- .../authme/listener/AuthMePlayerListener.java | 2 +- 3 files changed, 32 insertions(+), 26 deletions(-) diff --git a/src/main/java/fr/xephi/authme/Utils.java b/src/main/java/fr/xephi/authme/Utils.java index cadac9eb8..ee20c5784 100644 --- a/src/main/java/fr/xephi/authme/Utils.java +++ b/src/main/java/fr/xephi/authme/Utils.java @@ -210,15 +210,18 @@ public class Utils { LOGGEDIN } - public static void purgeDirectory(File dir) { - if (dir != null && dir.listFiles() != null) - for (File file : dir.listFiles()) { - if (file != null){ - if (file.isDirectory()) - purgeDirectory(file); - file.delete(); - } + public static void purgeDirectory(File file){ + String files[] = file.list(); + if (files != null && files.length != 0){ + for (String temp : files) { + File fileDelete = new File(file, temp); + if (fileDelete.isDirectory()){ + purgeDirectory(fileDelete); + fileDelete.delete(); + } else { + fileDelete.delete(); + } + } } } - } 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 948b0b079..b18ad9c16 100644 --- a/src/main/java/fr/xephi/authme/cache/backup/FileCache.java +++ b/src/main/java/fr/xephi/authme/cache/backup/FileCache.java @@ -45,9 +45,9 @@ public class FileCache { try { path = player.getUniqueId().toString(); } catch (Exception e) { - path = player.getName(); + path = player.getName().toLowerCase(); } catch (Error e) { - path = player.getName(); + path = player.getName().toLowerCase(); } File file = new File(plugin.getDataFolder() + File.separator + "cache" + File.separator + path + File.separator + "playerdatas.cache"); @@ -198,9 +198,9 @@ public class FileCache { try { path = player.getUniqueId().toString(); } catch (Exception e) { - path = player.getName(); + path = player.getName().toLowerCase(); } catch (Error e) { - path = player.getName(); + path = player.getName().toLowerCase(); } try { File file = new File(plugin.getDataFolder() + File.separator + "cache" + File.separator + path + File.separator + "playerdatas.cache"); @@ -537,22 +537,25 @@ public class FileCache { try { path = player.getUniqueId().toString(); } catch (Exception e) { - path = player.getName(); + path = player.getName().toLowerCase(); } catch (Error e) { - path = player.getName(); + path = player.getName().toLowerCase(); } try { File file = new File(plugin.getDataFolder() + File.separator + "cache" + File.separator + path); - if (!file.exists()) { - file = new File("cache/" + player.getName().toLowerCase() + ".cache"); - } - if (file.exists()) { - if (file.isDirectory() && file.listFiles() != null) { - Utils.purgeDirectory(file); - } else file.delete(); + if (file.list() != null) { + Utils.purgeDirectory(file); + file.delete(); + } else { + file = new File(plugin.getDataFolder() + File.separator + "cache" + File.separator + player.getName().toLowerCase() + ".cache"); + if(file.isFile()){ + file.delete(); + } else { + ConsoleLogger.showError("Failed to remove" + player.getName() + "cache, it doesn't exist!"); + } } } catch (Exception e) { - ConsoleLogger.showError("File cannot be removed correctly :/"); + ConsoleLogger.showError("Failed to remove" + player.getName() + "cache :/"); } } @@ -561,9 +564,9 @@ public class FileCache { try { path = player.getUniqueId().toString(); } catch (Exception e) { - path = player.getName(); + path = player.getName().toLowerCase(); } catch (Error e) { - path = player.getName(); + path = player.getName().toLowerCase(); } File file = new File(plugin.getDataFolder() + File.separator + "cache" + File.separator + path + File.separator + "playerdatas.cache"); if (!file.exists()) { diff --git a/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener.java b/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener.java index 5ce3148e1..2fff82fd5 100644 --- a/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener.java +++ b/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener.java @@ -438,7 +438,7 @@ public class AuthMePlayerListener implements Listener { if (Settings.antiBotInAction){ if (!plugin.database.isAuthAvailable(name)) { - event.setKickMessage(m.send("AntiBot service in action! Non registered players can't connect until the bot attack stops!")[0]); //Need to add string to messages + event.setKickMessage("AntiBot service in action! Non registered players can't connect until the bot attack stops!"); //Need to add string to messages event.setResult(PlayerLoginEvent.Result.KICK_OTHER); return; }