diff --git a/.floo b/.floo new file mode 100644 index 000000000..b0f2c28e0 --- /dev/null +++ b/.floo @@ -0,0 +1,3 @@ +{ + "url": "https://floobits.com/AuthMe-Team/AuthMeReloaded" +} \ No newline at end of file diff --git a/.flooignore b/.flooignore new file mode 100644 index 000000000..e9c355d00 --- /dev/null +++ b/.flooignore @@ -0,0 +1,123 @@ +### Java ### +*.class + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +#*.jar +*.war +*.ear + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* + + +### Intellij ### +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm + +*.iml + +## Directory-based project format: +.idea/ +# if you remove the above rule, at least ignore the following: + +# User-specific stuff: +# .idea/workspace.xml +# .idea/tasks.xml +# .idea/dictionaries + +# Sensitive or high-churn files: +# .idea/dataSources.ids +# .idea/dataSources.xml +# .idea/sqlDataSources.xml +# .idea/dynamic.xml +# .idea/uiDesigner.xml + +# Gradle: +# .idea/gradle.xml +# .idea/libraries + +# Mongo Explorer plugin: +# .idea/mongoSettings.xml + +## File-based project format: +*.ipr +*.iws + +## Plugin-specific files: + +# IntelliJ +/out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties + + +### Eclipse ### +*.pydevproject +.metadata +.gradle +bin/ +tmp/ +*.tmp +*.bak +*.swp +*~.nib +local.properties +.settings/ +.loadpath + +# Eclipse Core +.project + +# External tool builders +.externalToolBuilders/ + +# Locally stored "Eclipse launch configurations" +*.launch + +# CDT-specific +.cproject + +# JDT-specific (Eclipse Java Development Tools) +.classpath + +# PDT-specific +.buildpath + +# sbteclipse plugin +.target + +# TeXlipse plugin +.texlipse + + +### Maven ### +target/ +pom.xml.tag +pom.xml.releaseBackup +pom.xml.versionsBackup +pom.xml.next +release.properties +dependency-reduced-pom.xml +buildNumber.properties + + +### NetBeans ### +nbproject/private/ +build/ +nbbuild/ +dist/ +nbdist/ +nbactions.xml +nb-configuration.xml +.nb-gradle/ diff --git a/.gitignore b/.gitignore index a0348ece7..e9c355d00 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,3 @@ -# Created by https://www.gitignore.io - ### Java ### *.class diff --git a/pom.xml b/pom.xml index 1a9a64396..9c19232fd 100644 --- a/pom.xml +++ b/pom.xml @@ -46,7 +46,7 @@ UTF-8 fr.xephi.authme.AuthMe - CustomBuild + 100 [Xephi, sgdc3, DNx5, timvisee, games647, ljacqu] diff --git a/src/main/java/fr/xephi/authme/AuthMe.java b/src/main/java/fr/xephi/authme/AuthMe.java index f78c1ebdc..7630b99e2 100644 --- a/src/main/java/fr/xephi/authme/AuthMe.java +++ b/src/main/java/fr/xephi/authme/AuthMe.java @@ -1,18 +1,31 @@ package fr.xephi.authme; -import java.io.BufferedReader; -import java.io.InputStreamReader; -import java.net.URL; -import java.net.URLConnection; -import java.util.Calendar; -import java.util.Collection; -import java.util.Date; -import java.util.List; -import java.util.concurrent.ConcurrentHashMap; -import java.util.logging.Logger; - +import com.earth2me.essentials.Essentials; +import com.onarandombox.MultiverseCore.MultiverseCore; +import fr.xephi.authme.api.API; +import fr.xephi.authme.api.NewAPI; +import fr.xephi.authme.cache.auth.PlayerAuth; +import fr.xephi.authme.cache.auth.PlayerCache; +import fr.xephi.authme.cache.backup.JsonCache; +import fr.xephi.authme.cache.limbo.LimboCache; +import fr.xephi.authme.cache.limbo.LimboPlayer; +import fr.xephi.authme.command.CommandHandler; +import fr.xephi.authme.converter.Converter; +import fr.xephi.authme.converter.ForceFlatToSqlite; +import fr.xephi.authme.datasource.*; +import fr.xephi.authme.hooks.BungeeCordMessage; +import fr.xephi.authme.hooks.EssSpawn; import fr.xephi.authme.listener.*; +import fr.xephi.authme.modules.ModuleManager; import fr.xephi.authme.permission.PermissionsManager; +import fr.xephi.authme.process.Management; +import fr.xephi.authme.settings.Messages; +import fr.xephi.authme.settings.OtherAccounts; +import fr.xephi.authme.settings.Settings; +import fr.xephi.authme.settings.Spawn; +import fr.xephi.authme.util.GeoLiteAPI; +import fr.xephi.authme.util.Utils; +import net.minelink.ctplus.CombatTagPlus; import org.apache.logging.log4j.LogManager; import org.bukkit.Bukkit; import org.bukkit.Location; @@ -27,99 +40,148 @@ import org.bukkit.scheduler.BukkitTask; import org.mcstats.Metrics; import org.mcstats.Metrics.Graph; -import com.earth2me.essentials.Essentials; -import com.onarandombox.MultiverseCore.MultiverseCore; - -import fr.xephi.authme.api.API; -import fr.xephi.authme.api.NewAPI; -import fr.xephi.authme.cache.auth.PlayerAuth; -import fr.xephi.authme.cache.auth.PlayerCache; -import fr.xephi.authme.cache.backup.JsonCache; -import fr.xephi.authme.cache.limbo.LimboCache; -import fr.xephi.authme.cache.limbo.LimboPlayer; -import fr.xephi.authme.command.CommandHandler; -import fr.xephi.authme.converter.Converter; -import fr.xephi.authme.converter.ForceFlatToSqlite; -import fr.xephi.authme.datasource.CacheDataSource; -import fr.xephi.authme.datasource.DataSource; -import fr.xephi.authme.datasource.DatabaseCalls; -import fr.xephi.authme.datasource.FlatFile; -import fr.xephi.authme.datasource.MySQL; -import fr.xephi.authme.datasource.SQLite; -import fr.xephi.authme.hooks.BungeeCordMessage; -import fr.xephi.authme.hooks.EssSpawn; -import fr.xephi.authme.modules.ModuleManager; -import fr.xephi.authme.process.Management; -import fr.xephi.authme.settings.Messages; -import fr.xephi.authme.settings.OtherAccounts; -import fr.xephi.authme.settings.Settings; -import fr.xephi.authme.settings.Spawn; -import fr.xephi.authme.util.Utils; -import net.minelink.ctplus.CombatTagPlus; +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.net.URL; +import java.net.URLConnection; +import java.util.Calendar; +import java.util.Collection; +import java.util.Date; +import java.util.List; +import java.util.concurrent.ConcurrentHashMap; +import java.util.logging.Logger; /** * The AuthMe main class. */ public class AuthMe extends JavaPlugin { - /** Defines the name of the plugin. */ - // TODO: Create a getter method for this constant, and make it private - public static final String PLUGIN_NAME = "AuthMeReloaded"; - /** Defines the current AuthMeReloaded version name. */ + /** + * Defines the name of the plugin. + */ + private static final String PLUGIN_NAME = "AuthMeReloaded"; + /** + * Defines the current AuthMeReloaded version name. + */ private static final String PLUGIN_VERSION_NAME = "5.1-SNAPSHOT"; - /** Defines the current AuthMeReloaded version code. */ - // Increase this number by one when an update is released + /** + * Defines the current AuthMeReloaded version code. + */ + // TODO: Increase this number by one when an update is release + // TODO: Increase the count via maven private static final int PLUGIN_VERSION_CODE = 100; private static AuthMe plugin; private static Server server; - private Logger authmeLogger; - - // TODO: Move this to a better place! -- timvisee - private CommandHandler commandHandler = null; - private PermissionsManager permsMan = null; public Management management; public NewAPI api; public SendMailSSL mail; - private Settings settings; - private Messages m; public DataManager dataManager; public DataSource database; - private JsonCache playerBackup; public OtherAccounts otherAccounts; public Location essentialsSpawn; - public boolean antibotMod = false; - public boolean delayedAntiBot = true; - // Hooks TODO: move into modules public Essentials ess; public MultiverseCore multiverse; public CombatTagPlus combatTagPlus; public AuthMeInventoryPacketAdapter inventoryProtector; - - // Module manager - private ModuleManager moduleManager; - - // TODO: Create Manager for fields below + // Random data maps and stuff + // TODO: Create Manager for this public ConcurrentHashMap sessions = new ConcurrentHashMap<>(); public ConcurrentHashMap captcha = new ConcurrentHashMap<>(); public ConcurrentHashMap cap = new ConcurrentHashMap<>(); public ConcurrentHashMap realIp = new ConcurrentHashMap<>(); - - // In case we need to cache PlayerAuths, prevent connection before it's done + // AntiBot Status + // TODO: Create Manager for this + public boolean antiBotMod = false; + public boolean delayedAntiBot = true; + private CommandHandler commandHandler = null; + private PermissionsManager permsMan = null; + private Settings settings; + private Messages messages; + private JsonCache playerBackup; + private ModuleManager moduleManager; + // If cache is enabled, prevent any connection before the players data caching is completed. + // TODO: Move somewhere private boolean canConnect = true; /** - * Method canConnect. - - * @return boolean */ + * Returns the plugin's instance. + * + * @return AuthMe + */ + public static AuthMe getInstance() { + return plugin; + } + + /** + * Get the plugin's name. + * + * @return Plugin name. + */ + public static String getPluginName() { + return PLUGIN_NAME; + } + + /** + * Get the current installed AuthMeReloaded version name. + * + * @return The version name of the currently installed AuthMeReloaded instance. + */ + public static String getVersionName() { + return PLUGIN_VERSION_NAME; + } + + /** + * Get the current installed AuthMeReloaded version code. + * + * @return The version code of the currently installed AuthMeReloaded instance. + */ + public static int getVersionCode() { + return PLUGIN_VERSION_CODE; + } + + /** + * Returns the plugin's Settings. + * + * @return Settings + */ + public Settings getSettings() { + return settings; + } + + /** + * Returns the Messages instance. + * + * @return Messages + */ + + public Messages getMessages() { + return messages; + } + + /** + * Set the Messages instance. + * + * @param m Messages + */ + public void setMessages(Messages m) { + this.messages = m; + } + + /** + * Returns if players are allowed to join the server. + * + * @return boolean + */ public boolean canConnect() { return canConnect; } /** - * Method setCanConnect. + * Define if players are allowed to join the server. + * * @param canConnect boolean */ public void setCanConnect(boolean canConnect) { @@ -127,69 +189,246 @@ public class AuthMe extends JavaPlugin { } /** - * Method getInstance. - - * @return AuthMe */ - public static AuthMe getInstance() { - return plugin; - } - - /** - * Method getSettings. - - * @return Settings */ - public Settings getSettings() { - return settings; - } - - /** - * Method setMessages. - * @param m Messages - */ - public void setMessages(Messages m) { - this.m = m; - } - - /** - * Method getMessages. - - * @return Messages */ - public Messages getMessages() { - return m; - } - - /** - * Method onEnable. + * Method called when the server enables the plugin. + * * @see org.bukkit.plugin.Plugin#onEnable() */ @Override public void onEnable() { - // Set the Instance + // Set various instances server = getServer(); - authmeLogger = Logger.getLogger("AuthMe"); plugin = this; // Set up the permissions manager setupPermissionsManager(); // Set up and initialize the command handler + setupCommandHandler(); + + // Set up the module manager + setupModuleManager(); + + // Load settings and custom configurations, if it fails, stop the server due to security reasons. + if (loadSettings()) { + server.shutdown(); + setEnabled(false); + return; + } + + // Setup otherAccounts file + this.otherAccounts = OtherAccounts.getInstance(); + + // Setup messages + this.messages = Messages.getInstance(); + + // Set up Metrics + setupMetrics(); + + // Set console filter + setupConsoleFilter(); + + // AntiBot delay + setupAntiBotDelay(); + + // Download and load GeoIp.dat file if absent + GeoLiteAPI.isDataAvailable(); + + // Set up the mail API + setupMailApi(); + + // Hooks + // Check Combat Tag Plus Version + checkCombatTagPlus(); + + // Check Multiverse + checkMultiverse(); + + // Check Essentials + checkEssentials(); + + // Check if the protocollib is available. If so we could listen for + // inventory protection + checkProtocolLib(); + // End of Hooks + + // Do a backup on start + new PerformBackup(plugin).doBackup(PerformBackup.BackupCause.START); + + // Connect to the database and setup tables + try { + setupDatabase(); + } catch (Exception e) { + ConsoleLogger.writeStackTrace(e); + ConsoleLogger.showError(e.getMessage()); + ConsoleLogger.showError("Fatal error occurred during database connection! Authme initialization ABORTED!"); + stopOrUnload(); + return; + } + + // Setup the inventory backup + playerBackup = new JsonCache(); + + // Set the DataManager + dataManager = new DataManager(this); + + // Set up the new API + setupApi(); + + // Set up the management + management = new Management(this); + + // Set up the Bungeecord hook + setupBungeecordHook(); + + // Reload support hook + reloadSupportHook(); + + // Register event listeners + registerEventListeners(); + + // Purge on start if enabled + autoPurge(); + + // Start Email recall task if needed + recallEmail(); + + // Show settings warnings + showSettingsWarnings(); + + // Sponsor messages + ConsoleLogger.info("AuthMe hooks perfectly with the VeryGames server hosting!"); + ConsoleLogger.info("Development builds are available on our jenkins, thanks to f14stelt."); + ConsoleLogger.info("Do you want a good game server? Look at our sponsor GameHosting.it leader in Italy as Game Server Provider!"); + + // Successful message + ConsoleLogger.info("AuthMe " + this.getDescription().getVersion() + " correctly enabled!"); + } + + /** + * Set up the module manager. + */ + private void setupModuleManager() { + // TODO: Clean this up! + // TODO: split the plugin in more modules + // TODO: log number of loaded modules + + // Define the module manager instance + moduleManager = new ModuleManager(this); + + // Load the modules + // int loaded = moduleManager.loadModules(); + } + + /** + * Set up the mail API, if enabled. + */ + private void setupMailApi() { + // Make sure the mail API is enabled + if (Settings.getmailAccount.isEmpty() || Settings.getmailPassword.isEmpty()) { + return; + } + + // Set up the mail API + this.mail = new SendMailSSL(this); + } + + /** + * Show the settings warnings, for various risky settings. + */ + private void showSettingsWarnings() { + // Force single session disabled + if (!Settings.isForceSingleSessionEnabled) { + ConsoleLogger.showError("WARNING!!! By disabling ForceSingleSession, your server protection is inadequate!"); + } + + // Session timeout disabled + if (Settings.getSessionTimeout == 0 && Settings.isSessionsEnabled) { + ConsoleLogger.showError("WARNING!!! You set session timeout to 0, this may cause security issues!"); + } + } + + /** + * Register all event listeners. + */ + private void registerEventListeners() { + // Get the plugin manager instance + PluginManager pluginManager = server.getPluginManager(); + + // Register event listeners + pluginManager.registerEvents(new AuthMePlayerListener(this), this); + pluginManager.registerEvents(new AuthMeBlockListener(this), this); + pluginManager.registerEvents(new AuthMeEntityListener(this), this); + pluginManager.registerEvents(new AuthMeServerListener(this), this); + + // Try to register 1.6 player listeners + try { + Class.forName("org.bukkit.event.player.PlayerEditBookEvent"); + pluginManager.registerEvents(new AuthMePlayerListener16(this), this); + } catch (ClassNotFoundException ignore) { + } + + // Try to register 1.8 player listeners + try { + Class.forName("org.bukkit.event.player.PlayerInteractAtEntityEvent"); + pluginManager.registerEvents(new AuthMePlayerListener18(this), this); + } catch (ClassNotFoundException ignore) { + } + } + + private void reloadSupportHook() { + if (database != null) { + int playersOnline = Utils.getOnlinePlayers().size(); + if (playersOnline < 1) { + database.purgeLogged(); + } else if (Settings.reloadSupport) { + for (PlayerAuth auth : database.getLoggedPlayers()) { + if (auth == null) { + continue; + } + auth.setLastLogin(new Date().getTime()); + database.updateSession(auth); + PlayerCache.getInstance().addPlayer(auth); + } + } + } + } + + /** + * Set up the Bungecoord hook. + */ + private void setupBungeecordHook() { + if (Settings.bungee) { + Bukkit.getMessenger().registerOutgoingPluginChannel(this, "BungeeCord"); + Bukkit.getMessenger().registerIncomingPluginChannel(this, "BungeeCord", new BungeeCordMessage(this)); + } + } + + /** + * Set up the API. This sets up the new and the old API. + */ + @SuppressWarnings("deprecation") + private void setupApi() { + // Set up the API + api = new NewAPI(this); + + // Setup the old deprecated API + new API(this); + } + + /** + * Set up the command handler. + */ + private void setupCommandHandler() { this.commandHandler = new CommandHandler(false); this.commandHandler.init(); + } - // TODO: split the plugin in more modules - moduleManager = new ModuleManager(this); - @SuppressWarnings("unused") - int loaded = moduleManager.loadModules(); - - // TODO: remove vault as hard dependency - PluginManager pm = server.getPluginManager(); - - // Setup the Logger - if (authmeLogger == null) - authmeLogger = this.getLogger(); - else authmeLogger.setParent(this.getLogger()); - - // Load settings and custom configurations + /** + * Load the plugin's settings. + * + * @return True on success, false on failure. + */ + private boolean loadSettings() { // TODO: new configuration style (more files) try { settings = new Settings(this); @@ -198,16 +437,48 @@ public class AuthMe extends JavaPlugin { ConsoleLogger.writeStackTrace(e); ConsoleLogger.showError("Can't load the configuration file... Something went wrong, to avoid security issues the server will shutdown!"); server.shutdown(); - return; + return true; } + return false; + } - // Setup otherAccounts file - otherAccounts = OtherAccounts.getInstance(); + /** + * Set up the antibot delay. + */ + private void setupAntiBotDelay() { + if (Settings.enableAntiBot) { + Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable() { + @Override + public void run() { + delayedAntiBot = false; + } + }, 2400); + } + } - // Setup messages - m = Messages.getInstance(); + /** + * Set up the console filter. + */ + private void setupConsoleFilter() { + if (Settings.removePassword) { + ConsoleFilter filter = new ConsoleFilter(); + ConsoleLogger.getLogger().setFilter(filter); + Bukkit.getLogger().setFilter(filter); + Logger.getLogger("Minecraft").setFilter(filter); + // Set Log4J Filter + try { + Class.forName("org.apache.logging.log4j.core.Filter"); + setLog4JFilter(); + } catch (ClassNotFoundException | NoClassDefFoundError e) { + ConsoleLogger.info("You're using Minecraft 1.6.x or older, Log4J support will be disabled"); + } + } + } - // Start the metrics service + /** + * Set up Metrics. + */ + private void setupMetrics() { try { Metrics metrics = new Metrics(this); Graph messagesLanguage = metrics.createGraph("Messages language"); @@ -238,155 +509,14 @@ public class AuthMe extends JavaPlugin { ConsoleLogger.writeStackTrace(e); ConsoleLogger.showError("Can't start Metrics! The plugin will work anyway..."); } - - // Set Console Filter - if (Settings.removePassword) { - ConsoleFilter filter = new ConsoleFilter(); - this.getLogger().setFilter(filter); - Bukkit.getLogger().setFilter(filter); - Logger.getLogger("Minecraft").setFilter(filter); - authmeLogger.setFilter(filter); - // Set Log4J Filter - try { - Class.forName("org.apache.logging.log4j.core.Filter"); - setLog4JFilter(); - } catch (ClassNotFoundException | NoClassDefFoundError e) { - ConsoleLogger.info("You're using Minecraft 1.6.x or older, Log4J support will be disabled"); - } - } - - // AntiBot delay - if (Settings.enableAntiBot) { - Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable() { - - @Override - public void run() { - delayedAntiBot = false; - } - }, 2400); - } - - // Download GeoIp.dat file - Utils.checkGeoIP(); - - // Load MailApi if needed - if (!Settings.getmailAccount.isEmpty() && !Settings.getmailPassword.isEmpty()) { - mail = new SendMailSSL(this); - } - - // Check Combat Tag Plus Version - checkCombatTagPlus(); - - // Check Multiverse - checkMultiverse(); - - // Check Essentials - checkEssentials(); - - // Check if the protocollib is available. If so we could listen for - // inventory protection - checkProtocolLib(); - - // Do backup on start if enabled - if (Settings.isBackupActivated && Settings.isBackupOnStart) { - // Do backup and check return value! - if (new PerformBackup(this).doBackup()) { - ConsoleLogger.info("Backup performed correctly"); - } else { - ConsoleLogger.showError("Error while performing the backup!"); - } - } - - // Connect to the database and setup tables - try { - setupDatabase(); - } catch (Exception e) { - ConsoleLogger.writeStackTrace(e); - ConsoleLogger.showError(e.getMessage()); - ConsoleLogger.showError("Fatal error occurred during database connection! Authme initialization ABORTED!"); - stopOrUnload(); - return; - } - - // Setup the inventory backup - playerBackup = new JsonCache(); - - // Set the DataManager - dataManager = new DataManager(this); - - // Setup the new API - api = new NewAPI(this); - // Setup the old deprecated API - new API(this); - - // Setup Management - management = new Management(this); - - // Bungeecord hook - if (Settings.bungee) { - Bukkit.getMessenger().registerOutgoingPluginChannel(this, "BungeeCord"); - Bukkit.getMessenger().registerIncomingPluginChannel(this, "BungeeCord", new BungeeCordMessage(this)); - } - - // Reload support hook - if (database != null) { - int playersOnline = Utils.getOnlinePlayers().size(); - if (playersOnline < 1) { - database.purgeLogged(); - } else if (Settings.reloadSupport) { - for (PlayerAuth auth : database.getLoggedPlayers()) { - if (auth == null) - continue; - auth.setLastLogin(new Date().getTime()); - database.updateSession(auth); - PlayerCache.getInstance().addPlayer(auth); - } - } - } - - // Register events - pm.registerEvents(new AuthMePlayerListener(this), this); - // Try to register 1.6 player listeners - try { - Class.forName("org.bukkit.event.player.PlayerEditBookEvent"); - pm.registerEvents(new AuthMePlayerListener16(this), this); - } catch (ClassNotFoundException ignore) { - } - // Try to register 1.8 player listeners - try { - Class.forName("org.bukkit.event.player.PlayerInteractAtEntityEvent"); - pm.registerEvents(new AuthMePlayerListener18(this), this); - } catch (ClassNotFoundException ignore) { - } - pm.registerEvents(new AuthMeBlockListener(this), this); - pm.registerEvents(new AuthMeEntityListener(this), this); - pm.registerEvents(new AuthMeServerListener(this), this); - - // Purge on start if enabled - autoPurge(); - - // Start Email recall task if needed - recallEmail(); - - // Configuration Security Warnings - if (!Settings.isForceSingleSessionEnabled) { - ConsoleLogger.showError("WARNING!!! By disabling ForceSingleSession, your server protection is inadequate!"); - } - if (Settings.getSessionTimeout == 0 && Settings.isSessionsEnabled) { - ConsoleLogger.showError("WARNING!!! You set session timeout to 0, this may cause security issues!"); - } - - // Sponsor messages - ConsoleLogger.info("AuthMe hooks perfectly with the VERYGAMES server hosting!"); - ConsoleLogger.info("Development builds are available on our jenkins, thanks to f14stelt."); - ConsoleLogger.info("Do you want a good gameserver? Look at our sponsor GameHosting.it leader in Italy as Game Server Provider!"); - - // Successful message - ConsoleLogger.info("AuthMe " + this.getDescription().getVersion() + " correctly enabled!"); } + // Show the exception message and stop/unload the server/plugin as defined + // in the configuration + /** * Method onDisable. + * * @see org.bukkit.plugin.Plugin#onDisable() */ @Override @@ -400,12 +530,7 @@ public class AuthMe extends JavaPlugin { } // Do backup on stop if enabled - if (Settings.isBackupActivated && Settings.isBackupOnStop) { - boolean Backup = new PerformBackup(this).doBackup(); - if (Backup) - ConsoleLogger.info("Backup performed correctly."); - else ConsoleLogger.showError("Error while performing the backup!"); - } + new PerformBackup(plugin).doBackup(PerformBackup.BackupCause.STOP); // Unload modules moduleManager.unloadModules(); @@ -419,6 +544,8 @@ public class AuthMe extends JavaPlugin { ConsoleLogger.info("AuthMe " + this.getDescription().getVersion() + " disabled!"); } + // Initialize and setup the database + // Stop/unload the server/plugin as defined in the configuration public void stopOrUnload() { if (Settings.isStopEnabled) { @@ -429,22 +556,9 @@ public class AuthMe extends JavaPlugin { } } - // Show the exception message and stop/unload the server/plugin as defined - // in the configuration - /** - * Method stopOrUnload. - * @param e Exception - */ - public void stopOrUnload(Exception e) { - ConsoleLogger.showError(e.getMessage()); - stopOrUnload(); - } - - // Initialize and setup the database /** * Method setupDatabase. - - * @throws Exception */ + */ public void setupDatabase() throws Exception { if (database != null) database.close(); @@ -584,49 +698,6 @@ public class AuthMe extends JavaPlugin { } } - /** - * Check if a player/command sender have a permission - * - * @deprecated Deprecated since v5.1. Use the permissions manager instead! See: getPermissionsManager() - * - * @param player - * @param perm - - - * @return boolean */ - public boolean authmePermissible(Player player, String perm) { - // New code: - return getPermissionsManager().hasPermission(player, perm); - - // Legacy code: - /*if (player.hasPermission(perm)) { - return true; - } else if (permission != null) { - return permission.playerHas(player, perm); - } - return false;*/ - } - - /** - * @deprecated Deprecated since v5.1. Use the permissions manager instead! See: getPermissionsManager() - * - * @param sender - * @param perm - - - * @return boolean */ - public boolean authmePermissible(CommandSender sender, String perm) { - // Handle players with the permissions manager - if(sender instanceof Player) { - // Get the player instance - Player player = (Player) sender; - - // Check whether the player has permission, return the result - return getPermissionsManager().hasPermission(player, perm); - } - return false; - } - // Save Player Data public void savePlayer(Player player) { if ((Utils.isNPC(player)) || (Utils.isUnrestricted(player))) { @@ -754,12 +825,12 @@ public class AuthMe extends JavaPlugin { } public void switchAntiBotMod(boolean mode) { - this.antibotMod = mode; + this.antiBotMod = mode; Settings.switchAntiBotMod(mode); } public boolean getAntiBotModMode() { - return this.antibotMod; + return this.antiBotMod; } private void recallEmail() { @@ -776,7 +847,7 @@ public class AuthMe extends JavaPlugin { if (PlayerCache.getInstance().isAuthenticated(name)) { String email = database.getAuth(name).getEmail(); if (email == null || email.isEmpty() || email.equalsIgnoreCase("your@email.com")) - m.send(player, "add_email"); + messages.send(player, "add_email"); } } } @@ -784,7 +855,6 @@ public class AuthMe extends JavaPlugin { }, 1, 1200 * Settings.delayRecall); } - public String replaceAllInfos(String message, Player player) { int playersOnline = Utils.getOnlinePlayers().size(); message = message.replace("&", "\u00a7"); @@ -796,11 +866,10 @@ public class AuthMe extends JavaPlugin { message = message.replace("{WORLD}", player.getWorld().getName()); message = message.replace("{SERVER}", server.getServerName()); message = message.replace("{VERSION}", server.getBukkitVersion()); - message = message.replace("{COUNTRY}", Utils.getCountryName(getIP(player))); + message = message.replace("{COUNTRY}", GeoLiteAPI.getCountryName(getIP(player))); return message; } - public String getIP(Player player) { String name = player.getName().toLowerCase(); String ip = player.getAddress().getAddress().getHostAddress(); @@ -814,7 +883,6 @@ public class AuthMe extends JavaPlugin { return ip; } - public boolean isLoggedIp(String name, String ip) { int count = 0; for (Player player : Utils.getOnlinePlayers()) { @@ -824,7 +892,6 @@ public class AuthMe extends JavaPlugin { return count >= Settings.getMaxLoginPerIp; } - public boolean hasJoinedIp(String name, String ip) { int count = 0; for (Player player : Utils.getOnlinePlayers()) { @@ -834,7 +901,6 @@ public class AuthMe extends JavaPlugin { return count >= Settings.getMaxJoinPerIp; } - public ModuleManager getModuleManager() { return moduleManager; } @@ -843,7 +909,6 @@ public class AuthMe extends JavaPlugin { * Gets a player's real IP through VeryGames method. * * @param player the player to process - * * @return the real IP of the player */ @Deprecated @@ -864,19 +929,6 @@ public class AuthMe extends JavaPlugin { return realIP; } - - @Deprecated - public String getCountryCode(String ip) { - return Utils.getCountryCode(ip); - } - - - @Deprecated - public String getCountryName(String ip) { - return Utils.getCountryName(ip); - } - - public CommandHandler getCommandHandler() { return this.commandHandler; } @@ -884,20 +936,15 @@ public class AuthMe extends JavaPlugin { /** * Handle Bukkit commands. * - * @param sender - * The command sender (Bukkit). - * @param cmd - * The command (Bukkit). - * @param commandLabel - * The command label (Bukkit). - * @param args - * The command arguments (Bukkit). - * - * @return True if the command was executed, false otherwise. + * @param sender The command sender (Bukkit). + * @param cmd The command (Bukkit). + * @param commandLabel The command label (Bukkit). + * @param args The command arguments (Bukkit). + * @return True if the command was executed, false otherwise. */ @Override public boolean onCommand(CommandSender sender, Command cmd, - String commandLabel, String[] args) { + String commandLabel, String[] args) { // Get the command handler, and make sure it's valid CommandHandler commandHandler = this.getCommandHandler(); if (commandHandler == null) @@ -908,37 +955,20 @@ public class AuthMe extends JavaPlugin { } /** - * Get the current installed AuthMeReloaded version name. - * - * @return The version name of the currently installed AuthMeReloaded - * instance. + * Returns the management instance. */ - public static String getVersionName() { - return PLUGIN_VERSION_NAME; - } - - /** - * Get the current installed AuthMeReloaded version code. - * - * @return The version code of the currently installed AuthMeReloaded - * instance. - */ - public static int getVersionCode() { - return PLUGIN_VERSION_CODE; - } - - /** Returns the management instance. */ public Management getManagement() { return management; } /** - * Returns the server instance running this plugin. Use this method in favor of - * {@link AuthMe#getServer()} for testability purposes. + * Returns the server instance running this plugin. Use this method in favor of {@link + * AuthMe#getServer()} for testability purposes. * * @return the server instance */ public Server getGameServer() { return super.getServer(); } + } diff --git a/src/main/java/fr/xephi/authme/ConsoleFilter.java b/src/main/java/fr/xephi/authme/ConsoleFilter.java index 668ff2066..09da4983a 100644 --- a/src/main/java/fr/xephi/authme/ConsoleFilter.java +++ b/src/main/java/fr/xephi/authme/ConsoleFilter.java @@ -4,6 +4,7 @@ import java.util.logging.Filter; import java.util.logging.LogRecord; /** + * Console filter Class * * @author Xephi59 * @version $Revision: 1.0 $ @@ -15,10 +16,10 @@ public class ConsoleFilter implements Filter { /** * Method isLoggable. + * * @param record LogRecord - - - * @return boolean * @see java.util.logging.Filter#isLoggable(LogRecord) */ + * @return boolean * @see java.util.logging.Filter#isLoggable(LogRecord) + */ @Override public boolean isLoggable(LogRecord record) { try { diff --git a/src/main/java/fr/xephi/authme/ConsoleLogger.java b/src/main/java/fr/xephi/authme/ConsoleLogger.java index 1e58e9138..0bbacbfce 100644 --- a/src/main/java/fr/xephi/authme/ConsoleLogger.java +++ b/src/main/java/fr/xephi/authme/ConsoleLogger.java @@ -1,5 +1,9 @@ package fr.xephi.authme; +import com.google.common.base.Throwables; +import fr.xephi.authme.settings.Settings; +import fr.xephi.authme.util.StringUtils; + import java.io.IOException; import java.nio.file.Files; import java.nio.file.StandardOpenOption; @@ -8,12 +12,8 @@ import java.text.SimpleDateFormat; import java.util.Date; import java.util.logging.Logger; -import com.google.common.base.Throwables; - -import fr.xephi.authme.api.NewAPI; -import fr.xephi.authme.settings.Settings; - /** + * The plugin's static logger. */ public class ConsoleLogger { @@ -21,42 +21,52 @@ public class ConsoleLogger { private static final DateFormat df = new SimpleDateFormat("[MM-dd HH:mm:ss]"); /** - * Method info. + * Returns the plugin's logger. + * + * @return Logger + */ + public static Logger getLogger() { + return log; + } + + /** + * Print an info message. + * * @param message String */ public static void info(String message) { - log.info("[AuthMe] " + message); - if (Settings.useLogging) { - String dateTime; - synchronized (df) { - dateTime = df.format(new Date()); - } - writeLog(dateTime + " " + message); + log.info(message); + if (!Settings.useLogging) { + return; } + writeLog("" + message); } /** - * Method showError. + * Print an error message. + * * @param message String */ public static void showError(String message) { - log.warning("[AuthMe] " + message); - if (Settings.useLogging) { - String dateTime; - synchronized (df) { - dateTime = df.format(new Date()); - } - writeLog(dateTime + " ERROR: " + message); + log.warning(message); + if (!Settings.useLogging) { + return; } + writeLog("ERROR: " + message); } /** - * Method writeLog. + * Write a message into the log file with a TimeStamp. + * * @param message String */ - public static void writeLog(String message) { + private static void writeLog(String message) { + String dateTime; + synchronized (df) { + dateTime = df.format(new Date()); + } try { - Files.write(Settings.LOG_FILE.toPath(), (message + NewAPI.newline).getBytes(), + Files.write(Settings.LOG_FILE.toPath(), (dateTime + ": " + message + StringUtils.newline).getBytes(), StandardOpenOption.APPEND, StandardOpenOption.CREATE); } catch (IOException ignored) { @@ -64,16 +74,14 @@ public class ConsoleLogger { } /** - * Method writeStackTrace. + * Write a StackTrace into the log. + * * @param ex Exception */ public static void writeStackTrace(Exception ex) { - if (Settings.useLogging) { - String dateTime; - synchronized (df) { - dateTime = df.format(new Date()); - } - writeLog(dateTime + " " + Throwables.getStackTraceAsString(ex)); + if (!Settings.useLogging) { + return; } + writeLog("" + Throwables.getStackTraceAsString(ex)); } } diff --git a/src/main/java/fr/xephi/authme/DataManager.java b/src/main/java/fr/xephi/authme/DataManager.java index d4688e5c5..58bdca4dc 100644 --- a/src/main/java/fr/xephi/authme/DataManager.java +++ b/src/main/java/fr/xephi/authme/DataManager.java @@ -1,5 +1,12 @@ package fr.xephi.authme; +import fr.xephi.authme.permission.PermissionsManager; +import fr.xephi.authme.settings.Settings; +import fr.xephi.authme.util.Utils; +import org.bukkit.Bukkit; +import org.bukkit.OfflinePlayer; +import org.bukkit.entity.Player; + import java.io.File; import java.util.List; import java.util.concurrent.Callable; @@ -7,14 +14,6 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.Future; -import fr.xephi.authme.permission.PermissionsManager; -import org.bukkit.Bukkit; -import org.bukkit.OfflinePlayer; -import org.bukkit.entity.Player; - -import fr.xephi.authme.settings.Settings; -import fr.xephi.authme.util.Utils; - /** */ public class DataManager { @@ -23,6 +22,7 @@ public class DataManager { /** * Constructor for DataManager. + * * @param plugin AuthMe */ public DataManager(AuthMe plugin) { @@ -34,9 +34,10 @@ public class DataManager { /** * Method getOfflinePlayer. + * * @param name String - - * @return OfflinePlayer */ + * @return OfflinePlayer + */ public synchronized OfflinePlayer getOfflinePlayer(final String name) { ExecutorService executor = Executors.newSingleThreadExecutor(); Future result = executor.submit(new Callable() { @@ -65,6 +66,7 @@ public class DataManager { /** * Method purgeAntiXray. + * * @param cleared List */ public synchronized void purgeAntiXray(List cleared) { @@ -88,6 +90,7 @@ public class DataManager { /** * Method purgeLimitedCreative. + * * @param cleared List */ public synchronized void purgeLimitedCreative(List cleared) { @@ -121,6 +124,7 @@ public class DataManager { /** * Method purgeDat. + * * @param cleared List */ public synchronized void purgeDat(List cleared) { @@ -136,7 +140,7 @@ public class DataManager { File playerFile = new File(plugin.getServer().getWorldContainer() + File.separator + Settings.defaultWorld + File.separator + "players" + File.separator + player.getUniqueId() + ".dat"); playerFile.delete(); i++; - } catch(Exception ignore) { + } catch (Exception ignore) { File playerFile = new File(plugin.getServer().getWorldContainer() + File.separator + Settings.defaultWorld + File.separator + "players" + File.separator + player.getName() + ".dat"); if (playerFile.exists()) { playerFile.delete(); @@ -151,6 +155,7 @@ public class DataManager { /** * Method purgeEssentials. + * * @param cleared List */ @SuppressWarnings("deprecation") @@ -158,7 +163,7 @@ public class DataManager { int i = 0; for (String name : cleared) { try { - File playerFile = new File(plugin.ess.getDataFolder() + File.separator + "userdata" + File.separator + plugin.getServer().getOfflinePlayer(name).getUniqueId() + ".yml"); + File playerFile = new File(plugin.ess.getDataFolder() + File.separator + "userdata" + File.separator + plugin.getServer().getOfflinePlayer(name).getUniqueId() + ".yml"); playerFile.delete(); i++; } catch (Exception e) { @@ -173,13 +178,14 @@ public class DataManager { } // TODO: What is this method for? Is it correct? + /** * @param cleared Cleared players. */ public synchronized void purgePermissions(List cleared) { // Get the permissions manager, and make sure it's valid PermissionsManager permsMan = this.plugin.getPermissionsManager(); - if(permsMan == null) + if (permsMan == null) ConsoleLogger.showError("Unable to access permissions manager instance!"); assert permsMan != null; @@ -188,7 +194,7 @@ public class DataManager { try { permsMan.removeAllGroups(this.getOnlinePlayerLower(name.toLowerCase())); i++; - } catch(Exception e) { + } catch (Exception e) { } } ConsoleLogger.info("AutoPurgeDatabase : Removed " + i + " permissions"); @@ -209,10 +215,11 @@ public class DataManager { /** * Method isOnline. + * * @param player Player - * @param name String - - * @return boolean */ + * @param name String + * @return boolean + */ public boolean isOnline(Player player, final String name) { if (player.isOnline()) return true; @@ -239,9 +246,10 @@ public class DataManager { /** * Method getOnlinePlayerLower. + * * @param name String - - * @return Player */ + * @return Player + */ public Player getOnlinePlayerLower(String name) { name = name.toLowerCase(); for (Player player : Utils.getOnlinePlayers()) { diff --git a/src/main/java/fr/xephi/authme/ImageGenerator.java b/src/main/java/fr/xephi/authme/ImageGenerator.java index 2b6a187e3..bdcefa44a 100644 --- a/src/main/java/fr/xephi/authme/ImageGenerator.java +++ b/src/main/java/fr/xephi/authme/ImageGenerator.java @@ -1,9 +1,6 @@ package fr.xephi.authme; -import java.awt.Color; -import java.awt.Font; -import java.awt.GradientPaint; -import java.awt.Graphics2D; +import java.awt.*; import java.awt.image.BufferedImage; /** @@ -11,8 +8,10 @@ import java.awt.image.BufferedImage; public class ImageGenerator { private String pass; + /** * Constructor for ImageGenerator. + * * @param pass String */ public ImageGenerator(String pass) { @@ -21,8 +20,9 @@ public class ImageGenerator { /** * Method generateImage. - - * @return BufferedImage */ + * + * @return BufferedImage + */ public BufferedImage generateImage() { BufferedImage image = new BufferedImage(200, 60, BufferedImage.TYPE_BYTE_INDEXED); Graphics2D graphics = image.createGraphics(); diff --git a/src/main/java/fr/xephi/authme/Log4JFilter.java b/src/main/java/fr/xephi/authme/Log4JFilter.java index 917a75369..0db37bb74 100644 --- a/src/main/java/fr/xephi/authme/Log4JFilter.java +++ b/src/main/java/fr/xephi/authme/Log4JFilter.java @@ -1,56 +1,95 @@ package fr.xephi.authme; +import fr.xephi.authme.util.StringUtils; import org.apache.logging.log4j.Level; import org.apache.logging.log4j.Marker; import org.apache.logging.log4j.core.LogEvent; import org.apache.logging.log4j.core.Logger; import org.apache.logging.log4j.message.Message; -import fr.xephi.authme.util.StringUtils; - /** * Implements a filter for Log4j to skip sensitive AuthMe commands. + * * @author Xephi59 * @version $Revision: 1.0 $ */ public class Log4JFilter implements org.apache.logging.log4j.core.Filter { - - /** List of commands (lower-case) to skip. */ - private static final String[] COMMANDS_TO_SKIP = { "/login ", "/l ", "/reg ", "/changepassword ", - "/unregister ", "/authme register ", "/authme changepassword ", "/authme reg ", "/authme cp ", - "/register " }; - /** Constructor. */ + /** + * List of commands (lower-case) to skip. + */ + private static final String[] COMMANDS_TO_SKIP = {"/login ", "/l ", "/reg ", "/changepassword ", + "/unregister ", "/authme register ", "/authme changepassword ", "/authme reg ", "/authme cp ", + "/register "}; + + /** + * Constructor. + */ public Log4JFilter() { } + /** + * Validates a Message instance and returns the {@link Result} value + * depending depending on whether the message contains sensitive AuthMe + * data. + * + * @param message the Message object to verify + * @return the Result value + */ + private static Result validateMessage(Message message) { + if (message == null) { + return Result.NEUTRAL; + } + return validateMessage(message.getFormattedMessage()); + } + + /** + * Validates a message and returns the {@link Result} value depending + * depending on whether the message contains sensitive AuthMe data. + * + * @param message the message to verify + * @return the Result value + */ + private static Result validateMessage(String message) { + if (message == null) { + return Result.NEUTRAL; + } + + String lowerMessage = message.toLowerCase(); + if (lowerMessage.contains("issued server command:") + && StringUtils.containsAny(lowerMessage, COMMANDS_TO_SKIP)) { + return Result.DENY; + } + return Result.NEUTRAL; + } + @Override public Result filter(LogEvent record) { - if (record == null) { - return Result.NEUTRAL; - } - return validateMessage(record.getMessage()); + if (record == null) { + return Result.NEUTRAL; + } + return validateMessage(record.getMessage()); } @Override public Result filter(Logger arg0, Level arg1, Marker arg2, String message, - Object... arg4) { - return validateMessage(message); + Object... arg4) { + return validateMessage(message); } @Override public Result filter(Logger arg0, Level arg1, Marker arg2, Object message, - Throwable arg4) { - if (message == null) { - return Result.NEUTRAL; - } - return validateMessage(message.toString()); + Throwable arg4) { + if (message == null) { + return Result.NEUTRAL; + } + return validateMessage(message.toString()); } @Override public Result filter(Logger arg0, Level arg1, Marker arg2, Message message, - Throwable arg4) { - return validateMessage(message); + Throwable arg4) { + return validateMessage(message); } @Override @@ -63,41 +102,4 @@ public class Log4JFilter implements org.apache.logging.log4j.core.Filter { return Result.NEUTRAL; } - /** - * Validates a Message instance and returns the {@link Result} value - * depending depending on whether the message contains sensitive AuthMe - * data. - * - * @param message the Message object to verify - * - * @return the Result value - */ - private static Result validateMessage(Message message) { - if (message == null) { - return Result.NEUTRAL; - } - return validateMessage(message.getFormattedMessage()); - } - - /** - * Validates a message and returns the {@link Result} value depending - * depending on whether the message contains sensitive AuthMe data. - * - * @param message the message to verify - * - * @return the Result value - */ - private static Result validateMessage(String message) { - if (message == null) { - return Result.NEUTRAL; - } - - String lowerMessage = message.toLowerCase(); - if (lowerMessage.contains("issued server command:") - && StringUtils.containsAny(lowerMessage, COMMANDS_TO_SKIP)) { - return Result.DENY; - } - return Result.NEUTRAL; - } - } diff --git a/src/main/java/fr/xephi/authme/PerformBackup.java b/src/main/java/fr/xephi/authme/PerformBackup.java index 355c16497..92194949f 100644 --- a/src/main/java/fr/xephi/authme/PerformBackup.java +++ b/src/main/java/fr/xephi/authme/PerformBackup.java @@ -1,44 +1,66 @@ package fr.xephi.authme; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.text.SimpleDateFormat; -import java.util.Date; - import fr.xephi.authme.settings.Settings; +import java.io.*; +import java.text.SimpleDateFormat; +import java.util.Date; + /** + * The backup management class * * @author stefano * @version $Revision: 1.0 $ */ public class PerformBackup { + SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd_HH-mm"); + String dateString = format.format(new Date()); private String dbName = Settings.getMySQLDatabase; private String dbUserName = Settings.getMySQLUsername; private String dbPassword = Settings.getMySQLPassword; private String tblname = Settings.getMySQLTablename; - SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd_HH-mm"); - String dateString = format.format(new Date()); private String path = AuthMe.getInstance().getDataFolder() + File.separator + "backups" + File.separator + "backup" + dateString; private AuthMe instance; /** * Constructor for PerformBackup. + * * @param instance AuthMe */ public PerformBackup(AuthMe instance) { this.setInstance(instance); } + /** + * + */ + public void doBackup(BackupCause cause) { + // Check whether a backup should be made at the specified point in time + switch (cause) { + case START: + if (!Settings.isBackupOnStart) + return; + case STOP: + if (!Settings.isBackupOnStop) + return; + case COMMAND: + case OTHER: + } + + // Do backup and check return value! + if (doBackup()) { + ConsoleLogger.info("A backup has been performed successfully"); + } else { + ConsoleLogger.showError("Error while performing a backup!"); + } + } + /** * Method doBackup. - - * @return boolean */ + * + * @return boolean + */ public boolean doBackup() { switch (Settings.getDataSource) { @@ -55,8 +77,9 @@ public class PerformBackup { /** * Method MySqlBackup. - - * @return boolean */ + * + * @return boolean + */ private boolean MySqlBackup() { File dirBackup = new File(AuthMe.getInstance().getDataFolder() + "/backups"); @@ -98,9 +121,10 @@ public class PerformBackup { /** * Method FileBackup. + * * @param backend String - - * @return boolean */ + * @return boolean + */ private boolean FileBackup(String backend) { File dirBackup = new File(AuthMe.getInstance().getDataFolder() + "/backups"); @@ -117,15 +141,12 @@ public class PerformBackup { return false; } - /* - * Check if we are under Windows and correct location of mysqldump.exe - * otherwise return error. - */ /** * Method checkWindows. + * * @param windowsPath String - - * @return boolean */ + * @return boolean + */ private boolean checkWindows(String windowsPath) { String isWin = System.getProperty("os.name").toLowerCase(); if (isWin.indexOf("win") >= 0) { @@ -139,14 +160,17 @@ public class PerformBackup { } /* - * Copyr src bytefile into dst file + * Check if we are under Windows and correct location of mysqldump.exe + * otherwise return error. */ + /** * Method copy. + * * @param src File * @param dst File - - * @throws IOException */ + * @throws IOException + */ void copy(File src, File dst) throws IOException { InputStream in = new FileInputStream(src); OutputStream out = new FileOutputStream(dst); @@ -161,8 +185,22 @@ public class PerformBackup { out.close(); } + /* + * Copyr src bytefile into dst file + */ + + /** + * Method getInstance. + * + * @return AuthMe + */ + public AuthMe getInstance() { + return instance; + } + /** * Method setInstance. + * * @param instance AuthMe */ public void setInstance(AuthMe instance) { @@ -170,11 +208,13 @@ public class PerformBackup { } /** - * Method getInstance. - - * @return AuthMe */ - public AuthMe getInstance() { - return instance; + * Possible backup causes. + */ + public enum BackupCause { + START, + STOP, + COMMAND, + OTHER, } } diff --git a/src/main/java/fr/xephi/authme/SendMailSSL.java b/src/main/java/fr/xephi/authme/SendMailSSL.java index f3ed378d9..60f5eaeda 100644 --- a/src/main/java/fr/xephi/authme/SendMailSSL.java +++ b/src/main/java/fr/xephi/authme/SendMailSSL.java @@ -1,19 +1,16 @@ package fr.xephi.authme; -import java.io.File; +import fr.xephi.authme.cache.auth.PlayerAuth; +import fr.xephi.authme.settings.Settings; +import org.apache.commons.mail.HtmlEmail; +import org.bukkit.Bukkit; import javax.activation.DataSource; import javax.activation.FileDataSource; import javax.imageio.ImageIO; - -import org.apache.commons.mail.HtmlEmail; -import org.bukkit.Bukkit; - -import fr.xephi.authme.cache.auth.PlayerAuth; -import fr.xephi.authme.settings.Settings; +import java.io.File; /** - * * @author Xephi59 * @version $Revision: 1.0 $ */ @@ -23,6 +20,7 @@ public class SendMailSSL { /** * Constructor for SendMailSSL. + * * @param plugin AuthMe */ public SendMailSSL(AuthMe plugin) { @@ -31,7 +29,8 @@ public class SendMailSSL { /** * Method main. - * @param auth PlayerAuth + * + * @param auth PlayerAuth * @param newPass String */ public void main(final PlayerAuth auth, final String newPass) { diff --git a/src/main/java/fr/xephi/authme/api/API.java b/src/main/java/fr/xephi/authme/api/API.java index 6119f28eb..595e52027 100644 --- a/src/main/java/fr/xephi/authme/api/API.java +++ b/src/main/java/fr/xephi/authme/api/API.java @@ -1,19 +1,18 @@ package fr.xephi.authme.api; -import java.security.NoSuchAlgorithmException; - -import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; -import org.bukkit.plugin.Plugin; - import fr.xephi.authme.AuthMe; import fr.xephi.authme.cache.auth.PlayerAuth; import fr.xephi.authme.cache.auth.PlayerCache; import fr.xephi.authme.security.PasswordSecurity; import fr.xephi.authme.settings.Settings; import fr.xephi.authme.util.Utils; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import org.bukkit.plugin.Plugin; + +import java.security.NoSuchAlgorithmException; /** */ @@ -24,6 +23,7 @@ public class API { /** * Constructor for API. + * * @param instance AuthMe */ @Deprecated @@ -34,8 +34,8 @@ public class API { /** * Hook into AuthMe * - - * @return AuthMe instance */ + * @return AuthMe instance + */ @Deprecated public static AuthMe hookAuthMe() { if (instance != null) @@ -49,49 +49,18 @@ public class API { } /** - * Method getPlugin. - - * @return AuthMe */ - @Deprecated - public AuthMe getPlugin() { - return instance; - } - - /** - * * @param player - - * @return true if player is authenticate */ + * @return true if player is authenticate + */ @Deprecated public static boolean isAuthenticated(Player player) { return PlayerCache.getInstance().isAuthenticated(player.getName()); } /** - * * @param player - - * @return true if player is a npc */ - @Deprecated - public boolean isaNPC(Player player) { - return Utils.isNPC(player); - } - - /** - * - * @param player - - * @return true if player is a npc */ - @Deprecated - public boolean isNPC(Player player) { - return Utils.isNPC(player); - } - - /** - * - * @param player - - * @return true if the player is unrestricted */ + * @return true if the player is unrestricted + */ @Deprecated public static boolean isUnrestricted(Player player) { return Utils.isUnrestricted(player); @@ -99,9 +68,10 @@ public class API { /** * Method getLastLocation. + * * @param player Player - - * @return Location */ + * @return Location + */ @Deprecated public static Location getLastLocation(Player player) { try { @@ -121,13 +91,14 @@ public class API { /** * Method setPlayerInventory. - * @param player Player + * + * @param player Player * @param content ItemStack[] - * @param armor ItemStack[] + * @param armor ItemStack[] */ @Deprecated public static void setPlayerInventory(Player player, ItemStack[] content, - ItemStack[] armor) { + ItemStack[] armor) { try { player.getInventory().setContents(content); player.getInventory().setArmorContents(armor); @@ -136,10 +107,9 @@ public class API { } /** - * * @param playerName - - * @return true if player is registered */ + * @return true if player is registered + */ @Deprecated public static boolean isRegistered(String playerName) { String player = playerName.toLowerCase(); @@ -147,14 +117,13 @@ public class API { } /** - - - * @param playerName String + * @param playerName String * @param passwordToCheck String - * @return true if the password is correct , false else */ + * @return true if the password is correct , false else + */ @Deprecated public static boolean checkPassword(String playerName, - String passwordToCheck) { + String passwordToCheck) { if (!isRegistered(playerName)) return false; String player = playerName.toLowerCase(); @@ -169,11 +138,10 @@ public class API { /** * Register a player * - - * @param playerName String - * @param password String - * @return true if the player is register correctly */ + * @param password String + * @return true if the player is register correctly + */ @Deprecated public static boolean registerPlayer(String playerName, String password) { try { @@ -195,7 +163,6 @@ public class API { /** * Force a player to login * - * @param player * player */ @Deprecated @@ -203,4 +170,32 @@ public class API { instance.management.performLogin(player, "dontneed", true); } + /** + * Method getPlugin. + * + * @return AuthMe + */ + @Deprecated + public AuthMe getPlugin() { + return instance; + } + + /** + * @param player + * @return true if player is a npc + */ + @Deprecated + public boolean isaNPC(Player player) { + return Utils.isNPC(player); + } + + /** + * @param player + * @return true if player is a npc + */ + @Deprecated + public boolean isNPC(Player player) { + return Utils.isNPC(player); + } + } diff --git a/src/main/java/fr/xephi/authme/api/NewAPI.java b/src/main/java/fr/xephi/authme/api/NewAPI.java index b1aa27a63..a5bc9a68c 100644 --- a/src/main/java/fr/xephi/authme/api/NewAPI.java +++ b/src/main/java/fr/xephi/authme/api/NewAPI.java @@ -1,30 +1,29 @@ package fr.xephi.authme.api; -import java.security.NoSuchAlgorithmException; - -import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.Server; -import org.bukkit.entity.Player; -import org.bukkit.plugin.Plugin; - import fr.xephi.authme.AuthMe; import fr.xephi.authme.cache.auth.PlayerAuth; import fr.xephi.authme.cache.auth.PlayerCache; import fr.xephi.authme.security.PasswordSecurity; import fr.xephi.authme.settings.Settings; import fr.xephi.authme.util.Utils; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.Server; +import org.bukkit.entity.Player; +import org.bukkit.plugin.Plugin; + +import java.security.NoSuchAlgorithmException; /** */ public class NewAPI { - public static final String newline = System.getProperty("line.separator"); public static NewAPI singleton; public AuthMe plugin; /** * Constructor for NewAPI. + * * @param plugin AuthMe */ public NewAPI(AuthMe plugin) { @@ -33,6 +32,7 @@ public class NewAPI { /** * Constructor for NewAPI. + * * @param serv Server */ public NewAPI(Server serv) { @@ -42,8 +42,8 @@ public class NewAPI { /** * Hook into AuthMe * - - * @return AuthMe plugin */ + * @return AuthMe plugin + */ public static NewAPI getInstance() { if (singleton != null) return singleton; @@ -58,44 +58,43 @@ public class NewAPI { /** * Method getPlugin. - - * @return AuthMe */ + * + * @return AuthMe + */ public AuthMe getPlugin() { return plugin; } /** - * * @param player - - * @return true if player is authenticate */ + * @return true if player is authenticate + */ public boolean isAuthenticated(Player player) { return PlayerCache.getInstance().isAuthenticated(player.getName()); } /** - * * @param player - - * @return true if player is a npc */ + * @return true if player is a npc + */ public boolean isNPC(Player player) { return Utils.isNPC(player); } /** - * * @param player - - * @return true if the player is unrestricted */ + * @return true if the player is unrestricted + */ public boolean isUnrestricted(Player player) { return Utils.isUnrestricted(player); } /** * Method getLastLocation. + * * @param player Player - - * @return Location */ + * @return Location + */ public Location getLastLocation(Player player) { try { PlayerAuth auth = PlayerCache.getInstance().getAuth(player.getName().toLowerCase()); @@ -112,21 +111,19 @@ public class NewAPI { } /** - * * @param playerName - - * @return true if player is registered */ + * @return true if player is registered + */ public boolean isRegistered(String playerName) { String player = playerName.toLowerCase(); return plugin.database.isAuthAvailable(player); } /** - - - * @param playerName String + * @param playerName String * @param passwordToCheck String - * @return true if the password is correct , false else */ + * @return true if the password is correct , false else + */ public boolean checkPassword(String playerName, String passwordToCheck) { if (!isRegistered(playerName)) return false; @@ -142,11 +139,10 @@ public class NewAPI { /** * Register a player * - - * @param playerName String - * @param password String - * @return true if the player is register correctly */ + * @param password String + * @return true if the player is register correctly + */ public boolean registerPlayer(String playerName, String password) { try { String name = playerName.toLowerCase(); @@ -164,7 +160,6 @@ public class NewAPI { /** * Force a player to login * - * @param player * player */ public void forceLogin(Player player) { @@ -174,35 +169,28 @@ public class NewAPI { /** * Force a player to logout * - * @param player * player */ - public void forceLogout(Player player) - { - plugin.management.performLogout(player); + public void forceLogout(Player player) { + plugin.management.performLogout(player); } /** * Force a player to register * - - - * @param player * player + * @param player * player * @param password String */ - public void forceRegister(Player player, String password) - { - plugin.management.performRegister(player, password, null); + public void forceRegister(Player player, String password) { + plugin.management.performRegister(player, password, null); } /** * Force a player to unregister * - * @param player * player */ - public void forceUnregister(Player player) - { - plugin.management.performUnregister(player, "", true); + public void forceUnregister(Player player) { + plugin.management.performUnregister(player, "", true); } } diff --git a/src/main/java/fr/xephi/authme/cache/auth/PlayerAuth.java b/src/main/java/fr/xephi/authme/cache/auth/PlayerAuth.java index 5b2298233..2bfcd4f6d 100644 --- a/src/main/java/fr/xephi/authme/cache/auth/PlayerAuth.java +++ b/src/main/java/fr/xephi/authme/cache/auth/PlayerAuth.java @@ -22,10 +22,11 @@ public class PlayerAuth { /** * Constructor for PlayerAuth. - * @param nickname String - * @param ip String + * + * @param nickname String + * @param ip String * @param lastLogin long - * @param realName String + * @param realName String */ public PlayerAuth(String nickname, String ip, long lastLogin, String realName) { this(nickname, "", "", -1, ip, lastLogin, 0, 0, 0, "world", "your@email.com", realName); @@ -33,11 +34,12 @@ public class PlayerAuth { /** * Constructor for PlayerAuth. + * * @param nickname String - * @param x double - * @param y double - * @param z double - * @param world String + * @param x double + * @param y double + * @param z double + * @param world String * @param realName String */ public PlayerAuth(String nickname, double x, double y, double z, String world, String realName) { @@ -46,11 +48,12 @@ public class PlayerAuth { /** * Constructor for PlayerAuth. - * @param nickname String - * @param hash String - * @param ip String + * + * @param nickname String + * @param hash String + * @param ip String * @param lastLogin long - * @param realName String + * @param realName String */ public PlayerAuth(String nickname, String hash, String ip, long lastLogin, String realName) { this(nickname, hash, "", -1, ip, lastLogin, 0, 0, 0, "world", "your@email.com", realName); @@ -58,12 +61,13 @@ public class PlayerAuth { /** * Constructor for PlayerAuth. - * @param nickname String - * @param hash String - * @param ip String + * + * @param nickname String + * @param hash String + * @param ip String * @param lastLogin long - * @param email String - * @param realName String + * @param email String + * @param realName String */ public PlayerAuth(String nickname, String hash, String ip, long lastLogin, String email, String realName) { this(nickname, hash, "", -1, ip, lastLogin, 0, 0, 0, "world", email, realName); @@ -71,12 +75,13 @@ public class PlayerAuth { /** * Constructor for PlayerAuth. - * @param nickname String - * @param hash String - * @param salt String - * @param ip String + * + * @param nickname String + * @param hash String + * @param salt String + * @param ip String * @param lastLogin long - * @param realName String + * @param realName String */ public PlayerAuth(String nickname, String hash, String salt, String ip, long lastLogin, String realName) { this(nickname, hash, salt, -1, ip, lastLogin, 0, 0, 0, "world", "your@email.com", realName); @@ -84,16 +89,17 @@ public class PlayerAuth { /** * Constructor for PlayerAuth. - * @param nickname String - * @param hash String - * @param ip String + * + * @param nickname String + * @param hash String + * @param ip String * @param lastLogin long - * @param x double - * @param y double - * @param z double - * @param world String - * @param email String - * @param realName String + * @param x double + * @param y double + * @param z double + * @param world String + * @param email String + * @param realName String */ public PlayerAuth(String nickname, String hash, String ip, long lastLogin, double x, double y, double z, String world, String email, String realName) { this(nickname, hash, "", -1, ip, lastLogin, x, y, z, world, email, realName); @@ -101,17 +107,18 @@ public class PlayerAuth { /** * Constructor for PlayerAuth. - * @param nickname String - * @param hash String - * @param salt String - * @param ip String + * + * @param nickname String + * @param hash String + * @param salt String + * @param ip String * @param lastLogin long - * @param x double - * @param y double - * @param z double - * @param world String - * @param email String - * @param realName String + * @param x double + * @param y double + * @param z double + * @param world String + * @param email String + * @param realName String */ public PlayerAuth(String nickname, String hash, String salt, String ip, long lastLogin, double x, double y, double z, String world, String email, String realName) { this(nickname, hash, salt, -1, ip, lastLogin, x, y, z, world, email, realName); @@ -119,13 +126,14 @@ public class PlayerAuth { /** * Constructor for PlayerAuth. - * @param nickname String - * @param hash String - * @param salt String - * @param groupId int - * @param ip String + * + * @param nickname String + * @param hash String + * @param salt String + * @param groupId int + * @param ip String * @param lastLogin long - * @param realName String + * @param realName String */ public PlayerAuth(String nickname, String hash, String salt, int groupId, String ip, long lastLogin, String realName) { this(nickname, hash, salt, groupId, ip, lastLogin, 0, 0, 0, "world", "your@email.com", realName); @@ -133,18 +141,19 @@ public class PlayerAuth { /** * Constructor for PlayerAuth. - * @param nickname String - * @param hash String - * @param salt String - * @param groupId int - * @param ip String + * + * @param nickname String + * @param hash String + * @param salt String + * @param groupId int + * @param ip String * @param lastLogin long - * @param x double - * @param y double - * @param z double - * @param world String - * @param email String - * @param realName String + * @param x double + * @param y double + * @param z double + * @param world String + * @param email String + * @param realName String */ public PlayerAuth(String nickname, String hash, String salt, int groupId, String ip, long lastLogin, double x, double y, double z, String world, String email, String realName) { this.nickname = nickname; @@ -163,6 +172,7 @@ public class PlayerAuth { /** * Method set. + * * @param auth PlayerAuth */ public void set(PlayerAuth auth) { @@ -181,6 +191,7 @@ public class PlayerAuth { /** * Method setName. + * * @param nickname String */ public void setName(String nickname) { @@ -189,22 +200,25 @@ public class PlayerAuth { /** * Method getNickname. - - * @return String */ + * + * @return String + */ public String getNickname() { return nickname; } /** * Method getRealName. - - * @return String */ + * + * @return String + */ public String getRealName() { return realName; } /** * Method setRealName. + * * @param realName String */ public void setRealName(String realName) { @@ -213,14 +227,25 @@ public class PlayerAuth { /** * Method getGroupId. - - * @return int */ + * + * @return int + */ public int getGroupId() { return groupId; } + /** + * Method getQuitLocX. + * + * @return double + */ + public double getQuitLocX() { + return x; + } + /** * Method setQuitLocX. + * * @param d double */ public void setQuitLocX(double d) { @@ -228,15 +253,17 @@ public class PlayerAuth { } /** - * Method getQuitLocX. - - * @return double */ - public double getQuitLocX() { - return x; + * Method getQuitLocY. + * + * @return double + */ + public double getQuitLocY() { + return y; } /** * Method setQuitLocY. + * * @param d double */ public void setQuitLocY(double d) { @@ -244,15 +271,17 @@ public class PlayerAuth { } /** - * Method getQuitLocY. - - * @return double */ - public double getQuitLocY() { - return y; + * Method getQuitLocZ. + * + * @return double + */ + public double getQuitLocZ() { + return z; } /** * Method setQuitLocZ. + * * @param d double */ public void setQuitLocZ(double d) { @@ -260,15 +289,17 @@ public class PlayerAuth { } /** - * Method getQuitLocZ. - - * @return double */ - public double getQuitLocZ() { - return z; + * Method getWorld. + * + * @return String + */ + public String getWorld() { + return world; } /** * Method setWorld. + * * @param world String */ public void setWorld(String world) { @@ -276,15 +307,17 @@ public class PlayerAuth { } /** - * Method getWorld. - - * @return String */ - public String getWorld() { - return world; + * Method getIp. + * + * @return String + */ + public String getIp() { + return ip; } /** * Method setIp. + * * @param ip String */ public void setIp(String ip) { @@ -292,15 +325,17 @@ public class PlayerAuth { } /** - * Method getIp. - - * @return String */ - public String getIp() { - return ip; + * Method getLastLogin. + * + * @return long + */ + public long getLastLogin() { + return lastLogin; } /** * Method setLastLogin. + * * @param lastLogin long */ public void setLastLogin(long lastLogin) { @@ -308,15 +343,17 @@ public class PlayerAuth { } /** - * Method getLastLogin. - - * @return long */ - public long getLastLogin() { - return lastLogin; + * Method getEmail. + * + * @return String + */ + public String getEmail() { + return email; } /** * Method setEmail. + * * @param email String */ public void setEmail(String email) { @@ -324,41 +361,28 @@ public class PlayerAuth { } /** - * Method getEmail. - - * @return String */ - public String getEmail() { - return email; + * Method getSalt. + * + * @return String + */ + public String getSalt() { + return this.salt; } /** * Method setSalt. + * * @param salt String */ public void setSalt(String salt) { this.salt = salt; } - /** - * Method getSalt. - - * @return String */ - public String getSalt() { - return this.salt; - } - - /** - * Method setHash. - * @param hash String - */ - public void setHash(String hash) { - this.hash = hash; - } - /** * Method getHash. - - * @return String */ + * + * @return String + */ public String getHash() { if (Settings.getPasswordHash == HashAlgorithm.MD5VB) { if (salt != null && !salt.isEmpty() && Settings.getPasswordHash == HashAlgorithm.MD5VB) { @@ -368,11 +392,21 @@ public class PlayerAuth { return hash; } + /** + * Method setHash. + * + * @param hash String + */ + public void setHash(String hash) { + this.hash = hash; + } + /** * Method equals. + * * @param obj Object - - * @return boolean */ + * @return boolean + */ @Override public boolean equals(Object obj) { if (!(obj instanceof PlayerAuth)) { @@ -384,8 +418,9 @@ public class PlayerAuth { /** * Method hashCode. - - * @return int */ + * + * @return int + */ @Override public int hashCode() { int hashCode = 7; @@ -396,8 +431,9 @@ public class PlayerAuth { /** * Method toString. - - * @return String */ + * + * @return String + */ @Override public String toString() { return ("Player : " + nickname + " | " + realName diff --git a/src/main/java/fr/xephi/authme/cache/auth/PlayerCache.java b/src/main/java/fr/xephi/authme/cache/auth/PlayerCache.java index e72fcd685..53f0a799e 100644 --- a/src/main/java/fr/xephi/authme/cache/auth/PlayerCache.java +++ b/src/main/java/fr/xephi/authme/cache/auth/PlayerCache.java @@ -13,8 +13,21 @@ public class PlayerCache { cache = new ConcurrentHashMap<>(); } + /** + * Method getInstance. + * + * @return PlayerCache + */ + public static PlayerCache getInstance() { + if (singleton == null) { + singleton = new PlayerCache(); + } + return singleton; + } + /** * Method addPlayer. + * * @param auth PlayerAuth */ public void addPlayer(PlayerAuth auth) { @@ -23,6 +36,7 @@ public class PlayerCache { /** * Method updatePlayer. + * * @param auth PlayerAuth */ public void updatePlayer(PlayerAuth auth) { @@ -32,6 +46,7 @@ public class PlayerCache { /** * Method removePlayer. + * * @param user String */ public void removePlayer(String user) { @@ -40,45 +55,38 @@ public class PlayerCache { /** * Method isAuthenticated. + * * @param user String - - * @return boolean */ + * @return boolean + */ public boolean isAuthenticated(String user) { return cache.containsKey(user.toLowerCase()); } /** * Method getAuth. + * * @param user String - - * @return PlayerAuth */ + * @return PlayerAuth + */ public PlayerAuth getAuth(String user) { return cache.get(user.toLowerCase()); } - /** - * Method getInstance. - - * @return PlayerCache */ - public static PlayerCache getInstance() { - if (singleton == null) { - singleton = new PlayerCache(); - } - return singleton; - } - /** * Method getLogged. - - * @return int */ + * + * @return int + */ public int getLogged() { return cache.size(); } /** * Method getCache. - - * @return ConcurrentHashMap */ + * + * @return ConcurrentHashMap + */ public ConcurrentHashMap getCache() { return this.cache; } diff --git a/src/main/java/fr/xephi/authme/cache/backup/DataFileCache.java b/src/main/java/fr/xephi/authme/cache/backup/DataFileCache.java index 01751d789..c40cab961 100644 --- a/src/main/java/fr/xephi/authme/cache/backup/DataFileCache.java +++ b/src/main/java/fr/xephi/authme/cache/backup/DataFileCache.java @@ -10,9 +10,10 @@ public class DataFileCache { /** * Constructor for DataFileCache. - * @param group String + * + * @param group String * @param operator boolean - * @param flying boolean + * @param flying boolean */ public DataFileCache(String group, boolean operator, boolean flying) { this.group = group; @@ -22,24 +23,27 @@ public class DataFileCache { /** * Method getGroup. - - * @return String */ + * + * @return String + */ public String getGroup() { return group; } /** * Method getOperator. - - * @return boolean */ + * + * @return boolean + */ public boolean getOperator() { return operator; } /** * Method isFlying. - - * @return boolean */ + * + * @return boolean + */ public boolean isFlying() { return flying; } diff --git a/src/main/java/fr/xephi/authme/cache/backup/JsonCache.java b/src/main/java/fr/xephi/authme/cache/backup/JsonCache.java index 70d6614c8..9b0b7f369 100644 --- a/src/main/java/fr/xephi/authme/cache/backup/JsonCache.java +++ b/src/main/java/fr/xephi/authme/cache/backup/JsonCache.java @@ -1,27 +1,17 @@ package fr.xephi.authme.cache.backup; +import com.google.common.base.Charsets; +import com.google.common.io.Files; +import com.google.gson.*; +import fr.xephi.authme.ConsoleLogger; +import fr.xephi.authme.settings.Settings; +import fr.xephi.authme.util.Utils; +import org.bukkit.entity.Player; + import java.io.File; import java.io.IOException; import java.lang.reflect.Type; -import org.bukkit.entity.Player; - -import com.google.common.base.Charsets; -import com.google.common.io.Files; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import com.google.gson.JsonDeserializationContext; -import com.google.gson.JsonDeserializer; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonParseException; -import com.google.gson.JsonSerializationContext; -import com.google.gson.JsonSerializer; - -import fr.xephi.authme.ConsoleLogger; -import fr.xephi.authme.settings.Settings; -import fr.xephi.authme.util.Utils; - /** */ public class JsonCache { @@ -43,7 +33,8 @@ public class JsonCache { /** * Method createCache. - * @param player Player + * + * @param player Player * @param playerData DataFileCache */ public void createCache(Player player, DataFileCache playerData) { @@ -77,9 +68,10 @@ public class JsonCache { /** * Method readCache. + * * @param player Player - - * @return DataFileCache */ + * @return DataFileCache + */ public DataFileCache readCache(Player player) { String path; try { @@ -103,24 +95,41 @@ public class JsonCache { } /** + * Method removeCache. + * + * @param player Player */ - private class PlayerDataSerializer implements JsonSerializer { - /** - * Method serialize. - * @param dataFileCache DataFileCache - * @param type Type - * @param jsonSerializationContext JsonSerializationContext - - * @return JsonElement */ - @Override - public JsonElement serialize(DataFileCache dataFileCache, Type type, JsonSerializationContext jsonSerializationContext) { - JsonObject jsonObject = new JsonObject(); - jsonObject.addProperty("group", dataFileCache.getGroup()); - jsonObject.addProperty("operator", dataFileCache.getOperator()); - jsonObject.addProperty("flying", dataFileCache.isFlying()); - - return jsonObject; + public void removeCache(Player player) { + String path; + try { + path = player.getUniqueId().toString(); + } catch (Exception | Error e) { + path = player.getName().toLowerCase(); } + File file = new File(cacheDir, path); + if (file.exists()) { + Utils.purgeDirectory(file); + if (!file.delete()) { + ConsoleLogger.showError("Failed to remove" + player.getName() + "cache."); + } + } + } + + /** + * Method doesCacheExist. + * + * @param player Player + * @return boolean + */ + public boolean doesCacheExist(Player player) { + String path; + try { + path = player.getUniqueId().toString(); + } catch (Exception | Error e) { + path = player.getName().toLowerCase(); + } + File file = new File(cacheDir, path + File.separator + "cache.json"); + return file.exists(); } /** @@ -128,13 +137,12 @@ public class JsonCache { private static class PlayerDataDeserializer implements JsonDeserializer { /** * Method deserialize. - * @param jsonElement JsonElement - * @param type Type + * + * @param jsonElement JsonElement + * @param type Type * @param jsonDeserializationContext JsonDeserializationContext - - - - * @return DataFileCache * @throws JsonParseException * @see com.google.gson.JsonDeserializer#deserialize(JsonElement, Type, JsonDeserializationContext) */ + * @return DataFileCache * @throws JsonParseException * @see com.google.gson.JsonDeserializer#deserialize(JsonElement, Type, JsonDeserializationContext) + */ @Override public DataFileCache deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException { JsonObject jsonObject = jsonElement.getAsJsonObject(); @@ -161,39 +169,25 @@ public class JsonCache { } /** - * Method removeCache. - * @param player Player */ - public void removeCache(Player player) { - String path; - try { - path = player.getUniqueId().toString(); - } catch (Exception | Error e) { - path = player.getName().toLowerCase(); - } - File file = new File(cacheDir, path); - if (file.exists()) { - Utils.purgeDirectory(file); - if (!file.delete()) { - ConsoleLogger.showError("Failed to remove" + player.getName() + "cache."); - } - } - } + private class PlayerDataSerializer implements JsonSerializer { + /** + * Method serialize. + * + * @param dataFileCache DataFileCache + * @param type Type + * @param jsonSerializationContext JsonSerializationContext + * @return JsonElement + */ + @Override + public JsonElement serialize(DataFileCache dataFileCache, Type type, JsonSerializationContext jsonSerializationContext) { + JsonObject jsonObject = new JsonObject(); + jsonObject.addProperty("group", dataFileCache.getGroup()); + jsonObject.addProperty("operator", dataFileCache.getOperator()); + jsonObject.addProperty("flying", dataFileCache.isFlying()); - /** - * Method doesCacheExist. - * @param player Player - - * @return boolean */ - public boolean doesCacheExist(Player player) { - String path; - try { - path = player.getUniqueId().toString(); - } catch (Exception | Error e) { - path = player.getName().toLowerCase(); + return jsonObject; } - File file = new File(cacheDir, path + File.separator + "cache.json"); - return file.exists(); } } diff --git a/src/main/java/fr/xephi/authme/cache/limbo/LimboCache.java b/src/main/java/fr/xephi/authme/cache/limbo/LimboCache.java index 59dee4688..2fb08b669 100644 --- a/src/main/java/fr/xephi/authme/cache/limbo/LimboCache.java +++ b/src/main/java/fr/xephi/authme/cache/limbo/LimboCache.java @@ -1,19 +1,18 @@ package fr.xephi.authme.cache.limbo; -import java.util.concurrent.ConcurrentHashMap; - -import fr.xephi.authme.permission.PermissionsManager; -import org.bukkit.Bukkit; -import org.bukkit.GameMode; -import org.bukkit.Location; -import org.bukkit.entity.Player; - import fr.xephi.authme.AuthMe; import fr.xephi.authme.ConsoleLogger; import fr.xephi.authme.cache.backup.DataFileCache; import fr.xephi.authme.cache.backup.JsonCache; import fr.xephi.authme.events.ResetInventoryEvent; +import fr.xephi.authme.permission.PermissionsManager; import fr.xephi.authme.settings.Settings; +import org.bukkit.Bukkit; +import org.bukkit.GameMode; +import org.bukkit.Location; +import org.bukkit.entity.Player; + +import java.util.concurrent.ConcurrentHashMap; /** */ @@ -21,11 +20,12 @@ public class LimboCache { private volatile static LimboCache singleton; public ConcurrentHashMap cache; - private JsonCache playerData; public AuthMe plugin; + private JsonCache playerData; /** * Constructor for LimboCache. + * * @param plugin AuthMe */ private LimboCache(AuthMe plugin) { @@ -34,6 +34,18 @@ public class LimboCache { this.playerData = new JsonCache(); } + /** + * Method getInstance. + * + * @return LimboCache + */ + public static LimboCache getInstance() { + if (singleton == null) { + singleton = new LimboCache(AuthMe.getInstance()); + } + return singleton; + } + /** * Add a limbo player. * @@ -49,7 +61,7 @@ public class LimboCache { // Get the permissions manager, and make sure it's valid PermissionsManager permsMan = this.plugin.getPermissionsManager(); - if(permsMan == null) + if (permsMan == null) ConsoleLogger.showError("Unable to access permissions manager!"); assert permsMan != null; @@ -65,7 +77,7 @@ public class LimboCache { flying = player.isFlying(); // Check whether groups are supported - if(permsMan.hasGroupSupport()) + if (permsMan.hasGroupSupport()) playerGroup = permsMan.getPrimaryGroup(player); } @@ -91,8 +103,9 @@ public class LimboCache { /** * Method addLimboPlayer. + * * @param player Player - * @param group String + * @param group String */ public void addLimboPlayer(Player player, String group) { cache.put(player.getName().toLowerCase(), new LimboPlayer(player.getName().toLowerCase(), group)); @@ -100,6 +113,7 @@ public class LimboCache { /** * Method deleteLimboPlayer. + * * @param name String */ public void deleteLimboPlayer(String name) { @@ -108,35 +122,27 @@ public class LimboCache { /** * Method getLimboPlayer. + * * @param name String - - * @return LimboPlayer */ + * @return LimboPlayer + */ public LimboPlayer getLimboPlayer(String name) { return cache.get(name); } /** * Method hasLimboPlayer. + * * @param name String - - * @return boolean */ + * @return boolean + */ public boolean hasLimboPlayer(String name) { return cache.containsKey(name); } - /** - * Method getInstance. - - * @return LimboCache */ - public static LimboCache getInstance() { - if (singleton == null) { - singleton = new LimboCache(AuthMe.getInstance()); - } - return singleton; - } - /** * Method updateLimboPlayer. + * * @param player Player */ public void updateLimboPlayer(Player player) { diff --git a/src/main/java/fr/xephi/authme/cache/limbo/LimboPlayer.java b/src/main/java/fr/xephi/authme/cache/limbo/LimboPlayer.java index d6f7b02b2..64e65dc55 100644 --- a/src/main/java/fr/xephi/authme/cache/limbo/LimboPlayer.java +++ b/src/main/java/fr/xephi/authme/cache/limbo/LimboPlayer.java @@ -19,15 +19,16 @@ public class LimboPlayer { /** * Constructor for LimboPlayer. - * @param name String - * @param loc Location + * + * @param name String + * @param loc Location * @param gameMode GameMode * @param operator boolean - * @param group String - * @param flying boolean + * @param group String + * @param flying boolean */ public LimboPlayer(String name, Location loc, GameMode gameMode, - boolean operator, String group, boolean flying) { + boolean operator, String group, boolean flying) { this.name = name; this.loc = loc; this.gameMode = gameMode; @@ -38,7 +39,8 @@ public class LimboPlayer { /** * Constructor for LimboPlayer. - * @param name String + * + * @param name String * @param group String */ public LimboPlayer(String name, String group) { @@ -48,46 +50,61 @@ public class LimboPlayer { /** * Method getName. - - * @return String */ + * + * @return String + */ public String getName() { return name; } /** * Method getLoc. - - * @return Location */ + * + * @return Location + */ public Location getLoc() { return loc; } /** * Method getGameMode. - - * @return GameMode */ + * + * @return GameMode + */ public GameMode getGameMode() { return gameMode; } /** * Method getOperator. - - * @return boolean */ + * + * @return boolean + */ public boolean getOperator() { return operator; } /** * Method getGroup. - - * @return String */ + * + * @return String + */ public String getGroup() { return group; } + /** + * Method getTimeoutTaskId. + * + * @return BukkitTask + */ + public BukkitTask getTimeoutTaskId() { + return timeoutTaskId; + } + /** * Method setTimeoutTaskId. + * * @param i BukkitTask */ public void setTimeoutTaskId(BukkitTask i) { @@ -97,15 +114,17 @@ public class LimboPlayer { } /** - * Method getTimeoutTaskId. - - * @return BukkitTask */ - public BukkitTask getTimeoutTaskId() { - return timeoutTaskId; + * Method getMessageTaskId. + * + * @return BukkitTask + */ + public BukkitTask getMessageTaskId() { + return messageTaskId; } /** * Method setMessageTaskId. + * * @param messageTaskId BukkitTask */ public void setMessageTaskId(BukkitTask messageTaskId) { @@ -114,18 +133,11 @@ public class LimboPlayer { this.messageTaskId = messageTaskId; } - /** - * Method getMessageTaskId. - - * @return BukkitTask */ - public BukkitTask getMessageTaskId() { - return messageTaskId; - } - /** * Method isFlying. - - * @return boolean */ + * + * @return boolean + */ public boolean isFlying() { return flying; } diff --git a/src/main/java/fr/xephi/authme/command/CommandArgumentDescription.java b/src/main/java/fr/xephi/authme/command/CommandArgumentDescription.java index 75d6e4aeb..c486a3820 100644 --- a/src/main/java/fr/xephi/authme/command/CommandArgumentDescription.java +++ b/src/main/java/fr/xephi/authme/command/CommandArgumentDescription.java @@ -6,17 +6,23 @@ public class CommandArgumentDescription { // TODO: Allow argument to consist of infinite parts.