Merge branch 'master' of https://github.com/AuthMe/AuthMeReloaded into explicit-getters-from-db

This commit is contained in:
ljacqu
2017-04-29 08:19:30 +02:00
47 changed files with 786 additions and 306 deletions
@@ -30,7 +30,7 @@ public final class FileUtils {
public static boolean copyFileFromResource(File destinationFile, String resourcePath) {
if (destinationFile.exists()) {
return true;
} else if (!destinationFile.getParentFile().exists() && !destinationFile.getParentFile().mkdirs()) {
} else if (!createDirectory(destinationFile.getParentFile())) {
ConsoleLogger.warning("Cannot create parent directories for '" + destinationFile + "'");
return false;
}
@@ -50,6 +50,20 @@ public final class FileUtils {
return false;
}
/**
* Creates the given directory.
*
* @param dir the directory to create
* @return true upon success, false otherwise
*/
public static boolean createDirectory(File dir) {
if (!dir.exists() && !dir.mkdirs()) {
ConsoleLogger.warning("Could not create directory '" + dir + "'");
return false;
}
return true;
}
/**
* Returns a JAR file as stream. Returns null if it doesn't exist.
*
@@ -1,6 +1,7 @@
package fr.xephi.authme.util;
import fr.xephi.authme.ConsoleLogger;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
@@ -69,6 +70,22 @@ public final class Utils {
}
}
/**
* Sends a warning to the given sender (null safe), and logs the warning to the console.
* This method is aware that the command sender might be the console sender and avoids
* displaying the message twice in this case.
*
* @param sender the sender to inform
* @param message the warning to log and send
*/
public static void logAndSendWarning(CommandSender sender, String message) {
ConsoleLogger.warning(message);
// Make sure sender is not console user, which will see the message from ConsoleLogger already
if (sender != null && !(sender instanceof ConsoleCommandSender)) {
sender.sendMessage(ChatColor.RED + message);
}
}
/**
* Null-safe way to check whether a collection is empty or not.
*