From 47211ab803fc2bbda6f5b4cd52209615fc784f9c Mon Sep 17 00:00:00 2001 From: Gabriele C Date: Tue, 28 Jul 2015 02:57:50 +0200 Subject: [PATCH] Code cleanup --- src/main/java/fr/xephi/authme/Utils.java | 12 ++++++++++++ .../java/fr/xephi/authme/cache/backup/FileCache.java | 11 ++--------- .../xephi/authme/process/join/AsyncronousJoin.java | 6 +++--- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/main/java/fr/xephi/authme/Utils.java b/src/main/java/fr/xephi/authme/Utils.java index 15e01fe22..cadac9eb8 100644 --- a/src/main/java/fr/xephi/authme/Utils.java +++ b/src/main/java/fr/xephi/authme/Utils.java @@ -1,5 +1,6 @@ package fr.xephi.authme; +import java.io.File; import java.util.ArrayList; import java.util.Iterator; import java.util.List; @@ -208,5 +209,16 @@ public class Utils { NOTLOGGEDIN, 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(); + } + } + } } 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 11fce587c..948b0b079 100644 --- a/src/main/java/fr/xephi/authme/cache/backup/FileCache.java +++ b/src/main/java/fr/xephi/authme/cache/backup/FileCache.java @@ -24,6 +24,7 @@ import fr.xephi.authme.AuthMe; import fr.xephi.authme.ConsoleLogger; import fr.xephi.authme.api.API; import fr.xephi.authme.settings.Settings; +import fr.xephi.authme.Utils; public class FileCache { @@ -547,15 +548,7 @@ public class FileCache { } if (file.exists()) { if (file.isDirectory() && file.listFiles() != null) { - for (File f : file.listFiles()) { - if (f.isDirectory() && f.listFiles() != null) { - for (File a : f.listFiles()) { - a.delete(); - } - f.delete(); - } else f.delete(); - } - file.delete(); + Utils.purgeDirectory(file); } else file.delete(); } } catch (Exception e) { diff --git a/src/main/java/fr/xephi/authme/process/join/AsyncronousJoin.java b/src/main/java/fr/xephi/authme/process/join/AsyncronousJoin.java index 7e5101d0b..2e72bde46 100644 --- a/src/main/java/fr/xephi/authme/process/join/AsyncronousJoin.java +++ b/src/main/java/fr/xephi/authme/process/join/AsyncronousJoin.java @@ -141,7 +141,7 @@ public class AsyncronousJoin { SpawnTeleportEvent tpEvent = new SpawnTeleportEvent(player, player.getLocation(), spawnLoc, PlayerCache.getInstance().isAuthenticated(name)); plugin.getServer().getPluginManager().callEvent(tpEvent); if (!tpEvent.isCancelled()) { - if (player != null && player.isOnline() && tpEvent.getTo() != null) { + if (player.isOnline() && tpEvent.getTo() != null) { if (tpEvent.getTo().getWorld() != null) player.teleport(tpEvent.getTo()); } @@ -185,7 +185,7 @@ public class AsyncronousJoin { SpawnTeleportEvent tpEvent = new SpawnTeleportEvent(player, player.getLocation(), spawnLoc, PlayerCache.getInstance().isAuthenticated(name)); plugin.getServer().getPluginManager().callEvent(tpEvent); if (!tpEvent.isCancelled()) { - if (player != null && player.isOnline() && tpEvent.getTo() != null) { + if (player.isOnline() && tpEvent.getTo() != null) { if (tpEvent.getTo().getWorld() != null) player.teleport(tpEvent.getTo()); } @@ -291,7 +291,7 @@ public class AsyncronousJoin { FirstSpawnTeleportEvent tpEvent = new FirstSpawnTeleportEvent(player, player.getLocation(), loc); plugin.getServer().getPluginManager().callEvent(tpEvent); if (!tpEvent.isCancelled()) { - if (player != null && player.isOnline() && tpEvent.getTo() != null && tpEvent.getTo().getWorld() != null) { + if (player.isOnline() && tpEvent.getTo() != null && tpEvent.getTo().getWorld() != null) { player.teleport(tpEvent.getTo()); } }