Merge origin/enum into local branch

This commit is contained in:
ljacqu 2015-11-25 22:18:21 +01:00
commit 644f7e8541
185 changed files with 10883 additions and 9491 deletions

13
.editorconfig Normal file
View File

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

3
.floo Normal file
View File

@ -0,0 +1,3 @@
{
"url": "https://floobits.com/AuthMe-Team/AuthMeReloaded"
}

123
.flooignore Normal file
View File

@ -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/

53
.gitignore vendored
View File

@ -1,12 +1,7 @@
# Created by https://www.gitignore.io ### Java files ###
### Java ###
*.class *.class
# Mobile Tools for Java (J2ME) # Package Files
.mtj.tmp/
# Package Files #
#*.jar #*.jar
*.war *.war
*.ear *.ear
@ -15,40 +10,27 @@
hs_err_pid* hs_err_pid*
### Intellij ### ### Intellij ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm
# Ignore project files
*.iml *.iml
## Directory-based project format: # Ignore IDEA directory
.idea/ .idea/*
# if you remove the above rule, at least ignore the following:
# User-specific stuff: # Include the project's code style settings file
# .idea/workspace.xml !.idea/codeStyleSettings.xml
# .idea/tasks.xml
# .idea/dictionaries
# Sensitive or high-churn files: # Include the project's dictionary
# .idea/dataSources.ids !.idea/dictionaries/
# .idea/dataSources.xml !.idea/dictionaries/*
# .idea/sqlDataSources.xml
# .idea/dynamic.xml
# .idea/uiDesigner.xml
# Gradle: # File-based project format:
# .idea/gradle.xml
# .idea/libraries
# Mongo Explorer plugin:
# .idea/mongoSettings.xml
## File-based project format:
*.ipr *.ipr
*.iws *.iws
## Plugin-specific files: ### Plugin-specific files: ###
# IntelliJ # IntelliJ
/out/ /out/
@ -64,6 +46,7 @@ crashlytics.properties
crashlytics-build.properties crashlytics-build.properties
### Eclipse ### ### Eclipse ###
*.pydevproject *.pydevproject
.metadata .metadata
@ -103,6 +86,7 @@ local.properties
.texlipse .texlipse
### Maven ### ### Maven ###
target/ target/
pom.xml.tag pom.xml.tag
@ -114,6 +98,7 @@ dependency-reduced-pom.xml
buildNumber.properties buildNumber.properties
### NetBeans ### ### NetBeans ###
nbproject/private/ nbproject/private/
build/ build/
@ -123,3 +108,9 @@ nbdist/
nbactions.xml nbactions.xml
nb-configuration.xml nb-configuration.xml
.nb-gradle/ .nb-gradle/
### Git ###
# Don't exclude the .gitignore itself
!.gitignore

View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectCodeStyleSettingsManager">
<option name="PER_PROJECT_SETTINGS">
<value>
<option name="AUTODETECT_INDENTS" value="false" />
<option name="LINE_SEPARATOR" value="&#10;" />
<option name="JD_ADD_BLANK_AFTER_PARM_COMMENTS" value="true" />
<option name="JD_ADD_BLANK_AFTER_RETURN" value="true" />
<XML>
<option name="XML_LEGACY_SETTINGS_IMPORTED" value="true" />
</XML>
</value>
</option>
<option name="USE_PER_PROJECT_SETTINGS" value="true" />
</component>
</project>

View File

@ -0,0 +1,7 @@
<component name="ProjectDictionaryState">
<dictionary name="Tim">
<words>
<w>authme</w>
</words>
</dictionary>
</component>

1117
pom.xml

File diff suppressed because it is too large Load Diff

View File

@ -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<String> 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
}
}

File diff suppressed because it is too large Load Diff

View File

@ -4,6 +4,7 @@ import java.util.logging.Filter;
import java.util.logging.LogRecord; import java.util.logging.LogRecord;
/** /**
* Console filter Class
* *
* @author Xephi59 * @author Xephi59
* @version $Revision: 1.0 $ * @version $Revision: 1.0 $
@ -15,10 +16,11 @@ public class ConsoleFilter implements Filter {
/** /**
* Method isLoggable. * Method isLoggable.
*
* @param record LogRecord * @param record LogRecord
*
* @return boolean * @see java.util.logging.Filter#isLoggable(LogRecord)
* @return boolean * @see java.util.logging.Filter#isLoggable(LogRecord) */ */
@Override @Override
public boolean isLoggable(LogRecord record) { public boolean isLoggable(LogRecord record) {
try { try {
@ -29,8 +31,8 @@ public class ConsoleFilter implements Filter {
return true; 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 ")) 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; return true;
String playername = record.getMessage().split(" ")[0]; String playerName = record.getMessage().split(" ")[0];
record.setMessage(playername + " issued an AuthMe command!"); record.setMessage(playerName + " issued an AuthMe command!");
return true; return true;
} catch (NullPointerException npe) { } catch (NullPointerException npe) {
return true; return true;

View File

@ -1,79 +1,82 @@
package fr.xephi.authme; 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.io.IOException;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.StandardOpenOption; import java.nio.file.StandardOpenOption;
import java.text.DateFormat; import java.text.DateFormat;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Date; 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 static final DateFormat df = new SimpleDateFormat("[MM-dd HH:mm:ss]");
private ConsoleLogger() {
// Service class
}
/** /**
* Method info. * Print an info message.
*
* @param message String * @param message String
*/ */
public static void info(String message) { public static void info(String message) {
log.info("[AuthMe] " + message); wrapper.getLogger().info(message);
if (Settings.useLogging) { if (!Settings.useLogging) {
String dateTime; return;
synchronized (df) {
dateTime = df.format(new Date());
}
writeLog(dateTime + " " + message);
} }
writeLog("" + message);
} }
/** /**
* Method showError. * Print an error message.
*
* @param message String * @param message String
*/ */
public static void showError(String message) { public static void showError(String message) {
log.warning("[AuthMe] " + message); wrapper.getLogger().warning(message);
if (Settings.useLogging) { if (!Settings.useLogging) {
String dateTime; return;
synchronized (df) {
dateTime = df.format(new Date());
}
writeLog(dateTime + " ERROR: " + message);
} }
writeLog("ERROR: " + message);
} }
/** /**
* Method writeLog. * Write a message into the log file with a TimeStamp.
*
* @param message String * @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 { try {
Files.write(Settings.LOG_FILE.toPath(), (message + NewAPI.newline).getBytes(), Files.write(Settings.LOG_FILE.toPath(), (dateTime + ": " + message + StringUtils.newline).getBytes(),
StandardOpenOption.APPEND, StandardOpenOption.APPEND,
StandardOpenOption.CREATE); StandardOpenOption.CREATE);
} catch (IOException ignored) { } catch (IOException ignored) {
} }
} }
/** /**
* Method writeStackTrace. * Write a StackTrace into the log.
*
* @param ex Exception * @param ex Exception
*/ */
public static void writeStackTrace(Exception ex) { public static void writeStackTrace(Exception ex) {
if (Settings.useLogging) { if (!Settings.useLogging) {
String dateTime; return;
synchronized (df) {
dateTime = df.format(new Date());
}
writeLog(dateTime + " " + Throwables.getStackTraceAsString(ex));
} }
writeLog("" + Throwables.getStackTraceAsString(ex));
} }
} }

View File

@ -1,238 +1,269 @@
package fr.xephi.authme; package fr.xephi.authme;
import java.io.File; import fr.xephi.authme.permission.PermissionsManager;
import java.util.List; import fr.xephi.authme.settings.Settings;
import java.util.concurrent.Callable; import fr.xephi.authme.util.Utils;
import java.util.concurrent.ExecutorService; import org.bukkit.Bukkit;
import java.util.concurrent.Executors; import org.bukkit.OfflinePlayer;
import java.util.concurrent.Future; import org.bukkit.entity.Player;
import org.bukkit.Bukkit; import java.io.File;
import org.bukkit.OfflinePlayer; import java.util.List;
import org.bukkit.entity.Player; import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import fr.xephi.authme.settings.Settings; import java.util.concurrent.Executors;
import fr.xephi.authme.util.Utils; import java.util.concurrent.Future;
import net.milkbowl.vault.permission.Permission;
/**
/** */
*/ public class DataManager {
public class DataManager {
public final AuthMe plugin;
public AuthMe plugin;
/**
/** * Constructor for DataManager.
* Constructor for DataManager. *
* @param plugin AuthMe * @param plugin AuthMe
*/ */
public DataManager(AuthMe plugin) { public DataManager(AuthMe plugin) {
this.plugin = plugin; this.plugin = plugin;
} }
public void run() { /**
} * Method getOfflinePlayer.
*
/** * @param name String
* Method getOfflinePlayer. *
* @param name String * @return OfflinePlayer
*/
* @return OfflinePlayer */ public synchronized OfflinePlayer getOfflinePlayer(final String name) {
public synchronized OfflinePlayer getOfflinePlayer(final String name) { ExecutorService executor = Executors.newSingleThreadExecutor();
ExecutorService executor = Executors.newSingleThreadExecutor(); Future<OfflinePlayer> result = executor.submit(new Callable<OfflinePlayer>() {
Future<OfflinePlayer> result = executor.submit(new Callable<OfflinePlayer>() {
public synchronized OfflinePlayer call() throws Exception {
public synchronized OfflinePlayer call() throws Exception { OfflinePlayer result = null;
OfflinePlayer result = null; try {
try { for (OfflinePlayer op : Bukkit.getOfflinePlayers())
for (OfflinePlayer op : Bukkit.getOfflinePlayers()) if (op.getName().equalsIgnoreCase(name)) {
if (op.getName().equalsIgnoreCase(name)) { result = op;
result = op; break;
break; }
} } catch (Exception ignored) {
} catch (Exception e) { }
} return result;
return result; }
} });
}); try {
try { return result.get();
return result.get(); } catch (Exception e) {
} catch (Exception e) { return (null);
return (null); } finally {
} finally { executor.shutdown();
executor.shutdown(); }
} }
}
/**
/** * Method purgeAntiXray.
* Method purgeAntiXray. *
* @param cleared List<String> * @param cleared List<String>
*/ */
public synchronized void purgeAntiXray(List<String> cleared) { public synchronized void purgeAntiXray(List<String> cleared) {
int i = 0; int i = 0;
for (String name : cleared) { for (String name : cleared) {
try { try {
org.bukkit.OfflinePlayer player = getOfflinePlayer(name); org.bukkit.OfflinePlayer player = getOfflinePlayer(name);
if (player == null) if (player == null)
continue; continue;
String playerName = player.getName(); String playerName = player.getName();
File playerFile = new File("." + File.separator + "plugins" + File.separator + "AntiXRayData" + File.separator + "PlayerData" + File.separator + playerName); File playerFile = new File("." + File.separator + "plugins" + File.separator + "AntiXRayData" + File.separator + "PlayerData" + File.separator + playerName);
if (playerFile.exists()) { if (playerFile.exists()) {
playerFile.delete(); //noinspection ResultOfMethodCallIgnored
i++; playerFile.delete();
} i++;
} catch (Exception e) { }
} } catch (Exception ignored) {
} }
ConsoleLogger.info("AutoPurgeDatabase : Remove " + i + " AntiXRayData Files"); }
} ConsoleLogger.info("AutoPurgeDatabase : Remove " + i + " AntiXRayData Files");
}
/**
* Method purgeLimitedCreative. /**
* @param cleared List<String> * Method purgeLimitedCreative.
*/ *
public synchronized void purgeLimitedCreative(List<String> cleared) { * @param cleared List<String>
int i = 0; */
for (String name : cleared) { public synchronized void purgeLimitedCreative(List<String> cleared) {
try { int i = 0;
org.bukkit.OfflinePlayer player = getOfflinePlayer(name); for (String name : cleared) {
if (player == null) try {
continue; org.bukkit.OfflinePlayer player = getOfflinePlayer(name);
String playerName = player.getName(); if (player == null)
File playerFile = new File("." + File.separator + "plugins" + File.separator + "LimitedCreative" + File.separator + "inventories" + File.separator + playerName + ".yml"); continue;
if (playerFile.exists()) { String playerName = player.getName();
playerFile.delete(); File playerFile = new File("." + File.separator + "plugins" + File.separator + "LimitedCreative" + File.separator + "inventories" + File.separator + playerName + ".yml");
i++; if (playerFile.exists()) {
} //noinspection ResultOfMethodCallIgnored
playerFile = new File("." + File.separator + "plugins" + File.separator + "LimitedCreative" + File.separator + "inventories" + File.separator + playerName + "_creative.yml"); playerFile.delete();
if (playerFile.exists()) { i++;
playerFile.delete(); }
i++; playerFile = new File("." + File.separator + "plugins" + File.separator + "LimitedCreative" + File.separator + "inventories" + File.separator + playerName + "_creative.yml");
} if (playerFile.exists()) {
playerFile = new File("." + File.separator + "plugins" + File.separator + "LimitedCreative" + File.separator + "inventories" + File.separator + playerName + "_adventure.yml"); //noinspection ResultOfMethodCallIgnored
if (playerFile.exists()) { playerFile.delete();
playerFile.delete(); i++;
i++; }
} playerFile = new File("." + File.separator + "plugins" + File.separator + "LimitedCreative" + File.separator + "inventories" + File.separator + playerName + "_adventure.yml");
} catch (Exception e) { if (playerFile.exists()) {
} //noinspection ResultOfMethodCallIgnored
} playerFile.delete();
ConsoleLogger.info("AutoPurgeDatabase : Remove " + i + " LimitedCreative Survival, Creative and Adventure files"); i++;
} }
} catch (Exception ignored) {
/** }
* Method purgeDat. }
* @param cleared List<String> ConsoleLogger.info("AutoPurgeDatabase : Remove " + i + " LimitedCreative Survival, Creative and Adventure files");
*/ }
public synchronized void purgeDat(List<String> cleared) {
int i = 0; /**
for (String name : cleared) { * Method purgeDat.
try { *
org.bukkit.OfflinePlayer player = getOfflinePlayer(name); * @param cleared List<String>
if (player == null) { */
continue; public synchronized void purgeDat(List<String> cleared) {
} int i = 0;
for (String name : cleared) {
try { try {
File playerFile = new File(plugin.getServer().getWorldContainer() + File.separator + Settings.defaultWorld + File.separator + "players" + File.separator + player.getUniqueId() + ".dat"); org.bukkit.OfflinePlayer player = getOfflinePlayer(name);
playerFile.delete(); if (player == null) {
i++; continue;
} 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()) { try {
playerFile.delete(); File playerFile = new File(plugin.getServer().getWorldContainer() + File.separator + Settings.defaultWorld + File.separator + "players" + File.separator + player.getUniqueId() + ".dat");
i++; //noinspection ResultOfMethodCallIgnored
} playerFile.delete();
} i++;
} catch (Exception ignore) { } catch (Exception ignore) {
} File playerFile = new File(plugin.getServer().getWorldContainer() + File.separator + Settings.defaultWorld + File.separator + "players" + File.separator + player.getName() + ".dat");
} if (playerFile.exists()) {
ConsoleLogger.info("AutoPurgeDatabase : Remove " + i + " .dat Files"); //noinspection ResultOfMethodCallIgnored
} playerFile.delete();
i++;
/** }
* Method purgeEssentials. }
* @param cleared List<String> } catch (Exception ignore) {
*/ }
@SuppressWarnings("deprecation") }
public void purgeEssentials(List<String> cleared) { ConsoleLogger.info("AutoPurgeDatabase : Remove " + i + " .dat Files");
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"); * Method purgeEssentials.
playerFile.delete(); *
i++; * @param cleared List<String>
} catch (Exception e) { */
File playerFile = new File(plugin.ess.getDataFolder() + File.separator + "userdata" + File.separator + name + ".yml"); @SuppressWarnings("deprecation")
if (playerFile.exists()) { public void purgeEssentials(List<String> cleared) {
playerFile.delete(); int i = 0;
i++; 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
ConsoleLogger.info("AutoPurgeDatabase : Remove " + i + " EssentialsFiles"); playerFile.delete();
} i++;
} catch (Exception e) {
/** File playerFile = new File(plugin.ess.getDataFolder() + File.separator + "userdata" + File.separator + name + ".yml");
* Method purgePermissions. if (playerFile.exists()) {
* @param cleared List<String> //noinspection ResultOfMethodCallIgnored
* @param permission Permission playerFile.delete();
*/ i++;
public synchronized void purgePermissions(List<String> cleared, Permission permission) { }
int i = 0; }
for (String name : cleared) { }
try { ConsoleLogger.info("AutoPurgeDatabase : Remove " + i + " EssentialsFiles");
OfflinePlayer p = this.getOfflinePlayer(name); }
for (String group : permission.getPlayerGroups((Player) p)) {
permission.playerRemoveGroup(null, p, group); // TODO: What is this method for? Is it correct?
}
i++; /**
} catch (Exception e) { * @param cleared Cleared players.
} */
} public synchronized void purgePermissions(List<String> cleared) {
ConsoleLogger.info("AutoPurgeDatabase : Remove " + i + " Permissions"); // 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!");
* Method isOnline. assert permsMan != null;
* @param player Player
* @param name String int i = 0;
for (String name : cleared) {
* @return boolean */ try {
public boolean isOnline(Player player, final String name) { permsMan.removeAllGroups(this.getOnlinePlayerLower(name.toLowerCase()));
if (player.isOnline()) i++;
return true; } catch (Exception ignored) {
ExecutorService executor = Executors.newSingleThreadExecutor(); }
Future<Boolean> result = executor.submit(new Callable<Boolean>() { }
ConsoleLogger.info("AutoPurgeDatabase : Removed " + i + " permissions");
@Override
public synchronized Boolean call() throws Exception { /*int i = 0;
for (OfflinePlayer op : Utils.getOnlinePlayers()) for (String name : cleared) {
if (op.getName().equalsIgnoreCase(name)) { try {
return true; OfflinePlayer p = this.getOfflinePlayer(name);
} for (String group : permission.getPlayerGroups((Player) p)) {
return false; permission.playerRemoveGroup(null, p, group);
} }
}); i++;
try { } catch (Exception e) {
return result.get(); }
} catch (Exception e) { }
return false; ConsoleLogger.info("AutoPurgeDatabase : Remove " + i + " Permissions");*/
} finally { }
executor.shutdown();
} /**
} * Method isOnline.
*
/** * @param player Player
* Method getOnlinePlayerLower. * @param name String
* @param name String *
* @return boolean
* @return Player */ */
public Player getOnlinePlayerLower(String name) { public boolean isOnline(Player player, final String name) {
name = name.toLowerCase(); if (player.isOnline())
for (Player player : Utils.getOnlinePlayers()) { return true;
if (player.getName().equalsIgnoreCase(name)) ExecutorService executor = Executors.newSingleThreadExecutor();
return player; Future<Boolean> result = executor.submit(new Callable<Boolean>() {
}
return null; @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;
}
}

View File

@ -1,40 +1,40 @@
package fr.xephi.authme; package fr.xephi.authme;
import java.awt.Color; import java.awt.*;
import java.awt.Font; import java.awt.image.BufferedImage;
import java.awt.GradientPaint;
import java.awt.Graphics2D; /**
import java.awt.image.BufferedImage; */
public class ImageGenerator {
/**
*/ private final String pass;
public class ImageGenerator {
/**
private String pass; * Constructor for ImageGenerator.
/** *
* Constructor for ImageGenerator. * @param pass String
* @param pass String */
*/ public ImageGenerator(String pass) {
public ImageGenerator(String pass) { this.pass = pass;
this.pass = pass; }
}
/**
/** * Method generateImage.
* Method generateImage. *
* @return BufferedImage
* @return BufferedImage */ */
public BufferedImage generateImage() { public BufferedImage generateImage() {
BufferedImage image = new BufferedImage(200, 60, BufferedImage.TYPE_BYTE_INDEXED); BufferedImage image = new BufferedImage(200, 60, BufferedImage.TYPE_BYTE_INDEXED);
Graphics2D graphics = image.createGraphics(); Graphics2D graphics = image.createGraphics();
graphics.setColor(Color.BLACK); graphics.setColor(Color.BLACK);
graphics.fillRect(0, 0, 200, 40); graphics.fillRect(0, 0, 200, 40);
GradientPaint gradientPaint = new GradientPaint(10, 5, Color.WHITE, 20, 10, Color.WHITE, true); GradientPaint gradientPaint = new GradientPaint(10, 5, Color.WHITE, 20, 10, Color.WHITE, true);
graphics.setPaint(gradientPaint); graphics.setPaint(gradientPaint);
Font font = new Font("Comic Sans MS", Font.BOLD, 30); Font font = new Font("Comic Sans MS", Font.BOLD, 30);
graphics.setFont(font); graphics.setFont(font);
graphics.drawString(pass, 5, 30); graphics.drawString(pass, 5, 30);
graphics.dispose(); graphics.dispose();
image.flush(); image.flush();
return image; return image;
} }
} }

View File

@ -1,56 +1,97 @@
package fr.xephi.authme; package fr.xephi.authme;
import fr.xephi.authme.util.StringUtils;
import org.apache.logging.log4j.Level; import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.Marker; import org.apache.logging.log4j.Marker;
import org.apache.logging.log4j.core.LogEvent; import org.apache.logging.log4j.core.LogEvent;
import org.apache.logging.log4j.core.Logger; import org.apache.logging.log4j.core.Logger;
import org.apache.logging.log4j.message.Message; import org.apache.logging.log4j.message.Message;
import fr.xephi.authme.util.StringUtils;
/** /**
* Implements a filter for Log4j to skip sensitive AuthMe commands. * Implements a filter for Log4j to skip sensitive AuthMe commands.
*
* @author Xephi59 * @author Xephi59
* @version $Revision: 1.0 $ * @version $Revision: 1.0 $
*/ */
public class Log4JFilter implements org.apache.logging.log4j.core.Filter { 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() { 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 @Override
public Result filter(LogEvent record) { public Result filter(LogEvent record) {
if (record == null) { if (record == null) {
return Result.NEUTRAL; return Result.NEUTRAL;
} }
return validateMessage(record.getMessage()); return validateMessage(record.getMessage());
} }
@Override @Override
public Result filter(Logger arg0, Level arg1, Marker arg2, String message, public Result filter(Logger arg0, Level arg1, Marker arg2, String message,
Object... arg4) { Object... arg4) {
return validateMessage(message); return validateMessage(message);
} }
@Override @Override
public Result filter(Logger arg0, Level arg1, Marker arg2, Object message, public Result filter(Logger arg0, Level arg1, Marker arg2, Object message,
Throwable arg4) { Throwable arg4) {
if (message == null) { if (message == null) {
return Result.NEUTRAL; return Result.NEUTRAL;
} }
return validateMessage(message.toString()); return validateMessage(message.toString());
} }
@Override @Override
public Result filter(Logger arg0, Level arg1, Marker arg2, Message message, public Result filter(Logger arg0, Level arg1, Marker arg2, Message message,
Throwable arg4) { Throwable arg4) {
return validateMessage(message); return validateMessage(message);
} }
@Override @Override
@ -63,41 +104,4 @@ public class Log4JFilter implements org.apache.logging.log4j.core.Filter {
return Result.NEUTRAL; 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;
}
} }

View File

@ -1,44 +1,71 @@
package fr.xephi.authme; 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 fr.xephi.authme.settings.Settings;
import java.io.*;
import java.text.SimpleDateFormat;
import java.util.Date;
/** /**
* The backup management class
* *
* @author stefano * @author stefano
* @version $Revision: 1.0 $ * @version $Revision: 1.0 $
*/ */
public class PerformBackup { public class PerformBackup {
private String dbName = Settings.getMySQLDatabase; final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd_HH-mm");
private String dbUserName = Settings.getMySQLUsername; final String dateString = format.format(new Date());
private String dbPassword = Settings.getMySQLPassword; private final String dbName = Settings.getMySQLDatabase;
private String tblname = Settings.getMySQLTablename; private final String dbUserName = Settings.getMySQLUsername;
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd_HH-mm"); private final String dbPassword = Settings.getMySQLPassword;
String dateString = format.format(new Date()); private final String tblname = Settings.getMySQLTablename;
private String path = AuthMe.getInstance().getDataFolder() + File.separator + "backups" + File.separator + "backup" + dateString; private final String path = AuthMe.getInstance().getDataFolder() + File.separator + "backups" + File.separator + "backup" + dateString;
private AuthMe instance; private AuthMe instance;
/** /**
* Constructor for PerformBackup. * Constructor for PerformBackup.
*
* @param instance AuthMe * @param instance AuthMe
*/ */
public PerformBackup(AuthMe instance) { public PerformBackup(AuthMe instance) {
this.setInstance(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. * Method doBackup.
*
* @return boolean */ * @return boolean
*/
public boolean doBackup() { public boolean doBackup() {
switch (Settings.getDataSource) { switch (Settings.getDataSource) {
@ -55,8 +82,9 @@ public class PerformBackup {
/** /**
* Method MySqlBackup. * Method MySqlBackup.
*
* @return boolean */ * @return boolean
*/
private boolean MySqlBackup() { private boolean MySqlBackup() {
File dirBackup = new File(AuthMe.getInstance().getDataFolder() + "/backups"); File dirBackup = new File(AuthMe.getInstance().getDataFolder() + "/backups");
@ -98,9 +126,11 @@ public class PerformBackup {
/** /**
* Method FileBackup. * Method FileBackup.
*
* @param backend String * @param backend String
*
* @return boolean */ * @return boolean
*/
private boolean FileBackup(String backend) { private boolean FileBackup(String backend) {
File dirBackup = new File(AuthMe.getInstance().getDataFolder() + "/backups"); File dirBackup = new File(AuthMe.getInstance().getDataFolder() + "/backups");
@ -117,18 +147,16 @@ public class PerformBackup {
return false; return false;
} }
/*
* Check if we are under Windows and correct location of mysqldump.exe
* otherwise return error.
*/
/** /**
* Method checkWindows. * Method checkWindows.
*
* @param windowsPath String * @param windowsPath String
*
* @return boolean */ * @return boolean
*/
private boolean checkWindows(String windowsPath) { private boolean checkWindows(String windowsPath) {
String isWin = System.getProperty("os.name").toLowerCase(); String isWin = System.getProperty("os.name").toLowerCase();
if (isWin.indexOf("win") >= 0) { if (isWin.contains("win")) {
if (new File(windowsPath + "\\bin\\mysqldump.exe").exists()) { if (new File(windowsPath + "\\bin\\mysqldump.exe").exists()) {
return true; return true;
} else { } 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. * Method copy.
*
* @param src File * @param src File
* @param dst File * @param dst File
*
* @throws IOException */ * @throws IOException
*/
void copy(File src, File dst) throws IOException { void copy(File src, File dst) throws IOException {
InputStream in = new FileInputStream(src); InputStream in = new FileInputStream(src);
OutputStream out = new FileOutputStream(dst); OutputStream out = new FileOutputStream(dst);
@ -161,8 +193,22 @@ public class PerformBackup {
out.close(); out.close();
} }
/*
* Copyr src bytefile into dst file
*/
/**
* Method getInstance.
*
* @return AuthMe
*/
public AuthMe getInstance() {
return instance;
}
/** /**
* Method setInstance. * Method setInstance.
*
* @param instance AuthMe * @param instance AuthMe
*/ */
public void setInstance(AuthMe instance) { public void setInstance(AuthMe instance) {
@ -170,11 +216,13 @@ public class PerformBackup {
} }
/** /**
* Method getInstance. * Possible backup causes.
*/
* @return AuthMe */ public enum BackupCause {
public AuthMe getInstance() { START,
return instance; STOP,
COMMAND,
OTHER,
} }
} }

View File

@ -1,28 +1,26 @@
package fr.xephi.authme; 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.DataSource;
import javax.activation.FileDataSource; import javax.activation.FileDataSource;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
import java.io.File;
import org.apache.commons.mail.HtmlEmail;
import org.bukkit.Bukkit;
import fr.xephi.authme.cache.auth.PlayerAuth;
import fr.xephi.authme.settings.Settings;
/** /**
*
* @author Xephi59 * @author Xephi59
* @version $Revision: 1.0 $ * @version $Revision: 1.0 $
*/ */
public class SendMailSSL { public class SendMailSSL {
public AuthMe plugin; public final AuthMe plugin;
/** /**
* Constructor for SendMailSSL. * Constructor for SendMailSSL.
*
* @param plugin AuthMe * @param plugin AuthMe
*/ */
public SendMailSSL(AuthMe plugin) { public SendMailSSL(AuthMe plugin) {
@ -31,19 +29,20 @@ public class SendMailSSL {
/** /**
* Method main. * Method main.
* @param auth PlayerAuth *
* @param auth PlayerAuth
* @param newPass String * @param newPass String
*/ */
public void main(final PlayerAuth auth, final String newPass) { public void main(final PlayerAuth auth, final String newPass) {
String sendername; String senderName;
if (Settings.getmailSenderName == null || Settings.getmailSenderName.isEmpty()) { if (Settings.getmailSenderName == null || Settings.getmailSenderName.isEmpty()) {
sendername = Settings.getmailAccount; senderName = Settings.getmailAccount;
} else { } else {
sendername = Settings.getmailSenderName; senderName = Settings.getmailSenderName;
} }
final String sender = sendername; final String sender = senderName;
final int port = Settings.getMailPort; final int port = Settings.getMailPort;
final String acc = Settings.getmailAccount; final String acc = Settings.getmailAccount;
final String subject = Settings.getMailSubject; final String subject = Settings.getMailSubject;
@ -91,6 +90,7 @@ public class SendMailSSL {
ConsoleLogger.showError("Fail to send a mail to " + mail); ConsoleLogger.showError("Fail to send a mail to " + mail);
} }
if (file != null) if (file != null)
//noinspection ResultOfMethodCallIgnored
file.delete(); file.delete();
} catch (Exception e) { } catch (Exception e) {

View File

@ -1,19 +1,18 @@
package fr.xephi.authme.api; 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.AuthMe;
import fr.xephi.authme.cache.auth.PlayerAuth; import fr.xephi.authme.cache.auth.PlayerAuth;
import fr.xephi.authme.cache.auth.PlayerCache; import fr.xephi.authme.cache.auth.PlayerCache;
import fr.xephi.authme.security.PasswordSecurity; import fr.xephi.authme.security.PasswordSecurity;
import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.util.Utils; 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. * Constructor for API.
*
* @param instance AuthMe * @param instance AuthMe
*/ */
@Deprecated @Deprecated
@ -34,8 +34,8 @@ public class API {
/** /**
* Hook into AuthMe * Hook into AuthMe
* *
* @return AuthMe instance
* @return AuthMe instance */ */
@Deprecated @Deprecated
public static AuthMe hookAuthMe() { public static AuthMe hookAuthMe() {
if (instance != null) if (instance != null)
@ -49,49 +49,20 @@ public class API {
} }
/** /**
* Method getPlugin.
* @return AuthMe */
@Deprecated
public AuthMe getPlugin() {
return instance;
}
/**
*
* @param player * @param player
*
* @return true if player is authenticate */ * @return true if player is authenticate
*/
@Deprecated @Deprecated
public static boolean isAuthenticated(Player player) { public static boolean isAuthenticated(Player player) {
return PlayerCache.getInstance().isAuthenticated(player.getName()); return PlayerCache.getInstance().isAuthenticated(player.getName());
} }
/** /**
*
* @param player * @param player
* @return true if player is a npc */
@Deprecated
public boolean isaNPC(Player player) {
return Utils.isNPC(player);
}
/**
* *
* @param player * @return true if the player is unrestricted
*/
* @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 */
@Deprecated @Deprecated
public static boolean isUnrestricted(Player player) { public static boolean isUnrestricted(Player player) {
return Utils.isUnrestricted(player); return Utils.isUnrestricted(player);
@ -99,9 +70,11 @@ public class API {
/** /**
* Method getLastLocation. * Method getLastLocation.
*
* @param player Player * @param player Player
*
* @return Location */ * @return Location
*/
@Deprecated @Deprecated
public static Location getLastLocation(Player player) { public static Location getLastLocation(Player player) {
try { try {
@ -121,25 +94,26 @@ public class API {
/** /**
* Method setPlayerInventory. * Method setPlayerInventory.
* @param player Player *
* @param player Player
* @param content ItemStack[] * @param content ItemStack[]
* @param armor ItemStack[] * @param armor ItemStack[]
*/ */
@Deprecated @Deprecated
public static void setPlayerInventory(Player player, ItemStack[] content, public static void setPlayerInventory(Player player, ItemStack[] content,
ItemStack[] armor) { ItemStack[] armor) {
try { try {
player.getInventory().setContents(content); player.getInventory().setContents(content);
player.getInventory().setArmorContents(armor); player.getInventory().setArmorContents(armor);
} catch (NullPointerException npe) { } catch (NullPointerException ignored) {
} }
} }
/** /**
*
* @param playerName * @param playerName
*
* @return true if player is registered */ * @return true if player is registered
*/
@Deprecated @Deprecated
public static boolean isRegistered(String playerName) { public static boolean isRegistered(String playerName) {
String player = playerName.toLowerCase(); String player = playerName.toLowerCase();
@ -147,14 +121,14 @@ public class API {
} }
/** /**
* @param playerName String
* @param playerName String
* @param passwordToCheck String * @param passwordToCheck String
* @return true if the password is correct , false else */ *
* @return true if the password is correct , false else
*/
@Deprecated @Deprecated
public static boolean checkPassword(String playerName, public static boolean checkPassword(String playerName,
String passwordToCheck) { String passwordToCheck) {
if (!isRegistered(playerName)) if (!isRegistered(playerName))
return false; return false;
String player = playerName.toLowerCase(); String player = playerName.toLowerCase();
@ -169,11 +143,11 @@ public class API {
/** /**
* Register a player * Register a player
* *
* @param playerName String * @param playerName String
* @param password String * @param password String
* @return true if the player is register correctly */ *
* @return true if the player is register correctly
*/
@Deprecated @Deprecated
public static boolean registerPlayer(String playerName, String password) { public static boolean registerPlayer(String playerName, String password) {
try { try {
@ -183,10 +157,7 @@ public class API {
return false; return false;
} }
PlayerAuth auth = new PlayerAuth(name, hash, "198.18.0.1", 0, "your@email.com", playerName); PlayerAuth auth = new PlayerAuth(name, hash, "198.18.0.1", 0, "your@email.com", playerName);
if (!instance.database.saveAuth(auth)) { return instance.database.saveAuth(auth);
return false;
}
return true;
} catch (NoSuchAlgorithmException ex) { } catch (NoSuchAlgorithmException ex) {
return false; return false;
} }
@ -195,7 +166,6 @@ public class API {
/** /**
* Force a player to login * Force a player to login
* *
* @param player * player * @param player * player
*/ */
@Deprecated @Deprecated
@ -203,4 +173,34 @@ public class API {
instance.management.performLogin(player, "dontneed", true); 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);
}
} }

View File

@ -1,30 +1,29 @@
package fr.xephi.authme.api; 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.AuthMe;
import fr.xephi.authme.cache.auth.PlayerAuth; import fr.xephi.authme.cache.auth.PlayerAuth;
import fr.xephi.authme.cache.auth.PlayerCache; import fr.xephi.authme.cache.auth.PlayerCache;
import fr.xephi.authme.security.PasswordSecurity; import fr.xephi.authme.security.PasswordSecurity;
import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.util.Utils; 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 class NewAPI {
public static final String newline = System.getProperty("line.separator");
public static NewAPI singleton; public static NewAPI singleton;
public AuthMe plugin; public final AuthMe plugin;
/** /**
* Constructor for NewAPI. * Constructor for NewAPI.
*
* @param plugin AuthMe * @param plugin AuthMe
*/ */
public NewAPI(AuthMe plugin) { public NewAPI(AuthMe plugin) {
@ -33,17 +32,18 @@ public class NewAPI {
/** /**
* Constructor for NewAPI. * Constructor for NewAPI.
* @param serv Server *
* @param server Server
*/ */
public NewAPI(Server serv) { public NewAPI(Server server) {
this.plugin = (AuthMe) serv.getPluginManager().getPlugin("AuthMe"); this.plugin = (AuthMe) server.getPluginManager().getPlugin("AuthMe");
} }
/** /**
* Hook into AuthMe * Hook into AuthMe
* *
* @return AuthMe plugin
* @return AuthMe plugin */ */
public static NewAPI getInstance() { public static NewAPI getInstance() {
if (singleton != null) if (singleton != null)
return singleton; return singleton;
@ -58,44 +58,47 @@ public class NewAPI {
/** /**
* Method getPlugin. * Method getPlugin.
*
* @return AuthMe */ * @return AuthMe
*/
public AuthMe getPlugin() { public AuthMe getPlugin() {
return plugin; return plugin;
} }
/** /**
*
* @param player * @param player
*
* @return true if player is authenticate */ * @return true if player is authenticate
*/
public boolean isAuthenticated(Player player) { public boolean isAuthenticated(Player player) {
return PlayerCache.getInstance().isAuthenticated(player.getName()); return PlayerCache.getInstance().isAuthenticated(player.getName());
} }
/** /**
*
* @param player * @param player
*
* @return true if player is a npc */ * @return true if player is a npc
*/
public boolean isNPC(Player player) { public boolean isNPC(Player player) {
return Utils.isNPC(player); return Utils.isNPC(player);
} }
/** /**
*
* @param player * @param player
*
* @return true if the player is unrestricted */ * @return true if the player is unrestricted
*/
public boolean isUnrestricted(Player player) { public boolean isUnrestricted(Player player) {
return Utils.isUnrestricted(player); return Utils.isUnrestricted(player);
} }
/** /**
* Method getLastLocation. * Method getLastLocation.
*
* @param player Player * @param player Player
*
* @return Location */ * @return Location
*/
public Location getLastLocation(Player player) { public Location getLastLocation(Player player) {
try { try {
PlayerAuth auth = PlayerCache.getInstance().getAuth(player.getName().toLowerCase()); PlayerAuth auth = PlayerCache.getInstance().getAuth(player.getName().toLowerCase());
@ -112,21 +115,21 @@ public class NewAPI {
} }
/** /**
*
* @param playerName * @param playerName
*
* @return true if player is registered */ * @return true if player is registered
*/
public boolean isRegistered(String playerName) { public boolean isRegistered(String playerName) {
String player = playerName.toLowerCase(); String player = playerName.toLowerCase();
return plugin.database.isAuthAvailable(player); return plugin.database.isAuthAvailable(player);
} }
/** /**
* @param playerName String
* @param playerName String
* @param passwordToCheck 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) { public boolean checkPassword(String playerName, String passwordToCheck) {
if (!isRegistered(playerName)) if (!isRegistered(playerName))
return false; return false;
@ -142,11 +145,11 @@ public class NewAPI {
/** /**
* Register a player * Register a player
* *
* @param playerName String * @param playerName String
* @param password String * @param password String
* @return true if the player is register correctly */ *
* @return true if the player is register correctly
*/
public boolean registerPlayer(String playerName, String password) { public boolean registerPlayer(String playerName, String password) {
try { try {
String name = playerName.toLowerCase(); String name = playerName.toLowerCase();
@ -164,7 +167,6 @@ public class NewAPI {
/** /**
* Force a player to login * Force a player to login
* *
* @param player * player * @param player * player
*/ */
public void forceLogin(Player player) { public void forceLogin(Player player) {
@ -174,35 +176,28 @@ public class NewAPI {
/** /**
* Force a player to logout * Force a player to logout
* *
* @param player * player * @param player * player
*/ */
public void forceLogout(Player player) public void forceLogout(Player player) {
{ plugin.management.performLogout(player);
plugin.management.performLogout(player);
} }
/** /**
* Force a player to register * Force a player to register
* *
* @param player * player
* @param player * player
* @param password String * @param password String
*/ */
public void forceRegister(Player player, String password) public void forceRegister(Player player, String password) {
{ plugin.management.performRegister(player, password, null);
plugin.management.performRegister(player, password, null);
} }
/** /**
* Force a player to unregister * Force a player to unregister
* *
* @param player * player * @param player * player
*/ */
public void forceUnregister(Player player) public void forceUnregister(Player player) {
{ plugin.management.performUnregister(player, "", true);
plugin.management.performUnregister(player, "", true);
} }
} }

View File

@ -16,16 +16,17 @@ public class PlayerAuth {
private double z; private double z;
private String world; private String world;
private String salt; private String salt;
private int groupId; private final int groupId;
private String email; private String email;
private String realName; private String realName;
/** /**
* Constructor for PlayerAuth. * Constructor for PlayerAuth.
* @param nickname String *
* @param ip String * @param nickname String
* @param ip String
* @param lastLogin long * @param lastLogin long
* @param realName String * @param realName String
*/ */
public PlayerAuth(String nickname, String ip, long lastLogin, String realName) { public PlayerAuth(String nickname, String ip, long lastLogin, String realName) {
this(nickname, "", "", -1, ip, lastLogin, 0, 0, 0, "world", "your@email.com", realName); this(nickname, "", "", -1, ip, lastLogin, 0, 0, 0, "world", "your@email.com", realName);
@ -33,11 +34,12 @@ public class PlayerAuth {
/** /**
* Constructor for PlayerAuth. * Constructor for PlayerAuth.
*
* @param nickname String * @param nickname String
* @param x double * @param x double
* @param y double * @param y double
* @param z double * @param z double
* @param world String * @param world String
* @param realName String * @param realName String
*/ */
public PlayerAuth(String nickname, double x, double y, double z, String world, String realName) { public PlayerAuth(String nickname, double x, double y, double z, String world, String realName) {
@ -46,11 +48,12 @@ public class PlayerAuth {
/** /**
* Constructor for PlayerAuth. * Constructor for PlayerAuth.
* @param nickname String *
* @param hash String * @param nickname String
* @param ip String * @param hash String
* @param ip String
* @param lastLogin long * @param lastLogin long
* @param realName String * @param realName String
*/ */
public PlayerAuth(String nickname, String hash, String ip, long lastLogin, String realName) { 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); this(nickname, hash, "", -1, ip, lastLogin, 0, 0, 0, "world", "your@email.com", realName);
@ -58,12 +61,13 @@ public class PlayerAuth {
/** /**
* Constructor for PlayerAuth. * Constructor for PlayerAuth.
* @param nickname String *
* @param hash String * @param nickname String
* @param ip String * @param hash String
* @param ip String
* @param lastLogin long * @param lastLogin long
* @param email String * @param email String
* @param realName String * @param realName String
*/ */
public PlayerAuth(String nickname, String hash, String ip, long lastLogin, String email, String realName) { 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); this(nickname, hash, "", -1, ip, lastLogin, 0, 0, 0, "world", email, realName);
@ -71,12 +75,13 @@ public class PlayerAuth {
/** /**
* Constructor for PlayerAuth. * Constructor for PlayerAuth.
* @param nickname String *
* @param hash String * @param nickname String
* @param salt String * @param hash String
* @param ip String * @param salt String
* @param ip String
* @param lastLogin long * @param lastLogin long
* @param realName String * @param realName String
*/ */
public PlayerAuth(String nickname, String hash, String salt, String ip, long lastLogin, String realName) { 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); 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. * Constructor for PlayerAuth.
* @param nickname String *
* @param hash String * @param nickname String
* @param ip String * @param hash String
* @param ip String
* @param lastLogin long * @param lastLogin long
* @param x double * @param x double
* @param y double * @param y double
* @param z double * @param z double
* @param world String * @param world String
* @param email String * @param email String
* @param realName 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) { 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); this(nickname, hash, "", -1, ip, lastLogin, x, y, z, world, email, realName);
@ -101,17 +107,18 @@ public class PlayerAuth {
/** /**
* Constructor for PlayerAuth. * Constructor for PlayerAuth.
* @param nickname String *
* @param hash String * @param nickname String
* @param salt String * @param hash String
* @param ip String * @param salt String
* @param ip String
* @param lastLogin long * @param lastLogin long
* @param x double * @param x double
* @param y double * @param y double
* @param z double * @param z double
* @param world String * @param world String
* @param email String * @param email String
* @param realName 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) { 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); this(nickname, hash, salt, -1, ip, lastLogin, x, y, z, world, email, realName);
@ -119,13 +126,14 @@ public class PlayerAuth {
/** /**
* Constructor for PlayerAuth. * Constructor for PlayerAuth.
* @param nickname String *
* @param hash String * @param nickname String
* @param salt String * @param hash String
* @param groupId int * @param salt String
* @param ip String * @param groupId int
* @param ip String
* @param lastLogin long * @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) { 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); 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. * Constructor for PlayerAuth.
* @param nickname String *
* @param hash String * @param nickname String
* @param salt String * @param hash String
* @param groupId int * @param salt String
* @param ip String * @param groupId int
* @param ip String
* @param lastLogin long * @param lastLogin long
* @param x double * @param x double
* @param y double * @param y double
* @param z double * @param z double
* @param world String * @param world String
* @param email String * @param email String
* @param realName 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) { 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; this.nickname = nickname;
@ -163,6 +172,7 @@ public class PlayerAuth {
/** /**
* Method set. * Method set.
*
* @param auth PlayerAuth * @param auth PlayerAuth
*/ */
public void set(PlayerAuth auth) { public void set(PlayerAuth auth) {
@ -181,6 +191,7 @@ public class PlayerAuth {
/** /**
* Method setName. * Method setName.
*
* @param nickname String * @param nickname String
*/ */
public void setName(String nickname) { public void setName(String nickname) {
@ -189,22 +200,25 @@ public class PlayerAuth {
/** /**
* Method getNickname. * Method getNickname.
*
* @return String */ * @return String
*/
public String getNickname() { public String getNickname() {
return nickname; return nickname;
} }
/** /**
* Method getRealName. * Method getRealName.
*
* @return String */ * @return String
*/
public String getRealName() { public String getRealName() {
return realName; return realName;
} }
/** /**
* Method setRealName. * Method setRealName.
*
* @param realName String * @param realName String
*/ */
public void setRealName(String realName) { public void setRealName(String realName) {
@ -213,14 +227,25 @@ public class PlayerAuth {
/** /**
* Method getGroupId. * Method getGroupId.
*
* @return int */ * @return int
*/
public int getGroupId() { public int getGroupId() {
return groupId; return groupId;
} }
/**
* Method getQuitLocX.
*
* @return double
*/
public double getQuitLocX() {
return x;
}
/** /**
* Method setQuitLocX. * Method setQuitLocX.
*
* @param d double * @param d double
*/ */
public void setQuitLocX(double d) { public void setQuitLocX(double d) {
@ -228,15 +253,17 @@ public class PlayerAuth {
} }
/** /**
* Method getQuitLocX. * Method getQuitLocY.
*
* @return double */ * @return double
public double getQuitLocX() { */
return x; public double getQuitLocY() {
return y;
} }
/** /**
* Method setQuitLocY. * Method setQuitLocY.
*
* @param d double * @param d double
*/ */
public void setQuitLocY(double d) { public void setQuitLocY(double d) {
@ -244,15 +271,17 @@ public class PlayerAuth {
} }
/** /**
* Method getQuitLocY. * Method getQuitLocZ.
*
* @return double */ * @return double
public double getQuitLocY() { */
return y; public double getQuitLocZ() {
return z;
} }
/** /**
* Method setQuitLocZ. * Method setQuitLocZ.
*
* @param d double * @param d double
*/ */
public void setQuitLocZ(double d) { public void setQuitLocZ(double d) {
@ -260,15 +289,17 @@ public class PlayerAuth {
} }
/** /**
* Method getQuitLocZ. * Method getWorld.
*
* @return double */ * @return String
public double getQuitLocZ() { */
return z; public String getWorld() {
return world;
} }
/** /**
* Method setWorld. * Method setWorld.
*
* @param world String * @param world String
*/ */
public void setWorld(String world) { public void setWorld(String world) {
@ -276,15 +307,17 @@ public class PlayerAuth {
} }
/** /**
* Method getWorld. * Method getIp.
*
* @return String */ * @return String
public String getWorld() { */
return world; public String getIp() {
return ip;
} }
/** /**
* Method setIp. * Method setIp.
*
* @param ip String * @param ip String
*/ */
public void setIp(String ip) { public void setIp(String ip) {
@ -292,15 +325,17 @@ public class PlayerAuth {
} }
/** /**
* Method getIp. * Method getLastLogin.
*
* @return String */ * @return long
public String getIp() { */
return ip; public long getLastLogin() {
return lastLogin;
} }
/** /**
* Method setLastLogin. * Method setLastLogin.
*
* @param lastLogin long * @param lastLogin long
*/ */
public void setLastLogin(long lastLogin) { public void setLastLogin(long lastLogin) {
@ -308,15 +343,17 @@ public class PlayerAuth {
} }
/** /**
* Method getLastLogin. * Method getEmail.
*
* @return long */ * @return String
public long getLastLogin() { */
return lastLogin; public String getEmail() {
return email;
} }
/** /**
* Method setEmail. * Method setEmail.
*
* @param email String * @param email String
*/ */
public void setEmail(String email) { public void setEmail(String email) {
@ -324,41 +361,28 @@ public class PlayerAuth {
} }
/** /**
* Method getEmail. * Method getSalt.
*
* @return String */ * @return String
public String getEmail() { */
return email; public String getSalt() {
return this.salt;
} }
/** /**
* Method setSalt. * Method setSalt.
*
* @param salt String * @param salt String
*/ */
public void setSalt(String salt) { public void setSalt(String salt) {
this.salt = 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. * Method getHash.
*
* @return String */ * @return String
*/
public String getHash() { public String getHash() {
if (Settings.getPasswordHash == HashAlgorithm.MD5VB) { if (Settings.getPasswordHash == HashAlgorithm.MD5VB) {
if (salt != null && !salt.isEmpty() && Settings.getPasswordHash == HashAlgorithm.MD5VB) { if (salt != null && !salt.isEmpty() && Settings.getPasswordHash == HashAlgorithm.MD5VB) {
@ -368,11 +392,22 @@ public class PlayerAuth {
return hash; return hash;
} }
/**
* Method setHash.
*
* @param hash String
*/
public void setHash(String hash) {
this.hash = hash;
}
/** /**
* Method equals. * Method equals.
*
* @param obj Object * @param obj Object
*
* @return boolean */ * @return boolean
*/
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (!(obj instanceof PlayerAuth)) { if (!(obj instanceof PlayerAuth)) {
@ -384,8 +419,9 @@ public class PlayerAuth {
/** /**
* Method hashCode. * Method hashCode.
*
* @return int */ * @return int
*/
@Override @Override
public int hashCode() { public int hashCode() {
int hashCode = 7; int hashCode = 7;
@ -396,17 +432,18 @@ public class PlayerAuth {
/** /**
* Method toString. * Method toString.
*
* @return String */ * @return String
*/
@Override @Override
public String toString() { public String toString() {
return ("Player : " + nickname + " | " + realName return ("Player : " + nickname + " | " + realName
+ " ! IP : " + ip + " ! IP : " + ip
+ " ! LastLogin : " + lastLogin + " ! LastLogin : " + lastLogin
+ " ! LastPosition : " + x + "," + y + "," + z + "," + world + " ! LastPosition : " + x + "," + y + "," + z + "," + world
+ " ! Email : " + email + " ! Email : " + email
+ " ! Hash : " + hash + " ! Hash : " + hash
+ " ! Salt : " + salt); + " ! Salt : " + salt);
} }
} }

View File

@ -7,14 +7,27 @@ import java.util.concurrent.ConcurrentHashMap;
public class PlayerCache { public class PlayerCache {
private volatile static PlayerCache singleton; private volatile static PlayerCache singleton;
private ConcurrentHashMap<String, PlayerAuth> cache; private final ConcurrentHashMap<String, PlayerAuth> cache;
private PlayerCache() { private PlayerCache() {
cache = new ConcurrentHashMap<>(); cache = new ConcurrentHashMap<>();
} }
/**
* Method getInstance.
*
* @return PlayerCache
*/
public static PlayerCache getInstance() {
if (singleton == null) {
singleton = new PlayerCache();
}
return singleton;
}
/** /**
* Method addPlayer. * Method addPlayer.
*
* @param auth PlayerAuth * @param auth PlayerAuth
*/ */
public void addPlayer(PlayerAuth auth) { public void addPlayer(PlayerAuth auth) {
@ -23,6 +36,7 @@ public class PlayerCache {
/** /**
* Method updatePlayer. * Method updatePlayer.
*
* @param auth PlayerAuth * @param auth PlayerAuth
*/ */
public void updatePlayer(PlayerAuth auth) { public void updatePlayer(PlayerAuth auth) {
@ -32,6 +46,7 @@ public class PlayerCache {
/** /**
* Method removePlayer. * Method removePlayer.
*
* @param user String * @param user String
*/ */
public void removePlayer(String user) { public void removePlayer(String user) {
@ -40,45 +55,40 @@ public class PlayerCache {
/** /**
* Method isAuthenticated. * Method isAuthenticated.
*
* @param user String * @param user String
*
* @return boolean */ * @return boolean
*/
public boolean isAuthenticated(String user) { public boolean isAuthenticated(String user) {
return cache.containsKey(user.toLowerCase()); return cache.containsKey(user.toLowerCase());
} }
/** /**
* Method getAuth. * Method getAuth.
*
* @param user String * @param user String
*
* @return PlayerAuth */ * @return PlayerAuth
*/
public PlayerAuth getAuth(String user) { public PlayerAuth getAuth(String user) {
return cache.get(user.toLowerCase()); return cache.get(user.toLowerCase());
} }
/**
* Method getInstance.
* @return PlayerCache */
public static PlayerCache getInstance() {
if (singleton == null) {
singleton = new PlayerCache();
}
return singleton;
}
/** /**
* Method getLogged. * Method getLogged.
*
* @return int */ * @return int
*/
public int getLogged() { public int getLogged() {
return cache.size(); return cache.size();
} }
/** /**
* Method getCache. * Method getCache.
*
* @return ConcurrentHashMap<String,PlayerAuth> */ * @return ConcurrentHashMap<String,PlayerAuth>
*/
public ConcurrentHashMap<String, PlayerAuth> getCache() { public ConcurrentHashMap<String, PlayerAuth> getCache() {
return this.cache; return this.cache;
} }

View File

@ -4,15 +4,16 @@ package fr.xephi.authme.cache.backup;
*/ */
public class DataFileCache { public class DataFileCache {
private String group; private final String group;
private boolean operator; private final boolean operator;
private boolean flying; private final boolean flying;
/** /**
* Constructor for DataFileCache. * Constructor for DataFileCache.
* @param group String *
* @param group String
* @param operator boolean * @param operator boolean
* @param flying boolean * @param flying boolean
*/ */
public DataFileCache(String group, boolean operator, boolean flying) { public DataFileCache(String group, boolean operator, boolean flying) {
this.group = group; this.group = group;
@ -22,24 +23,27 @@ public class DataFileCache {
/** /**
* Method getGroup. * Method getGroup.
*
* @return String */ * @return String
*/
public String getGroup() { public String getGroup() {
return group; return group;
} }
/** /**
* Method getOperator. * Method getOperator.
*
* @return boolean */ * @return boolean
*/
public boolean getOperator() { public boolean getOperator() {
return operator; return operator;
} }
/** /**
* Method isFlying. * Method isFlying.
*
* @return boolean */ * @return boolean
*/
public boolean isFlying() { public boolean isFlying() {
return flying; return flying;
} }

View File

@ -1,27 +1,17 @@
package fr.xephi.authme.cache.backup; 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.File;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.Type; 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 { public class JsonCache {
@ -35,15 +25,16 @@ public class JsonCache {
ConsoleLogger.showError("Failed to create cache directory."); ConsoleLogger.showError("Failed to create cache directory.");
} }
gson = new GsonBuilder() gson = new GsonBuilder()
.registerTypeAdapter(DataFileCache.class, new PlayerDataSerializer()) .registerTypeAdapter(DataFileCache.class, new PlayerDataSerializer())
.registerTypeAdapter(DataFileCache.class, new PlayerDataDeserializer()) .registerTypeAdapter(DataFileCache.class, new PlayerDataDeserializer())
.setPrettyPrinting() .setPrettyPrinting()
.create(); .create();
} }
/** /**
* Method createCache. * Method createCache.
* @param player Player *
* @param player Player
* @param playerData DataFileCache * @param playerData DataFileCache
*/ */
public void createCache(Player player, DataFileCache playerData) { public void createCache(Player player, DataFileCache playerData) {
@ -77,9 +68,11 @@ public class JsonCache {
/** /**
* Method readCache. * Method readCache.
*
* @param player Player * @param player Player
*
* @return DataFileCache */ * @return DataFileCache
*/
public DataFileCache readCache(Player player) { public DataFileCache readCache(Player player) {
String path; String path;
try { try {
@ -103,24 +96,42 @@ public class JsonCache {
} }
/** /**
* Method removeCache.
*
* @param player Player
*/ */
private class PlayerDataSerializer implements JsonSerializer<DataFileCache> { public void removeCache(Player player) {
/** String path;
* Method serialize. try {
* @param dataFileCache DataFileCache path = player.getUniqueId().toString();
* @param type Type } catch (Exception | Error e) {
* @param jsonSerializationContext JsonSerializationContext path = player.getName().toLowerCase();
* @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;
} }
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<DataFileCache> { private static class PlayerDataDeserializer implements JsonDeserializer<DataFileCache> {
/** /**
* Method deserialize. * Method deserialize.
* @param jsonElement JsonElement *
* @param type Type * @param jsonElement JsonElement
* @param type Type
* @param jsonDeserializationContext JsonDeserializationContext * @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 @Override
public DataFileCache deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException { public DataFileCache deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
JsonObject jsonObject = jsonElement.getAsJsonObject(); JsonObject jsonObject = jsonElement.getAsJsonObject();
@ -161,39 +172,26 @@ public class JsonCache {
} }
/** /**
* Method removeCache.
* @param player Player
*/ */
public void removeCache(Player player) { private class PlayerDataSerializer implements JsonSerializer<DataFileCache> {
String path; /**
try { * Method serialize.
path = player.getUniqueId().toString(); *
} catch (Exception | Error e) { * @param dataFileCache DataFileCache
path = player.getName().toLowerCase(); * @param type Type
} * @param jsonSerializationContext JsonSerializationContext
File file = new File(cacheDir, path); *
if (file.exists()) { * @return JsonElement
Utils.purgeDirectory(file); */
if (!file.delete()) { @Override
ConsoleLogger.showError("Failed to remove" + player.getName() + "cache."); 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;
* 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();
} }
} }

View File

@ -1,30 +1,31 @@
package fr.xephi.authme.cache.limbo; 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.AuthMe;
import fr.xephi.authme.ConsoleLogger; import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.cache.backup.DataFileCache; import fr.xephi.authme.cache.backup.DataFileCache;
import fr.xephi.authme.cache.backup.JsonCache; import fr.xephi.authme.cache.backup.JsonCache;
import fr.xephi.authme.events.ResetInventoryEvent; import fr.xephi.authme.events.ResetInventoryEvent;
import fr.xephi.authme.permission.PermissionsManager;
import fr.xephi.authme.settings.Settings; 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 { public class LimboCache {
private volatile static LimboCache singleton; private volatile static LimboCache singleton;
public ConcurrentHashMap<String, LimboPlayer> cache; public final ConcurrentHashMap<String, LimboPlayer> cache;
private JsonCache playerData; public final AuthMe plugin;
public AuthMe plugin; private final JsonCache playerData;
/** /**
* Constructor for LimboCache. * Constructor for LimboCache.
*
* @param plugin AuthMe * @param plugin AuthMe
*/ */
private LimboCache(AuthMe plugin) { private LimboCache(AuthMe plugin) {
@ -34,8 +35,21 @@ public class LimboCache {
} }
/** /**
* Method addLimboPlayer. * Method getInstance.
* @param player Player *
* @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) { public void addLimboPlayer(Player player) {
String name = player.getName().toLowerCase(); String name = player.getName().toLowerCase();
@ -45,6 +59,12 @@ public class LimboCache {
String playerGroup = ""; String playerGroup = "";
boolean flying = false; 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)) { if (playerData.doesCacheExist(player)) {
DataFileCache cache = playerData.readCache(player); DataFileCache cache = playerData.readCache(player);
if (cache != null) { if (cache != null) {
@ -55,14 +75,10 @@ public class LimboCache {
} else { } else {
operator = player.isOp(); operator = player.isOp();
flying = player.isFlying(); flying = player.isFlying();
if (plugin.vaultGroupManagement != null) {
try { // Check whether groups are supported
playerGroup = plugin.vaultGroupManagement.getPrimaryGroup(player); if (permsMan.hasGroupSupport())
} catch (UnsupportedOperationException e) { playerGroup = permsMan.getPrimaryGroup(player);
ConsoleLogger.showError("Your permission system (" + plugin.vaultGroupManagement.getName() + ") do not support Group system with that config... unhook!");
plugin.vaultGroupManagement = null;
}
}
} }
if (Settings.isForceSurvivalModeEnabled) { if (Settings.isForceSurvivalModeEnabled) {
@ -87,8 +103,9 @@ public class LimboCache {
/** /**
* Method addLimboPlayer. * Method addLimboPlayer.
*
* @param player Player * @param player Player
* @param group String * @param group String
*/ */
public void addLimboPlayer(Player player, String group) { public void addLimboPlayer(Player player, String group) {
cache.put(player.getName().toLowerCase(), new LimboPlayer(player.getName().toLowerCase(), group)); cache.put(player.getName().toLowerCase(), new LimboPlayer(player.getName().toLowerCase(), group));
@ -96,6 +113,7 @@ public class LimboCache {
/** /**
* Method deleteLimboPlayer. * Method deleteLimboPlayer.
*
* @param name String * @param name String
*/ */
public void deleteLimboPlayer(String name) { public void deleteLimboPlayer(String name) {
@ -104,35 +122,29 @@ public class LimboCache {
/** /**
* Method getLimboPlayer. * Method getLimboPlayer.
*
* @param name String * @param name String
*
* @return LimboPlayer */ * @return LimboPlayer
*/
public LimboPlayer getLimboPlayer(String name) { public LimboPlayer getLimboPlayer(String name) {
return cache.get(name); return cache.get(name);
} }
/** /**
* Method hasLimboPlayer. * Method hasLimboPlayer.
*
* @param name String * @param name String
*
* @return boolean */ * @return boolean
*/
public boolean hasLimboPlayer(String name) { public boolean hasLimboPlayer(String name) {
return cache.containsKey(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. * Method updateLimboPlayer.
*
* @param player Player * @param player Player
*/ */
public void updateLimboPlayer(Player player) { public void updateLimboPlayer(Player player) {

View File

@ -8,7 +8,7 @@ import org.bukkit.scheduler.BukkitTask;
*/ */
public class LimboPlayer { public class LimboPlayer {
private String name; private final String name;
private Location loc = null; private Location loc = null;
private BukkitTask timeoutTaskId = null; private BukkitTask timeoutTaskId = null;
private BukkitTask messageTaskId = null; private BukkitTask messageTaskId = null;
@ -19,15 +19,16 @@ public class LimboPlayer {
/** /**
* Constructor for LimboPlayer. * Constructor for LimboPlayer.
* @param name String *
* @param loc Location * @param name String
* @param loc Location
* @param gameMode GameMode * @param gameMode GameMode
* @param operator boolean * @param operator boolean
* @param group String * @param group String
* @param flying boolean * @param flying boolean
*/ */
public LimboPlayer(String name, Location loc, GameMode gameMode, public LimboPlayer(String name, Location loc, GameMode gameMode,
boolean operator, String group, boolean flying) { boolean operator, String group, boolean flying) {
this.name = name; this.name = name;
this.loc = loc; this.loc = loc;
this.gameMode = gameMode; this.gameMode = gameMode;
@ -38,7 +39,8 @@ public class LimboPlayer {
/** /**
* Constructor for LimboPlayer. * Constructor for LimboPlayer.
* @param name String *
* @param name String
* @param group String * @param group String
*/ */
public LimboPlayer(String name, String group) { public LimboPlayer(String name, String group) {
@ -48,46 +50,61 @@ public class LimboPlayer {
/** /**
* Method getName. * Method getName.
*
* @return String */ * @return String
*/
public String getName() { public String getName() {
return name; return name;
} }
/** /**
* Method getLoc. * Method getLoc.
*
* @return Location */ * @return Location
*/
public Location getLoc() { public Location getLoc() {
return loc; return loc;
} }
/** /**
* Method getGameMode. * Method getGameMode.
*
* @return GameMode */ * @return GameMode
*/
public GameMode getGameMode() { public GameMode getGameMode() {
return gameMode; return gameMode;
} }
/** /**
* Method getOperator. * Method getOperator.
*
* @return boolean */ * @return boolean
*/
public boolean getOperator() { public boolean getOperator() {
return operator; return operator;
} }
/** /**
* Method getGroup. * Method getGroup.
*
* @return String */ * @return String
*/
public String getGroup() { public String getGroup() {
return group; return group;
} }
/**
* Method getTimeoutTaskId.
*
* @return BukkitTask
*/
public BukkitTask getTimeoutTaskId() {
return timeoutTaskId;
}
/** /**
* Method setTimeoutTaskId. * Method setTimeoutTaskId.
*
* @param i BukkitTask * @param i BukkitTask
*/ */
public void setTimeoutTaskId(BukkitTask i) { public void setTimeoutTaskId(BukkitTask i) {
@ -97,15 +114,17 @@ public class LimboPlayer {
} }
/** /**
* Method getTimeoutTaskId. * Method getMessageTaskId.
*
* @return BukkitTask */ * @return BukkitTask
public BukkitTask getTimeoutTaskId() { */
return timeoutTaskId; public BukkitTask getMessageTaskId() {
return messageTaskId;
} }
/** /**
* Method setMessageTaskId. * Method setMessageTaskId.
*
* @param messageTaskId BukkitTask * @param messageTaskId BukkitTask
*/ */
public void setMessageTaskId(BukkitTask messageTaskId) { public void setMessageTaskId(BukkitTask messageTaskId) {
@ -114,18 +133,11 @@ public class LimboPlayer {
this.messageTaskId = messageTaskId; this.messageTaskId = messageTaskId;
} }
/**
* Method getMessageTaskId.
* @return BukkitTask */
public BukkitTask getMessageTaskId() {
return messageTaskId;
}
/** /**
* Method isFlying. * Method isFlying.
*
* @return boolean */ * @return boolean
*/
public boolean isFlying() { public boolean isFlying() {
return flying; return flying;
} }

View File

@ -6,17 +6,23 @@ public class CommandArgumentDescription {
// TODO: Allow argument to consist of infinite parts. <label ...> // TODO: Allow argument to consist of infinite parts. <label ...>
/** Argument label. */ /**
* Argument label.
*/
private String label; private String label;
/** Argument description. */ /**
* Argument description.
*/
private String description; private String description;
/** Defines whether the argument is optional. */ /**
* Defines whether the argument is optional.
*/
private boolean optional = false; private boolean optional = false;
/** /**
* Constructor. * Constructor.
* *
* @param label The argument label. * @param label The argument label.
* @param description The argument description. * @param description The argument description.
*/ */
public CommandArgumentDescription(String label, String description) { public CommandArgumentDescription(String label, String description) {
@ -26,9 +32,9 @@ public class CommandArgumentDescription {
/** /**
* Constructor. * Constructor.
* *
* @param label The argument label. * @param label The argument label.
* @param description The argument description. * @param description The argument description.
* @param optional True if the argument is optional, false otherwise. * @param optional True if the argument is optional, false otherwise.
*/ */
public CommandArgumentDescription(String label, String description, boolean optional) { public CommandArgumentDescription(String label, String description, boolean optional) {
setLabel(label); setLabel(label);

View File

@ -1,45 +1,62 @@
package fr.xephi.authme.command; package fr.xephi.authme.command;
import fr.xephi.authme.util.StringUtils;
import org.bukkit.command.CommandSender;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.List; import java.util.List;
import org.bukkit.command.CommandSender;
import fr.xephi.authme.util.StringUtils;
/** /**
*/ */
public class CommandDescription { public class CommandDescription {
/** Defines the acceptable labels. */ /**
* Defines the acceptable labels.
*/
private List<String> labels = new ArrayList<>(); private List<String> labels = new ArrayList<>();
/** Command description. */ /**
* Command description.
*/
private String description = ""; private String description = "";
/** Detailed description. */ /**
* Detailed description.
*/
private String detailedDescription = ""; private String detailedDescription = "";
/** The executable command instance. */ /**
* The executable command instance.
*/
private ExecutableCommand executableCommand; private ExecutableCommand executableCommand;
/** The parent command. */ /**
* The parent command.
*/
private CommandDescription parent = null; private CommandDescription parent = null;
/** The child labels. */ /**
* The child labels.
*/
private List<CommandDescription> children = new ArrayList<>(); private List<CommandDescription> children = new ArrayList<>();
/** The command arguments. */ /**
* The command arguments.
*/
private List<CommandArgumentDescription> arguments = new ArrayList<>(); private List<CommandArgumentDescription> arguments = new ArrayList<>();
/** Defines whether there is an argument maximum or not. */ /**
* Defines whether there is an argument maximum or not.
*/
private boolean noArgumentMaximum = false; private boolean noArgumentMaximum = false;
/** Defines the command permissions. */ /**
* Defines the command permissions.
*/
private CommandPermissions permissions = new CommandPermissions(); private CommandPermissions permissions = new CommandPermissions();
/** /**
* Constructor. * Constructor.
* *
* @param executableCommand The executable command, or null. * @param executableCommand The executable command, or null.
* @param label Command label. * @param label Command label.
* @param description Command description. * @param description Command description.
* @param detailedDescription Detailed comment description. * @param detailedDescription Detailed comment description.
* @param parent Parent command. * @param parent Parent command.
*/ */
public CommandDescription(ExecutableCommand executableCommand, String label, String description, String detailedDescription, CommandDescription parent) { public CommandDescription(ExecutableCommand executableCommand, String label, String description, String detailedDescription, CommandDescription parent) {
this(executableCommand, label, description, parent, detailedDescription, null); this(executableCommand, label, description, parent, detailedDescription, null);
@ -48,11 +65,11 @@ public class CommandDescription {
/** /**
* Constructor. * Constructor.
* *
* @param executableCommand The executable command, or null. * @param executableCommand The executable command, or null.
* @param labels List of command labels. * @param labels List of command labels.
* @param description Command description. * @param description Command description.
* @param detailedDescription Detailed comment description. * @param detailedDescription Detailed comment description.
* @param parent Parent command. * @param parent Parent command.
*/ */
public CommandDescription(ExecutableCommand executableCommand, List<String> labels, String description, String detailedDescription, CommandDescription parent) { public CommandDescription(ExecutableCommand executableCommand, List<String> labels, String description, String detailedDescription, CommandDescription parent) {
this(executableCommand, labels, description, detailedDescription, parent, null); this(executableCommand, labels, description, detailedDescription, parent, null);
@ -61,12 +78,12 @@ public class CommandDescription {
/** /**
* Constructor. * Constructor.
* *
* @param executableCommand The executable command, or null. * @param executableCommand The executable command, or null.
* @param label Command label. * @param label Command label.
* @param description Command description. * @param description Command description.
* @param parent Parent command. * @param parent Parent command.
* @param detailedDescription Detailed comment description. * @param detailedDescription Detailed comment description.
* @param arguments Command arguments. * @param arguments Command arguments.
*/ */
public CommandDescription(ExecutableCommand executableCommand, String label, String description, CommandDescription parent, String detailedDescription, List<CommandArgumentDescription> arguments) { public CommandDescription(ExecutableCommand executableCommand, String label, String description, CommandDescription parent, String detailedDescription, List<CommandArgumentDescription> arguments) {
setExecutableCommand(executableCommand); setExecutableCommand(executableCommand);
@ -80,12 +97,12 @@ public class CommandDescription {
/** /**
* Constructor. * Constructor.
* *
* @param executableCommand The executable command, or null. * @param executableCommand The executable command, or null.
* @param labels List of command labels. * @param labels List of command labels.
* @param description Command description. * @param description Command description.
* @param detailedDescription Detailed comment description. * @param detailedDescription Detailed comment description.
* @param parent Parent command. * @param parent Parent command.
* @param arguments Command arguments. * @param arguments Command arguments.
*/ */
public CommandDescription(ExecutableCommand executableCommand, List<String> labels, String description, String detailedDescription, CommandDescription parent, List<CommandArgumentDescription> arguments) { public CommandDescription(ExecutableCommand executableCommand, List<String> labels, String description, String detailedDescription, CommandDescription parent, List<CommandArgumentDescription> arguments) {
setExecutableCommand(executableCommand); setExecutableCommand(executableCommand);
@ -96,6 +113,69 @@ public class CommandDescription {
setArguments(arguments); setArguments(arguments);
} }
/**
* Check whether a label is valid to use.
*
* @param label The label to test.
*
* @return True if the label is valid to use, false otherwise.
*/
public static boolean isValidLabel(String label) {
// Make sure the label isn't null
if (label == null)
return false;
// Trim the label
label = label.trim();
// Make sure the label is at least one character long
if (label.length() <= 0)
return false;
// Make sure the label doesn't contain any spaces, return the result
return !label.contains(" ");
}
/**
* Check whether two labels equal to each other.
*
* @param commandLabel The first command label.
* @param otherCommandLabel The other command label.
*
* @return True if the labels are equal to each other.
*/
private static boolean commandLabelEquals(String commandLabel, String otherCommandLabel) {
// Trim the command labels from unwanted whitespaces
commandLabel = commandLabel.trim();
otherCommandLabel = otherCommandLabel.trim();
// Check whether the the two command labels are equal (case insensitive)
return (commandLabel.equalsIgnoreCase(otherCommandLabel));
}
/**
* Get the first relative command label.
*
* @return First relative command label.
*/
public String getLabel() {
// Ensure there's any item in the command list
if (this.labels.size() == 0)
return "";
// Return the first command on the list
return this.labels.get(0);
}
/**
* Set the command label, this will append the command label to already existing ones.
*
* @param commandLabel Command label to set or add.
*/
public void setLabel(String commandLabel) {
setLabel(commandLabel, false);
}
/** /**
* Get the label most similar to the reference. The first label will be returned if no reference was supplied. * Get the label most similar to the reference. The first label will be returned if no reference was supplied.
* *
@ -105,11 +185,11 @@ public class CommandDescription {
*/ */
public String getLabel(CommandParts reference) { public String getLabel(CommandParts reference) {
// Ensure there's any item in the command list // Ensure there's any item in the command list
if(this.labels.size() == 0) if (this.labels.size() == 0)
return ""; return "";
// Return the first label if we can't use the reference // Return the first label if we can't use the reference
if(reference == null) if (reference == null)
return this.labels.get(0); return this.labels.get(0);
// Get the correct label from the reference // Get the correct label from the reference
@ -118,9 +198,9 @@ public class CommandDescription {
// Check whether the preferred label is in the label list // Check whether the preferred label is in the label list
double currentDifference = -1; double currentDifference = -1;
String currentLabel = this.labels.get(0); String currentLabel = this.labels.get(0);
for(String entry : this.labels) { for (String entry : this.labels) {
double entryDifference = StringUtils.getDifference(entry, preferred); double entryDifference = StringUtils.getDifference(entry, preferred);
if(entryDifference < currentDifference || currentDifference < 0) { if (entryDifference < currentDifference || currentDifference < 0) {
currentDifference = entryDifference; currentDifference = entryDifference;
currentLabel = entry; currentLabel = entry;
} }
@ -153,27 +233,18 @@ public class CommandDescription {
} }
} }
/**
* Set the command label, this will append the command label to already existing ones.
*
* @param commandLabel Command label to set or add.
*/
public void setLabel(String commandLabel) {
setLabel(commandLabel, false);
}
/** /**
* Set the command label. * Set the command label.
* *
* @param commandLabel Command label to set. * @param commandLabel Command label to set.
* @param overwrite True to replace all old command labels, false to append this command label to the currently * @param overwrite True to replace all old command labels, false to append this command label to the currently
* existing labels. * existing labels.
* *
* @return Trie if the command label is added, or if it was added already. False on failure.
* @return Trie if the command label is added, or if it was added already. False on failure. */ */
public boolean setLabel(String commandLabel, boolean overwrite) { public boolean setLabel(String commandLabel, boolean overwrite) {
// Check whether this new command should overwrite the previous ones // Check whether this new command should overwrite the previous ones
if(!overwrite) if (!overwrite)
return addLabel(commandLabel); return addLabel(commandLabel);
// Replace all labels with this new one // Replace all labels with this new one
@ -186,15 +257,15 @@ public class CommandDescription {
* *
* @param commandLabel Command label to add. * @param commandLabel Command label to add.
* *
* @return True if the label was added, or if it was added already. False on error.
* @return True if the label was added, or if it was added already. False on error. */ */
public boolean addLabel(String commandLabel) { public boolean addLabel(String commandLabel) {
// Verify the label // Verify the label
if(!isValidLabel(commandLabel)) if (!isValidLabel(commandLabel))
return false; return false;
// Ensure this command isn't a duplicate // Ensure this command isn't a duplicate
if(hasLabel(commandLabel)) if (hasLabel(commandLabel))
return true; return true;
// Add the command to the list // Add the command to the list
@ -206,12 +277,12 @@ public class CommandDescription {
* *
* @param commandLabels List of command labels to add. * @param commandLabels List of command labels to add.
* *
* @return True if succeed, false on failure.
* @return True if succeed, false on failure. */ */
public boolean addLabels(List<String> commandLabels) { public boolean addLabels(List<String> commandLabels) {
// Add each command label separately // Add each command label separately
for(String cmd : commandLabels) for (String cmd : commandLabels)
if(!addLabel(cmd)) if (!addLabel(cmd))
return false; return false;
return true; return true;
} }
@ -221,12 +292,12 @@ public class CommandDescription {
* *
* @param commandLabel Command to check for. * @param commandLabel Command to check for.
* *
* @return True if this command label equals to the param command.
* @return True if this command label equals to the param command. */ */
public boolean hasLabel(String commandLabel) { public boolean hasLabel(String commandLabel) {
// Check whether any command matches with the argument // Check whether any command matches with the argument
for(String entry : this.labels) for (String entry : this.labels)
if(commandLabelEquals(entry, commandLabel)) if (commandLabelEquals(entry, commandLabel))
return true; return true;
// No match found, return false // No match found, return false
@ -235,13 +306,15 @@ public class CommandDescription {
/** /**
* Check whether this command description has a list of labels * Check whether this command description has a list of labels
*
* @param commandLabels List of labels * @param commandLabels List of labels
*
* @return True if all labels match, false otherwise */ * @return True if all labels match, false otherwise
*/
public boolean hasLabels(List<String> commandLabels) { public boolean hasLabels(List<String> commandLabels) {
// Check if there's a match for every command // Check if there's a match for every command
for(String cmd : commandLabels) for (String cmd : commandLabels)
if(!hasLabel(cmd)) if (!hasLabel(cmd))
return false; return false;
// There seems to be a match for every command, return true // There seems to be a match for every command, return true
@ -254,11 +327,11 @@ public class CommandDescription {
* *
* @param commandReference The command reference. * @param commandReference The command reference.
* *
* @return True if the command reference is suitable to this command label, false otherwise.
* @return True if the command reference is suitable to this command label, false otherwise. */ */
public boolean isSuitableLabel(CommandParts commandReference) { public boolean isSuitableLabel(CommandParts commandReference) {
// Make sure the command reference is valid // Make sure the command reference is valid
if(commandReference.getCount() <= 0) if (commandReference.getCount() <= 0)
return false; return false;
// Get the parent count // Get the parent count
@ -268,29 +341,6 @@ public class CommandDescription {
return hasLabel(element); return hasLabel(element);
} }
/**
* Check whether a label is valid to use.
*
* @param label The label to test.
*
* @return True if the label is valid to use, false otherwise. */
public static boolean isValidLabel(String label) {
// Make sure the label isn't null
if(label == null)
return false;
// Trim the label
label = label.trim();
// Make sure the label is at least one character long
if(label.length() <= 0)
return false;
// Make sure the label doesn't contain any spaces, return the result
return !label.contains(" ");
}
/** /**
* Get the absolute command label, without a slash. * Get the absolute command label, without a slash.
* *
@ -304,6 +354,7 @@ public class CommandDescription {
* Get the absolute command label. * Get the absolute command label.
* *
* @param includeSlash boolean * @param includeSlash boolean
*
* @return Absolute command label. * @return Absolute command label.
*/ */
public String getAbsoluteLabel(boolean includeSlash) { public String getAbsoluteLabel(boolean includeSlash) {
@ -313,14 +364,15 @@ public class CommandDescription {
/** /**
* Get the absolute command label. * Get the absolute command label.
* *
* @param includeSlash boolean * @param includeSlash
* @param reference CommandParts * @param reference
*
* @return Absolute command label. * @return Absolute command label.
*/ */
public String getAbsoluteLabel(boolean includeSlash, CommandParts reference) { public String getAbsoluteLabel(boolean includeSlash, CommandParts reference) {
// Get the command reference, and make sure it is valid // Get the command reference, and make sure it is valid
CommandParts out = getCommandReference(reference); CommandParts out = getCommandReference(reference);
if(out == null) if (out == null)
return ""; return "";
// Return the result // Return the result
@ -339,7 +391,7 @@ public class CommandDescription {
List<String> referenceList = new ArrayList<>(); List<String> referenceList = new ArrayList<>();
// Check whether this command has a parent, if so, add the absolute parent command // Check whether this command has a parent, if so, add the absolute parent command
if(getParent() != null) if (getParent() != null)
referenceList.addAll(getParent().getCommandReference(reference).getList()); referenceList.addAll(getParent().getCommandReference(reference).getList());
// Get the current label // Get the current label
@ -363,14 +415,14 @@ public class CommandDescription {
/** /**
* Get the difference between this command and another command reference. * Get the difference between this command and another command reference.
* *
* @param other The other command reference. * @param other The other command reference.
* @param fullCompare True to fully compare both command references. * @param fullCompare True to fully compare both command references.
* *
* @return The command difference. Zero if there's no difference. A negative number on error. * @return The command difference. Zero if there's no difference. A negative number on error.
*/ */
public double getCommandDifference(CommandParts other, boolean fullCompare) { public double getCommandDifference(CommandParts other, boolean fullCompare) {
// Make sure the reference is valid // Make sure the reference is valid
if(other == null) if (other == null)
return -1; return -1;
// Get the command reference // Get the command reference
@ -410,7 +462,7 @@ public class CommandDescription {
/** /**
* Execute the command, if possible. * Execute the command, if possible.
* *
* @param sender The command sender that triggered the execution of this command. * @param sender The command sender that triggered the execution of this command.
* @param commandReference The command reference. * @param commandReference The command reference.
* @param commandArguments The command arguments. * @param commandArguments The command arguments.
* *
@ -418,7 +470,7 @@ public class CommandDescription {
*/ */
public boolean execute(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) { public boolean execute(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
// Make sure the command is executable // Make sure the command is executable
if(!isExecutable()) if (!isExecutable())
return false; return false;
// Execute the command, return the result // Execute the command, return the result
@ -428,8 +480,8 @@ public class CommandDescription {
/** /**
* Get the parent command if this command description has a parent. * Get the parent command if this command description has a parent.
* *
* @return Parent command, or null
* @return Parent command, or null */ */
public CommandDescription getParent() { public CommandDescription getParent() {
return this.parent; return this.parent;
} }
@ -437,11 +489,11 @@ public class CommandDescription {
/** /**
* Get the number of parent this description has. * Get the number of parent this description has.
* *
* @return The number of parents.
* @return The number of parents. */ */
public int getParentCount() { public int getParentCount() {
// Check whether the this description has a parent // Check whether the this description has a parent
if(!hasParent()) if (!hasParent())
return 0; return 0;
// Get the parent count of the parent, return the result // Get the parent count of the parent, return the result
@ -453,18 +505,18 @@ public class CommandDescription {
* *
* @param parent Parent command. * @param parent Parent command.
* *
* @return True on success, false on failure.
* @return True on success, false on failure. */ */
public boolean setParent(CommandDescription parent) { public boolean setParent(CommandDescription parent) {
// Make sure the parent is different // Make sure the parent is different
if(this.parent == parent) if (this.parent == parent)
return true; return true;
// Set the parent // Set the parent
this.parent = parent; this.parent = parent;
// Make sure the parent isn't null // Make sure the parent isn't null
if(parent == null) if (parent == null)
return true; return true;
// Add this description as a child to the parent // Add this description as a child to the parent
@ -474,8 +526,8 @@ public class CommandDescription {
/** /**
* Check whether the plugin description has a parent command. * Check whether the plugin description has a parent command.
* *
* @return True if the description has a parent command, false otherwise.
* @return True if the description has a parent command, false otherwise. */ */
public boolean hasParent() { public boolean hasParent() {
return this.parent != null; return this.parent != null;
} }
@ -483,38 +535,12 @@ public class CommandDescription {
/** /**
* Get all command children. * Get all command children.
* *
* @return Command children.
* @return Command children. */ */
public List<CommandDescription> getChildren() { public List<CommandDescription> getChildren() {
return this.children; return this.children;
} }
/**
* Add a child to the command description.
*
* @param commandDescription The child to add.
*
* @return True on success, false on failure. */
public boolean addChild(CommandDescription commandDescription) {
// Make sure the description is valid
if(commandDescription == null)
return false;
if(!commandDescription.isValid())
return false;
// Make sure the child doesn't exist already
if(isChild(commandDescription))
return true;
// The command description to add as a child
if(!this.children.add(commandDescription))
return false;
// Set this description as parent on the child
return commandDescription.setParent(this);
}
/** /**
* Set the children of this command. * Set the children of this command.
* *
@ -522,19 +548,45 @@ public class CommandDescription {
*/ */
public void setChildren(List<CommandDescription> children) { public void setChildren(List<CommandDescription> children) {
// Check whether the children list should be cleared // Check whether the children list should be cleared
if(children == null) if (children == null)
this.children.clear(); this.children.clear();
else else
this.children = children; this.children = children;
} }
/**
* Add a child to the command description.
*
* @param commandDescription The child to add.
*
* @return True on success, false on failure.
*/
public boolean addChild(CommandDescription commandDescription) {
// Make sure the description is valid
if (commandDescription == null)
return false;
if (!commandDescription.isValid())
return false;
// Make sure the child doesn't exist already
if (isChild(commandDescription))
return true;
// The command description to add as a child
if (!this.children.add(commandDescription))
return false;
// Set this description as parent on the child
return commandDescription.setParent(this);
}
/** /**
* Check whether this command has any child labels. * Check whether this command has any child labels.
* *
* @return True if this command has any child labels.
* @return True if this command has any child labels. */ */
public boolean hasChilds() { public boolean hasChildren() {
return (this.children.size() != 0); return (this.children.size() != 0);
} }
@ -543,13 +595,13 @@ public class CommandDescription {
* *
* @param commandDescription The command description to check for. * @param commandDescription The command description to check for.
* *
* @return True if this command description has the specific child, false otherwise.
* @return True if this command description has the specific child, false otherwise. */ */
public boolean isChild(CommandDescription commandDescription) { public boolean isChild(CommandDescription commandDescription) {
// Make sure the description is valid // Make sure the description is valid
if(commandDescription == null) if (commandDescription == null)
return false; return false;
if(!commandDescription.isValid()) if (!commandDescription.isValid())
return false; return false;
// Check whether this child exists, return the result // Check whether this child exists, return the result
@ -561,15 +613,15 @@ public class CommandDescription {
* *
* @param argument The argument to add. * @param argument The argument to add.
* *
* @return True if succeed, false if failed.
* @return True if succeed, false if failed. */ */
public boolean addArgument(CommandArgumentDescription argument) { public boolean addArgument(CommandArgumentDescription argument) {
// Make sure the argument is valid // Make sure the argument is valid
if(argument == null) if (argument == null)
return false; return false;
// Make sure the argument isn't added already // Make sure the argument isn't added already
if(hasArgument(argument)) if (hasArgument(argument))
return true; return true;
// Add the argument, return the result // Add the argument, return the result
@ -630,9 +682,9 @@ public class CommandDescription {
int optionalArgument = 0; int optionalArgument = 0;
// Loop through each argument // Loop through each argument
for(CommandArgumentDescription argument : this.arguments) { for (CommandArgumentDescription argument : this.arguments) {
// Check whether the command is optional // Check whether the command is optional
if(!argument.isOptional()) { if (!argument.isOptional()) {
requiredArguments += optionalArgument + 1; requiredArguments += optionalArgument + 1;
optionalArgument = 0; optionalArgument = 0;
@ -647,11 +699,11 @@ public class CommandDescription {
/** /**
* Get the maximum number of arguments. * Get the maximum number of arguments.
* *
* @return The maximum number of arguments. A negative number will be returned if there's no maximum.
* @return The maximum number of arguments. A negative number will be returned if there's no maximum. */ */
public int getMaximumArguments() { public int getMaximumArguments() {
// Check whether there is a maximum set // Check whether there is a maximum set
if(this.noArgumentMaximum) if (this.noArgumentMaximum)
return -1; return -1;
// Return the maximum based on the registered arguments // Return the maximum based on the registered arguments
@ -671,8 +723,8 @@ public class CommandDescription {
/** /**
* Get the command description. * Get the command description.
* *
* @return Command description.
* @return Command description. */ */
public String getDescription() { public String getDescription() {
return hasDescription() ? this.description : this.detailedDescription; return hasDescription() ? this.description : this.detailedDescription;
} }
@ -683,7 +735,7 @@ public class CommandDescription {
* @param description New command description. Null to reset the description. * @param description New command description. Null to reset the description.
*/ */
public void setDescription(String description) { public void setDescription(String description) {
if(description == null) if (description == null)
this.description = ""; this.description = "";
else else
@ -693,8 +745,8 @@ public class CommandDescription {
/** /**
* Check whether this command has any description. * Check whether this command has any description.
* *
* @return True if this command has any description.
* @return True if this command has any description. */ */
public boolean hasDescription() { public boolean hasDescription() {
return (this.description.trim().length() != 0); return (this.description.trim().length() != 0);
} }
@ -702,8 +754,8 @@ public class CommandDescription {
/** /**
* Get the command detailed description. * Get the command detailed description.
* *
* @return Command detailed description.
* @return Command detailed description. */ */
public String getDetailedDescription() { public String getDetailedDescription() {
return hasDetailedDescription() ? this.detailedDescription : this.description; return hasDetailedDescription() ? this.detailedDescription : this.description;
} }
@ -714,7 +766,7 @@ public class CommandDescription {
* @param detailedDescription New command description. Null to reset the description. * @param detailedDescription New command description. Null to reset the description.
*/ */
public void setDetailedDescription(String detailedDescription) { public void setDetailedDescription(String detailedDescription) {
if(detailedDescription == null) if (detailedDescription == null)
this.detailedDescription = ""; this.detailedDescription = "";
else else
@ -724,8 +776,8 @@ public class CommandDescription {
/** /**
* Check whether this command has any detailed description. * Check whether this command has any detailed description.
* *
* @return True if this command has any detailed description.
* @return True if this command has any detailed description. */ */
public boolean hasDetailedDescription() { public boolean hasDetailedDescription() {
return (this.detailedDescription.trim().length() != 0); return (this.detailedDescription.trim().length() != 0);
} }
@ -735,35 +787,35 @@ public class CommandDescription {
* *
* @param queryReference The query reference to find a command for. * @param queryReference The query reference to find a command for.
* *
* @return The command found, or null.
* @return The command found, or null. */ */
public FoundCommandResult findCommand(final CommandParts queryReference) { public FoundCommandResult findCommand(final CommandParts queryReference) {
// Make sure the command reference is valid // Make sure the command reference is valid
if(queryReference.getCount() <= 0) if (queryReference.getCount() <= 0)
return null; return null;
// Check whether this description is for the last element in the command reference, if so return the current command // Check whether this description is for the last element in the command reference, if so return the current command
if(queryReference.getCount() <= getParentCount() + 1) if (queryReference.getCount() <= getParentCount() + 1)
return new FoundCommandResult( return new FoundCommandResult(
this, this,
getCommandReference(queryReference), getCommandReference(queryReference),
new CommandParts(), new CommandParts(),
queryReference); queryReference);
// Get the new command reference and arguments // Get the new command reference and arguments
CommandParts newReference = new CommandParts(queryReference.getRange(0, getParentCount() + 1)); CommandParts newReference = new CommandParts(queryReference.getRange(0, getParentCount() + 1));
CommandParts newArguments = new CommandParts(queryReference.getRange(getParentCount() + 1)); CommandParts newArguments = new CommandParts(queryReference.getRange(getParentCount() + 1));
// Handle the child's, if this command has any // Handle the child's, if this command has any
if(getChildren().size() > 0) { if (getChildren().size() > 0) {
// Get a new instance of the child's list, and sort them by their difference in comparison to the query reference // Get a new instance of the child's list, and sort them by their difference in comparison to the query reference
List<CommandDescription> commandChildren = new ArrayList<>(getChildren()); List<CommandDescription> commandChildren = new ArrayList<>(getChildren());
Collections.sort(commandChildren, new Comparator<CommandDescription>() { Collections.sort(commandChildren, new Comparator<CommandDescription>() {
@Override @Override
public int compare(CommandDescription o1, CommandDescription o2) { public int compare(CommandDescription o1, CommandDescription o2) {
return Double.compare( return Double.compare(
o1.getCommandDifference(queryReference), o1.getCommandDifference(queryReference),
o2.getCommandDifference(queryReference)); o2.getCommandDifference(queryReference));
} }
}); });
@ -771,21 +823,21 @@ public class CommandDescription {
double firstChildDifference = commandChildren.get(0).getCommandDifference(queryReference, true); double firstChildDifference = commandChildren.get(0).getCommandDifference(queryReference, true);
// Check if the reference perfectly suits the arguments of the current command if it doesn't perfectly suits a child command // Check if the reference perfectly suits the arguments of the current command if it doesn't perfectly suits a child command
if(firstChildDifference > 0.0) if (firstChildDifference > 0.0)
if(getSuitableArgumentsDifference(queryReference) == 0) if (getSuitableArgumentsDifference(queryReference) == 0)
return new FoundCommandResult(this, newReference, newArguments, queryReference); return new FoundCommandResult(this, newReference, newArguments, queryReference);
// Loop through each child // Loop through each child
for(CommandDescription child : commandChildren) { for (CommandDescription child : commandChildren) {
// Get the best suitable command // Get the best suitable command
FoundCommandResult result = child.findCommand(queryReference); FoundCommandResult result = child.findCommand(queryReference);
if(result != null) if (result != null)
return result; return result;
} }
} }
// Check if the remaining command reference elements fit the arguments for this command // Check if the remaining command reference elements fit the arguments for this command
if(getSuitableArgumentsDifference(queryReference) >= 0) if (getSuitableArgumentsDifference(queryReference) >= 0)
return new FoundCommandResult(this, newReference, newArguments, queryReference); return new FoundCommandResult(this, newReference, newArguments, queryReference);
// No command found, return null // No command found, return null
@ -797,8 +849,8 @@ public class CommandDescription {
* *
* @param commandReference The command reference. * @param commandReference The command reference.
* *
* @return True if so, false otherwise.
* @return True if so, false otherwise. */ */
public boolean hasSuitableCommand(CommandParts commandReference) { public boolean hasSuitableCommand(CommandParts commandReference) {
return findCommand(commandReference) != null; return findCommand(commandReference) != null;
} }
@ -808,8 +860,8 @@ public class CommandDescription {
* *
* @param commandReference The command reference. * @param commandReference The command reference.
* *
* @return True if the arguments are suitable, false otherwise.
* @return True if the arguments are suitable, false otherwise. */ */
public boolean hasSuitableArguments(CommandParts commandReference) { public boolean hasSuitableArguments(CommandParts commandReference) {
return getSuitableArgumentsDifference(commandReference) == 0; return getSuitableArgumentsDifference(commandReference) == 0;
} }
@ -866,27 +918,13 @@ public class CommandDescription {
/** /**
* Set the command permissions. * Set the command permissions.
* *
* @param permissionNode The permission node required. * @param permissionNode The permission node required.
* @param defaultPermission The default permission. * @param defaultPermission The default permission.
*/ */
public void setCommandPermissions(String permissionNode, CommandPermissions.DefaultPermission defaultPermission) { public void setCommandPermissions(String permissionNode, CommandPermissions.DefaultPermission defaultPermission) {
this.permissions = new CommandPermissions(permissionNode, defaultPermission); this.permissions = new CommandPermissions(permissionNode, defaultPermission);
} }
/**
* Check whether two labels equal to each other.
*
* @param commandLabel The first command label.
* @param otherCommandLabel The other command label.
*
* @return True if the labels are equal to each other.
*/
private static boolean commandLabelEquals(String commandLabel, String otherCommandLabel) {
commandLabel = commandLabel.trim();
otherCommandLabel = otherCommandLabel.trim();
return commandLabel.equalsIgnoreCase(otherCommandLabel);
}
/** /**
* Check whether the command description has been set up properly. * Check whether the command description has been set up properly.
* *

View File

@ -1,20 +1,21 @@
package fr.xephi.authme.command; package fr.xephi.authme.command;
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.command.help.HelpProvider;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.command.help.HelpProvider;
/** /**
*/ */
public class CommandHandler { public class CommandHandler {
/** The command manager instance. */ /**
* The command manager instance.
*/
private CommandManager commandManager; private CommandManager commandManager;
/** /**
@ -24,19 +25,19 @@ public class CommandHandler {
*/ */
public CommandHandler(boolean init) { public CommandHandler(boolean init) {
// Initialize // Initialize
if(init) if (init)
init(); init();
} }
/** /**
* Initialize the command handler. * Initialize the command handler.
* *
* @return True if succeed, false on failure. True will also be returned if the command handler was already * @return True if succeed, false on failure. True will also be returned if the command handler was already
* initialized. */ * initialized.
*/
public boolean init() { public boolean init() {
// Make sure the handler isn't initialized already // Make sure the handler isn't initialized already
if(isInit()) if (isInit())
return true; return true;
// Initialize the command manager // Initialize the command manager
@ -50,8 +51,8 @@ public class CommandHandler {
/** /**
* Check whether the command handler is initialized. * Check whether the command handler is initialized.
* *
* @return True if the command handler is initialized.
* @return True if the command handler is initialized. */ */
public boolean isInit() { public boolean isInit() {
return this.commandManager != null; return this.commandManager != null;
} }
@ -59,12 +60,12 @@ public class CommandHandler {
/** /**
* Destroy the command handler. * Destroy the command handler.
* *
* @return True if the command handler was destroyed successfully, false otherwise. True will also be returned if * @return True if the command handler was destroyed successfully, false otherwise. True will also be returned if
* the command handler wasn't initialized. */ * the command handler wasn't initialized.
*/
public boolean destroy() { public boolean destroy() {
// Make sure the command handler is initialized // Make sure the command handler is initialized
if(!isInit()) if (!isInit())
return true; return true;
// Unset the command manager // Unset the command manager
@ -75,8 +76,8 @@ public class CommandHandler {
/** /**
* Get the command manager. * Get the command manager.
* *
* @return Command manager instance.
* @return Command manager instance. */ */
public CommandManager getCommandManager() { public CommandManager getCommandManager() {
return this.commandManager; return this.commandManager;
} }
@ -84,26 +85,26 @@ public class CommandHandler {
/** /**
* Process a command. * Process a command.
* *
* @param sender The command sender (Bukkit). * @param sender The command sender (Bukkit).
* @param bukkitCommand The command (Bukkit). * @param bukkitCommand The command (Bukkit).
* @param bukkitCommandLabel The command label (Bukkit). * @param bukkitCommandLabel The command label (Bukkit).
* @param bukkitArgs The command arguments (Bukkit). * @param bukkitArgs The command arguments (Bukkit).
* *
* @return True if the command was executed, false otherwise.
* @return True if the command was executed, false otherwise. */ */
public boolean onCommand(CommandSender sender, org.bukkit.command.Command bukkitCommand, String bukkitCommandLabel, String[] bukkitArgs) { public boolean onCommand(CommandSender sender, org.bukkit.command.Command bukkitCommand, String bukkitCommandLabel, String[] bukkitArgs) {
// Process the arguments // Process the arguments
List<String> args = processArguments(bukkitArgs); List<String> args = processArguments(bukkitArgs);
// Create a command reference, and make sure at least one command part is available // Create a command reference, and make sure at least one command part is available
CommandParts commandReference = new CommandParts(bukkitCommandLabel, args); CommandParts commandReference = new CommandParts(bukkitCommandLabel, args);
if(commandReference.getCount() == 0) if (commandReference.getCount() == 0)
return false; return false;
// Get a suitable command for this reference, and make sure it isn't null // Get a suitable command for this reference, and make sure it isn't null
FoundCommandResult result = this.commandManager.findCommand(commandReference); FoundCommandResult result = this.commandManager.findCommand(commandReference);
if(result == null) { if (result == null) {
sender.sendMessage(ChatColor.DARK_RED + "Failed to parse " + AuthMe.PLUGIN_NAME + " command!"); sender.sendMessage(ChatColor.DARK_RED + "Failed to parse " + AuthMe.getPluginName() + " command!");
return false; return false;
} }
@ -112,13 +113,13 @@ public class CommandHandler {
// Make sure the difference between the command reference and the actual command isn't too big // Make sure the difference between the command reference and the actual command isn't too big
final double commandDifference = result.getDifference(); final double commandDifference = result.getDifference();
if(commandDifference > 0.12) { if (commandDifference > 0.12) {
// Show the unknown command warning // Show the unknown command warning
sender.sendMessage(ChatColor.DARK_RED + "Unknown command!"); sender.sendMessage(ChatColor.DARK_RED + "Unknown command!");
// Show a command suggestion if available and the difference isn't too big // Show a command suggestion if available and the difference isn't too big
if(commandDifference < 0.75) if (commandDifference < 0.75)
if(result.getCommandDescription() != null) if (result.getCommandDescription() != null)
sender.sendMessage(ChatColor.YELLOW + "Did you mean " + ChatColor.GOLD + "/" + result.getCommandDescription().getCommandReference(commandReference) + ChatColor.YELLOW + "?"); sender.sendMessage(ChatColor.YELLOW + "Did you mean " + ChatColor.GOLD + "/" + result.getCommandDescription().getCommandReference(commandReference) + ChatColor.YELLOW + "?");
// Show the help command // Show the help command
@ -127,17 +128,17 @@ public class CommandHandler {
} }
// Show a message when the command handler is assuming a command // Show a message when the command handler is assuming a command
if(commandDifference > 0) { if (commandDifference > 0) {
// Get the suggested command // Get the suggested command
CommandParts suggestedCommandParts = new CommandParts(result.getCommandDescription().getCommandReference(commandReference)); CommandParts suggestedCommandParts = new CommandParts(result.getCommandDescription().getCommandReference(commandReference));
// Show the suggested command // Show the suggested command
sender.sendMessage(ChatColor.DARK_RED + "Unknown command, assuming " + ChatColor.GOLD + "/" + suggestedCommandParts + sender.sendMessage(ChatColor.DARK_RED + "Unknown command, assuming " + ChatColor.GOLD + "/" + suggestedCommandParts +
ChatColor.DARK_RED + "!"); ChatColor.DARK_RED + "!");
} }
// Make sure the command is executable // Make sure the command is executable
if(!result.isExecutable()) { if (!result.isExecutable()) {
// Get the command reference // Get the command reference
CommandParts helpCommandReference = new CommandParts(result.getCommandReference().getRange(1)); CommandParts helpCommandReference = new CommandParts(result.getCommandReference().getRange(1));
@ -150,14 +151,14 @@ public class CommandHandler {
} }
// Make sure the command sender has permission // Make sure the command sender has permission
if(!result.hasPermission(sender)) { if (!result.hasPermission(sender)) {
// Show the no permissions warning // Show the no permissions warning
sender.sendMessage(ChatColor.DARK_RED + "You don't have permission to use this command!"); sender.sendMessage(ChatColor.DARK_RED + "You don't have permission to use this command!");
return true; return true;
} }
// Make sure the command sender has permission // Make sure the command sender has permission
if(!result.hasProperArguments()) { if (!result.hasProperArguments()) {
// Get the command and the suggested command reference // Get the command and the suggested command reference
CommandParts suggestedCommandReference = new CommandParts(result.getCommandDescription().getCommandReference(commandReference)); CommandParts suggestedCommandReference = new CommandParts(result.getCommandDescription().getCommandReference(commandReference));
CommandParts helpCommandReference = new CommandParts(suggestedCommandReference.getRange(1)); CommandParts helpCommandReference = new CommandParts(suggestedCommandReference.getRange(1));
@ -182,19 +183,19 @@ public class CommandHandler {
* *
* @param args The command arguments to process. * @param args The command arguments to process.
* *
* @return The processed command arguments.
* @return The processed command arguments. */ */
private List<String> processArguments(String[] args) { private List<String> processArguments(String[] args) {
// Convert the array into a list of arguments // Convert the array into a list of arguments
List<String> arguments = new ArrayList<>(Arrays.asList(args)); List<String> arguments = new ArrayList<>(Arrays.asList(args));
/// Remove all empty arguments /// Remove all empty arguments
for(int i = 0; i < arguments.size(); i++) { for (int i = 0; i < arguments.size(); i++) {
// Get the argument value // Get the argument value
final String arg = arguments.get(i); final String arg = arguments.get(i);
// Check whether the argument value is empty // Check whether the argument value is empty
if(arg.trim().length() == 0) { if (arg.trim().length() == 0) {
// Remove the current argument // Remove the current argument
arguments.remove(i); arguments.remove(i);

View File

@ -1,29 +1,7 @@
package fr.xephi.authme.command; package fr.xephi.authme.command;
import java.util.ArrayList;
import java.util.List;
import fr.xephi.authme.command.executable.HelpCommand; import fr.xephi.authme.command.executable.HelpCommand;
import fr.xephi.authme.command.executable.authme.AccountsCommand; import fr.xephi.authme.command.executable.authme.*;
import fr.xephi.authme.command.executable.authme.AuthMeCommand;
import fr.xephi.authme.command.executable.authme.ChangePasswordCommand;
import fr.xephi.authme.command.executable.authme.FirstSpawnCommand;
import fr.xephi.authme.command.executable.authme.ForceLoginCommand;
import fr.xephi.authme.command.executable.authme.GetEmailCommand;
import fr.xephi.authme.command.executable.authme.GetIpCommand;
import fr.xephi.authme.command.executable.authme.LastLoginCommand;
import fr.xephi.authme.command.executable.authme.PurgeBannedPlayersCommand;
import fr.xephi.authme.command.executable.authme.PurgeCommand;
import fr.xephi.authme.command.executable.authme.PurgeLastPositionCommand;
import fr.xephi.authme.command.executable.authme.RegisterCommand;
import fr.xephi.authme.command.executable.authme.ReloadCommand;
import fr.xephi.authme.command.executable.authme.SetEmailCommand;
import fr.xephi.authme.command.executable.authme.SetFirstSpawnCommand;
import fr.xephi.authme.command.executable.authme.SetSpawnCommand;
import fr.xephi.authme.command.executable.authme.SpawnCommand;
import fr.xephi.authme.command.executable.authme.SwitchAntiBotCommand;
import fr.xephi.authme.command.executable.authme.UnregisterCommand;
import fr.xephi.authme.command.executable.authme.VersionCommand;
import fr.xephi.authme.command.executable.captcha.CaptchaCommand; import fr.xephi.authme.command.executable.captcha.CaptchaCommand;
import fr.xephi.authme.command.executable.converter.ConverterCommand; import fr.xephi.authme.command.executable.converter.ConverterCommand;
import fr.xephi.authme.command.executable.email.AddEmailCommand; import fr.xephi.authme.command.executable.email.AddEmailCommand;
@ -32,18 +10,22 @@ import fr.xephi.authme.command.executable.email.RecoverEmailCommand;
import fr.xephi.authme.command.executable.login.LoginCommand; import fr.xephi.authme.command.executable.login.LoginCommand;
import fr.xephi.authme.command.executable.logout.LogoutCommand; import fr.xephi.authme.command.executable.logout.LogoutCommand;
import java.util.ArrayList;
import java.util.List;
/** /**
*/ */
public class CommandManager { public class CommandManager {
/** The list of commandDescriptions. */ /**
private List<CommandDescription> commandDescriptions = new ArrayList<>(); * The list of commandDescriptions.
*/
private final List<CommandDescription> commandDescriptions = new ArrayList<>();
/** /**
* Constructor. * Constructor.
* *
* @param registerCommands * @param registerCommands True to register the commands, false otherwise.
* True to register the commands, false otherwise.
*/ */
public CommandManager(boolean registerCommands) { public CommandManager(boolean registerCommands) {
// Register the commands // Register the commands
@ -55,7 +37,7 @@ public class CommandManager {
* Register all commands. * Register all commands.
*/ */
// TODO ljacqu 20151121: Create a builder class for CommandDescription // TODO ljacqu 20151121: Create a builder class for CommandDescription
@SuppressWarnings({ "serial" }) @SuppressWarnings({"serial"})
public void registerCommands() { public void registerCommands() {
// Register the base AuthMe Reloaded command // Register the base AuthMe Reloaded command
CommandDescription authMeBaseCommand = new CommandDescription(new AuthMeCommand(), new ArrayList<String>() { CommandDescription authMeBaseCommand = new CommandDescription(new AuthMeCommand(), new ArrayList<String>() {
@ -574,8 +556,8 @@ public class CommandManager {
/** /**
* Get the list of command descriptions * Get the list of command descriptions
* *
* @return List of command descriptions.
* @return List of command descriptions. */ */
public List<CommandDescription> getCommandDescriptions() { public List<CommandDescription> getCommandDescriptions() {
return this.commandDescriptions; return this.commandDescriptions;
} }
@ -583,8 +565,8 @@ public class CommandManager {
/** /**
* Get the number of command description count. * Get the number of command description count.
* *
* @return Command description count.
* @return Command description count. */ */
public int getCommandDescriptionCount() { public int getCommandDescriptionCount() {
return this.getCommandDescriptions().size(); return this.getCommandDescriptions().size();
} }
@ -592,11 +574,10 @@ public class CommandManager {
/** /**
* Find the best suitable command for the specified reference. * Find the best suitable command for the specified reference.
* *
* @param queryReference * @param queryReference The query reference to find a command for.
* The query reference to find a command for.
* *
* @return The command found, or null.
* @return The command found, or null. */ */
public FoundCommandResult findCommand(CommandParts queryReference) { public FoundCommandResult findCommand(CommandParts queryReference) {
// Make sure the command reference is valid // Make sure the command reference is valid
if (queryReference.getCount() <= 0) if (queryReference.getCount() <= 0)

View File

@ -1,21 +1,24 @@
package fr.xephi.authme.command; package fr.xephi.authme.command;
import fr.xephi.authme.util.StringUtils;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import fr.xephi.authme.util.StringUtils;
/** /**
*/ */
public class CommandParts { public class CommandParts {
/** The list of parts for this command. */ /**
private List<String> parts = new ArrayList<>(); * The list of parts for this command.
*/
private final List<String> parts = new ArrayList<>();
/** /**
* Constructor. * Constructor.
*/ */
public CommandParts() { } public CommandParts() {
}
/** /**
* Constructor. * Constructor.
@ -47,7 +50,7 @@ public class CommandParts {
/** /**
* Constructor. * Constructor.
* *
* @param base The base part. * @param base The base part.
* @param parts The list of additional parts. * @param parts The list of additional parts.
*/ */
public CommandParts(String base, List<String> parts) { public CommandParts(String base, List<String> parts) {
@ -58,8 +61,8 @@ public class CommandParts {
/** /**
* Get the command parts. * Get the command parts.
* *
* @return Command parts.
* @return Command parts. */ */
public List<String> getList() { public List<String> getList() {
return this.parts; return this.parts;
} }
@ -69,8 +72,8 @@ public class CommandParts {
* *
* @param part The part to add. * @param part The part to add.
* *
* @return The result.
* @return The result. */ */
public boolean add(String part) { public boolean add(String part) {
return this.parts.add(part); return this.parts.add(part);
} }
@ -80,8 +83,8 @@ public class CommandParts {
* *
* @param parts The parts to add. * @param parts The parts to add.
* *
* @return The result.
* @return The result. */ */
public boolean add(List<String> parts) { public boolean add(List<String> parts) {
return this.parts.addAll(parts); return this.parts.addAll(parts);
} }
@ -91,10 +94,10 @@ public class CommandParts {
* *
* @param parts The parts to add. * @param parts The parts to add.
* *
* @return The result.
* @return The result. */ */
public boolean add(String[] parts) { public boolean add(String[] parts) {
for(String entry : parts) for (String entry : parts)
add(entry); add(entry);
return true; return true;
} }
@ -102,8 +105,8 @@ public class CommandParts {
/** /**
* Get the number of parts. * Get the number of parts.
* *
* @return Part count.
* @return Part count. */ */
public int getCount() { public int getCount() {
return this.parts.size(); return this.parts.size();
} }
@ -113,11 +116,11 @@ public class CommandParts {
* *
* @param i Part index. * @param i Part index.
* *
* @return The part.
* @return The part. */ */
public String get(int i) { public String get(int i) {
// Make sure the index is in-bound // Make sure the index is in-bound
if(i < 0 || i >= getCount()) if (i < 0 || i >= getCount())
return null; return null;
// Get and return the argument // Get and return the argument
@ -129,8 +132,8 @@ public class CommandParts {
* *
* @param start The starting index. * @param start The starting index.
* *
* @return The parts range. Arguments that were out of bound are not included.
* @return The parts range. Arguments that were out of bound are not included. */ */
public List<String> getRange(int start) { public List<String> getRange(int start) {
return getRange(start, getCount() - start); return getRange(start, getCount() - start);
} }
@ -141,17 +144,17 @@ public class CommandParts {
* @param start The starting index. * @param start The starting index.
* @param count The number of parts to get. * @param count The number of parts to get.
* *
* @return The parts range. Parts that were out of bound are not included.
* @return The parts range. Parts that were out of bound are not included. */ */
public List<String> getRange(int start, int count) { public List<String> getRange(int start, int count) {
// Create a new list to put the range into // Create a new list to put the range into
List<String> elements = new ArrayList<>(); List<String> elements = new ArrayList<>();
// Get the range // Get the range
for(int i = start; i < start + count; i++) { for (int i = start; i < start + count; i++) {
// Get the part and add it if it's valid // Get the part and add it if it's valid
String element = get(i); String element = get(i);
if(element != null) if (element != null)
elements.add(element); elements.add(element);
} }
@ -173,21 +176,21 @@ public class CommandParts {
/** /**
* Get the difference value between two references. * Get the difference value between two references.
* *
* @param other The other reference. * @param other The other reference.
* @param fullCompare True to compare the full references as far as the range reaches. * @param fullCompare True to compare the full references as far as the range reaches.
* *
* @return The result from zero to above. A negative number will be returned on error. * @return The result from zero to above. A negative number will be returned on error.
*/ */
public double getDifference(CommandParts other, boolean fullCompare) { public double getDifference(CommandParts other, boolean fullCompare) {
// Make sure the other reference is correct // Make sure the other reference is correct
if(other == null) if (other == null)
return -1; return -1;
// Get the range to use // Get the range to use
int range = Math.min(this.getCount(), other.getCount()); int range = Math.min(this.getCount(), other.getCount());
// Get and the difference // Get and the difference
if(fullCompare) if (fullCompare)
return StringUtils.getDifference(this.toString(), other.toString()); return StringUtils.getDifference(this.toString(), other.toString());
return StringUtils.getDifference(this.getRange(range - 1, 1).toString(), other.getRange(range - 1, 1).toString()); return StringUtils.getDifference(this.getRange(range - 1, 1).toString(), other.getRange(range - 1, 1).toString());
} }

View File

@ -1,34 +1,39 @@
package fr.xephi.authme.command; package fr.xephi.authme.command;
import java.util.ArrayList; import fr.xephi.authme.AuthMe;
import java.util.List;
import fr.xephi.authme.permission.PermissionsManager; import fr.xephi.authme.permission.PermissionsManager;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
//import com.timvisee.dungeonmaze.Core; //import com.timvisee.dungeonmaze.Core;
//import com.timvisee.dungeonmaze.permission.PermissionsManager; //import com.timvisee.dungeonmaze.permission.PermissionsManager;
import fr.xephi.authme.AuthMe;
/** /**
*/ */
public class CommandPermissions { public class CommandPermissions {
/** Defines the permission nodes required to have permission to execute this command. */ /**
* Defines the permission nodes required to have permission to execute this command.
*/
private List<String> permissionNodes = new ArrayList<>(); private List<String> permissionNodes = new ArrayList<>();
/** Defines the default permission if the permission nodes couldn't be used. */ /**
* Defines the default permission if the permission nodes couldn't be used.
*/
private DefaultPermission defaultPermission = DefaultPermission.NOT_ALLOWED; private DefaultPermission defaultPermission = DefaultPermission.NOT_ALLOWED;
/** /**
* Constructor. * Constructor.
*/ */
public CommandPermissions() { } public CommandPermissions() {
}
/** /**
* Constructor. * Constructor.
* *
* @param permissionNode The permission node required to execute a command. * @param permissionNode The permission node required to execute a command.
* @param defaultPermission The default permission if the permission nodes couldn't be used. * @param defaultPermission The default permission if the permission nodes couldn't be used.
*/ */
public CommandPermissions(String permissionNode, DefaultPermission defaultPermission) { public CommandPermissions(String permissionNode, DefaultPermission defaultPermission) {
@ -39,7 +44,7 @@ public class CommandPermissions {
/** /**
* Constructor. * Constructor.
* *
* @param permissionNodes The permission nodes required to execute a command. * @param permissionNodes The permission nodes required to execute a command.
* @param defaultPermission The default permission if the permission nodes couldn't be used. * @param defaultPermission The default permission if the permission nodes couldn't be used.
*/ */
public CommandPermissions(List<String> permissionNodes, DefaultPermission defaultPermission) { public CommandPermissions(List<String> permissionNodes, DefaultPermission defaultPermission) {
@ -51,18 +56,18 @@ public class CommandPermissions {
* *
* @param permissionNode The permission node to add. * @param permissionNode The permission node to add.
* *
* @return True on success, false on failure.
* @return True on success, false on failure. */ */
public boolean addPermissionNode(String permissionNode) { public boolean addPermissionNode(String permissionNode) {
// Trim the permission node // Trim the permission node
permissionNode = permissionNode.trim(); permissionNode = permissionNode.trim();
// Make sure the permission node is valid // Make sure the permission node is valid
if(permissionNode.length() == 0) if (permissionNode.length() == 0)
return false; return false;
// Make sure this permission node hasn't been added already // Make sure this permission node hasn't been added already
if(hasPermissionNode(permissionNode)) if (hasPermissionNode(permissionNode))
return true; return true;
// Add the permission node, return the result // Add the permission node, return the result
@ -74,8 +79,8 @@ public class CommandPermissions {
* *
* @param permissionNode The permission node to check for. * @param permissionNode The permission node to check for.
* *
* @return True if this permission node is required, false if not.
* @return True if this permission node is required, false if not. */ */
public boolean hasPermissionNode(String permissionNode) { public boolean hasPermissionNode(String permissionNode) {
return this.permissionNodes.contains(permissionNode); return this.permissionNodes.contains(permissionNode);
} }
@ -83,21 +88,12 @@ public class CommandPermissions {
/** /**
* Get the permission nodes required to execute this command. * Get the permission nodes required to execute this command.
* *
* @return The permission nodes required to execute this command.
* @return The permission nodes required to execute this command. */ */
public List<String> getPermissionNodes() { public List<String> getPermissionNodes() {
return this.permissionNodes; return this.permissionNodes;
} }
/**
* Get the number of permission nodes set.
*
* @return Permission node count. */
public int getPermissionNodeCount() {
return this.permissionNodes.size();
}
/** /**
* Set the permission nodes required to execute this command. * Set the permission nodes required to execute this command.
* *
@ -107,22 +103,32 @@ public class CommandPermissions {
this.permissionNodes = permissionNodes; this.permissionNodes = permissionNodes;
} }
/**
* Get the number of permission nodes set.
*
* @return Permission node count.
*/
public int getPermissionNodeCount() {
return this.permissionNodes.size();
}
/** /**
* Check whether this command requires any permission to be executed. This is based on the getPermission() method. * Check whether this command requires any permission to be executed. This is based on the getPermission() method.
* *
* @param sender CommandSender * @param sender CommandSender
* @return True if this command requires any permission to be executed by a player. */ *
* @return True if this command requires any permission to be executed by a player.
*/
public boolean hasPermission(CommandSender sender) { public boolean hasPermission(CommandSender sender) {
// Make sure any permission node is set // Make sure any permission node is set
if(getPermissionNodeCount() == 0) if (getPermissionNodeCount() == 0)
return true; return true;
// Get the default permission // Get the default permission
final boolean defaultPermission = getDefaultPermissionCommandSender(sender); final boolean defaultPermission = getDefaultPermissionCommandSender(sender);
// Make sure the command sender is a player, if not use the default // Make sure the command sender is a player, if not use the default
if(!(sender instanceof Player)) if (!(sender instanceof Player))
return defaultPermission; return defaultPermission;
// Get the player instance // Get the player instance
@ -130,12 +136,12 @@ public class CommandPermissions {
// Get the permissions manager, and make sure it's instance is valid // Get the permissions manager, and make sure it's instance is valid
PermissionsManager permissionsManager = AuthMe.getInstance().getPermissionsManager(); PermissionsManager permissionsManager = AuthMe.getInstance().getPermissionsManager();
if(permissionsManager == null) if (permissionsManager == null)
return false; return false;
// Check whether the player has permission, return the result // Check whether the player has permission, return the result
for(String node : this.permissionNodes) for (String node : this.permissionNodes)
if(!permissionsManager.hasPermission(player, node, defaultPermission)) if (!permissionsManager.hasPermission(player, node, defaultPermission))
return false; return false;
return true; return true;
} }
@ -143,8 +149,8 @@ public class CommandPermissions {
/** /**
* Get the default permission if the permission nodes couldn't be used. * Get the default permission if the permission nodes couldn't be used.
* *
* @return The default permission.
* @return The default permission. */ */
public DefaultPermission getDefaultPermission() { public DefaultPermission getDefaultPermission() {
return this.defaultPermission; return this.defaultPermission;
} }
@ -163,19 +169,19 @@ public class CommandPermissions {
* *
* @param sender The command sender to get the default permission for. * @param sender The command sender to get the default permission for.
* *
* @return True if the command sender has permission by default, false otherwise.
* @return True if the command sender has permission by default, false otherwise. */ */
public boolean getDefaultPermissionCommandSender(CommandSender sender) { public boolean getDefaultPermissionCommandSender(CommandSender sender) {
switch(getDefaultPermission()) { switch (getDefaultPermission()) {
case ALLOWED: case ALLOWED:
return true; return true;
case OP_ONLY: case OP_ONLY:
return sender.isOp(); return sender.isOp();
case NOT_ALLOWED: case NOT_ALLOWED:
default: default:
return false; return false;
} }
} }

View File

@ -10,7 +10,7 @@ public abstract class ExecutableCommand {
/** /**
* Execute the command. * Execute the command.
* *
* @param sender The command sender. * @param sender The command sender.
* @param commandReference The command reference. * @param commandReference The command reference.
* @param commandArguments The command arguments. * @param commandArguments The command arguments.
* *

View File

@ -6,22 +6,30 @@ import org.bukkit.command.CommandSender;
*/ */
public class FoundCommandResult { public class FoundCommandResult {
/** The command description instance. */ /**
* The command description instance.
*/
private CommandDescription commandDescription; private CommandDescription commandDescription;
/** The command reference. */ /**
private CommandParts commandReference; * The command reference.
/** The command arguments. */ */
private CommandParts commandArguments; private final CommandParts commandReference;
/** The original search query reference. */ /**
private CommandParts queryReference; * The command arguments.
*/
private final CommandParts commandArguments;
/**
* The original search query reference.
*/
private final CommandParts queryReference;
/** /**
* Constructor. * Constructor.
* *
* @param commandDescription The command description. * @param commandDescription The command description.
* @param commandReference The command reference. * @param commandReference The command reference.
* @param commandArguments The command arguments. * @param commandArguments The command arguments.
* @param queryReference The original query reference. * @param queryReference The original query reference.
*/ */
public FoundCommandResult(CommandDescription commandDescription, CommandParts commandReference, CommandParts commandArguments, CommandParts queryReference) { public FoundCommandResult(CommandDescription commandDescription, CommandParts commandReference, CommandParts commandArguments, CommandParts queryReference) {
this.commandDescription = commandDescription; this.commandDescription = commandDescription;
@ -33,11 +41,11 @@ public class FoundCommandResult {
/** /**
* Check whether the command was suitable. * Check whether the command was suitable.
* *
* @return True if the command was suitable, false otherwise.
* @return True if the command was suitable, false otherwise. */ */
public boolean hasProperArguments() { public boolean hasProperArguments() {
// Make sure the command description is set // Make sure the command description is set
if(this.commandDescription == null) if (this.commandDescription == null)
return false; return false;
// Get and return the result // Get and return the result
@ -47,8 +55,8 @@ public class FoundCommandResult {
/** /**
* Get the command description. * Get the command description.
* *
* @return Command description.
* @return Command description. */ */
public CommandDescription getCommandDescription() { public CommandDescription getCommandDescription() {
return this.commandDescription; return this.commandDescription;
} }
@ -57,7 +65,6 @@ public class FoundCommandResult {
* Set the command description. * Set the command description.
* *
* @param commandDescription The command description. * @param commandDescription The command description.
*
*/ */
public void setCommandDescription(CommandDescription commandDescription) { public void setCommandDescription(CommandDescription commandDescription) {
this.commandDescription = commandDescription; this.commandDescription = commandDescription;
@ -66,11 +73,11 @@ public class FoundCommandResult {
/** /**
* Check whether the command is executable. * Check whether the command is executable.
* *
* @return True if the command is executable, false otherwise.
* @return True if the command is executable, false otherwise. */ */
public boolean isExecutable() { public boolean isExecutable() {
// Make sure the command description is valid // Make sure the command description is valid
if(this.commandDescription == null) if (this.commandDescription == null)
return false; return false;
// Check whether the command is executable, return the result // Check whether the command is executable, return the result
@ -82,11 +89,11 @@ public class FoundCommandResult {
* *
* @param sender The command sender that executed the command. * @param sender The command sender that executed the command.
* *
* @return True on success, false on failure.
* @return True on success, false on failure. */ */
public boolean executeCommand(CommandSender sender) { public boolean executeCommand(CommandSender sender) {
// Make sure the command description is valid // Make sure the command description is valid
if(this.commandDescription == null) if (this.commandDescription == null)
return false; return false;
// Execute the command // Execute the command
@ -98,11 +105,11 @@ public class FoundCommandResult {
* *
* @param sender The command sender. * @param sender The command sender.
* *
* @return True if the command sender has permission, false otherwise.
* @return True if the command sender has permission, false otherwise. */ */
public boolean hasPermission(CommandSender sender) { public boolean hasPermission(CommandSender sender) {
// Make sure the command description is valid // Make sure the command description is valid
if(this.commandDescription == null) if (this.commandDescription == null)
return false; return false;
// Get and return the permission // Get and return the permission
@ -112,8 +119,8 @@ public class FoundCommandResult {
/** /**
* Get the command reference. * Get the command reference.
* *
* @return The command reference.
* @return The command reference. */ */
public CommandParts getCommandReference() { public CommandParts getCommandReference() {
return this.commandReference; return this.commandReference;
} }
@ -121,8 +128,8 @@ public class FoundCommandResult {
/** /**
* Get the command arguments. * Get the command arguments.
* *
* @return The command arguments.
* @return The command arguments. */ */
public CommandParts getCommandArguments() { public CommandParts getCommandArguments() {
return this.commandArguments; return this.commandArguments;
} }
@ -130,8 +137,8 @@ public class FoundCommandResult {
/** /**
* Get the original query reference. * Get the original query reference.
* *
* @return Original query reference.
* @return Original query reference. */ */
public CommandParts getQueryReference() { public CommandParts getQueryReference() {
return this.queryReference; return this.queryReference;
} }
@ -139,11 +146,11 @@ public class FoundCommandResult {
/** /**
* Get the difference value between the original query and the result reference. * Get the difference value between the original query and the result reference.
* *
* @return The difference value.
* @return The difference value. */ */
public double getDifference() { public double getDifference() {
// Get the difference through the command found // Get the difference through the command found
if(this.commandDescription != null) if (this.commandDescription != null)
return this.commandDescription.getCommandDifference(this.queryReference); return this.commandDescription.getCommandDifference(this.queryReference);
// Get the difference from the query reference // Get the difference from the query reference

View File

@ -1,10 +1,9 @@
package fr.xephi.authme.command.executable; package fr.xephi.authme.command.executable;
import org.bukkit.command.CommandSender;
import fr.xephi.authme.command.CommandParts; import fr.xephi.authme.command.CommandParts;
import fr.xephi.authme.command.ExecutableCommand; import fr.xephi.authme.command.ExecutableCommand;
import fr.xephi.authme.command.help.HelpProvider; import fr.xephi.authme.command.help.HelpProvider;
import org.bukkit.command.CommandSender;
/** /**
*/ */

View File

@ -1,16 +1,15 @@
package fr.xephi.authme.command.executable.authme; package fr.xephi.authme.command.executable.authme;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import fr.xephi.authme.AuthMe; import fr.xephi.authme.AuthMe;
import fr.xephi.authme.ConsoleLogger; import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.cache.auth.PlayerAuth; import fr.xephi.authme.cache.auth.PlayerAuth;
import fr.xephi.authme.command.CommandParts; import fr.xephi.authme.command.CommandParts;
import fr.xephi.authme.command.ExecutableCommand; import fr.xephi.authme.command.ExecutableCommand;
import fr.xephi.authme.settings.Messages; import fr.xephi.authme.settings.Messages;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import java.util.List;
/** /**
*/ */
@ -26,7 +25,7 @@ public class AccountsCommand extends ExecutableCommand {
// Get the player query // Get the player query
String playerQuery = sender.getName(); String playerQuery = sender.getName();
if(commandArguments.getCount() >= 1) if (commandArguments.getCount() >= 1)
playerQuery = commandArguments.get(0); playerQuery = commandArguments.get(0);
final String playerQueryFinal = playerQuery; final String playerQueryFinal = playerQuery;

View File

@ -1,11 +1,10 @@
package fr.xephi.authme.command.executable.authme; package fr.xephi.authme.command.executable.authme;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import fr.xephi.authme.AuthMe; import fr.xephi.authme.AuthMe;
import fr.xephi.authme.command.CommandParts; import fr.xephi.authme.command.CommandParts;
import fr.xephi.authme.command.ExecutableCommand; import fr.xephi.authme.command.ExecutableCommand;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
/** /**
*/ */
@ -14,7 +13,7 @@ public class AuthMeCommand extends ExecutableCommand {
@Override @Override
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) { public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
// Show some version info // Show some version info
sender.sendMessage(ChatColor.GREEN + "This server is running " + AuthMe.PLUGIN_NAME + " v" + AuthMe.getVersionName() + "! " + ChatColor.RED + "<3"); sender.sendMessage(ChatColor.GREEN + "This server is running " + AuthMe.getPluginName() + " v" + AuthMe.getVersionName() + "! " + ChatColor.RED + "<3");
sender.sendMessage(ChatColor.YELLOW + "Use the command " + ChatColor.GOLD + "/" + commandReference.get(0) + " help" + ChatColor.YELLOW + " to view help."); sender.sendMessage(ChatColor.YELLOW + "Use the command " + ChatColor.GOLD + "/" + commandReference.get(0) + " help" + ChatColor.YELLOW + " to view help.");
sender.sendMessage(ChatColor.YELLOW + "Use the command " + ChatColor.GOLD + "/" + commandReference.get(0) + " about" + ChatColor.YELLOW + " to view about."); sender.sendMessage(ChatColor.YELLOW + "Use the command " + ChatColor.GOLD + "/" + commandReference.get(0) + " about" + ChatColor.YELLOW + " to view about.");
return true; return true;

View File

@ -1,10 +1,5 @@
package fr.xephi.authme.command.executable.authme; package fr.xephi.authme.command.executable.authme;
import java.security.NoSuchAlgorithmException;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import fr.xephi.authme.AuthMe; import fr.xephi.authme.AuthMe;
import fr.xephi.authme.ConsoleLogger; import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.cache.auth.PlayerAuth; import fr.xephi.authme.cache.auth.PlayerAuth;
@ -14,6 +9,10 @@ import fr.xephi.authme.command.ExecutableCommand;
import fr.xephi.authme.security.PasswordSecurity; import fr.xephi.authme.security.PasswordSecurity;
import fr.xephi.authme.settings.Messages; import fr.xephi.authme.settings.Messages;
import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.Settings;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import java.security.NoSuchAlgorithmException;
/** /**
*/ */

View File

@ -1,12 +1,11 @@
package fr.xephi.authme.command.executable.authme; package fr.xephi.authme.command.executable.authme;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import fr.xephi.authme.ConsoleLogger; import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.command.CommandParts; import fr.xephi.authme.command.CommandParts;
import fr.xephi.authme.command.ExecutableCommand; import fr.xephi.authme.command.ExecutableCommand;
import fr.xephi.authme.settings.Spawn; import fr.xephi.authme.settings.Spawn;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
/** /**
*/ */

View File

@ -1,12 +1,11 @@
package fr.xephi.authme.command.executable.authme; package fr.xephi.authme.command.executable.authme;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import fr.xephi.authme.AuthMe; import fr.xephi.authme.AuthMe;
import fr.xephi.authme.command.CommandParts; import fr.xephi.authme.command.CommandParts;
import fr.xephi.authme.command.ExecutableCommand; import fr.xephi.authme.command.ExecutableCommand;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
/** /**
*/ */
@ -19,11 +18,12 @@ public class ForceLoginCommand extends ExecutableCommand {
// Get the player query // Get the player query
String playerName = sender.getName(); String playerName = sender.getName();
if(commandArguments.getCount() >= 1) if (commandArguments.getCount() >= 1)
playerName = commandArguments.get(0); playerName = commandArguments.get(0);
// Command logic // Command logic
try { try {
@SuppressWarnings("deprecation")
Player player = Bukkit.getPlayer(playerName); Player player = Bukkit.getPlayer(playerName);
if (player == null || !player.isOnline()) { if (player == null || !player.isOnline()) {
sender.sendMessage("Player needs to be online!"); sender.sendMessage("Player needs to be online!");

View File

@ -1,12 +1,11 @@
package fr.xephi.authme.command.executable.authme; package fr.xephi.authme.command.executable.authme;
import org.bukkit.command.CommandSender;
import fr.xephi.authme.AuthMe; import fr.xephi.authme.AuthMe;
import fr.xephi.authme.cache.auth.PlayerAuth; import fr.xephi.authme.cache.auth.PlayerAuth;
import fr.xephi.authme.command.CommandParts; import fr.xephi.authme.command.CommandParts;
import fr.xephi.authme.command.ExecutableCommand; import fr.xephi.authme.command.ExecutableCommand;
import fr.xephi.authme.settings.Messages; import fr.xephi.authme.settings.Messages;
import org.bukkit.command.CommandSender;
/** /**
*/ */
@ -19,13 +18,13 @@ public class GetEmailCommand extends ExecutableCommand {
* @param commandReference The command reference. * @param commandReference The command reference.
* @param commandArguments The command arguments. * @param commandArguments The command arguments.
* *
* @return True if the command was executed successfully, false otherwise.
* @return True if the command was executed successfully, false otherwise. */ */
@Override @Override
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) { public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
// Get the player name // Get the player name
String playerName = sender.getName(); String playerName = sender.getName();
if(commandArguments.getCount() >= 1) if (commandArguments.getCount() >= 1)
playerName = commandArguments.get(0); playerName = commandArguments.get(0);
// Get the authenticated user // Get the authenticated user

View File

@ -1,12 +1,11 @@
package fr.xephi.authme.command.executable.authme; package fr.xephi.authme.command.executable.authme;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import fr.xephi.authme.AuthMe; import fr.xephi.authme.AuthMe;
import fr.xephi.authme.command.CommandParts; import fr.xephi.authme.command.CommandParts;
import fr.xephi.authme.command.ExecutableCommand; import fr.xephi.authme.command.ExecutableCommand;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
/** /**
*/ */
@ -19,9 +18,10 @@ public class GetIpCommand extends ExecutableCommand {
// Get the player query // Get the player query
String playerName = sender.getName(); String playerName = sender.getName();
if(commandArguments.getCount() >= 1) if (commandArguments.getCount() >= 1)
playerName = commandArguments.get(0); playerName = commandArguments.get(0);
@SuppressWarnings("deprecation")
Player player = Bukkit.getPlayer(playerName); Player player = Bukkit.getPlayer(playerName);
if (player == null) { if (player == null) {
sender.sendMessage("This player is not actually online"); sender.sendMessage("This player is not actually online");

View File

@ -1,14 +1,13 @@
package fr.xephi.authme.command.executable.authme; package fr.xephi.authme.command.executable.authme;
import java.util.Date;
import org.bukkit.command.CommandSender;
import fr.xephi.authme.AuthMe; import fr.xephi.authme.AuthMe;
import fr.xephi.authme.cache.auth.PlayerAuth; import fr.xephi.authme.cache.auth.PlayerAuth;
import fr.xephi.authme.command.CommandParts; import fr.xephi.authme.command.CommandParts;
import fr.xephi.authme.command.ExecutableCommand; import fr.xephi.authme.command.ExecutableCommand;
import fr.xephi.authme.settings.Messages; import fr.xephi.authme.settings.Messages;
import org.bukkit.command.CommandSender;
import java.util.Date;
/** /**
*/ */
@ -18,7 +17,7 @@ public class LastLoginCommand extends ExecutableCommand {
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) { public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
// Get the player // Get the player
String playerName = sender.getName(); String playerName = sender.getName();
if(commandArguments.getCount() >= 1) if (commandArguments.getCount() >= 1)
playerName = commandArguments.get(0); playerName = commandArguments.get(0);
// Validate the player // Validate the player

View File

@ -1,15 +1,14 @@
package fr.xephi.authme.command.executable.authme; package fr.xephi.authme.command.executable.authme;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
import fr.xephi.authme.AuthMe; import fr.xephi.authme.AuthMe;
import fr.xephi.authme.command.CommandParts; import fr.xephi.authme.command.CommandParts;
import fr.xephi.authme.command.ExecutableCommand; import fr.xephi.authme.command.ExecutableCommand;
import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.Settings;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
import java.util.ArrayList;
import java.util.List;
/** /**
*/ */
@ -22,8 +21,8 @@ public class PurgeBannedPlayersCommand extends ExecutableCommand {
* @param commandReference The command reference. * @param commandReference The command reference.
* @param commandArguments The command arguments. * @param commandArguments The command arguments.
* *
* @return True if the command was executed successfully, false otherwise.
* @return True if the command was executed successfully, false otherwise. */ */
@Override @Override
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) { public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
// AuthMe plugin instance // AuthMe plugin instance

View File

@ -1,15 +1,14 @@
package fr.xephi.authme.command.executable.authme; package fr.xephi.authme.command.executable.authme;
import java.util.Calendar;
import java.util.List;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import fr.xephi.authme.AuthMe; import fr.xephi.authme.AuthMe;
import fr.xephi.authme.command.CommandParts; import fr.xephi.authme.command.CommandParts;
import fr.xephi.authme.command.ExecutableCommand; import fr.xephi.authme.command.ExecutableCommand;
import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.Settings;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import java.util.Calendar;
import java.util.List;
/** /**
*/ */
@ -22,8 +21,8 @@ public class PurgeCommand extends ExecutableCommand {
* @param commandReference The command reference. * @param commandReference The command reference.
* @param commandArguments The command arguments. * @param commandArguments The command arguments.
* *
* @return True if the command was executed successfully, false otherwise.
* @return True if the command was executed successfully, false otherwise. */ */
@Override @Override
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) { public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
// AuthMe plugin instance // AuthMe plugin instance
@ -36,13 +35,13 @@ public class PurgeCommand extends ExecutableCommand {
int days; int days;
try { try {
days = Integer.valueOf(daysStr); days = Integer.valueOf(daysStr);
} catch(Exception ex) { } catch (Exception ex) {
sender.sendMessage(ChatColor.RED + "The value you've entered is invalid!"); sender.sendMessage(ChatColor.RED + "The value you've entered is invalid!");
return true; return true;
} }
// Validate the value // Validate the value
if(days < 30) { if (days < 30) {
sender.sendMessage(ChatColor.RED + "You can only purge data older than 30 days"); sender.sendMessage(ChatColor.RED + "You can only purge data older than 30 days");
return true; return true;
} }
@ -59,13 +58,13 @@ public class PurgeCommand extends ExecutableCommand {
sender.sendMessage(ChatColor.GOLD + "Deleted " + purged.size() + " user accounts"); sender.sendMessage(ChatColor.GOLD + "Deleted " + purged.size() + " user accounts");
// Purge other data // Purge other data
if(Settings.purgeEssentialsFile && plugin.ess != null) if (Settings.purgeEssentialsFile && plugin.ess != null)
plugin.dataManager.purgeEssentials(purged); plugin.dataManager.purgeEssentials(purged);
if(Settings.purgePlayerDat) if (Settings.purgePlayerDat)
plugin.dataManager.purgeDat(purged); plugin.dataManager.purgeDat(purged);
if(Settings.purgeLimitedCreative) if (Settings.purgeLimitedCreative)
plugin.dataManager.purgeLimitedCreative(purged); plugin.dataManager.purgeLimitedCreative(purged);
if(Settings.purgeAntiXray) if (Settings.purgeAntiXray)
plugin.dataManager.purgeAntiXray(purged); plugin.dataManager.purgeAntiXray(purged);
// Show a status message // Show a status message

View File

@ -1,14 +1,13 @@
package fr.xephi.authme.command.executable.authme; package fr.xephi.authme.command.executable.authme;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import fr.xephi.authme.AuthMe; import fr.xephi.authme.AuthMe;
import fr.xephi.authme.ConsoleLogger; import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.cache.auth.PlayerAuth; import fr.xephi.authme.cache.auth.PlayerAuth;
import fr.xephi.authme.command.CommandParts; import fr.xephi.authme.command.CommandParts;
import fr.xephi.authme.command.ExecutableCommand; import fr.xephi.authme.command.ExecutableCommand;
import fr.xephi.authme.settings.Messages; import fr.xephi.authme.settings.Messages;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
/** /**
*/ */
@ -21,8 +20,8 @@ public class PurgeLastPositionCommand extends ExecutableCommand {
* @param commandReference The command reference. * @param commandReference The command reference.
* @param commandArguments The command arguments. * @param commandArguments The command arguments.
* *
* @return True if the command was executed successfully, false otherwise.
* @return True if the command was executed successfully, false otherwise. */ */
@Override @Override
public boolean executeCommand(final CommandSender sender, CommandParts commandReference, CommandParts commandArguments) { public boolean executeCommand(final CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
// AuthMe plugin instance // AuthMe plugin instance
@ -33,7 +32,7 @@ public class PurgeLastPositionCommand extends ExecutableCommand {
// Get the player // Get the player
String playerName = sender.getName(); String playerName = sender.getName();
if(commandArguments.getCount() >= 1) if (commandArguments.getCount() >= 1)
playerName = commandArguments.get(0); playerName = commandArguments.get(0);
String playerNameLowerCase = playerName.toLowerCase(); String playerNameLowerCase = playerName.toLowerCase();

View File

@ -1,10 +1,5 @@
package fr.xephi.authme.command.executable.authme; package fr.xephi.authme.command.executable.authme;
import java.security.NoSuchAlgorithmException;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import fr.xephi.authme.AuthMe; import fr.xephi.authme.AuthMe;
import fr.xephi.authme.ConsoleLogger; import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.cache.auth.PlayerAuth; import fr.xephi.authme.cache.auth.PlayerAuth;
@ -13,6 +8,10 @@ import fr.xephi.authme.command.ExecutableCommand;
import fr.xephi.authme.security.PasswordSecurity; import fr.xephi.authme.security.PasswordSecurity;
import fr.xephi.authme.settings.Messages; import fr.xephi.authme.settings.Messages;
import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.Settings;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import java.security.NoSuchAlgorithmException;
/** /**
*/ */
@ -25,8 +24,8 @@ public class RegisterCommand extends ExecutableCommand {
* @param commandReference The command reference. * @param commandReference The command reference.
* @param commandArguments The command arguments. * @param commandArguments The command arguments.
* *
* @return True if the command was executed successfully, false otherwise.
* @return True if the command was executed successfully, false otherwise. */ */
@Override @Override
public boolean executeCommand(final CommandSender sender, CommandParts commandReference, CommandParts commandArguments) { public boolean executeCommand(final CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
// AuthMe plugin instance // AuthMe plugin instance

View File

@ -1,7 +1,6 @@
package fr.xephi.authme.command.executable.authme; package fr.xephi.authme.command.executable.authme;
//import org.bukkit.ChatColor; //import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import fr.xephi.authme.AuthMe; import fr.xephi.authme.AuthMe;
import fr.xephi.authme.ConsoleLogger; import fr.xephi.authme.ConsoleLogger;
@ -10,6 +9,7 @@ import fr.xephi.authme.command.ExecutableCommand;
import fr.xephi.authme.settings.Messages; import fr.xephi.authme.settings.Messages;
import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.util.Profiler; import fr.xephi.authme.util.Profiler;
import org.bukkit.command.CommandSender;
/** /**
*/ */
@ -22,8 +22,8 @@ public class ReloadCommand extends ExecutableCommand {
* @param commandReference The command reference. * @param commandReference The command reference.
* @param commandArguments The command arguments. * @param commandArguments The command arguments.
* *
* @return True if the command was executed successfully, false otherwise.
* @return True if the command was executed successfully, false otherwise. */ */
@Override @Override
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) { public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
// Profile the reload process // Profile the reload process

View File

@ -1,14 +1,13 @@
package fr.xephi.authme.command.executable.authme; package fr.xephi.authme.command.executable.authme;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import fr.xephi.authme.AuthMe; import fr.xephi.authme.AuthMe;
import fr.xephi.authme.cache.auth.PlayerAuth; import fr.xephi.authme.cache.auth.PlayerAuth;
import fr.xephi.authme.command.CommandParts; import fr.xephi.authme.command.CommandParts;
import fr.xephi.authme.command.ExecutableCommand; import fr.xephi.authme.command.ExecutableCommand;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import java.util.List;
/** /**
*/ */
@ -21,8 +20,8 @@ public class ResetNameCommand extends ExecutableCommand {
* @param commandReference The command reference. * @param commandReference The command reference.
* @param commandArguments The command arguments. * @param commandArguments The command arguments.
* *
* @return True if the command was executed successfully, false otherwise.
* @return True if the command was executed successfully, false otherwise. */ */
@Override @Override
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) { public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
// AuthMe plugin instance // AuthMe plugin instance
@ -33,7 +32,7 @@ public class ResetNameCommand extends ExecutableCommand {
@Override @Override
public void run() { public void run() {
List<PlayerAuth> authentications = plugin.database.getAllAuths(); List<PlayerAuth> authentications = plugin.database.getAllAuths();
for(PlayerAuth auth : authentications) { for (PlayerAuth auth : authentications) {
auth.setRealName("Player"); auth.setRealName("Player");
plugin.database.updateSession(auth); plugin.database.updateSession(auth);
} }

View File

@ -1,7 +1,5 @@
package fr.xephi.authme.command.executable.authme; package fr.xephi.authme.command.executable.authme;
import org.bukkit.command.CommandSender;
import fr.xephi.authme.AuthMe; import fr.xephi.authme.AuthMe;
import fr.xephi.authme.cache.auth.PlayerAuth; import fr.xephi.authme.cache.auth.PlayerAuth;
import fr.xephi.authme.cache.auth.PlayerCache; import fr.xephi.authme.cache.auth.PlayerCache;
@ -9,6 +7,7 @@ import fr.xephi.authme.command.CommandParts;
import fr.xephi.authme.command.ExecutableCommand; import fr.xephi.authme.command.ExecutableCommand;
import fr.xephi.authme.settings.Messages; import fr.xephi.authme.settings.Messages;
import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.Settings;
import org.bukkit.command.CommandSender;
/** /**
*/ */
@ -21,8 +20,8 @@ public class SetEmailCommand extends ExecutableCommand {
* @param commandReference The command reference. * @param commandReference The command reference.
* @param commandArguments The command arguments. * @param commandArguments The command arguments.
* *
* @return True if the command was executed successfully, false otherwise.
* @return True if the command was executed successfully, false otherwise. */ */
@Override @Override
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) { public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
// AuthMe plugin instance // AuthMe plugin instance

View File

@ -1,12 +1,11 @@
package fr.xephi.authme.command.executable.authme; package fr.xephi.authme.command.executable.authme;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import fr.xephi.authme.ConsoleLogger; import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.command.CommandParts; import fr.xephi.authme.command.CommandParts;
import fr.xephi.authme.command.ExecutableCommand; import fr.xephi.authme.command.ExecutableCommand;
import fr.xephi.authme.settings.Spawn; import fr.xephi.authme.settings.Spawn;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
/** /**
*/ */
@ -19,8 +18,8 @@ public class SetFirstSpawnCommand extends ExecutableCommand {
* @param commandReference The command reference. * @param commandReference The command reference.
* @param commandArguments The command arguments. * @param commandArguments The command arguments.
* *
* @return True if the command was executed successfully, false otherwise.
* @return True if the command was executed successfully, false otherwise. */ */
@Override @Override
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) { public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
try { try {

View File

@ -1,12 +1,11 @@
package fr.xephi.authme.command.executable.authme; package fr.xephi.authme.command.executable.authme;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import fr.xephi.authme.ConsoleLogger; import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.command.CommandParts; import fr.xephi.authme.command.CommandParts;
import fr.xephi.authme.command.ExecutableCommand; import fr.xephi.authme.command.ExecutableCommand;
import fr.xephi.authme.settings.Spawn; import fr.xephi.authme.settings.Spawn;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
/** /**
*/ */
@ -19,8 +18,8 @@ public class SetSpawnCommand extends ExecutableCommand {
* @param commandReference The command reference. * @param commandReference The command reference.
* @param commandArguments The command arguments. * @param commandArguments The command arguments.
* *
* @return True if the command was executed successfully, false otherwise.
* @return True if the command was executed successfully, false otherwise. */ */
@Override @Override
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) { public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
// Make sure the command executor is a player // Make sure the command executor is a player

View File

@ -1,12 +1,11 @@
package fr.xephi.authme.command.executable.authme; package fr.xephi.authme.command.executable.authme;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import fr.xephi.authme.ConsoleLogger; import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.command.CommandParts; import fr.xephi.authme.command.CommandParts;
import fr.xephi.authme.command.ExecutableCommand; import fr.xephi.authme.command.ExecutableCommand;
import fr.xephi.authme.settings.Spawn; import fr.xephi.authme.settings.Spawn;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
/** /**
*/ */
@ -19,8 +18,8 @@ public class SpawnCommand extends ExecutableCommand {
* @param commandReference The command reference. * @param commandReference The command reference.
* @param commandArguments The command arguments. * @param commandArguments The command arguments.
* *
* @return True if the command was executed successfully, false otherwise.
* @return True if the command was executed successfully, false otherwise. */ */
@Override @Override
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) { public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
// Make sure the command executor is a player // Make sure the command executor is a player

View File

@ -1,12 +1,11 @@
package fr.xephi.authme.command.executable.authme; package fr.xephi.authme.command.executable.authme;
import org.bukkit.ChatColor; import fr.xephi.authme.AntiBot;
import org.bukkit.command.CommandSender;
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.command.CommandParts; import fr.xephi.authme.command.CommandParts;
import fr.xephi.authme.command.ExecutableCommand; import fr.xephi.authme.command.ExecutableCommand;
import fr.xephi.authme.command.help.HelpProvider; import fr.xephi.authme.command.help.HelpProvider;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
/** /**
*/ */
@ -19,29 +18,30 @@ public class SwitchAntiBotCommand extends ExecutableCommand {
* @param commandReference The command reference. * @param commandReference The command reference.
* @param commandArguments The command arguments. * @param commandArguments The command arguments.
* *
* @return True if the command was executed successfully, false otherwise.
* @return True if the command was executed successfully, false otherwise. */ */
@Override @Override
public boolean executeCommand(final CommandSender sender, CommandParts commandReference, CommandParts commandArguments) { public boolean executeCommand(final CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
// AuthMe plugin instance
final AuthMe plugin = AuthMe.getInstance();
// Get the new state // Get the new state
String newState = plugin.getAntiBotModMode() ? "OFF" : "ON"; String newState = null;
if(commandArguments.getCount() >= 1) if (commandArguments.getCount() == 1) {
newState = commandArguments.get(0); newState = commandArguments.get(0);
} else if(commandArguments.getCount() == 0) {
sender.sendMessage("[AuthMe] AntiBot status: " + AntiBot.getAntiBotStatus().name());
return true;
}
// Enable the mod // Enable the mod
if(newState.equalsIgnoreCase("ON")) { if (newState.equalsIgnoreCase("ON")) {
plugin.switchAntiBotMod(true); AntiBot.overrideAntiBotStatus(true);
sender.sendMessage("[AuthMe] AntiBotMod enabled"); sender.sendMessage("[AuthMe] AntiBot Manual Ovverride: enabled!");
return true; return true;
} }
// Disable the mod // Disable the mod
if(newState.equalsIgnoreCase("OFF")) { if (newState.equalsIgnoreCase("OFF")) {
plugin.switchAntiBotMod(false); AntiBot.overrideAntiBotStatus(false);
sender.sendMessage("[AuthMe] AntiBotMod disabled"); sender.sendMessage("[AuthMe] AntiBotMod Manual Ovverride: disabled!");
return true; return true;
} }

View File

@ -1,24 +1,24 @@
package fr.xephi.authme.command.executable.authme; package fr.xephi.authme.command.executable.authme;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.scheduler.BukkitScheduler;
import org.bukkit.scheduler.BukkitTask;
import fr.xephi.authme.AuthMe; import fr.xephi.authme.AuthMe;
import fr.xephi.authme.ConsoleLogger; import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.cache.auth.PlayerCache; import fr.xephi.authme.cache.auth.PlayerCache;
import fr.xephi.authme.cache.limbo.LimboCache; import fr.xephi.authme.cache.limbo.LimboCache;
import fr.xephi.authme.command.CommandParts; import fr.xephi.authme.command.CommandParts;
import fr.xephi.authme.command.ExecutableCommand; import fr.xephi.authme.command.ExecutableCommand;
import fr.xephi.authme.settings.MessageKey;
import fr.xephi.authme.settings.Messages; import fr.xephi.authme.settings.Messages;
import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.task.MessageTask; import fr.xephi.authme.task.MessageTask;
import fr.xephi.authme.task.TimeoutTask; import fr.xephi.authme.task.TimeoutTask;
import fr.xephi.authme.util.Utils; import fr.xephi.authme.util.Utils;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.scheduler.BukkitScheduler;
import org.bukkit.scheduler.BukkitTask;
/** /**
*/ */
@ -30,8 +30,9 @@ public class UnregisterCommand extends ExecutableCommand {
* @param sender The command sender. * @param sender The command sender.
* @param commandReference The command reference. * @param commandReference The command reference.
* @param commandArguments The command arguments. * @param commandArguments The command arguments.
*
* @return True if the command was executed successfully, false otherwise. */ * @return True if the command was executed successfully, false otherwise.
*/
@Override @Override
public boolean executeCommand(final CommandSender sender, CommandParts commandReference, CommandParts commandArguments) { public boolean executeCommand(final CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
// AuthMe plugin instance // AuthMe plugin instance
@ -46,18 +47,17 @@ public class UnregisterCommand extends ExecutableCommand {
// Make sure the user is valid // Make sure the user is valid
if (!plugin.database.isAuthAvailable(playerNameLowerCase)) { if (!plugin.database.isAuthAvailable(playerNameLowerCase)) {
m.send(sender, "user_unknown"); m.send(sender, MessageKey.UNKNOWN_USER);
return true; return true;
} }
// Remove the player // Remove the player
if (!plugin.database.removeAuth(playerNameLowerCase)) { if (!plugin.database.removeAuth(playerNameLowerCase)) {
m.send(sender, "error"); m.send(sender, MessageKey.ERROR);
return true; return true;
} }
// Unregister the player // Unregister the player
@SuppressWarnings("deprecation")
Player target = Bukkit.getPlayer(playerNameLowerCase); Player target = Bukkit.getPlayer(playerNameLowerCase);
PlayerCache.getInstance().removePlayer(playerNameLowerCase); PlayerCache.getInstance().removePlayer(playerNameLowerCase);
Utils.setGroup(target, Utils.GroupType.UNREGISTERED); Utils.setGroup(target, Utils.GroupType.UNREGISTERED);
@ -71,19 +71,21 @@ public class UnregisterCommand extends ExecutableCommand {
BukkitTask id = scheduler.runTaskLaterAsynchronously(plugin, new TimeoutTask(plugin, playerNameLowerCase, target), delay); BukkitTask id = scheduler.runTaskLaterAsynchronously(plugin, new TimeoutTask(plugin, playerNameLowerCase, target), delay);
LimboCache.getInstance().getLimboPlayer(playerNameLowerCase).setTimeoutTaskId(id); LimboCache.getInstance().getLimboPlayer(playerNameLowerCase).setTimeoutTaskId(id);
} }
LimboCache.getInstance().getLimboPlayer(playerNameLowerCase).setMessageTaskId(scheduler.runTaskAsynchronously(plugin, new MessageTask(plugin, playerNameLowerCase, m.send("reg_msg"), interval))); LimboCache.getInstance().getLimboPlayer(playerNameLowerCase).setMessageTaskId(
scheduler.runTaskAsynchronously(plugin,
new MessageTask(plugin, playerNameLowerCase, m.retrieve(MessageKey.REGISTER_MESSAGE), interval)));
if (Settings.applyBlindEffect) if (Settings.applyBlindEffect)
target.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, Settings.getRegistrationTimeout * 20, 2)); target.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, Settings.getRegistrationTimeout * 20, 2));
if (!Settings.isMovementAllowed && Settings.isRemoveSpeedEnabled) { if (!Settings.isMovementAllowed && Settings.isRemoveSpeedEnabled) {
target.setWalkSpeed(0.0f); target.setWalkSpeed(0.0f);
target.setFlySpeed(0.0f); target.setFlySpeed(0.0f);
} }
m.send(target, "unregistered"); m.send(target, MessageKey.UNREGISTERED_SUCCESS);
} }
// Show a status message // Show a status message
m.send(sender, "unregistered"); m.send(sender, MessageKey.UNREGISTERED_SUCCESS);
ConsoleLogger.info(playerName + " unregistered"); ConsoleLogger.info(playerName + " unregistered");
return true; return true;
} }

View File

@ -1,13 +1,12 @@
package fr.xephi.authme.command.executable.authme; package fr.xephi.authme.command.executable.authme;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import fr.xephi.authme.AuthMe; import fr.xephi.authme.AuthMe;
import fr.xephi.authme.command.CommandParts; import fr.xephi.authme.command.CommandParts;
import fr.xephi.authme.command.ExecutableCommand; import fr.xephi.authme.command.ExecutableCommand;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
/** /**
*/ */
@ -20,13 +19,13 @@ public class VersionCommand extends ExecutableCommand {
* @param commandReference The command reference. * @param commandReference The command reference.
* @param commandArguments The command arguments. * @param commandArguments The command arguments.
* *
* @return True if the command was executed successfully, false otherwise.
* @return True if the command was executed successfully, false otherwise. */ */
@Override @Override
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) { public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
// Show some version info // Show some version info
sender.sendMessage(ChatColor.GOLD + "==========[ " + AuthMe.PLUGIN_NAME.toUpperCase() + " ABOUT ]=========="); sender.sendMessage(ChatColor.GOLD + "==========[ " + AuthMe.getPluginName().toUpperCase() + " ABOUT ]==========");
sender.sendMessage(ChatColor.GOLD + "Version: " + ChatColor.WHITE + AuthMe.PLUGIN_NAME + " v" + AuthMe.getVersionName() + ChatColor.GRAY + " (code: " + AuthMe.getVersionCode() + ")"); sender.sendMessage(ChatColor.GOLD + "Version: " + ChatColor.WHITE + AuthMe.getPluginName() + " v" + AuthMe.getVersionName() + ChatColor.GRAY + " (code: " + AuthMe.getVersionCode() + ")");
sender.sendMessage(ChatColor.GOLD + "Developers:"); sender.sendMessage(ChatColor.GOLD + "Developers:");
printDeveloper(sender, "Xephi", "xephi59", "Lead Developer"); printDeveloper(sender, "Xephi", "xephi59", "Lead Developer");
printDeveloper(sender, "DNx5", "DNx5", "Developer"); printDeveloper(sender, "DNx5", "DNx5", "Developer");
@ -42,10 +41,10 @@ public class VersionCommand extends ExecutableCommand {
/** /**
* Print a developer with proper styling. * Print a developer with proper styling.
* *
* @param sender The command sender. * @param sender The command sender.
* @param name The display name of the developer. * @param name The display name of the developer.
* @param minecraftName The Minecraft username of the developer, if available. * @param minecraftName The Minecraft username of the developer, if available.
* @param function The function of the developer. * @param function The function of the developer.
*/ */
@SuppressWarnings("StringConcatenationInsideStringBufferAppend") @SuppressWarnings("StringConcatenationInsideStringBufferAppend")
private void printDeveloper(CommandSender sender, String name, String minecraftName, String function) { private void printDeveloper(CommandSender sender, String name, String minecraftName, String function) {
@ -55,13 +54,13 @@ public class VersionCommand extends ExecutableCommand {
msg.append(name); msg.append(name);
// Append the Minecraft name, if available // Append the Minecraft name, if available
if(minecraftName.length() != 0) if (minecraftName.length() != 0)
msg.append(ChatColor.GRAY + " // " + ChatColor.WHITE + minecraftName); msg.append(ChatColor.GRAY + " // " + ChatColor.WHITE + minecraftName);
msg.append(ChatColor.GRAY + "" + ChatColor.ITALIC + " (" + function + ")"); msg.append(ChatColor.GRAY + "" + ChatColor.ITALIC + " (" + function + ")");
// Show the online status // Show the online status
if(minecraftName.length() != 0) if (minecraftName.length() != 0)
if(isPlayerOnline(minecraftName)) if (isPlayerOnline(minecraftName))
msg.append(ChatColor.GREEN + "" + ChatColor.ITALIC + " (In-Game)"); msg.append(ChatColor.GREEN + "" + ChatColor.ITALIC + " (In-Game)");
// Print the message // Print the message
@ -73,12 +72,16 @@ public class VersionCommand extends ExecutableCommand {
* *
* @param minecraftName The Minecraft player name. * @param minecraftName The Minecraft player name.
* *
* @return True if the player is online, false otherwise.
* @return True if the player is online, false otherwise. */ */
private boolean isPlayerOnline(String minecraftName) { private boolean isPlayerOnline(String minecraftName) {
for(Player player : Bukkit.getOnlinePlayers()) // Note ljacqu 20151121: Generally you should use Utils#getOnlinePlayers to retrieve the list of online players.
if(player.getName().equalsIgnoreCase(minecraftName)) // If it's only used in a for-each loop such as here, it's fine. For other purposes, go through the Utils class.
for (Player player : Bukkit.getOnlinePlayers()) {
if (player.getName().equalsIgnoreCase(minecraftName)) {
return true; return true;
}
}
return false; return false;
} }
} }

View File

@ -1,45 +1,24 @@
package fr.xephi.authme.command.executable.captcha; package fr.xephi.authme.command.executable.captcha;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import fr.xephi.authme.AuthMe; import fr.xephi.authme.AuthMe;
import fr.xephi.authme.cache.auth.PlayerCache; import fr.xephi.authme.cache.auth.PlayerCache;
import fr.xephi.authme.command.CommandParts; import fr.xephi.authme.command.CommandParts;
import fr.xephi.authme.command.ExecutableCommand; import fr.xephi.authme.command.ExecutableCommand;
import fr.xephi.authme.security.RandomString; import fr.xephi.authme.security.RandomString;
import fr.xephi.authme.settings.MessageKey;
import fr.xephi.authme.settings.Messages; import fr.xephi.authme.settings.Messages;
import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.Settings;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
/** /**
*/ */
public class CaptchaCommand extends ExecutableCommand { public class CaptchaCommand extends ExecutableCommand {
/**
* Execute the command.
*
* @param sender The command sender.
* @param commandReference The command reference.
* @param commandArguments The command arguments.
*
* @return True if the command was executed successfully, false otherwise. */
@Override @Override
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) { public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
// AuthMe plugin instance
final AuthMe plugin = AuthMe.getInstance();
// Messages instance
final Messages m = Messages.getInstance();
// Random string instance, for captcha generation (I think) -- timvisee
RandomString randStr = new RandomString(Settings.captchaLength);
// Get the parameter values
String captcha = commandArguments.get(0);
// Make sure the current command executor is a player // Make sure the current command executor is a player
if(!(sender instanceof Player)) { if (!(sender instanceof Player)) {
return true; return true;
} }
@ -47,39 +26,47 @@ public class CaptchaCommand extends ExecutableCommand {
final Player player = (Player) sender; final Player player = (Player) sender;
final String playerNameLowerCase = player.getName().toLowerCase(); final String playerNameLowerCase = player.getName().toLowerCase();
// Get the parameter values
String captcha = commandArguments.get(0);
// Messages instance
final Messages m = Messages.getInstance();
// Command logic // Command logic
if (PlayerCache.getInstance().isAuthenticated(playerNameLowerCase)) { if (PlayerCache.getInstance().isAuthenticated(playerNameLowerCase)) {
m.send(player, "logged_in"); m.send(player, MessageKey.ALREADY_LOGGED_IN_ERROR);
return true; return true;
} }
if (!Settings.useCaptcha) { if (!Settings.useCaptcha) {
m.send(player, "usage_log"); m.send(player, MessageKey.USAGE_LOGIN);
return true; return true;
} }
// AuthMe plugin instance
final AuthMe plugin = AuthMe.getInstance();
if (!plugin.cap.containsKey(playerNameLowerCase)) { if (!plugin.cap.containsKey(playerNameLowerCase)) {
m.send(player, "usage_log"); m.send(player, MessageKey.USAGE_LOGIN);
return true; return true;
} }
if (Settings.useCaptcha && !captcha.equals(plugin.cap.get(playerNameLowerCase))) { if (Settings.useCaptcha && !captcha.equals(plugin.cap.get(playerNameLowerCase))) {
plugin.cap.remove(playerNameLowerCase); plugin.cap.remove(playerNameLowerCase);
plugin.cap.put(playerNameLowerCase, randStr.nextString()); String randStr = new RandomString(Settings.captchaLength).nextString();
for (String s : m.send("wrong_captcha")) { plugin.cap.put(playerNameLowerCase, randStr);
for (String s : m.retrieve(MessageKey.CAPTCHA_WRONG_ERROR)) {
player.sendMessage(s.replace("THE_CAPTCHA", plugin.cap.get(playerNameLowerCase))); player.sendMessage(s.replace("THE_CAPTCHA", plugin.cap.get(playerNameLowerCase)));
} }
return true; return true;
} }
try { plugin.captcha.remove(playerNameLowerCase);
plugin.captcha.remove(playerNameLowerCase); plugin.cap.remove(playerNameLowerCase);
plugin.cap.remove(playerNameLowerCase);
} catch (NullPointerException ignored) { }
// Show a status message // Show a status message
m.send(player, "valid_captcha"); m.send(player, MessageKey.CAPTCHA_SUCCESS);
m.send(player, "login_msg"); m.send(player, MessageKey.LOGIN_MESSAGE);
return true; return true;
} }
} }

View File

@ -1,8 +1,5 @@
package fr.xephi.authme.command.executable.changepassword; package fr.xephi.authme.command.executable.changepassword;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import fr.xephi.authme.AuthMe; import fr.xephi.authme.AuthMe;
import fr.xephi.authme.cache.auth.PlayerCache; import fr.xephi.authme.cache.auth.PlayerCache;
import fr.xephi.authme.command.CommandParts; import fr.xephi.authme.command.CommandParts;
@ -10,6 +7,8 @@ import fr.xephi.authme.command.ExecutableCommand;
import fr.xephi.authme.settings.Messages; import fr.xephi.authme.settings.Messages;
import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.task.ChangePasswordTask; import fr.xephi.authme.task.ChangePasswordTask;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
/** /**
*/ */

View File

@ -1,21 +1,12 @@
package fr.xephi.authme.command.executable.converter; package fr.xephi.authme.command.executable.converter;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import fr.xephi.authme.AuthMe; import fr.xephi.authme.AuthMe;
import fr.xephi.authme.command.CommandParts; import fr.xephi.authme.command.CommandParts;
import fr.xephi.authme.command.ExecutableCommand; import fr.xephi.authme.command.ExecutableCommand;
import fr.xephi.authme.converter.Converter; import fr.xephi.authme.converter.*;
import fr.xephi.authme.converter.CrazyLoginConverter;
import fr.xephi.authme.converter.FlatToSql;
import fr.xephi.authme.converter.FlatToSqlite;
import fr.xephi.authme.converter.RakamakConverter;
import fr.xephi.authme.converter.RoyalAuthConverter;
import fr.xephi.authme.converter.SqlToFlat;
import fr.xephi.authme.converter.vAuthConverter;
import fr.xephi.authme.converter.xAuthConverter;
import fr.xephi.authme.settings.Messages; import fr.xephi.authme.settings.Messages;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
/** /**
*/ */
@ -24,12 +15,12 @@ public class ConverterCommand extends ExecutableCommand {
/** /**
* Execute the command. * Execute the command.
* *
* @param sender The command sender. * @param sender The command sender.
* @param commandReference The command reference. * @param commandReference The command reference.
* @param commandArguments The command arguments. * @param commandArguments The command arguments.
* *
* @return True if the command was executed successfully, false otherwise.
* @return True if the command was executed successfully, false otherwise. */ */
@Override @Override
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) { public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
// AuthMe plugin instance // AuthMe plugin instance
@ -51,32 +42,32 @@ public class ConverterCommand extends ExecutableCommand {
// Get the proper converter instance // Get the proper converter instance
Converter converter = null; Converter converter = null;
switch (jobType) { switch (jobType) {
case ftsql: case ftsql:
converter = new FlatToSql(); converter = new FlatToSql();
break; break;
case ftsqlite: case ftsqlite:
converter = new FlatToSqlite(sender); converter = new FlatToSqlite(sender);
break; break;
case xauth: case xauth:
converter = new xAuthConverter(plugin, sender); converter = new xAuthConverter(plugin, sender);
break; break;
case crazylogin: case crazylogin:
converter = new CrazyLoginConverter(plugin, sender); converter = new CrazyLoginConverter(plugin, sender);
break; break;
case rakamak: case rakamak:
converter = new RakamakConverter(plugin, sender); converter = new RakamakConverter(plugin, sender);
break; break;
case royalauth: case royalauth:
converter = new RoyalAuthConverter(plugin); converter = new RoyalAuthConverter(plugin);
break; break;
case vauth: case vauth:
converter = new vAuthConverter(plugin, sender); converter = new vAuthConverter(plugin, sender);
break; break;
case sqltoflat: case sqltoflat:
converter = new SqlToFlat(plugin, sender); converter = new SqlToFlat(plugin, sender);
break; break;
default: default:
break; break;
} }
// Run the convert job // Run the convert job
@ -99,29 +90,24 @@ public class ConverterCommand extends ExecutableCommand {
vauth("vauth"), vauth("vauth"),
sqltoflat("sqltoflat"); sqltoflat("sqltoflat");
String name; final String name;
/** /**
* Constructor for ConvertType. * Constructor for ConvertType.
*
* @param name String * @param name String
*/ */
ConvertType(String name) { ConvertType(String name) {
this.name = name; this.name = name;
} }
/**
* Method getName.
* @return String */
String getName() {
return this.name;
}
/** /**
* Method fromName. * Method fromName.
*
* @param name String * @param name String
*
* @return ConvertType */ * @return ConvertType
*/
public static ConvertType fromName(String name) { public static ConvertType fromName(String name) {
for (ConvertType type : ConvertType.values()) { for (ConvertType type : ConvertType.values()) {
if (type.getName().equalsIgnoreCase(name)) if (type.getName().equalsIgnoreCase(name))
@ -129,5 +115,14 @@ public class ConverterCommand extends ExecutableCommand {
} }
return null; return null;
} }
/**
* Method getName.
*
* @return String
*/
String getName() {
return this.name;
}
} }
} }

View File

@ -1,12 +1,10 @@
package fr.xephi.authme.command.executable.email; package fr.xephi.authme.command.executable.email;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import fr.xephi.authme.AuthMe; import fr.xephi.authme.AuthMe;
import fr.xephi.authme.command.CommandParts; import fr.xephi.authme.command.CommandParts;
import fr.xephi.authme.command.ExecutableCommand; import fr.xephi.authme.command.ExecutableCommand;
import fr.xephi.authme.settings.Messages; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
/** /**
*/ */

View File

@ -1,11 +1,10 @@
package fr.xephi.authme.command.executable.email; package fr.xephi.authme.command.executable.email;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import fr.xephi.authme.AuthMe; import fr.xephi.authme.AuthMe;
import fr.xephi.authme.command.CommandParts; import fr.xephi.authme.command.CommandParts;
import fr.xephi.authme.command.ExecutableCommand; import fr.xephi.authme.command.ExecutableCommand;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
/** /**
*/ */

View File

@ -1,10 +1,5 @@
package fr.xephi.authme.command.executable.email; package fr.xephi.authme.command.executable.email;
import java.security.NoSuchAlgorithmException;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import fr.xephi.authme.AuthMe; import fr.xephi.authme.AuthMe;
import fr.xephi.authme.ConsoleLogger; import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.cache.auth.PlayerAuth; import fr.xephi.authme.cache.auth.PlayerAuth;
@ -15,6 +10,10 @@ import fr.xephi.authme.security.PasswordSecurity;
import fr.xephi.authme.security.RandomString; import fr.xephi.authme.security.RandomString;
import fr.xephi.authme.settings.Messages; import fr.xephi.authme.settings.Messages;
import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.Settings;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.security.NoSuchAlgorithmException;
/** /**
*/ */

View File

@ -1,11 +1,10 @@
package fr.xephi.authme.command.executable.login; package fr.xephi.authme.command.executable.login;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import fr.xephi.authme.AuthMe; import fr.xephi.authme.AuthMe;
import fr.xephi.authme.command.CommandParts; import fr.xephi.authme.command.CommandParts;
import fr.xephi.authme.command.ExecutableCommand; import fr.xephi.authme.command.ExecutableCommand;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
/** /**
*/ */
@ -21,10 +20,10 @@ public class LoginCommand extends ExecutableCommand {
// Get the necessary objects // Get the necessary objects
final AuthMe plugin = AuthMe.getInstance(); final AuthMe plugin = AuthMe.getInstance();
final Player player = (Player) sender; final Player player = (Player) sender;
final String playerPass = commandArguments.get(0); final String password = commandArguments.get(0);
// Log the player in // Log the player in
plugin.getManagement().performLogin(player, playerPass, false); plugin.getManagement().performLogin(player, password, false);
return true; return true;
} }
} }

View File

@ -1,11 +1,10 @@
package fr.xephi.authme.command.executable.logout; package fr.xephi.authme.command.executable.logout;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import fr.xephi.authme.AuthMe; import fr.xephi.authme.AuthMe;
import fr.xephi.authme.command.CommandParts; import fr.xephi.authme.command.CommandParts;
import fr.xephi.authme.command.ExecutableCommand; import fr.xephi.authme.command.ExecutableCommand;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
/** /**
*/ */

View File

@ -1,15 +1,14 @@
package fr.xephi.authme.command.executable.register; package fr.xephi.authme.command.executable.register;
import fr.xephi.authme.process.Management;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import fr.xephi.authme.AuthMe; import fr.xephi.authme.AuthMe;
import fr.xephi.authme.command.CommandParts; import fr.xephi.authme.command.CommandParts;
import fr.xephi.authme.command.ExecutableCommand; import fr.xephi.authme.command.ExecutableCommand;
import fr.xephi.authme.process.Management;
import fr.xephi.authme.security.RandomString; import fr.xephi.authme.security.RandomString;
import fr.xephi.authme.settings.Messages; import fr.xephi.authme.settings.Messages;
import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.Settings;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
/** /**
*/ */

View File

@ -1,13 +1,12 @@
package fr.xephi.authme.command.executable.unregister; package fr.xephi.authme.command.executable.unregister;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import fr.xephi.authme.AuthMe; import fr.xephi.authme.AuthMe;
import fr.xephi.authme.cache.auth.PlayerCache; import fr.xephi.authme.cache.auth.PlayerCache;
import fr.xephi.authme.command.CommandParts; import fr.xephi.authme.command.CommandParts;
import fr.xephi.authme.command.ExecutableCommand; import fr.xephi.authme.command.ExecutableCommand;
import fr.xephi.authme.settings.Messages; import fr.xephi.authme.settings.Messages;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
/** /**
*/ */
@ -16,12 +15,12 @@ public class UnregisterCommand extends ExecutableCommand {
/** /**
* Execute the command. * Execute the command.
* *
* @param sender The command sender. * @param sender The command sender.
* @param commandReference The command reference. * @param commandReference The command reference.
* @param commandArguments The command arguments. * @param commandArguments The command arguments.
* *
* @return True if the command was executed successfully, false otherwise.
* @return True if the command was executed successfully, false otherwise. */ */
@Override @Override
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) { public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
// AuthMe plugin instance // AuthMe plugin instance
@ -31,7 +30,7 @@ public class UnregisterCommand extends ExecutableCommand {
final Messages m = Messages.getInstance(); final Messages m = Messages.getInstance();
// Make sure the current command executor is a player // Make sure the current command executor is a player
if(!(sender instanceof Player)) { if (!(sender instanceof Player)) {
return true; return true;
} }

View File

@ -1,20 +1,19 @@
package fr.xephi.authme.command.help; package fr.xephi.authme.command.help;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import fr.xephi.authme.AuthMe; import fr.xephi.authme.AuthMe;
import fr.xephi.authme.command.CommandArgumentDescription; import fr.xephi.authme.command.CommandArgumentDescription;
import fr.xephi.authme.command.CommandDescription; import fr.xephi.authme.command.CommandDescription;
import fr.xephi.authme.command.CommandParts; import fr.xephi.authme.command.CommandParts;
import fr.xephi.authme.command.CommandPermissions; import fr.xephi.authme.command.CommandPermissions;
import fr.xephi.authme.util.StringUtils; import fr.xephi.authme.util.StringUtils;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
/** /**
*/ */
@ -23,8 +22,8 @@ public class HelpPrinter {
/** /**
* Print the command help information. * Print the command help information.
* *
* @param sender The command sender to print the help to. * @param sender The command sender to print the help to.
* @param command The command to print. * @param command The command to print.
* @param commandReference The command reference used. * @param commandReference The command reference used.
*/ */
public static void printCommand(CommandSender sender, CommandDescription command, CommandParts commandReference) { public static void printCommand(CommandSender sender, CommandDescription command, CommandParts commandReference) {
@ -35,16 +34,16 @@ public class HelpPrinter {
/** /**
* Print the command help description information. This will print both the short, as the detailed description if available. * Print the command help description information. This will print both the short, as the detailed description if available.
* *
* @param sender The command sender to print the help to. * @param sender The command sender to print the help to.
* @param command The command to print the description help for. * @param command The command to print the description help for.
*/ */
public static void printCommandDescription(CommandSender sender, CommandDescription command) { public static void printCommandDescription(CommandSender sender, CommandDescription command) {
// Print the regular description, if available // Print the regular description, if available
if(command.hasDescription()) if (command.hasDescription())
sender.sendMessage(ChatColor.GOLD + "Short Description: " + ChatColor.WHITE + command.getDescription()); sender.sendMessage(ChatColor.GOLD + "Short Description: " + ChatColor.WHITE + command.getDescription());
// Print the detailed description, if available // Print the detailed description, if available
if(command.hasDetailedDescription()) { if (command.hasDetailedDescription()) {
sender.sendMessage(ChatColor.GOLD + "Detailed Description:"); sender.sendMessage(ChatColor.GOLD + "Detailed Description:");
sender.sendMessage(ChatColor.WHITE + " " + command.getDetailedDescription()); sender.sendMessage(ChatColor.WHITE + " " + command.getDetailedDescription());
} }
@ -53,26 +52,26 @@ public class HelpPrinter {
/** /**
* Print the command help arguments information if available. * Print the command help arguments information if available.
* *
* @param sender The command sender to print the help to. * @param sender The command sender to print the help to.
* @param command The command to print the argument help for. * @param command The command to print the argument help for.
*/ */
@SuppressWarnings("StringConcatenationInsideStringBufferAppend") @SuppressWarnings("StringConcatenationInsideStringBufferAppend")
public static void printArguments(CommandSender sender, CommandDescription command) { public static void printArguments(CommandSender sender, CommandDescription command) {
// Make sure there are any commands to print // Make sure there are any commands to print
if(!command.hasArguments() && command.getMaximumArguments() >= 0) if (!command.hasArguments() && command.getMaximumArguments() >= 0)
return; return;
// Print the header // Print the header
sender.sendMessage(ChatColor.GOLD + "Arguments:"); sender.sendMessage(ChatColor.GOLD + "Arguments:");
// Print each argument // Print each argument
for(CommandArgumentDescription arg : command.getArguments()) { for (CommandArgumentDescription arg : command.getArguments()) {
// Create a string builder to build the syntax in // Create a string builder to build the syntax in
StringBuilder argString = new StringBuilder(); StringBuilder argString = new StringBuilder();
argString.append(" " + ChatColor.YELLOW + ChatColor.ITALIC + arg.getLabel() + " : " + ChatColor.WHITE + arg.getDescription()); argString.append(" " + ChatColor.YELLOW + ChatColor.ITALIC + arg.getLabel() + " : " + ChatColor.WHITE + arg.getDescription());
// Suffix a note if the command is optional // Suffix a note if the command is optional
if(arg.isOptional()) if (arg.isOptional())
argString.append(ChatColor.GRAY + "" + ChatColor.ITALIC + " (Optional)"); argString.append(ChatColor.GRAY + "" + ChatColor.ITALIC + " (Optional)");
// Print the syntax // Print the syntax
@ -80,57 +79,57 @@ public class HelpPrinter {
} }
// Show the unlimited arguments argument // Show the unlimited arguments argument
if(command.getMaximumArguments() < 0) if (command.getMaximumArguments() < 0)
sender.sendMessage(" " + ChatColor.YELLOW + ChatColor.ITALIC + "... : " + ChatColor.WHITE + "Any additional arguments." + ChatColor.GRAY + ChatColor.ITALIC + " (Optional)"); sender.sendMessage(" " + ChatColor.YELLOW + ChatColor.ITALIC + "... : " + ChatColor.WHITE + "Any additional arguments." + ChatColor.GRAY + ChatColor.ITALIC + " (Optional)");
} }
/** /**
* Print the command help permissions information if available. * Print the command help permissions information if available.
* *
* @param sender The command sender to print the help to. * @param sender The command sender to print the help to.
* @param command The command to print the permissions help for. * @param command The command to print the permissions help for.
*/ */
public static void printPermissions(CommandSender sender, CommandDescription command) { public static void printPermissions(CommandSender sender, CommandDescription command) {
// Get the permissions and make sure it isn't null // Get the permissions and make sure it isn't null
CommandPermissions permissions = command.getCommandPermissions(); CommandPermissions permissions = command.getCommandPermissions();
if(permissions == null) if (permissions == null)
return; return;
// Make sure any permission node is set // Make sure any permission node is set
if(permissions.getPermissionNodeCount() <= 0) if (permissions.getPermissionNodeCount() <= 0)
return; return;
// Print the header // Print the header
sender.sendMessage(ChatColor.GOLD + "Permissions:"); sender.sendMessage(ChatColor.GOLD + "Permissions:");
// Print each node // Print each node
for(String node : permissions.getPermissionNodes()) { for (String node : permissions.getPermissionNodes()) {
boolean nodePermission = true; boolean nodePermission = true;
if(sender instanceof Player) if (sender instanceof Player)
nodePermission = AuthMe.getInstance().getPermissionsManager().hasPermission((Player) sender, node); nodePermission = AuthMe.getInstance().getPermissionsManager().hasPermission((Player) sender, node);
final String nodePermsString = ChatColor.GRAY + (nodePermission ? ChatColor.ITALIC + " (Permission!)" : ChatColor.ITALIC + " (No Permission!)"); final String nodePermsString = ChatColor.GRAY + (nodePermission ? ChatColor.ITALIC + " (Permission!)" : ChatColor.ITALIC + " (No Permission!)");
sender.sendMessage(" " + ChatColor.YELLOW + ChatColor.ITALIC + node + nodePermsString); sender.sendMessage(" " + ChatColor.YELLOW + ChatColor.ITALIC + node + nodePermsString);
} }
// Print the default permission // Print the default permission
switch(permissions.getDefaultPermission()) { switch (permissions.getDefaultPermission()) {
case ALLOWED: case ALLOWED:
sender.sendMessage(ChatColor.GOLD + " Default: " + ChatColor.GRAY + ChatColor.ITALIC + "Permission!"); sender.sendMessage(ChatColor.GOLD + " Default: " + ChatColor.GRAY + ChatColor.ITALIC + "Permission!");
break; break;
case OP_ONLY: case OP_ONLY:
final String defaultPermsString = ChatColor.GRAY + (permissions.getDefaultPermissionCommandSender(sender) ? ChatColor.ITALIC + " (Permission!)" : ChatColor.ITALIC + " (No Permission!)"); final String defaultPermsString = ChatColor.GRAY + (permissions.getDefaultPermissionCommandSender(sender) ? ChatColor.ITALIC + " (Permission!)" : ChatColor.ITALIC + " (No Permission!)");
sender.sendMessage(ChatColor.GOLD + " Default: " + ChatColor.YELLOW + ChatColor.ITALIC + "OP's Only!" + defaultPermsString); sender.sendMessage(ChatColor.GOLD + " Default: " + ChatColor.YELLOW + ChatColor.ITALIC + "OP's Only!" + defaultPermsString);
break; break;
case NOT_ALLOWED: case NOT_ALLOWED:
default: default:
sender.sendMessage(ChatColor.GOLD + " Default: " + ChatColor.GRAY + ChatColor.ITALIC + "No Permission!"); sender.sendMessage(ChatColor.GOLD + " Default: " + ChatColor.GRAY + ChatColor.ITALIC + "No Permission!");
break; break;
} }
// Print the permission result // Print the permission result
if(permissions.hasPermission(sender)) if (permissions.hasPermission(sender))
sender.sendMessage(ChatColor.GOLD + " Result: " + ChatColor.GREEN + ChatColor.ITALIC + "Permission!"); sender.sendMessage(ChatColor.GOLD + " Result: " + ChatColor.GREEN + ChatColor.ITALIC + "Permission!");
else else
sender.sendMessage(ChatColor.GOLD + " Result: " + ChatColor.DARK_RED + ChatColor.ITALIC + "No Permission!"); sender.sendMessage(ChatColor.GOLD + " Result: " + ChatColor.DARK_RED + ChatColor.ITALIC + "No Permission!");
@ -139,13 +138,13 @@ public class HelpPrinter {
/** /**
* Print the command help alternatives information if available. * Print the command help alternatives information if available.
* *
* @param sender The command sender to print the help to. * @param sender The command sender to print the help to.
* @param command The command used. * @param command The command used.
* @param commandReference The original command reference used for this command. * @param commandReference The original command reference used for this command.
*/ */
public static void printAlternatives(CommandSender sender, CommandDescription command, CommandParts commandReference) { public static void printAlternatives(CommandSender sender, CommandDescription command, CommandParts commandReference) {
// Make sure there are any alternatives // Make sure there are any alternatives
if(command.getLabels().size() <= 1) if (command.getLabels().size() <= 1)
return; return;
// Print the header // Print the header
@ -156,9 +155,9 @@ public class HelpPrinter {
// Create a list of alternatives // Create a list of alternatives
List<String> alternatives = new ArrayList<>(); List<String> alternatives = new ArrayList<>();
for(String entry : command.getLabels()) { for (String entry : command.getLabels()) {
// Exclude the proper argument // Exclude the proper argument
if(entry.equalsIgnoreCase(usedLabel)) if (entry.equalsIgnoreCase(usedLabel))
continue; continue;
alternatives.add(entry); alternatives.add(entry);
} }
@ -172,27 +171,27 @@ public class HelpPrinter {
}); });
// Print each alternative with proper syntax // Print each alternative with proper syntax
for(String alternative : alternatives) for (String alternative : alternatives)
sender.sendMessage(" " + HelpSyntaxHelper.getCommandSyntax(command, commandReference, alternative, true)); sender.sendMessage(" " + HelpSyntaxHelper.getCommandSyntax(command, commandReference, alternative, true));
} }
/** /**
* Print the command help child's information if available. * Print the command help child's information if available.
* *
* @param sender The command sender to print the help to. * @param sender The command sender to print the help to.
* @param command The command to print the help for. * @param command The command to print the help for.
* @param commandReference The original command reference used for this command. * @param commandReference The original command reference used for this command.
*/ */
public static void printChildren(CommandSender sender, CommandDescription command, CommandParts commandReference) { public static void printChildren(CommandSender sender, CommandDescription command, CommandParts commandReference) {
// Make sure there are child's // Make sure there are child's
if(command.getChildren().size() <= 0) if (command.getChildren().size() <= 0)
return; return;
// Print the header // Print the header
sender.sendMessage(ChatColor.GOLD + "Commands:"); sender.sendMessage(ChatColor.GOLD + "Commands:");
// Loop through each child // Loop through each child
for(CommandDescription child : command.getChildren()) for (CommandDescription child : command.getChildren())
sender.sendMessage(" " + HelpSyntaxHelper.getCommandSyntax(child, commandReference, null, false) + ChatColor.GRAY + ChatColor.ITALIC + " : " + child.getDescription()); sender.sendMessage(" " + HelpSyntaxHelper.getCommandSyntax(child, commandReference, null, false) + ChatColor.GRAY + ChatColor.ITALIC + " : " + child.getDescription());
} }
} }

View File

@ -1,12 +1,11 @@
package fr.xephi.authme.command.help; package fr.xephi.authme.command.help;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import fr.xephi.authme.AuthMe; import fr.xephi.authme.AuthMe;
import fr.xephi.authme.command.CommandDescription; import fr.xephi.authme.command.CommandDescription;
import fr.xephi.authme.command.CommandParts; import fr.xephi.authme.command.CommandParts;
import fr.xephi.authme.command.FoundCommandResult; import fr.xephi.authme.command.FoundCommandResult;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
/** /**
*/ */
@ -15,7 +14,7 @@ public class HelpProvider {
/** /**
* Show help for a specific command. * Show help for a specific command.
* *
* @param sender The command sender the help needs to be shown to. * @param sender The command sender the help needs to be shown to.
* @param reference The command reference to the help command. * @param reference The command reference to the help command.
* @param helpQuery The query to show help for. * @param helpQuery The query to show help for.
*/ */
@ -26,31 +25,31 @@ public class HelpProvider {
/** /**
* Show help for a specific command. * Show help for a specific command.
* *
* @param sender The command sender the help needs to be shown to. * @param sender The command sender the help needs to be shown to.
* @param reference The command reference to the help command. * @param reference The command reference to the help command.
* @param helpQuery The query to show help for. * @param helpQuery The query to show help for.
* @param showCommand True to show the command. * @param showCommand True to show the command.
* @param showDescription True to show the command description, both the short and detailed description. * @param showDescription True to show the command description, both the short and detailed description.
* @param showArguments True to show the command argument help. * @param showArguments True to show the command argument help.
* @param showPermissions True to show the command permission help. * @param showPermissions True to show the command permission help.
* @param showAlternatives True to show the command alternatives. * @param showAlternatives True to show the command alternatives.
* @param showCommands True to show the child commands. * @param showCommands True to show the child commands.
*/ */
public static void showHelp(CommandSender sender, CommandParts reference, CommandParts helpQuery, boolean showCommand, boolean showDescription, boolean showArguments, boolean showPermissions, boolean showAlternatives, boolean showCommands) { public static void showHelp(CommandSender sender, CommandParts reference, CommandParts helpQuery, boolean showCommand, boolean showDescription, boolean showArguments, boolean showPermissions, boolean showAlternatives, boolean showCommands) {
// Find the command for this help query, one with and one without a prefixed base command // Find the command for this help query, one with and one without a prefixed base command
FoundCommandResult result = AuthMe.getInstance().getCommandHandler().getCommandManager().findCommand(new CommandParts(helpQuery.getList())); FoundCommandResult result = AuthMe.getInstance().getCommandHandler().getCommandManager().findCommand(new CommandParts(helpQuery.getList()));
CommandParts commandReferenceOther = new CommandParts(reference.get(0), helpQuery.getList()); CommandParts commandReferenceOther = new CommandParts(reference.get(0), helpQuery.getList());
FoundCommandResult resultOther = AuthMe.getInstance().getCommandHandler().getCommandManager().findCommand(commandReferenceOther); FoundCommandResult resultOther = AuthMe.getInstance().getCommandHandler().getCommandManager().findCommand(commandReferenceOther);
if(resultOther != null) { if (resultOther != null) {
if(result == null) if (result == null)
result = resultOther; result = resultOther;
else if(result.getDifference() > resultOther.getDifference()) else if (result.getDifference() > resultOther.getDifference())
result = resultOther; result = resultOther;
} }
// Make sure a result was found // Make sure a result was found
if(result == null) { if (result == null) {
// Show a warning message // Show a warning message
sender.sendMessage(ChatColor.DARK_RED + "" + ChatColor.ITALIC + helpQuery); sender.sendMessage(ChatColor.DARK_RED + "" + ChatColor.ITALIC + helpQuery);
sender.sendMessage(ChatColor.DARK_RED + "Couldn't show any help information for this help query."); sender.sendMessage(ChatColor.DARK_RED + "Couldn't show any help information for this help query.");
@ -59,7 +58,7 @@ public class HelpProvider {
// Get the command description, and make sure it's valid // Get the command description, and make sure it's valid
CommandDescription command = result.getCommandDescription(); CommandDescription command = result.getCommandDescription();
if(command == null) { if (command == null) {
// Show a warning message // Show a warning message
sender.sendMessage(ChatColor.DARK_RED + "Failed to retrieve any help information!"); sender.sendMessage(ChatColor.DARK_RED + "Failed to retrieve any help information!");
return; return;
@ -73,7 +72,7 @@ public class HelpProvider {
// Make sure the difference between the command reference and the actual command isn't too big // Make sure the difference between the command reference and the actual command isn't too big
final double commandDifference = result.getDifference(); final double commandDifference = result.getDifference();
if(commandDifference > 0.20) { if (commandDifference > 0.20) {
// Show the unknown command warning // Show the unknown command warning
sender.sendMessage(ChatColor.DARK_RED + "No help found for '" + helpQuery + "'!"); sender.sendMessage(ChatColor.DARK_RED + "No help found for '" + helpQuery + "'!");
@ -81,8 +80,8 @@ public class HelpProvider {
CommandParts suggestedCommandParts = new CommandParts(result.getCommandDescription().getCommandReference(commandReference).getRange(1)); CommandParts suggestedCommandParts = new CommandParts(result.getCommandDescription().getCommandReference(commandReference).getRange(1));
// Show a command suggestion if available and the difference isn't too big // Show a command suggestion if available and the difference isn't too big
if(commandDifference < 0.75) if (commandDifference < 0.75)
if(result.getCommandDescription() != null) if (result.getCommandDescription() != null)
sender.sendMessage(ChatColor.YELLOW + "Did you mean " + ChatColor.GOLD + "/" + baseCommand + " help " + suggestedCommandParts + ChatColor.YELLOW + "?"); sender.sendMessage(ChatColor.YELLOW + "Did you mean " + ChatColor.GOLD + "/" + baseCommand + " help " + suggestedCommandParts + ChatColor.YELLOW + "?");
// Show the help command // Show the help command
@ -91,7 +90,7 @@ public class HelpProvider {
} }
// Show a message when the command handler is assuming a command // Show a message when the command handler is assuming a command
if(commandDifference > 0) { if (commandDifference > 0) {
// Get the suggested command // Get the suggested command
CommandParts suggestedCommandParts = new CommandParts(result.getCommandDescription().getCommandReference(commandReference).getRange(1)); CommandParts suggestedCommandParts = new CommandParts(result.getCommandDescription().getCommandReference(commandReference).getRange(1));
@ -100,20 +99,20 @@ public class HelpProvider {
} }
// Print the help header // Print the help header
sender.sendMessage(ChatColor.GOLD + "==========[ " + AuthMe.PLUGIN_NAME.toUpperCase() + " HELP ]=========="); sender.sendMessage(ChatColor.GOLD + "==========[ " + AuthMe.getPluginName().toUpperCase() + " HELP ]==========");
// Print the command help information // Print the command help information
if(showCommand) if (showCommand)
HelpPrinter.printCommand(sender, command, commandReference); HelpPrinter.printCommand(sender, command, commandReference);
if(showDescription) if (showDescription)
HelpPrinter.printCommandDescription(sender, command); HelpPrinter.printCommandDescription(sender, command);
if(showArguments) if (showArguments)
HelpPrinter.printArguments(sender, command); HelpPrinter.printArguments(sender, command);
if(showPermissions) if (showPermissions)
HelpPrinter.printPermissions(sender, command); HelpPrinter.printPermissions(sender, command);
if(showAlternatives) if (showAlternatives)
HelpPrinter.printAlternatives(sender, command, commandReference); HelpPrinter.printAlternatives(sender, command, commandReference);
if(showCommands) if (showCommands)
HelpPrinter.printChildren(sender, command, commandReference); HelpPrinter.printChildren(sender, command, commandReference);
} }
} }

View File

@ -1,11 +1,10 @@
package fr.xephi.authme.command.help; package fr.xephi.authme.command.help;
import fr.xephi.authme.util.StringUtils;
import org.bukkit.ChatColor;
import fr.xephi.authme.command.CommandArgumentDescription; import fr.xephi.authme.command.CommandArgumentDescription;
import fr.xephi.authme.command.CommandDescription; import fr.xephi.authme.command.CommandDescription;
import fr.xephi.authme.command.CommandParts; import fr.xephi.authme.command.CommandParts;
import fr.xephi.authme.util.StringUtils;
import org.bukkit.ChatColor;
/** /**
* Helper class for formatting a command's structure (name and arguments) * Helper class for formatting a command's structure (name and arguments)
@ -21,9 +20,9 @@ public final class HelpSyntaxHelper {
* Get the formatted syntax for a command. * Get the formatted syntax for a command.
* *
* @param commandDescription The command to build the syntax for. * @param commandDescription The command to build the syntax for.
* @param commandReference The reference of the command. * @param commandReference The reference of the command.
* @param alternativeLabel The alternative label to use for this command syntax. * @param alternativeLabel The alternative label to use for this command syntax.
* @param highlight True to highlight the important parts of this command. * @param highlight True to highlight the important parts of this command.
* *
* @return The command with proper syntax. * @return The command with proper syntax.
*/ */
@ -37,7 +36,7 @@ public final class HelpSyntaxHelper {
// Get the help command reference, and the command label // Get the help command reference, and the command label
CommandParts helpCommandReference = commandDescription.getCommandReference(commandReference); CommandParts helpCommandReference = commandDescription.getCommandReference(commandReference);
final String parentCommand = new CommandParts( final String parentCommand = new CommandParts(
helpCommandReference.getRange(0, helpCommandReference.getCount() - 1)).toString(); helpCommandReference.getRange(0, helpCommandReference.getCount() - 1)).toString();
// Check whether the alternative label should be used // Check whether the alternative label should be used
String commandLabel; String commandLabel;

View File

@ -1,17 +1,16 @@
package fr.xephi.authme.converter; package fr.xephi.authme.converter;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import org.bukkit.command.CommandSender;
import fr.xephi.authme.AuthMe; import fr.xephi.authme.AuthMe;
import fr.xephi.authme.ConsoleLogger; import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.cache.auth.PlayerAuth; import fr.xephi.authme.cache.auth.PlayerAuth;
import fr.xephi.authme.datasource.DataSource; import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.Settings;
import org.bukkit.command.CommandSender;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
/** /**
* @author Xephi59 * @author Xephi59
@ -19,14 +18,15 @@ import fr.xephi.authme.settings.Settings;
*/ */
public class CrazyLoginConverter implements Converter { public class CrazyLoginConverter implements Converter {
public AuthMe instance; public final AuthMe instance;
public DataSource database; public final DataSource database;
public CommandSender sender; public final CommandSender sender;
/** /**
* Constructor for CrazyLoginConverter. * Constructor for CrazyLoginConverter.
*
* @param instance AuthMe * @param instance AuthMe
* @param sender CommandSender * @param sender CommandSender
*/ */
public CrazyLoginConverter(AuthMe instance, CommandSender sender) { public CrazyLoginConverter(AuthMe instance, CommandSender sender) {
this.instance = instance; this.instance = instance;
@ -36,14 +36,16 @@ public class CrazyLoginConverter implements Converter {
/** /**
* Method getInstance. * Method getInstance.
*
* @return CrazyLoginConverter */ * @return CrazyLoginConverter
*/
public CrazyLoginConverter getInstance() { public CrazyLoginConverter getInstance() {
return this; return this;
} }
/** /**
* Method run. * Method run.
*
* @see java.lang.Runnable#run() * @see java.lang.Runnable#run()
*/ */
@Override @Override

View File

@ -1,16 +1,11 @@
package fr.xephi.authme.converter; package fr.xephi.authme.converter;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import fr.xephi.authme.AuthMe; import fr.xephi.authme.AuthMe;
import fr.xephi.authme.ConsoleLogger; import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.Settings;
import java.io.*;
/** /**
* @author Xephi59 * @author Xephi59
* @version $Revision: 1.0 $ * @version $Revision: 1.0 $
@ -47,6 +42,7 @@ public class FlatToSql implements Converter {
/** /**
* Method run. * Method run.
*
* @see java.lang.Runnable#run() * @see java.lang.Runnable#run()
*/ */
@Override @Override

View File

@ -1,26 +1,20 @@
package fr.xephi.authme.converter; package fr.xephi.authme.converter;
import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.settings.Settings;
import org.bukkit.command.CommandSender;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.FileReader; import java.io.FileReader;
import java.io.IOException; import java.io.IOException;
import java.sql.Connection; import java.sql.*;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import org.bukkit.command.CommandSender;
import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.settings.Settings;
/** /**
*/ */
public class FlatToSqlite implements Converter { public class FlatToSqlite implements Converter {
public CommandSender sender; public final CommandSender sender;
private String tableName; private String tableName;
private String columnName; private String columnName;
private String columnPassword; private String columnPassword;
@ -34,8 +28,10 @@ public class FlatToSqlite implements Converter {
private String database; private String database;
private String columnID; private String columnID;
private Connection con; private Connection con;
/** /**
* Constructor for FlatToSqlite. * Constructor for FlatToSqlite.
*
* @param sender CommandSender * @param sender CommandSender
*/ */
public FlatToSqlite(CommandSender sender) { public FlatToSqlite(CommandSender sender) {
@ -44,6 +40,7 @@ public class FlatToSqlite implements Converter {
/** /**
* Method close. * Method close.
*
* @param o AutoCloseable * @param o AutoCloseable
*/ */
private static void close(AutoCloseable o) { private static void close(AutoCloseable o) {
@ -58,6 +55,7 @@ public class FlatToSqlite implements Converter {
/** /**
* Method run. * Method run.
*
* @see java.lang.Runnable#run() * @see java.lang.Runnable#run()
*/ */
@Override @Override
@ -121,9 +119,9 @@ public class FlatToSqlite implements Converter {
/** /**
* Method connect. * Method connect.
*
* @throws ClassNotFoundException * @throws SQLException
* @throws ClassNotFoundException * @throws SQLException */ */
private synchronized void connect() throws ClassNotFoundException, SQLException { private synchronized void connect() throws ClassNotFoundException, SQLException {
Class.forName("org.sqlite.JDBC"); Class.forName("org.sqlite.JDBC");
con = DriverManager.getConnection("jdbc:sqlite:plugins/AuthMe/" + database + ".db"); con = DriverManager.getConnection("jdbc:sqlite:plugins/AuthMe/" + database + ".db");
@ -131,8 +129,9 @@ public class FlatToSqlite implements Converter {
/** /**
* Method setup. * Method setup.
*
* @throws SQLException */ * @throws SQLException
*/
private synchronized void setup() throws SQLException { private synchronized void setup() throws SQLException {
Statement st = null; Statement st = null;
ResultSet rs = null; ResultSet rs = null;
@ -178,9 +177,11 @@ public class FlatToSqlite implements Converter {
/** /**
* Method saveAuth. * Method saveAuth.
*
* @param s String * @param s String
*
* @return boolean */ * @return boolean
*/
private synchronized boolean saveAuth(String s) { private synchronized boolean saveAuth(String s) {
PreparedStatement pst = null; PreparedStatement pst = null;
try { try {

View File

@ -11,10 +11,12 @@ import fr.xephi.authme.settings.Settings;
*/ */
public class ForceFlatToSqlite implements Converter { public class ForceFlatToSqlite implements Converter {
private DataSource data; private final DataSource data;
/** /**
* Constructor for ForceFlatToSqlite. * Constructor for ForceFlatToSqlite.
* @param data DataSource *
* @param data DataSource
* @param plugin AuthMe * @param plugin AuthMe
*/ */
public ForceFlatToSqlite(DataSource data, AuthMe plugin) { public ForceFlatToSqlite(DataSource data, AuthMe plugin) {
@ -23,6 +25,7 @@ public class ForceFlatToSqlite implements Converter {
/** /**
* Method run. * Method run.
*
* @see java.lang.Runnable#run() * @see java.lang.Runnable#run()
*/ */
@Override @Override

View File

@ -1,5 +1,14 @@
package fr.xephi.authme.converter; package fr.xephi.authme.converter;
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.cache.auth.PlayerAuth;
import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.security.HashAlgorithm;
import fr.xephi.authme.security.PasswordSecurity;
import fr.xephi.authme.settings.Settings;
import org.bukkit.command.CommandSender;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.FileReader; import java.io.FileReader;
@ -8,30 +17,21 @@ import java.security.NoSuchAlgorithmException;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map.Entry; import java.util.Map.Entry;
import org.bukkit.command.CommandSender;
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.cache.auth.PlayerAuth;
import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.security.HashAlgorithm;
import fr.xephi.authme.security.PasswordSecurity;
import fr.xephi.authme.settings.Settings;
/** /**
* @author Xephi59 * @author Xephi59
* @version $Revision: 1.0 $ * @version $Revision: 1.0 $
*/ */
public class RakamakConverter implements Converter { public class RakamakConverter implements Converter {
public AuthMe instance; public final AuthMe instance;
public DataSource database; public final DataSource database;
public CommandSender sender; public final CommandSender sender;
/** /**
* Constructor for RakamakConverter. * Constructor for RakamakConverter.
*
* @param instance AuthMe * @param instance AuthMe
* @param sender CommandSender * @param sender CommandSender
*/ */
public RakamakConverter(AuthMe instance, CommandSender sender) { public RakamakConverter(AuthMe instance, CommandSender sender) {
this.instance = instance; this.instance = instance;
@ -41,14 +41,16 @@ public class RakamakConverter implements Converter {
/** /**
* Method getInstance. * Method getInstance.
*
* @return RakamakConverter */ * @return RakamakConverter
*/
public RakamakConverter getInstance() { public RakamakConverter getInstance() {
return this; return this;
} }
/** /**
* Method run. * Method run.
*
* @see java.lang.Runnable#run() * @see java.lang.Runnable#run()
*/ */
@Override @Override

View File

@ -1,23 +1,23 @@
package fr.xephi.authme.converter; package fr.xephi.authme.converter;
import java.io.File;
import org.bukkit.OfflinePlayer;
import fr.xephi.authme.AuthMe; import fr.xephi.authme.AuthMe;
import fr.xephi.authme.ConsoleLogger; import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.cache.auth.PlayerAuth; import fr.xephi.authme.cache.auth.PlayerAuth;
import fr.xephi.authme.datasource.DataSource; import fr.xephi.authme.datasource.DataSource;
import org.bukkit.OfflinePlayer;
import java.io.File;
/** /**
*/ */
public class RoyalAuthConverter implements Converter { public class RoyalAuthConverter implements Converter {
public AuthMe plugin; public final AuthMe plugin;
private DataSource data; private final DataSource data;
/** /**
* Constructor for RoyalAuthConverter. * Constructor for RoyalAuthConverter.
*
* @param plugin AuthMe * @param plugin AuthMe
*/ */
public RoyalAuthConverter(AuthMe plugin) { public RoyalAuthConverter(AuthMe plugin) {
@ -27,6 +27,7 @@ public class RoyalAuthConverter implements Converter {
/** /**
* Method run. * Method run.
*
* @see java.lang.Runnable#run() * @see java.lang.Runnable#run()
*/ */
@Override @Override

View File

@ -1,15 +1,16 @@
package fr.xephi.authme.converter; package fr.xephi.authme.converter;
import java.io.File;
import fr.xephi.authme.settings.CustomConfiguration; import fr.xephi.authme.settings.CustomConfiguration;
import java.io.File;
/** /**
*/ */
public class RoyalAuthYamlReader extends CustomConfiguration { public class RoyalAuthYamlReader extends CustomConfiguration {
/** /**
* Constructor for RoyalAuthYamlReader. * Constructor for RoyalAuthYamlReader.
*
* @param file File * @param file File
*/ */
public RoyalAuthYamlReader(File file) { public RoyalAuthYamlReader(File file) {
@ -20,16 +21,18 @@ public class RoyalAuthYamlReader extends CustomConfiguration {
/** /**
* Method getLastLogin. * Method getLastLogin.
*
* @return long */ * @return long
*/
public long getLastLogin() { public long getLastLogin() {
return getLong("timestamps.quit"); return getLong("timestamps.quit");
} }
/** /**
* Method getHash. * Method getHash.
*
* @return String */ * @return String
*/
public String getHash() { public String getHash() {
return getString("login.password"); return getString("login.password");
} }

View File

@ -1,26 +1,26 @@
package fr.xephi.authme.converter; package fr.xephi.authme.converter;
import java.util.List;
import org.bukkit.command.CommandSender;
import fr.xephi.authme.AuthMe; import fr.xephi.authme.AuthMe;
import fr.xephi.authme.ConsoleLogger; import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.cache.auth.PlayerAuth; import fr.xephi.authme.cache.auth.PlayerAuth;
import fr.xephi.authme.datasource.DataSource; import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.datasource.FlatFile; import fr.xephi.authme.datasource.FlatFile;
import fr.xephi.authme.settings.Messages; import fr.xephi.authme.settings.Messages;
import org.bukkit.command.CommandSender;
import java.util.List;
/** /**
*/ */
public class SqlToFlat implements Converter { public class SqlToFlat implements Converter {
public AuthMe plugin; public final AuthMe plugin;
public DataSource database; public final DataSource database;
public CommandSender sender; public final CommandSender sender;
/** /**
* Constructor for SqlToFlat. * Constructor for SqlToFlat.
*
* @param plugin AuthMe * @param plugin AuthMe
* @param sender CommandSender * @param sender CommandSender
*/ */
@ -32,6 +32,7 @@ public class SqlToFlat implements Converter {
/** /**
* Method run. * Method run.
*
* @see java.lang.Runnable#run() * @see java.lang.Runnable#run()
*/ */
@Override @Override

View File

@ -1,21 +1,21 @@
package fr.xephi.authme.converter; package fr.xephi.authme.converter;
import org.bukkit.command.CommandSender;
import fr.xephi.authme.AuthMe; import fr.xephi.authme.AuthMe;
import fr.xephi.authme.ConsoleLogger; import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.datasource.DataSource; import fr.xephi.authme.datasource.DataSource;
import org.bukkit.command.CommandSender;
/** /**
*/ */
public class vAuthConverter implements Converter { public class vAuthConverter implements Converter {
public AuthMe plugin; public final AuthMe plugin;
public DataSource database; public final DataSource database;
public CommandSender sender; public final CommandSender sender;
/** /**
* Constructor for vAuthConverter. * Constructor for vAuthConverter.
*
* @param plugin AuthMe * @param plugin AuthMe
* @param sender CommandSender * @param sender CommandSender
*/ */
@ -27,6 +27,7 @@ public class vAuthConverter implements Converter {
/** /**
* Method run. * Method run.
*
* @see java.lang.Runnable#run() * @see java.lang.Runnable#run()
*/ */
@Override @Override

View File

@ -1,29 +1,29 @@
package fr.xephi.authme.converter; package fr.xephi.authme.converter;
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.cache.auth.PlayerAuth;
import fr.xephi.authme.datasource.DataSource;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.Scanner; import java.util.Scanner;
import java.util.UUID; import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.cache.auth.PlayerAuth;
import fr.xephi.authme.datasource.DataSource;
/** /**
*/ */
public class vAuthFileReader { public class vAuthFileReader {
public AuthMe plugin; public final AuthMe plugin;
public DataSource database; public final DataSource database;
public CommandSender sender; public final CommandSender sender;
/** /**
* Constructor for vAuthFileReader. * Constructor for vAuthFileReader.
*
* @param plugin AuthMe * @param plugin AuthMe
* @param sender CommandSender * @param sender CommandSender
*/ */
@ -35,9 +35,10 @@ public class vAuthFileReader {
/** /**
* Method convert. * Method convert.
*
* @throws IOException */ * @throws IOException
public void convert() throws IOException { */
public void convert() {
final File file = new File(plugin.getDataFolder().getParent() + "" + File.separator + "vAuth" + File.separator + "passwords.yml"); final File file = new File(plugin.getDataFolder().getParent() + "" + File.separator + "vAuth" + File.separator + "passwords.yml");
Scanner scanner; Scanner scanner;
try { try {
@ -48,15 +49,15 @@ public class vAuthFileReader {
String password = line.split(": ")[1]; String password = line.split(": ")[1];
PlayerAuth auth; PlayerAuth auth;
if (isUUIDinstance(password)) { if (isUUIDinstance(password)) {
String pname; String playerName;
try { try {
pname = Bukkit.getOfflinePlayer(UUID.fromString(name)).getName(); playerName = Bukkit.getOfflinePlayer(UUID.fromString(name)).getName();
} catch (Exception | NoSuchMethodError e) { } catch (Exception | NoSuchMethodError e) {
pname = getName(UUID.fromString(name)); playerName = getName(UUID.fromString(name));
} }
if (pname == null) if (playerName == null)
continue; continue;
auth = new PlayerAuth(pname.toLowerCase(), password, "127.0.0.1", System.currentTimeMillis(), "your@email.com", pname); auth = new PlayerAuth(playerName.toLowerCase(), password, "127.0.0.1", System.currentTimeMillis(), "your@email.com", playerName);
} else { } else {
auth = new PlayerAuth(name.toLowerCase(), password, "127.0.0.1", System.currentTimeMillis(), "your@email.com", name); auth = new PlayerAuth(name.toLowerCase(), password, "127.0.0.1", System.currentTimeMillis(), "your@email.com", name);
} }
@ -70,9 +71,11 @@ public class vAuthFileReader {
/** /**
* Method isUUIDinstance. * Method isUUIDinstance.
*
* @param s String * @param s String
*
* @return boolean */ * @return boolean
*/
private boolean isUUIDinstance(String s) { private boolean isUUIDinstance(String s) {
if (String.valueOf(s.charAt(8)).equalsIgnoreCase("-")) if (String.valueOf(s.charAt(8)).equalsIgnoreCase("-"))
return true; return true;
@ -81,9 +84,11 @@ public class vAuthFileReader {
/** /**
* Method getName. * Method getName.
*
* @param uuid UUID * @param uuid UUID
*
* @return String */ * @return String
*/
private String getName(UUID uuid) { private String getName(UUID uuid) {
try { try {
for (OfflinePlayer op : Bukkit.getOfflinePlayers()) { for (OfflinePlayer op : Bukkit.getOfflinePlayers()) {

View File

@ -1,18 +1,18 @@
package fr.xephi.authme.converter; package fr.xephi.authme.converter;
import org.bukkit.command.CommandSender;
import fr.xephi.authme.AuthMe; import fr.xephi.authme.AuthMe;
import org.bukkit.command.CommandSender;
/** /**
*/ */
public class xAuthConverter implements Converter { public class xAuthConverter implements Converter {
public AuthMe plugin; public final AuthMe plugin;
public CommandSender sender; public final CommandSender sender;
/** /**
* Constructor for xAuthConverter. * Constructor for xAuthConverter.
*
* @param plugin AuthMe * @param plugin AuthMe
* @param sender CommandSender * @param sender CommandSender
*/ */
@ -23,6 +23,7 @@ public class xAuthConverter implements Converter {
/** /**
* Method run. * Method run.
*
* @see java.lang.Runnable#run() * @see java.lang.Runnable#run()
*/ */
@Override @Override

View File

@ -1,5 +1,13 @@
package fr.xephi.authme.converter; package fr.xephi.authme.converter;
import de.luricos.bukkit.xAuth.database.DatabaseTables;
import de.luricos.bukkit.xAuth.utils.xAuthLog;
import de.luricos.bukkit.xAuth.xAuth;
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.cache.auth.PlayerAuth;
import fr.xephi.authme.datasource.DataSource;
import org.bukkit.command.CommandSender;
import java.io.File; import java.io.File;
import java.sql.Connection; import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
@ -8,27 +16,19 @@ import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.bukkit.command.CommandSender;
import de.luricos.bukkit.xAuth.xAuth;
import de.luricos.bukkit.xAuth.database.DatabaseTables;
import de.luricos.bukkit.xAuth.utils.xAuthLog;
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.cache.auth.PlayerAuth;
import fr.xephi.authme.datasource.DataSource;
/** /**
*/ */
public class xAuthToFlat { public class xAuthToFlat {
public AuthMe instance; public final AuthMe instance;
public DataSource database; public final DataSource database;
public CommandSender sender; public final CommandSender sender;
/** /**
* Constructor for xAuthToFlat. * Constructor for xAuthToFlat.
*
* @param instance AuthMe * @param instance AuthMe
* @param sender CommandSender * @param sender CommandSender
*/ */
public xAuthToFlat(AuthMe instance, CommandSender sender) { public xAuthToFlat(AuthMe instance, CommandSender sender) {
this.instance = instance; this.instance = instance;
@ -38,8 +38,9 @@ public class xAuthToFlat {
/** /**
* Method convert. * Method convert.
*
* @return boolean */ * @return boolean
*/
public boolean convert() { public boolean convert() {
if (instance.getServer().getPluginManager().getPlugin("xAuth") == null) { if (instance.getServer().getPluginManager().getPlugin("xAuth") == null) {
sender.sendMessage("[AuthMe] xAuth plugin not found"); sender.sendMessage("[AuthMe] xAuth plugin not found");
@ -63,7 +64,7 @@ public class xAuthToFlat {
database.saveAuth(auth); database.saveAuth(auth);
} }
} }
sender.sendMessage("[AuthMe] Successfull convert from xAuth database"); sender.sendMessage("[AuthMe] Successfully convert from xAuth database");
} catch (Exception e) { } catch (Exception e) {
sender.sendMessage("[AuthMe] An error has been thrown while import xAuth database, the import hadn't fail but can be not complete "); sender.sendMessage("[AuthMe] An error has been thrown while import xAuth database, the import hadn't fail but can be not complete ");
} }
@ -72,9 +73,11 @@ public class xAuthToFlat {
/** /**
* Method getIdPlayer. * Method getIdPlayer.
*
* @param id int * @param id int
*
* @return String */ * @return String
*/
public String getIdPlayer(int id) { public String getIdPlayer(int id) {
String realPass = ""; String realPass = "";
Connection conn = xAuth.getPlugin().getDatabaseController().getConnection(); Connection conn = xAuth.getPlugin().getDatabaseController().getConnection();
@ -99,8 +102,9 @@ public class xAuthToFlat {
/** /**
* Method getXAuthPlayers. * Method getXAuthPlayers.
*
* @return List<Integer> */ * @return List<Integer>
*/
public List<Integer> getXAuthPlayers() { public List<Integer> getXAuthPlayers() {
List<Integer> xP = new ArrayList<>(); List<Integer> xP = new ArrayList<>();
Connection conn = xAuth.getPlugin().getDatabaseController().getConnection(); Connection conn = xAuth.getPlugin().getDatabaseController().getConnection();
@ -124,9 +128,11 @@ public class xAuthToFlat {
/** /**
* Method getPassword. * Method getPassword.
*
* @param accountId int * @param accountId int
*
* @return String */ * @return String
*/
public String getPassword(int accountId) { public String getPassword(int accountId) {
String realPass = ""; String realPass = "";
Connection conn = xAuth.getPlugin().getDatabaseController().getConnection(); Connection conn = xAuth.getPlugin().getDatabaseController().getConnection();

File diff suppressed because it is too large Load Diff

View File

@ -1,188 +1,223 @@
package fr.xephi.authme.datasource; package fr.xephi.authme.datasource;
import java.util.List; import fr.xephi.authme.cache.auth.PlayerAuth;
import fr.xephi.authme.cache.auth.PlayerAuth; import java.util.List;
/** /**
*/ */
public interface DataSource { public interface DataSource {
/** /**
*/ * Method isAuthAvailable.
enum DataSourceType { *
MYSQL, * @param user String
FILE, *
SQLITE * @return boolean
} */
boolean isAuthAvailable(String user);
/**
* Method isAuthAvailable. /**
* @param user String * Method getAuth.
*
* @return boolean */ * @param user String
boolean isAuthAvailable(String user); *
* @return PlayerAuth
/** */
* Method getAuth. PlayerAuth getAuth(String user);
* @param user String
/**
* @return PlayerAuth */ * Method saveAuth.
PlayerAuth getAuth(String user); *
* @param auth PlayerAuth
/** *
* Method saveAuth. * @return boolean
* @param auth PlayerAuth */
boolean saveAuth(PlayerAuth auth);
* @return boolean */
boolean saveAuth(PlayerAuth auth); /**
* Method updateSession.
/** *
* Method updateSession. * @param auth PlayerAuth
* @param auth PlayerAuth *
* @return boolean
* @return boolean */ */
boolean updateSession(PlayerAuth auth); boolean updateSession(PlayerAuth auth);
/** /**
* Method updatePassword. * Method updatePassword.
* @param auth PlayerAuth *
* @param auth PlayerAuth
* @return boolean */ *
boolean updatePassword(PlayerAuth auth); * @return boolean
*/
/** boolean updatePassword(PlayerAuth auth);
* Method purgeDatabase.
* @param until long /**
* Method purgeDatabase.
* @return int */ *
int purgeDatabase(long until); * @param until long
*
/** * @return int
* Method autoPurgeDatabase. */
* @param until long int purgeDatabase(long until);
* @return List<String> */ /**
List<String> autoPurgeDatabase(long until); * Method autoPurgeDatabase.
*
/** * @param until long
* Method removeAuth. *
* @param user String * @return List<String>
*/
* @return boolean */ List<String> autoPurgeDatabase(long until);
boolean removeAuth(String user);
/**
/** * Method removeAuth.
* Method updateQuitLoc. *
* @param auth PlayerAuth * @param user String
*
* @return boolean */ * @return boolean
boolean updateQuitLoc(PlayerAuth auth); */
boolean removeAuth(String user);
/**
* Method getIps. /**
* @param ip String * Method updateQuitLoc.
*
* @return int */ * @param auth PlayerAuth
int getIps(String ip); *
* @return boolean
/** */
* Method getAllAuthsByName. boolean updateQuitLoc(PlayerAuth auth);
* @param auth PlayerAuth
/**
* @return List<String> */ * Method getIps.
List<String> getAllAuthsByName(PlayerAuth auth); *
* @param ip String
/** *
* Method getAllAuthsByIp. * @return int
* @param ip String */
int getIps(String ip);
* @return List<String> * @throws Exception */ /**
List<String> getAllAuthsByIp(String ip) throws Exception; * Method getAllAuthsByName.
*
/** * @param auth PlayerAuth
* Method getAllAuthsByEmail. *
* @param email String * @return List<String>
*/
List<String> getAllAuthsByName(PlayerAuth auth);
* @return List<String> * @throws Exception */
List<String> getAllAuthsByEmail(String email) throws Exception; /**
* Method getAllAuthsByIp.
/** *
* Method updateEmail. * @param ip String
* @param auth PlayerAuth *
* @return List<String> * @throws Exception
* @return boolean */ */
boolean updateEmail(PlayerAuth auth); List<String> getAllAuthsByIp(String ip) throws Exception;
/** /**
* Method updateSalt. * Method getAllAuthsByEmail.
* @param auth PlayerAuth *
* @param email String
* @return boolean */ *
boolean updateSalt(PlayerAuth auth); * @return List<String> * @throws Exception
*/
void close(); List<String> getAllAuthsByEmail(String email) throws Exception;
void reload(); /**
* Method updateEmail.
/** *
* Method purgeBanned. * @param auth PlayerAuth
* @param banned List<String> *
*/ * @return boolean
void purgeBanned(List<String> banned); */
boolean updateEmail(PlayerAuth auth);
/**
* Method getType. /**
* Method updateSalt.
* @return DataSourceType */ *
DataSourceType getType(); * @param auth PlayerAuth
*
/** * @return boolean
* Method isLogged. */
* @param user String boolean updateSalt(PlayerAuth auth);
* @return boolean */ void close();
boolean isLogged(String user);
void reload();
/**
* Method setLogged. /**
* @param user String * Method purgeBanned.
*/ *
void setLogged(String user); * @param banned List<String>
*/
/** void purgeBanned(List<String> banned);
* Method setUnlogged.
* @param user String /**
*/ * Method getType.
void setUnlogged(String user); *
* @return DataSourceType
void purgeLogged(); */
DataSourceType getType();
/**
* Method getAccountsRegistered. /**
* Method isLogged.
* @return int */ *
int getAccountsRegistered(); * @param user String
*
/** * @return boolean
* Method updateName. */
* @param oldone String boolean isLogged(String user);
* @param newone String
*/ /**
void updateName(String oldone, String newone); * Method setLogged.
*
/** * @param user String
* Method getAllAuths. */
void setLogged(String user);
* @return List<PlayerAuth> */
List<PlayerAuth> getAllAuths(); /**
* Method setUnlogged.
/** *
* Method getLoggedPlayers. * @param user String
*/
* @return List<PlayerAuth> */ void setUnlogged(String user);
List<PlayerAuth> getLoggedPlayers();
void purgeLogged();
}
/**
* Method getAccountsRegistered.
*
* @return int
*/
int getAccountsRegistered();
/**
* Method updateName.
*
* @param oldOne String
* @param newOne String
*/
void updateName(String oldOne, String newOne);
/**
* Method getAllAuths.
*
* @return List<PlayerAuth>
*/
List<PlayerAuth> getAllAuths();
/**
* Method getLoggedPlayers.
*
* @return List<PlayerAuth>
*/
List<PlayerAuth> getLoggedPlayers();
enum DataSourceType {
MYSQL,
FILE,
SQLITE
}
}

View File

@ -1,485 +1,513 @@
package fr.xephi.authme.datasource; package fr.xephi.authme.datasource;
import java.util.ArrayList; import fr.xephi.authme.cache.auth.PlayerAuth;
import java.util.List;
import java.util.concurrent.Callable; import java.util.ArrayList;
import java.util.concurrent.ExecutorService; import java.util.List;
import java.util.concurrent.Executors; import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import fr.xephi.authme.cache.auth.PlayerAuth; import java.util.concurrent.Executors;
/** /**
*/ */
public class DatabaseCalls implements DataSource { public class DatabaseCalls implements DataSource {
private DataSource database; private final ExecutorService exec;
private final ExecutorService exec; private final DataSource database;
/** /**
* Constructor for DatabaseCalls. * Constructor for DatabaseCalls.
* @param database DataSource *
*/ * @param database DataSource
public DatabaseCalls(DataSource database) { */
this.database = database; public DatabaseCalls(DataSource database) {
this.exec = Executors.newCachedThreadPool(); this.database = database;
} this.exec = Executors.newCachedThreadPool();
}
/**
* Method isAuthAvailable. /**
* @param user String * Method isAuthAvailable.
*
* @param user String
* @return boolean * @see fr.xephi.authme.datasource.DataSource#isAuthAvailable(String) */ *
@Override * @return boolean * @see fr.xephi.authme.datasource.DataSource#isAuthAvailable(String)
public synchronized boolean isAuthAvailable(final String user) { */
try { @Override
return exec.submit(new Callable<Boolean>() { public synchronized boolean isAuthAvailable(final String user) {
public Boolean call() throws Exception { try {
return database.isAuthAvailable(user); return exec.submit(new Callable<Boolean>() {
} public Boolean call() throws Exception {
}).get(); return database.isAuthAvailable(user);
} catch (Exception e) { }
return false; }).get();
} } catch (Exception e) {
} return false;
}
/** }
* Method getAuth.
* @param user String /**
* Method getAuth.
*
* @return PlayerAuth * @see fr.xephi.authme.datasource.DataSource#getAuth(String) */ * @param user String
@Override *
public synchronized PlayerAuth getAuth(final String user) { * @return PlayerAuth * @see fr.xephi.authme.datasource.DataSource#getAuth(String)
try { */
return exec.submit(new Callable<PlayerAuth>() { @Override
public PlayerAuth call() throws Exception { public synchronized PlayerAuth getAuth(final String user) {
return database.getAuth(user); try {
} return exec.submit(new Callable<PlayerAuth>() {
}).get(); public PlayerAuth call() throws Exception {
} catch (Exception e) { return database.getAuth(user);
return null; }
} }).get();
} } catch (Exception e) {
return null;
/** }
* Method saveAuth. }
* @param auth PlayerAuth
/**
* Method saveAuth.
* @return boolean * @see fr.xephi.authme.datasource.DataSource#saveAuth(PlayerAuth) */ *
@Override * @param auth PlayerAuth
public synchronized boolean saveAuth(final PlayerAuth auth) { *
try { * @return boolean * @see fr.xephi.authme.datasource.DataSource#saveAuth(PlayerAuth)
return exec.submit(new Callable<Boolean>() { */
public Boolean call() throws Exception { @Override
return database.saveAuth(auth); public synchronized boolean saveAuth(final PlayerAuth auth) {
} try {
}).get(); return exec.submit(new Callable<Boolean>() {
} catch (Exception e) { public Boolean call() throws Exception {
return false; return database.saveAuth(auth);
} }
} }).get();
} catch (Exception e) {
/** return false;
* Method updateSession. }
* @param auth PlayerAuth }
/**
* @return boolean * @see fr.xephi.authme.datasource.DataSource#updateSession(PlayerAuth) */ * Method updateSession.
@Override *
public synchronized boolean updateSession(final PlayerAuth auth) { * @param auth PlayerAuth
try { *
return exec.submit(new Callable<Boolean>() { * @return boolean * @see fr.xephi.authme.datasource.DataSource#updateSession(PlayerAuth)
public Boolean call() throws Exception { */
return database.updateSession(auth); @Override
} public synchronized boolean updateSession(final PlayerAuth auth) {
}).get(); try {
} catch (Exception e) { return exec.submit(new Callable<Boolean>() {
return false; public Boolean call() throws Exception {
} return database.updateSession(auth);
} }
}).get();
/** } catch (Exception e) {
* Method updatePassword. return false;
* @param auth PlayerAuth }
}
* @return boolean * @see fr.xephi.authme.datasource.DataSource#updatePassword(PlayerAuth) */ /**
@Override * Method updatePassword.
public synchronized boolean updatePassword(final PlayerAuth auth) { *
try { * @param auth PlayerAuth
return exec.submit(new Callable<Boolean>() { *
public Boolean call() throws Exception { * @return boolean * @see fr.xephi.authme.datasource.DataSource#updatePassword(PlayerAuth)
return database.updatePassword(auth); */
} @Override
}).get(); public synchronized boolean updatePassword(final PlayerAuth auth) {
} catch (Exception e) { try {
return false; return exec.submit(new Callable<Boolean>() {
} public Boolean call() throws Exception {
} return database.updatePassword(auth);
}
/** }).get();
* Method purgeDatabase. } catch (Exception e) {
* @param until long return false;
}
}
* @return int * @see fr.xephi.authme.datasource.DataSource#purgeDatabase(long) */
@Override /**
public synchronized int purgeDatabase(final long until) { * Method purgeDatabase.
try { *
return exec.submit(new Callable<Integer>() { * @param until long
public Integer call() throws Exception { *
return database.purgeDatabase(until); * @return int * @see fr.xephi.authme.datasource.DataSource#purgeDatabase(long)
} */
}).get(); @Override
} catch (Exception e) { public synchronized int purgeDatabase(final long until) {
return -1; try {
} return exec.submit(new Callable<Integer>() {
} public Integer call() throws Exception {
return database.purgeDatabase(until);
/** }
* Method autoPurgeDatabase. }).get();
* @param until long } catch (Exception e) {
return -1;
}
* @return List<String> * @see fr.xephi.authme.datasource.DataSource#autoPurgeDatabase(long) */ }
@Override
public synchronized List<String> autoPurgeDatabase(final long until) { /**
try { * Method autoPurgeDatabase.
return exec.submit(new Callable<List<String>>() { *
public List<String> call() throws Exception { * @param until long
return database.autoPurgeDatabase(until); *
} * @return List<String> * @see fr.xephi.authme.datasource.DataSource#autoPurgeDatabase(long)
}).get(); */
} catch (Exception e) { @Override
return new ArrayList<>(); public synchronized List<String> autoPurgeDatabase(final long until) {
} try {
} return exec.submit(new Callable<List<String>>() {
public List<String> call() throws Exception {
/** return database.autoPurgeDatabase(until);
* Method removeAuth. }
* @param user String }).get();
} catch (Exception e) {
return new ArrayList<>();
* @return boolean * @see fr.xephi.authme.datasource.DataSource#removeAuth(String) */ }
@Override }
public synchronized boolean removeAuth(final String user) {
try { /**
return exec.submit(new Callable<Boolean>() { * Method removeAuth.
public Boolean call() throws Exception { *
return database.removeAuth(user); * @param user String
} *
}).get(); * @return boolean * @see fr.xephi.authme.datasource.DataSource#removeAuth(String)
} catch (Exception e) { */
return false; @Override
} public synchronized boolean removeAuth(final String user) {
} try {
return exec.submit(new Callable<Boolean>() {
/** public Boolean call() throws Exception {
* Method updateQuitLoc. return database.removeAuth(user);
* @param auth PlayerAuth }
}).get();
} catch (Exception e) {
* @return boolean * @see fr.xephi.authme.datasource.DataSource#updateQuitLoc(PlayerAuth) */ return false;
@Override }
public synchronized boolean updateQuitLoc(final PlayerAuth auth) { }
try {
return exec.submit(new Callable<Boolean>() { /**
public Boolean call() throws Exception { * Method updateQuitLoc.
return database.updateQuitLoc(auth); *
} * @param auth PlayerAuth
}).get(); *
} catch (Exception e) { * @return boolean * @see fr.xephi.authme.datasource.DataSource#updateQuitLoc(PlayerAuth)
return false; */
} @Override
} public synchronized boolean updateQuitLoc(final PlayerAuth auth) {
try {
/** return exec.submit(new Callable<Boolean>() {
* Method getIps. public Boolean call() throws Exception {
* @param ip String return database.updateQuitLoc(auth);
}
}).get();
* @return int * @see fr.xephi.authme.datasource.DataSource#getIps(String) */ } catch (Exception e) {
@Override return false;
public synchronized int getIps(final String ip) { }
try { }
return exec.submit(new Callable<Integer>() {
/**
public Integer call() throws Exception { * Method getIps.
return database.getIps(ip); *
} * @param ip String
}).get(); *
} catch (Exception e) { * @return int * @see fr.xephi.authme.datasource.DataSource#getIps(String)
return -1; */
} @Override
} public synchronized int getIps(final String ip) {
try {
/** return exec.submit(new Callable<Integer>() {
* Method getAllAuthsByName.
* @param auth PlayerAuth public Integer call() throws Exception {
return database.getIps(ip);
}
* @return List<String> * @see fr.xephi.authme.datasource.DataSource#getAllAuthsByName(PlayerAuth) */ }).get();
@Override } catch (Exception e) {
public synchronized List<String> getAllAuthsByName(final PlayerAuth auth) { return -1;
try { }
return exec.submit(new Callable<List<String>>() { }
public List<String> call() throws Exception {
return database.getAllAuthsByName(auth); /**
} * Method getAllAuthsByName.
}).get(); *
} catch (Exception e) { * @param auth PlayerAuth
return new ArrayList<>(); *
} * @return List<String> * @see fr.xephi.authme.datasource.DataSource#getAllAuthsByName(PlayerAuth)
} */
@Override
/** public synchronized List<String> getAllAuthsByName(final PlayerAuth auth) {
* Method getAllAuthsByIp. try {
* @param ip String return exec.submit(new Callable<List<String>>() {
public List<String> call() throws Exception {
return database.getAllAuthsByName(auth);
* @return List<String> * @see fr.xephi.authme.datasource.DataSource#getAllAuthsByIp(String) */ }
@Override }).get();
public synchronized List<String> getAllAuthsByIp(final String ip) { } catch (Exception e) {
try { return new ArrayList<>();
return exec.submit(new Callable<List<String>>() { }
public List<String> call() throws Exception { }
return database.getAllAuthsByIp(ip);
} /**
}).get(); * Method getAllAuthsByIp.
} catch (Exception e) { *
return new ArrayList<>(); * @param ip String
} *
} * @return List<String> * @see fr.xephi.authme.datasource.DataSource#getAllAuthsByIp(String)
*/
/** @Override
* Method getAllAuthsByEmail. public synchronized List<String> getAllAuthsByIp(final String ip) {
* @param email String try {
return exec.submit(new Callable<List<String>>() {
public List<String> call() throws Exception {
* @return List<String> * @see fr.xephi.authme.datasource.DataSource#getAllAuthsByEmail(String) */ return database.getAllAuthsByIp(ip);
@Override }
public synchronized List<String> getAllAuthsByEmail(final String email) { }).get();
try { } catch (Exception e) {
return exec.submit(new Callable<List<String>>() { return new ArrayList<>();
public List<String> call() throws Exception { }
return database.getAllAuthsByEmail(email); }
}
}).get(); /**
} catch (Exception e) { * Method getAllAuthsByEmail.
return new ArrayList<>(); *
} * @param email String
} *
* @return List<String> * @see fr.xephi.authme.datasource.DataSource#getAllAuthsByEmail(String)
/** */
* Method updateEmail. @Override
* @param auth PlayerAuth public synchronized List<String> getAllAuthsByEmail(final String email) {
try {
return exec.submit(new Callable<List<String>>() {
* @return boolean * @see fr.xephi.authme.datasource.DataSource#updateEmail(PlayerAuth) */ public List<String> call() throws Exception {
@Override return database.getAllAuthsByEmail(email);
public synchronized boolean updateEmail(final PlayerAuth auth) { }
try { }).get();
return exec.submit(new Callable<Boolean>() { } catch (Exception e) {
public Boolean call() throws Exception { return new ArrayList<>();
return database.updateEmail(auth); }
} }
}).get();
} catch (Exception e) { /**
return false; * Method updateEmail.
} *
} * @param auth PlayerAuth
*
/** * @return boolean * @see fr.xephi.authme.datasource.DataSource#updateEmail(PlayerAuth)
* Method updateSalt. */
* @param auth PlayerAuth @Override
public synchronized boolean updateEmail(final PlayerAuth auth) {
try {
* @return boolean * @see fr.xephi.authme.datasource.DataSource#updateSalt(PlayerAuth) */ return exec.submit(new Callable<Boolean>() {
@Override public Boolean call() throws Exception {
public synchronized boolean updateSalt(final PlayerAuth auth) { return database.updateEmail(auth);
try { }
return exec.submit(new Callable<Boolean>() { }).get();
public Boolean call() throws Exception { } catch (Exception e) {
return database.updateSalt(auth); return false;
} }
}).get(); }
} catch (Exception e) {
return false; /**
} * Method updateSalt.
} *
* @param auth PlayerAuth
/** *
* Method close. * @return boolean * @see fr.xephi.authme.datasource.DataSource#updateSalt(PlayerAuth)
* @see fr.xephi.authme.datasource.DataSource#close() */
*/ @Override
@Override public synchronized boolean updateSalt(final PlayerAuth auth) {
public synchronized void close() { try {
exec.shutdown(); return exec.submit(new Callable<Boolean>() {
database.close(); public Boolean call() throws Exception {
} return database.updateSalt(auth);
}
/** }).get();
* Method reload. } catch (Exception e) {
* @see fr.xephi.authme.datasource.DataSource#reload() return false;
*/ }
@Override }
public synchronized void reload() {
database.reload(); /**
} * Method close.
*
/** * @see fr.xephi.authme.datasource.DataSource#close()
* Method purgeBanned. */
* @param banned List<String> @Override
public synchronized void close() {
* @see fr.xephi.authme.datasource.DataSource#purgeBanned(List<String>) */ exec.shutdown();
@Override database.close();
public synchronized void purgeBanned(final List<String> banned) { }
new Thread(new Runnable() {
public synchronized void run() { /**
database.purgeBanned(banned); * Method reload.
} *
}).start(); * @see fr.xephi.authme.datasource.DataSource#reload()
} */
@Override
/** public synchronized void reload() {
* Method getType. database.reload();
}
* @return DataSourceType * @see fr.xephi.authme.datasource.DataSource#getType() */ /**
@Override * Method purgeBanned.
public synchronized DataSourceType getType() { *
return database.getType(); * @param banned List<String>
} *
* @see fr.xephi.authme.datasource.DataSource#purgeBanned(List<String>)
/** */
* Method isLogged. @Override
* @param user String public synchronized void purgeBanned(final List<String> banned) {
new Thread(new Runnable() {
public synchronized void run() {
* @return boolean * @see fr.xephi.authme.datasource.DataSource#isLogged(String) */ database.purgeBanned(banned);
@Override }
public synchronized boolean isLogged(final String user) { }).start();
try { }
return exec.submit(new Callable<Boolean>() {
public Boolean call() throws Exception { /**
return database.isLogged(user); * Method getType.
} *
}).get(); * @return DataSourceType * @see fr.xephi.authme.datasource.DataSource#getType()
} catch (Exception e) { */
return false; @Override
} public synchronized DataSourceType getType() {
} return database.getType();
}
/**
* Method setLogged. /**
* @param user String * Method isLogged.
*
* @see fr.xephi.authme.datasource.DataSource#setLogged(String) */ * @param user String
@Override *
public synchronized void setLogged(final String user) { * @return boolean * @see fr.xephi.authme.datasource.DataSource#isLogged(String)
exec.execute(new Runnable() { */
public synchronized void run() { @Override
database.setLogged(user); public synchronized boolean isLogged(final String user) {
} try {
}); return exec.submit(new Callable<Boolean>() {
} public Boolean call() throws Exception {
return database.isLogged(user);
/** }
* Method setUnlogged. }).get();
* @param user String } catch (Exception e) {
return false;
* @see fr.xephi.authme.datasource.DataSource#setUnlogged(String) */ }
@Override }
public synchronized void setUnlogged(final String user) {
exec.execute(new Runnable() { /**
public synchronized void run() { * Method setLogged.
database.setUnlogged(user); *
} * @param user String
}); *
} * @see fr.xephi.authme.datasource.DataSource#setLogged(String)
*/
/** @Override
* Method purgeLogged. public synchronized void setLogged(final String user) {
* @see fr.xephi.authme.datasource.DataSource#purgeLogged() exec.execute(new Runnable() {
*/ public synchronized void run() {
@Override database.setLogged(user);
public synchronized void purgeLogged() { }
exec.execute(new Runnable() { });
public synchronized void run() { }
database.purgeLogged();
} /**
}); * Method setUnlogged.
} *
* @param user String
/** *
* Method getAccountsRegistered. * @see fr.xephi.authme.datasource.DataSource#setUnlogged(String)
*/
@Override
* @return int * @see fr.xephi.authme.datasource.DataSource#getAccountsRegistered() */ public synchronized void setUnlogged(final String user) {
@Override exec.execute(new Runnable() {
public synchronized int getAccountsRegistered() { public synchronized void run() {
try { database.setUnlogged(user);
return exec.submit(new Callable<Integer>() { }
public Integer call() throws Exception { });
return database.getAccountsRegistered(); }
}
}).get(); /**
} catch (Exception e) { * Method purgeLogged.
return -1; *
} * @see fr.xephi.authme.datasource.DataSource#purgeLogged()
} */
@Override
/** public synchronized void purgeLogged() {
* Method updateName. exec.execute(new Runnable() {
* @param oldone String public synchronized void run() {
* @param newone String database.purgeLogged();
}
* @see fr.xephi.authme.datasource.DataSource#updateName(String, String) */ });
@Override }
public synchronized void updateName(final String oldone, final String newone) {
exec.execute(new Runnable() { /**
public synchronized void run() { * Method getAccountsRegistered.
database.updateName(oldone, newone); *
} * @return int * @see fr.xephi.authme.datasource.DataSource#getAccountsRegistered()
}); */
} @Override
public synchronized int getAccountsRegistered() {
/** try {
* Method getAllAuths. return exec.submit(new Callable<Integer>() {
public Integer call() throws Exception {
return database.getAccountsRegistered();
* @return List<PlayerAuth> * @see fr.xephi.authme.datasource.DataSource#getAllAuths() */ }
@Override }).get();
public synchronized List<PlayerAuth> getAllAuths() { } catch (Exception e) {
try { return -1;
return exec.submit(new Callable<List<PlayerAuth>>() { }
public List<PlayerAuth> call() throws Exception { }
return database.getAllAuths();
} /**
}).get(); * Method updateName.
} catch (Exception e) { *
return new ArrayList<>(); * @param oldOne String
} * @param newOne String
} *
* @see fr.xephi.authme.datasource.DataSource#updateName(String, String)
/** */
* Method getLoggedPlayers. @Override
public synchronized void updateName(final String oldOne, final String newOne) {
exec.execute(new Runnable() {
* @return List<PlayerAuth> * @see fr.xephi.authme.datasource.DataSource#getLoggedPlayers() */ public synchronized void run() {
@Override database.updateName(oldOne, newOne);
public List<PlayerAuth> getLoggedPlayers() { }
try { });
return exec.submit(new Callable<List<PlayerAuth>>() { }
public List<PlayerAuth> call() throws Exception {
return database.getLoggedPlayers(); /**
} * Method getAllAuths.
}).get(); *
} catch (Exception e) { * @return List<PlayerAuth> * @see fr.xephi.authme.datasource.DataSource#getAllAuths()
return new ArrayList<>(); */
} @Override
} public synchronized List<PlayerAuth> getAllAuths() {
try {
} return exec.submit(new Callable<List<PlayerAuth>>() {
public List<PlayerAuth> call() throws Exception {
return database.getAllAuths();
}
}).get();
} catch (Exception e) {
return new ArrayList<>();
}
}
/**
* Method getLoggedPlayers.
*
* @return List<PlayerAuth> * @see fr.xephi.authme.datasource.DataSource#getLoggedPlayers()
*/
@Override
public List<PlayerAuth> getLoggedPlayers() {
try {
return exec.submit(new Callable<List<PlayerAuth>>() {
public List<PlayerAuth> call() throws Exception {
return database.getLoggedPlayers();
}
}).get();
} catch (Exception e) {
return new ArrayList<>();
}
}
}

View File

@ -1,21 +1,15 @@
package fr.xephi.authme.datasource; package fr.xephi.authme.datasource;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import fr.xephi.authme.AuthMe; import fr.xephi.authme.AuthMe;
import fr.xephi.authme.ConsoleLogger; import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.cache.auth.PlayerAuth; import fr.xephi.authme.cache.auth.PlayerAuth;
import fr.xephi.authme.cache.auth.PlayerCache; import fr.xephi.authme.cache.auth.PlayerCache;
import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.Settings;
import java.io.*;
import java.util.ArrayList;
import java.util.List;
/** /**
*/ */
public class FlatFile implements DataSource { public class FlatFile implements DataSource {
@ -31,7 +25,7 @@ public class FlatFile implements DataSource {
* :LASTPOSZ:LASTPOSWORLD PLAYERNAME:HASHSUM:IP:LOGININMILLIESECONDS * :LASTPOSZ:LASTPOSWORLD PLAYERNAME:HASHSUM:IP:LOGININMILLIESECONDS
* PLAYERNAME:HASHSUM:IP PLAYERNAME:HASHSUM * PLAYERNAME:HASHSUM:IP PLAYERNAME:HASHSUM
*/ */
private File source; private final File source;
public FlatFile() { public FlatFile() {
source = Settings.AUTH_FILE; source = Settings.AUTH_FILE;
@ -52,10 +46,11 @@ public class FlatFile implements DataSource {
/** /**
* Method isAuthAvailable. * Method isAuthAvailable.
*
* @param user String * @param user String
*
* @return boolean * @see fr.xephi.authme.datasource.DataSource#isAuthAvailable(String)
* @return boolean * @see fr.xephi.authme.datasource.DataSource#isAuthAvailable(String) */ */
@Override @Override
public synchronized boolean isAuthAvailable(String user) { public synchronized boolean isAuthAvailable(String user) {
BufferedReader br = null; BufferedReader br = null;
@ -78,7 +73,7 @@ public class FlatFile implements DataSource {
if (br != null) { if (br != null) {
try { try {
br.close(); br.close();
} catch (IOException ex) { } catch (IOException ignored) {
} }
} }
} }
@ -87,10 +82,11 @@ public class FlatFile implements DataSource {
/** /**
* Method saveAuth. * Method saveAuth.
*
* @param auth PlayerAuth * @param auth PlayerAuth
*
* @return boolean * @see fr.xephi.authme.datasource.DataSource#saveAuth(PlayerAuth)
* @return boolean * @see fr.xephi.authme.datasource.DataSource#saveAuth(PlayerAuth) */ */
@Override @Override
public synchronized boolean saveAuth(PlayerAuth auth) { public synchronized boolean saveAuth(PlayerAuth auth) {
if (isAuthAvailable(auth.getNickname())) { if (isAuthAvailable(auth.getNickname())) {
@ -107,7 +103,7 @@ public class FlatFile implements DataSource {
if (bw != null) { if (bw != null) {
try { try {
bw.close(); bw.close();
} catch (IOException ex) { } catch (IOException ignored) {
} }
} }
} }
@ -116,10 +112,11 @@ public class FlatFile implements DataSource {
/** /**
* Method updatePassword. * Method updatePassword.
*
* @param auth PlayerAuth * @param auth PlayerAuth
*
* @return boolean * @see fr.xephi.authme.datasource.DataSource#updatePassword(PlayerAuth)
* @return boolean * @see fr.xephi.authme.datasource.DataSource#updatePassword(PlayerAuth) */ */
@Override @Override
public synchronized boolean updatePassword(PlayerAuth auth) { public synchronized boolean updatePassword(PlayerAuth auth) {
if (!isAuthAvailable(auth.getNickname())) { if (!isAuthAvailable(auth.getNickname())) {
@ -168,7 +165,7 @@ public class FlatFile implements DataSource {
if (br != null) { if (br != null) {
try { try {
br.close(); br.close();
} catch (IOException ex) { } catch (IOException ignored) {
} }
} }
} }
@ -181,10 +178,11 @@ public class FlatFile implements DataSource {
/** /**
* Method updateSession. * Method updateSession.
*
* @param auth PlayerAuth * @param auth PlayerAuth
*
* @return boolean * @see fr.xephi.authme.datasource.DataSource#updateSession(PlayerAuth)
* @return boolean * @see fr.xephi.authme.datasource.DataSource#updateSession(PlayerAuth) */ */
@Override @Override
public boolean updateSession(PlayerAuth auth) { public boolean updateSession(PlayerAuth auth) {
if (!isAuthAvailable(auth.getNickname())) { if (!isAuthAvailable(auth.getNickname())) {
@ -233,7 +231,7 @@ public class FlatFile implements DataSource {
if (br != null) { if (br != null) {
try { try {
br.close(); br.close();
} catch (IOException ex) { } catch (IOException ignored) {
} }
} }
} }
@ -246,10 +244,11 @@ public class FlatFile implements DataSource {
/** /**
* Method updateQuitLoc. * Method updateQuitLoc.
*
* @param auth PlayerAuth * @param auth PlayerAuth
*
* @return boolean * @see fr.xephi.authme.datasource.DataSource#updateQuitLoc(PlayerAuth)
* @return boolean * @see fr.xephi.authme.datasource.DataSource#updateQuitLoc(PlayerAuth) */ */
@Override @Override
public boolean updateQuitLoc(PlayerAuth auth) { public boolean updateQuitLoc(PlayerAuth auth) {
if (!isAuthAvailable(auth.getNickname())) { if (!isAuthAvailable(auth.getNickname())) {
@ -277,7 +276,7 @@ public class FlatFile implements DataSource {
if (br != null) { if (br != null) {
try { try {
br.close(); br.close();
} catch (IOException ex) { } catch (IOException ignored) {
} }
} }
} }
@ -290,10 +289,11 @@ public class FlatFile implements DataSource {
/** /**
* Method getIps. * Method getIps.
*
* @param ip String * @param ip String
*
* @return int * @see fr.xephi.authme.datasource.DataSource#getIps(String)
* @return int * @see fr.xephi.authme.datasource.DataSource#getIps(String) */ */
@Override @Override
public int getIps(String ip) { public int getIps(String ip) {
BufferedReader br = null; BufferedReader br = null;
@ -318,7 +318,7 @@ public class FlatFile implements DataSource {
if (br != null) { if (br != null) {
try { try {
br.close(); br.close();
} catch (IOException ex) { } catch (IOException ignored) {
} }
} }
} }
@ -326,10 +326,11 @@ public class FlatFile implements DataSource {
/** /**
* Method purgeDatabase. * Method purgeDatabase.
*
* @param until long * @param until long
*
* @return int * @see fr.xephi.authme.datasource.DataSource#purgeDatabase(long)
* @return int * @see fr.xephi.authme.datasource.DataSource#purgeDatabase(long) */ */
@Override @Override
public int purgeDatabase(long until) { public int purgeDatabase(long until) {
BufferedReader br = null; BufferedReader br = null;
@ -363,13 +364,13 @@ public class FlatFile implements DataSource {
if (br != null) { if (br != null) {
try { try {
br.close(); br.close();
} catch (IOException ex) { } catch (IOException ignored) {
} }
} }
if (bw != null) { if (bw != null) {
try { try {
bw.close(); bw.close();
} catch (IOException ex) { } catch (IOException ignored) {
} }
} }
} }
@ -378,10 +379,11 @@ public class FlatFile implements DataSource {
/** /**
* Method autoPurgeDatabase. * Method autoPurgeDatabase.
*
* @param until long * @param until long
*
* @return List<String> * @see fr.xephi.authme.datasource.DataSource#autoPurgeDatabase(long)
* @return List<String> * @see fr.xephi.authme.datasource.DataSource#autoPurgeDatabase(long) */ */
@Override @Override
public List<String> autoPurgeDatabase(long until) { public List<String> autoPurgeDatabase(long until) {
BufferedReader br = null; BufferedReader br = null;
@ -415,13 +417,13 @@ public class FlatFile implements DataSource {
if (br != null) { if (br != null) {
try { try {
br.close(); br.close();
} catch (IOException ex) { } catch (IOException ignored) {
} }
} }
if (bw != null) { if (bw != null) {
try { try {
bw.close(); bw.close();
} catch (IOException ex) { } catch (IOException ignored) {
} }
} }
} }
@ -430,10 +432,11 @@ public class FlatFile implements DataSource {
/** /**
* Method removeAuth. * Method removeAuth.
*
* @param user String * @param user String
*
* @return boolean * @see fr.xephi.authme.datasource.DataSource#removeAuth(String)
* @return boolean * @see fr.xephi.authme.datasource.DataSource#removeAuth(String) */ */
@Override @Override
public synchronized boolean removeAuth(String user) { public synchronized boolean removeAuth(String user) {
if (!isAuthAvailable(user)) { if (!isAuthAvailable(user)) {
@ -465,13 +468,13 @@ public class FlatFile implements DataSource {
if (br != null) { if (br != null) {
try { try {
br.close(); br.close();
} catch (IOException ex) { } catch (IOException ignored) {
} }
} }
if (bw != null) { if (bw != null) {
try { try {
bw.close(); bw.close();
} catch (IOException ex) { } catch (IOException ignored) {
} }
} }
} }
@ -480,10 +483,11 @@ public class FlatFile implements DataSource {
/** /**
* Method getAuth. * Method getAuth.
*
* @param user String * @param user String
*
* @return PlayerAuth * @see fr.xephi.authme.datasource.DataSource#getAuth(String)
* @return PlayerAuth * @see fr.xephi.authme.datasource.DataSource#getAuth(String) */ */
@Override @Override
public synchronized PlayerAuth getAuth(String user) { public synchronized PlayerAuth getAuth(String user) {
BufferedReader br = null; BufferedReader br = null;
@ -519,7 +523,7 @@ public class FlatFile implements DataSource {
if (br != null) { if (br != null) {
try { try {
br.close(); br.close();
} catch (IOException ex) { } catch (IOException ignored) {
} }
} }
} }
@ -528,6 +532,7 @@ public class FlatFile implements DataSource {
/** /**
* Method close. * Method close.
*
* @see fr.xephi.authme.datasource.DataSource#close() * @see fr.xephi.authme.datasource.DataSource#close()
*/ */
@Override @Override
@ -536,6 +541,7 @@ public class FlatFile implements DataSource {
/** /**
* Method reload. * Method reload.
*
* @see fr.xephi.authme.datasource.DataSource#reload() * @see fr.xephi.authme.datasource.DataSource#reload()
*/ */
@Override @Override
@ -544,10 +550,11 @@ public class FlatFile implements DataSource {
/** /**
* Method updateEmail. * Method updateEmail.
*
* @param auth PlayerAuth * @param auth PlayerAuth
*
* @return boolean * @see fr.xephi.authme.datasource.DataSource#updateEmail(PlayerAuth)
* @return boolean * @see fr.xephi.authme.datasource.DataSource#updateEmail(PlayerAuth) */ */
@Override @Override
public boolean updateEmail(PlayerAuth auth) { public boolean updateEmail(PlayerAuth auth) {
if (!isAuthAvailable(auth.getNickname())) { if (!isAuthAvailable(auth.getNickname())) {
@ -575,7 +582,7 @@ public class FlatFile implements DataSource {
if (br != null) { if (br != null) {
try { try {
br.close(); br.close();
} catch (IOException ex) { } catch (IOException ignored) {
} }
} }
} }
@ -588,10 +595,11 @@ public class FlatFile implements DataSource {
/** /**
* Method updateSalt. * Method updateSalt.
*
* @param auth PlayerAuth * @param auth PlayerAuth
*
* @return boolean * @see fr.xephi.authme.datasource.DataSource#updateSalt(PlayerAuth)
* @return boolean * @see fr.xephi.authme.datasource.DataSource#updateSalt(PlayerAuth) */ */
@Override @Override
public boolean updateSalt(PlayerAuth auth) { public boolean updateSalt(PlayerAuth auth) {
return false; return false;
@ -599,10 +607,11 @@ public class FlatFile implements DataSource {
/** /**
* Method getAllAuthsByName. * Method getAllAuthsByName.
*
* @param auth PlayerAuth * @param auth PlayerAuth
*
* @return List<String> * @see fr.xephi.authme.datasource.DataSource#getAllAuthsByName(PlayerAuth)
* @return List<String> * @see fr.xephi.authme.datasource.DataSource#getAllAuthsByName(PlayerAuth) */ */
@Override @Override
public List<String> getAllAuthsByName(PlayerAuth auth) { public List<String> getAllAuthsByName(PlayerAuth auth) {
BufferedReader br = null; BufferedReader br = null;
@ -627,7 +636,7 @@ public class FlatFile implements DataSource {
if (br != null) { if (br != null) {
try { try {
br.close(); br.close();
} catch (IOException ex) { } catch (IOException ignored) {
} }
} }
} }
@ -635,10 +644,11 @@ public class FlatFile implements DataSource {
/** /**
* Method getAllAuthsByIp. * Method getAllAuthsByIp.
*
* @param ip String * @param ip String
*
* @return List<String> * @see fr.xephi.authme.datasource.DataSource#getAllAuthsByIp(String)
* @return List<String> * @see fr.xephi.authme.datasource.DataSource#getAllAuthsByIp(String) */ */
@Override @Override
public List<String> getAllAuthsByIp(String ip) { public List<String> getAllAuthsByIp(String ip) {
BufferedReader br = null; BufferedReader br = null;
@ -663,7 +673,7 @@ public class FlatFile implements DataSource {
if (br != null) { if (br != null) {
try { try {
br.close(); br.close();
} catch (IOException ex) { } catch (IOException ignored) {
} }
} }
} }
@ -671,10 +681,11 @@ public class FlatFile implements DataSource {
/** /**
* Method getAllAuthsByEmail. * Method getAllAuthsByEmail.
*
* @param email String * @param email String
*
* @return List<String> * @see fr.xephi.authme.datasource.DataSource#getAllAuthsByEmail(String)
* @return List<String> * @see fr.xephi.authme.datasource.DataSource#getAllAuthsByEmail(String) */ */
@Override @Override
public List<String> getAllAuthsByEmail(String email) { public List<String> getAllAuthsByEmail(String email) {
BufferedReader br = null; BufferedReader br = null;
@ -699,7 +710,7 @@ public class FlatFile implements DataSource {
if (br != null) { if (br != null) {
try { try {
br.close(); br.close();
} catch (IOException ex) { } catch (IOException ignored) {
} }
} }
} }
@ -707,9 +718,11 @@ public class FlatFile implements DataSource {
/** /**
* Method purgeBanned. * Method purgeBanned.
*
* @param banned List<String> * @param banned List<String>
*
* @see fr.xephi.authme.datasource.DataSource#purgeBanned(List<String>) */ * @see fr.xephi.authme.datasource.DataSource#purgeBanned(List<String>)
*/
@Override @Override
public void purgeBanned(List<String> banned) { public void purgeBanned(List<String> banned) {
BufferedReader br = null; BufferedReader br = null;
@ -724,41 +737,38 @@ public class FlatFile implements DataSource {
if (banned.contains(args[0])) { if (banned.contains(args[0])) {
lines.add(line); lines.add(line);
} }
} catch (NullPointerException | ArrayIndexOutOfBoundsException exc) { } catch (NullPointerException | ArrayIndexOutOfBoundsException ignored) {
} }
} }
bw = new BufferedWriter(new FileWriter(source)); bw = new BufferedWriter(new FileWriter(source));
for (String l : lines) { for (String l : lines) {
bw.write(l + "\n"); bw.write(l + "\n");
} }
} catch (FileNotFoundException ex) {
ConsoleLogger.showError(ex.getMessage());
return;
} catch (IOException ex) { } catch (IOException ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return;
} finally { } finally {
if (br != null) { if (br != null) {
try { try {
br.close(); br.close();
} catch (IOException ex) { } catch (IOException ignored) {
} }
} }
if (bw != null) { if (bw != null) {
try { try {
bw.close(); bw.close();
} catch (IOException ex) { } catch (IOException ignored) {
} }
} }
} }
return;
} }
/** /**
* Method getType. * Method getType.
*
* @return DataSourceType * @see fr.xephi.authme.datasource.DataSource#getType()
* @return DataSourceType * @see fr.xephi.authme.datasource.DataSource#getType() */ */
@Override @Override
public DataSourceType getType() { public DataSourceType getType() {
return DataSourceType.FILE; return DataSourceType.FILE;
@ -766,10 +776,11 @@ public class FlatFile implements DataSource {
/** /**
* Method isLogged. * Method isLogged.
*
* @param user String * @param user String
*
* @return boolean * @see fr.xephi.authme.datasource.DataSource#isLogged(String)
* @return boolean * @see fr.xephi.authme.datasource.DataSource#isLogged(String) */ */
@Override @Override
public boolean isLogged(String user) { public boolean isLogged(String user) {
return PlayerCache.getInstance().isAuthenticated(user); return PlayerCache.getInstance().isAuthenticated(user);
@ -777,24 +788,29 @@ public class FlatFile implements DataSource {
/** /**
* Method setLogged. * Method setLogged.
*
* @param user String * @param user String
*
* @see fr.xephi.authme.datasource.DataSource#setLogged(String) */ * @see fr.xephi.authme.datasource.DataSource#setLogged(String)
*/
@Override @Override
public void setLogged(String user) { public void setLogged(String user) {
} }
/** /**
* Method setUnlogged. * Method setUnlogged.
*
* @param user String * @param user String
*
* @see fr.xephi.authme.datasource.DataSource#setUnlogged(String) */ * @see fr.xephi.authme.datasource.DataSource#setUnlogged(String)
*/
@Override @Override
public void setUnlogged(String user) { public void setUnlogged(String user) {
} }
/** /**
* Method purgeLogged. * Method purgeLogged.
*
* @see fr.xephi.authme.datasource.DataSource#purgeLogged() * @see fr.xephi.authme.datasource.DataSource#purgeLogged()
*/ */
@Override @Override
@ -803,9 +819,9 @@ public class FlatFile implements DataSource {
/** /**
* Method getAccountsRegistered. * Method getAccountsRegistered.
*
* @return int * @see fr.xephi.authme.datasource.DataSource#getAccountsRegistered()
* @return int * @see fr.xephi.authme.datasource.DataSource#getAccountsRegistered() */ */
@Override @Override
public int getAccountsRegistered() { public int getAccountsRegistered() {
BufferedReader br = null; BufferedReader br = null;
@ -822,7 +838,7 @@ public class FlatFile implements DataSource {
if (br != null) { if (br != null) {
try { try {
br.close(); br.close();
} catch (IOException ex) { } catch (IOException ignored) {
} }
} }
} }
@ -831,23 +847,25 @@ public class FlatFile implements DataSource {
/** /**
* Method updateName. * Method updateName.
* @param oldone String *
* @param newone String * @param oldOne String
* @param newOne String
* @see fr.xephi.authme.datasource.DataSource#updateName(String, String) */ *
* @see fr.xephi.authme.datasource.DataSource#updateName(String, String)
*/
@Override @Override
public void updateName(String oldone, String newone) { public void updateName(String oldOne, String newOne) {
PlayerAuth auth = this.getAuth(oldone); PlayerAuth auth = this.getAuth(oldOne);
auth.setName(newone); auth.setName(newOne);
this.saveAuth(auth); this.saveAuth(auth);
this.removeAuth(oldone); this.removeAuth(oldOne);
} }
/** /**
* Method getAllAuths. * Method getAllAuths.
*
* @return List<PlayerAuth> * @see fr.xephi.authme.datasource.DataSource#getAllAuths()
* @return List<PlayerAuth> * @see fr.xephi.authme.datasource.DataSource#getAllAuths() */ */
@Override @Override
public List<PlayerAuth> getAllAuths() { public List<PlayerAuth> getAllAuths() {
BufferedReader br = null; BufferedReader br = null;
@ -888,7 +906,7 @@ public class FlatFile implements DataSource {
if (br != null) { if (br != null) {
try { try {
br.close(); br.close();
} catch (IOException ex) { } catch (IOException ignored) {
} }
} }
} }
@ -897,9 +915,9 @@ public class FlatFile implements DataSource {
/** /**
* Method getLoggedPlayers. * Method getLoggedPlayers.
*
* @return List<PlayerAuth> * @see fr.xephi.authme.datasource.DataSource#getLoggedPlayers()
* @return List<PlayerAuth> * @see fr.xephi.authme.datasource.DataSource#getLoggedPlayers() */ */
@Override @Override
public List<PlayerAuth> getLoggedPlayers() { public List<PlayerAuth> getLoggedPlayers() {
return new ArrayList<>(); return new ArrayList<>();

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -5,7 +5,6 @@ import org.bukkit.event.Event;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;
/** /**
*
* This event is call when a player try to /login * This event is call when a player try to /login
* *
* @author Xephi59 * @author Xephi59
@ -13,12 +12,13 @@ import org.bukkit.event.HandlerList;
*/ */
public class AuthMeAsyncPreLoginEvent extends Event { public class AuthMeAsyncPreLoginEvent extends Event {
private Player player;
private boolean canLogin = true;
private static final HandlerList handlers = new HandlerList(); private static final HandlerList handlers = new HandlerList();
private final Player player;
private boolean canLogin = true;
/** /**
* Constructor for AuthMeAsyncPreLoginEvent. * Constructor for AuthMeAsyncPreLoginEvent.
*
* @param player Player * @param player Player
*/ */
public AuthMeAsyncPreLoginEvent(Player player) { public AuthMeAsyncPreLoginEvent(Player player) {
@ -28,22 +28,25 @@ public class AuthMeAsyncPreLoginEvent extends Event {
/** /**
* Method getPlayer. * Method getPlayer.
*
* @return Player */ * @return Player
*/
public Player getPlayer() { public Player getPlayer() {
return player; return player;
} }
/** /**
* Method canLogin. * Method canLogin.
*
* @return boolean */ * @return boolean
*/
public boolean canLogin() { public boolean canLogin() {
return canLogin; return canLogin;
} }
/** /**
* Method setCanLogin. * Method setCanLogin.
*
* @param canLogin boolean * @param canLogin boolean
*/ */
public void setCanLogin(boolean canLogin) { public void setCanLogin(boolean canLogin) {
@ -52,8 +55,9 @@ public class AuthMeAsyncPreLoginEvent extends Event {
/** /**
* Method getHandlers. * Method getHandlers.
*
* @return HandlerList */ * @return HandlerList
*/
@Override @Override
public HandlerList getHandlers() { public HandlerList getHandlers() {
return handlers; return handlers;

View File

@ -4,7 +4,6 @@ import org.bukkit.Location;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
/** /**
*
* This event is call when AuthMe try to teleport a player * This event is call when AuthMe try to teleport a player
* *
* @author Xephi59 * @author Xephi59
@ -12,14 +11,15 @@ import org.bukkit.entity.Player;
*/ */
public class AuthMeTeleportEvent extends CustomEvent { public class AuthMeTeleportEvent extends CustomEvent {
private Player player; private final Player player;
private Location to; private Location to;
private Location from; private final Location from;
/** /**
* Constructor for AuthMeTeleportEvent. * Constructor for AuthMeTeleportEvent.
*
* @param player Player * @param player Player
* @param to Location * @param to Location
*/ */
public AuthMeTeleportEvent(Player player, Location to) { public AuthMeTeleportEvent(Player player, Location to) {
this.player = player; this.player = player;
@ -29,32 +29,36 @@ public class AuthMeTeleportEvent extends CustomEvent {
/** /**
* Method getPlayer. * Method getPlayer.
*
* @return Player */ * @return Player
*/
public Player getPlayer() { public Player getPlayer() {
return player; return player;
} }
/**
* Method getTo.
*
* @return Location
*/
public Location getTo() {
return to;
}
/** /**
* Method setTo. * Method setTo.
*
* @param to Location * @param to Location
*/ */
public void setTo(Location to) { public void setTo(Location to) {
this.to = to; this.to = to;
} }
/**
* Method getTo.
* @return Location */
public Location getTo() {
return to;
}
/** /**
* Method getFrom. * Method getFrom.
*
* @return Location */ * @return Location
*/
public Location getFrom() { public Location getFrom() {
return from; return from;
} }

View File

@ -5,14 +5,13 @@ import org.bukkit.event.Event;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;
/** /**
*
* @author Xephi59 * @author Xephi59
* @version $Revision: 1.0 $ * @version $Revision: 1.0 $
*/ */
public class CustomEvent extends Event implements Cancellable { public class CustomEvent extends Event implements Cancellable {
private boolean isCancelled;
private static final HandlerList handlers = new HandlerList(); private static final HandlerList handlers = new HandlerList();
private boolean isCancelled;
public CustomEvent() { public CustomEvent() {
super(false); super(false);
@ -20,42 +19,47 @@ public class CustomEvent extends Event implements Cancellable {
/** /**
* Constructor for CustomEvent. * Constructor for CustomEvent.
*
* @param b boolean * @param b boolean
*/ */
public CustomEvent(boolean b) { public CustomEvent(boolean b) {
super(b); super(b);
} }
/**
* Method getHandlers.
* @return HandlerList */
public HandlerList getHandlers() {
return handlers;
}
/** /**
* Method getHandlerList. * Method getHandlerList.
*
* @return HandlerList */ * @return HandlerList
*/
public static HandlerList getHandlerList() { public static HandlerList getHandlerList() {
return handlers; return handlers;
} }
/**
* Method getHandlers.
*
* @return HandlerList
*/
public HandlerList getHandlers() {
return handlers;
}
/** /**
* Method isCancelled. * Method isCancelled.
*
* @return boolean * @see org.bukkit.event.Cancellable#isCancelled()
* @return boolean * @see org.bukkit.event.Cancellable#isCancelled() */ */
public boolean isCancelled() { public boolean isCancelled() {
return this.isCancelled; return this.isCancelled;
} }
/** /**
* Method setCancelled. * Method setCancelled.
*
* @param cancelled boolean * @param cancelled boolean
*
* @see org.bukkit.event.Cancellable#setCancelled(boolean) */ * @see org.bukkit.event.Cancellable#setCancelled(boolean)
*/
public void setCancelled(boolean cancelled) { public void setCancelled(boolean cancelled) {
this.isCancelled = cancelled; this.isCancelled = cancelled;
} }

View File

@ -4,7 +4,6 @@ import org.bukkit.Location;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
/** /**
*
* Called if a player is teleported to the authme first spawn * Called if a player is teleported to the authme first spawn
* *
* @author Xephi59 * @author Xephi59
@ -12,15 +11,16 @@ import org.bukkit.entity.Player;
*/ */
public class FirstSpawnTeleportEvent extends CustomEvent { public class FirstSpawnTeleportEvent extends CustomEvent {
private Player player; private final Player player;
private Location to; private Location to;
private Location from; private final Location from;
/** /**
* Constructor for FirstSpawnTeleportEvent. * Constructor for FirstSpawnTeleportEvent.
*
* @param player Player * @param player Player
* @param from Location * @param from Location
* @param to Location * @param to Location
*/ */
public FirstSpawnTeleportEvent(Player player, Location from, Location to) { public FirstSpawnTeleportEvent(Player player, Location from, Location to) {
super(true); super(true);
@ -31,32 +31,36 @@ public class FirstSpawnTeleportEvent extends CustomEvent {
/** /**
* Method getPlayer. * Method getPlayer.
*
* @return Player */ * @return Player
*/
public Player getPlayer() { public Player getPlayer() {
return player; return player;
} }
/**
* Method getTo.
*
* @return Location
*/
public Location getTo() {
return to;
}
/** /**
* Method setTo. * Method setTo.
*
* @param to Location * @param to Location
*/ */
public void setTo(Location to) { public void setTo(Location to) {
this.to = to; this.to = to;
} }
/**
* Method getTo.
* @return Location */
public Location getTo() {
return to;
}
/** /**
* Method getFrom. * Method getFrom.
*
* @return Location */ * @return Location
*/
public Location getFrom() { public Location getFrom() {
return from; return from;
} }

View File

@ -5,7 +5,6 @@ import org.bukkit.event.Event;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;
/** /**
*
* This event is called when a player login or register through AuthMe. The * This event is called when a player login or register through AuthMe. The
* boolean 'isLogin' will be false if, and only if, login/register failed. * boolean 'isLogin' will be false if, and only if, login/register failed.
* *
@ -14,13 +13,14 @@ import org.bukkit.event.HandlerList;
*/ */
public class LoginEvent extends Event { public class LoginEvent extends Event {
private static final HandlerList handlers = new HandlerList();
private Player player; private Player player;
private boolean isLogin; private boolean isLogin;
private static final HandlerList handlers = new HandlerList();
/** /**
* Constructor for LoginEvent. * Constructor for LoginEvent.
* @param player Player *
* @param player Player
* @param isLogin boolean * @param isLogin boolean
*/ */
public LoginEvent(Player player, boolean isLogin) { public LoginEvent(Player player, boolean isLogin) {
@ -28,24 +28,45 @@ public class LoginEvent extends Event {
this.isLogin = isLogin; this.isLogin = isLogin;
} }
/**
* Method getHandlerList.
*
* @return HandlerList
*/
public static HandlerList getHandlerList() {
return handlers;
}
/** /**
* Method getPlayer. * Method getPlayer.
*
* @return Player */ * @return Player
*/
public Player getPlayer() { public Player getPlayer() {
return this.player; return this.player;
} }
/** /**
* Method setPlayer. * Method setPlayer.
*
* @param player Player * @param player Player
*/ */
public void setPlayer(Player player) { public void setPlayer(Player player) {
this.player = player; this.player = player;
} }
/**
* Method isLogin.
*
* @return boolean
*/
public boolean isLogin() {
return isLogin;
}
/** /**
* Method setLogin. * Method setLogin.
*
* @param isLogin boolean * @param isLogin boolean
*/ */
@Deprecated @Deprecated
@ -53,29 +74,14 @@ public class LoginEvent extends Event {
this.isLogin = isLogin; this.isLogin = isLogin;
} }
/**
* Method isLogin.
* @return boolean */
public boolean isLogin() {
return isLogin;
}
/** /**
* Method getHandlers. * Method getHandlers.
*
* @return HandlerList */ * @return HandlerList
*/
@Override @Override
public HandlerList getHandlers() { public HandlerList getHandlers() {
return handlers; return handlers;
} }
/**
* Method getHandlerList.
* @return HandlerList */
public static HandlerList getHandlerList() {
return handlers;
}
} }

View File

@ -5,7 +5,6 @@ import org.bukkit.event.Event;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;
/** /**
*
* This event is called when a player logout through AuthMe. * This event is called when a player logout through AuthMe.
* *
* @author Xephi59 * @author Xephi59
@ -13,27 +12,39 @@ import org.bukkit.event.HandlerList;
*/ */
public class LogoutEvent extends Event { public class LogoutEvent extends Event {
private Player player;
private static final HandlerList handlers = new HandlerList(); private static final HandlerList handlers = new HandlerList();
private Player player;
/** /**
* Constructor for LogoutEvent. * Constructor for LogoutEvent.
*
* @param player Player * @param player Player
*/ */
public LogoutEvent(Player player) { public LogoutEvent(Player player) {
this.player = player; this.player = player;
} }
/**
* Method getHandlerList.
*
* @return HandlerList
*/
public static HandlerList getHandlerList() {
return handlers;
}
/** /**
* Method getPlayer. * Method getPlayer.
*
* @return Player */ * @return Player
*/
public Player getPlayer() { public Player getPlayer() {
return this.player; return this.player;
} }
/** /**
* Method setPlayer. * Method setPlayer.
*
* @param player Player * @param player Player
*/ */
public void setPlayer(Player player) { public void setPlayer(Player player) {
@ -42,19 +53,12 @@ public class LogoutEvent extends Event {
/** /**
* Method getHandlers. * Method getHandlers.
*
* @return HandlerList */ * @return HandlerList
*/
@Override @Override
public HandlerList getHandlers() { public HandlerList getHandlers() {
return handlers; return handlers;
} }
/**
* Method getHandlerList.
* @return HandlerList */
public static HandlerList getHandlerList() {
return handlers;
}
} }

View File

@ -1,20 +1,18 @@
package fr.xephi.authme.events; package fr.xephi.authme.events;
import fr.xephi.authme.security.crypts.EncryptionMethod;
import org.bukkit.event.Event; import org.bukkit.event.Event;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;
import fr.xephi.authme.security.crypts.EncryptionMethod;
/** /**
* <p> * <p>
* This event is called when we need to compare or get an hash password, for set * This event is called when we need to compare or get an hash password, for set
* a custom EncryptionMethod * a custom EncryptionMethod
* </p> * </p>
* *
* @see fr.xephi.authme.security.crypts.EncryptionMethod
*
* @author Xephi59 * @author Xephi59
* @version $Revision: 1.0 $ * @version $Revision: 1.0 $
* @see fr.xephi.authme.security.crypts.EncryptionMethod
*/ */
public class PasswordEncryptionEvent extends Event { public class PasswordEncryptionEvent extends Event {
@ -24,7 +22,8 @@ public class PasswordEncryptionEvent extends Event {
/** /**
* Constructor for PasswordEncryptionEvent. * Constructor for PasswordEncryptionEvent.
* @param method EncryptionMethod *
* @param method EncryptionMethod
* @param playerName String * @param playerName String
*/ */
public PasswordEncryptionEvent(EncryptionMethod method, String playerName) { public PasswordEncryptionEvent(EncryptionMethod method, String playerName) {
@ -33,45 +32,50 @@ public class PasswordEncryptionEvent extends Event {
this.playerName = playerName; this.playerName = playerName;
} }
/**
* Method getHandlerList.
*
* @return HandlerList
*/
public static HandlerList getHandlerList() {
return handlers;
}
/** /**
* Method getHandlers. * Method getHandlers.
*
* @return HandlerList */ * @return HandlerList
*/
@Override @Override
public HandlerList getHandlers() { public HandlerList getHandlers() {
return handlers; return handlers;
} }
/**
* Method getMethod.
*
* @return EncryptionMethod
*/
public EncryptionMethod getMethod() {
return method;
}
/** /**
* Method setMethod. * Method setMethod.
*
* @param method EncryptionMethod * @param method EncryptionMethod
*/ */
public void setMethod(EncryptionMethod method) { public void setMethod(EncryptionMethod method) {
this.method = method; this.method = method;
} }
/**
* Method getMethod.
* @return EncryptionMethod */
public EncryptionMethod getMethod() {
return method;
}
/** /**
* Method getPlayerName. * Method getPlayerName.
*
* @return String */ * @return String
*/
public String getPlayerName() { public String getPlayerName() {
return playerName; return playerName;
} }
/**
* Method getHandlerList.
* @return HandlerList */
public static HandlerList getHandlerList() {
return handlers;
}
} }

View File

@ -4,7 +4,6 @@ import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
/** /**
*
* This event is call just after store inventory into cache and will empty the * This event is call just after store inventory into cache and will empty the
* player inventory. * player inventory.
* *
@ -13,14 +12,15 @@ import org.bukkit.inventory.ItemStack;
*/ */
public class ProtectInventoryEvent extends CustomEvent { public class ProtectInventoryEvent extends CustomEvent {
private ItemStack[] storedinventory; private final ItemStack[] storedinventory;
private ItemStack[] storedarmor; private final ItemStack[] storedarmor;
private ItemStack[] emptyInventory = null; private ItemStack[] emptyInventory = null;
private ItemStack[] emptyArmor = null; private ItemStack[] emptyArmor = null;
private Player player; private final Player player;
/** /**
* Constructor for ProtectInventoryEvent. * Constructor for ProtectInventoryEvent.
*
* @param player Player * @param player Player
*/ */
public ProtectInventoryEvent(Player player) { public ProtectInventoryEvent(Player player) {
@ -34,30 +34,34 @@ public class ProtectInventoryEvent extends CustomEvent {
/** /**
* Method getStoredInventory. * Method getStoredInventory.
*
* @return ItemStack[] */ * @return ItemStack[]
*/
public ItemStack[] getStoredInventory() { public ItemStack[] getStoredInventory() {
return this.storedinventory; return this.storedinventory;
} }
/** /**
* Method getStoredArmor. * Method getStoredArmor.
*
* @return ItemStack[] */ * @return ItemStack[]
*/
public ItemStack[] getStoredArmor() { public ItemStack[] getStoredArmor() {
return this.storedarmor; return this.storedarmor;
} }
/** /**
* Method getPlayer. * Method getPlayer.
*
* @return Player */ * @return Player
*/
public Player getPlayer() { public Player getPlayer() {
return this.player; return this.player;
} }
/** /**
* Method setNewInventory. * Method setNewInventory.
*
* @param emptyInventory ItemStack[] * @param emptyInventory ItemStack[]
*/ */
public void setNewInventory(ItemStack[] emptyInventory) { public void setNewInventory(ItemStack[] emptyInventory) {
@ -66,14 +70,16 @@ public class ProtectInventoryEvent extends CustomEvent {
/** /**
* Method getEmptyInventory. * Method getEmptyInventory.
*
* @return ItemStack[] */ * @return ItemStack[]
*/
public ItemStack[] getEmptyInventory() { public ItemStack[] getEmptyInventory() {
return this.emptyInventory; return this.emptyInventory;
} }
/** /**
* Method setNewArmor. * Method setNewArmor.
*
* @param emptyArmor ItemStack[] * @param emptyArmor ItemStack[]
*/ */
public void setNewArmor(ItemStack[] emptyArmor) { public void setNewArmor(ItemStack[] emptyArmor) {
@ -82,8 +88,9 @@ public class ProtectInventoryEvent extends CustomEvent {
/** /**
* Method getEmptyArmor. * Method getEmptyArmor.
*
* @return ItemStack[] */ * @return ItemStack[]
*/
public ItemStack[] getEmptyArmor() { public ItemStack[] getEmptyArmor() {
return this.emptyArmor; return this.emptyArmor;
} }

View File

@ -4,7 +4,6 @@ import org.bukkit.Location;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
/** /**
*
* This event is call if, and only if, a player is teleported just after a * This event is call if, and only if, a player is teleported just after a
* register. * register.
* *
@ -13,14 +12,15 @@ import org.bukkit.entity.Player;
*/ */
public class RegisterTeleportEvent extends CustomEvent { public class RegisterTeleportEvent extends CustomEvent {
private Player player; private final Player player;
private Location to; private Location to;
private Location from; private final Location from;
/** /**
* Constructor for RegisterTeleportEvent. * Constructor for RegisterTeleportEvent.
*
* @param player Player * @param player Player
* @param to Location * @param to Location
*/ */
public RegisterTeleportEvent(Player player, Location to) { public RegisterTeleportEvent(Player player, Location to) {
this.player = player; this.player = player;
@ -30,32 +30,36 @@ public class RegisterTeleportEvent extends CustomEvent {
/** /**
* Method getPlayer. * Method getPlayer.
*
* @return Player */ * @return Player
*/
public Player getPlayer() { public Player getPlayer() {
return player; return player;
} }
/**
* Method getTo.
*
* @return Location
*/
public Location getTo() {
return to;
}
/** /**
* Method setTo. * Method setTo.
*
* @param to Location * @param to Location
*/ */
public void setTo(Location to) { public void setTo(Location to) {
this.to = to; this.to = to;
} }
/**
* Method getTo.
* @return Location */
public Location getTo() {
return to;
}
/** /**
* Method getFrom. * Method getFrom.
*
* @return Location */ * @return Location
*/
public Location getFrom() { public Location getFrom() {
return from; return from;
} }

View File

@ -3,7 +3,6 @@ package fr.xephi.authme.events;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
/** /**
*
* This event is call when a creative inventory is reseted. * This event is call when a creative inventory is reseted.
* *
* @author Xephi59 * @author Xephi59
@ -15,6 +14,7 @@ public class ResetInventoryEvent extends CustomEvent {
/** /**
* Constructor for ResetInventoryEvent. * Constructor for ResetInventoryEvent.
*
* @param player Player * @param player Player
*/ */
public ResetInventoryEvent(Player player) { public ResetInventoryEvent(Player player) {
@ -24,14 +24,16 @@ public class ResetInventoryEvent extends CustomEvent {
/** /**
* Method getPlayer. * Method getPlayer.
*
* @return Player */ * @return Player
*/
public Player getPlayer() { public Player getPlayer() {
return this.player; return this.player;
} }
/** /**
* Method setPlayer. * Method setPlayer.
*
* @param player Player * @param player Player
*/ */
public void setPlayer(Player player) { public void setPlayer(Player player) {

View File

@ -14,6 +14,7 @@ public class RestoreInventoryEvent extends CustomEvent {
/** /**
* Constructor for RestoreInventoryEvent. * Constructor for RestoreInventoryEvent.
*
* @param player Player * @param player Player
*/ */
public RestoreInventoryEvent(Player player) { public RestoreInventoryEvent(Player player) {
@ -22,8 +23,9 @@ public class RestoreInventoryEvent extends CustomEvent {
/** /**
* Constructor for RestoreInventoryEvent. * Constructor for RestoreInventoryEvent.
*
* @param player Player * @param player Player
* @param async boolean * @param async boolean
*/ */
public RestoreInventoryEvent(Player player, boolean async) { public RestoreInventoryEvent(Player player, boolean async) {
super(async); super(async);
@ -32,14 +34,16 @@ public class RestoreInventoryEvent extends CustomEvent {
/** /**
* Method getPlayer. * Method getPlayer.
*
* @return Player */ * @return Player
*/
public Player getPlayer() { public Player getPlayer() {
return this.player; return this.player;
} }
/** /**
* Method setPlayer. * Method setPlayer.
*
* @param player Player * @param player Player
*/ */
public void setPlayer(Player player) { public void setPlayer(Player player) {

View File

@ -4,7 +4,6 @@ import org.bukkit.Location;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
/** /**
*
* Called if a player is teleported to a specific spawn * Called if a player is teleported to a specific spawn
* *
* @author Xephi59 * @author Xephi59
@ -12,20 +11,21 @@ import org.bukkit.entity.Player;
*/ */
public class SpawnTeleportEvent extends CustomEvent { public class SpawnTeleportEvent extends CustomEvent {
private Player player; private final Player player;
private Location to; private Location to;
private Location from; private final Location from;
private boolean isAuthenticated; private final boolean isAuthenticated;
/** /**
* Constructor for SpawnTeleportEvent. * Constructor for SpawnTeleportEvent.
* @param player Player *
* @param from Location * @param player Player
* @param to Location * @param from Location
* @param to Location
* @param isAuthenticated boolean * @param isAuthenticated boolean
*/ */
public SpawnTeleportEvent(Player player, Location from, Location to, public SpawnTeleportEvent(Player player, Location from, Location to,
boolean isAuthenticated) { boolean isAuthenticated) {
this.player = player; this.player = player;
this.from = from; this.from = from;
this.to = to; this.to = to;
@ -34,40 +34,45 @@ public class SpawnTeleportEvent extends CustomEvent {
/** /**
* Method getPlayer. * Method getPlayer.
*
* @return Player */ * @return Player
*/
public Player getPlayer() { public Player getPlayer() {
return player; return player;
} }
/**
* Method getTo.
*
* @return Location
*/
public Location getTo() {
return to;
}
/** /**
* Method setTo. * Method setTo.
*
* @param to Location * @param to Location
*/ */
public void setTo(Location to) { public void setTo(Location to) {
this.to = to; this.to = to;
} }
/**
* Method getTo.
* @return Location */
public Location getTo() {
return to;
}
/** /**
* Method getFrom. * Method getFrom.
*
* @return Location */ * @return Location
*/
public Location getFrom() { public Location getFrom() {
return from; return from;
} }
/** /**
* Method isAuthenticated. * Method isAuthenticated.
*
* @return boolean */ * @return boolean
*/
public boolean isAuthenticated() { public boolean isAuthenticated() {
return isAuthenticated; return isAuthenticated;
} }

View File

@ -1,21 +1,20 @@
package fr.xephi.authme.hooks; package fr.xephi.authme.hooks;
import org.bukkit.entity.Player;
import org.bukkit.plugin.messaging.PluginMessageListener;
import com.google.common.io.ByteArrayDataInput; import com.google.common.io.ByteArrayDataInput;
import com.google.common.io.ByteStreams; import com.google.common.io.ByteStreams;
import fr.xephi.authme.AuthMe; import fr.xephi.authme.AuthMe;
import org.bukkit.entity.Player;
import org.bukkit.plugin.messaging.PluginMessageListener;
/** /**
*/ */
public class BungeeCordMessage implements PluginMessageListener { public class BungeeCordMessage implements PluginMessageListener {
public AuthMe plugin; public final AuthMe plugin;
/** /**
* Constructor for BungeeCordMessage. * Constructor for BungeeCordMessage.
*
* @param plugin AuthMe * @param plugin AuthMe
*/ */
public BungeeCordMessage(AuthMe plugin) { public BungeeCordMessage(AuthMe plugin) {
@ -24,11 +23,13 @@ public class BungeeCordMessage implements PluginMessageListener {
/** /**
* Method onPluginMessageReceived. * Method onPluginMessageReceived.
*
* @param channel String * @param channel String
* @param player Player * @param player Player
* @param message byte[] * @param message byte[]
*
* @see org.bukkit.plugin.messaging.PluginMessageListener#onPluginMessageReceived(String, Player, byte[]) */ * @see org.bukkit.plugin.messaging.PluginMessageListener#onPluginMessageReceived(String, Player, byte[])
*/
@Override @Override
public void onPluginMessageReceived(String channel, Player player, public void onPluginMessageReceived(String channel, Player player,
byte[] message) { byte[] message) {

View File

@ -1,11 +1,10 @@
package fr.xephi.authme.hooks; package fr.xephi.authme.hooks;
import java.io.File; import fr.xephi.authme.settings.CustomConfiguration;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import fr.xephi.authme.settings.CustomConfiguration; import java.io.File;
/** /**
*/ */
@ -21,8 +20,9 @@ public class EssSpawn extends CustomConfiguration {
/** /**
* Method getInstance. * Method getInstance.
*
* @return EssSpawn */ * @return EssSpawn
*/
public static EssSpawn getInstance() { public static EssSpawn getInstance() {
if (spawn == null) { if (spawn == null) {
spawn = new EssSpawn(); spawn = new EssSpawn();
@ -32,8 +32,9 @@ public class EssSpawn extends CustomConfiguration {
/** /**
* Method getLocation. * Method getLocation.
*
* @return Location */ * @return Location
*/
public Location getLocation() { public Location getLocation() {
try { try {
if (!this.contains("spawns.default.world")) if (!this.contains("spawns.default.world"))

View File

@ -1,22 +1,22 @@
package fr.xephi.authme.listener; package fr.xephi.authme.listener;
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.util.Utils;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.block.BlockPlaceEvent;
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.util.Utils;
/** /**
*/ */
public class AuthMeBlockListener implements Listener { public class AuthMeBlockListener implements Listener {
public AuthMe instance; public final AuthMe instance;
/** /**
* Constructor for AuthMeBlockListener. * Constructor for AuthMeBlockListener.
*
* @param instance AuthMe * @param instance AuthMe
*/ */
public AuthMeBlockListener(AuthMe instance) { public AuthMeBlockListener(AuthMe instance) {
@ -26,6 +26,7 @@ public class AuthMeBlockListener implements Listener {
/** /**
* Method onBlockPlace. * Method onBlockPlace.
*
* @param event BlockPlaceEvent * @param event BlockPlaceEvent
*/ */
@EventHandler(ignoreCancelled = true) @EventHandler(ignoreCancelled = true)
@ -37,6 +38,7 @@ public class AuthMeBlockListener implements Listener {
/** /**
* Method onBlockBreak. * Method onBlockBreak.
*
* @param event BlockBreakEvent * @param event BlockBreakEvent
*/ */
@EventHandler(ignoreCancelled = true) @EventHandler(ignoreCancelled = true)

Some files were not shown because too many files have changed in this diff Show More