diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 000000000..ae800ac65 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,13 @@ +# Top-most EditorConfig file +root = true + +# Unix-style newlines with a newline ending every file +[*] +end_of_line = lf +insert_final_newline = true + +# Set the charset, and space indention +[*.java] +charset = utf-8 +indent_style = space +indent_size = 4 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..607894b51 100644 --- a/.gitignore +++ b/.gitignore @@ -1,12 +1,7 @@ -# Created by https://www.gitignore.io - -### Java ### +### Java files ### *.class -# Mobile Tools for Java (J2ME) -.mtj.tmp/ - -# Package Files # +# Package Files #*.jar *.war *.ear @@ -15,40 +10,27 @@ hs_err_pid* + ### Intellij ### # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm - +# Ignore project files *.iml -## Directory-based project format: -.idea/ -# if you remove the above rule, at least ignore the following: +# Ignore IDEA directory +.idea/* -# User-specific stuff: -# .idea/workspace.xml -# .idea/tasks.xml -# .idea/dictionaries +# Include the project's code style settings file +!.idea/codeStyleSettings.xml -# Sensitive or high-churn files: -# .idea/dataSources.ids -# .idea/dataSources.xml -# .idea/sqlDataSources.xml -# .idea/dynamic.xml -# .idea/uiDesigner.xml +# Include the project's dictionary +!.idea/dictionaries/ +!.idea/dictionaries/* -# Gradle: -# .idea/gradle.xml -# .idea/libraries - -# Mongo Explorer plugin: -# .idea/mongoSettings.xml - -## File-based project format: +# File-based project format: *.ipr *.iws -## Plugin-specific files: - +### Plugin-specific files: ### # IntelliJ /out/ @@ -64,6 +46,7 @@ crashlytics.properties crashlytics-build.properties + ### Eclipse ### *.pydevproject .metadata @@ -103,6 +86,7 @@ local.properties .texlipse + ### Maven ### target/ pom.xml.tag @@ -114,6 +98,7 @@ dependency-reduced-pom.xml buildNumber.properties + ### NetBeans ### nbproject/private/ build/ @@ -123,3 +108,9 @@ nbdist/ nbactions.xml nb-configuration.xml .nb-gradle/ + + + +### Git ### +# Don't exclude the .gitignore itself +!.gitignore diff --git a/.idea/codeStyleSettings.xml b/.idea/codeStyleSettings.xml new file mode 100644 index 000000000..6e95fe792 --- /dev/null +++ b/.idea/codeStyleSettings.xml @@ -0,0 +1,17 @@ + + + + + + \ No newline at end of file diff --git a/.idea/dictionaries/Tim.xml b/.idea/dictionaries/Tim.xml new file mode 100644 index 000000000..1cd4a23ca --- /dev/null +++ b/.idea/dictionaries/Tim.xml @@ -0,0 +1,7 @@ + + + + authme + + + diff --git a/pom.xml b/pom.xml index 1a9a64396..3a5a82db0 100644 --- a/pom.xml +++ b/pom.xml @@ -1,60 +1,66 @@ - - 4.0.0 - - fr.xephi - authme - 5.1-SNAPSHOT - jar - - AuthMeReloaded - Authentication plugin for CraftBukkit/Spigot! - 2013 - http://dev.bukkit.org/bukkit-plugins/authme-reloaded/ - - - - AuthMe-Team - https://github.com/AuthMe-Team - - - - scm:git:https://github.com/Xephi/AuthMeReloaded.git - scm:git:git@github.com:Xephi/AuthMeReloaded.git - http://github.com/Xephi/AuthMeReloaded - - - - jenkins - http://ci.xephi.fr/job/AuthMeReloaded/ - - - - GitHub - https://github.com/Xephi/AuthMeReloaded/issues - - - - - The GNU General Public Licence version 3 (GPLv3) - http://www.gnu.org/licenses/gpl-3.0.html - - - - + + 4.0.0 + + fr.xephi + authme + 5.1-SNAPSHOT + jar + + AuthMeReloaded + Authentication plugin for CraftBukkit/Spigot! + 2013 + http://dev.bukkit.org/bukkit-plugins/authme-reloaded/ + + + + AuthMe-Team + https://github.com/AuthMe-Team + + + + scm:git:https://github.com/Xephi/AuthMeReloaded.git + scm:git:git@github.com:Xephi/AuthMeReloaded.git + http://github.com/Xephi/AuthMeReloaded + + + + jenkins + http://ci.xephi.fr/job/AuthMeReloaded/ + + + + GitHub + https://github.com/Xephi/AuthMeReloaded/issues + + + + + The GNU General Public Licence version 3 (GPLv3) + http://www.gnu.org/licenses/gpl-3.0.html + + + + + 3.3.3 + + + + UTF-8 + - UTF-8 + AuthMe fr.xephi.authme.AuthMe - CustomBuild + 100 [Xephi, sgdc3, DNx5, timvisee, games647, ljacqu] - - - 1.7 - - - 1.8.8-R0.1-SNAPSHOT - + + + 1.7 + + + 1.8.8-R0.1-SNAPSHOT + AuthMe-${project.version} @@ -90,7 +96,12 @@ - + + + src/test/resources + + + org.apache.maven.plugins @@ -103,539 +114,525 @@ - - org.apache.maven.plugins - maven-shade-plugin - 2.4.2 - - false - false - - - org.mcstats - fr.xephi.authme - - - com.google.gson - fr.xephi.authme.libs.gson - - - com.zaxxer.hikari - fr.xephi.authme.libs.hikari - - - org.slf4j - fr.xephi.authme.libs.slf4j - - - com.maxmind.geoip - fr.xephi.authme.libs.geoip - - - net.ricecode.similarity - fr.xephi.authme.libs.similarity - - - - - - package - - shade - - - - - - + + org.apache.maven.plugins + maven-shade-plugin + 2.4.2 + + false + false + + + org.mcstats + fr.xephi.authme + + + com.google.gson + fr.xephi.authme.libs.gson + + + com.zaxxer.hikari + fr.xephi.authme.libs.hikari + + + org.slf4j + fr.xephi.authme.libs.slf4j + + + com.maxmind.geoip + fr.xephi.authme.libs.geoip + + + net.ricecode.similarity + fr.xephi.authme.libs.similarity + + + + + + package + + shade + + + + + + - - - - spigot-repo - http://hub.spigotmc.org/nexus/content/groups/public - + + + + spigot-repo + http://hub.spigotmc.org/nexus/content/groups/public + - - - ess-repo - http://ci.drtshock.net/plugin/repository/everything - + + + ess-repo + http://ci.drtshock.net/plugin/repository/everything + - - - minelink-thirdparty - http://repo.minelink.net/content/repositories/public - + + + minelink-thirdparty + http://repo.minelink.net/content/repositories/public + - - - dmulloy2-repo - http://repo.dmulloy2.net/content/groups/public/ - + + + dmulloy2-repo + http://repo.dmulloy2.net/content/groups/public/ + - - - onarandombox - http://repo.onarandombox.com/content/groups/public - + + + onarandombox + http://repo.onarandombox.com/content/groups/public + - - - vault-repo - http://nexus.theyeticave.net/content/repositories/pub_releases - + + + vault-repo + http://nexus.theyeticave.net/content/repositories/pub_releases + - - - luricos-releases - http://repo.luricos.de/content/repositories/releases - + + + luricos-releases + http://repo.luricos.de/content/repositories/releases + - - - xephi-repo - http://ci.xephi.fr/plugin/repository/everything/ - + + + xephi-repo + http://ci.xephi.fr/plugin/repository/everything/ + - - - pex-repo - http://pex-repo.aoeu.xyz/ - - + + + pex-repo + http://pex-repo.aoeu.xyz/ + + - - - - com.zaxxer - HikariCP - 2.4.1 - compile - - - slf4j-api - org.slf4j - - - true - - - org.slf4j - slf4j-jdk14 - 1.7.12 - compile - true - + + + + com.zaxxer + HikariCP + 2.4.1 + compile + + + slf4j-api + org.slf4j + + + true + + + org.slf4j + slf4j-jdk14 + 1.7.12 + compile + true + - - - org.apache.logging.log4j - log4j-core - - 2.0-beta9 - provided - true - + + + org.apache.logging.log4j + log4j-core + + 2.0-beta9 + provided + true + - - - com.sun.mail - mailapi - 1.5.4 - compile - true - - - com.sun.mail - smtp - 1.5.4 - compile - true - - - org.apache.commons - commons-email - 1.4 - compile - true - + + + org.apache.commons + commons-email + 1.4 + compile + true + - - - com.google.code.gson - gson - 2.4 - compile - true - + + + com.google.code.gson + gson + 2.4 + compile + true + - - - com.maxmind.geoip - geoip-api - 1.2.15 - compile - true - + + + com.maxmind.geoip + geoip-api + 1.2.15 + compile + true + - - - org.mcstats.bukkit - metrics - R8-SNAPSHOT - compile - - - org.bukkit - bukkit - - - true - + + + org.mcstats.bukkit + metrics + R8-SNAPSHOT + compile + + + org.bukkit + bukkit + + + true + - - - org.bukkit - bukkit - ${bukkitVersion} - provided - true - - - junit - junit - - - json-simple - com.googlecode.json-simple - - - gson - com.google.code.gson - - - persistence-api - javax.persistence - - - + + + org.bukkit + bukkit + ${bukkitVersion} + provided + true + + + junit + junit + + + json-simple + com.googlecode.json-simple + + + gson + com.google.code.gson + + + persistence-api + javax.persistence + + + - - - com.comphenix.protocol - ProtocolLib - 3.6.5-SNAPSHOT - provided - true - - - cglib-nodep - cglib - - - BukkitExecutors - com.comphenix.executors - - - + + + com.comphenix.protocol + ProtocolLib + 3.6.5-SNAPSHOT + provided + true + + + cglib-nodep + cglib + + + BukkitExecutors + com.comphenix.executors + + + - - - ru.tehkode - PermissionsEx - 1.23.1 - provided - - - org.bukkit - bukkit - - - net.gravitydevelopment.updater - updater - - - commons-dbcp - commons-dbcp - - - AccountsClient - com.mojang - - - + + + ru.tehkode + PermissionsEx + 1.23.1 + provided + + + org.bukkit + bukkit + + + net.gravitydevelopment.updater + updater + + + commons-dbcp + commons-dbcp + + + AccountsClient + com.mojang + + + - - - org.anjocaido - groupmanager - 2.13.1 - system - ${basedir}/lib/EssentialsGroupManager-2.13.1.jar - + + + org.anjocaido + groupmanager + 2.13.1 + system + ${basedir}/lib/EssentialsGroupManager-2.13.1.jar + - - - de.bananaco - bpermissions - 1.12-DEV - system - ${basedir}/lib/bPermissions-2.12-DEV.jar - + + + de.bananaco + bpermissions + 1.12-DEV + system + ${basedir}/lib/bPermissions-2.12-DEV.jar + - - - org.tyrannyofheaven.bukkit - zPermissions - 1.3-SNAPSHOT - system - ${basedir}/lib/zPermissions-1.3beta1.jar - + + + org.tyrannyofheaven.bukkit + zPermissions + 1.3-SNAPSHOT + system + ${basedir}/lib/zPermissions-1.3beta1.jar + - - - com.nijiko - permissions - 3.1.6 - system - ${basedir}/lib/Permission-3.1.6.jar - + + + com.nijiko + permissions + 3.1.6 + system + ${basedir}/lib/Permission-3.1.6.jar + - - - net.milkbowl.vault - VaultAPI - 1.5 - provided - - - org.bukkit - bukkit - - - org.bukkit - craftbukkit - - - true - + + + net.milkbowl.vault + VaultAPI + 1.5 + provided + + + org.bukkit + bukkit + + + org.bukkit + craftbukkit + + + true + - - - com.onarandombox.multiversecore - Multiverse-Core - 2.5 - jar - provided - - - org.bukkit - bukkit - - - org.bukkit - craftbukkit - - - AllPay - com.fernferret.allpay - - - Vault - net.milkbowl.vault - - - CommandHandler - com.pneumaticraft.commandhandler - - - SerializationConfig - me.main__.util - - - Logging - com.dumptruckman.minecraft - - - metrics - org.mcstats.bukkit - - - buscript - com.dumptruckman.minecraft - - - junit - junit - - - true - + + + com.onarandombox.multiversecore + Multiverse-Core + 2.5 + jar + provided + + + org.bukkit + bukkit + + + org.bukkit + craftbukkit + + + AllPay + com.fernferret.allpay + + + VaultAPI + net.milkbowl.vault + + + CommandHandler + com.pneumaticraft.commandhandler + + + SerializationConfig + me.main__.util + + + Logging + com.dumptruckman.minecraft + + + metrics + org.mcstats.bukkit + + + buscript + com.dumptruckman.minecraft + + + junit + junit + + + true + - - - net.ess3 - EssentialsX - 2.0.1-SNAPSHOT - provided - - - org.spigotmc - spigot-api - - - true - + + + net.ess3 + EssentialsX + 2.0.1-SNAPSHOT + provided + + + org.spigotmc + spigot-api + + + true + - - - net.minelink - CombatTagPlus - 1.2.1-SNAPSHOT - provided - - - org.bukkit - bukkit - - - org.bukkit - craftbukkit - - - CombatTagPlusHook - net.minelink - - - CombatTagPlusFactions-v1_6 - net.minelink - - - CombatTagPlusCompat-v1_7_R3 - net.minelink - - - CombatTagPlusFactions-v1_8 - net.minelink - - - CombatTagPlusCompat-v1_7_R4 - net.minelink - - - CombatTagPlusWG-v5 - net.minelink - - - CombatTagPlusWG-v6 - net.minelink - - - CombatTagPlusCompat-API - net.minelink - - - CombatTagPlusFactions-v2_6 - net.minelink - - - CombatTagPlusCompat-v1_8_R3 - net.minelink - - - CombatTagPlusFactions-v2_7 - net.minelink - - - CombatTagPlusCompat-v1_8_R2 - net.minelink - - - CombatTagPlusCompat-v1_8_R1 - net.minelink - - - metrics-lite - org.mcstats.bukkit - - - true - + + + net.minelink + CombatTagPlus + 1.2.1-SNAPSHOT + provided + + + org.bukkit + bukkit + + + org.bukkit + craftbukkit + + + CombatTagPlusHook + net.minelink + + + CombatTagPlusFactions-v1_6 + net.minelink + + + CombatTagPlusCompat-v1_7_R3 + net.minelink + + + CombatTagPlusFactions-v1_8 + net.minelink + + + CombatTagPlusCompat-v1_7_R4 + net.minelink + + + CombatTagPlusWG-v5 + net.minelink + + + CombatTagPlusWG-v6 + net.minelink + + + CombatTagPlusCompat-API + net.minelink + + + CombatTagPlusFactions-v2_6 + net.minelink + + + CombatTagPlusCompat-v1_8_R3 + net.minelink + + + CombatTagPlusFactions-v2_7 + net.minelink + + + CombatTagPlusCompat-v1_8_R2 + net.minelink + + + CombatTagPlusCompat-v1_8_R1 + net.minelink + + + metrics-lite + org.mcstats.bukkit + + + true + - - - de.luricos.bukkit - xAuth - 2.6 - provided - - - org.bukkit - bukkit - - - org.bukkit - craftbukkit - - - updater - net.gravitydevelopment.updater - - - lombok - org.projectlombok - - - EssentialsGroupManager - net.ess3 - - - PermissionsEx - ru.tehkode - - - AccountsClient - com.mojang - - - log4j-core - org.apache.logging.log4j - - - true - + + + de.luricos.bukkit + xAuth + 2.6 + provided + + + org.bukkit + bukkit + + + org.bukkit + craftbukkit + + + updater + net.gravitydevelopment.updater + + + lombok + org.projectlombok + + + EssentialsGroupManager + net.ess3 + + + PermissionsEx + ru.tehkode + + + AccountsClient + com.mojang + + + log4j-core + org.apache.logging.log4j + + + true + - - - junit - junit - test - 4.12 - true - - - org.hamcrest - java-hamcrest - test - 2.0.0.0 - true - - - org.mockito - mockito-core - test - 2.0.5-beta - true - + + + junit + junit + test + 4.12 + true + + + org.hamcrest + java-hamcrest + test + 2.0.0.0 + true + + + org.mockito + mockito-core + test + 2.0.5-beta + true + - - - net.ricecode - string-similarity - 1.0.0 - compile - true - - + + + net.ricecode + string-similarity + 1.0.0 + compile + true + + diff --git a/src/main/java/fr/xephi/authme/AntiBot.java b/src/main/java/fr/xephi/authme/AntiBot.java new file mode 100644 index 000000000..3b8d0afc8 --- /dev/null +++ b/src/main/java/fr/xephi/authme/AntiBot.java @@ -0,0 +1,98 @@ +package fr.xephi.authme; + +import fr.xephi.authme.settings.MessageKey; +import fr.xephi.authme.settings.Messages; +import fr.xephi.authme.settings.Settings; +import fr.xephi.authme.util.Wrapper; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; + +import java.util.ArrayList; +import java.util.List; + +/** + * The AntiBot Service Management class. + */ +public class AntiBot { + + private static final AuthMe plugin = AuthMe.getInstance(); + private static final Messages messages = plugin.getMessages(); + private static Wrapper wrapper = new Wrapper(plugin); + private static final List antibotPlayers = new ArrayList<>(); + private static AntiBotStatus antiBotStatus = AntiBotStatus.DISABLED; + + public static void setupAntiBotService() { + if (!Settings.enableAntiBot) { + return; + } + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { + @Override + public void run() { + antiBotStatus = AntiBotStatus.LISTENING; + } + }, 2400); + } + + public static void overrideAntiBotStatus(boolean activated) { + if (antiBotStatus == AntiBotStatus.DISABLED) { + return; + } + if (activated) { + antiBotStatus = AntiBotStatus.ACTIVE; + } else { + antiBotStatus = AntiBotStatus.LISTENING; + } + } + + public static AntiBotStatus getAntiBotStatus() { + return antiBotStatus; + } + + public static void activateAntiBot() { + antiBotStatus = AntiBotStatus.ACTIVE; + for (String s : messages.retrieve(MessageKey.ANTIBOT_AUTO_ENABLED_MESSAGE)) { + Bukkit.broadcastMessage(s); + } + + wrapper.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { + @Override + public void run() { + if (antiBotStatus == AntiBotStatus.ACTIVE) { + antiBotStatus = AntiBotStatus.LISTENING; + antibotPlayers.clear(); + for (String s : messages.retrieve(MessageKey.ANTIBOT_AUTO_DISABLED_MESSAGE)) { + Bukkit.broadcastMessage(s.replace("%m", "" + Settings.antiBotDuration)); + } + } + } + }, Settings.antiBotDuration * 1200); + } + + public static void checkAntiBot(final Player player) { + if (antiBotStatus == AntiBotStatus.ACTIVE || antiBotStatus == AntiBotStatus.DISABLED) { + return; + } + if (plugin.getPermissionsManager().hasPermission(player, "authme.bypassantibot")) { + return; + } + + antibotPlayers.add(player.getName().toLowerCase()); + if (antibotPlayers.size() > Settings.antiBotSensibility) { + activateAntiBot(); + return; + } + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { + @Override + public void run() { + antibotPlayers.remove(player.getName().toLowerCase()); + } + }, 300); + } + + public enum AntiBotStatus { + LISTENING, + DISABLED, + ACTIVE + } + +} diff --git a/src/main/java/fr/xephi/authme/AuthMe.java b/src/main/java/fr/xephi/authme/AuthMe.java index c253ca5b7..3b8a53dab 100644 --- a/src/main/java/fr/xephi/authme/AuthMe.java +++ b/src/main/java/fr/xephi/authme/AuthMe.java @@ -1,5 +1,46 @@ package fr.xephi.authme; +import com.comphenix.protocol.ProtocolLibrary; +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; +import org.bukkit.Server; +import org.bukkit.World; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.plugin.PluginManager; +import org.bukkit.plugin.java.JavaPlugin; +import org.bukkit.scheduler.BukkitTask; +import org.mcstats.Metrics; +import org.mcstats.Metrics.Graph; + import java.io.BufferedReader; import java.io.InputStreamReader; import java.net.URL; @@ -11,119 +52,136 @@ import java.util.List; import java.util.concurrent.ConcurrentHashMap; import java.util.logging.Logger; -import fr.xephi.authme.listener.*; -import fr.xephi.authme.permission.PermissionsManager; -import org.apache.logging.log4j.LogManager; -import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.Server; -import org.bukkit.World; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.plugin.PluginManager; -import org.bukkit.plugin.RegisteredServiceProvider; -import org.bukkit.plugin.java.JavaPlugin; -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.milkbowl.vault.permission.Permission; -import net.minelink.ctplus.CombatTagPlus; - /** * 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. */ - private static final int PLUGIN_VERSION_CODE = 100; // 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 + 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 Permission vaultGroupManagement; // TODO: Remove this instance, and replace every usage with permissions manager! + // Hooks TODO: Move into modules public Essentials ess; public MultiverseCore multiverse; public CombatTagPlus combatTagPlus; public AuthMeInventoryPacketAdapter inventoryProtector; - // Module manager - private ModuleManager moduleManager; + // Data maps and stuff + // TODO: Move into a manager + public final ConcurrentHashMap sessions = new ConcurrentHashMap<>(); + public final ConcurrentHashMap captcha = new ConcurrentHashMap<>(); + public final ConcurrentHashMap cap = new ConcurrentHashMap<>(); + public final ConcurrentHashMap realIp = new ConcurrentHashMap<>(); - // TODO: Create Manager for fields below - 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 + // If cache is enabled, prevent any connection before the players data caching is completed. + // TODO: Move somewhere private boolean canConnect = true; + private CommandHandler commandHandler = null; + private PermissionsManager permsMan = null; + private Settings settings; + private Messages messages; + private JsonCache playerBackup; + private ModuleManager moduleManager; + /** - * 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) { @@ -131,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 + AntiBot.setupAntiBotService(); + + // 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 BungeeCord 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); @@ -202,16 +437,34 @@ 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 console filter. + */ + private void setupConsoleFilter() { + if (Settings.removePassword) { + ConsoleFilter filter = new ConsoleFilter(); + 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"); + } + } + } - // Setup messages - m = Messages.getInstance(); - - // Start the metrics service + /** + * Set up Metrics. + */ + private void setupMetrics() { try { Metrics metrics = new Metrics(this); Graph messagesLanguage = metrics.createGraph("Messages language"); @@ -242,158 +495,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); - } - - // Find Permissions - checkVault(); - - // 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 @@ -407,12 +516,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(); @@ -426,6 +530,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) { @@ -436,22 +542,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(); @@ -525,21 +618,6 @@ public class AuthMe extends JavaPlugin { }); } - // Check the presence of the Vault plugin and a permissions provider - public void checkVault() { - if (server.getPluginManager().isPluginEnabled("Vault")) { - RegisteredServiceProvider permissionProvider = server.getServicesManager().getRegistration(net.milkbowl.vault.permission.Permission.class); - if (permissionProvider != null) { - vaultGroupManagement = permissionProvider.getProvider(); - ConsoleLogger.info("Vault detected, hooking with the " + vaultGroupManagement.getName() + " group management system..."); - } else { - ConsoleLogger.showError("Vault detected, but I can't find any group management plugin to hook with!"); - } - } else { - vaultGroupManagement = null; - } - } - // Get the Multiverse plugin public void checkMultiverse() { if (Settings.multiverse && server.getPluginManager().isPluginEnabled("Multiverse-Core")) { @@ -560,7 +638,7 @@ public class AuthMe extends JavaPlugin { try { ess = (Essentials) server.getPluginManager().getPlugin("Essentials"); ConsoleLogger.info("Hooked correctly with Essentials"); - } catch (Exception | NoClassDefFoundError ingnored) { + } catch (Exception | NoClassDefFoundError ignored) { ess = null; } } else { @@ -585,7 +663,7 @@ public class AuthMe extends JavaPlugin { try { combatTagPlus = (CombatTagPlus) server.getPluginManager().getPlugin("CombatTagPlus"); ConsoleLogger.info("Hooked correctly with CombatTagPlus"); - } catch (Exception | NoClassDefFoundError ingnored) { + } catch (Exception | NoClassDefFoundError ignored) { combatTagPlus = null; } } else { @@ -595,60 +673,28 @@ public class AuthMe extends JavaPlugin { // Check the presence of the ProtocolLib plugin public void checkProtocolLib() { - if (Settings.protectInventoryBeforeLogInEnabled) { - if (server.getPluginManager().isPluginEnabled("ProtocolLib")) { - inventoryProtector = new AuthMeInventoryPacketAdapter(this); - inventoryProtector.register(); - } else { + if (!server.getPluginManager().isPluginEnabled("ProtocolLib")) { + if (Settings.protectInventoryBeforeLogInEnabled) { ConsoleLogger.showError("WARNING!!! The protectInventory feature requires ProtocolLib! Disabling it..."); Settings.protectInventoryBeforeLogInEnabled = false; + getSettings().set("settings.restrictions.ProtectInventoryBeforeLogIn", false); + } + return; + } + + if (Settings.protectInventoryBeforeLogInEnabled) { + if (inventoryProtector == null) { + inventoryProtector = new AuthMeInventoryPacketAdapter(this); + inventoryProtector.register(); + } + } else { + if (inventoryProtector != null) { + ProtocolLibrary.getProtocolManager().removePacketListener(inventoryProtector); + inventoryProtector = null; } } } - /** - * 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))) { @@ -706,19 +752,15 @@ public class AuthMe extends JavaPlugin { } ConsoleLogger.info("AutoPurging the Database: " + cleared.size() + " accounts removed!"); if (Settings.purgeEssentialsFile && this.ess != null) - dataManager.purgeEssentials(cleared); // name to UUID convertion - // needed with latest versions + dataManager.purgeEssentials(cleared); if (Settings.purgePlayerDat) - dataManager.purgeDat(cleared); // name to UUID convertion needed - // with latest versions of MC + dataManager.purgeDat(cleared); if (Settings.purgeLimitedCreative) dataManager.purgeLimitedCreative(cleared); if (Settings.purgeAntiXray) - dataManager.purgeAntiXray(cleared); // IDK if it uses UUID or - // names... (Actually it purges - // only names!) + dataManager.purgeAntiXray(cleared); if (Settings.purgePermissions) - dataManager.purgePermissions(cleared, vaultGroupManagement); + dataManager.purgePermissions(cleared); } // Return the spawn location of a player @@ -743,12 +785,12 @@ public class AuthMe extends JavaPlugin { return spawnLoc; } - // Return the default spawnpoint of a world + // Return the default spawn point of a world private Location getDefaultSpawn(World world) { return world.getSpawnLocation(); } - // Return the multiverse spawnpoint of a world + // Return the multiverse spawn point of a world private Location getMultiverseSpawn(World world) { if (multiverse != null && Settings.multiverse) { try { @@ -760,7 +802,7 @@ public class AuthMe extends JavaPlugin { return null; } - // Return the essentials spawnpoint + // Return the essentials spawn point private Location getEssentialsSpawn() { if (essentialsSpawn != null) { return essentialsSpawn; @@ -768,7 +810,7 @@ public class AuthMe extends JavaPlugin { return null; } - // Return the authme soawnpoint + // Return the AuthMe spawn point private Location getAuthMeSpawn(Player player) { if ((!database.isAuthAvailable(player.getName().toLowerCase()) || !player.hasPlayedBefore()) && (Spawn.getInstance().getFirstSpawn() != null)) { return Spawn.getInstance().getFirstSpawn(); @@ -779,15 +821,6 @@ public class AuthMe extends JavaPlugin { return player.getWorld().getSpawnLocation(); } - public void switchAntiBotMod(boolean mode) { - this.antibotMod = mode; - Settings.switchAntiBotMod(mode); - } - - public boolean getAntiBotModMode() { - return this.antibotMod; - } - private void recallEmail() { if (!Settings.recallEmail) return; @@ -802,7 +835,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"); } } } @@ -810,8 +843,7 @@ public class AuthMe extends JavaPlugin { }, 1, 1200 * Settings.delayRecall); } - - public String replaceAllInfos(String message, Player player) { + public String replaceAllInfo(String message, Player player) { int playersOnline = Utils.getOnlinePlayers().size(); message = message.replace("&", "\u00a7"); message = message.replace("{PLAYER}", player.getName()); @@ -822,11 +854,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(); @@ -835,12 +866,11 @@ public class AuthMe extends JavaPlugin { ip = realIp.get(name); } if (Settings.checkVeryGames) - if (getVeryGamesIP(player) != null) - ip = getVeryGamesIP(player); + if (getVeryGamesIp(player) != null) + ip = getVeryGamesIp(player); return ip; } - public boolean isLoggedIp(String name, String ip) { int count = 0; for (Player player : Utils.getOnlinePlayers()) { @@ -850,7 +880,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()) { @@ -860,7 +889,6 @@ public class AuthMe extends JavaPlugin { return count >= Settings.getMaxJoinPerIp; } - public ModuleManager getModuleManager() { return moduleManager; } @@ -868,19 +896,20 @@ public class AuthMe extends JavaPlugin { /** * Gets a player's real IP through VeryGames method. * - * @param player the player to process + * @param player The player to process. * - * @return the real IP of the player + * @return The real IP of the player. */ + // TODO: Cache the result @Deprecated - public String getVeryGamesIP(Player player) { + public String getVeryGamesIp(Player player) { String realIP = player.getAddress().getAddress().getHostAddress(); String sUrl = "http://monitor-1.verygames.net/api/?action=ipclean-real-ip&out=raw&ip=%IP%&port=%PORT%"; sUrl = sUrl.replace("%IP%", player.getAddress().getAddress().getHostAddress()).replace("%PORT%", "" + player.getAddress().getPort()); try { URL url = new URL(sUrl); - URLConnection urlc = url.openConnection(); - BufferedReader in = new BufferedReader(new InputStreamReader(urlc.getInputStream())); + URLConnection urlCon = url.openConnection(); + BufferedReader in = new BufferedReader(new InputStreamReader(urlCon.getInputStream())); String inputLine = in.readLine(); if (inputLine != null && !inputLine.isEmpty() && !inputLine.equalsIgnoreCase("error") && !inputLine.contains("error")) { realIP = inputLine; @@ -890,19 +919,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; } @@ -910,20 +926,16 @@ 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). + * @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. + * @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) @@ -934,27 +946,10 @@ public class AuthMe extends JavaPlugin { } /** - * Get the current installed AuthMeReloaded version name. - * - * @return The version name of the currently installed AuthMeReloaded - * instance. + * Return 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; } + } diff --git a/src/main/java/fr/xephi/authme/ConsoleFilter.java b/src/main/java/fr/xephi/authme/ConsoleFilter.java index 668ff2066..7e12ef10e 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,11 @@ 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 { @@ -29,8 +31,8 @@ public class ConsoleFilter implements Filter { return true; if (!logM.contains("/login ") && !logM.contains("/l ") && !logM.contains("/reg ") && !logM.contains("/changepassword ") && !logM.contains("/unregister ") && !logM.contains("/authme register ") && !logM.contains("/authme changepassword ") && !logM.contains("/authme reg ") && !logM.contains("/authme cp ") && !logM.contains("/register ")) return true; - String playername = record.getMessage().split(" ")[0]; - record.setMessage(playername + " issued an AuthMe command!"); + String playerName = record.getMessage().split(" ")[0]; + record.setMessage(playerName + " issued an AuthMe command!"); return true; } catch (NullPointerException npe) { return true; diff --git a/src/main/java/fr/xephi/authme/ConsoleLogger.java b/src/main/java/fr/xephi/authme/ConsoleLogger.java index 1e58e9138..6009bc3a1 100644 --- a/src/main/java/fr/xephi/authme/ConsoleLogger.java +++ b/src/main/java/fr/xephi/authme/ConsoleLogger.java @@ -1,79 +1,82 @@ package fr.xephi.authme; +import com.google.common.base.Throwables; +import fr.xephi.authme.settings.Settings; +import fr.xephi.authme.util.StringUtils; +import fr.xephi.authme.util.Wrapper; + import java.io.IOException; import java.nio.file.Files; import java.nio.file.StandardOpenOption; import java.text.DateFormat; 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 { +public final class ConsoleLogger { - private static final Logger log = AuthMe.getInstance().getLogger(); + private static Wrapper wrapper = new Wrapper(AuthMe.getInstance()); private static final DateFormat df = new SimpleDateFormat("[MM-dd HH:mm:ss]"); + private ConsoleLogger() { + // Service class + } + /** - * Method info. + * 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); + wrapper.getLogger().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); + wrapper.getLogger().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(), - StandardOpenOption.APPEND, - StandardOpenOption.CREATE); + Files.write(Settings.LOG_FILE.toPath(), (dateTime + ": " + message + StringUtils.newline).getBytes(), + StandardOpenOption.APPEND, + StandardOpenOption.CREATE); } catch (IOException ignored) { } } /** - * 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 edc96eee7..c3847f3b6 100644 --- a/src/main/java/fr/xephi/authme/DataManager.java +++ b/src/main/java/fr/xephi/authme/DataManager.java @@ -1,238 +1,269 @@ -package fr.xephi.authme; - -import java.io.File; -import java.util.List; -import java.util.concurrent.Callable; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.Future; - -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; -import net.milkbowl.vault.permission.Permission; - -/** - */ -public class DataManager { - - public AuthMe plugin; - - /** - * Constructor for DataManager. - * @param plugin AuthMe - */ - public DataManager(AuthMe plugin) { - this.plugin = plugin; - } - - public void run() { - } - - /** - * Method getOfflinePlayer. - * @param name String - - * @return OfflinePlayer */ - public synchronized OfflinePlayer getOfflinePlayer(final String name) { - ExecutorService executor = Executors.newSingleThreadExecutor(); - Future result = executor.submit(new Callable() { - - public synchronized OfflinePlayer call() throws Exception { - OfflinePlayer result = null; - try { - for (OfflinePlayer op : Bukkit.getOfflinePlayers()) - if (op.getName().equalsIgnoreCase(name)) { - result = op; - break; - } - } catch (Exception e) { - } - return result; - } - }); - try { - return result.get(); - } catch (Exception e) { - return (null); - } finally { - executor.shutdown(); - } - } - - /** - * Method purgeAntiXray. - * @param cleared List - */ - public synchronized void purgeAntiXray(List cleared) { - int i = 0; - for (String name : cleared) { - try { - org.bukkit.OfflinePlayer player = getOfflinePlayer(name); - if (player == null) - continue; - String playerName = player.getName(); - File playerFile = new File("." + File.separator + "plugins" + File.separator + "AntiXRayData" + File.separator + "PlayerData" + File.separator + playerName); - if (playerFile.exists()) { - playerFile.delete(); - i++; - } - } catch (Exception e) { - } - } - ConsoleLogger.info("AutoPurgeDatabase : Remove " + i + " AntiXRayData Files"); - } - - /** - * Method purgeLimitedCreative. - * @param cleared List - */ - public synchronized void purgeLimitedCreative(List cleared) { - int i = 0; - for (String name : cleared) { - try { - org.bukkit.OfflinePlayer player = getOfflinePlayer(name); - if (player == null) - continue; - String playerName = player.getName(); - File playerFile = new File("." + File.separator + "plugins" + File.separator + "LimitedCreative" + File.separator + "inventories" + File.separator + playerName + ".yml"); - if (playerFile.exists()) { - playerFile.delete(); - i++; - } - playerFile = new File("." + File.separator + "plugins" + File.separator + "LimitedCreative" + File.separator + "inventories" + File.separator + playerName + "_creative.yml"); - if (playerFile.exists()) { - playerFile.delete(); - i++; - } - playerFile = new File("." + File.separator + "plugins" + File.separator + "LimitedCreative" + File.separator + "inventories" + File.separator + playerName + "_adventure.yml"); - if (playerFile.exists()) { - playerFile.delete(); - i++; - } - } catch (Exception e) { - } - } - ConsoleLogger.info("AutoPurgeDatabase : Remove " + i + " LimitedCreative Survival, Creative and Adventure files"); - } - - /** - * Method purgeDat. - * @param cleared List - */ - public synchronized void purgeDat(List cleared) { - int i = 0; - for (String name : cleared) { - try { - org.bukkit.OfflinePlayer player = getOfflinePlayer(name); - if (player == null) { - continue; - } - - try { - 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) { - File playerFile = new File(plugin.getServer().getWorldContainer() + File.separator + Settings.defaultWorld + File.separator + "players" + File.separator + player.getName() + ".dat"); - if (playerFile.exists()) { - playerFile.delete(); - i++; - } - } - } catch (Exception ignore) { - } - } - ConsoleLogger.info("AutoPurgeDatabase : Remove " + i + " .dat Files"); - } - - /** - * Method purgeEssentials. - * @param cleared List - */ - @SuppressWarnings("deprecation") - public void purgeEssentials(List cleared) { - 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"); - playerFile.delete(); - i++; - } catch (Exception e) { - File playerFile = new File(plugin.ess.getDataFolder() + File.separator + "userdata" + File.separator + name + ".yml"); - if (playerFile.exists()) { - playerFile.delete(); - i++; - } - } - } - ConsoleLogger.info("AutoPurgeDatabase : Remove " + i + " EssentialsFiles"); - } - - /** - * Method purgePermissions. - * @param cleared List - * @param permission Permission - */ - public synchronized void purgePermissions(List cleared, Permission permission) { - int i = 0; - for (String name : cleared) { - try { - OfflinePlayer p = this.getOfflinePlayer(name); - for (String group : permission.getPlayerGroups((Player) p)) { - permission.playerRemoveGroup(null, p, group); - } - i++; - } catch (Exception e) { - } - } - ConsoleLogger.info("AutoPurgeDatabase : Remove " + i + " Permissions"); - } - - /** - * Method isOnline. - * @param player Player - * @param name String - - * @return boolean */ - public boolean isOnline(Player player, final String name) { - if (player.isOnline()) - return true; - ExecutorService executor = Executors.newSingleThreadExecutor(); - Future result = executor.submit(new Callable() { - - @Override - public synchronized Boolean call() throws Exception { - for (OfflinePlayer op : Utils.getOnlinePlayers()) - if (op.getName().equalsIgnoreCase(name)) { - return true; - } - return false; - } - }); - try { - return result.get(); - } catch (Exception e) { - return false; - } finally { - executor.shutdown(); - } - } - - /** - * Method getOnlinePlayerLower. - * @param name String - - * @return Player */ - public Player getOnlinePlayerLower(String name) { - name = name.toLowerCase(); - for (Player player : Utils.getOnlinePlayers()) { - if (player.getName().equalsIgnoreCase(name)) - return player; - } - return null; - } -} +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; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; + +/** + */ +public class DataManager { + + public final AuthMe plugin; + + /** + * Constructor for DataManager. + * + * @param plugin AuthMe + */ + public DataManager(AuthMe plugin) { + this.plugin = plugin; + } + + /** + * Method getOfflinePlayer. + * + * @param name String + * + * @return OfflinePlayer + */ + public synchronized OfflinePlayer getOfflinePlayer(final String name) { + ExecutorService executor = Executors.newSingleThreadExecutor(); + Future result = executor.submit(new Callable() { + + public synchronized OfflinePlayer call() throws Exception { + OfflinePlayer result = null; + try { + for (OfflinePlayer op : Bukkit.getOfflinePlayers()) + if (op.getName().equalsIgnoreCase(name)) { + result = op; + break; + } + } catch (Exception ignored) { + } + return result; + } + }); + try { + return result.get(); + } catch (Exception e) { + return (null); + } finally { + executor.shutdown(); + } + } + + /** + * Method purgeAntiXray. + * + * @param cleared List + */ + public synchronized void purgeAntiXray(List cleared) { + int i = 0; + for (String name : cleared) { + try { + org.bukkit.OfflinePlayer player = getOfflinePlayer(name); + if (player == null) + continue; + String playerName = player.getName(); + File playerFile = new File("." + File.separator + "plugins" + File.separator + "AntiXRayData" + File.separator + "PlayerData" + File.separator + playerName); + if (playerFile.exists()) { + //noinspection ResultOfMethodCallIgnored + playerFile.delete(); + i++; + } + } catch (Exception ignored) { + } + } + ConsoleLogger.info("AutoPurgeDatabase : Remove " + i + " AntiXRayData Files"); + } + + /** + * Method purgeLimitedCreative. + * + * @param cleared List + */ + public synchronized void purgeLimitedCreative(List cleared) { + int i = 0; + for (String name : cleared) { + try { + org.bukkit.OfflinePlayer player = getOfflinePlayer(name); + if (player == null) + continue; + String playerName = player.getName(); + File playerFile = new File("." + File.separator + "plugins" + File.separator + "LimitedCreative" + File.separator + "inventories" + File.separator + playerName + ".yml"); + if (playerFile.exists()) { + //noinspection ResultOfMethodCallIgnored + playerFile.delete(); + i++; + } + playerFile = new File("." + File.separator + "plugins" + File.separator + "LimitedCreative" + File.separator + "inventories" + File.separator + playerName + "_creative.yml"); + if (playerFile.exists()) { + //noinspection ResultOfMethodCallIgnored + playerFile.delete(); + i++; + } + playerFile = new File("." + File.separator + "plugins" + File.separator + "LimitedCreative" + File.separator + "inventories" + File.separator + playerName + "_adventure.yml"); + if (playerFile.exists()) { + //noinspection ResultOfMethodCallIgnored + playerFile.delete(); + i++; + } + } catch (Exception ignored) { + } + } + ConsoleLogger.info("AutoPurgeDatabase : Remove " + i + " LimitedCreative Survival, Creative and Adventure files"); + } + + /** + * Method purgeDat. + * + * @param cleared List + */ + public synchronized void purgeDat(List cleared) { + int i = 0; + for (String name : cleared) { + try { + org.bukkit.OfflinePlayer player = getOfflinePlayer(name); + if (player == null) { + continue; + } + + try { + File playerFile = new File(plugin.getServer().getWorldContainer() + File.separator + Settings.defaultWorld + File.separator + "players" + File.separator + player.getUniqueId() + ".dat"); + //noinspection ResultOfMethodCallIgnored + playerFile.delete(); + i++; + } 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()) { + //noinspection ResultOfMethodCallIgnored + playerFile.delete(); + i++; + } + } + } catch (Exception ignore) { + } + } + ConsoleLogger.info("AutoPurgeDatabase : Remove " + i + " .dat Files"); + } + + /** + * Method purgeEssentials. + * + * @param cleared List + */ + @SuppressWarnings("deprecation") + public void purgeEssentials(List cleared) { + 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"); + //noinspection ResultOfMethodCallIgnored + playerFile.delete(); + i++; + } catch (Exception e) { + File playerFile = new File(plugin.ess.getDataFolder() + File.separator + "userdata" + File.separator + name + ".yml"); + if (playerFile.exists()) { + //noinspection ResultOfMethodCallIgnored + playerFile.delete(); + i++; + } + } + } + ConsoleLogger.info("AutoPurgeDatabase : Remove " + i + " EssentialsFiles"); + } + + // 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) + ConsoleLogger.showError("Unable to access permissions manager instance!"); + assert permsMan != null; + + int i = 0; + for (String name : cleared) { + try { + permsMan.removeAllGroups(this.getOnlinePlayerLower(name.toLowerCase())); + i++; + } catch (Exception ignored) { + } + } + ConsoleLogger.info("AutoPurgeDatabase : Removed " + i + " permissions"); + + /*int i = 0; + for (String name : cleared) { + try { + OfflinePlayer p = this.getOfflinePlayer(name); + for (String group : permission.getPlayerGroups((Player) p)) { + permission.playerRemoveGroup(null, p, group); + } + i++; + } catch (Exception e) { + } + } + ConsoleLogger.info("AutoPurgeDatabase : Remove " + i + " Permissions");*/ + } + + /** + * Method isOnline. + * + * @param player Player + * @param name String + * + * @return boolean + */ + public boolean isOnline(Player player, final String name) { + if (player.isOnline()) + return true; + ExecutorService executor = Executors.newSingleThreadExecutor(); + Future result = executor.submit(new Callable() { + + @Override + public synchronized Boolean call() throws Exception { + for (OfflinePlayer op : Utils.getOnlinePlayers()) + if (op.getName().equalsIgnoreCase(name)) { + return true; + } + return false; + } + }); + try { + return result.get(); + } catch (Exception e) { + return false; + } finally { + executor.shutdown(); + } + } + + /** + * Method getOnlinePlayerLower. + * + * @param name String + * + * @return Player + */ + public Player getOnlinePlayerLower(String name) { + name = name.toLowerCase(); + for (Player player : Utils.getOnlinePlayers()) { + if (player.getName().equalsIgnoreCase(name)) + return player; + } + return null; + } +} diff --git a/src/main/java/fr/xephi/authme/ImageGenerator.java b/src/main/java/fr/xephi/authme/ImageGenerator.java index 2b6a187e3..e529efabd 100644 --- a/src/main/java/fr/xephi/authme/ImageGenerator.java +++ b/src/main/java/fr/xephi/authme/ImageGenerator.java @@ -1,40 +1,40 @@ -package fr.xephi.authme; - -import java.awt.Color; -import java.awt.Font; -import java.awt.GradientPaint; -import java.awt.Graphics2D; -import java.awt.image.BufferedImage; - -/** - */ -public class ImageGenerator { - - private String pass; - /** - * Constructor for ImageGenerator. - * @param pass String - */ - public ImageGenerator(String pass) { - this.pass = pass; - } - - /** - * Method generateImage. - - * @return BufferedImage */ - public BufferedImage generateImage() { - BufferedImage image = new BufferedImage(200, 60, BufferedImage.TYPE_BYTE_INDEXED); - Graphics2D graphics = image.createGraphics(); - graphics.setColor(Color.BLACK); - graphics.fillRect(0, 0, 200, 40); - GradientPaint gradientPaint = new GradientPaint(10, 5, Color.WHITE, 20, 10, Color.WHITE, true); - graphics.setPaint(gradientPaint); - Font font = new Font("Comic Sans MS", Font.BOLD, 30); - graphics.setFont(font); - graphics.drawString(pass, 5, 30); - graphics.dispose(); - image.flush(); - return image; - } -} +package fr.xephi.authme; + +import java.awt.*; +import java.awt.image.BufferedImage; + +/** + */ +public class ImageGenerator { + + private final String pass; + + /** + * Constructor for ImageGenerator. + * + * @param pass String + */ + public ImageGenerator(String pass) { + this.pass = pass; + } + + /** + * Method generateImage. + * + * @return BufferedImage + */ + public BufferedImage generateImage() { + BufferedImage image = new BufferedImage(200, 60, BufferedImage.TYPE_BYTE_INDEXED); + Graphics2D graphics = image.createGraphics(); + graphics.setColor(Color.BLACK); + graphics.fillRect(0, 0, 200, 40); + GradientPaint gradientPaint = new GradientPaint(10, 5, Color.WHITE, 20, 10, Color.WHITE, true); + graphics.setPaint(gradientPaint); + Font font = new Font("Comic Sans MS", Font.BOLD, 30); + graphics.setFont(font); + graphics.drawString(pass, 5, 30); + graphics.dispose(); + image.flush(); + return image; + } +} diff --git a/src/main/java/fr/xephi/authme/Log4JFilter.java b/src/main/java/fr/xephi/authme/Log4JFilter.java index 917a75369..581699f08 100644 --- a/src/main/java/fr/xephi/authme/Log4JFilter.java +++ b/src/main/java/fr/xephi/authme/Log4JFilter.java @@ -1,56 +1,97 @@ 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 +104,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..6dbb7e4f9 100644 --- a/src/main/java/fr/xephi/authme/PerformBackup.java +++ b/src/main/java/fr/xephi/authme/PerformBackup.java @@ -1,44 +1,71 @@ 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 { - 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; + final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd_HH-mm"); + final String dateString = format.format(new Date()); + private final String dbName = Settings.getMySQLDatabase; + private final String dbUserName = Settings.getMySQLUsername; + private final String dbPassword = Settings.getMySQLPassword; + private final String tblname = Settings.getMySQLTablename; + private final 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); } + /** + * Perform a backup with the given reason. + * + * @param cause BackupCause The cause of the backup. + */ + public void doBackup(BackupCause cause) { + if (!Settings.isBackupActivated) { + ConsoleLogger.showError("Can't perform a Backup: disabled in configuration. Cause of the Backup: " + cause.name()); + } + // 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. Cause of the Backup: " + cause.name()); + } else { + ConsoleLogger.showError("Error while performing a backup! Cause of the Backup: " + cause.name()); + } + } + /** * Method doBackup. - - * @return boolean */ + * + * @return boolean + */ public boolean doBackup() { switch (Settings.getDataSource) { @@ -55,8 +82,9 @@ public class PerformBackup { /** * Method MySqlBackup. - - * @return boolean */ + * + * @return boolean + */ private boolean MySqlBackup() { File dirBackup = new File(AuthMe.getInstance().getDataFolder() + "/backups"); @@ -98,9 +126,11 @@ 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,18 +147,16 @@ 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) { + if (isWin.contains("win")) { if (new File(windowsPath + "\\bin\\mysqldump.exe").exists()) { return true; } else { @@ -139,14 +167,18 @@ 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 +193,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 +216,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..397ddac91 100644 --- a/src/main/java/fr/xephi/authme/SendMailSSL.java +++ b/src/main/java/fr/xephi/authme/SendMailSSL.java @@ -1,28 +1,26 @@ 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 $ */ public class SendMailSSL { - public AuthMe plugin; + public final AuthMe plugin; /** * Constructor for SendMailSSL. + * * @param plugin AuthMe */ public SendMailSSL(AuthMe plugin) { @@ -31,19 +29,20 @@ public class SendMailSSL { /** * Method main. - * @param auth PlayerAuth + * + * @param auth PlayerAuth * @param newPass String */ public void main(final PlayerAuth auth, final String newPass) { - String sendername; + String senderName; if (Settings.getmailSenderName == null || Settings.getmailSenderName.isEmpty()) { - sendername = Settings.getmailAccount; + senderName = Settings.getmailAccount; } else { - sendername = Settings.getmailSenderName; + senderName = Settings.getmailSenderName; } - final String sender = sendername; + final String sender = senderName; final int port = Settings.getMailPort; final String acc = Settings.getmailAccount; final String subject = Settings.getMailSubject; @@ -91,6 +90,7 @@ public class SendMailSSL { ConsoleLogger.showError("Fail to send a mail to " + mail); } if (file != null) + //noinspection ResultOfMethodCallIgnored file.delete(); } catch (Exception e) { diff --git a/src/main/java/fr/xephi/authme/api/API.java b/src/main/java/fr/xephi/authme/api/API.java index 6119f28eb..e849e7950 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,20 @@ 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 +70,11 @@ public class API { /** * Method getLastLocation. + * * @param player Player - - * @return Location */ + * + * @return Location + */ @Deprecated public static Location getLastLocation(Player player) { try { @@ -121,25 +94,26 @@ 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); - } catch (NullPointerException npe) { + } catch (NullPointerException ignored) { } } /** - * * @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 +121,14 @@ 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 +143,11 @@ 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 { @@ -183,10 +157,7 @@ public class API { return false; } PlayerAuth auth = new PlayerAuth(name, hash, "198.18.0.1", 0, "your@email.com", playerName); - if (!instance.database.saveAuth(auth)) { - return false; - } - return true; + return instance.database.saveAuth(auth); } catch (NoSuchAlgorithmException ex) { return false; } @@ -195,7 +166,6 @@ public class API { /** * Force a player to login * - * @param player * player */ @Deprecated @@ -203,4 +173,34 @@ 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..cfe4508f0 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; + public final AuthMe plugin; /** * Constructor for NewAPI. + * * @param plugin AuthMe */ public NewAPI(AuthMe plugin) { @@ -33,17 +32,18 @@ public class NewAPI { /** * Constructor for NewAPI. - * @param serv Server + * + * @param server Server */ - public NewAPI(Server serv) { - this.plugin = (AuthMe) serv.getPluginManager().getPlugin("AuthMe"); + public NewAPI(Server server) { + this.plugin = (AuthMe) server.getPluginManager().getPlugin("AuthMe"); } /** * Hook into AuthMe * - - * @return AuthMe plugin */ + * @return AuthMe plugin + */ public static NewAPI getInstance() { if (singleton != null) return singleton; @@ -58,44 +58,47 @@ 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 +115,21 @@ 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 +145,11 @@ 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 +167,6 @@ public class NewAPI { /** * Force a player to login * - * @param player * player */ public void forceLogin(Player player) { @@ -174,35 +176,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..8bf22fb63 100644 --- a/src/main/java/fr/xephi/authme/cache/auth/PlayerAuth.java +++ b/src/main/java/fr/xephi/authme/cache/auth/PlayerAuth.java @@ -16,16 +16,17 @@ public class PlayerAuth { private double z; private String world; private String salt; - private int groupId; + private final int groupId; private String email; private String realName; /** * 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,22 @@ 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 +419,9 @@ public class PlayerAuth { /** * Method hashCode. - - * @return int */ + * + * @return int + */ @Override public int hashCode() { int hashCode = 7; @@ -396,17 +432,18 @@ public class PlayerAuth { /** * Method toString. - - * @return String */ + * + * @return String + */ @Override public String toString() { return ("Player : " + nickname + " | " + realName - + " ! IP : " + ip - + " ! LastLogin : " + lastLogin - + " ! LastPosition : " + x + "," + y + "," + z + "," + world - + " ! Email : " + email - + " ! Hash : " + hash - + " ! Salt : " + salt); + + " ! IP : " + ip + + " ! LastLogin : " + lastLogin + + " ! LastPosition : " + x + "," + y + "," + z + "," + world + + " ! Email : " + email + + " ! Hash : " + hash + + " ! Salt : " + salt); } } 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..4f9d21878 100644 --- a/src/main/java/fr/xephi/authme/cache/auth/PlayerCache.java +++ b/src/main/java/fr/xephi/authme/cache/auth/PlayerCache.java @@ -7,14 +7,27 @@ import java.util.concurrent.ConcurrentHashMap; public class PlayerCache { private volatile static PlayerCache singleton; - private ConcurrentHashMap cache; + private final ConcurrentHashMap cache; private 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,40 @@ 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..e567229d9 100644 --- a/src/main/java/fr/xephi/authme/cache/backup/DataFileCache.java +++ b/src/main/java/fr/xephi/authme/cache/backup/DataFileCache.java @@ -4,15 +4,16 @@ package fr.xephi.authme.cache.backup; */ public class DataFileCache { - private String group; - private boolean operator; - private boolean flying; + private final String group; + private final boolean operator; + private final boolean flying; /** * 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..b07c74d9e 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 { @@ -35,15 +25,16 @@ public class JsonCache { ConsoleLogger.showError("Failed to create cache directory."); } gson = new GsonBuilder() - .registerTypeAdapter(DataFileCache.class, new PlayerDataSerializer()) - .registerTypeAdapter(DataFileCache.class, new PlayerDataDeserializer()) - .setPrettyPrinting() - .create(); + .registerTypeAdapter(DataFileCache.class, new PlayerDataSerializer()) + .registerTypeAdapter(DataFileCache.class, new PlayerDataDeserializer()) + .setPrettyPrinting() + .create(); } /** * Method createCache. - * @param player Player + * + * @param player Player * @param playerData DataFileCache */ public void createCache(Player player, DataFileCache playerData) { @@ -77,9 +68,11 @@ public class JsonCache { /** * Method readCache. + * * @param player Player - - * @return DataFileCache */ + * + * @return DataFileCache + */ public DataFileCache readCache(Player player) { String path; try { @@ -103,24 +96,42 @@ 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 +139,13 @@ 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 +172,26 @@ 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 7205c7081..69774e221 100644 --- a/src/main/java/fr/xephi/authme/cache/limbo/LimboCache.java +++ b/src/main/java/fr/xephi/authme/cache/limbo/LimboCache.java @@ -1,30 +1,31 @@ package fr.xephi.authme.cache.limbo; -import java.util.concurrent.ConcurrentHashMap; - -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; /** */ public class LimboCache { private volatile static LimboCache singleton; - public ConcurrentHashMap cache; - private JsonCache playerData; - public AuthMe plugin; + public final ConcurrentHashMap cache; + public final AuthMe plugin; + private final JsonCache playerData; /** * Constructor for LimboCache. + * * @param plugin AuthMe */ private LimboCache(AuthMe plugin) { @@ -34,8 +35,21 @@ public class LimboCache { } /** - * Method addLimboPlayer. - * @param player Player + * Method getInstance. + * + * @return LimboCache + */ + public static LimboCache getInstance() { + if (singleton == null) { + singleton = new LimboCache(AuthMe.getInstance()); + } + return singleton; + } + + /** + * Add a limbo player. + * + * @param player Player instance to add. */ public void addLimboPlayer(Player player) { String name = player.getName().toLowerCase(); @@ -45,6 +59,12 @@ public class LimboCache { String playerGroup = ""; boolean flying = false; + // Get the permissions manager, and make sure it's valid + PermissionsManager permsMan = this.plugin.getPermissionsManager(); + if (permsMan == null) + ConsoleLogger.showError("Unable to access permissions manager!"); + assert permsMan != null; + if (playerData.doesCacheExist(player)) { DataFileCache cache = playerData.readCache(player); if (cache != null) { @@ -55,14 +75,10 @@ public class LimboCache { } else { operator = player.isOp(); flying = player.isFlying(); - if (plugin.vaultGroupManagement != null) { - try { - playerGroup = plugin.vaultGroupManagement.getPrimaryGroup(player); - } catch (UnsupportedOperationException e) { - ConsoleLogger.showError("Your permission system (" + plugin.vaultGroupManagement.getName() + ") do not support Group system with that config... unhook!"); - plugin.vaultGroupManagement = null; - } - } + + // Check whether groups are supported + if (permsMan.hasGroupSupport()) + playerGroup = permsMan.getPrimaryGroup(player); } if (Settings.isForceSurvivalModeEnabled) { @@ -87,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)); @@ -96,6 +113,7 @@ public class LimboCache { /** * Method deleteLimboPlayer. + * * @param name String */ public void deleteLimboPlayer(String name) { @@ -104,35 +122,29 @@ 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..96c5a9ee9 100644 --- a/src/main/java/fr/xephi/authme/cache/limbo/LimboPlayer.java +++ b/src/main/java/fr/xephi/authme/cache/limbo/LimboPlayer.java @@ -8,7 +8,7 @@ import org.bukkit.scheduler.BukkitTask; */ public class LimboPlayer { - private String name; + private final String name; private Location loc = null; private BukkitTask timeoutTaskId = null; private BukkitTask messageTaskId = null; @@ -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.