Code cleanup

This commit is contained in:
Gabriele C 2015-07-28 02:57:50 +02:00
parent 223fff4b52
commit 47211ab803
3 changed files with 17 additions and 12 deletions

View File

@ -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();
}
}
}
}

View File

@ -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) {

View File

@ -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());
}
}