commit
8046d690ad
@ -1,6 +1,10 @@
|
|||||||
<p align="center"><img src="http://i61.tinypic.com/291dm49.png"></p>
|
<p align="center"><img src="http://i61.tinypic.com/291dm49.png"></p>
|
||||||
<p align="center"><strong>The most used authentication plugin for CraftBukkit/Spigot!</strong></p>
|
<p align="center"><strong>The most used authentication plugin for CraftBukkit/Spigot!</strong></p>
|
||||||
<hr>
|
<hr>
|
||||||
|
|
||||||
|
####Development history:
|
||||||
|
[](https://www.youtube.com/watch?v=hJRzNfYyd9k)
|
||||||
|
|
||||||
#####Development tools:
|
#####Development tools:
|
||||||
|
|
||||||
- DEVELOPMENT TEAM REPO (<strong>please send PRs here!</strong>): <a href="https://github.com/AuthMe-Team/AuthMeReloaded">Github Development Page</a>
|
- DEVELOPMENT TEAM REPO (<strong>please send PRs here!</strong>): <a href="https://github.com/AuthMe-Team/AuthMeReloaded">Github Development Page</a>
|
||||||
|
|||||||
20
pom.xml
20
pom.xml
@ -210,12 +210,13 @@
|
|||||||
<artifactId>javax.mail</artifactId>
|
<artifactId>javax.mail</artifactId>
|
||||||
<version>1.5.4</version>
|
<version>1.5.4</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
<exclusions>
|
<optional>true</optional>
|
||||||
<exclusion>
|
</dependency>
|
||||||
<artifactId>activation</artifactId>
|
<dependency>
|
||||||
<groupId>javax.activation</groupId>
|
<groupId>javax.mail</groupId>
|
||||||
</exclusion>
|
<artifactId>javax.mail-api</artifactId>
|
||||||
</exclusions>
|
<version>1.5.4</version>
|
||||||
|
<scope>compile</scope>
|
||||||
<optional>true</optional>
|
<optional>true</optional>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
@ -502,5 +503,12 @@
|
|||||||
<optional>true</optional>
|
<optional>true</optional>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- String comparison library. Used for dynamic help system. -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>net.ricecode</groupId>
|
||||||
|
<artifactId>string-similarity</artifactId>
|
||||||
|
<version>1.0.0</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
@ -16,6 +16,7 @@ import org.bukkit.Bukkit;
|
|||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Server;
|
import org.bukkit.Server;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.PluginManager;
|
import org.bukkit.plugin.PluginManager;
|
||||||
@ -35,15 +36,7 @@ import fr.xephi.authme.cache.auth.PlayerCache;
|
|||||||
import fr.xephi.authme.cache.backup.JsonCache;
|
import fr.xephi.authme.cache.backup.JsonCache;
|
||||||
import fr.xephi.authme.cache.limbo.LimboCache;
|
import fr.xephi.authme.cache.limbo.LimboCache;
|
||||||
import fr.xephi.authme.cache.limbo.LimboPlayer;
|
import fr.xephi.authme.cache.limbo.LimboPlayer;
|
||||||
import fr.xephi.authme.commands.AdminCommand;
|
import fr.xephi.authme.command.CommandHandler;
|
||||||
import fr.xephi.authme.commands.CaptchaCommand;
|
|
||||||
import fr.xephi.authme.commands.ChangePasswordCommand;
|
|
||||||
import fr.xephi.authme.commands.ConverterCommand;
|
|
||||||
import fr.xephi.authme.commands.EmailCommand;
|
|
||||||
import fr.xephi.authme.commands.LoginCommand;
|
|
||||||
import fr.xephi.authme.commands.LogoutCommand;
|
|
||||||
import fr.xephi.authme.commands.RegisterCommand;
|
|
||||||
import fr.xephi.authme.commands.UnregisterCommand;
|
|
||||||
import fr.xephi.authme.converter.Converter;
|
import fr.xephi.authme.converter.Converter;
|
||||||
import fr.xephi.authme.converter.ForceFlatToSqlite;
|
import fr.xephi.authme.converter.ForceFlatToSqlite;
|
||||||
import fr.xephi.authme.datasource.CacheDataSource;
|
import fr.xephi.authme.datasource.CacheDataSource;
|
||||||
@ -68,15 +61,27 @@ import fr.xephi.authme.settings.Messages;
|
|||||||
import fr.xephi.authme.settings.OtherAccounts;
|
import fr.xephi.authme.settings.OtherAccounts;
|
||||||
import fr.xephi.authme.settings.Settings;
|
import fr.xephi.authme.settings.Settings;
|
||||||
import fr.xephi.authme.settings.Spawn;
|
import fr.xephi.authme.settings.Spawn;
|
||||||
|
import fr.xephi.authme.util.Utils;
|
||||||
import net.milkbowl.vault.permission.Permission;
|
import net.milkbowl.vault.permission.Permission;
|
||||||
import net.minelink.ctplus.CombatTagPlus;
|
import net.minelink.ctplus.CombatTagPlus;
|
||||||
|
|
||||||
public class AuthMe extends JavaPlugin {
|
public class AuthMe extends JavaPlugin {
|
||||||
|
|
||||||
|
/** Defines the name of the plugin. */
|
||||||
|
// TODO: Create a getter method for this constant, and make it private
|
||||||
|
public static final String PLUGIN_NAME = "AuthMeReloaded";
|
||||||
|
/** Defines the current AuthMeReloaded version name. */
|
||||||
|
private static final String PLUGIN_VERSION_NAME = "5.1-SNAPSHOT";
|
||||||
|
/** Defines the current AuthMeReloaded version code. */
|
||||||
|
private static final int PLUGIN_VERSION_CODE = 100; // Increase this number by one when an update is released
|
||||||
|
|
||||||
private static AuthMe authme;
|
private static AuthMe authme;
|
||||||
private static Server server;
|
private static Server server;
|
||||||
private Logger authmeLogger;
|
private Logger authmeLogger;
|
||||||
|
|
||||||
|
// TODO: Move this to a better place! -- timvisee
|
||||||
|
private CommandHandler commandHandler = null;
|
||||||
|
|
||||||
public Management management;
|
public Management management;
|
||||||
public NewAPI api;
|
public NewAPI api;
|
||||||
public SendMailSSL mail;
|
public SendMailSSL mail;
|
||||||
@ -109,7 +114,7 @@ public class AuthMe extends JavaPlugin {
|
|||||||
// In case we need to cache PlayerAuths, prevent connection before it's done
|
// In case we need to cache PlayerAuths, prevent connection before it's done
|
||||||
private boolean canConnect = true;
|
private boolean canConnect = true;
|
||||||
|
|
||||||
public boolean isCanConnect() {
|
public boolean canConnect() {
|
||||||
return canConnect;
|
return canConnect;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -140,6 +145,10 @@ public class AuthMe extends JavaPlugin {
|
|||||||
authmeLogger = Logger.getLogger("AuthMe");
|
authmeLogger = Logger.getLogger("AuthMe");
|
||||||
authme = this;
|
authme = this;
|
||||||
|
|
||||||
|
// Set up and initialize the command handler
|
||||||
|
this.commandHandler = new CommandHandler(false);
|
||||||
|
this.commandHandler.init();
|
||||||
|
|
||||||
// TODO: split the plugin in more modules
|
// TODO: split the plugin in more modules
|
||||||
moduleManager = new ModuleManager(this);
|
moduleManager = new ModuleManager(this);
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
@ -327,16 +336,17 @@ public class AuthMe extends JavaPlugin {
|
|||||||
pm.registerEvents(new AuthMeEntityListener(this), this);
|
pm.registerEvents(new AuthMeEntityListener(this), this);
|
||||||
pm.registerEvents(new AuthMeServerListener(this), this);
|
pm.registerEvents(new AuthMeServerListener(this), this);
|
||||||
|
|
||||||
|
// TODO: This is moved to CommandManager.registerCommands() handled by AuthMe.onCommand() -- timvisee
|
||||||
// Register commands
|
// Register commands
|
||||||
getCommand("authme").setExecutor(new AdminCommand(this));
|
//getCommand("authme").setExecutor(new AdminCommand(this));
|
||||||
getCommand("register").setExecutor(new RegisterCommand(this));
|
//getCommand("register").setExecutor(new RegisterCommand(this));
|
||||||
getCommand("login").setExecutor(new LoginCommand(this));
|
//getCommand("login").setExecutor(new LoginCommand(this));
|
||||||
getCommand("changepassword").setExecutor(new ChangePasswordCommand(this));
|
//getCommand("changepassword").setExecutor(new ChangePasswordCommand(this));
|
||||||
getCommand("logout").setExecutor(new LogoutCommand(this));
|
//getCommand("logout").setExecutor(new LogoutCommand(this));
|
||||||
getCommand("unregister").setExecutor(new UnregisterCommand(this));
|
//getCommand("unregister").setExecutor(new UnregisterCommand(this));
|
||||||
getCommand("email").setExecutor(new EmailCommand(this));
|
//getCommand("email").setExecutor(new EmailCommand(this));
|
||||||
getCommand("captcha").setExecutor(new CaptchaCommand(this));
|
//getCommand("captcha").setExecutor(new CaptchaCommand(this));
|
||||||
getCommand("converter").setExecutor(new ConverterCommand(this));
|
//getCommand("converter").setExecutor(new ConverterCommand(this));
|
||||||
|
|
||||||
// Purge on start if enabled
|
// Purge on start if enabled
|
||||||
autoPurge();
|
autoPurge();
|
||||||
@ -703,6 +713,10 @@ public class AuthMe extends JavaPlugin {
|
|||||||
Settings.switchAntiBotMod(mode);
|
Settings.switchAntiBotMod(mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean getAntiBotModMode() {
|
||||||
|
return this.antibotMod;
|
||||||
|
}
|
||||||
|
|
||||||
private void recallEmail() {
|
private void recallEmail() {
|
||||||
if (!Settings.recallEmail)
|
if (!Settings.recallEmail)
|
||||||
return;
|
return;
|
||||||
@ -808,4 +822,52 @@ public class AuthMe extends JavaPlugin {
|
|||||||
public String getCountryName(String ip) {
|
public String getCountryName(String ip) {
|
||||||
return Utils.getCountryName(ip);
|
return Utils.getCountryName(ip);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the command handler instance.
|
||||||
|
*
|
||||||
|
* @return Command handler.
|
||||||
|
*/
|
||||||
|
public CommandHandler getCommandHandler() {
|
||||||
|
return this.commandHandler;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle Bukkit commands.
|
||||||
|
*
|
||||||
|
* @param sender The command sender (Bukkit).
|
||||||
|
* @param cmd The command (Bukkit).
|
||||||
|
* @param commandLabel The command label (Bukkit).
|
||||||
|
* @param args The command arguments (Bukkit).
|
||||||
|
*
|
||||||
|
* @return True if the command was executed, false otherwise.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
|
||||||
|
// Get the command handler, and make sure it's valid
|
||||||
|
CommandHandler commandHandler = this.getCommandHandler();
|
||||||
|
if(commandHandler == null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// Handle the command, return the result
|
||||||
|
return commandHandler.onCommand(sender, cmd, commandLabel, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the current installed AuthMeReloaded version name.
|
||||||
|
*
|
||||||
|
* @return The version name of the currently installed AuthMeReloaded instance.
|
||||||
|
*/
|
||||||
|
public static String getVersionName() {
|
||||||
|
return PLUGIN_VERSION_NAME;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the current installed AuthMeReloaded version code.
|
||||||
|
*
|
||||||
|
* @return The version code of the currently installed AuthMeReloaded instance.
|
||||||
|
*/
|
||||||
|
public static int getVersionCode() {
|
||||||
|
return PLUGIN_VERSION_CODE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,9 @@
|
|||||||
package fr.xephi.authme;
|
package fr.xephi.authme;
|
||||||
|
|
||||||
|
import com.google.common.base.Throwables;
|
||||||
|
import fr.xephi.authme.api.NewAPI;
|
||||||
|
import fr.xephi.authme.settings.Settings;
|
||||||
|
|
||||||
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;
|
||||||
@ -8,39 +12,30 @@ import java.text.SimpleDateFormat;
|
|||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import com.google.common.base.Throwables;
|
|
||||||
|
|
||||||
import fr.xephi.authme.api.NewAPI;
|
|
||||||
import fr.xephi.authme.settings.Settings;
|
|
||||||
|
|
||||||
public class ConsoleLogger {
|
public class ConsoleLogger {
|
||||||
|
|
||||||
private static final Logger log = AuthMe.getInstance().getLogger();
|
private static final Logger log = AuthMe.getInstance().getLogger();
|
||||||
private static final DateFormat df = new SimpleDateFormat("[MM-dd HH:mm:ss]");
|
private static final DateFormat df = new SimpleDateFormat("[MM-dd HH:mm:ss]");
|
||||||
|
|
||||||
public static void info(String message) {
|
public static void info(String message) {
|
||||||
if (AuthMe.getInstance().isEnabled()) {
|
log.info("[AuthMe] " + message);
|
||||||
log.info("[AuthMe] " + message);
|
if (Settings.useLogging) {
|
||||||
if (Settings.useLogging) {
|
String dateTime;
|
||||||
String dateTime;
|
synchronized (df) {
|
||||||
synchronized (df) {
|
dateTime = df.format(new Date());
|
||||||
dateTime = df.format(new Date());
|
|
||||||
}
|
|
||||||
writeLog(dateTime + " " + message);
|
|
||||||
}
|
}
|
||||||
|
writeLog(dateTime + " " + message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void showError(String message) {
|
public static void showError(String message) {
|
||||||
if (AuthMe.getInstance().isEnabled()) {
|
log.warning("[AuthMe] " + message);
|
||||||
log.warning("[AuthMe] " + message);
|
if (Settings.useLogging) {
|
||||||
if (Settings.useLogging) {
|
String dateTime;
|
||||||
String dateTime;
|
synchronized (df) {
|
||||||
synchronized (df) {
|
dateTime = df.format(new Date());
|
||||||
dateTime = df.format(new Date());
|
|
||||||
}
|
|
||||||
writeLog(dateTime + " ERROR: " + message);
|
|
||||||
}
|
}
|
||||||
|
writeLog(dateTime + " ERROR: " + message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -54,10 +49,12 @@ public class ConsoleLogger {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void writeStackTrace(Exception ex) {
|
public static void writeStackTrace(Exception ex) {
|
||||||
String dateTime;
|
if (Settings.useLogging) {
|
||||||
synchronized (df) {
|
String dateTime;
|
||||||
dateTime = df.format(new Date());
|
synchronized (df) {
|
||||||
|
dateTime = df.format(new Date());
|
||||||
|
}
|
||||||
|
writeLog(dateTime + " " + Throwables.getStackTraceAsString(ex));
|
||||||
}
|
}
|
||||||
writeLog(dateTime + " " + Throwables.getStackTraceAsString(ex));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,6 +12,7 @@ import org.bukkit.OfflinePlayer;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import fr.xephi.authme.settings.Settings;
|
import fr.xephi.authme.settings.Settings;
|
||||||
|
import fr.xephi.authme.util.Utils;
|
||||||
import net.milkbowl.vault.permission.Permission;
|
import net.milkbowl.vault.permission.Permission;
|
||||||
|
|
||||||
public class DataManager {
|
public class DataManager {
|
||||||
|
|||||||
@ -112,10 +112,10 @@ public class SendMailSSL {
|
|||||||
if (file != null)
|
if (file != null)
|
||||||
file.delete();
|
file.delete();
|
||||||
|
|
||||||
} catch (RuntimeException e) {
|
} catch(Exception e) {
|
||||||
ConsoleLogger.showError("Some error occured while trying to send a email to " + mail);
|
// Print the stack trace
|
||||||
} catch (Exception e) {
|
e.printStackTrace();
|
||||||
ConsoleLogger.showError("Some error occured while trying to send a email to " + mail);
|
ConsoleLogger.showError("Some error occurred while trying to send a email to " + mail);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -9,11 +9,11 @@ import org.bukkit.inventory.ItemStack;
|
|||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
import fr.xephi.authme.AuthMe;
|
import fr.xephi.authme.AuthMe;
|
||||||
import fr.xephi.authme.Utils;
|
|
||||||
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;
|
||||||
|
|
||||||
public class API {
|
public class API {
|
||||||
|
|
||||||
|
|||||||
@ -9,11 +9,11 @@ import org.bukkit.entity.Player;
|
|||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
import fr.xephi.authme.AuthMe;
|
import fr.xephi.authme.AuthMe;
|
||||||
import fr.xephi.authme.Utils;
|
|
||||||
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;
|
||||||
|
|
||||||
public class NewAPI {
|
public class NewAPI {
|
||||||
|
|
||||||
|
|||||||
@ -19,8 +19,8 @@ import com.google.gson.JsonSerializationContext;
|
|||||||
import com.google.gson.JsonSerializer;
|
import com.google.gson.JsonSerializer;
|
||||||
|
|
||||||
import fr.xephi.authme.ConsoleLogger;
|
import fr.xephi.authme.ConsoleLogger;
|
||||||
import fr.xephi.authme.Utils;
|
|
||||||
import fr.xephi.authme.settings.Settings;
|
import fr.xephi.authme.settings.Settings;
|
||||||
|
import fr.xephi.authme.util.Utils;
|
||||||
|
|
||||||
public class JsonCache {
|
public class JsonCache {
|
||||||
|
|
||||||
|
|||||||
@ -0,0 +1,90 @@
|
|||||||
|
package fr.xephi.authme.command;
|
||||||
|
|
||||||
|
public class CommandArgumentDescription {
|
||||||
|
|
||||||
|
// TODO: Allow argument to consist of infinite parts. <label ...>
|
||||||
|
|
||||||
|
/** Argument label. */
|
||||||
|
private String label;
|
||||||
|
/** Argument description. */
|
||||||
|
private String description;
|
||||||
|
/** Defines whether the argument is optional. */
|
||||||
|
private boolean optional = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor.
|
||||||
|
*
|
||||||
|
* @param label The argument label.
|
||||||
|
* @param description The argument description.
|
||||||
|
*/
|
||||||
|
public CommandArgumentDescription(String label, String description) {
|
||||||
|
this(label, description, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor.
|
||||||
|
*
|
||||||
|
* @param label The argument label.
|
||||||
|
* @param description The argument description.
|
||||||
|
* @param optional True if the argument is optional, false otherwise.
|
||||||
|
*/
|
||||||
|
public CommandArgumentDescription(String label, String description, boolean optional) {
|
||||||
|
setLabel(label);
|
||||||
|
setDescription(description);
|
||||||
|
setOptional(optional);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the argument label.
|
||||||
|
*
|
||||||
|
* @return Argument label.
|
||||||
|
*/
|
||||||
|
public String getLabel() {
|
||||||
|
return this.label;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the argument label.
|
||||||
|
*
|
||||||
|
* @param label Argument label.
|
||||||
|
*/
|
||||||
|
public void setLabel(String label) {
|
||||||
|
this.label = label;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the argument description.
|
||||||
|
*
|
||||||
|
* @return Argument description.
|
||||||
|
*/
|
||||||
|
public String getDescription() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the argument description.
|
||||||
|
*
|
||||||
|
* @param description Argument description.
|
||||||
|
*/
|
||||||
|
public void setDescription(String description) {
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check whether the argument is optional.
|
||||||
|
*
|
||||||
|
* @return True if the argument is optional, false otherwise.
|
||||||
|
*/
|
||||||
|
public boolean isOptional() {
|
||||||
|
return optional;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set whether the argument is optional.
|
||||||
|
*
|
||||||
|
* @param optional True if the argument is optional, false otherwise.
|
||||||
|
*/
|
||||||
|
public void setOptional(boolean optional) {
|
||||||
|
this.optional = optional;
|
||||||
|
}
|
||||||
|
}
|
||||||
918
src/main/java/fr/xephi/authme/command/CommandDescription.java
Normal file
918
src/main/java/fr/xephi/authme/command/CommandDescription.java
Normal file
@ -0,0 +1,918 @@
|
|||||||
|
package fr.xephi.authme.command;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
|
import fr.xephi.authme.util.StringUtils;
|
||||||
|
|
||||||
|
public class CommandDescription {
|
||||||
|
|
||||||
|
/** Defines the acceptable labels. */
|
||||||
|
private List<String> labels = new ArrayList<>();
|
||||||
|
/** Command description. */
|
||||||
|
private String description = "";
|
||||||
|
/** Detailed description. */
|
||||||
|
private String detailedDescription = "";
|
||||||
|
/** The executable command instance. */
|
||||||
|
private ExecutableCommand executableCommand;
|
||||||
|
/** The parent command. */
|
||||||
|
private CommandDescription parent = null;
|
||||||
|
/** The child labels. */
|
||||||
|
private List<CommandDescription> children = new ArrayList<>();
|
||||||
|
/** The command arguments. */
|
||||||
|
private List<CommandArgumentDescription> arguments = new ArrayList<>();
|
||||||
|
/** Defines whether there is an argument maximum or not. */
|
||||||
|
private boolean noArgumentMaximum = false;
|
||||||
|
/** Defines the command permissions. */
|
||||||
|
private CommandPermissions permissions = new CommandPermissions();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor.
|
||||||
|
*
|
||||||
|
* @param executableCommand The executable command, or null.
|
||||||
|
* @param label Command label.
|
||||||
|
* @param description Command description.
|
||||||
|
* @param detailedDescription Detailed comment description.
|
||||||
|
* @param parent Parent command.
|
||||||
|
*/
|
||||||
|
public CommandDescription(ExecutableCommand executableCommand, String label, String description, String detailedDescription, CommandDescription parent) {
|
||||||
|
this(executableCommand, label, description, parent, detailedDescription, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor.
|
||||||
|
*
|
||||||
|
* @param executableCommand The executable command, or null.
|
||||||
|
* @param labels List of command labels.
|
||||||
|
* @param description Command description.
|
||||||
|
* @param detailedDescription Detailed comment description.
|
||||||
|
* @param parent Parent command.
|
||||||
|
*/
|
||||||
|
public CommandDescription(ExecutableCommand executableCommand, List<String> labels, String description, String detailedDescription, CommandDescription parent) {
|
||||||
|
this(executableCommand, labels, description, detailedDescription, parent, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor.
|
||||||
|
*
|
||||||
|
* @param executableCommand The executable command, or null.
|
||||||
|
* @param label Command label.
|
||||||
|
* @param description Command description.
|
||||||
|
* @param parent Parent command.
|
||||||
|
* @param detailedDescription Detailed comment description.
|
||||||
|
* @param arguments Command arguments.
|
||||||
|
*/
|
||||||
|
public CommandDescription(ExecutableCommand executableCommand, String label, String description, CommandDescription parent, String detailedDescription, List<CommandArgumentDescription> arguments) {
|
||||||
|
setExecutableCommand(executableCommand);
|
||||||
|
setLabel(label);
|
||||||
|
setDescription(description);
|
||||||
|
setDetailedDescription(detailedDescription);
|
||||||
|
setParent(parent);
|
||||||
|
setArguments(arguments);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor.
|
||||||
|
*
|
||||||
|
* @param executableCommand The executable command, or null.
|
||||||
|
* @param labels List of command labels.
|
||||||
|
* @param description Command description.
|
||||||
|
* @param detailedDescription Detailed comment description.
|
||||||
|
* @param parent Parent command.
|
||||||
|
* @param arguments Command arguments.
|
||||||
|
*/
|
||||||
|
public CommandDescription(ExecutableCommand executableCommand, List<String> labels, String description, String detailedDescription, CommandDescription parent, List<CommandArgumentDescription> arguments) {
|
||||||
|
setExecutableCommand(executableCommand);
|
||||||
|
setLabels(labels);
|
||||||
|
setDescription(description);
|
||||||
|
setDetailedDescription(detailedDescription);
|
||||||
|
setParent(parent);
|
||||||
|
setArguments(arguments);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the label most similar to the reference. The first label will be returned if no reference was supplied.
|
||||||
|
*
|
||||||
|
* @param reference The command reference.
|
||||||
|
*
|
||||||
|
* @return The most similar label, or the first label. An empty label will be returned if no label was set.
|
||||||
|
*/
|
||||||
|
public String getLabel(CommandParts reference) {
|
||||||
|
// Ensure there's any item in the command list
|
||||||
|
if(this.labels.size() == 0)
|
||||||
|
return "";
|
||||||
|
|
||||||
|
// Return the first label if we can't use the reference
|
||||||
|
if(reference == null)
|
||||||
|
return this.labels.get(0);
|
||||||
|
|
||||||
|
// Get the correct label from the reference
|
||||||
|
String preferred = reference.get(getParentCount());
|
||||||
|
|
||||||
|
// Check whether the preferred label is in the label list
|
||||||
|
double currentDifference = -1;
|
||||||
|
String currentLabel = this.labels.get(0);
|
||||||
|
for(String entry : this.labels) {
|
||||||
|
double entryDifference = StringUtils.getDifference(entry, preferred);
|
||||||
|
if(entryDifference < currentDifference || currentDifference < 0) {
|
||||||
|
currentDifference = entryDifference;
|
||||||
|
currentLabel = entry;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return the most similar label
|
||||||
|
return currentLabel;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all relative command labels.
|
||||||
|
*
|
||||||
|
* @return All relative labels labels.
|
||||||
|
*/
|
||||||
|
public List<String> getLabels() {
|
||||||
|
return this.labels;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the list of command labels.
|
||||||
|
*
|
||||||
|
* @param labels New list of command labels. Null to clear the list of labels.
|
||||||
|
*/
|
||||||
|
public void setLabels(List<String> labels) {
|
||||||
|
// Check whether the command label list should be cleared
|
||||||
|
if(labels == null)
|
||||||
|
this.labels.clear();
|
||||||
|
|
||||||
|
else
|
||||||
|
this.labels = labels;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
* @param commandLabel Command label to set.
|
||||||
|
* @param overwrite True to replace all old command labels, false to append this command label to the currently
|
||||||
|
* existing labels.
|
||||||
|
*
|
||||||
|
* @return Trie if the command label is added, or if it was added already. False on failure.
|
||||||
|
*/
|
||||||
|
public boolean setLabel(String commandLabel, boolean overwrite) {
|
||||||
|
// Check whether this new command should overwrite the previous ones
|
||||||
|
if(!overwrite)
|
||||||
|
return addLabel(commandLabel);
|
||||||
|
|
||||||
|
// Replace all labels with this new one
|
||||||
|
this.labels.clear();
|
||||||
|
return this.labels.add(commandLabel);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a command label to the list.
|
||||||
|
*
|
||||||
|
* @param commandLabel Command label to add.
|
||||||
|
*
|
||||||
|
* @return True if the label was added, or if it was added already. False on error.
|
||||||
|
*/
|
||||||
|
public boolean addLabel(String commandLabel) {
|
||||||
|
// Verify the label
|
||||||
|
if(!isValidLabel(commandLabel))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// Ensure this command isn't a duplicate
|
||||||
|
if(hasLabel(commandLabel))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
// Add the command to the list
|
||||||
|
return this.labels.add(commandLabel);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a list of command labels.
|
||||||
|
*
|
||||||
|
* @param commandLabels List of command labels to add.
|
||||||
|
*
|
||||||
|
* @return True if succeed, false on failure.
|
||||||
|
*/
|
||||||
|
public boolean addLabels(List<String> commandLabels) {
|
||||||
|
// Add each command label separately
|
||||||
|
for(String cmd : commandLabels)
|
||||||
|
if(!addLabel(cmd))
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check whether this command description has a specific command.
|
||||||
|
*
|
||||||
|
* @param commandLabel Command to check for.
|
||||||
|
*
|
||||||
|
* @return True if this command label equals to the param command.
|
||||||
|
*/
|
||||||
|
public boolean hasLabel(String commandLabel) {
|
||||||
|
// Check whether any command matches with the argument
|
||||||
|
for(String entry : this.labels)
|
||||||
|
if(commandLabelEquals(entry, commandLabel))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
// No match found, return false
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check whether this command description has a list of labels
|
||||||
|
* @param commandLabels List of labels
|
||||||
|
* @return True if all labels match, false otherwise
|
||||||
|
*/
|
||||||
|
public boolean hasLabels(List<String> commandLabels) {
|
||||||
|
// Check if there's a match for every command
|
||||||
|
for(String cmd : commandLabels)
|
||||||
|
if(!hasLabel(cmd))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// There seems to be a match for every command, return true
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check whether this command label is applicable with a command reference. This doesn't check if the parent
|
||||||
|
* are suitable too.
|
||||||
|
*
|
||||||
|
* @param commandReference The command reference.
|
||||||
|
*
|
||||||
|
* @return True if the command reference is suitable to this command label, false otherwise.
|
||||||
|
*/
|
||||||
|
public boolean isSuitableLabel(CommandParts commandReference) {
|
||||||
|
// Make sure the command reference is valid
|
||||||
|
if(commandReference.getCount() <= 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// Get the parent count
|
||||||
|
String element = commandReference.get(getParentCount());
|
||||||
|
|
||||||
|
// Check whether this command description has this command label
|
||||||
|
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.
|
||||||
|
*/
|
||||||
|
public String getAbsoluteLabel() {
|
||||||
|
return getAbsoluteLabel(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the absolute command label.
|
||||||
|
*
|
||||||
|
* @return Absolute command label.
|
||||||
|
*/
|
||||||
|
public String getAbsoluteLabel(boolean includeSlash) {
|
||||||
|
return getAbsoluteLabel(includeSlash, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the absolute command label.
|
||||||
|
*
|
||||||
|
* @return Absolute command label.
|
||||||
|
*/
|
||||||
|
public String getAbsoluteLabel(boolean includeSlash, CommandParts reference) {
|
||||||
|
// Get the command reference, and make sure it is valid
|
||||||
|
CommandParts out = getCommandReference(reference);
|
||||||
|
if(out == null)
|
||||||
|
return "";
|
||||||
|
|
||||||
|
// Return the result
|
||||||
|
return (includeSlash ? "/" : "") + out.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the command reference.
|
||||||
|
*
|
||||||
|
* @param reference The reference to use as template, which is used to choose the most similar reference.
|
||||||
|
*
|
||||||
|
* @return Command reference.
|
||||||
|
*/
|
||||||
|
public CommandParts getCommandReference(CommandParts reference) {
|
||||||
|
// Build the reference
|
||||||
|
List<String> referenceList = new ArrayList<>();
|
||||||
|
|
||||||
|
// Check whether this command has a parent, if so, add the absolute parent command
|
||||||
|
if(getParent() != null)
|
||||||
|
referenceList.addAll(getParent().getCommandReference(reference).getList());
|
||||||
|
|
||||||
|
// Get the current label
|
||||||
|
referenceList.add(getLabel(reference));
|
||||||
|
|
||||||
|
// Return the reference
|
||||||
|
return new CommandParts(referenceList);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the difference between this command and another command reference.
|
||||||
|
*
|
||||||
|
* @param other The other command reference.
|
||||||
|
*
|
||||||
|
* @return The command difference. Zero if there's no difference. A negative number on error.
|
||||||
|
*/
|
||||||
|
public double getCommandDifference(CommandParts other) {
|
||||||
|
return getCommandDifference(other, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the difference between this command and another command reference.
|
||||||
|
*
|
||||||
|
* @param other The other command reference.
|
||||||
|
* @param fullCompare True to fully compare both command references.
|
||||||
|
*
|
||||||
|
* @return The command difference. Zero if there's no difference. A negative number on error.
|
||||||
|
*/
|
||||||
|
public double getCommandDifference(CommandParts other, boolean fullCompare) {
|
||||||
|
// Make sure the reference is valid
|
||||||
|
if(other == null)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
// Get the command reference
|
||||||
|
CommandParts reference = getCommandReference(other);
|
||||||
|
|
||||||
|
// Compare the two references, return the result
|
||||||
|
return reference.getDifference(new CommandParts(other.getRange(0, reference.getCount())), fullCompare);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the executable command.
|
||||||
|
*
|
||||||
|
* @return The executable command.
|
||||||
|
*/
|
||||||
|
public ExecutableCommand getExecutableCommand() {
|
||||||
|
return this.executableCommand;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the executable command.
|
||||||
|
*
|
||||||
|
* @param executableCommand The executable command.
|
||||||
|
*/
|
||||||
|
public void setExecutableCommand(ExecutableCommand executableCommand) {
|
||||||
|
this.executableCommand = executableCommand;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check whether this command is executable, based on the assigned executable command.
|
||||||
|
*
|
||||||
|
* @return True if this command is executable.
|
||||||
|
*/
|
||||||
|
public boolean isExecutable() {
|
||||||
|
return this.executableCommand != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the command, if possible.
|
||||||
|
*
|
||||||
|
* @param sender The command sender that triggered the execution of this command.
|
||||||
|
* @param commandReference The command reference.
|
||||||
|
* @param commandArguments The command arguments.
|
||||||
|
*
|
||||||
|
* @return True on success, false on failure.
|
||||||
|
*/
|
||||||
|
public boolean execute(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
||||||
|
// Make sure the command is executable
|
||||||
|
if(!isExecutable())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// Execute the command, return the result
|
||||||
|
return getExecutableCommand().executeCommand(sender, commandReference, commandArguments);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the parent command if this command description has a parent.
|
||||||
|
*
|
||||||
|
* @return Parent command, or null
|
||||||
|
*/
|
||||||
|
public CommandDescription getParent() {
|
||||||
|
return this.parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the number of parent this description has.
|
||||||
|
*
|
||||||
|
* @return The number of parents.
|
||||||
|
*/
|
||||||
|
public int getParentCount() {
|
||||||
|
// Check whether the this description has a parent
|
||||||
|
if(!hasParent())
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
// Get the parent count of the parent, return the result
|
||||||
|
return getParent().getParentCount() + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the parent command.
|
||||||
|
*
|
||||||
|
* @param parent Parent command.
|
||||||
|
*
|
||||||
|
* @return True on success, false on failure.
|
||||||
|
*/
|
||||||
|
public boolean setParent(CommandDescription parent) {
|
||||||
|
// Make sure the parent is different
|
||||||
|
if(this.parent == parent)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
// Set the parent
|
||||||
|
this.parent = parent;
|
||||||
|
|
||||||
|
// Make sure the parent isn't null
|
||||||
|
if(parent == null)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
// Add this description as a child to the parent
|
||||||
|
return parent.addChild(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check whether the plugin description has a parent command.
|
||||||
|
*
|
||||||
|
* @return True if the description has a parent command, false otherwise.
|
||||||
|
*/
|
||||||
|
public boolean hasParent() {
|
||||||
|
return this.parent != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all command children.
|
||||||
|
*
|
||||||
|
* @return Command children.
|
||||||
|
*/
|
||||||
|
public List<CommandDescription> getChildren() {
|
||||||
|
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.
|
||||||
|
*
|
||||||
|
* @param children New command children. Null to remove all children.
|
||||||
|
*/
|
||||||
|
public void setChildren(List<CommandDescription> children) {
|
||||||
|
// Check whether the children list should be cleared
|
||||||
|
if(children == null)
|
||||||
|
this.children.clear();
|
||||||
|
|
||||||
|
else
|
||||||
|
this.children = children;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check whether this command has any child labels.
|
||||||
|
*
|
||||||
|
* @return True if this command has any child labels.
|
||||||
|
*/
|
||||||
|
public boolean hasChilds() {
|
||||||
|
return (this.children.size() != 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if this command description has a specific child.
|
||||||
|
*
|
||||||
|
* @param commandDescription The command description to check for.
|
||||||
|
*
|
||||||
|
* @return True if this command description has the specific child, false otherwise.
|
||||||
|
*/
|
||||||
|
public boolean isChild(CommandDescription commandDescription) {
|
||||||
|
// Make sure the description is valid
|
||||||
|
if(commandDescription == null)
|
||||||
|
return false;
|
||||||
|
if(!commandDescription.isValid())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// Check whether this child exists, return the result
|
||||||
|
return this.children.contains(commandDescription);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add an argument.
|
||||||
|
*
|
||||||
|
* @param argument The argument to add.
|
||||||
|
*
|
||||||
|
* @return True if succeed, false if failed.
|
||||||
|
*/
|
||||||
|
public boolean addArgument(CommandArgumentDescription argument) {
|
||||||
|
// Make sure the argument is valid
|
||||||
|
if(argument == null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// Make sure the argument isn't added already
|
||||||
|
if(hasArgument(argument))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
// Add the argument, return the result
|
||||||
|
return this.arguments.add(argument);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all command arguments.
|
||||||
|
*
|
||||||
|
* @return Command arguments.
|
||||||
|
*/
|
||||||
|
public List<CommandArgumentDescription> getArguments() {
|
||||||
|
return this.arguments;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the arguments of this command.
|
||||||
|
*
|
||||||
|
* @param arguments New command arguments. Null to clear the list of arguments.
|
||||||
|
*/
|
||||||
|
public void setArguments(List<CommandArgumentDescription> arguments) {
|
||||||
|
// Convert null into an empty argument list
|
||||||
|
if(arguments == null)
|
||||||
|
this.arguments.clear();
|
||||||
|
|
||||||
|
else
|
||||||
|
this.arguments = arguments;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check whether an argument exists.
|
||||||
|
*
|
||||||
|
* @param argument The argument to check for.
|
||||||
|
*
|
||||||
|
* @return True if this argument already exists, false otherwise.
|
||||||
|
*/
|
||||||
|
public boolean hasArgument(CommandArgumentDescription argument) {
|
||||||
|
// Make sure the argument is valid
|
||||||
|
if(argument == null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// Check whether the argument exists, return the result
|
||||||
|
return this.arguments.contains(argument);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check whether this command has any arguments.
|
||||||
|
*
|
||||||
|
* @return True if this command has any arguments.
|
||||||
|
*/
|
||||||
|
public boolean hasArguments() {
|
||||||
|
return (this.arguments.size() != 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The minimum number of arguments required for this command.
|
||||||
|
*
|
||||||
|
* @return The minimum number of required arguments.
|
||||||
|
*/
|
||||||
|
public int getMinimumArguments() {
|
||||||
|
// Get the number of required and optional arguments
|
||||||
|
int requiredArguments = 0;
|
||||||
|
int optionalArgument = 0;
|
||||||
|
|
||||||
|
// Loop through each argument
|
||||||
|
for(CommandArgumentDescription argument : this.arguments) {
|
||||||
|
// Check whether the command is optional
|
||||||
|
if(!argument.isOptional()) {
|
||||||
|
requiredArguments += optionalArgument + 1;
|
||||||
|
optionalArgument = 0;
|
||||||
|
|
||||||
|
} else
|
||||||
|
optionalArgument++;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return the number of required arguments
|
||||||
|
return requiredArguments;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the maximum number of arguments.
|
||||||
|
*
|
||||||
|
* @return The maximum number of arguments. A negative number will be returned if there's no maximum.
|
||||||
|
*/
|
||||||
|
public int getMaximumArguments() {
|
||||||
|
// Check whether there is a maximum set
|
||||||
|
if(this.noArgumentMaximum)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
// Return the maximum based on the registered arguments
|
||||||
|
return this.arguments.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set whether there is an argument maximum.
|
||||||
|
*
|
||||||
|
* @param maximumArguments True if there is an argument maximum, based on the number of registered arguments.
|
||||||
|
*/
|
||||||
|
public void setMaximumArguments(boolean maximumArguments) {
|
||||||
|
this.noArgumentMaximum = !maximumArguments;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the command description.
|
||||||
|
*
|
||||||
|
* @return Command description.
|
||||||
|
*/
|
||||||
|
public String getDescription() {
|
||||||
|
return hasDescription() ? this.description : this.detailedDescription;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the command description.
|
||||||
|
*
|
||||||
|
* @param description New command description. Null to reset the description.
|
||||||
|
*/
|
||||||
|
public void setDescription(String description) {
|
||||||
|
if(description == null)
|
||||||
|
this.description = "";
|
||||||
|
|
||||||
|
else
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check whether this command has any description.
|
||||||
|
*
|
||||||
|
* @return True if this command has any description.
|
||||||
|
*/
|
||||||
|
public boolean hasDescription() {
|
||||||
|
return (this.description.trim().length() != 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the command detailed description.
|
||||||
|
*
|
||||||
|
* @return Command detailed description.
|
||||||
|
*/
|
||||||
|
public String getDetailedDescription() {
|
||||||
|
return hasDetailedDescription() ? this.detailedDescription : this.description;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the command detailed description.
|
||||||
|
*
|
||||||
|
* @param detailedDescription New command description. Null to reset the description.
|
||||||
|
*/
|
||||||
|
public void setDetailedDescription(String detailedDescription) {
|
||||||
|
if(detailedDescription == null)
|
||||||
|
this.detailedDescription = "";
|
||||||
|
|
||||||
|
else
|
||||||
|
this.detailedDescription = detailedDescription;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check whether this command has any detailed description.
|
||||||
|
*
|
||||||
|
* @return True if this command has any detailed description.
|
||||||
|
*/
|
||||||
|
public boolean hasDetailedDescription() {
|
||||||
|
return (this.detailedDescription.trim().length() != 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find the best suitable command for a query reference.
|
||||||
|
*
|
||||||
|
* @param queryReference The query reference to find a command for.
|
||||||
|
*
|
||||||
|
* @return The command found, or null.
|
||||||
|
*/
|
||||||
|
public FoundCommandResult findCommand(final CommandParts queryReference) {
|
||||||
|
// Make sure the command reference is valid
|
||||||
|
if(queryReference.getCount() <= 0)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
// Check whether this description is for the last element in the command reference, if so return the current command
|
||||||
|
if(queryReference.getCount() <= getParentCount() + 1)
|
||||||
|
return new FoundCommandResult(
|
||||||
|
this,
|
||||||
|
getCommandReference(queryReference),
|
||||||
|
new CommandParts(),
|
||||||
|
queryReference);
|
||||||
|
|
||||||
|
// Get the new command reference and arguments
|
||||||
|
CommandParts newReference = new CommandParts(queryReference.getRange(0, getParentCount() + 1));
|
||||||
|
CommandParts newArguments = new CommandParts(queryReference.getRange(getParentCount() + 1));
|
||||||
|
|
||||||
|
// Handle the child's, if this command has any
|
||||||
|
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
|
||||||
|
List<CommandDescription> commandChildren = new ArrayList<>(getChildren());
|
||||||
|
Collections.sort(commandChildren, new Comparator<CommandDescription>() {
|
||||||
|
@Override
|
||||||
|
public int compare(CommandDescription o1, CommandDescription o2) {
|
||||||
|
return Double.compare(
|
||||||
|
o1.getCommandDifference(queryReference),
|
||||||
|
o2.getCommandDifference(queryReference));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Get the difference of the first child in the list
|
||||||
|
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
|
||||||
|
if(firstChildDifference > 0.0)
|
||||||
|
if(getSuitableArgumentsDifference(queryReference) == 0)
|
||||||
|
return new FoundCommandResult(this, newReference, newArguments, queryReference);
|
||||||
|
|
||||||
|
// Loop through each child
|
||||||
|
for(CommandDescription child : commandChildren) {
|
||||||
|
// Get the best suitable command
|
||||||
|
FoundCommandResult result = child.findCommand(queryReference);
|
||||||
|
if(result != null)
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if the remaining command reference elements fit the arguments for this command
|
||||||
|
if(getSuitableArgumentsDifference(queryReference) >= 0)
|
||||||
|
return new FoundCommandResult(this, newReference, newArguments, queryReference);
|
||||||
|
|
||||||
|
// No command found, return null
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check whether there's any command description that matches the specified command reference.
|
||||||
|
*
|
||||||
|
* @param commandReference The command reference.
|
||||||
|
*
|
||||||
|
* @return True if so, false otherwise.
|
||||||
|
*/
|
||||||
|
public boolean hasSuitableCommand(CommandParts commandReference) {
|
||||||
|
return findCommand(commandReference) != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the remaining command reference elements are suitable with arguments of the current command description.
|
||||||
|
*
|
||||||
|
* @param commandReference The command reference.
|
||||||
|
*
|
||||||
|
* @return True if the arguments are suitable, false otherwise.
|
||||||
|
*/
|
||||||
|
public boolean hasSuitableArguments(CommandParts commandReference) {
|
||||||
|
return getSuitableArgumentsDifference(commandReference) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the remaining command reference elements are suitable with arguments of the current command description,
|
||||||
|
* and get the difference in argument count.
|
||||||
|
*
|
||||||
|
* @param commandReference The command reference.
|
||||||
|
*
|
||||||
|
* @return The difference in argument count between the reference and the actual command.
|
||||||
|
*/
|
||||||
|
public int getSuitableArgumentsDifference(CommandParts commandReference) {
|
||||||
|
// Make sure the command reference is valid
|
||||||
|
if(commandReference.getCount() <= 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
// Get the remaining command reference element count
|
||||||
|
int remainingElementCount = commandReference.getCount() - getParentCount() - 1;
|
||||||
|
|
||||||
|
// Check if there are too less arguments
|
||||||
|
if(getMinimumArguments() > remainingElementCount)
|
||||||
|
return Math.abs(getMinimumArguments() - remainingElementCount);
|
||||||
|
|
||||||
|
// Check if there are too many arguments
|
||||||
|
if(getMaximumArguments() < remainingElementCount && getMaximumArguments() >= 0)
|
||||||
|
return Math.abs(remainingElementCount - getMaximumArguments());
|
||||||
|
|
||||||
|
// The arguments seem to be EQUALS, return the result
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the command permissions.
|
||||||
|
*
|
||||||
|
* @return The command permissions.
|
||||||
|
*/
|
||||||
|
public CommandPermissions getCommandPermissions() {
|
||||||
|
return this.permissions;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the command permissions.
|
||||||
|
*
|
||||||
|
* @param commandPermissions The command permissions.
|
||||||
|
*/
|
||||||
|
public void setCommandPermissions(CommandPermissions commandPermissions) {
|
||||||
|
this.permissions = commandPermissions;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the command permissions.
|
||||||
|
*
|
||||||
|
* @param permissionNode The permission node required.
|
||||||
|
* @param defaultPermission The default permission.
|
||||||
|
*/
|
||||||
|
public void setCommandPermissions(String permissionNode, CommandPermissions.DefaultPermission 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) {
|
||||||
|
// 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));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check whether the command description has been set up properly.
|
||||||
|
*
|
||||||
|
* @return True if the command description is valid, false otherwise.
|
||||||
|
*/
|
||||||
|
public boolean isValid() {
|
||||||
|
// Make sure any command label is set
|
||||||
|
if(getLabels().size() == 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// Make sure the permissions are set up properly
|
||||||
|
if(this.permissions == null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// Everything seems to be correct, return the result
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
207
src/main/java/fr/xephi/authme/command/CommandHandler.java
Normal file
207
src/main/java/fr/xephi/authme/command/CommandHandler.java
Normal file
@ -0,0 +1,207 @@
|
|||||||
|
package fr.xephi.authme.command;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
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 {
|
||||||
|
|
||||||
|
/** The command manager instance. */
|
||||||
|
private CommandManager commandManager;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor.
|
||||||
|
*
|
||||||
|
* @param init True to immediately initialize.
|
||||||
|
*/
|
||||||
|
public CommandHandler(boolean init) {
|
||||||
|
// Initialize
|
||||||
|
if(init)
|
||||||
|
init();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize the command handler.
|
||||||
|
*
|
||||||
|
* @return True if succeed, false on failure. True will also be returned if the command handler was already
|
||||||
|
* initialized.
|
||||||
|
*/
|
||||||
|
public boolean init() {
|
||||||
|
// Make sure the handler isn't initialized already
|
||||||
|
if(isInit())
|
||||||
|
return true;
|
||||||
|
|
||||||
|
// Initialize the command manager
|
||||||
|
this.commandManager = new CommandManager(false);
|
||||||
|
this.commandManager.registerCommands();
|
||||||
|
|
||||||
|
// Return the result
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check whether the command handler is initialized.
|
||||||
|
*
|
||||||
|
* @return True if the command handler is initialized.
|
||||||
|
*/
|
||||||
|
public boolean isInit() {
|
||||||
|
return this.commandManager != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Destroy the command handler.
|
||||||
|
*
|
||||||
|
* @return True if the command handler was destroyed successfully, false otherwise. True will also be returned if
|
||||||
|
* the command handler wasn't initialized.
|
||||||
|
*/
|
||||||
|
public boolean destroy() {
|
||||||
|
// Make sure the command handler is initialized
|
||||||
|
if(!isInit())
|
||||||
|
return true;
|
||||||
|
|
||||||
|
// Unset the command manager
|
||||||
|
this.commandManager = null;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the command manager.
|
||||||
|
*
|
||||||
|
* @return Command manager instance.
|
||||||
|
*/
|
||||||
|
public CommandManager getCommandManager() {
|
||||||
|
return this.commandManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Process a command.
|
||||||
|
*
|
||||||
|
* @param sender The command sender (Bukkit).
|
||||||
|
* @param bukkitCommand The command (Bukkit).
|
||||||
|
* @param bukkitCommandLabel The command label (Bukkit).
|
||||||
|
* @param bukkitArgs The command arguments (Bukkit).
|
||||||
|
*
|
||||||
|
* @return True if the command was executed, false otherwise.
|
||||||
|
*/
|
||||||
|
public boolean onCommand(CommandSender sender, org.bukkit.command.Command bukkitCommand, String bukkitCommandLabel, String[] bukkitArgs) {
|
||||||
|
// Process the arguments
|
||||||
|
List<String> args = processArguments(bukkitArgs);
|
||||||
|
|
||||||
|
// Create a command reference, and make sure at least one command part is available
|
||||||
|
CommandParts commandReference = new CommandParts(bukkitCommandLabel, args);
|
||||||
|
if(commandReference.getCount() == 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// Get a suitable command for this reference, and make sure it isn't null
|
||||||
|
FoundCommandResult result = this.commandManager.findCommand(commandReference);
|
||||||
|
if(result == null) {
|
||||||
|
sender.sendMessage(ChatColor.DARK_RED + "Failed to parse " + AuthMe.PLUGIN_NAME + " command!");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the base command
|
||||||
|
String baseCommand = commandReference.get(0);
|
||||||
|
|
||||||
|
// Make sure the difference between the command reference and the actual command isn't too big
|
||||||
|
final double commandDifference = result.getDifference();
|
||||||
|
if(commandDifference > 0.12) {
|
||||||
|
// Show the unknown command warning
|
||||||
|
sender.sendMessage(ChatColor.DARK_RED + "Unknown command!");
|
||||||
|
|
||||||
|
// Show a command suggestion if available and the difference isn't too big
|
||||||
|
if(commandDifference < 0.75)
|
||||||
|
if(result.getCommandDescription() != null)
|
||||||
|
sender.sendMessage(ChatColor.YELLOW + "Did you mean " + ChatColor.GOLD + "/" + result.getCommandDescription().getCommandReference(commandReference) + ChatColor.YELLOW + "?");
|
||||||
|
|
||||||
|
// Show the help command
|
||||||
|
sender.sendMessage(ChatColor.YELLOW + "Use the command " + ChatColor.GOLD + "/" + baseCommand + " help" + ChatColor.YELLOW + " to view help.");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Show a message when the command handler is assuming a command
|
||||||
|
if(commandDifference > 0) {
|
||||||
|
// Get the suggested command
|
||||||
|
CommandParts suggestedCommandParts = new CommandParts(result.getCommandDescription().getCommandReference(commandReference));
|
||||||
|
|
||||||
|
// Show the suggested command
|
||||||
|
sender.sendMessage(ChatColor.DARK_RED + "Unknown command, assuming " + ChatColor.GOLD + "/" + suggestedCommandParts +
|
||||||
|
ChatColor.DARK_RED + "!");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make sure the command is executable
|
||||||
|
if(!result.isExecutable()) {
|
||||||
|
// Get the command reference
|
||||||
|
CommandParts helpCommandReference = new CommandParts(result.getCommandReference().getRange(1));
|
||||||
|
|
||||||
|
// Show the unknown command warning
|
||||||
|
sender.sendMessage(ChatColor.DARK_RED + "Invalid command!");
|
||||||
|
|
||||||
|
// Show the help command
|
||||||
|
sender.sendMessage(ChatColor.YELLOW + "Use the command " + ChatColor.GOLD + "/" + baseCommand + " help " + helpCommandReference + ChatColor.YELLOW + " to view help.");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make sure the command sender has permission
|
||||||
|
if(!result.hasPermission(sender)) {
|
||||||
|
// Show the no permissions warning
|
||||||
|
sender.sendMessage(ChatColor.DARK_RED + "You don't have permission to use this command!");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make sure the command sender has permission
|
||||||
|
if(!result.hasProperArguments()) {
|
||||||
|
// Get the command and the suggested command reference
|
||||||
|
CommandParts suggestedCommandReference = new CommandParts(result.getCommandDescription().getCommandReference(commandReference));
|
||||||
|
CommandParts helpCommandReference = new CommandParts(suggestedCommandReference.getRange(1));
|
||||||
|
|
||||||
|
// Show the invalid arguments warning
|
||||||
|
sender.sendMessage(ChatColor.DARK_RED + "Incorrect command arguments!");
|
||||||
|
|
||||||
|
// Show the command argument help
|
||||||
|
HelpProvider.showHelp(sender, commandReference, suggestedCommandReference, true, false, true, false, false, false);
|
||||||
|
|
||||||
|
// Show the command to use for detailed help
|
||||||
|
sender.sendMessage(ChatColor.GOLD + "Detailed help: " + ChatColor.WHITE + "/" + baseCommand + " help " + helpCommandReference);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Execute the command if it's suitable
|
||||||
|
return result.executeCommand(sender);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Process the command arguments, and return them as an array list.
|
||||||
|
*
|
||||||
|
* @param args The command arguments to process.
|
||||||
|
*
|
||||||
|
* @return The processed command arguments.
|
||||||
|
*/
|
||||||
|
private List<String> processArguments(String[] args) {
|
||||||
|
// Convert the array into a list of arguments
|
||||||
|
List<String> arguments = new ArrayList<>(Arrays.asList(args));
|
||||||
|
|
||||||
|
/// Remove all empty arguments
|
||||||
|
for(int i = 0; i < arguments.size(); i++) {
|
||||||
|
// Get the argument value
|
||||||
|
final String arg = arguments.get(i);
|
||||||
|
|
||||||
|
// Check whether the argument value is empty
|
||||||
|
if(arg.trim().length() == 0) {
|
||||||
|
// Remove the current argument
|
||||||
|
arguments.remove(i);
|
||||||
|
|
||||||
|
// Decrease the index by one, continue to the next argument
|
||||||
|
i--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return the argument
|
||||||
|
return arguments;
|
||||||
|
}
|
||||||
|
}
|
||||||
682
src/main/java/fr/xephi/authme/command/CommandManager.java
Normal file
682
src/main/java/fr/xephi/authme/command/CommandManager.java
Normal file
@ -0,0 +1,682 @@
|
|||||||
|
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.authme.AccountsCommand;
|
||||||
|
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.converter.ConverterCommand;
|
||||||
|
import fr.xephi.authme.command.executable.email.AddEmailCommand;
|
||||||
|
import fr.xephi.authme.command.executable.email.ChangeEmailCommand;
|
||||||
|
import fr.xephi.authme.command.executable.email.RecoverEmailCommand;
|
||||||
|
import fr.xephi.authme.command.executable.login.LoginCommand;
|
||||||
|
import fr.xephi.authme.command.executable.logout.LogoutCommand;
|
||||||
|
|
||||||
|
public class CommandManager {
|
||||||
|
|
||||||
|
/** The list of commandDescriptions. */
|
||||||
|
private List<CommandDescription> commandDescriptions = new ArrayList<>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor.
|
||||||
|
*
|
||||||
|
* @param registerCommands True to register the commands, false otherwise.
|
||||||
|
*/
|
||||||
|
public CommandManager(boolean registerCommands) {
|
||||||
|
// Register the commands
|
||||||
|
if(registerCommands)
|
||||||
|
registerCommands();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register all commands.
|
||||||
|
*/
|
||||||
|
@SuppressWarnings({ "serial" })
|
||||||
|
public void registerCommands() {
|
||||||
|
// Register the base AuthMe Reloaded command
|
||||||
|
CommandDescription authMeBaseCommand = new CommandDescription(
|
||||||
|
new AuthMeCommand(),
|
||||||
|
new ArrayList<String>() {{
|
||||||
|
add("authme");
|
||||||
|
}},
|
||||||
|
"Main command",
|
||||||
|
"The main AuthMeReloaded command. The root for all admin commands.", null);
|
||||||
|
|
||||||
|
// Register the help command
|
||||||
|
CommandDescription authMeHelpCommand = new CommandDescription(
|
||||||
|
new HelpCommand(),
|
||||||
|
new ArrayList<String>() {{
|
||||||
|
add("help");
|
||||||
|
add("hlp");
|
||||||
|
add("h");
|
||||||
|
add("sos");
|
||||||
|
add("?");
|
||||||
|
}},
|
||||||
|
"View help",
|
||||||
|
"View detailed help pages about AuthMeReloaded commands.",
|
||||||
|
authMeBaseCommand);
|
||||||
|
authMeHelpCommand.addArgument(new CommandArgumentDescription("query", "The command or query to view help for.", true));
|
||||||
|
authMeHelpCommand.setMaximumArguments(false);
|
||||||
|
|
||||||
|
// Register the register command
|
||||||
|
CommandDescription registerCommand = new CommandDescription(
|
||||||
|
new RegisterCommand(),
|
||||||
|
new ArrayList<String>() {{
|
||||||
|
add("register");
|
||||||
|
add("reg");
|
||||||
|
add("r");
|
||||||
|
}},
|
||||||
|
"Register a player",
|
||||||
|
"Register the specified player with the specified password.",
|
||||||
|
authMeBaseCommand);
|
||||||
|
registerCommand.setCommandPermissions("authme.admin.register", CommandPermissions.DefaultPermission.OP_ONLY);
|
||||||
|
registerCommand.addArgument(new CommandArgumentDescription("player", "Player name", false));
|
||||||
|
registerCommand.addArgument(new CommandArgumentDescription("password", "Password", false));
|
||||||
|
|
||||||
|
// Register the unregister command
|
||||||
|
CommandDescription unregisterCommand = new CommandDescription(
|
||||||
|
new UnregisterCommand(),
|
||||||
|
new ArrayList<String>() {{
|
||||||
|
add("unregister");
|
||||||
|
add("unreg");
|
||||||
|
add("unr");
|
||||||
|
add("delete");
|
||||||
|
add("del");
|
||||||
|
}},
|
||||||
|
"Unregister a player",
|
||||||
|
"Unregister the specified player.",
|
||||||
|
authMeBaseCommand);
|
||||||
|
unregisterCommand.setCommandPermissions("authme.admin.unregister", CommandPermissions.DefaultPermission.OP_ONLY);
|
||||||
|
unregisterCommand.addArgument(new CommandArgumentDescription("player", "Player name", false));
|
||||||
|
|
||||||
|
// Register the forcelogin command
|
||||||
|
CommandDescription forceLoginCommand = new CommandDescription(
|
||||||
|
new ForceLoginCommand(),
|
||||||
|
new ArrayList<String>() {{
|
||||||
|
add("forcelogin");
|
||||||
|
add("login");
|
||||||
|
}},
|
||||||
|
"Enforce login player",
|
||||||
|
"Enforce the specified player to login.",
|
||||||
|
authMeBaseCommand);
|
||||||
|
forceLoginCommand.setCommandPermissions("authme.admin.forcelogin", CommandPermissions.DefaultPermission.OP_ONLY);
|
||||||
|
forceLoginCommand.addArgument(new CommandArgumentDescription("player", "Online player name", true));
|
||||||
|
|
||||||
|
// Register the changepassword command
|
||||||
|
CommandDescription changePasswordCommand = new CommandDescription(
|
||||||
|
new ChangePasswordCommand(),
|
||||||
|
new ArrayList<String>() {{
|
||||||
|
add("password");
|
||||||
|
add("changepassword");
|
||||||
|
add("changepass");
|
||||||
|
add("cp");
|
||||||
|
}},
|
||||||
|
"Change player's password",
|
||||||
|
"Change the password of a player.",
|
||||||
|
authMeBaseCommand);
|
||||||
|
changePasswordCommand.setCommandPermissions("authme.admin.changepassword", CommandPermissions.DefaultPermission.OP_ONLY);
|
||||||
|
changePasswordCommand.addArgument(new CommandArgumentDescription("player", "Player name", false));
|
||||||
|
changePasswordCommand.addArgument(new CommandArgumentDescription("pwd", "New password", false));
|
||||||
|
|
||||||
|
// Register the purge command
|
||||||
|
CommandDescription lastLoginCommand = new CommandDescription(
|
||||||
|
new LastLoginCommand(),
|
||||||
|
new ArrayList<String>() {{
|
||||||
|
add("lastlogin");
|
||||||
|
add("ll");
|
||||||
|
}},
|
||||||
|
"Player's last login",
|
||||||
|
"View the date of the specified players last login",
|
||||||
|
authMeBaseCommand);
|
||||||
|
lastLoginCommand.setCommandPermissions("authme.admin.lastlogin", CommandPermissions.DefaultPermission.OP_ONLY);
|
||||||
|
lastLoginCommand.addArgument(new CommandArgumentDescription("player", "Player name", true));
|
||||||
|
|
||||||
|
// Register the accounts command
|
||||||
|
CommandDescription accountsCommand = new CommandDescription(
|
||||||
|
new AccountsCommand(),
|
||||||
|
new ArrayList<String>() {{
|
||||||
|
add("accounts");
|
||||||
|
add("account");
|
||||||
|
}},
|
||||||
|
"Display player accounts",
|
||||||
|
"Display all accounts of a player by it's player name or IP.",
|
||||||
|
authMeBaseCommand);
|
||||||
|
accountsCommand.setCommandPermissions("authme.admin.accounts", CommandPermissions.DefaultPermission.OP_ONLY);
|
||||||
|
accountsCommand.addArgument(new CommandArgumentDescription("player", "Player name or IP", true));
|
||||||
|
|
||||||
|
// Register the getemail command
|
||||||
|
CommandDescription getEmailCommand = new CommandDescription(
|
||||||
|
new GetEmailCommand(),
|
||||||
|
new ArrayList<String>() {{
|
||||||
|
add("getemail");
|
||||||
|
add("getmail");
|
||||||
|
add("email");
|
||||||
|
add("mail");
|
||||||
|
}},
|
||||||
|
"Display player's email",
|
||||||
|
"Display the email address of the specified player if set.",
|
||||||
|
authMeBaseCommand);
|
||||||
|
getEmailCommand.setCommandPermissions("authme.admin.getemail", CommandPermissions.DefaultPermission.OP_ONLY);
|
||||||
|
getEmailCommand.addArgument(new CommandArgumentDescription("player", "Player name", true));
|
||||||
|
|
||||||
|
// Register the setemail command
|
||||||
|
CommandDescription setEmailCommand = new CommandDescription(
|
||||||
|
new SetEmailCommand(),
|
||||||
|
new ArrayList<String>() {{
|
||||||
|
add("chgemail");
|
||||||
|
add("chgmail");
|
||||||
|
add("setemail");
|
||||||
|
add("setmail");
|
||||||
|
}},
|
||||||
|
"Change player's email",
|
||||||
|
"Change the email address of the specified player.",
|
||||||
|
authMeBaseCommand);
|
||||||
|
setEmailCommand.setCommandPermissions("authme.admin.chgemail", CommandPermissions.DefaultPermission.OP_ONLY);
|
||||||
|
setEmailCommand.addArgument(new CommandArgumentDescription("player", "Player name", false));
|
||||||
|
setEmailCommand.addArgument(new CommandArgumentDescription("email", "Player email", false));
|
||||||
|
|
||||||
|
// Register the getip command
|
||||||
|
CommandDescription getIpCommand = new CommandDescription(
|
||||||
|
new GetIpCommand(),
|
||||||
|
new ArrayList<String>() {{
|
||||||
|
add("getip");
|
||||||
|
add("ip");
|
||||||
|
}},
|
||||||
|
"Get player's IP",
|
||||||
|
"Get the IP address of the specified online player.",
|
||||||
|
authMeBaseCommand);
|
||||||
|
getIpCommand.setCommandPermissions("authme.admin.getip", CommandPermissions.DefaultPermission.OP_ONLY);
|
||||||
|
getIpCommand.addArgument(new CommandArgumentDescription("player", "Online player name", true));
|
||||||
|
|
||||||
|
// Register the spawn command
|
||||||
|
CommandDescription spawnCommand = new CommandDescription(
|
||||||
|
new SpawnCommand(),
|
||||||
|
new ArrayList<String>() {{
|
||||||
|
add("spawn");
|
||||||
|
add("home");
|
||||||
|
}},
|
||||||
|
"Teleport to spawn",
|
||||||
|
"Teleport to the spawn.",
|
||||||
|
authMeBaseCommand);
|
||||||
|
spawnCommand.setCommandPermissions("authme.admin.spawn", CommandPermissions.DefaultPermission.OP_ONLY);
|
||||||
|
|
||||||
|
// Register the setspawn command
|
||||||
|
CommandDescription setSpawnCommand = new CommandDescription(
|
||||||
|
new SetSpawnCommand(),
|
||||||
|
new ArrayList<String>() {{
|
||||||
|
add("setspawn");
|
||||||
|
add("chgspawn");
|
||||||
|
}},
|
||||||
|
"Change the spawn",
|
||||||
|
"Change the player's spawn to your current position.",
|
||||||
|
authMeBaseCommand);
|
||||||
|
setSpawnCommand.setCommandPermissions("authme.admin.setspawn", CommandPermissions.DefaultPermission.OP_ONLY);
|
||||||
|
|
||||||
|
// Register the firstspawn command
|
||||||
|
CommandDescription firstSpawnCommand = new CommandDescription(
|
||||||
|
new FirstSpawnCommand(),
|
||||||
|
new ArrayList<String>() {{
|
||||||
|
add("firstspawn");
|
||||||
|
add("firsthome");
|
||||||
|
}},
|
||||||
|
"Teleport to first spawn",
|
||||||
|
"Teleport to the first spawn.",
|
||||||
|
authMeBaseCommand);
|
||||||
|
firstSpawnCommand.setCommandPermissions("authme.admin.firstspawn", CommandPermissions.DefaultPermission.OP_ONLY);
|
||||||
|
|
||||||
|
// Register the setfirstspawn command
|
||||||
|
CommandDescription setFirstSpawnCommand = new CommandDescription(
|
||||||
|
new SetFirstSpawnCommand(),
|
||||||
|
new ArrayList<String>() {{
|
||||||
|
add("setfirstspawn");
|
||||||
|
add("chgfirstspawn");
|
||||||
|
}},
|
||||||
|
"Change the first spawn",
|
||||||
|
"Change the first player's spawn to your current position.",
|
||||||
|
authMeBaseCommand);
|
||||||
|
setFirstSpawnCommand.setCommandPermissions("authme.admin.setfirstspawn", CommandPermissions.DefaultPermission.OP_ONLY);
|
||||||
|
|
||||||
|
// Register the purge command
|
||||||
|
CommandDescription purgeCommand = new CommandDescription(
|
||||||
|
new PurgeCommand(),
|
||||||
|
new ArrayList<String>() {{
|
||||||
|
add("purge");
|
||||||
|
add("delete");
|
||||||
|
}},
|
||||||
|
"Purge old data",
|
||||||
|
"Purge old AuthMeReloaded data longer than the specified amount of days ago.",
|
||||||
|
authMeBaseCommand);
|
||||||
|
purgeCommand.setCommandPermissions("authme.admin.purge", CommandPermissions.DefaultPermission.OP_ONLY);
|
||||||
|
purgeCommand.addArgument(new CommandArgumentDescription("days", "Number of days", false));
|
||||||
|
|
||||||
|
// Register the purgelastposition command
|
||||||
|
CommandDescription purgeLastPositionCommand = new CommandDescription(
|
||||||
|
new PurgeLastPositionCommand(),
|
||||||
|
new ArrayList<String>() {{
|
||||||
|
add("resetpos");
|
||||||
|
add("purgelastposition");
|
||||||
|
add("purgelastpos");
|
||||||
|
add("resetposition");
|
||||||
|
add("resetlastposition");
|
||||||
|
add("resetlastpos");
|
||||||
|
}},
|
||||||
|
"Purge player's last position",
|
||||||
|
"Purge the last know position of the specified player.",
|
||||||
|
authMeBaseCommand);
|
||||||
|
purgeLastPositionCommand.setCommandPermissions("authme.admin.purgelastpos", CommandPermissions.DefaultPermission.OP_ONLY);
|
||||||
|
purgeLastPositionCommand.addArgument(new CommandArgumentDescription("player", "Player name", true));
|
||||||
|
|
||||||
|
// Register the purgebannedplayers command
|
||||||
|
CommandDescription purgeBannedPlayersCommand = new CommandDescription(
|
||||||
|
new PurgeBannedPlayersCommand(),
|
||||||
|
new ArrayList<String>() {{
|
||||||
|
add("purgebannedplayers");
|
||||||
|
add("purgebannedplayer");
|
||||||
|
add("deletebannedplayers");
|
||||||
|
add("deletebannedplayer");
|
||||||
|
}},
|
||||||
|
"Purge banned palyers data",
|
||||||
|
"Purge all AuthMeReloaded data for banned players.",
|
||||||
|
authMeBaseCommand);
|
||||||
|
purgeBannedPlayersCommand.setCommandPermissions("authme.admin.purgebannedplayers", CommandPermissions.DefaultPermission.OP_ONLY);
|
||||||
|
|
||||||
|
// Register the switchantibot command
|
||||||
|
CommandDescription switchAntiBotCommand = new CommandDescription(
|
||||||
|
new SwitchAntiBotCommand(),
|
||||||
|
new ArrayList<String>() {{
|
||||||
|
add("switchantibot");
|
||||||
|
add("toggleantibot");
|
||||||
|
add("antibot");
|
||||||
|
}},
|
||||||
|
"Switch AntiBot mode",
|
||||||
|
"Switch or toggle the AntiBot mode to the specified state.",
|
||||||
|
authMeBaseCommand);
|
||||||
|
switchAntiBotCommand.setCommandPermissions("authme.admin.switchantibot", CommandPermissions.DefaultPermission.OP_ONLY);
|
||||||
|
switchAntiBotCommand.addArgument(new CommandArgumentDescription("mode", "ON / OFF", true));
|
||||||
|
|
||||||
|
// // Register the resetname command
|
||||||
|
// CommandDescription resetNameCommand = new CommandDescription(
|
||||||
|
// new ResetNameCommand(),
|
||||||
|
// new ArrayList<String>() {{
|
||||||
|
// add("resetname");
|
||||||
|
// add("resetnames");
|
||||||
|
// }},
|
||||||
|
// "Reset name",
|
||||||
|
// "Reset name",
|
||||||
|
// authMeCommand);
|
||||||
|
// resetNameCommand.setCommandPermissions("authme.admin.resetname", CommandPermissions.DefaultPermission.OP_ONLY);
|
||||||
|
|
||||||
|
// Register the reload command
|
||||||
|
CommandDescription reloadCommand = new CommandDescription(
|
||||||
|
new ReloadCommand(),
|
||||||
|
new ArrayList<String>() {{
|
||||||
|
add("reload");
|
||||||
|
add("rld");
|
||||||
|
}},
|
||||||
|
"Reload plugin",
|
||||||
|
"Reload the AuthMeReloaded plugin.",
|
||||||
|
authMeBaseCommand);
|
||||||
|
reloadCommand.setCommandPermissions("authme.admin.reload", CommandPermissions.DefaultPermission.OP_ONLY);
|
||||||
|
|
||||||
|
// Register the version command
|
||||||
|
CommandDescription versionCommand = new CommandDescription(
|
||||||
|
new VersionCommand(),
|
||||||
|
new ArrayList<String>() {{
|
||||||
|
add("version");
|
||||||
|
add("ver");
|
||||||
|
add("v");
|
||||||
|
add("about");
|
||||||
|
add("info");
|
||||||
|
}},
|
||||||
|
"Version info",
|
||||||
|
"Show detailed information about the installed AuthMeReloaded version, and shows the developers, contributors, license and other information.",
|
||||||
|
authMeBaseCommand);
|
||||||
|
versionCommand.setMaximumArguments(false);
|
||||||
|
|
||||||
|
// Register the base Dungeon Maze command
|
||||||
|
CommandDescription loginBaseCommand = new CommandDescription(
|
||||||
|
new LoginCommand(),
|
||||||
|
new ArrayList<String>() {{
|
||||||
|
add("login");
|
||||||
|
}},
|
||||||
|
"Login command",
|
||||||
|
"Command to login using AuthMeReloaded.", null);
|
||||||
|
loginBaseCommand.setCommandPermissions("authme.login", CommandPermissions.DefaultPermission.ALLOWED);
|
||||||
|
loginBaseCommand.addArgument(new CommandArgumentDescription("password", "Login password", false));
|
||||||
|
|
||||||
|
// Register the help command
|
||||||
|
CommandDescription loginHelpCommand = new CommandDescription(
|
||||||
|
new HelpCommand(),
|
||||||
|
new ArrayList<String>() {{
|
||||||
|
add("help");
|
||||||
|
add("hlp");
|
||||||
|
add("h");
|
||||||
|
add("sos");
|
||||||
|
add("?");
|
||||||
|
}},
|
||||||
|
"View help",
|
||||||
|
"View detailed help pages about AuthMeReloaded login commands.",
|
||||||
|
loginBaseCommand);
|
||||||
|
loginHelpCommand.addArgument(new CommandArgumentDescription("query", "The command or query to view help for.", true));
|
||||||
|
loginHelpCommand.setMaximumArguments(false);
|
||||||
|
|
||||||
|
// Register the base logout command
|
||||||
|
CommandDescription logoutBaseCommand = new CommandDescription(
|
||||||
|
new LogoutCommand(),
|
||||||
|
new ArrayList<String>() {{
|
||||||
|
add("logout");
|
||||||
|
}},
|
||||||
|
"Logout command",
|
||||||
|
"Command to logout using AuthMeReloaded.", null);
|
||||||
|
logoutBaseCommand.setCommandPermissions("authme.logout", CommandPermissions.DefaultPermission.ALLOWED);
|
||||||
|
|
||||||
|
// Register the help command
|
||||||
|
CommandDescription logoutHelpCommand = new CommandDescription(
|
||||||
|
new HelpCommand(),
|
||||||
|
new ArrayList<String>() {{
|
||||||
|
add("help");
|
||||||
|
add("hlp");
|
||||||
|
add("h");
|
||||||
|
add("sos");
|
||||||
|
add("?");
|
||||||
|
}},
|
||||||
|
"View help",
|
||||||
|
"View detailed help pages about AuthMeReloaded logout commands.",
|
||||||
|
logoutBaseCommand);
|
||||||
|
logoutHelpCommand.addArgument(new CommandArgumentDescription("query", "The command or query to view help for.", true));
|
||||||
|
logoutHelpCommand.setMaximumArguments(false);
|
||||||
|
|
||||||
|
// Register the base register command
|
||||||
|
CommandDescription registerBaseCommand = new CommandDescription(
|
||||||
|
new fr.xephi.authme.command.executable.register.RegisterCommand(),
|
||||||
|
new ArrayList<String>() {{
|
||||||
|
add("register");
|
||||||
|
add("reg");
|
||||||
|
}},
|
||||||
|
"Registration command",
|
||||||
|
"Command to register using AuthMeReloaded.", null);
|
||||||
|
registerBaseCommand.setCommandPermissions("authme.register", CommandPermissions.DefaultPermission.ALLOWED);
|
||||||
|
registerBaseCommand.addArgument(new CommandArgumentDescription("password", "Password", false));
|
||||||
|
registerBaseCommand.addArgument(new CommandArgumentDescription("verifyPassword", "Verify password", false));
|
||||||
|
registerBaseCommand.setMaximumArguments(false);
|
||||||
|
|
||||||
|
// Register the help command
|
||||||
|
CommandDescription registerHelpCommand = new CommandDescription(
|
||||||
|
new HelpCommand(),
|
||||||
|
new ArrayList<String>() {{
|
||||||
|
add("help");
|
||||||
|
add("hlp");
|
||||||
|
add("h");
|
||||||
|
add("sos");
|
||||||
|
add("?");
|
||||||
|
}},
|
||||||
|
"View help",
|
||||||
|
"View detailed help pages about AuthMeReloaded register commands.",
|
||||||
|
registerBaseCommand);
|
||||||
|
registerHelpCommand.addArgument(new CommandArgumentDescription("query", "The command or query to view help for.", true));
|
||||||
|
registerHelpCommand.setMaximumArguments(false);
|
||||||
|
|
||||||
|
// Register the base unregister command
|
||||||
|
CommandDescription unregisterBaseCommand = new CommandDescription(
|
||||||
|
new fr.xephi.authme.command.executable.unregister.UnregisterCommand(),
|
||||||
|
new ArrayList<String>() {{
|
||||||
|
add("unregister");
|
||||||
|
add("unreg");
|
||||||
|
}},
|
||||||
|
"Unregistration command",
|
||||||
|
"Command to unregister using AuthMeReloaded.", null);
|
||||||
|
unregisterBaseCommand.setCommandPermissions("authme.unregister", CommandPermissions.DefaultPermission.ALLOWED);
|
||||||
|
unregisterBaseCommand.addArgument(new CommandArgumentDescription("password", "Password", false));
|
||||||
|
|
||||||
|
// Register the help command
|
||||||
|
CommandDescription unregisterHelpCommand = new CommandDescription(
|
||||||
|
new HelpCommand(),
|
||||||
|
new ArrayList<String>() {{
|
||||||
|
add("help");
|
||||||
|
add("hlp");
|
||||||
|
add("h");
|
||||||
|
add("sos");
|
||||||
|
add("?");
|
||||||
|
}},
|
||||||
|
"View help",
|
||||||
|
"View detailed help pages about AuthMeReloaded unregister commands.",
|
||||||
|
unregisterBaseCommand);
|
||||||
|
unregisterHelpCommand.addArgument(new CommandArgumentDescription("query", "The command or query to view help for.", true));
|
||||||
|
unregisterHelpCommand.setMaximumArguments(false);
|
||||||
|
|
||||||
|
// Register the base changepassword command
|
||||||
|
CommandDescription changePasswordBaseCommand = new CommandDescription(
|
||||||
|
new fr.xephi.authme.command.executable.changepassword.ChangePasswordCommand(),
|
||||||
|
new ArrayList<String>() {{
|
||||||
|
add("changepassword");
|
||||||
|
add("changepass");
|
||||||
|
}},
|
||||||
|
"Change password command",
|
||||||
|
"Command to change your password using AuthMeReloaded.", null);
|
||||||
|
changePasswordBaseCommand.setCommandPermissions("authme.changepassword", CommandPermissions.DefaultPermission.ALLOWED);
|
||||||
|
changePasswordBaseCommand.addArgument(new CommandArgumentDescription("password", "Password", false));
|
||||||
|
changePasswordBaseCommand.addArgument(new CommandArgumentDescription("verifyPassword", "Verify password", false));
|
||||||
|
changePasswordBaseCommand.setMaximumArguments(false);
|
||||||
|
|
||||||
|
// Register the help command
|
||||||
|
CommandDescription changePasswordHelpCommand = new CommandDescription(
|
||||||
|
new HelpCommand(),
|
||||||
|
new ArrayList<String>() {{
|
||||||
|
add("help");
|
||||||
|
add("hlp");
|
||||||
|
add("h");
|
||||||
|
add("sos");
|
||||||
|
add("?");
|
||||||
|
}},
|
||||||
|
"View help",
|
||||||
|
"View detailed help pages about AuthMeReloaded change password commands.",
|
||||||
|
changePasswordBaseCommand);
|
||||||
|
changePasswordHelpCommand.addArgument(new CommandArgumentDescription("query", "The command or query to view help for.", true));
|
||||||
|
changePasswordHelpCommand.setMaximumArguments(false);
|
||||||
|
|
||||||
|
// Register the base Dungeon Maze command
|
||||||
|
CommandDescription emailBaseCommand = new CommandDescription(
|
||||||
|
new HelpCommand(),
|
||||||
|
new ArrayList<String>() {{
|
||||||
|
add("email");
|
||||||
|
add("mail");
|
||||||
|
}},
|
||||||
|
"E-mail command",
|
||||||
|
"The AuthMe Reloaded E-mail command. The root for all E-mail commands.", null);
|
||||||
|
|
||||||
|
// Register the help command
|
||||||
|
CommandDescription emailHelpCommand = new CommandDescription(
|
||||||
|
new HelpCommand(),
|
||||||
|
new ArrayList<String>() {{
|
||||||
|
add("help");
|
||||||
|
add("hlp");
|
||||||
|
add("h");
|
||||||
|
add("sos");
|
||||||
|
add("?");
|
||||||
|
}},
|
||||||
|
"View help",
|
||||||
|
"View detailed help pages about AuthMeReloaded help commands.",
|
||||||
|
emailBaseCommand);
|
||||||
|
emailHelpCommand.addArgument(new CommandArgumentDescription("query", "The command or query to view help for.", true));
|
||||||
|
emailHelpCommand.setMaximumArguments(false);
|
||||||
|
|
||||||
|
// Register the add command
|
||||||
|
CommandDescription addEmailCommand = new CommandDescription(
|
||||||
|
new AddEmailCommand(),
|
||||||
|
new ArrayList<String>() {{
|
||||||
|
add("add");
|
||||||
|
add("addemail");
|
||||||
|
add("addmail");
|
||||||
|
}},
|
||||||
|
"Add E-mail",
|
||||||
|
"Add an new E-Mail address to your account.",
|
||||||
|
emailBaseCommand);
|
||||||
|
addEmailCommand.setCommandPermissions("authme.email.add", CommandPermissions.DefaultPermission.ALLOWED);
|
||||||
|
addEmailCommand.addArgument(new CommandArgumentDescription("email", "Email address", false));
|
||||||
|
addEmailCommand.addArgument(new CommandArgumentDescription("verifyEmail", "Email address verification", false));
|
||||||
|
|
||||||
|
// Register the change command
|
||||||
|
CommandDescription changeEmailCommand = new CommandDescription(
|
||||||
|
new ChangeEmailCommand(),
|
||||||
|
new ArrayList<String>() {{
|
||||||
|
add("change");
|
||||||
|
add("changeemail");
|
||||||
|
add("changemail");
|
||||||
|
}},
|
||||||
|
"Change E-mail",
|
||||||
|
"Change an E-Mail address of your account.",
|
||||||
|
emailBaseCommand);
|
||||||
|
changeEmailCommand.setCommandPermissions("authme.email.change", CommandPermissions.DefaultPermission.ALLOWED);
|
||||||
|
changeEmailCommand.addArgument(new CommandArgumentDescription("oldEmail", "Old email address", false));
|
||||||
|
changeEmailCommand.addArgument(new CommandArgumentDescription("newEmail", "New email address", false));
|
||||||
|
|
||||||
|
// Register the recover command
|
||||||
|
CommandDescription recoverEmailCommand = new CommandDescription(
|
||||||
|
new RecoverEmailCommand(),
|
||||||
|
new ArrayList<String>() {{
|
||||||
|
add("recover");
|
||||||
|
add("recovery");
|
||||||
|
add("recoveremail");
|
||||||
|
add("recovermail");
|
||||||
|
}},
|
||||||
|
"Recover using E-mail",
|
||||||
|
"Recover your account using an E-mail address.",
|
||||||
|
emailBaseCommand);
|
||||||
|
recoverEmailCommand.setCommandPermissions("authme.email.recover", CommandPermissions.DefaultPermission.ALLOWED);
|
||||||
|
recoverEmailCommand.addArgument(new CommandArgumentDescription("email", "Email address", false));
|
||||||
|
|
||||||
|
// Register the base captcha command
|
||||||
|
CommandDescription captchaBaseCommand = new CommandDescription(
|
||||||
|
new CaptchaCommand(),
|
||||||
|
new ArrayList<String>() {{
|
||||||
|
add("captcha");
|
||||||
|
add("capt");
|
||||||
|
}},
|
||||||
|
"Captcha command",
|
||||||
|
"Captcha command for AuthMeReloaded.", null);
|
||||||
|
captchaBaseCommand.setCommandPermissions("authme.captcha", CommandPermissions.DefaultPermission.ALLOWED);
|
||||||
|
captchaBaseCommand.addArgument(new CommandArgumentDescription("captcha", "The captcha", false));
|
||||||
|
captchaBaseCommand.setMaximumArguments(false);
|
||||||
|
|
||||||
|
// Register the help command
|
||||||
|
CommandDescription captchaHelpCommand = new CommandDescription(
|
||||||
|
new HelpCommand(),
|
||||||
|
new ArrayList<String>() {{
|
||||||
|
add("help");
|
||||||
|
add("hlp");
|
||||||
|
add("h");
|
||||||
|
add("sos");
|
||||||
|
add("?");
|
||||||
|
}},
|
||||||
|
"View help",
|
||||||
|
"View detailed help pages about AuthMeReloaded change captcha commands.",
|
||||||
|
captchaBaseCommand);
|
||||||
|
captchaHelpCommand.addArgument(new CommandArgumentDescription("query", "The command or query to view help for.", true));
|
||||||
|
captchaHelpCommand.setMaximumArguments(false);
|
||||||
|
|
||||||
|
// Register the base converter command
|
||||||
|
CommandDescription converterBaseCommand = new CommandDescription(
|
||||||
|
new ConverterCommand(),
|
||||||
|
new ArrayList<String>() {{
|
||||||
|
add("converter");
|
||||||
|
add("convert");
|
||||||
|
add("conv");
|
||||||
|
}},
|
||||||
|
"Convert command",
|
||||||
|
"Convert command for AuthMeReloaded.", null);
|
||||||
|
converterBaseCommand.setCommandPermissions("authme.converter", CommandPermissions.DefaultPermission.OP_ONLY);
|
||||||
|
converterBaseCommand.addArgument(new CommandArgumentDescription("job", "Conversion job: flattosql / flattosqlite /| xauth / crazylogin / rakamak / royalauth / vauth / sqltoflat", false));
|
||||||
|
converterBaseCommand.setMaximumArguments(false);
|
||||||
|
|
||||||
|
// Register the help command
|
||||||
|
CommandDescription converterHelpCommand = new CommandDescription(
|
||||||
|
new HelpCommand(),
|
||||||
|
new ArrayList<String>() {{
|
||||||
|
add("help");
|
||||||
|
add("hlp");
|
||||||
|
add("h");
|
||||||
|
add("sos");
|
||||||
|
add("?");
|
||||||
|
}},
|
||||||
|
"View help",
|
||||||
|
"View detailed help pages about AuthMeReloaded change captcha commands.",
|
||||||
|
converterBaseCommand);
|
||||||
|
converterHelpCommand.addArgument(new CommandArgumentDescription("query", "The command or query to view help for.", true));
|
||||||
|
converterHelpCommand.setMaximumArguments(false);
|
||||||
|
|
||||||
|
// Add the base commands to the commands array
|
||||||
|
this.commandDescriptions.add(authMeBaseCommand);
|
||||||
|
this.commandDescriptions.add(loginBaseCommand);
|
||||||
|
this.commandDescriptions.add(logoutBaseCommand);
|
||||||
|
this.commandDescriptions.add(registerBaseCommand);
|
||||||
|
this.commandDescriptions.add(unregisterBaseCommand);
|
||||||
|
this.commandDescriptions.add(changePasswordBaseCommand);
|
||||||
|
this.commandDescriptions.add(emailBaseCommand);
|
||||||
|
this.commandDescriptions.add(captchaBaseCommand);
|
||||||
|
this.commandDescriptions.add(converterBaseCommand);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the list of command descriptions
|
||||||
|
*
|
||||||
|
* @return List of command descriptions.
|
||||||
|
*/
|
||||||
|
public List<CommandDescription> getCommandDescriptions() {
|
||||||
|
return this.commandDescriptions;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the number of command description count.
|
||||||
|
*
|
||||||
|
* @return Command description count.
|
||||||
|
*/
|
||||||
|
public int getCommandDescriptionCount() {
|
||||||
|
return this.getCommandDescriptions().size();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find the best suitable command for the specified reference.
|
||||||
|
*
|
||||||
|
* @param queryReference The query reference to find a command for.
|
||||||
|
*
|
||||||
|
* @return The command found, or null.
|
||||||
|
*/
|
||||||
|
public FoundCommandResult findCommand(CommandParts queryReference) {
|
||||||
|
// Make sure the command reference is valid
|
||||||
|
if(queryReference.getCount() <= 0)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
// Get the base command description
|
||||||
|
for(CommandDescription commandDescription : this.commandDescriptions) {
|
||||||
|
// Check whether there's a command description available for the current command
|
||||||
|
if(!commandDescription.isSuitableLabel(queryReference))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
// Find the command reference, return the result
|
||||||
|
return commandDescription.findCommand(queryReference);
|
||||||
|
}
|
||||||
|
|
||||||
|
// No applicable command description found, return false
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
203
src/main/java/fr/xephi/authme/command/CommandParts.java
Normal file
203
src/main/java/fr/xephi/authme/command/CommandParts.java
Normal file
@ -0,0 +1,203 @@
|
|||||||
|
package fr.xephi.authme.command;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import fr.xephi.authme.util.ListUtils;
|
||||||
|
import fr.xephi.authme.util.StringUtils;
|
||||||
|
|
||||||
|
public class CommandParts {
|
||||||
|
|
||||||
|
/** The list of parts for this command. */
|
||||||
|
private List<String> parts = new ArrayList<>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor.
|
||||||
|
*/
|
||||||
|
public CommandParts() { }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor.
|
||||||
|
*
|
||||||
|
* @param part The part to add.
|
||||||
|
*/
|
||||||
|
public CommandParts(String part) {
|
||||||
|
this.parts.add(part);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor.
|
||||||
|
*
|
||||||
|
* @param commandParts The command parts instance.
|
||||||
|
*/
|
||||||
|
public CommandParts(CommandParts commandParts) {
|
||||||
|
this.parts.addAll(commandParts.getList());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor.
|
||||||
|
*
|
||||||
|
* @param parts The list of parts.
|
||||||
|
*/
|
||||||
|
public CommandParts(List<String> parts) {
|
||||||
|
this.parts.addAll(parts);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor.
|
||||||
|
*
|
||||||
|
* @param base The base part.
|
||||||
|
* @param parts The list of additional parts.
|
||||||
|
*/
|
||||||
|
public CommandParts(String base, List<String> parts) {
|
||||||
|
this.parts.add(base);
|
||||||
|
this.parts.addAll(parts);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the command parts.
|
||||||
|
*
|
||||||
|
* @return Command parts.
|
||||||
|
*/
|
||||||
|
public List<String> getList() {
|
||||||
|
return this.parts;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a part.
|
||||||
|
*
|
||||||
|
* @param part The part to add.
|
||||||
|
*
|
||||||
|
* @return The result.
|
||||||
|
*/
|
||||||
|
public boolean add(String part) {
|
||||||
|
return this.parts.add(part);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add some parts.
|
||||||
|
*
|
||||||
|
* @param parts The parts to add.
|
||||||
|
*
|
||||||
|
* @return The result.
|
||||||
|
*/
|
||||||
|
public boolean add(List<String> parts) {
|
||||||
|
return this.parts.addAll(parts);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add some parts.
|
||||||
|
*
|
||||||
|
* @param parts The parts to add.
|
||||||
|
*
|
||||||
|
* @return The result.
|
||||||
|
*/
|
||||||
|
public boolean add(String[] parts) {
|
||||||
|
for(String entry : parts)
|
||||||
|
add(entry);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the number of parts.
|
||||||
|
*
|
||||||
|
* @return Part count.
|
||||||
|
*/
|
||||||
|
public int getCount() {
|
||||||
|
return this.parts.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a part by it's index.
|
||||||
|
*
|
||||||
|
* @param i Part index.
|
||||||
|
*
|
||||||
|
* @return The part.
|
||||||
|
*/
|
||||||
|
public String get(int i) {
|
||||||
|
// Make sure the index is in-bound
|
||||||
|
if(i < 0 || i >= getCount())
|
||||||
|
return null;
|
||||||
|
|
||||||
|
// Get and return the argument
|
||||||
|
return this.parts.get(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a range of the parts starting at the specified index up to the end of the range.
|
||||||
|
*
|
||||||
|
* @param start The starting index.
|
||||||
|
*
|
||||||
|
* @return The parts range. Arguments that were out of bound are not included.
|
||||||
|
*/
|
||||||
|
public List<String> getRange(int start) {
|
||||||
|
return getRange(start, getCount() - start);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a range of the parts.
|
||||||
|
*
|
||||||
|
* @param start The starting index.
|
||||||
|
* @param count The number of parts to get.
|
||||||
|
*
|
||||||
|
* @return The parts range. Parts that were out of bound are not included.
|
||||||
|
*/
|
||||||
|
public List<String> getRange(int start, int count) {
|
||||||
|
// Create a new list to put the range into
|
||||||
|
List<String> elements = new ArrayList<>();
|
||||||
|
|
||||||
|
// Get the range
|
||||||
|
for(int i = start; i < start + count; i++) {
|
||||||
|
// Get the part and add it if it's valid
|
||||||
|
String element = get(i);
|
||||||
|
if(element != null)
|
||||||
|
elements.add(element);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return the list of parts
|
||||||
|
return elements;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the difference value between two references. This won't do a full compare, just the last reference parts instead.
|
||||||
|
*
|
||||||
|
* @param other The other reference.
|
||||||
|
*
|
||||||
|
* @return The result from zero to above. A negative number will be returned on error.
|
||||||
|
*/
|
||||||
|
public double getDifference(CommandParts other) {
|
||||||
|
return getDifference(other, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the difference value between two references.
|
||||||
|
*
|
||||||
|
* @param other The other reference.
|
||||||
|
* @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.
|
||||||
|
*/
|
||||||
|
public double getDifference(CommandParts other, boolean fullCompare) {
|
||||||
|
// Make sure the other reference is correct
|
||||||
|
if(other == null)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
// Get the range to use
|
||||||
|
int range = Math.min(this.getCount(), other.getCount());
|
||||||
|
|
||||||
|
// Get and the difference
|
||||||
|
if(fullCompare)
|
||||||
|
return StringUtils.getDifference(this.toString(), other.toString());
|
||||||
|
return StringUtils.getDifference(this.getRange(range - 1, 1).toString(), other.getRange(range - 1, 1).toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert the parts to a string.
|
||||||
|
*
|
||||||
|
* @return The part as a string.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return ListUtils.implode(this.parts, " ");
|
||||||
|
}
|
||||||
|
}
|
||||||
183
src/main/java/fr/xephi/authme/command/CommandPermissions.java
Normal file
183
src/main/java/fr/xephi/authme/command/CommandPermissions.java
Normal file
@ -0,0 +1,183 @@
|
|||||||
|
package fr.xephi.authme.command;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
//import com.timvisee.dungeonmaze.Core;
|
||||||
|
//import com.timvisee.dungeonmaze.permission.PermissionsManager;
|
||||||
|
import fr.xephi.authme.AuthMe;
|
||||||
|
|
||||||
|
public class CommandPermissions {
|
||||||
|
|
||||||
|
/** Defines the permission nodes required to have permission to execute this command. */
|
||||||
|
private List<String> permissionNodes = new ArrayList<>();
|
||||||
|
/** Defines the default permission if the permission nodes couldn't be used. */
|
||||||
|
private DefaultPermission defaultPermission = DefaultPermission.NOT_ALLOWED;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor.
|
||||||
|
*/
|
||||||
|
public CommandPermissions() { }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor.
|
||||||
|
*
|
||||||
|
* @param permissionNode The permission node required to execute a command.
|
||||||
|
* @param defaultPermission The default permission if the permission nodes couldn't be used.
|
||||||
|
*/
|
||||||
|
public CommandPermissions(String permissionNode, DefaultPermission defaultPermission) {
|
||||||
|
this.permissionNodes.add(permissionNode);
|
||||||
|
this.defaultPermission = defaultPermission;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor.
|
||||||
|
*
|
||||||
|
* @param permissionNodes The permission nodes required to execute a command.
|
||||||
|
* @param defaultPermission The default permission if the permission nodes couldn't be used.
|
||||||
|
*/
|
||||||
|
public CommandPermissions(List<String> permissionNodes, DefaultPermission defaultPermission) {
|
||||||
|
this.permissionNodes.addAll(permissionNodes);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a permission node required to execute this command.
|
||||||
|
*
|
||||||
|
* @param permissionNode The permission node to add.
|
||||||
|
*
|
||||||
|
* @return True on success, false on failure.
|
||||||
|
*/
|
||||||
|
public boolean addPermissionNode(String permissionNode) {
|
||||||
|
// Trim the permission node
|
||||||
|
permissionNode = permissionNode.trim();
|
||||||
|
|
||||||
|
// Make sure the permission node is valid
|
||||||
|
if(permissionNode.length() == 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// Make sure this permission node hasn't been added already
|
||||||
|
if(hasPermissionNode(permissionNode))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
// Add the permission node, return the result
|
||||||
|
return this.permissionNodes.add(permissionNode);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check whether this command requires a specified permission node to execute.
|
||||||
|
*
|
||||||
|
* @param permissionNode The permission node to check for.
|
||||||
|
*
|
||||||
|
* @return True if this permission node is required, false if not.
|
||||||
|
*/
|
||||||
|
public boolean hasPermissionNode(String permissionNode) {
|
||||||
|
return this.permissionNodes.contains(permissionNode);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the permission nodes required to execute this command.
|
||||||
|
*
|
||||||
|
* @return The permission nodes required to execute this command.
|
||||||
|
*/
|
||||||
|
public List<String> getPermissionNodes() {
|
||||||
|
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.
|
||||||
|
*
|
||||||
|
* @param permissionNodes The permission nodes required to execute this command.
|
||||||
|
*/
|
||||||
|
public void setPermissionNodes(List<String> permissionNodes) {
|
||||||
|
this.permissionNodes = permissionNodes;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check whether this command requires any permission to be executed. This is based on the getPermission() method.
|
||||||
|
*
|
||||||
|
* @return True if this command requires any permission to be executed by a player.
|
||||||
|
*/
|
||||||
|
public boolean hasPermission(CommandSender sender) {
|
||||||
|
// Make sure any permission node is set
|
||||||
|
if(getPermissionNodeCount() == 0)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
// Get the default permission
|
||||||
|
final boolean defaultPermission = getDefaultPermissionCommandSender(sender);
|
||||||
|
|
||||||
|
// Make sure the command sender is a player, if not use the default
|
||||||
|
if(!(sender instanceof Player))
|
||||||
|
return defaultPermission;
|
||||||
|
|
||||||
|
// Get the player instance
|
||||||
|
Player player = (Player) sender;
|
||||||
|
|
||||||
|
// // Get the permissions manager, and make sure it's instance is valid
|
||||||
|
// PermissionsManager permissionsManager = Core.getPermissionsManager();
|
||||||
|
// if(permissionsManager == null)
|
||||||
|
// return false;
|
||||||
|
|
||||||
|
// Check whether the player has permission, return the result
|
||||||
|
for(String node : this.permissionNodes)
|
||||||
|
if(!AuthMe.getInstance().authmePermissible(player, node))
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the default permission if the permission nodes couldn't be used.
|
||||||
|
*
|
||||||
|
* @return The default permission.
|
||||||
|
*/
|
||||||
|
public DefaultPermission getDefaultPermission() {
|
||||||
|
return this.defaultPermission;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the default permission used if the permission nodes couldn't be used.
|
||||||
|
*
|
||||||
|
* @param defaultPermission The default permission.
|
||||||
|
*/
|
||||||
|
public void setDefaultPermission(DefaultPermission defaultPermission) {
|
||||||
|
this.defaultPermission = defaultPermission;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the default permission for a specified command sender.
|
||||||
|
*
|
||||||
|
* @param sender The command sender to get the default permission for.
|
||||||
|
*
|
||||||
|
* @return True if the command sender has permission by default, false otherwise.
|
||||||
|
*/
|
||||||
|
public boolean getDefaultPermissionCommandSender(CommandSender sender) {
|
||||||
|
switch(getDefaultPermission()) {
|
||||||
|
case ALLOWED:
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case OP_ONLY:
|
||||||
|
return sender.isOp();
|
||||||
|
|
||||||
|
case NOT_ALLOWED:
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum DefaultPermission {
|
||||||
|
NOT_ALLOWED,
|
||||||
|
OP_ONLY,
|
||||||
|
ALLOWED
|
||||||
|
}
|
||||||
|
}
|
||||||
17
src/main/java/fr/xephi/authme/command/ExecutableCommand.java
Normal file
17
src/main/java/fr/xephi/authme/command/ExecutableCommand.java
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
package fr.xephi.authme.command;
|
||||||
|
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
|
public abstract class 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.
|
||||||
|
*/
|
||||||
|
public abstract boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments);
|
||||||
|
}
|
||||||
150
src/main/java/fr/xephi/authme/command/FoundCommandResult.java
Normal file
150
src/main/java/fr/xephi/authme/command/FoundCommandResult.java
Normal file
@ -0,0 +1,150 @@
|
|||||||
|
package fr.xephi.authme.command;
|
||||||
|
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
|
public class FoundCommandResult {
|
||||||
|
|
||||||
|
/** The command description instance. */
|
||||||
|
private CommandDescription commandDescription;
|
||||||
|
/** The command reference. */
|
||||||
|
private CommandParts commandReference;
|
||||||
|
/** The command arguments. */
|
||||||
|
private CommandParts commandArguments;
|
||||||
|
/** The original search query reference. */
|
||||||
|
private CommandParts queryReference;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor.
|
||||||
|
*
|
||||||
|
* @param commandDescription The command description.
|
||||||
|
* @param commandReference The command reference.
|
||||||
|
* @param commandArguments The command arguments.
|
||||||
|
* @param queryReference The original query reference.
|
||||||
|
*/
|
||||||
|
public FoundCommandResult(CommandDescription commandDescription, CommandParts commandReference, CommandParts commandArguments, CommandParts queryReference) {
|
||||||
|
this.commandDescription = commandDescription;
|
||||||
|
this.commandReference = commandReference;
|
||||||
|
this.commandArguments = commandArguments;
|
||||||
|
this.queryReference = queryReference;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check whether the command was suitable.
|
||||||
|
*
|
||||||
|
* @return True if the command was suitable, false otherwise.
|
||||||
|
*/
|
||||||
|
public boolean hasProperArguments() {
|
||||||
|
// Make sure the command description is set
|
||||||
|
if(this.commandDescription == null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// Get and return the result
|
||||||
|
return getCommandDescription().getSuitableArgumentsDifference(this.queryReference) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the command description.
|
||||||
|
*
|
||||||
|
* @return Command description.
|
||||||
|
*/
|
||||||
|
public CommandDescription getCommandDescription() {
|
||||||
|
return this.commandDescription;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the command description.
|
||||||
|
*
|
||||||
|
* @param commandDescription The command description.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public void setCommandDescription(CommandDescription commandDescription) {
|
||||||
|
this.commandDescription = commandDescription;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check whether the command is executable.
|
||||||
|
*
|
||||||
|
* @return True if the command is executable, false otherwise.
|
||||||
|
*/
|
||||||
|
public boolean isExecutable() {
|
||||||
|
// Make sure the command description is valid
|
||||||
|
if(this.commandDescription == null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// Check whether the command is executable, return the result
|
||||||
|
return this.commandDescription.isExecutable();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the command.
|
||||||
|
*
|
||||||
|
* @param sender The command sender that executed the command.
|
||||||
|
*
|
||||||
|
* @return True on success, false on failure.
|
||||||
|
*/
|
||||||
|
public boolean executeCommand(CommandSender sender) {
|
||||||
|
// Make sure the command description is valid
|
||||||
|
if(this.commandDescription == null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// Execute the command
|
||||||
|
return this.commandDescription.execute(sender, this.commandReference, this.commandArguments);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check whether a command sender has permission to execute the command.
|
||||||
|
*
|
||||||
|
* @param sender The command sender.
|
||||||
|
*
|
||||||
|
* @return True if the command sender has permission, false otherwise.
|
||||||
|
*/
|
||||||
|
public boolean hasPermission(CommandSender sender) {
|
||||||
|
// Make sure the command description is valid
|
||||||
|
if(this.commandDescription == null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// Get and return the permission
|
||||||
|
return this.commandDescription.getCommandPermissions().hasPermission(sender);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the command reference.
|
||||||
|
*
|
||||||
|
* @return The command reference.
|
||||||
|
*/
|
||||||
|
public CommandParts getCommandReference() {
|
||||||
|
return this.commandReference;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the command arguments.
|
||||||
|
*
|
||||||
|
* @return The command arguments.
|
||||||
|
*/
|
||||||
|
public CommandParts getCommandArguments() {
|
||||||
|
return this.commandArguments;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the original query reference.
|
||||||
|
*
|
||||||
|
* @return Original query reference.
|
||||||
|
*/
|
||||||
|
public CommandParts getQueryReference() {
|
||||||
|
return this.queryReference;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the difference value between the original query and the result reference.
|
||||||
|
*
|
||||||
|
* @return The difference value.
|
||||||
|
*/
|
||||||
|
public double getDifference() {
|
||||||
|
// Get the difference through the command found
|
||||||
|
if(this.commandDescription != null)
|
||||||
|
return this.commandDescription.getCommandDifference(this.queryReference);
|
||||||
|
|
||||||
|
// Get the difference from the query reference
|
||||||
|
return this.queryReference.getDifference(commandReference, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,38 @@
|
|||||||
|
package fr.xephi.authme.command.executable;
|
||||||
|
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
|
import fr.xephi.authme.command.CommandParts;
|
||||||
|
import fr.xephi.authme.command.ExecutableCommand;
|
||||||
|
import fr.xephi.authme.command.help.HelpProvider;
|
||||||
|
|
||||||
|
public class HelpCommand 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
|
||||||
|
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
||||||
|
// Check whether quick help should be shown
|
||||||
|
boolean quickHelp = commandArguments.getCount() == 0;
|
||||||
|
|
||||||
|
// Set the proper command arguments for the quick help
|
||||||
|
if(quickHelp)
|
||||||
|
commandArguments = new CommandParts(commandReference.get(0));
|
||||||
|
|
||||||
|
// Show the new help
|
||||||
|
if(quickHelp)
|
||||||
|
HelpProvider.showHelp(sender, commandReference, commandArguments, false, false, false, false, false, true);
|
||||||
|
else
|
||||||
|
HelpProvider.showHelp(sender, commandReference, commandArguments);
|
||||||
|
|
||||||
|
// Return the result
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,122 @@
|
|||||||
|
package fr.xephi.authme.command.executable.authme;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import fr.xephi.authme.ConsoleLogger;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
|
import fr.xephi.authme.AuthMe;
|
||||||
|
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||||
|
import fr.xephi.authme.command.CommandParts;
|
||||||
|
import fr.xephi.authme.command.ExecutableCommand;
|
||||||
|
import fr.xephi.authme.settings.Messages;
|
||||||
|
|
||||||
|
public class AccountsCommand 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
|
||||||
|
public boolean executeCommand(final CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
||||||
|
// AuthMe plugin instance
|
||||||
|
final AuthMe plugin = AuthMe.getInstance();
|
||||||
|
|
||||||
|
// Messages instance
|
||||||
|
final Messages m = Messages.getInstance();
|
||||||
|
|
||||||
|
// Get the player query
|
||||||
|
String playerQuery = sender.getName();
|
||||||
|
if(commandArguments.getCount() >= 1)
|
||||||
|
playerQuery = commandArguments.get(0);
|
||||||
|
final String playerQueryFinal = playerQuery;
|
||||||
|
|
||||||
|
// Command logic
|
||||||
|
if (!playerQuery.contains(".")) {
|
||||||
|
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
PlayerAuth auth;
|
||||||
|
StringBuilder message = new StringBuilder("[AuthMe] ");
|
||||||
|
try {
|
||||||
|
auth = plugin.database.getAuth(playerQueryFinal.toLowerCase());
|
||||||
|
} catch (NullPointerException npe) {
|
||||||
|
m.send(sender, "unknown_user");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (auth == null) {
|
||||||
|
m.send(sender, "unknown_user");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
List<String> accountList = plugin.database.getAllAuthsByName(auth);
|
||||||
|
if (accountList == null || accountList.isEmpty()) {
|
||||||
|
m.send(sender, "user_unknown");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (accountList.size() == 1) {
|
||||||
|
sender.sendMessage("[AuthMe] " + playerQueryFinal + " is a single account player");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int i = 0;
|
||||||
|
for (String account : accountList) {
|
||||||
|
i++;
|
||||||
|
message.append(account);
|
||||||
|
if (i != accountList.size()) {
|
||||||
|
message.append(", ");
|
||||||
|
} else {
|
||||||
|
message.append(".");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sender.sendMessage("[AuthMe] " + playerQueryFinal + " has " + String.valueOf(accountList.size()) + " accounts");
|
||||||
|
sender.sendMessage(message.toString());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
List<String> accountList;
|
||||||
|
try {
|
||||||
|
accountList = plugin.database.getAllAuthsByIp(playerQueryFinal);
|
||||||
|
} catch (Exception e) {
|
||||||
|
ConsoleLogger.showError(e.getMessage());
|
||||||
|
ConsoleLogger.writeStackTrace(e);
|
||||||
|
m.send(sender, "error");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
StringBuilder message = new StringBuilder("[AuthMe] ");
|
||||||
|
if (accountList == null || accountList.isEmpty()) {
|
||||||
|
sender.sendMessage("[AuthMe] This IP does not exist in the database");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (accountList.size() == 1) {
|
||||||
|
sender.sendMessage("[AuthMe] " + playerQueryFinal + " is a single account player");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int i = 0;
|
||||||
|
for (String account : accountList) {
|
||||||
|
i++;
|
||||||
|
message.append(account);
|
||||||
|
if (i != accountList.size()) {
|
||||||
|
message.append(", ");
|
||||||
|
} else {
|
||||||
|
message.append(".");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sender.sendMessage("[AuthMe] " + playerQueryFinal + " has " + String.valueOf(accountList.size()) + " accounts");
|
||||||
|
sender.sendMessage(message.toString());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,29 @@
|
|||||||
|
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.command.CommandParts;
|
||||||
|
import fr.xephi.authme.command.ExecutableCommand;
|
||||||
|
|
||||||
|
public class AuthMeCommand 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
|
||||||
|
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
||||||
|
// Show some version info
|
||||||
|
sender.sendMessage(ChatColor.GREEN + "This server is running " + AuthMe.PLUGIN_NAME + " 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) + " about" + ChatColor.YELLOW + " to view about.");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,101 @@
|
|||||||
|
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.ConsoleLogger;
|
||||||
|
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||||
|
import fr.xephi.authme.cache.auth.PlayerCache;
|
||||||
|
import fr.xephi.authme.command.CommandParts;
|
||||||
|
import fr.xephi.authme.command.ExecutableCommand;
|
||||||
|
import fr.xephi.authme.security.PasswordSecurity;
|
||||||
|
import fr.xephi.authme.settings.Messages;
|
||||||
|
import fr.xephi.authme.settings.Settings;
|
||||||
|
|
||||||
|
public class ChangePasswordCommand 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
|
||||||
|
public boolean executeCommand(final CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
||||||
|
// AuthMe plugin instance
|
||||||
|
final AuthMe plugin = AuthMe.getInstance();
|
||||||
|
|
||||||
|
// Messages instance
|
||||||
|
final Messages m = Messages.getInstance();
|
||||||
|
|
||||||
|
// Get the player and password
|
||||||
|
String playerName = commandArguments.get(0);
|
||||||
|
final String playerPass = commandArguments.get(1);
|
||||||
|
|
||||||
|
// Validate the password
|
||||||
|
String playerPassLowerCase = playerPass.toLowerCase();
|
||||||
|
if (playerPassLowerCase.contains("delete") || playerPassLowerCase.contains("where") || playerPassLowerCase.contains("insert") || playerPassLowerCase.contains("modify") || playerPassLowerCase.contains("from") || playerPassLowerCase.contains("select") || playerPassLowerCase.contains(";") || playerPassLowerCase.contains("null") || !playerPassLowerCase.matches(Settings.getPassRegex)) {
|
||||||
|
m.send(sender, "password_error");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (playerPassLowerCase.equalsIgnoreCase(playerName)) {
|
||||||
|
m.send(sender, "password_error_nick");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (playerPassLowerCase.length() < Settings.getPasswordMinLen || playerPassLowerCase.length() > Settings.passwordMaxLength) {
|
||||||
|
m.send(sender, "pass_len");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (!Settings.unsafePasswords.isEmpty()) {
|
||||||
|
if (Settings.unsafePasswords.contains(playerPassLowerCase)) {
|
||||||
|
m.send(sender, "password_error_unsafe");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set the password
|
||||||
|
final String playerNameLowerCase = playerName.toLowerCase();
|
||||||
|
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
String hash;
|
||||||
|
try {
|
||||||
|
hash = PasswordSecurity.getHash(Settings.getPasswordHash, playerPass, playerNameLowerCase);
|
||||||
|
} catch (NoSuchAlgorithmException e) {
|
||||||
|
m.send(sender, "error");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
PlayerAuth auth = null;
|
||||||
|
if (PlayerCache.getInstance().isAuthenticated(playerNameLowerCase)) {
|
||||||
|
auth = PlayerCache.getInstance().getAuth(playerNameLowerCase);
|
||||||
|
} else if (plugin.database.isAuthAvailable(playerNameLowerCase)) {
|
||||||
|
auth = plugin.database.getAuth(playerNameLowerCase);
|
||||||
|
}
|
||||||
|
if (auth == null) {
|
||||||
|
m.send(sender, "unknown_user");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
auth.setHash(hash);
|
||||||
|
if (PasswordSecurity.userSalt.containsKey(playerNameLowerCase)) {
|
||||||
|
auth.setSalt(PasswordSecurity.userSalt.get(playerNameLowerCase));
|
||||||
|
plugin.database.updateSalt(auth);
|
||||||
|
}
|
||||||
|
if (!plugin.database.updatePassword(auth)) {
|
||||||
|
m.send(sender, "error");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
sender.sendMessage("pwd_changed");
|
||||||
|
ConsoleLogger.info(playerNameLowerCase + "'s password changed");
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,38 @@
|
|||||||
|
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.command.CommandParts;
|
||||||
|
import fr.xephi.authme.command.ExecutableCommand;
|
||||||
|
import fr.xephi.authme.settings.Spawn;
|
||||||
|
|
||||||
|
public class FirstSpawnCommand 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
|
||||||
|
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
||||||
|
// Make sure the command executor is a player
|
||||||
|
try {
|
||||||
|
if (sender instanceof Player) {
|
||||||
|
if (Spawn.getInstance().getFirstSpawn() != null)
|
||||||
|
((Player) sender).teleport(Spawn.getInstance().getFirstSpawn());
|
||||||
|
else sender.sendMessage("[AuthMe] First spawn has failed, please try to define the first spawn");
|
||||||
|
} else {
|
||||||
|
sender.sendMessage("[AuthMe] Please use that command in game");
|
||||||
|
}
|
||||||
|
} catch (NullPointerException ex) {
|
||||||
|
ConsoleLogger.showError(ex.getMessage());
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,52 @@
|
|||||||
|
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.command.CommandParts;
|
||||||
|
import fr.xephi.authme.command.ExecutableCommand;
|
||||||
|
|
||||||
|
public class ForceLoginCommand 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
|
||||||
|
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
||||||
|
// AuthMe plugin instance
|
||||||
|
final AuthMe plugin = AuthMe.getInstance();
|
||||||
|
|
||||||
|
// Get the player query
|
||||||
|
String playerName = sender.getName();
|
||||||
|
if(commandArguments.getCount() >= 1)
|
||||||
|
playerName = commandArguments.get(0);
|
||||||
|
|
||||||
|
// Command logic
|
||||||
|
try {
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
Player player = Bukkit.getPlayer(playerName);
|
||||||
|
if (player == null || !player.isOnline()) {
|
||||||
|
sender.sendMessage("Player needs to be online!");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (!plugin.authmePermissible(player, "authme.canbeforced")) {
|
||||||
|
sender.sendMessage("You cannot force login for the player " + playerName + "!");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
plugin.management.performLogin(player, "dontneed", true);
|
||||||
|
sender.sendMessage("Force Login for " + playerName + " performed!");
|
||||||
|
} catch (Exception e) {
|
||||||
|
sender.sendMessage("An error occurred while trying to get that player!");
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,46 @@
|
|||||||
|
package fr.xephi.authme.command.executable.authme;
|
||||||
|
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
|
import fr.xephi.authme.AuthMe;
|
||||||
|
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||||
|
import fr.xephi.authme.command.CommandParts;
|
||||||
|
import fr.xephi.authme.command.ExecutableCommand;
|
||||||
|
import fr.xephi.authme.settings.Messages;
|
||||||
|
|
||||||
|
public class GetEmailCommand 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
|
||||||
|
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
||||||
|
// AuthMe plugin instance
|
||||||
|
AuthMe plugin = AuthMe.getInstance();
|
||||||
|
|
||||||
|
// Messages instance
|
||||||
|
Messages m = Messages.getInstance();
|
||||||
|
|
||||||
|
// Get the player name
|
||||||
|
String playerName = sender.getName();
|
||||||
|
if(commandArguments.getCount() >= 1)
|
||||||
|
playerName = commandArguments.get(0);
|
||||||
|
|
||||||
|
// Get the authenticated user
|
||||||
|
PlayerAuth auth = plugin.database.getAuth(playerName.toLowerCase());
|
||||||
|
if (auth == null) {
|
||||||
|
m.send(sender, "unknown_user");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Show the email address
|
||||||
|
sender.sendMessage("[AuthMe] " + playerName + "'s email: " + auth.getEmail());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,42 @@
|
|||||||
|
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.command.CommandParts;
|
||||||
|
import fr.xephi.authme.command.ExecutableCommand;
|
||||||
|
|
||||||
|
public class GetIpCommand 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
|
||||||
|
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
||||||
|
// AuthMe plugin instance
|
||||||
|
final AuthMe plugin = AuthMe.getInstance();
|
||||||
|
|
||||||
|
// Get the player query
|
||||||
|
String playerName = sender.getName();
|
||||||
|
if(commandArguments.getCount() >= 1)
|
||||||
|
playerName = commandArguments.get(0);
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
Player player = Bukkit.getPlayer(playerName);
|
||||||
|
if (player == null) {
|
||||||
|
sender.sendMessage("This player is not actually online");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
sender.sendMessage(player.getName() + "'s actual IP is : " + player.getAddress().getAddress().getHostAddress() + ":" + player.getAddress().getPort());
|
||||||
|
sender.sendMessage(player.getName() + "'s real IP is : " + plugin.getIP(player));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,69 @@
|
|||||||
|
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.cache.auth.PlayerAuth;
|
||||||
|
import fr.xephi.authme.command.CommandParts;
|
||||||
|
import fr.xephi.authme.command.ExecutableCommand;
|
||||||
|
import fr.xephi.authme.settings.Messages;
|
||||||
|
|
||||||
|
public class LastLoginCommand 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
|
||||||
|
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
||||||
|
// AuthMe plugin instance
|
||||||
|
AuthMe plugin = AuthMe.getInstance();
|
||||||
|
|
||||||
|
// Messages instance
|
||||||
|
Messages m = Messages.getInstance();
|
||||||
|
|
||||||
|
// Get the player
|
||||||
|
String playerName = sender.getName();
|
||||||
|
if(commandArguments.getCount() >= 1)
|
||||||
|
playerName = commandArguments.get(0);
|
||||||
|
|
||||||
|
// Validate the player
|
||||||
|
PlayerAuth auth;
|
||||||
|
try {
|
||||||
|
auth = plugin.database.getAuth(playerName.toLowerCase());
|
||||||
|
} catch (NullPointerException e) {
|
||||||
|
m.send(sender, "unknown_user");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (auth == null) {
|
||||||
|
m.send(sender, "user_unknown");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the last login date
|
||||||
|
long lastLogin = auth.getLastLogin();
|
||||||
|
Date date = new Date(lastLogin);
|
||||||
|
|
||||||
|
// Get the difference
|
||||||
|
final long diff = System.currentTimeMillis() - lastLogin;
|
||||||
|
|
||||||
|
// Build the message
|
||||||
|
final String msg = (int) (diff / 86400000) + " days " + (int) (diff / 3600000 % 24) + " hours " + (int) (diff / 60000 % 60) + " mins " + (int) (diff / 1000 % 60) + " secs.";
|
||||||
|
|
||||||
|
// Get the player's last IP
|
||||||
|
String lastIP = auth.getIp();
|
||||||
|
|
||||||
|
// Show the player status
|
||||||
|
sender.sendMessage("[AuthMe] " + playerName + " last login : " + date.toString());
|
||||||
|
sender.sendMessage("[AuthMe] The player " + auth.getNickname() + " is unlogged since " + msg);
|
||||||
|
sender.sendMessage("[AuthMe] Last Player's IP: " + lastIP);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,51 @@
|
|||||||
|
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.command.CommandParts;
|
||||||
|
import fr.xephi.authme.command.ExecutableCommand;
|
||||||
|
import fr.xephi.authme.settings.Settings;
|
||||||
|
|
||||||
|
public class PurgeBannedPlayersCommand 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
|
||||||
|
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
||||||
|
// AuthMe plugin instance
|
||||||
|
final AuthMe plugin = AuthMe.getInstance();
|
||||||
|
|
||||||
|
// Get the list of banned players
|
||||||
|
List<String> bannedPlayers = new ArrayList<>();
|
||||||
|
for (OfflinePlayer offlinePlayer : plugin.getServer().getBannedPlayers()) {
|
||||||
|
bannedPlayers.add(offlinePlayer.getName().toLowerCase());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Purge the banned players
|
||||||
|
plugin.database.purgeBanned(bannedPlayers);
|
||||||
|
if (Settings.purgeEssentialsFile && plugin.ess != null)
|
||||||
|
plugin.dataManager.purgeEssentials(bannedPlayers);
|
||||||
|
if (Settings.purgePlayerDat)
|
||||||
|
plugin.dataManager.purgeDat(bannedPlayers);
|
||||||
|
if (Settings.purgeLimitedCreative)
|
||||||
|
plugin.dataManager.purgeLimitedCreative(bannedPlayers);
|
||||||
|
if (Settings.purgeAntiXray)
|
||||||
|
plugin.dataManager.purgeAntiXray(bannedPlayers);
|
||||||
|
|
||||||
|
// Show a status message
|
||||||
|
sender.sendMessage("[AuthMe] Database has been purged correctly");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,73 @@
|
|||||||
|
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.command.CommandParts;
|
||||||
|
import fr.xephi.authme.command.ExecutableCommand;
|
||||||
|
import fr.xephi.authme.settings.Settings;
|
||||||
|
|
||||||
|
public class PurgeCommand 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
|
||||||
|
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
||||||
|
// AuthMe plugin instance
|
||||||
|
AuthMe plugin = AuthMe.getInstance();
|
||||||
|
|
||||||
|
// Get the days parameter
|
||||||
|
String daysStr = commandArguments.get(0);
|
||||||
|
|
||||||
|
// Convert the days string to an integer value, and make sure it's valid
|
||||||
|
int days;
|
||||||
|
try {
|
||||||
|
days = Integer.valueOf(daysStr);
|
||||||
|
} catch(Exception ex) {
|
||||||
|
sender.sendMessage(ChatColor.RED + "The value you've entered is invalid!");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validate the value
|
||||||
|
if(days < 30) {
|
||||||
|
sender.sendMessage(ChatColor.RED + "You can only purge data older than 30 days");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create a calender instance to determine the date
|
||||||
|
Calendar calendar = Calendar.getInstance();
|
||||||
|
calendar.add(Calendar.DATE, -days);
|
||||||
|
long until = calendar.getTimeInMillis();
|
||||||
|
|
||||||
|
// Purge the data, get the purged values
|
||||||
|
List<String> purged = plugin.database.autoPurgeDatabase(until);
|
||||||
|
|
||||||
|
// Show a status message
|
||||||
|
sender.sendMessage(ChatColor.GOLD + "Deleted " + purged.size() + " user accounts");
|
||||||
|
|
||||||
|
// Purge other data
|
||||||
|
if(Settings.purgeEssentialsFile && plugin.ess != null)
|
||||||
|
plugin.dataManager.purgeEssentials(purged);
|
||||||
|
if(Settings.purgePlayerDat)
|
||||||
|
plugin.dataManager.purgeDat(purged);
|
||||||
|
if(Settings.purgeLimitedCreative)
|
||||||
|
plugin.dataManager.purgeLimitedCreative(purged);
|
||||||
|
if(Settings.purgeAntiXray)
|
||||||
|
plugin.dataManager.purgeAntiXray(purged);
|
||||||
|
|
||||||
|
// Show a status message
|
||||||
|
sender.sendMessage(ChatColor.GREEN + "[AuthMe] Database has been purged correctly");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,65 @@
|
|||||||
|
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.ConsoleLogger;
|
||||||
|
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||||
|
import fr.xephi.authme.command.CommandParts;
|
||||||
|
import fr.xephi.authme.command.ExecutableCommand;
|
||||||
|
import fr.xephi.authme.settings.Messages;
|
||||||
|
|
||||||
|
public class PurgeLastPositionCommand 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
|
||||||
|
public boolean executeCommand(final CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
||||||
|
// AuthMe plugin instance
|
||||||
|
final AuthMe plugin = AuthMe.getInstance();
|
||||||
|
|
||||||
|
// Messages instance
|
||||||
|
final Messages m = Messages.getInstance();
|
||||||
|
|
||||||
|
// Get the player
|
||||||
|
String playerName = sender.getName();
|
||||||
|
if(commandArguments.getCount() >= 1)
|
||||||
|
playerName = commandArguments.get(0);
|
||||||
|
String playerNameLowerCase = playerName.toLowerCase();
|
||||||
|
|
||||||
|
// Purge the last position of the player
|
||||||
|
try {
|
||||||
|
// Get the user auth and make sure the user exists
|
||||||
|
PlayerAuth auth = plugin.database.getAuth(playerNameLowerCase);
|
||||||
|
if (auth == null) {
|
||||||
|
m.send(sender, "unknown_user");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set the last position
|
||||||
|
auth.setQuitLocX(0D);
|
||||||
|
auth.setQuitLocY(0D);
|
||||||
|
auth.setQuitLocZ(0D);
|
||||||
|
auth.setWorld("world");
|
||||||
|
plugin.database.updateQuitLoc(auth);
|
||||||
|
|
||||||
|
// Show a status message
|
||||||
|
sender.sendMessage(playerNameLowerCase + "'s last position location is now reset");
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
ConsoleLogger.showError("An error occurred while trying to reset location or player do not exist, please see below: ");
|
||||||
|
ConsoleLogger.showError(e.getMessage());
|
||||||
|
if (sender instanceof Player)
|
||||||
|
sender.sendMessage("An error occurred while trying to reset location or player do not exist, please see logs");
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,93 @@
|
|||||||
|
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.ConsoleLogger;
|
||||||
|
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||||
|
import fr.xephi.authme.command.CommandParts;
|
||||||
|
import fr.xephi.authme.command.ExecutableCommand;
|
||||||
|
import fr.xephi.authme.security.PasswordSecurity;
|
||||||
|
import fr.xephi.authme.settings.Messages;
|
||||||
|
import fr.xephi.authme.settings.Settings;
|
||||||
|
|
||||||
|
public class RegisterCommand 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
|
||||||
|
public boolean executeCommand(final CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
||||||
|
// AuthMe plugin instance
|
||||||
|
final AuthMe plugin = AuthMe.getInstance();
|
||||||
|
|
||||||
|
// Messages instance
|
||||||
|
final Messages m = Messages.getInstance();
|
||||||
|
|
||||||
|
// Get the player name and password
|
||||||
|
final String playerName = commandArguments.get(0);
|
||||||
|
final String playerPass = commandArguments.get(1);
|
||||||
|
final String playerNameLowerCase = playerName.toLowerCase();
|
||||||
|
final String playerPassLowerCase = playerPass.toLowerCase();
|
||||||
|
|
||||||
|
// Command logic
|
||||||
|
if (playerPassLowerCase.contains("delete") || playerPassLowerCase.contains("where") || playerPassLowerCase.contains("insert") || playerPassLowerCase.contains("modify") || playerPassLowerCase.contains("from") || playerPassLowerCase.contains("select") || playerPassLowerCase.contains(";") || playerPassLowerCase.contains("null") || !playerPassLowerCase.matches(Settings.getPassRegex)) {
|
||||||
|
m.send(sender, "password_error");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (playerPassLowerCase.equalsIgnoreCase(playerName)) {
|
||||||
|
m.send(sender, "password_error_nick");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (playerPassLowerCase.length() < Settings.getPasswordMinLen || playerPassLowerCase.length() > Settings.passwordMaxLength) {
|
||||||
|
m.send(sender, "pass_len");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (!Settings.unsafePasswords.isEmpty()) {
|
||||||
|
if (Settings.unsafePasswords.contains(playerPassLowerCase)) {
|
||||||
|
m.send(sender, "password_error_unsafe");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable() {
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
if (plugin.database.isAuthAvailable(playerNameLowerCase)) {
|
||||||
|
m.send(sender, "user_regged");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String hash = PasswordSecurity.getHash(Settings.getPasswordHash, playerPassLowerCase, playerNameLowerCase);
|
||||||
|
PlayerAuth auth = new PlayerAuth(playerNameLowerCase, hash, "192.168.0.1", 0L, "your@email.com", playerName);
|
||||||
|
if (PasswordSecurity.userSalt.containsKey(playerNameLowerCase) && PasswordSecurity.userSalt.get(playerNameLowerCase) != null)
|
||||||
|
auth.setSalt(PasswordSecurity.userSalt.get(playerNameLowerCase));
|
||||||
|
else auth.setSalt("");
|
||||||
|
if (!plugin.database.saveAuth(auth)) {
|
||||||
|
m.send(sender, "error");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
plugin.database.setUnlogged(playerNameLowerCase);
|
||||||
|
if (Bukkit.getPlayerExact(playerName) != null)
|
||||||
|
Bukkit.getPlayerExact(playerName).kickPlayer("An admin just registered you, please log again");
|
||||||
|
m.send(sender, "registered");
|
||||||
|
ConsoleLogger.info(playerNameLowerCase + " registered");
|
||||||
|
} catch (NoSuchAlgorithmException ex) {
|
||||||
|
ConsoleLogger.showError(ex.getMessage());
|
||||||
|
m.send(sender, "error");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,59 @@
|
|||||||
|
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.ConsoleLogger;
|
||||||
|
import fr.xephi.authme.command.CommandParts;
|
||||||
|
import fr.xephi.authme.command.ExecutableCommand;
|
||||||
|
import fr.xephi.authme.settings.Messages;
|
||||||
|
import fr.xephi.authme.settings.Settings;
|
||||||
|
import fr.xephi.authme.util.Profiler;
|
||||||
|
|
||||||
|
public class ReloadCommand 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
|
||||||
|
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
||||||
|
// Profile the reload process
|
||||||
|
Profiler p = new Profiler(true);
|
||||||
|
|
||||||
|
// AuthMe plugin instance
|
||||||
|
AuthMe plugin = AuthMe.getInstance();
|
||||||
|
|
||||||
|
// Messages instance
|
||||||
|
Messages m = Messages.getInstance();
|
||||||
|
|
||||||
|
// Show a status message
|
||||||
|
// sender.sendMessage(ChatColor.YELLOW + "Reloading AuthMeReloaded...");
|
||||||
|
|
||||||
|
try {
|
||||||
|
Settings.reload();
|
||||||
|
plugin.getModuleManager().reloadModules();
|
||||||
|
Messages.getInstance().reloadMessages();
|
||||||
|
plugin.setupDatabase();
|
||||||
|
} catch (Exception e) {
|
||||||
|
ConsoleLogger.showError("Fatal error occurred! AuthMe instance ABORTED!");
|
||||||
|
ConsoleLogger.writeStackTrace(e);
|
||||||
|
plugin.stopOrUnload();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Show a status message
|
||||||
|
// TODO: add the profiler result
|
||||||
|
m.send(sender, "reload");
|
||||||
|
|
||||||
|
// AuthMeReloaded reloaded, show a status message
|
||||||
|
// sender.sendMessage(ChatColor.GREEN + "AuthMeReloaded has been reloaded successfully, took " + p.getTimeFormatted() + "!");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,43 @@
|
|||||||
|
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.cache.auth.PlayerAuth;
|
||||||
|
import fr.xephi.authme.command.CommandParts;
|
||||||
|
import fr.xephi.authme.command.ExecutableCommand;
|
||||||
|
|
||||||
|
public class ResetNameCommand 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
|
||||||
|
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
||||||
|
// AuthMe plugin instance
|
||||||
|
final AuthMe plugin = AuthMe.getInstance();
|
||||||
|
|
||||||
|
// Command logic
|
||||||
|
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
List<PlayerAuth> authentications = plugin.database.getAllAuths();
|
||||||
|
for(PlayerAuth auth : authentications) {
|
||||||
|
auth.setRealName("Player");
|
||||||
|
plugin.database.updateSession(auth);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,64 @@
|
|||||||
|
package fr.xephi.authme.command.executable.authme;
|
||||||
|
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
|
import fr.xephi.authme.AuthMe;
|
||||||
|
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||||
|
import fr.xephi.authme.cache.auth.PlayerCache;
|
||||||
|
import fr.xephi.authme.command.CommandParts;
|
||||||
|
import fr.xephi.authme.command.ExecutableCommand;
|
||||||
|
import fr.xephi.authme.settings.Messages;
|
||||||
|
import fr.xephi.authme.settings.Settings;
|
||||||
|
|
||||||
|
public class SetEmailCommand 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
|
||||||
|
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
||||||
|
// AuthMe plugin instance
|
||||||
|
AuthMe plugin = AuthMe.getInstance();
|
||||||
|
|
||||||
|
// Messages instance
|
||||||
|
Messages m = Messages.getInstance();
|
||||||
|
|
||||||
|
// Get the player name and email address
|
||||||
|
String playerName = commandArguments.get(0);
|
||||||
|
String playerEmail = commandArguments.get(1);
|
||||||
|
|
||||||
|
// Validate the email address
|
||||||
|
if (!Settings.isEmailCorrect(playerEmail)) {
|
||||||
|
m.send(sender, "email_invalid");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validate the user
|
||||||
|
PlayerAuth auth = plugin.database.getAuth(playerName.toLowerCase());
|
||||||
|
if (auth == null) {
|
||||||
|
m.send(sender, "unknown_user");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set the email address
|
||||||
|
auth.setEmail(playerEmail);
|
||||||
|
if (!plugin.database.updateEmail(auth)) {
|
||||||
|
m.send(sender, "error");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update the player cache
|
||||||
|
if (PlayerCache.getInstance().getAuth(playerName.toLowerCase()) != null)
|
||||||
|
PlayerCache.getInstance().updatePlayer(auth);
|
||||||
|
|
||||||
|
// Show a status message
|
||||||
|
m.send(sender, "email_changed");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,37 @@
|
|||||||
|
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.command.CommandParts;
|
||||||
|
import fr.xephi.authme.command.ExecutableCommand;
|
||||||
|
import fr.xephi.authme.settings.Spawn;
|
||||||
|
|
||||||
|
public class SetFirstSpawnCommand 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
|
||||||
|
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
||||||
|
try {
|
||||||
|
if (sender instanceof Player) {
|
||||||
|
if (Spawn.getInstance().setFirstSpawn(((Player) sender).getLocation()))
|
||||||
|
sender.sendMessage("[AuthMe] Correctly defined new first spawn point");
|
||||||
|
else sender.sendMessage("[AuthMe] SetFirstSpawn has failed, please retry");
|
||||||
|
} else {
|
||||||
|
sender.sendMessage("[AuthMe] Please use that command in game");
|
||||||
|
}
|
||||||
|
} catch (NullPointerException ex) {
|
||||||
|
ConsoleLogger.showError(ex.getMessage());
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,40 @@
|
|||||||
|
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.command.CommandParts;
|
||||||
|
import fr.xephi.authme.command.ExecutableCommand;
|
||||||
|
import fr.xephi.authme.settings.Spawn;
|
||||||
|
|
||||||
|
public class SetSpawnCommand 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
|
||||||
|
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
||||||
|
// Make sure the command executor is a player
|
||||||
|
try {
|
||||||
|
if (sender instanceof Player) {
|
||||||
|
if (Spawn.getInstance().setSpawn(((Player) sender).getLocation())) {
|
||||||
|
sender.sendMessage("[AuthMe] Correctly defined new spawn point");
|
||||||
|
} else {
|
||||||
|
sender.sendMessage("[AuthMe] SetSpawn has failed, please retry");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
sender.sendMessage("[AuthMe] Please use that command in game");
|
||||||
|
}
|
||||||
|
} catch (NullPointerException ex) {
|
||||||
|
ConsoleLogger.showError(ex.getMessage());
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,38 @@
|
|||||||
|
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.command.CommandParts;
|
||||||
|
import fr.xephi.authme.command.ExecutableCommand;
|
||||||
|
import fr.xephi.authme.settings.Spawn;
|
||||||
|
|
||||||
|
public class SpawnCommand 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
|
||||||
|
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
||||||
|
// Make sure the command executor is a player
|
||||||
|
try {
|
||||||
|
if (sender instanceof Player) {
|
||||||
|
if (Spawn.getInstance().getSpawn() != null)
|
||||||
|
((Player) sender).teleport(Spawn.getInstance().getSpawn());
|
||||||
|
else sender.sendMessage("[AuthMe] Spawn has failed, please try to define the spawn");
|
||||||
|
} else {
|
||||||
|
sender.sendMessage("[AuthMe] Please use that command in game");
|
||||||
|
}
|
||||||
|
} catch (NullPointerException ex) {
|
||||||
|
ConsoleLogger.showError(ex.getMessage());
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,57 @@
|
|||||||
|
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.command.CommandParts;
|
||||||
|
import fr.xephi.authme.command.ExecutableCommand;
|
||||||
|
import fr.xephi.authme.command.help.HelpProvider;
|
||||||
|
|
||||||
|
public class SwitchAntiBotCommand 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
|
||||||
|
public boolean executeCommand(final CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
||||||
|
// AuthMe plugin instance
|
||||||
|
final AuthMe plugin = AuthMe.getInstance();
|
||||||
|
|
||||||
|
// Get the new state
|
||||||
|
String newState = plugin.getAntiBotModMode() ? "OFF" : "ON";
|
||||||
|
if(commandArguments.getCount() >= 1)
|
||||||
|
newState = commandArguments.get(0);
|
||||||
|
|
||||||
|
// Enable the mod
|
||||||
|
if(newState.equalsIgnoreCase("ON")) {
|
||||||
|
plugin.switchAntiBotMod(true);
|
||||||
|
sender.sendMessage("[AuthMe] AntiBotMod enabled");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Disable the mod
|
||||||
|
if(newState.equalsIgnoreCase("OFF")) {
|
||||||
|
plugin.switchAntiBotMod(false);
|
||||||
|
sender.sendMessage("[AuthMe] AntiBotMod disabled");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Show the invalid arguments warning
|
||||||
|
sender.sendMessage(ChatColor.DARK_RED + "Invalid AntiBot mode!");
|
||||||
|
|
||||||
|
// Show the command argument help
|
||||||
|
HelpProvider.showHelp(sender, commandReference, commandReference, true, false, true, false, false, false);
|
||||||
|
|
||||||
|
// Show the command to use for detailed help
|
||||||
|
CommandParts helpCommandReference = new CommandParts(commandReference.getRange(1));
|
||||||
|
sender.sendMessage(ChatColor.GOLD + "Detailed help: " + ChatColor.WHITE + "/" + commandReference.get(0) + " help " + helpCommandReference);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,89 @@
|
|||||||
|
package fr.xephi.authme.command.executable.authme;
|
||||||
|
|
||||||
|
import fr.xephi.authme.AuthMe;
|
||||||
|
import fr.xephi.authme.ConsoleLogger;
|
||||||
|
import fr.xephi.authme.cache.auth.PlayerCache;
|
||||||
|
import fr.xephi.authme.cache.limbo.LimboCache;
|
||||||
|
import fr.xephi.authme.command.CommandParts;
|
||||||
|
import fr.xephi.authme.command.ExecutableCommand;
|
||||||
|
import fr.xephi.authme.events.SpawnTeleportEvent;
|
||||||
|
import fr.xephi.authme.settings.Messages;
|
||||||
|
import fr.xephi.authme.settings.Settings;
|
||||||
|
import fr.xephi.authme.task.MessageTask;
|
||||||
|
import fr.xephi.authme.task.TimeoutTask;
|
||||||
|
import fr.xephi.authme.util.Utils;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
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;
|
||||||
|
|
||||||
|
public class UnregisterCommand 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
|
||||||
|
public boolean executeCommand(final CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
||||||
|
// AuthMe plugin instance
|
||||||
|
final AuthMe plugin = AuthMe.getInstance();
|
||||||
|
|
||||||
|
// Messages instance
|
||||||
|
final Messages m = Messages.getInstance();
|
||||||
|
|
||||||
|
// Get the player name
|
||||||
|
String playerName = commandArguments.get(0);
|
||||||
|
String playerNameLowerCase = playerName.toLowerCase();
|
||||||
|
|
||||||
|
// Make sure the user is valid
|
||||||
|
if (!plugin.database.isAuthAvailable(playerNameLowerCase)) {
|
||||||
|
m.send(sender, "user_unknown");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove the player
|
||||||
|
if (!plugin.database.removeAuth(playerNameLowerCase)) {
|
||||||
|
m.send(sender, "error");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unregister the player
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
Player target = Bukkit.getPlayer(playerNameLowerCase);
|
||||||
|
PlayerCache.getInstance().removePlayer(playerNameLowerCase);
|
||||||
|
Utils.setGroup(target, Utils.GroupType.UNREGISTERED);
|
||||||
|
if (target != null && target.isOnline()) {
|
||||||
|
Utils.teleportToSpawn(target);
|
||||||
|
LimboCache.getInstance().addLimboPlayer(target);
|
||||||
|
int delay = Settings.getRegistrationTimeout * 20;
|
||||||
|
int interval = Settings.getWarnMessageInterval;
|
||||||
|
BukkitScheduler scheduler = sender.getServer().getScheduler();
|
||||||
|
if (delay != 0) {
|
||||||
|
BukkitTask id = scheduler.runTaskLaterAsynchronously(plugin, new TimeoutTask(plugin, playerNameLowerCase, target), delay);
|
||||||
|
LimboCache.getInstance().getLimboPlayer(playerNameLowerCase).setTimeoutTaskId(id);
|
||||||
|
}
|
||||||
|
LimboCache.getInstance().getLimboPlayer(playerNameLowerCase).setMessageTaskId(scheduler.runTaskAsynchronously(plugin, new MessageTask(plugin, playerNameLowerCase, m.send("reg_msg"), interval)));
|
||||||
|
if (Settings.applyBlindEffect)
|
||||||
|
target.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, Settings.getRegistrationTimeout * 20, 2));
|
||||||
|
if (!Settings.isMovementAllowed && Settings.isRemoveSpeedEnabled) {
|
||||||
|
target.setWalkSpeed(0.0f);
|
||||||
|
target.setFlySpeed(0.0f);
|
||||||
|
}
|
||||||
|
m.send(target, "unregistered");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Show a status message
|
||||||
|
m.send(sender, "unregistered");
|
||||||
|
ConsoleLogger.info(playerName + " unregistered");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,82 @@
|
|||||||
|
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.command.CommandParts;
|
||||||
|
import fr.xephi.authme.command.ExecutableCommand;
|
||||||
|
|
||||||
|
public class VersionCommand 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
|
||||||
|
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
||||||
|
// Show some version info
|
||||||
|
sender.sendMessage(ChatColor.GOLD + "==========[ " + AuthMe.PLUGIN_NAME.toUpperCase() + " ABOUT ]==========");
|
||||||
|
sender.sendMessage(ChatColor.GOLD + "Version: " + ChatColor.WHITE + AuthMe.PLUGIN_NAME + " v" + AuthMe.getVersionName() + ChatColor.GRAY + " (code: " + AuthMe.getVersionCode() + ")");
|
||||||
|
sender.sendMessage(ChatColor.GOLD + "Developers:");
|
||||||
|
printDeveloper(sender, "Xephi", "xephi59", "Lead Developer");
|
||||||
|
printDeveloper(sender, "DNx5", "DNx5", "Developer");
|
||||||
|
printDeveloper(sender, "games647", "games647", "Developer");
|
||||||
|
printDeveloper(sender, "Tim Visee", "timvisee", "Developer");
|
||||||
|
printDeveloper(sender, "Sgdc3", "sgdc3", "Project manager, Contributor");
|
||||||
|
sender.sendMessage(ChatColor.GOLD + "Website: " + ChatColor.WHITE + "http://dev.bukkit.org/bukkit-plugins/authme-reloaded/");
|
||||||
|
sender.sendMessage(ChatColor.GOLD + "License: " + ChatColor.WHITE + "GNU GPL v3.0" + ChatColor.GRAY + ChatColor.ITALIC + " (See LICENSE file)");
|
||||||
|
sender.sendMessage(ChatColor.GOLD + "Copyright: " + ChatColor.WHITE + "Copyright (c) Xephi 2015. All rights reserved.");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Print a developer with proper styling.
|
||||||
|
*
|
||||||
|
* @param sender The command sender.
|
||||||
|
* @param name The display name of the developer.
|
||||||
|
* @param minecraftName The Minecraft username of the developer, if available.
|
||||||
|
* @param function The function of the developer.
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("StringConcatenationInsideStringBufferAppend")
|
||||||
|
private void printDeveloper(CommandSender sender, String name, String minecraftName, String function) {
|
||||||
|
// Print the name
|
||||||
|
StringBuilder msg = new StringBuilder();
|
||||||
|
msg.append(" " + ChatColor.WHITE);
|
||||||
|
msg.append(name);
|
||||||
|
|
||||||
|
// Append the Minecraft name, if available
|
||||||
|
if(minecraftName.length() != 0)
|
||||||
|
msg.append(ChatColor.GRAY + " // " + ChatColor.WHITE + minecraftName);
|
||||||
|
msg.append(ChatColor.GRAY + "" + ChatColor.ITALIC + " (" + function + ")");
|
||||||
|
|
||||||
|
// Show the online status
|
||||||
|
if(minecraftName.length() != 0)
|
||||||
|
if(isPlayerOnline(minecraftName))
|
||||||
|
msg.append(ChatColor.GREEN + "" + ChatColor.ITALIC + " (In-Game)");
|
||||||
|
|
||||||
|
// Print the message
|
||||||
|
sender.sendMessage(msg.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check whether a player is online.
|
||||||
|
*
|
||||||
|
* @param minecraftName The Minecraft player name.
|
||||||
|
*
|
||||||
|
* @return True if the player is online, false otherwise.
|
||||||
|
*/
|
||||||
|
private boolean isPlayerOnline(String minecraftName) {
|
||||||
|
for(Player player : Bukkit.getOnlinePlayers())
|
||||||
|
if(player.getName().equalsIgnoreCase(minecraftName))
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,83 @@
|
|||||||
|
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.cache.auth.PlayerCache;
|
||||||
|
import fr.xephi.authme.command.CommandParts;
|
||||||
|
import fr.xephi.authme.command.ExecutableCommand;
|
||||||
|
import fr.xephi.authme.security.RandomString;
|
||||||
|
import fr.xephi.authme.settings.Messages;
|
||||||
|
import fr.xephi.authme.settings.Settings;
|
||||||
|
|
||||||
|
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
|
||||||
|
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
|
||||||
|
if(!(sender instanceof Player)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the player instance and name
|
||||||
|
final Player player = (Player) sender;
|
||||||
|
final String playerNameLowerCase = player.getName().toLowerCase();
|
||||||
|
|
||||||
|
// Command logic
|
||||||
|
if (PlayerCache.getInstance().isAuthenticated(playerNameLowerCase)) {
|
||||||
|
m.send(player, "logged_in");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!Settings.useCaptcha) {
|
||||||
|
m.send(player, "usage_log");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!plugin.cap.containsKey(playerNameLowerCase)) {
|
||||||
|
m.send(player, "usage_log");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Settings.useCaptcha && !captcha.equals(plugin.cap.get(playerNameLowerCase))) {
|
||||||
|
plugin.cap.remove(playerNameLowerCase);
|
||||||
|
plugin.cap.put(playerNameLowerCase, randStr.nextString());
|
||||||
|
for (String s : m.send("wrong_captcha")) {
|
||||||
|
player.sendMessage(s.replace("THE_CAPTCHA", plugin.cap.get(playerNameLowerCase)));
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
plugin.captcha.remove(playerNameLowerCase);
|
||||||
|
plugin.cap.remove(playerNameLowerCase);
|
||||||
|
} catch (NullPointerException ignored) { }
|
||||||
|
|
||||||
|
// Show a status message
|
||||||
|
m.send(player, "valid_captcha");
|
||||||
|
m.send(player, "login_msg");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,75 @@
|
|||||||
|
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.cache.auth.PlayerCache;
|
||||||
|
import fr.xephi.authme.command.CommandParts;
|
||||||
|
import fr.xephi.authme.command.ExecutableCommand;
|
||||||
|
import fr.xephi.authme.settings.Messages;
|
||||||
|
import fr.xephi.authme.settings.Settings;
|
||||||
|
import fr.xephi.authme.task.ChangePasswordTask;
|
||||||
|
|
||||||
|
public class ChangePasswordCommand 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
|
||||||
|
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
||||||
|
// AuthMe plugin instance
|
||||||
|
final AuthMe plugin = AuthMe.getInstance();
|
||||||
|
|
||||||
|
// Messages instance
|
||||||
|
final Messages m = Messages.getInstance();
|
||||||
|
|
||||||
|
// Get the passwords
|
||||||
|
String playerPass = commandArguments.get(0);
|
||||||
|
String playerPassVerify = commandArguments.get(1);
|
||||||
|
|
||||||
|
// Make sure the current command executor is a player
|
||||||
|
if(!(sender instanceof Player)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the player instance and make sure it's authenticated
|
||||||
|
Player player = (Player) sender;
|
||||||
|
String name = player.getName().toLowerCase();
|
||||||
|
if (!PlayerCache.getInstance().isAuthenticated(name)) {
|
||||||
|
m.send(player, "not_logged_in");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make sure the password is allowed
|
||||||
|
String playerPassLowerCase = playerPass.toLowerCase();
|
||||||
|
if (playerPassLowerCase.contains("delete") || playerPassLowerCase.contains("where") || playerPassLowerCase.contains("insert") || playerPassLowerCase.contains("modify") || playerPassLowerCase.contains("from") || playerPassLowerCase.contains("select") || playerPassLowerCase.contains(";") || playerPassLowerCase.contains("null") || !playerPassLowerCase.matches(Settings.getPassRegex)) {
|
||||||
|
m.send(player, "password_error");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (playerPassLowerCase.equalsIgnoreCase(name)) {
|
||||||
|
m.send(player, "password_error_nick");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (playerPassLowerCase.length() < Settings.getPasswordMinLen || playerPassLowerCase.length() > Settings.passwordMaxLength) {
|
||||||
|
m.send(player, "pass_len");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (!Settings.unsafePasswords.isEmpty()) {
|
||||||
|
if (Settings.unsafePasswords.contains(playerPassLowerCase)) {
|
||||||
|
m.send(player, "password_error_unsafe");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set the password
|
||||||
|
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new ChangePasswordTask(plugin, player, playerPass, playerPassVerify));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,116 @@
|
|||||||
|
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.command.CommandParts;
|
||||||
|
import fr.xephi.authme.command.ExecutableCommand;
|
||||||
|
import fr.xephi.authme.converter.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;
|
||||||
|
|
||||||
|
public class ConverterCommand 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
|
||||||
|
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
||||||
|
// AuthMe plugin instance
|
||||||
|
final AuthMe plugin = AuthMe.getInstance();
|
||||||
|
|
||||||
|
// Messages instance
|
||||||
|
final Messages m = Messages.getInstance();
|
||||||
|
|
||||||
|
// Get the conversion job
|
||||||
|
String job = commandArguments.get(0);
|
||||||
|
|
||||||
|
// Determine the job type
|
||||||
|
ConvertType jobType = ConvertType.fromName(job);
|
||||||
|
if (jobType == null) {
|
||||||
|
m.send(sender, "error");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the proper converter instance
|
||||||
|
Converter converter = null;
|
||||||
|
switch (jobType) {
|
||||||
|
case ftsql:
|
||||||
|
converter = new FlatToSql();
|
||||||
|
break;
|
||||||
|
case ftsqlite:
|
||||||
|
converter = new FlatToSqlite(sender);
|
||||||
|
break;
|
||||||
|
case xauth:
|
||||||
|
converter = new xAuthConverter(plugin, sender);
|
||||||
|
break;
|
||||||
|
case crazylogin:
|
||||||
|
converter = new CrazyLoginConverter(plugin, sender);
|
||||||
|
break;
|
||||||
|
case rakamak:
|
||||||
|
converter = new RakamakConverter(plugin, sender);
|
||||||
|
break;
|
||||||
|
case royalauth:
|
||||||
|
converter = new RoyalAuthConverter(plugin);
|
||||||
|
break;
|
||||||
|
case vauth:
|
||||||
|
converter = new vAuthConverter(plugin, sender);
|
||||||
|
break;
|
||||||
|
case sqltoflat:
|
||||||
|
converter = new SqlToFlat(plugin, sender);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Run the convert job
|
||||||
|
Bukkit.getScheduler().runTaskAsynchronously(plugin, converter);
|
||||||
|
|
||||||
|
// Show a status message
|
||||||
|
sender.sendMessage("[AuthMe] Successfully converted from " + jobType.getName());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum ConvertType {
|
||||||
|
ftsql("flattosql"),
|
||||||
|
ftsqlite("flattosqlite"),
|
||||||
|
xauth("xauth"),
|
||||||
|
crazylogin("crazylogin"),
|
||||||
|
rakamak("rakamak"),
|
||||||
|
royalauth("royalauth"),
|
||||||
|
vauth("vauth"),
|
||||||
|
sqltoflat("sqltoflat");
|
||||||
|
|
||||||
|
String name;
|
||||||
|
|
||||||
|
ConvertType(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
String getName() {
|
||||||
|
return this.name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ConvertType fromName(String name) {
|
||||||
|
for (ConvertType type : ConvertType.values()) {
|
||||||
|
if (type.getName().equalsIgnoreCase(name))
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,45 @@
|
|||||||
|
package fr.xephi.authme.command.executable.email;
|
||||||
|
|
||||||
|
import fr.xephi.authme.AuthMe;
|
||||||
|
import fr.xephi.authme.command.CommandParts;
|
||||||
|
import fr.xephi.authme.command.ExecutableCommand;
|
||||||
|
import fr.xephi.authme.settings.Messages;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public class AddEmailCommand 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
|
||||||
|
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
||||||
|
// AuthMe plugin instance
|
||||||
|
final AuthMe plugin = AuthMe.getInstance();
|
||||||
|
|
||||||
|
// Messages instance
|
||||||
|
final Messages m = Messages.getInstance();
|
||||||
|
|
||||||
|
// Get the parameter values
|
||||||
|
String playerMail = commandArguments.get(0);
|
||||||
|
String playerMailVerify = commandArguments.get(1);
|
||||||
|
|
||||||
|
// Make sure the current command executor is a player
|
||||||
|
if (!(sender instanceof Player)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the player instance and name
|
||||||
|
final Player player = (Player) sender;
|
||||||
|
final String playerName = player.getName().toLowerCase();
|
||||||
|
|
||||||
|
// Command logic
|
||||||
|
plugin.management.performAddEmail(player, playerMail, playerMailVerify);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,45 @@
|
|||||||
|
package fr.xephi.authme.command.executable.email;
|
||||||
|
|
||||||
|
import fr.xephi.authme.AuthMe;
|
||||||
|
import fr.xephi.authme.command.CommandParts;
|
||||||
|
import fr.xephi.authme.command.ExecutableCommand;
|
||||||
|
import fr.xephi.authme.settings.Messages;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public class ChangeEmailCommand 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
|
||||||
|
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
||||||
|
// AuthMe plugin instance
|
||||||
|
final AuthMe plugin = AuthMe.getInstance();
|
||||||
|
|
||||||
|
// Messages instance
|
||||||
|
final Messages m = Messages.getInstance();
|
||||||
|
|
||||||
|
// Get the parameter values
|
||||||
|
String playerMailOld = commandArguments.get(0);
|
||||||
|
String playerMailNew = commandArguments.get(1);
|
||||||
|
|
||||||
|
// Make sure the current command executor is a player
|
||||||
|
if (!(sender instanceof Player)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the player instance and name
|
||||||
|
final Player player = (Player) sender;
|
||||||
|
final String playerName = player.getName();
|
||||||
|
|
||||||
|
// Command logic
|
||||||
|
plugin.management.performChangeEmail(player, playerMailOld, playerMailNew);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,97 @@
|
|||||||
|
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.ConsoleLogger;
|
||||||
|
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||||
|
import fr.xephi.authme.cache.auth.PlayerCache;
|
||||||
|
import fr.xephi.authme.command.CommandParts;
|
||||||
|
import fr.xephi.authme.command.ExecutableCommand;
|
||||||
|
import fr.xephi.authme.security.PasswordSecurity;
|
||||||
|
import fr.xephi.authme.security.RandomString;
|
||||||
|
import fr.xephi.authme.settings.Messages;
|
||||||
|
import fr.xephi.authme.settings.Settings;
|
||||||
|
|
||||||
|
public class RecoverEmailCommand 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
|
||||||
|
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
||||||
|
// AuthMe plugin instance
|
||||||
|
final AuthMe plugin = AuthMe.getInstance();
|
||||||
|
|
||||||
|
// Messages instance
|
||||||
|
final Messages m = Messages.getInstance();
|
||||||
|
|
||||||
|
// Get the parameter values
|
||||||
|
String playerMail = commandArguments.get(0);
|
||||||
|
|
||||||
|
// Make sure the current command executor is a player
|
||||||
|
if(!(sender instanceof Player)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the player instance and name
|
||||||
|
final Player player = (Player) sender;
|
||||||
|
final String playerName = player.getName();
|
||||||
|
|
||||||
|
// Command logic
|
||||||
|
if (plugin.mail == null) {
|
||||||
|
m.send(player, "error");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (plugin.database.isAuthAvailable(playerName)) {
|
||||||
|
if (PlayerCache.getInstance().isAuthenticated(playerName)) {
|
||||||
|
m.send(player, "logged_in");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
RandomString rand = new RandomString(Settings.getRecoveryPassLength);
|
||||||
|
String thePass = rand.nextString();
|
||||||
|
String hashNew = PasswordSecurity.getHash(Settings.getPasswordHash, thePass, playerName);
|
||||||
|
PlayerAuth auth;
|
||||||
|
if (PlayerCache.getInstance().isAuthenticated(playerName)) {
|
||||||
|
auth = PlayerCache.getInstance().getAuth(playerName);
|
||||||
|
} else if (plugin.database.isAuthAvailable(playerName)) {
|
||||||
|
auth = plugin.database.getAuth(playerName);
|
||||||
|
} else {
|
||||||
|
m.send(player, "unknown_user");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (Settings.getmailAccount.equals("") || Settings.getmailAccount.isEmpty()) {
|
||||||
|
m.send(player, "error");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!playerMail.equalsIgnoreCase(auth.getEmail()) || playerMail.equalsIgnoreCase("your@email.com") || auth.getEmail().equalsIgnoreCase("your@email.com")) {
|
||||||
|
m.send(player, "email_invalid");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
auth.setHash(hashNew);
|
||||||
|
plugin.database.updatePassword(auth);
|
||||||
|
plugin.mail.main(auth, thePass);
|
||||||
|
m.send(player, "email_send");
|
||||||
|
} catch (NoSuchAlgorithmException | NoClassDefFoundError ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
ConsoleLogger.showError(ex.getMessage());
|
||||||
|
m.send(sender, "error");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
m.send(player, "reg_email_msg");
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,41 @@
|
|||||||
|
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.command.CommandParts;
|
||||||
|
import fr.xephi.authme.command.ExecutableCommand;
|
||||||
|
|
||||||
|
public class LoginCommand 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
|
||||||
|
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
||||||
|
// AuthMe plugin instance
|
||||||
|
final AuthMe plugin = AuthMe.getInstance();
|
||||||
|
|
||||||
|
// Make sure the current command executor is a player
|
||||||
|
if(!(sender instanceof Player)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the player instance
|
||||||
|
final Player player = (Player) sender;
|
||||||
|
|
||||||
|
// Get the password
|
||||||
|
String playerPass = commandArguments.get(0);
|
||||||
|
|
||||||
|
// Login the player
|
||||||
|
plugin.management.performLogin(player, playerPass, false);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,38 @@
|
|||||||
|
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.command.CommandParts;
|
||||||
|
import fr.xephi.authme.command.ExecutableCommand;
|
||||||
|
|
||||||
|
public class LogoutCommand 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
|
||||||
|
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
||||||
|
// AuthMe plugin instance
|
||||||
|
final AuthMe plugin = AuthMe.getInstance();
|
||||||
|
|
||||||
|
// Make sure the current command executor is a player
|
||||||
|
if(!(sender instanceof Player)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the player instance
|
||||||
|
final Player player = (Player) sender;
|
||||||
|
|
||||||
|
// Logout the player
|
||||||
|
plugin.management.performLogout(player);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,70 @@
|
|||||||
|
package fr.xephi.authme.command.executable.register;
|
||||||
|
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import fr.xephi.authme.AuthMe;
|
||||||
|
import fr.xephi.authme.command.CommandParts;
|
||||||
|
import fr.xephi.authme.command.ExecutableCommand;
|
||||||
|
import fr.xephi.authme.security.RandomString;
|
||||||
|
import fr.xephi.authme.settings.Messages;
|
||||||
|
import fr.xephi.authme.settings.Settings;
|
||||||
|
|
||||||
|
public class RegisterCommand 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
|
||||||
|
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
||||||
|
// AuthMe plugin instance
|
||||||
|
final AuthMe plugin = AuthMe.getInstance();
|
||||||
|
|
||||||
|
// Messages instance
|
||||||
|
final Messages m = Messages.getInstance();
|
||||||
|
|
||||||
|
// Make sure the sender is a player
|
||||||
|
if (!(sender instanceof Player)) {
|
||||||
|
sender.sendMessage("Player Only! Use 'authme register <playername> <password>' instead");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make sure the command arguments are valid
|
||||||
|
final Player player = (Player) sender;
|
||||||
|
if (commandArguments.getCount() == 0 || (Settings.getEnablePasswordVerifier && commandArguments.getCount() < 2)) {
|
||||||
|
m.send(player, "usage_reg");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Settings.emailRegistration && !Settings.getmailAccount.isEmpty()) {
|
||||||
|
if (Settings.doubleEmailCheck) {
|
||||||
|
if (commandArguments.getCount() < 2 || !commandArguments.get(0).equals(commandArguments.get(1))) {
|
||||||
|
m.send(player, "usage_reg");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
final String email = commandArguments.get(0);
|
||||||
|
if (!Settings.isEmailCorrect(email)) {
|
||||||
|
m.send(player, "email_invalid");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
RandomString rand = new RandomString(Settings.getRecoveryPassLength);
|
||||||
|
final String thePass = rand.nextString();
|
||||||
|
plugin.management.performRegister(player, thePass, email);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (commandArguments.getCount() > 1 && Settings.getEnablePasswordVerifier)
|
||||||
|
if (!commandArguments.get(0).equals(commandArguments.get(1))) {
|
||||||
|
m.send(player, "password_error");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
plugin.management.performRegister(player, commandArguments.get(0), "");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,53 @@
|
|||||||
|
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.cache.auth.PlayerCache;
|
||||||
|
import fr.xephi.authme.command.CommandParts;
|
||||||
|
import fr.xephi.authme.command.ExecutableCommand;
|
||||||
|
import fr.xephi.authme.settings.Messages;
|
||||||
|
|
||||||
|
public class UnregisterCommand 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
|
||||||
|
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
||||||
|
// AuthMe plugin instance
|
||||||
|
final AuthMe plugin = AuthMe.getInstance();
|
||||||
|
|
||||||
|
// Messages instance
|
||||||
|
final Messages m = Messages.getInstance();
|
||||||
|
|
||||||
|
// Make sure the current command executor is a player
|
||||||
|
if(!(sender instanceof Player)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the password
|
||||||
|
String playerPass = commandArguments.get(0);
|
||||||
|
|
||||||
|
// Get the player instance and name
|
||||||
|
final Player player = (Player) sender;
|
||||||
|
final String playerNameLowerCase = player.getName().toLowerCase();
|
||||||
|
|
||||||
|
// Make sure the player is authenticated
|
||||||
|
if (!PlayerCache.getInstance().isAuthenticated(playerNameLowerCase)) {
|
||||||
|
m.send(player, "not_logged_in");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unregister the player
|
||||||
|
plugin.management.performUnregister(player, playerPass, false);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
196
src/main/java/fr/xephi/authme/command/help/HelpPrinter.java
Normal file
196
src/main/java/fr/xephi/authme/command/help/HelpPrinter.java
Normal file
@ -0,0 +1,196 @@
|
|||||||
|
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.command.CommandArgumentDescription;
|
||||||
|
import fr.xephi.authme.command.CommandDescription;
|
||||||
|
import fr.xephi.authme.command.CommandParts;
|
||||||
|
import fr.xephi.authme.command.CommandPermissions;
|
||||||
|
import fr.xephi.authme.util.StringUtils;
|
||||||
|
|
||||||
|
public class HelpPrinter {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Print the command help information.
|
||||||
|
*
|
||||||
|
* @param sender The command sender to print the help to.
|
||||||
|
* @param command The command to print.
|
||||||
|
* @param commandReference The command reference used.
|
||||||
|
*/
|
||||||
|
public static void printCommand(CommandSender sender, CommandDescription command, CommandParts commandReference) {
|
||||||
|
// Print the proper command syntax
|
||||||
|
sender.sendMessage(ChatColor.GOLD + "Command: " + HelpSyntaxHelper.getCommandSyntax(command, commandReference, null, true));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 command The command to print the description help for.
|
||||||
|
*/
|
||||||
|
public static void printCommandDescription(CommandSender sender, CommandDescription command) {
|
||||||
|
// Print the regular description, if available
|
||||||
|
if(command.hasDescription())
|
||||||
|
sender.sendMessage(ChatColor.GOLD + "Short Description: " + ChatColor.WHITE + command.getDescription());
|
||||||
|
|
||||||
|
// Print the detailed description, if available
|
||||||
|
if(command.hasDetailedDescription()) {
|
||||||
|
sender.sendMessage(ChatColor.GOLD + "Detailed Description:");
|
||||||
|
sender.sendMessage(ChatColor.WHITE + " " + command.getDetailedDescription());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Print the command help arguments information if available.
|
||||||
|
*
|
||||||
|
* @param sender The command sender to print the help to.
|
||||||
|
* @param command The command to print the argument help for.
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("StringConcatenationInsideStringBufferAppend")
|
||||||
|
public static void printArguments(CommandSender sender, CommandDescription command) {
|
||||||
|
// Make sure there are any commands to print
|
||||||
|
if(!command.hasArguments() && command.getMaximumArguments() >= 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// Print the header
|
||||||
|
sender.sendMessage(ChatColor.GOLD + "Arguments:");
|
||||||
|
|
||||||
|
// Print each argument
|
||||||
|
for(CommandArgumentDescription arg : command.getArguments()) {
|
||||||
|
// Create a string builder to build the syntax in
|
||||||
|
StringBuilder argString = new StringBuilder();
|
||||||
|
argString.append(" " + ChatColor.YELLOW + ChatColor.ITALIC + arg.getLabel() + " : " + ChatColor.WHITE + arg.getDescription());
|
||||||
|
|
||||||
|
// Suffix a note if the command is optional
|
||||||
|
if(arg.isOptional())
|
||||||
|
argString.append(ChatColor.GRAY + "" + ChatColor.ITALIC + " (Optional)");
|
||||||
|
|
||||||
|
// Print the syntax
|
||||||
|
sender.sendMessage(argString.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Show the unlimited arguments argument
|
||||||
|
if(command.getMaximumArguments() < 0)
|
||||||
|
sender.sendMessage(" " + ChatColor.YELLOW + ChatColor.ITALIC + "... : " + ChatColor.WHITE + "Any additional arguments." + ChatColor.GRAY + ChatColor.ITALIC + " (Optional)");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Print the command help permissions information if available.
|
||||||
|
*
|
||||||
|
* @param sender The command sender to print the help to.
|
||||||
|
* @param command The command to print the permissions help for.
|
||||||
|
*/
|
||||||
|
public static void printPermissions(CommandSender sender, CommandDescription command) {
|
||||||
|
// Get the permissions and make sure it isn't null
|
||||||
|
CommandPermissions permissions = command.getCommandPermissions();
|
||||||
|
if(permissions == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// Make sure any permission node is set
|
||||||
|
if(permissions.getPermissionNodeCount() <= 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// Print the header
|
||||||
|
sender.sendMessage(ChatColor.GOLD + "Permissions:");
|
||||||
|
|
||||||
|
// Print each node
|
||||||
|
for(String node : permissions.getPermissionNodes()) {
|
||||||
|
boolean nodePermission = true;
|
||||||
|
if(sender instanceof Player)
|
||||||
|
nodePermission = AuthMe.getInstance().authmePermissible((Player) sender, node);
|
||||||
|
final String nodePermsString = ChatColor.GRAY + (nodePermission ? ChatColor.ITALIC + " (Permission!)" : ChatColor.ITALIC + " (No Permission!)");
|
||||||
|
sender.sendMessage(" " + ChatColor.YELLOW + ChatColor.ITALIC + node + nodePermsString);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Print the default permission
|
||||||
|
switch(permissions.getDefaultPermission()) {
|
||||||
|
case ALLOWED:
|
||||||
|
sender.sendMessage(ChatColor.GOLD + " Default: " + ChatColor.GRAY + ChatColor.ITALIC + "Permission!");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case OP_ONLY:
|
||||||
|
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);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case NOT_ALLOWED:
|
||||||
|
default:
|
||||||
|
sender.sendMessage(ChatColor.GOLD + " Default: " + ChatColor.GRAY + ChatColor.ITALIC + "No Permission!");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Print the permission result
|
||||||
|
if(permissions.hasPermission(sender))
|
||||||
|
sender.sendMessage(ChatColor.GOLD + " Result: " + ChatColor.GREEN + ChatColor.ITALIC + "Permission!");
|
||||||
|
else
|
||||||
|
sender.sendMessage(ChatColor.GOLD + " Result: " + ChatColor.DARK_RED + ChatColor.ITALIC + "No Permission!");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Print the command help alternatives information if available.
|
||||||
|
*
|
||||||
|
* @param sender The command sender to print the help to.
|
||||||
|
* @param command The command used.
|
||||||
|
* @param commandReference The original command reference used for this command.
|
||||||
|
*/
|
||||||
|
public static void printAlternatives(CommandSender sender, CommandDescription command, CommandParts commandReference) {
|
||||||
|
// Make sure there are any alternatives
|
||||||
|
if(command.getLabels().size() <= 1)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// Print the header
|
||||||
|
sender.sendMessage(ChatColor.GOLD + "Alternatives:");
|
||||||
|
|
||||||
|
// Get the label used
|
||||||
|
final String usedLabel = commandReference.get(command.getParentCount());
|
||||||
|
|
||||||
|
// Create a list of alternatives
|
||||||
|
List<String> alternatives = new ArrayList<>();
|
||||||
|
for(String entry : command.getLabels()) {
|
||||||
|
// Exclude the proper argument
|
||||||
|
if(entry.equalsIgnoreCase(usedLabel))
|
||||||
|
continue;
|
||||||
|
alternatives.add(entry);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sort the alternatives
|
||||||
|
Collections.sort(alternatives, new Comparator<String>() {
|
||||||
|
@Override
|
||||||
|
public int compare(String o1, String o2) {
|
||||||
|
return Double.compare(StringUtils.getDifference(usedLabel, o1), StringUtils.getDifference(usedLabel, o2));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Print each alternative with proper syntax
|
||||||
|
for(String alternative : alternatives)
|
||||||
|
sender.sendMessage(" " + HelpSyntaxHelper.getCommandSyntax(command, commandReference, alternative, true));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Print the command help child's information if available.
|
||||||
|
*
|
||||||
|
* @param sender The command sender to print the help to.
|
||||||
|
* @param command The command to print the help for.
|
||||||
|
* @param commandReference The original command reference used for this command.
|
||||||
|
*/
|
||||||
|
public static void printChildren(CommandSender sender, CommandDescription command, CommandParts commandReference) {
|
||||||
|
// Make sure there are child's
|
||||||
|
if(command.getChildren().size() <= 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// Print the header
|
||||||
|
sender.sendMessage(ChatColor.GOLD + "Commands:");
|
||||||
|
|
||||||
|
// Loop through each child
|
||||||
|
for(CommandDescription child : command.getChildren())
|
||||||
|
sender.sendMessage(" " + HelpSyntaxHelper.getCommandSyntax(child, commandReference, null, false) + ChatColor.GRAY + ChatColor.ITALIC + " : " + child.getDescription());
|
||||||
|
}
|
||||||
|
}
|
||||||
117
src/main/java/fr/xephi/authme/command/help/HelpProvider.java
Normal file
117
src/main/java/fr/xephi/authme/command/help/HelpProvider.java
Normal file
@ -0,0 +1,117 @@
|
|||||||
|
package fr.xephi.authme.command.help;
|
||||||
|
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
|
import fr.xephi.authme.AuthMe;
|
||||||
|
import fr.xephi.authme.command.CommandDescription;
|
||||||
|
import fr.xephi.authme.command.CommandParts;
|
||||||
|
import fr.xephi.authme.command.FoundCommandResult;
|
||||||
|
|
||||||
|
public class HelpProvider {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Show help for a specific command.
|
||||||
|
*
|
||||||
|
* @param sender The command sender the help needs to be shown to.
|
||||||
|
* @param reference The command reference to the help command.
|
||||||
|
* @param helpQuery The query to show help for.
|
||||||
|
*/
|
||||||
|
public static void showHelp(CommandSender sender, CommandParts reference, CommandParts helpQuery) {
|
||||||
|
showHelp(sender, reference, helpQuery, true, true, true, true, true, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Show help for a specific command.
|
||||||
|
*
|
||||||
|
* @param sender The command sender the help needs to be shown to.
|
||||||
|
* @param reference The command reference to the help command.
|
||||||
|
* @param helpQuery The query to show help for.
|
||||||
|
* @param showCommand True to show the command.
|
||||||
|
* @param showDescription True to show the command description, both the short and detailed description.
|
||||||
|
* @param showArguments True to show the command argument help.
|
||||||
|
* @param showPermissions True to show the command permission help.
|
||||||
|
* @param showAlternatives True to show the command alternatives.
|
||||||
|
* @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) {
|
||||||
|
// 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()));
|
||||||
|
CommandParts commandReferenceOther = new CommandParts(reference.get(0), helpQuery.getList());
|
||||||
|
FoundCommandResult resultOther = AuthMe.getInstance().getCommandHandler().getCommandManager().findCommand(commandReferenceOther);
|
||||||
|
if(resultOther != null) {
|
||||||
|
if(result == null)
|
||||||
|
result = resultOther;
|
||||||
|
|
||||||
|
else if(result.getDifference() > resultOther.getDifference())
|
||||||
|
result = resultOther;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make sure a result was found
|
||||||
|
if(result == null) {
|
||||||
|
// Show a warning message
|
||||||
|
sender.sendMessage(ChatColor.DARK_RED + "" + ChatColor.ITALIC + helpQuery);
|
||||||
|
sender.sendMessage(ChatColor.DARK_RED + "Couldn't show any help information for this help query.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the command description, and make sure it's valid
|
||||||
|
CommandDescription command = result.getCommandDescription();
|
||||||
|
if(command == null) {
|
||||||
|
// Show a warning message
|
||||||
|
sender.sendMessage(ChatColor.DARK_RED + "Failed to retrieve any help information!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the proper command reference to use for the help page
|
||||||
|
CommandParts commandReference = command.getCommandReference(result.getQueryReference());
|
||||||
|
|
||||||
|
// Get the base command
|
||||||
|
String baseCommand = commandReference.get(0);
|
||||||
|
|
||||||
|
// Make sure the difference between the command reference and the actual command isn't too big
|
||||||
|
final double commandDifference = result.getDifference();
|
||||||
|
if(commandDifference > 0.20) {
|
||||||
|
// Show the unknown command warning
|
||||||
|
sender.sendMessage(ChatColor.DARK_RED + "No help found for '" + helpQuery + "'!");
|
||||||
|
|
||||||
|
// Get the suggested command
|
||||||
|
CommandParts suggestedCommandParts = new CommandParts(result.getCommandDescription().getCommandReference(commandReference).getRange(1));
|
||||||
|
|
||||||
|
// Show a command suggestion if available and the difference isn't too big
|
||||||
|
if(commandDifference < 0.75)
|
||||||
|
if(result.getCommandDescription() != null)
|
||||||
|
sender.sendMessage(ChatColor.YELLOW + "Did you mean " + ChatColor.GOLD + "/" + baseCommand + " help " + suggestedCommandParts + ChatColor.YELLOW + "?");
|
||||||
|
|
||||||
|
// Show the help command
|
||||||
|
sender.sendMessage(ChatColor.YELLOW + "Use the command " + ChatColor.GOLD + "/" + baseCommand + " help" + ChatColor.YELLOW + " to view help.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Show a message when the command handler is assuming a command
|
||||||
|
if(commandDifference > 0) {
|
||||||
|
// Get the suggested command
|
||||||
|
CommandParts suggestedCommandParts = new CommandParts(result.getCommandDescription().getCommandReference(commandReference).getRange(1));
|
||||||
|
|
||||||
|
// Show the suggested command
|
||||||
|
sender.sendMessage(ChatColor.DARK_RED + "No help found, assuming '" + ChatColor.GOLD + suggestedCommandParts + ChatColor.DARK_RED + "'!");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Print the help header
|
||||||
|
sender.sendMessage(ChatColor.GOLD + "==========[ " + AuthMe.PLUGIN_NAME.toUpperCase() + " HELP ]==========");
|
||||||
|
|
||||||
|
// Print the command help information
|
||||||
|
if(showCommand)
|
||||||
|
HelpPrinter.printCommand(sender, command, commandReference);
|
||||||
|
if(showDescription)
|
||||||
|
HelpPrinter.printCommandDescription(sender, command);
|
||||||
|
if(showArguments)
|
||||||
|
HelpPrinter.printArguments(sender, command);
|
||||||
|
if(showPermissions)
|
||||||
|
HelpPrinter.printPermissions(sender, command);
|
||||||
|
if(showAlternatives)
|
||||||
|
HelpPrinter.printAlternatives(sender, command, commandReference);
|
||||||
|
if(showCommands)
|
||||||
|
HelpPrinter.printChildren(sender, command, commandReference);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,61 @@
|
|||||||
|
package fr.xephi.authme.command.help;
|
||||||
|
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
|
||||||
|
import fr.xephi.authme.command.CommandArgumentDescription;
|
||||||
|
import fr.xephi.authme.command.CommandDescription;
|
||||||
|
import fr.xephi.authme.command.CommandParts;
|
||||||
|
import fr.xephi.authme.util.ListUtils;
|
||||||
|
|
||||||
|
public class HelpSyntaxHelper {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the proper syntax for a command.
|
||||||
|
*
|
||||||
|
* @param commandDescription The command to get the syntax for.
|
||||||
|
* @param commandReference The reference of the command.
|
||||||
|
* @param alternativeLabel The alternative label to use for this command syntax.
|
||||||
|
* @param highlight True to highlight the important parts of this command.
|
||||||
|
*
|
||||||
|
* @return The command with proper syntax.
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("StringConcatenationInsideStringBufferAppend")
|
||||||
|
public static String getCommandSyntax(CommandDescription commandDescription, CommandParts commandReference, String alternativeLabel, boolean highlight) {
|
||||||
|
// Create a string builder to build the command
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
|
||||||
|
// Set the color and prefix a slash
|
||||||
|
sb.append(ChatColor.WHITE + "/");
|
||||||
|
|
||||||
|
// Get the help command reference, and the command label
|
||||||
|
CommandParts helpCommandReference = commandDescription.getCommandReference(commandReference);
|
||||||
|
final String parentCommand = (new CommandParts(helpCommandReference.getRange(0, helpCommandReference.getCount() - 1))).toString();
|
||||||
|
String commandLabel = helpCommandReference.get(helpCommandReference.getCount() - 1);
|
||||||
|
|
||||||
|
// Check whether the alternative label should be used
|
||||||
|
if(alternativeLabel != null)
|
||||||
|
if(alternativeLabel.trim().length() > 0)
|
||||||
|
commandLabel = alternativeLabel;
|
||||||
|
|
||||||
|
// Show the important bit of the command, highlight this part if required
|
||||||
|
sb.append(ListUtils.implode(parentCommand, (highlight ? ChatColor.YELLOW + "" + ChatColor.BOLD : "") + commandLabel, " "));
|
||||||
|
if(highlight)
|
||||||
|
sb.append(ChatColor.YELLOW);
|
||||||
|
|
||||||
|
// Add each command arguments
|
||||||
|
for(CommandArgumentDescription arg : commandDescription.getArguments()) {
|
||||||
|
// Add the argument as optional or non-optional argument
|
||||||
|
if(!arg.isOptional())
|
||||||
|
sb.append(ChatColor.ITALIC + " <" + arg.getLabel() + ">");
|
||||||
|
else
|
||||||
|
sb.append(ChatColor.ITALIC + " [" + arg.getLabel() + "]");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add some dots if the command allows unlimited arguments
|
||||||
|
if(commandDescription.getMaximumArguments() < 0)
|
||||||
|
sb.append(ChatColor.ITALIC + " ...");
|
||||||
|
|
||||||
|
// Return the build command syntax
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,11 +1,19 @@
|
|||||||
package fr.xephi.authme.commands;
|
package fr.xephi.authme.commands;
|
||||||
|
|
||||||
import java.security.NoSuchAlgorithmException;
|
import fr.xephi.authme.AuthMe;
|
||||||
import java.util.ArrayList;
|
import fr.xephi.authme.ConsoleLogger;
|
||||||
import java.util.Calendar;
|
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||||
import java.util.Date;
|
import fr.xephi.authme.cache.auth.PlayerCache;
|
||||||
import java.util.List;
|
import fr.xephi.authme.cache.limbo.LimboCache;
|
||||||
|
import fr.xephi.authme.events.SpawnTeleportEvent;
|
||||||
|
import fr.xephi.authme.security.PasswordSecurity;
|
||||||
|
import fr.xephi.authme.settings.Messages;
|
||||||
|
import fr.xephi.authme.settings.Settings;
|
||||||
|
import fr.xephi.authme.settings.Spawn;
|
||||||
|
import fr.xephi.authme.task.MessageTask;
|
||||||
|
import fr.xephi.authme.task.TimeoutTask;
|
||||||
|
import fr.xephi.authme.util.Utils;
|
||||||
|
import fr.xephi.authme.util.Utils.GroupType;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
@ -18,20 +26,11 @@ import org.bukkit.potion.PotionEffectType;
|
|||||||
import org.bukkit.scheduler.BukkitScheduler;
|
import org.bukkit.scheduler.BukkitScheduler;
|
||||||
import org.bukkit.scheduler.BukkitTask;
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
|
|
||||||
import fr.xephi.authme.AuthMe;
|
import java.security.NoSuchAlgorithmException;
|
||||||
import fr.xephi.authme.ConsoleLogger;
|
import java.util.ArrayList;
|
||||||
import fr.xephi.authme.Utils;
|
import java.util.Calendar;
|
||||||
import fr.xephi.authme.Utils.GroupType;
|
import java.util.Date;
|
||||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
import java.util.List;
|
||||||
import fr.xephi.authme.cache.auth.PlayerCache;
|
|
||||||
import fr.xephi.authme.cache.limbo.LimboCache;
|
|
||||||
import fr.xephi.authme.events.SpawnTeleportEvent;
|
|
||||||
import fr.xephi.authme.security.PasswordSecurity;
|
|
||||||
import fr.xephi.authme.settings.Messages;
|
|
||||||
import fr.xephi.authme.settings.Settings;
|
|
||||||
import fr.xephi.authme.settings.Spawn;
|
|
||||||
import fr.xephi.authme.task.MessageTask;
|
|
||||||
import fr.xephi.authme.task.TimeoutTask;
|
|
||||||
|
|
||||||
public class AdminCommand implements CommandExecutor {
|
public class AdminCommand implements CommandExecutor {
|
||||||
|
|
||||||
@ -195,7 +194,7 @@ public class AdminCommand implements CommandExecutor {
|
|||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
final String[] arguments = args;
|
final String[] arguments = args;
|
||||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
|
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
StringBuilder message = new StringBuilder("[AuthMe] ");
|
StringBuilder message = new StringBuilder("[AuthMe] ");
|
||||||
@ -203,7 +202,15 @@ public class AdminCommand implements CommandExecutor {
|
|||||||
sender.sendMessage("[AuthMe] Please put a valid IP");
|
sender.sendMessage("[AuthMe] Please put a valid IP");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
List<String> accountList = plugin.database.getAllAuthsByIp(arguments[1]);
|
List<String> accountList = null;
|
||||||
|
try {
|
||||||
|
accountList = plugin.database.getAllAuthsByIp(arguments[1]);
|
||||||
|
} catch (Exception e) {
|
||||||
|
ConsoleLogger.showError(e.getMessage());
|
||||||
|
ConsoleLogger.writeStackTrace(e);
|
||||||
|
m.send(sender, "error");
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (accountList == null || accountList.isEmpty()) {
|
if (accountList == null || accountList.isEmpty()) {
|
||||||
sender.sendMessage("[AuthMe] This IP does not exist in the database");
|
sender.sendMessage("[AuthMe] This IP does not exist in the database");
|
||||||
return;
|
return;
|
||||||
@ -274,7 +281,7 @@ public class AdminCommand implements CommandExecutor {
|
|||||||
}
|
}
|
||||||
plugin.database.setUnlogged(name);
|
plugin.database.setUnlogged(name);
|
||||||
if (Bukkit.getPlayerExact(realName) != null)
|
if (Bukkit.getPlayerExact(realName) != null)
|
||||||
Bukkit.getPlayerExact(realName).kickPlayer("An admin just registered you, please log again");
|
Bukkit.getPlayerExact(realName).kickPlayer("An admin just registered you, please log again");
|
||||||
m.send(sender, "registered");
|
m.send(sender, "registered");
|
||||||
ConsoleLogger.info(name + " registered");
|
ConsoleLogger.info(name + " registered");
|
||||||
} catch (NoSuchAlgorithmException ex) {
|
} catch (NoSuchAlgorithmException ex) {
|
||||||
@ -472,33 +479,32 @@ public class AdminCommand implements CommandExecutor {
|
|||||||
Player target = Bukkit.getPlayer(name);
|
Player target = Bukkit.getPlayer(name);
|
||||||
PlayerCache.getInstance().removePlayer(name);
|
PlayerCache.getInstance().removePlayer(name);
|
||||||
Utils.setGroup(target, GroupType.UNREGISTERED);
|
Utils.setGroup(target, GroupType.UNREGISTERED);
|
||||||
if (target != null) {
|
if (target != null && target.isOnline()) {
|
||||||
if (target.isOnline()) {
|
if (Settings.isTeleportToSpawnEnabled && !Settings.noTeleport) {
|
||||||
if (Settings.isTeleportToSpawnEnabled && !Settings.noTeleport) {
|
Location spawn = plugin.getSpawnLocation(target);
|
||||||
Location spawn = plugin.getSpawnLocation(target);
|
SpawnTeleportEvent tpEvent = new SpawnTeleportEvent(target, target.getLocation(), spawn, false);
|
||||||
SpawnTeleportEvent tpEvent = new SpawnTeleportEvent(target, target.getLocation(), spawn, false);
|
plugin.getServer().getPluginManager().callEvent(tpEvent);
|
||||||
plugin.getServer().getPluginManager().callEvent(tpEvent);
|
if (!tpEvent.isCancelled()) {
|
||||||
if (!tpEvent.isCancelled()) {
|
target.teleport(tpEvent.getTo());
|
||||||
target.teleport(tpEvent.getTo());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
LimboCache.getInstance().addLimboPlayer(target);
|
|
||||||
int delay = Settings.getRegistrationTimeout * 20;
|
|
||||||
int interval = Settings.getWarnMessageInterval;
|
|
||||||
BukkitScheduler sched = sender.getServer().getScheduler();
|
|
||||||
if (delay != 0) {
|
|
||||||
BukkitTask id = sched.runTaskLaterAsynchronously(plugin, new TimeoutTask(plugin, name, target), delay);
|
|
||||||
LimboCache.getInstance().getLimboPlayer(name).setTimeoutTaskId(id);
|
|
||||||
}
|
|
||||||
LimboCache.getInstance().getLimboPlayer(name).setMessageTaskId(sched.runTaskAsynchronously(plugin, new MessageTask(plugin, name, m.send("reg_msg"), interval)));
|
|
||||||
if (Settings.applyBlindEffect)
|
|
||||||
target.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, Settings.getRegistrationTimeout * 20, 2));
|
|
||||||
if (!Settings.isMovementAllowed && Settings.isRemoveSpeedEnabled) {
|
|
||||||
target.setWalkSpeed(0.0f);
|
|
||||||
target.setFlySpeed(0.0f);
|
|
||||||
}
|
|
||||||
m.send(target, "unregistered");
|
|
||||||
}
|
}
|
||||||
|
LimboCache.getInstance().addLimboPlayer(target);
|
||||||
|
int delay = Settings.getRegistrationTimeout * 20;
|
||||||
|
int interval = Settings.getWarnMessageInterval;
|
||||||
|
BukkitScheduler sched = sender.getServer().getScheduler();
|
||||||
|
if (delay != 0) {
|
||||||
|
BukkitTask id = sched.runTaskLaterAsynchronously(plugin, new TimeoutTask(plugin, name, target), delay);
|
||||||
|
LimboCache.getInstance().getLimboPlayer(name).setTimeoutTaskId(id);
|
||||||
|
}
|
||||||
|
LimboCache.getInstance().getLimboPlayer(name).setMessageTaskId(sched.runTaskAsynchronously(plugin, new MessageTask(plugin, name, m.send("reg_msg"), interval)));
|
||||||
|
if (Settings.applyBlindEffect)
|
||||||
|
target.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, Settings.getRegistrationTimeout * 20, 2));
|
||||||
|
if (!Settings.isMovementAllowed && Settings.isRemoveSpeedEnabled) {
|
||||||
|
target.setWalkSpeed(0.0f);
|
||||||
|
target.setFlySpeed(0.0f);
|
||||||
|
}
|
||||||
|
m.send(target, "unregistered");
|
||||||
|
|
||||||
}
|
}
|
||||||
m.send(sender, "unregistered");
|
m.send(sender, "unregistered");
|
||||||
ConsoleLogger.info(args[1] + " unregistered");
|
ConsoleLogger.info(args[1] + " unregistered");
|
||||||
|
|||||||
@ -1,13 +1,5 @@
|
|||||||
package fr.xephi.authme.commands;
|
package fr.xephi.authme.commands;
|
||||||
|
|
||||||
import java.security.NoSuchAlgorithmException;
|
|
||||||
import java.util.Arrays;
|
|
||||||
|
|
||||||
import org.bukkit.command.Command;
|
|
||||||
import org.bukkit.command.CommandExecutor;
|
|
||||||
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;
|
||||||
@ -16,9 +8,14 @@ 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.Command;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @author Xephi59
|
* @author Xephi59
|
||||||
*/
|
*/
|
||||||
public class EmailCommand implements CommandExecutor {
|
public class EmailCommand implements CommandExecutor {
|
||||||
@ -32,7 +29,7 @@ public class EmailCommand implements CommandExecutor {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(CommandSender sender, Command cmnd, String label,
|
public boolean onCommand(CommandSender sender, Command cmnd, String label,
|
||||||
String[] args) {
|
String[] args) {
|
||||||
if (!(sender instanceof Player)) {
|
if (!(sender instanceof Player)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -57,81 +54,13 @@ public class EmailCommand implements CommandExecutor {
|
|||||||
m.send(player, "usage_email_add");
|
m.send(player, "usage_email_add");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (Settings.getmaxRegPerEmail > 0) {
|
plugin.management.performAddEmail(player, args[1], args[2]);
|
||||||
if (!plugin.authmePermissible(sender, "authme.allow2accounts") && plugin.database.getAllAuthsByEmail(args[1]).size() >= Settings.getmaxRegPerEmail) {
|
|
||||||
m.send(player, "max_reg");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (args[1].equals(args[2]) && PlayerCache.getInstance().isAuthenticated(name)) {
|
|
||||||
PlayerAuth auth = PlayerCache.getInstance().getAuth(name);
|
|
||||||
if (auth.getEmail() == null || (!auth.getEmail().equals("your@email.com") && !auth.getEmail().isEmpty())) {
|
|
||||||
m.send(player, "usage_email_change");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (!Settings.isEmailCorrect(args[1])) {
|
|
||||||
m.send(player, "email_invalid");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
auth.setEmail(args[1]);
|
|
||||||
if (!plugin.database.updateEmail(auth)) {
|
|
||||||
m.send(player, "error");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
PlayerCache.getInstance().updatePlayer(auth);
|
|
||||||
m.send(player, "email_added");
|
|
||||||
player.sendMessage(auth.getEmail());
|
|
||||||
} else if (PlayerCache.getInstance().isAuthenticated(name)) {
|
|
||||||
m.send(player, "email_confirm");
|
|
||||||
} else {
|
|
||||||
if (!plugin.database.isAuthAvailable(name)) {
|
|
||||||
m.send(player, "login_msg");
|
|
||||||
} else {
|
|
||||||
m.send(player, "reg_email_msg");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (args[0].equalsIgnoreCase("change")) {
|
} else if (args[0].equalsIgnoreCase("change")) {
|
||||||
if (args.length != 3) {
|
if (args.length != 3) {
|
||||||
m.send(player, "usage_email_change");
|
m.send(player, "usage_email_change");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (Settings.getmaxRegPerEmail > 0) {
|
plugin.management.performChangeEmail(player, args[1], args[2]);
|
||||||
if (!plugin.authmePermissible(sender, "authme.allow2accounts") && plugin.database.getAllAuthsByEmail(args[2]).size() >= Settings.getmaxRegPerEmail) {
|
|
||||||
m.send(player, "max_reg");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (PlayerCache.getInstance().isAuthenticated(name)) {
|
|
||||||
PlayerAuth auth = PlayerCache.getInstance().getAuth(name);
|
|
||||||
if (auth.getEmail() == null || auth.getEmail().equals("your@email.com") || auth.getEmail().isEmpty()) {
|
|
||||||
m.send(player, "usage_email_add");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (!args[1].equals(auth.getEmail())) {
|
|
||||||
m.send(player, "old_email_invalid");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (!Settings.isEmailCorrect(args[2])) {
|
|
||||||
m.send(player, "new_email_invalid");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
auth.setEmail(args[2]);
|
|
||||||
if (!plugin.database.updateEmail(auth)) {
|
|
||||||
m.send(player, "error");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
PlayerCache.getInstance().updatePlayer(auth);
|
|
||||||
m.send(player, "email_changed");
|
|
||||||
player.sendMessage(Arrays.toString(m.send("email_defined")) + auth.getEmail());
|
|
||||||
} else if (PlayerCache.getInstance().isAuthenticated(name)) {
|
|
||||||
m.send(player, "email_confirm");
|
|
||||||
} else {
|
|
||||||
if (!plugin.database.isAuthAvailable(name)) {
|
|
||||||
m.send(player, "login_msg");
|
|
||||||
} else {
|
|
||||||
m.send(player, "reg_email_msg");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (args[0].equalsIgnoreCase("recovery")) {
|
if (args[0].equalsIgnoreCase("recovery")) {
|
||||||
if (args.length != 2) {
|
if (args.length != 2) {
|
||||||
@ -151,7 +80,7 @@ public class EmailCommand implements CommandExecutor {
|
|||||||
RandomString rand = new RandomString(Settings.getRecoveryPassLength);
|
RandomString rand = new RandomString(Settings.getRecoveryPassLength);
|
||||||
String thePass = rand.nextString();
|
String thePass = rand.nextString();
|
||||||
String hashnew = PasswordSecurity.getHash(Settings.getPasswordHash, thePass, name);
|
String hashnew = PasswordSecurity.getHash(Settings.getPasswordHash, thePass, name);
|
||||||
PlayerAuth auth = null;
|
PlayerAuth auth;
|
||||||
if (PlayerCache.getInstance().isAuthenticated(name)) {
|
if (PlayerCache.getInstance().isAuthenticated(name)) {
|
||||||
auth = PlayerCache.getInstance().getAuth(name);
|
auth = PlayerCache.getInstance().getAuth(name);
|
||||||
} else if (plugin.database.isAuthAvailable(name)) {
|
} else if (plugin.database.isAuthAvailable(name)) {
|
||||||
|
|||||||
@ -1,40 +1,21 @@
|
|||||||
package fr.xephi.authme.commands;
|
package fr.xephi.authme.commands;
|
||||||
|
|
||||||
import java.security.NoSuchAlgorithmException;
|
|
||||||
|
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandExecutor;
|
import org.bukkit.command.CommandExecutor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
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.Utils;
|
|
||||||
import fr.xephi.authme.Utils.GroupType;
|
|
||||||
import fr.xephi.authme.cache.auth.PlayerCache;
|
import fr.xephi.authme.cache.auth.PlayerCache;
|
||||||
import fr.xephi.authme.cache.backup.JsonCache;
|
|
||||||
import fr.xephi.authme.cache.limbo.LimboCache;
|
|
||||||
import fr.xephi.authme.events.SpawnTeleportEvent;
|
|
||||||
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.task.MessageTask;
|
|
||||||
import fr.xephi.authme.task.TimeoutTask;
|
|
||||||
|
|
||||||
public class UnregisterCommand implements CommandExecutor {
|
public class UnregisterCommand implements CommandExecutor {
|
||||||
|
|
||||||
private Messages m = Messages.getInstance();
|
private Messages m = Messages.getInstance();
|
||||||
public AuthMe plugin;
|
public AuthMe plugin;
|
||||||
private JsonCache playerCache;
|
|
||||||
|
|
||||||
public UnregisterCommand(AuthMe plugin) {
|
public UnregisterCommand(AuthMe plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
this.playerCache = new JsonCache();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -1,18 +1,15 @@
|
|||||||
package fr.xephi.authme.datasource;
|
package fr.xephi.authme.datasource;
|
||||||
|
|
||||||
|
import fr.xephi.authme.AuthMe;
|
||||||
|
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||||
|
import fr.xephi.authme.cache.auth.PlayerCache;
|
||||||
|
import fr.xephi.authme.util.Utils;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.*;
|
||||||
import java.util.concurrent.ExecutorService;
|
|
||||||
import java.util.concurrent.Executors;
|
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import fr.xephi.authme.AuthMe;
|
|
||||||
import fr.xephi.authme.Utils;
|
|
||||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
|
||||||
import fr.xephi.authme.cache.auth.PlayerCache;
|
|
||||||
|
|
||||||
public class CacheDataSource implements DataSource {
|
public class CacheDataSource implements DataSource {
|
||||||
|
|
||||||
@ -229,23 +226,15 @@ public class CacheDataSource implements DataSource {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized boolean updateEmail(final PlayerAuth auth) {
|
public synchronized boolean updateEmail(final PlayerAuth auth) {
|
||||||
if (!cache.containsKey(auth.getNickname())) {
|
try {
|
||||||
|
return exec.submit(new Callable<Boolean>() {
|
||||||
|
public Boolean call() {
|
||||||
|
return source.updateEmail(auth);
|
||||||
|
}
|
||||||
|
}).get();
|
||||||
|
} catch (Exception e) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
PlayerAuth cachedAuth = cache.get(auth.getNickname());
|
|
||||||
final String oldEmail = cachedAuth.getEmail();
|
|
||||||
cachedAuth.setEmail(auth.getEmail());
|
|
||||||
exec.execute(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
if (!source.updateEmail(auth)) {
|
|
||||||
if (cache.containsKey(auth.getNickname())) {
|
|
||||||
cache.get(auth.getNickname()).setEmail(oldEmail);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -281,25 +270,21 @@ public class CacheDataSource implements DataSource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized List<String> getAllAuthsByIp(String ip) {
|
public synchronized List<String> getAllAuthsByIp(final String ip) throws Exception {
|
||||||
List<String> result = new ArrayList<>();
|
return exec.submit(new Callable<List<String>>() {
|
||||||
for (Map.Entry<String, PlayerAuth> stringPlayerAuthEntry : cache.entrySet()) {
|
public List<String> call() throws Exception {
|
||||||
PlayerAuth p = stringPlayerAuthEntry.getValue();
|
return source.getAllAuthsByIp(ip);
|
||||||
if (p.getIp().equals(ip))
|
}
|
||||||
result.add(p.getNickname());
|
}).get();
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized List<String> getAllAuthsByEmail(String email) {
|
public synchronized List<String> getAllAuthsByEmail(final String email) throws Exception {
|
||||||
List<String> result = new ArrayList<>();
|
return exec.submit(new Callable<List<String>>() {
|
||||||
for (Map.Entry<String, PlayerAuth> stringPlayerAuthEntry : cache.entrySet()) {
|
public List<String> call() throws Exception {
|
||||||
PlayerAuth p = stringPlayerAuthEntry.getValue();
|
return source.getAllAuthsByEmail(email);
|
||||||
if (p.getEmail().equals(email))
|
}
|
||||||
result.add(p.getNickname());
|
}).get();
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
package fr.xephi.authme.datasource;
|
package fr.xephi.authme.datasource;
|
||||||
|
|
||||||
|
import java.sql.SQLException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||||
@ -35,9 +36,9 @@ public interface DataSource {
|
|||||||
|
|
||||||
List<String> getAllAuthsByName(PlayerAuth auth);
|
List<String> getAllAuthsByName(PlayerAuth auth);
|
||||||
|
|
||||||
List<String> getAllAuthsByIp(String ip);
|
List<String> getAllAuthsByIp(String ip) throws Exception;
|
||||||
|
|
||||||
List<String> getAllAuthsByEmail(String email);
|
List<String> getAllAuthsByEmail(String email) throws Exception;
|
||||||
|
|
||||||
boolean updateEmail(PlayerAuth auth);
|
boolean updateEmail(PlayerAuth auth);
|
||||||
|
|
||||||
|
|||||||
@ -1,26 +1,18 @@
|
|||||||
package fr.xephi.authme.datasource;
|
package fr.xephi.authme.datasource;
|
||||||
|
|
||||||
import java.sql.Blob;
|
|
||||||
import java.sql.Connection;
|
|
||||||
import java.sql.PreparedStatement;
|
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.sql.Statement;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
|
|
||||||
import com.zaxxer.hikari.HikariConfig;
|
import com.zaxxer.hikari.HikariConfig;
|
||||||
import com.zaxxer.hikari.HikariDataSource;
|
import com.zaxxer.hikari.HikariDataSource;
|
||||||
import com.zaxxer.hikari.pool.PoolInitializationException;
|
import com.zaxxer.hikari.pool.PoolInitializationException;
|
||||||
|
|
||||||
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.security.HashAlgorithm;
|
import fr.xephi.authme.security.HashAlgorithm;
|
||||||
import fr.xephi.authme.settings.Settings;
|
import fr.xephi.authme.settings.Settings;
|
||||||
|
|
||||||
|
import java.sql.*;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class MySQL implements DataSource {
|
public class MySQL implements DataSource {
|
||||||
|
|
||||||
private String host;
|
private String host;
|
||||||
@ -108,19 +100,12 @@ public class MySQL implements DataSource {
|
|||||||
config.setJdbcUrl("jdbc:mysql://" + this.host + ":" + this.port + "/" + this.database);
|
config.setJdbcUrl("jdbc:mysql://" + this.host + ":" + this.port + "/" + this.database);
|
||||||
config.setUsername(this.username);
|
config.setUsername(this.username);
|
||||||
config.setPassword(this.password);
|
config.setPassword(this.password);
|
||||||
if (Settings.isMySQLWebsite)
|
config.addDataSourceProperty("cachePrepStmts", "false");
|
||||||
{
|
|
||||||
config.addDataSourceProperty("cachePrepStmts", "false");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
config.addDataSourceProperty("cachePrepStmts", "true");
|
|
||||||
config.addDataSourceProperty("prepStmtCacheSize", "250");
|
|
||||||
config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
|
|
||||||
}
|
|
||||||
config.addDataSourceProperty("autoReconnect", false);
|
config.addDataSourceProperty("autoReconnect", false);
|
||||||
config.setInitializationFailFast(true); // Don't start the plugin if the database is unavariable
|
config.setInitializationFailFast(true); // Don't start the plugin if the database is unavailable
|
||||||
config.setMaxLifetime(180000); // 3 Min
|
config.setMaxLifetime(180000); // 3 Min
|
||||||
config.setIdleTimeout(60000); // 1 Min
|
config.setIdleTimeout(60000); // 1 Min
|
||||||
|
config.setMinimumIdle(2);
|
||||||
config.setMaximumPoolSize(maxConnections);
|
config.setMaximumPoolSize(maxConnections);
|
||||||
ds = new HikariDataSource(config);
|
ds = new HikariDataSource(config);
|
||||||
ConsoleLogger.info("Connection arguments loaded, Hikari ConnectionPool ready!");
|
ConsoleLogger.info("Connection arguments loaded, Hikari ConnectionPool ready!");
|
||||||
@ -136,24 +121,7 @@ public class MySQL implements DataSource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private synchronized Connection getConnection() throws SQLException {
|
private synchronized Connection getConnection() throws SQLException {
|
||||||
if (!ds.isClosed())
|
return ds.getConnection();
|
||||||
{
|
|
||||||
Connection con;
|
|
||||||
con = ds.getConnection();
|
|
||||||
return con;
|
|
||||||
}
|
|
||||||
ConsoleLogger.showError("Can't open a database connection!");
|
|
||||||
if (Settings.isStopEnabled)
|
|
||||||
{
|
|
||||||
ConsoleLogger.showError("Server will ShuttingDown for Security reason");
|
|
||||||
Bukkit.getScheduler().scheduleSyncDelayedTask(AuthMe.getInstance(), new Runnable(){
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
AuthMe.getInstance().getServer().shutdown();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized void setupConnection() throws SQLException {
|
private synchronized void setupConnection() throws SQLException {
|
||||||
@ -162,7 +130,7 @@ public class MySQL implements DataSource {
|
|||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
try {
|
try {
|
||||||
if ((con = getConnection()) == null)
|
if ((con = getConnection()) == null)
|
||||||
return;
|
return;
|
||||||
st = con.createStatement();
|
st = con.createStatement();
|
||||||
st.executeUpdate("CREATE TABLE IF NOT EXISTS " + tableName + " (" + columnID + " INTEGER AUTO_INCREMENT," + columnName + " VARCHAR(255) NOT NULL UNIQUE," + columnPassword + " VARCHAR(255) NOT NULL," + columnIp + " VARCHAR(40) NOT NULL DEFAULT '127.0.0.1'," + columnLastLogin + " BIGINT NOT NULL DEFAULT '" + System.currentTimeMillis() + "'," + lastlocX + " DOUBLE NOT NULL DEFAULT '0.0'," + lastlocY + " DOUBLE NOT NULL DEFAULT '0.0'," + lastlocZ + " DOUBLE NOT NULL DEFAULT '0.0'," + lastlocWorld + " VARCHAR(255) NOT NULL DEFAULT '" + Settings.defaultWorld + "'," + columnEmail + " VARCHAR(255) DEFAULT 'your@email.com'," + columnLogged + " SMALLINT NOT NULL DEFAULT '0'," + "CONSTRAINT table_const_prim PRIMARY KEY (" + columnID + "));");
|
st.executeUpdate("CREATE TABLE IF NOT EXISTS " + tableName + " (" + columnID + " INTEGER AUTO_INCREMENT," + columnName + " VARCHAR(255) NOT NULL UNIQUE," + columnPassword + " VARCHAR(255) NOT NULL," + columnIp + " VARCHAR(40) NOT NULL DEFAULT '127.0.0.1'," + columnLastLogin + " BIGINT NOT NULL DEFAULT '" + System.currentTimeMillis() + "'," + lastlocX + " DOUBLE NOT NULL DEFAULT '0.0'," + lastlocY + " DOUBLE NOT NULL DEFAULT '0.0'," + lastlocZ + " DOUBLE NOT NULL DEFAULT '0.0'," + lastlocWorld + " VARCHAR(255) NOT NULL DEFAULT '" + Settings.defaultWorld + "'," + columnEmail + " VARCHAR(255) DEFAULT 'your@email.com'," + columnLogged + " SMALLINT NOT NULL DEFAULT '0'," + "CONSTRAINT table_const_prim PRIMARY KEY (" + columnID + "));");
|
||||||
rs = con.getMetaData().getColumns(null, null, tableName, columnPassword);
|
rs = con.getMetaData().getColumns(null, null, tableName, columnPassword);
|
||||||
@ -210,7 +178,7 @@ public class MySQL implements DataSource {
|
|||||||
st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + columnRealName + " VARCHAR(255) NOT NULL DEFAULT 'Player' AFTER " + columnLogged + ";");
|
st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + columnRealName + " VARCHAR(255) NOT NULL DEFAULT 'Player' AFTER " + columnLogged + ";");
|
||||||
}
|
}
|
||||||
if (Settings.isMySQLWebsite)
|
if (Settings.isMySQLWebsite)
|
||||||
st.execute("SET GLOBAL query_cache_size = 0; SET GLOBAL query_cache_type = 0;");
|
st.execute("SET GLOBAL query_cache_size = 0; SET GLOBAL query_cache_type = 0;");
|
||||||
} finally {
|
} finally {
|
||||||
close(rs);
|
close(rs);
|
||||||
close(st);
|
close(st);
|
||||||
@ -226,7 +194,7 @@ public class MySQL implements DataSource {
|
|||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
try {
|
try {
|
||||||
if ((con = getConnection()) == null)
|
if ((con = getConnection()) == null)
|
||||||
return true;
|
return true;
|
||||||
pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE LOWER(" + columnName + ")=LOWER(?);");
|
pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE LOWER(" + columnName + ")=LOWER(?);");
|
||||||
pst.setString(1, user);
|
pst.setString(1, user);
|
||||||
rs = pst.executeQuery();
|
rs = pst.executeQuery();
|
||||||
@ -250,7 +218,7 @@ public class MySQL implements DataSource {
|
|||||||
int id;
|
int id;
|
||||||
try {
|
try {
|
||||||
if ((con = getConnection()) == null)
|
if ((con = getConnection()) == null)
|
||||||
return null;
|
return null;
|
||||||
pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE LOWER(" + columnName + ")=LOWER(?);");
|
pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE LOWER(" + columnName + ")=LOWER(?);");
|
||||||
pst.setString(1, user);
|
pst.setString(1, user);
|
||||||
rs = pst.executeQuery();
|
rs = pst.executeQuery();
|
||||||
@ -301,7 +269,7 @@ public class MySQL implements DataSource {
|
|||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
try {
|
try {
|
||||||
if ((con = getConnection()) == null)
|
if ((con = getConnection()) == null)
|
||||||
return false;
|
return false;
|
||||||
if ((columnSalt == null || columnSalt.isEmpty()) || (auth.getSalt() == null || auth.getSalt().isEmpty())) {
|
if ((columnSalt == null || columnSalt.isEmpty()) || (auth.getSalt() == null || auth.getSalt().isEmpty())) {
|
||||||
pst = con.prepareStatement("INSERT INTO " + tableName + "(" + columnName + "," + columnPassword + "," + columnIp + "," + columnLastLogin + "," + columnRealName + ") VALUES (?,?,?,?,?);");
|
pst = con.prepareStatement("INSERT INTO " + tableName + "(" + columnName + "," + columnPassword + "," + columnIp + "," + columnLastLogin + "," + columnRealName + ") VALUES (?,?,?,?,?);");
|
||||||
pst.setString(1, auth.getNickname());
|
pst.setString(1, auth.getNickname());
|
||||||
@ -508,7 +476,7 @@ public class MySQL implements DataSource {
|
|||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
try {
|
try {
|
||||||
if ((con = getConnection()) == null)
|
if ((con = getConnection()) == null)
|
||||||
return false;
|
return false;
|
||||||
pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnPassword + "=? WHERE LOWER(" + columnName + ")=?;");
|
pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnPassword + "=? WHERE LOWER(" + columnName + ")=?;");
|
||||||
pst.setString(1, auth.getHash());
|
pst.setString(1, auth.getHash());
|
||||||
pst.setString(2, auth.getNickname());
|
pst.setString(2, auth.getNickname());
|
||||||
@ -552,7 +520,7 @@ public class MySQL implements DataSource {
|
|||||||
PreparedStatement pst = null;
|
PreparedStatement pst = null;
|
||||||
try {
|
try {
|
||||||
if ((con = getConnection()) == null)
|
if ((con = getConnection()) == null)
|
||||||
return false;
|
return false;
|
||||||
pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnIp + "=?, " + columnLastLogin + "=?, " + columnRealName + "=? WHERE LOWER(" + columnName + ")=?;");
|
pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnIp + "=?, " + columnLastLogin + "=?, " + columnRealName + "=? WHERE LOWER(" + columnName + ")=?;");
|
||||||
pst.setString(1, auth.getIp());
|
pst.setString(1, auth.getIp());
|
||||||
pst.setLong(2, auth.getLastLogin());
|
pst.setLong(2, auth.getLastLogin());
|
||||||
@ -575,7 +543,7 @@ public class MySQL implements DataSource {
|
|||||||
PreparedStatement pst = null;
|
PreparedStatement pst = null;
|
||||||
try {
|
try {
|
||||||
if ((con = getConnection()) == null)
|
if ((con = getConnection()) == null)
|
||||||
return 0;
|
return 0;
|
||||||
pst = con.prepareStatement("DELETE FROM " + tableName + " WHERE " + columnLastLogin + "<?;");
|
pst = con.prepareStatement("DELETE FROM " + tableName + " WHERE " + columnLastLogin + "<?;");
|
||||||
pst.setLong(1, until);
|
pst.setLong(1, until);
|
||||||
return pst.executeUpdate();
|
return pst.executeUpdate();
|
||||||
@ -596,7 +564,7 @@ public class MySQL implements DataSource {
|
|||||||
List<String> list = new ArrayList<>();
|
List<String> list = new ArrayList<>();
|
||||||
try {
|
try {
|
||||||
if ((con = getConnection()) == null)
|
if ((con = getConnection()) == null)
|
||||||
return list;
|
return list;
|
||||||
pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnLastLogin + "<?;");
|
pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnLastLogin + "<?;");
|
||||||
pst.setLong(1, until);
|
pst.setLong(1, until);
|
||||||
rs = pst.executeQuery();
|
rs = pst.executeQuery();
|
||||||
@ -624,7 +592,7 @@ public class MySQL implements DataSource {
|
|||||||
PreparedStatement pst = null;
|
PreparedStatement pst = null;
|
||||||
try {
|
try {
|
||||||
if ((con = getConnection()) == null)
|
if ((con = getConnection()) == null)
|
||||||
return false;
|
return false;
|
||||||
if (Settings.getPasswordHash == HashAlgorithm.XENFORO) {
|
if (Settings.getPasswordHash == HashAlgorithm.XENFORO) {
|
||||||
int id;
|
int id;
|
||||||
ResultSet rs;
|
ResultSet rs;
|
||||||
@ -661,7 +629,7 @@ public class MySQL implements DataSource {
|
|||||||
PreparedStatement pst = null;
|
PreparedStatement pst = null;
|
||||||
try {
|
try {
|
||||||
if ((con = getConnection()) == null)
|
if ((con = getConnection()) == null)
|
||||||
return false;
|
return false;
|
||||||
pst = con.prepareStatement("UPDATE " + tableName + " SET " + lastlocX + " =?, " + lastlocY + "=?, " + lastlocZ + "=?, " + lastlocWorld + "=? WHERE LOWER(" + columnName + ")=?;");
|
pst = con.prepareStatement("UPDATE " + tableName + " SET " + lastlocX + " =?, " + lastlocY + "=?, " + lastlocZ + "=?, " + lastlocWorld + "=? WHERE LOWER(" + columnName + ")=?;");
|
||||||
pst.setDouble(1, auth.getQuitLocX());
|
pst.setDouble(1, auth.getQuitLocX());
|
||||||
pst.setDouble(2, auth.getQuitLocY());
|
pst.setDouble(2, auth.getQuitLocY());
|
||||||
@ -687,7 +655,7 @@ public class MySQL implements DataSource {
|
|||||||
int countIp = 0;
|
int countIp = 0;
|
||||||
try {
|
try {
|
||||||
if ((con = getConnection()) == null)
|
if ((con = getConnection()) == null)
|
||||||
return 0;
|
return 0;
|
||||||
pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnIp + "=?;");
|
pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnIp + "=?;");
|
||||||
pst.setString(1, ip);
|
pst.setString(1, ip);
|
||||||
rs = pst.executeQuery();
|
rs = pst.executeQuery();
|
||||||
@ -711,13 +679,14 @@ public class MySQL implements DataSource {
|
|||||||
PreparedStatement pst = null;
|
PreparedStatement pst = null;
|
||||||
try {
|
try {
|
||||||
if ((con = getConnection()) == null)
|
if ((con = getConnection()) == null)
|
||||||
return false;
|
return false;
|
||||||
pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnEmail + " =? WHERE LOWER(" + columnName + ")=?;");
|
pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnEmail + " =? WHERE LOWER(" + columnName + ")=?;");
|
||||||
pst.setString(1, auth.getEmail());
|
pst.setString(1, auth.getEmail());
|
||||||
pst.setString(2, auth.getNickname());
|
pst.setString(2, auth.getNickname());
|
||||||
pst.executeUpdate();
|
pst.executeUpdate();
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
ConsoleLogger.showError(ex.getMessage());
|
ConsoleLogger.showError(ex.getMessage());
|
||||||
|
ConsoleLogger.writeStackTrace(ex);
|
||||||
return false;
|
return false;
|
||||||
} finally {
|
} finally {
|
||||||
close(pst);
|
close(pst);
|
||||||
@ -735,7 +704,7 @@ public class MySQL implements DataSource {
|
|||||||
PreparedStatement pst = null;
|
PreparedStatement pst = null;
|
||||||
try {
|
try {
|
||||||
if ((con = getConnection()) == null)
|
if ((con = getConnection()) == null)
|
||||||
return false;
|
return false;
|
||||||
pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnSalt + " =? WHERE LOWER(" + columnName + ")=?;");
|
pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnSalt + " =? WHERE LOWER(" + columnName + ")=?;");
|
||||||
pst.setString(1, auth.getSalt());
|
pst.setString(1, auth.getSalt());
|
||||||
pst.setString(2, auth.getNickname());
|
pst.setString(2, auth.getNickname());
|
||||||
@ -777,6 +746,7 @@ public class MySQL implements DataSource {
|
|||||||
o.close();
|
o.close();
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
ConsoleLogger.showError(ex.getMessage());
|
ConsoleLogger.showError(ex.getMessage());
|
||||||
|
ConsoleLogger.writeStackTrace(ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -789,7 +759,7 @@ public class MySQL implements DataSource {
|
|||||||
List<String> countIp = new ArrayList<>();
|
List<String> countIp = new ArrayList<>();
|
||||||
try {
|
try {
|
||||||
if ((con = getConnection()) == null)
|
if ((con = getConnection()) == null)
|
||||||
return countIp;
|
return countIp;
|
||||||
pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnIp + "=?;");
|
pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnIp + "=?;");
|
||||||
pst.setString(1, auth.getIp());
|
pst.setString(1, auth.getIp());
|
||||||
rs = pst.executeQuery();
|
rs = pst.executeQuery();
|
||||||
@ -815,7 +785,7 @@ public class MySQL implements DataSource {
|
|||||||
List<String> countIp = new ArrayList<>();
|
List<String> countIp = new ArrayList<>();
|
||||||
try {
|
try {
|
||||||
if ((con = getConnection()) == null)
|
if ((con = getConnection()) == null)
|
||||||
return countIp;
|
return countIp;
|
||||||
pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnIp + "=?;");
|
pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnIp + "=?;");
|
||||||
pst.setString(1, ip);
|
pst.setString(1, ip);
|
||||||
rs = pst.executeQuery();
|
rs = pst.executeQuery();
|
||||||
@ -834,14 +804,13 @@ public class MySQL implements DataSource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized List<String> getAllAuthsByEmail(String email) {
|
public synchronized List<String> getAllAuthsByEmail(String email) throws SQLException {
|
||||||
Connection con = null;
|
final Connection con = getConnection();
|
||||||
PreparedStatement pst = null;
|
PreparedStatement pst = null;
|
||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
List<String> countEmail = new ArrayList<>();
|
List<String> countEmail = new ArrayList<>();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if ((con = getConnection()) == null)
|
|
||||||
return countEmail;
|
|
||||||
pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnEmail + "=?;");
|
pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnEmail + "=?;");
|
||||||
pst.setString(1, email);
|
pst.setString(1, email);
|
||||||
rs = pst.executeQuery();
|
rs = pst.executeQuery();
|
||||||
@ -849,9 +818,6 @@ public class MySQL implements DataSource {
|
|||||||
countEmail.add(rs.getString(columnName));
|
countEmail.add(rs.getString(columnName));
|
||||||
}
|
}
|
||||||
return countEmail;
|
return countEmail;
|
||||||
} catch (Exception ex) {
|
|
||||||
ConsoleLogger.showError(ex.getMessage());
|
|
||||||
return new ArrayList<>();
|
|
||||||
} finally {
|
} finally {
|
||||||
close(rs);
|
close(rs);
|
||||||
close(pst);
|
close(pst);
|
||||||
@ -865,7 +831,7 @@ public class MySQL implements DataSource {
|
|||||||
PreparedStatement pst = null;
|
PreparedStatement pst = null;
|
||||||
try {
|
try {
|
||||||
if ((con = getConnection()) == null)
|
if ((con = getConnection()) == null)
|
||||||
return;
|
return;
|
||||||
for (String name : banned) {
|
for (String name : banned) {
|
||||||
pst = con.prepareStatement("DELETE FROM " + tableName + " WHERE LOWER(" + columnName + ")=?;");
|
pst = con.prepareStatement("DELETE FROM " + tableName + " WHERE LOWER(" + columnName + ")=?;");
|
||||||
pst.setString(1, name);
|
pst.setString(1, name);
|
||||||
@ -891,7 +857,7 @@ public class MySQL implements DataSource {
|
|||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
try {
|
try {
|
||||||
if ((con = getConnection()) == null)
|
if ((con = getConnection()) == null)
|
||||||
return false;
|
return false;
|
||||||
pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE LOWER(" + columnName + ")=?;");
|
pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE LOWER(" + columnName + ")=?;");
|
||||||
pst.setString(1, user);
|
pst.setString(1, user);
|
||||||
rs = pst.executeQuery();
|
rs = pst.executeQuery();
|
||||||
@ -914,7 +880,7 @@ public class MySQL implements DataSource {
|
|||||||
PreparedStatement pst = null;
|
PreparedStatement pst = null;
|
||||||
try {
|
try {
|
||||||
if ((con = getConnection()) == null)
|
if ((con = getConnection()) == null)
|
||||||
return;
|
return;
|
||||||
pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnLogged + "=? WHERE LOWER(" + columnName + ")=?;");
|
pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnLogged + "=? WHERE LOWER(" + columnName + ")=?;");
|
||||||
pst.setInt(1, 1);
|
pst.setInt(1, 1);
|
||||||
pst.setString(2, user);
|
pst.setString(2, user);
|
||||||
@ -934,7 +900,7 @@ public class MySQL implements DataSource {
|
|||||||
if (user != null)
|
if (user != null)
|
||||||
try {
|
try {
|
||||||
if ((con = getConnection()) == null)
|
if ((con = getConnection()) == null)
|
||||||
return;
|
return;
|
||||||
pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnLogged + "=? WHERE LOWER(" + columnName + ")=?;");
|
pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnLogged + "=? WHERE LOWER(" + columnName + ")=?;");
|
||||||
pst.setInt(1, 0);
|
pst.setInt(1, 0);
|
||||||
pst.setString(2, user);
|
pst.setString(2, user);
|
||||||
@ -953,7 +919,7 @@ public class MySQL implements DataSource {
|
|||||||
PreparedStatement pst = null;
|
PreparedStatement pst = null;
|
||||||
try {
|
try {
|
||||||
if ((con = getConnection()) == null)
|
if ((con = getConnection()) == null)
|
||||||
return;
|
return;
|
||||||
pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnLogged + "=? WHERE " + columnLogged + "=?;");
|
pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnLogged + "=? WHERE " + columnLogged + "=?;");
|
||||||
pst.setInt(1, 0);
|
pst.setInt(1, 0);
|
||||||
pst.setInt(2, 1);
|
pst.setInt(2, 1);
|
||||||
@ -974,7 +940,7 @@ public class MySQL implements DataSource {
|
|||||||
ResultSet rs;
|
ResultSet rs;
|
||||||
try {
|
try {
|
||||||
if ((con = getConnection()) == null)
|
if ((con = getConnection()) == null)
|
||||||
return result;
|
return result;
|
||||||
pst = con.prepareStatement("SELECT COUNT(*) FROM " + tableName + ";");
|
pst = con.prepareStatement("SELECT COUNT(*) FROM " + tableName + ";");
|
||||||
rs = pst.executeQuery();
|
rs = pst.executeQuery();
|
||||||
if (rs != null && rs.next()) {
|
if (rs != null && rs.next()) {
|
||||||
@ -996,7 +962,7 @@ public class MySQL implements DataSource {
|
|||||||
PreparedStatement pst = null;
|
PreparedStatement pst = null;
|
||||||
try {
|
try {
|
||||||
if ((con = getConnection()) == null)
|
if ((con = getConnection()) == null)
|
||||||
return;
|
return;
|
||||||
pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnName + "=? WHERE LOWER(" + columnName + ")=?;");
|
pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnName + "=? WHERE LOWER(" + columnName + ")=?;");
|
||||||
pst.setString(1, newone);
|
pst.setString(1, newone);
|
||||||
pst.setString(2, oldone);
|
pst.setString(2, oldone);
|
||||||
@ -1017,7 +983,7 @@ public class MySQL implements DataSource {
|
|||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
try {
|
try {
|
||||||
if ((con = getConnection()) == null)
|
if ((con = getConnection()) == null)
|
||||||
return auths;
|
return auths;
|
||||||
pst = con.prepareStatement("SELECT * FROM " + tableName + ";");
|
pst = con.prepareStatement("SELECT * FROM " + tableName + ";");
|
||||||
rs = pst.executeQuery();
|
rs = pst.executeQuery();
|
||||||
while (rs.next()) {
|
while (rs.next()) {
|
||||||
@ -1068,7 +1034,7 @@ public class MySQL implements DataSource {
|
|||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
try {
|
try {
|
||||||
if ((con = getConnection()) == null)
|
if ((con = getConnection()) == null)
|
||||||
return auths;
|
return auths;
|
||||||
pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnLogged + "=1;");
|
pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnLogged + "=1;");
|
||||||
rs = pst.executeQuery();
|
rs = pst.executeQuery();
|
||||||
while (rs.next()) {
|
while (rs.next()) {
|
||||||
|
|||||||
@ -83,10 +83,10 @@ public class SQLite_HIKARI implements DataSource {
|
|||||||
config.setPoolName("AuthMeSQLitePool");
|
config.setPoolName("AuthMeSQLitePool");
|
||||||
config.setDriverClassName("org.sqlite.JDBC"); // RuntimeException
|
config.setDriverClassName("org.sqlite.JDBC"); // RuntimeException
|
||||||
config.setJdbcUrl("jdbc:sqlite:plugins/AuthMe/" + database + ".db");
|
config.setJdbcUrl("jdbc:sqlite:plugins/AuthMe/" + database + ".db");
|
||||||
config.setConnectionTestQuery("SELECT 1");
|
|
||||||
config.setMaxLifetime(180000); // 3 Min
|
config.setMaxLifetime(180000); // 3 Min
|
||||||
config.setIdleTimeout(60000); // 1 Min
|
config.setIdleTimeout(60000); // 1 Min
|
||||||
config.setMaximumPoolSize(50); // 50 (including idle connections)
|
config.setMinimumIdle(2);
|
||||||
|
config.setMaximumPoolSize(8); // don't set too much
|
||||||
ds = new HikariDataSource(config);
|
ds = new HikariDataSource(config);
|
||||||
ConsoleLogger.info("Connection arguments loaded, Hikari ConnectionPool ready!");
|
ConsoleLogger.info("Connection arguments loaded, Hikari ConnectionPool ready!");
|
||||||
}
|
}
|
||||||
@ -472,13 +472,12 @@ public class SQLite_HIKARI implements DataSource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> getAllAuthsByIp(String ip) {
|
public List<String> getAllAuthsByIp(String ip) throws SQLException {
|
||||||
Connection con = null;
|
final Connection con = getConnection();
|
||||||
PreparedStatement pst = null;
|
PreparedStatement pst = null;
|
||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
List<String> countIp = new ArrayList<>();
|
List<String> countIp = new ArrayList<>();
|
||||||
try {
|
try {
|
||||||
con = getConnection();
|
|
||||||
pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnIp + "=?;");
|
pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnIp + "=?;");
|
||||||
pst.setString(1, ip);
|
pst.setString(1, ip);
|
||||||
rs = pst.executeQuery();
|
rs = pst.executeQuery();
|
||||||
@ -486,11 +485,6 @@ public class SQLite_HIKARI implements DataSource {
|
|||||||
countIp.add(rs.getString(columnName));
|
countIp.add(rs.getString(columnName));
|
||||||
}
|
}
|
||||||
return countIp;
|
return countIp;
|
||||||
} catch (SQLException ex) {
|
|
||||||
ConsoleLogger.showError(ex.getMessage());
|
|
||||||
return new ArrayList<>();
|
|
||||||
} catch (NullPointerException npe) {
|
|
||||||
return new ArrayList<>();
|
|
||||||
} finally {
|
} finally {
|
||||||
close(rs);
|
close(rs);
|
||||||
close(pst);
|
close(pst);
|
||||||
@ -499,13 +493,12 @@ public class SQLite_HIKARI implements DataSource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> getAllAuthsByEmail(String email) {
|
public List<String> getAllAuthsByEmail(String email) throws SQLException {
|
||||||
Connection con = null;
|
final Connection con = getConnection();
|
||||||
PreparedStatement pst = null;
|
PreparedStatement pst = null;
|
||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
List<String> countEmail = new ArrayList<>();
|
List<String> countEmail = new ArrayList<>();
|
||||||
try {
|
try {
|
||||||
con = getConnection();
|
|
||||||
pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnEmail + "=?;");
|
pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnEmail + "=?;");
|
||||||
pst.setString(1, email);
|
pst.setString(1, email);
|
||||||
rs = pst.executeQuery();
|
rs = pst.executeQuery();
|
||||||
@ -513,11 +506,6 @@ public class SQLite_HIKARI implements DataSource {
|
|||||||
countEmail.add(rs.getString(columnName));
|
countEmail.add(rs.getString(columnName));
|
||||||
}
|
}
|
||||||
return countEmail;
|
return countEmail;
|
||||||
} catch (SQLException ex) {
|
|
||||||
ConsoleLogger.showError(ex.getMessage());
|
|
||||||
return new ArrayList<>();
|
|
||||||
} catch (NullPointerException npe) {
|
|
||||||
return new ArrayList<>();
|
|
||||||
} finally {
|
} finally {
|
||||||
close(rs);
|
close(rs);
|
||||||
close(pst);
|
close(pst);
|
||||||
|
|||||||
@ -7,7 +7,7 @@ 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.AuthMe;
|
||||||
import fr.xephi.authme.Utils;
|
import fr.xephi.authme.util.Utils;
|
||||||
|
|
||||||
public class AuthMeBlockListener implements Listener {
|
public class AuthMeBlockListener implements Listener {
|
||||||
|
|
||||||
|
|||||||
@ -20,7 +20,7 @@ import org.bukkit.event.entity.ProjectileLaunchEvent;
|
|||||||
import org.bukkit.projectiles.ProjectileSource;
|
import org.bukkit.projectiles.ProjectileSource;
|
||||||
|
|
||||||
import fr.xephi.authme.AuthMe;
|
import fr.xephi.authme.AuthMe;
|
||||||
import fr.xephi.authme.Utils;
|
import fr.xephi.authme.util.Utils;
|
||||||
|
|
||||||
public class AuthMeEntityListener implements Listener {
|
public class AuthMeEntityListener implements Listener {
|
||||||
|
|
||||||
|
|||||||
@ -42,20 +42,21 @@ import com.google.common.io.ByteStreams;
|
|||||||
|
|
||||||
import fr.xephi.authme.AuthMe;
|
import fr.xephi.authme.AuthMe;
|
||||||
import fr.xephi.authme.ConsoleLogger;
|
import fr.xephi.authme.ConsoleLogger;
|
||||||
import fr.xephi.authme.Utils;
|
|
||||||
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.cache.limbo.LimboCache;
|
import fr.xephi.authme.cache.limbo.LimboCache;
|
||||||
import fr.xephi.authme.cache.limbo.LimboPlayer;
|
import fr.xephi.authme.cache.limbo.LimboPlayer;
|
||||||
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.Utils;
|
||||||
|
|
||||||
public class AuthMePlayerListener implements Listener {
|
public class AuthMePlayerListener implements Listener {
|
||||||
|
|
||||||
|
public AuthMe plugin;
|
||||||
|
private Messages m = Messages.getInstance();
|
||||||
|
|
||||||
public static ConcurrentHashMap<String, GameMode> gameMode = new ConcurrentHashMap<>();
|
public static ConcurrentHashMap<String, GameMode> gameMode = new ConcurrentHashMap<>();
|
||||||
public static ConcurrentHashMap<String, String> joinMessage = new ConcurrentHashMap<>();
|
public static ConcurrentHashMap<String, String> joinMessage = new ConcurrentHashMap<>();
|
||||||
private Messages m = Messages.getInstance();
|
|
||||||
public AuthMe plugin;
|
|
||||||
public static ConcurrentHashMap<String, Boolean> causeByAuthMe = new ConcurrentHashMap<>();
|
public static ConcurrentHashMap<String, Boolean> causeByAuthMe = new ConcurrentHashMap<>();
|
||||||
private List<String> antibot = new ArrayList<>();
|
private List<String> antibot = new ArrayList<>();
|
||||||
|
|
||||||
@ -65,41 +66,36 @@ public class AuthMePlayerListener implements Listener {
|
|||||||
|
|
||||||
private void handleChat(AsyncPlayerChatEvent event) {
|
private void handleChat(AsyncPlayerChatEvent event) {
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
if (!Utils.checkAuth(player)) {
|
|
||||||
String cmd = event.getMessage().split(" ")[0];
|
if (Settings.isChatAllowed)
|
||||||
if (!Settings.isChatAllowed && !(Settings.allowCommands.contains(cmd))) {
|
return;
|
||||||
event.setCancelled(true);
|
if (Utils.checkAuth(player))
|
||||||
}
|
return;
|
||||||
if (plugin.database.isAuthAvailable(player.getName().toLowerCase())) {
|
|
||||||
m.send(player, "login_msg");
|
event.setCancelled(true);
|
||||||
|
|
||||||
|
if (plugin.database.isAuthAvailable(player.getName().toLowerCase())) {
|
||||||
|
m.send(player, "login_msg");
|
||||||
|
} else {
|
||||||
|
if (Settings.emailRegistration) {
|
||||||
|
m.send(player, "reg_email_msg");
|
||||||
} else {
|
} else {
|
||||||
if (Settings.emailRegistration) {
|
m.send(player, "reg_msg");
|
||||||
m.send(player, "reg_email_msg");
|
|
||||||
} else {
|
|
||||||
m.send(player, "reg_msg");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
|
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
|
||||||
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
|
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
|
||||||
String msg = event.getMessage();
|
String cmd = event.getMessage().split(" ")[0].toLowerCase();
|
||||||
if (msg.equalsIgnoreCase("/worldedit cui"))
|
if (Settings.useEssentialsMotd && cmd.equals("/motd"))
|
||||||
return;
|
|
||||||
|
|
||||||
String cmd = msg.split(" ")[0];
|
|
||||||
if (cmd.equalsIgnoreCase("/login") || cmd.equalsIgnoreCase("/register") || cmd.equalsIgnoreCase("/l") || cmd.equalsIgnoreCase("/reg") || cmd.equalsIgnoreCase("/email") || cmd.equalsIgnoreCase("/captcha"))
|
|
||||||
return;
|
|
||||||
if (Settings.useEssentialsMotd && cmd.equalsIgnoreCase("/motd"))
|
|
||||||
return;
|
return;
|
||||||
if (Settings.allowCommands.contains(cmd))
|
if (Settings.allowCommands.contains(cmd))
|
||||||
return;
|
return;
|
||||||
|
if (Utils.checkAuth(event.getPlayer()))
|
||||||
if (!Utils.checkAuth(event.getPlayer())) {
|
return;
|
||||||
event.setMessage("/notloggedin");
|
event.setCancelled(true);
|
||||||
event.setCancelled(true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.NORMAL)
|
@EventHandler(ignoreCancelled = true, priority = EventPriority.NORMAL)
|
||||||
@ -134,22 +130,25 @@ public class AuthMePlayerListener implements Listener {
|
|||||||
|
|
||||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
|
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
|
||||||
public void onPlayerMove(PlayerMoveEvent event) {
|
public void onPlayerMove(PlayerMoveEvent event) {
|
||||||
|
if (Settings.isMovementAllowed && Settings.getMovementRadius <= 0)
|
||||||
|
return;
|
||||||
|
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
if (Utils.checkAuth(player))
|
if (Utils.checkAuth(player))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!Settings.isMovementAllowed) {
|
if (!Settings.isMovementAllowed) {
|
||||||
if (Settings.isRemoveSpeedEnabled) {
|
if (event.getFrom().distance(event.getTo()) > 0) {
|
||||||
player.setWalkSpeed(0.0f);
|
if (Settings.isRemoveSpeedEnabled) {
|
||||||
player.setFlySpeed(0.0f);
|
player.setWalkSpeed(0.0f);
|
||||||
}
|
player.setFlySpeed(0.0f);
|
||||||
if (!event.getFrom().getBlock().equals(event.getTo().getBlock())) {
|
}
|
||||||
event.setTo(event.getFrom());
|
event.setTo(event.getFrom());
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Settings.getMovementRadius == 0) {
|
if (Settings.getMovementRadius <= 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -202,8 +201,16 @@ public class AuthMePlayerListener implements Listener {
|
|||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST)
|
@EventHandler(priority = EventPriority.HIGHEST)
|
||||||
public void onPlayerJoin(final PlayerJoinEvent event) {
|
public void onPlayerJoin(final PlayerJoinEvent event) {
|
||||||
if (event.getPlayer() == null) {
|
if (event.getPlayer() == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
final Player player = event.getPlayer();
|
||||||
|
String name = player.getName().toLowerCase();
|
||||||
|
|
||||||
|
// Remove the join message while the player isn't logging in
|
||||||
|
if (Settings.delayJoinLeaveMessages && event.getJoinMessage() != null) {
|
||||||
|
joinMessage.put(name, event.getJoinMessage());
|
||||||
|
event.setJoinMessage(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Shedule login task so works after the prelogin
|
// Shedule login task so works after the prelogin
|
||||||
@ -212,16 +219,7 @@ public class AuthMePlayerListener implements Listener {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
Player player = event.getPlayer();
|
|
||||||
String name = player.getName().toLowerCase();
|
|
||||||
|
|
||||||
plugin.management.performJoin(player);
|
plugin.management.performJoin(player);
|
||||||
|
|
||||||
// Remove the join message while the player isn't logging in
|
|
||||||
if ((Settings.enableProtection || Settings.delayJoinMessage) && event.getJoinMessage() != null) {
|
|
||||||
joinMessage.put(name, event.getJoinMessage());
|
|
||||||
event.setJoinMessage(null);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -374,12 +372,12 @@ public class AuthMePlayerListener implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
String name = player.getName().toLowerCase();
|
|
||||||
|
if (!Utils.checkAuth(player) && Settings.delayJoinLeaveMessages) {
|
||||||
|
event.setQuitMessage(null);
|
||||||
|
}
|
||||||
|
|
||||||
plugin.management.performQuit(player, false);
|
plugin.management.performQuit(player, false);
|
||||||
|
|
||||||
if (!PlayerCache.getInstance().isAuthenticated(name) && Settings.enableProtection)
|
|
||||||
event.setQuitMessage(null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
|
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
|
||||||
|
|||||||
@ -7,7 +7,7 @@ import org.bukkit.event.Listener;
|
|||||||
import org.bukkit.event.player.PlayerEditBookEvent;
|
import org.bukkit.event.player.PlayerEditBookEvent;
|
||||||
|
|
||||||
import fr.xephi.authme.AuthMe;
|
import fr.xephi.authme.AuthMe;
|
||||||
import fr.xephi.authme.Utils;
|
import fr.xephi.authme.util.Utils;
|
||||||
|
|
||||||
public class AuthMePlayerListener16 implements Listener {
|
public class AuthMePlayerListener16 implements Listener {
|
||||||
|
|
||||||
|
|||||||
@ -7,7 +7,7 @@ import org.bukkit.event.Listener;
|
|||||||
import org.bukkit.event.player.PlayerInteractAtEntityEvent;
|
import org.bukkit.event.player.PlayerInteractAtEntityEvent;
|
||||||
|
|
||||||
import fr.xephi.authme.AuthMe;
|
import fr.xephi.authme.AuthMe;
|
||||||
import fr.xephi.authme.Utils;
|
import fr.xephi.authme.util.Utils;
|
||||||
|
|
||||||
public class AuthMePlayerListener18 implements Listener {
|
public class AuthMePlayerListener18 implements Listener {
|
||||||
|
|
||||||
|
|||||||
@ -9,9 +9,9 @@ import org.bukkit.event.server.ServerListPingEvent;
|
|||||||
|
|
||||||
import fr.xephi.authme.AuthMe;
|
import fr.xephi.authme.AuthMe;
|
||||||
import fr.xephi.authme.ConsoleLogger;
|
import fr.xephi.authme.ConsoleLogger;
|
||||||
import fr.xephi.authme.Utils;
|
|
||||||
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.Utils;
|
||||||
|
|
||||||
public class AuthMeServerListener implements Listener {
|
public class AuthMeServerListener implements Listener {
|
||||||
|
|
||||||
|
|||||||
@ -1,38 +1,35 @@
|
|||||||
package fr.xephi.authme.process;
|
package fr.xephi.authme.process;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.plugin.PluginManager;
|
|
||||||
|
|
||||||
import fr.xephi.authme.AuthMe;
|
import fr.xephi.authme.AuthMe;
|
||||||
|
import fr.xephi.authme.process.email.AsyncChangeEmail;
|
||||||
import fr.xephi.authme.process.join.AsyncronousJoin;
|
import fr.xephi.authme.process.join.AsyncronousJoin;
|
||||||
import fr.xephi.authme.process.login.AsyncronousLogin;
|
import fr.xephi.authme.process.login.AsyncronousLogin;
|
||||||
import fr.xephi.authme.process.logout.AsyncronousLogout;
|
import fr.xephi.authme.process.logout.AsyncronousLogout;
|
||||||
import fr.xephi.authme.process.quit.AsyncronousQuit;
|
import fr.xephi.authme.process.quit.AsyncronousQuit;
|
||||||
import fr.xephi.authme.process.register.AsyncronousRegister;
|
import fr.xephi.authme.process.register.AsyncRegister;
|
||||||
import fr.xephi.authme.process.unregister.AsyncronousUnregister;
|
import fr.xephi.authme.process.unregister.AsyncronousUnregister;
|
||||||
import fr.xephi.authme.security.RandomString;
|
import fr.xephi.authme.security.RandomString;
|
||||||
import fr.xephi.authme.settings.Settings;
|
import fr.xephi.authme.settings.Settings;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.scheduler.BukkitScheduler;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @authors Xephi59,
|
* @authors Xephi59,
|
||||||
* <a href="http://dev.bukkit.org/profiles/Possible/">Possible</a>
|
* <a href="http://dev.bukkit.org/profiles/Possible/">Possible</a>
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class Management {
|
public class Management {
|
||||||
|
|
||||||
public AuthMe plugin;
|
private final AuthMe plugin;
|
||||||
|
private final BukkitScheduler sched;
|
||||||
public static RandomString rdm = new RandomString(Settings.captchaLength);
|
public static RandomString rdm = new RandomString(Settings.captchaLength);
|
||||||
public PluginManager pm;
|
|
||||||
|
|
||||||
public Management(AuthMe plugin) {
|
public Management(AuthMe plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
this.pm = plugin.getServer().getPluginManager();
|
this.sched = this.plugin.getServer().getScheduler();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void performLogin(final Player player, final String password, final boolean forceLogin) {
|
public void performLogin(final Player player, final String password, final boolean forceLogin) {
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {
|
sched.runTaskAsynchronously(plugin, new Runnable() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
@ -41,18 +38,8 @@ public class Management {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void performRegister(final Player player, final String password, final String email) {
|
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
new AsyncronousRegister(player, password, email, plugin, plugin.database).process();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public void performLogout(final Player player) {
|
public void performLogout(final Player player) {
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {
|
sched.runTaskAsynchronously(plugin, new Runnable() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
@ -61,19 +48,28 @@ public class Management {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void performQuit(final Player player, final boolean isKick) {
|
public void performRegister(final Player player, final String password, final String email) {
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {
|
sched.runTaskAsynchronously(plugin, new Runnable() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
new AsyncronousQuit(player, plugin, plugin.database, isKick).process();
|
new AsyncRegister(player, password, email, plugin, plugin.database).process();
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public void performUnregister(final Player player, final String password, final boolean force) {
|
||||||
|
sched.runTaskAsynchronously(plugin, new Runnable() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
new AsyncronousUnregister(player, password, force, plugin).process();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void performJoin(final Player player) {
|
public void performJoin(final Player player) {
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {
|
sched.runTaskAsynchronously(plugin, new Runnable() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
@ -83,13 +79,32 @@ public class Management {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void performUnregister(final Player player, final String password, final boolean force) {
|
public void performQuit(final Player player, final boolean isKick) {
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {
|
sched.runTaskAsynchronously(plugin, new Runnable() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
new AsyncronousUnregister(player, password, force, plugin).process();
|
new AsyncronousQuit(player, plugin, plugin.database, isKick).process();
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public void performAddEmail(final Player player, final String newEmail, final String newEmailVerify) {
|
||||||
|
sched.runTaskAsynchronously(plugin, new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
new AsyncChangeEmail(player, plugin, null, newEmail, newEmailVerify).process();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void performChangeEmail(final Player player, final String oldEmail, final String newEmail) {
|
||||||
|
sched.runTaskAsynchronously(plugin, new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
new AsyncChangeEmail(player, plugin, oldEmail, newEmail).process();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,97 @@
|
|||||||
|
package fr.xephi.authme.process.email;
|
||||||
|
|
||||||
|
import fr.xephi.authme.AuthMe;
|
||||||
|
import fr.xephi.authme.ConsoleLogger;
|
||||||
|
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||||
|
import fr.xephi.authme.cache.auth.PlayerCache;
|
||||||
|
import fr.xephi.authme.settings.Messages;
|
||||||
|
import fr.xephi.authme.settings.Settings;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
public class AsyncChangeEmail {
|
||||||
|
|
||||||
|
private final Player player;
|
||||||
|
private final AuthMe plugin;
|
||||||
|
private final String oldEmail;
|
||||||
|
private final String newEmail;
|
||||||
|
private final String newEmailVerify;
|
||||||
|
private final Messages m;
|
||||||
|
|
||||||
|
public AsyncChangeEmail(Player player, AuthMe plugin, String oldEmail, String newEmail, String newEmailVerify) {
|
||||||
|
this.player = player;
|
||||||
|
this.plugin = plugin;
|
||||||
|
this.oldEmail = oldEmail;
|
||||||
|
this.newEmail = newEmail;
|
||||||
|
this.newEmailVerify = newEmailVerify;
|
||||||
|
this.m = Messages.getInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
public AsyncChangeEmail(Player player, AuthMe plugin, String oldEmail, String newEmail) {
|
||||||
|
this(player, plugin, oldEmail, newEmail, newEmail);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void process() {
|
||||||
|
try {
|
||||||
|
String playerName = player.getName().toLowerCase();
|
||||||
|
|
||||||
|
if (Settings.getmaxRegPerEmail > 0) {
|
||||||
|
if (!plugin.authmePermissible(player, "authme.allow2accounts") && plugin.database.getAllAuthsByEmail(newEmail).size() >= Settings.getmaxRegPerEmail) {
|
||||||
|
m.send(player, "max_reg");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (PlayerCache.getInstance().isAuthenticated(playerName)) {
|
||||||
|
if (!newEmail.equals(newEmailVerify)) {
|
||||||
|
m.send(player, "email_confirm");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
PlayerAuth auth = PlayerCache.getInstance().getAuth(playerName);
|
||||||
|
if (oldEmail != null) {
|
||||||
|
if (auth.getEmail() == null || auth.getEmail().equals("your@email.com") || auth.getEmail().isEmpty()) {
|
||||||
|
m.send(player, "usage_email_add");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!oldEmail.equals(auth.getEmail())) {
|
||||||
|
m.send(player, "old_email_invalid");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!Settings.isEmailCorrect(newEmail)) {
|
||||||
|
m.send(player, "new_email_invalid");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String old = auth.getEmail();
|
||||||
|
auth.setEmail(newEmail);
|
||||||
|
if (!plugin.database.updateEmail(auth)) {
|
||||||
|
m.send(player, "error");
|
||||||
|
auth.setEmail(old);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
PlayerCache.getInstance().updatePlayer(auth);
|
||||||
|
if (oldEmail == null) {
|
||||||
|
m.send(player, "email_added");
|
||||||
|
player.sendMessage(auth.getEmail());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
m.send(player, "email_changed");
|
||||||
|
player.sendMessage(Arrays.toString(m.send("email_defined")) + auth.getEmail());
|
||||||
|
} else {
|
||||||
|
if (plugin.database.isAuthAvailable(playerName)) {
|
||||||
|
m.send(player, "login_msg");
|
||||||
|
} else {
|
||||||
|
if (Settings.emailRegistration)
|
||||||
|
m.send(player, "reg_email_msg");
|
||||||
|
else
|
||||||
|
m.send(player, "reg_msg");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
ConsoleLogger.showError(e.getMessage());
|
||||||
|
ConsoleLogger.writeStackTrace(e);
|
||||||
|
m.send(player, "error");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -13,8 +13,6 @@ 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.Utils;
|
|
||||||
import fr.xephi.authme.Utils.GroupType;
|
|
||||||
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.cache.limbo.LimboCache;
|
import fr.xephi.authme.cache.limbo.LimboCache;
|
||||||
@ -28,6 +26,8 @@ import fr.xephi.authme.settings.Settings;
|
|||||||
import fr.xephi.authme.settings.Spawn;
|
import fr.xephi.authme.settings.Spawn;
|
||||||
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.GroupType;
|
||||||
|
|
||||||
public class AsyncronousJoin {
|
public class AsyncronousJoin {
|
||||||
|
|
||||||
@ -58,8 +58,7 @@ public class AsyncronousJoin {
|
|||||||
plugin.ess.getUser(player).setSocialSpyEnabled(false);
|
plugin.ess.getUser(player).setSocialSpyEnabled(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!plugin.isCanConnect())
|
if (!plugin.canConnect()) {
|
||||||
{
|
|
||||||
final GameMode gM = AuthMePlayerListener.gameMode.get(name);
|
final GameMode gM = AuthMePlayerListener.gameMode.get(name);
|
||||||
sched.scheduleSyncDelayedTask(plugin, new Runnable() {
|
sched.scheduleSyncDelayedTask(plugin, new Runnable() {
|
||||||
|
|
||||||
@ -71,6 +70,7 @@ public class AsyncronousJoin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final String ip = plugin.getIP(player);
|
final String ip = plugin.getIP(player);
|
||||||
|
|||||||
@ -9,7 +9,6 @@ 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.Utils;
|
|
||||||
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.cache.limbo.LimboCache;
|
import fr.xephi.authme.cache.limbo.LimboCache;
|
||||||
@ -21,6 +20,7 @@ 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 fr.xephi.authme.task.MessageTask;
|
import fr.xephi.authme.task.MessageTask;
|
||||||
|
import fr.xephi.authme.util.Utils;
|
||||||
|
|
||||||
public class AsyncronousLogin {
|
public class AsyncronousLogin {
|
||||||
|
|
||||||
|
|||||||
@ -8,8 +8,6 @@ import org.bukkit.plugin.PluginManager;
|
|||||||
import org.bukkit.potion.PotionEffectType;
|
import org.bukkit.potion.PotionEffectType;
|
||||||
|
|
||||||
import fr.xephi.authme.AuthMe;
|
import fr.xephi.authme.AuthMe;
|
||||||
import fr.xephi.authme.Utils;
|
|
||||||
import fr.xephi.authme.Utils.GroupType;
|
|
||||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||||
import fr.xephi.authme.cache.backup.JsonCache;
|
import fr.xephi.authme.cache.backup.JsonCache;
|
||||||
import fr.xephi.authme.cache.limbo.LimboCache;
|
import fr.xephi.authme.cache.limbo.LimboCache;
|
||||||
@ -21,6 +19,8 @@ import fr.xephi.authme.events.RestoreInventoryEvent;
|
|||||||
import fr.xephi.authme.events.SpawnTeleportEvent;
|
import fr.xephi.authme.events.SpawnTeleportEvent;
|
||||||
import fr.xephi.authme.listener.AuthMePlayerListener;
|
import fr.xephi.authme.listener.AuthMePlayerListener;
|
||||||
import fr.xephi.authme.settings.Settings;
|
import fr.xephi.authme.settings.Settings;
|
||||||
|
import fr.xephi.authme.util.Utils;
|
||||||
|
import fr.xephi.authme.util.Utils.GroupType;
|
||||||
|
|
||||||
public class ProcessSyncronousPlayerLogin implements Runnable {
|
public class ProcessSyncronousPlayerLogin implements Runnable {
|
||||||
|
|
||||||
|
|||||||
@ -5,8 +5,6 @@ import org.bukkit.entity.Player;
|
|||||||
import org.bukkit.scheduler.BukkitScheduler;
|
import org.bukkit.scheduler.BukkitScheduler;
|
||||||
|
|
||||||
import fr.xephi.authme.AuthMe;
|
import fr.xephi.authme.AuthMe;
|
||||||
import fr.xephi.authme.Utils;
|
|
||||||
import fr.xephi.authme.Utils.GroupType;
|
|
||||||
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.cache.limbo.LimboCache;
|
import fr.xephi.authme.cache.limbo.LimboCache;
|
||||||
@ -14,6 +12,8 @@ import fr.xephi.authme.datasource.DataSource;
|
|||||||
import fr.xephi.authme.events.AuthMeTeleportEvent;
|
import fr.xephi.authme.events.AuthMeTeleportEvent;
|
||||||
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.Utils;
|
||||||
|
import fr.xephi.authme.util.Utils.GroupType;
|
||||||
|
|
||||||
public class AsyncronousLogout {
|
public class AsyncronousLogout {
|
||||||
|
|
||||||
@ -55,22 +55,12 @@ public class AsyncronousLogout {
|
|||||||
|
|
||||||
PlayerCache.getInstance().removePlayer(name);
|
PlayerCache.getInstance().removePlayer(name);
|
||||||
database.setUnlogged(name);
|
database.setUnlogged(name);
|
||||||
if (Settings.isTeleportToSpawnEnabled && !Settings.noTeleport) {
|
sched.scheduleSyncDelayedTask(plugin, new Runnable() {
|
||||||
Location spawnLoc = plugin.getSpawnLocation(p);
|
@Override
|
||||||
final AuthMeTeleportEvent tpEvent = new AuthMeTeleportEvent(p, spawnLoc);
|
public void run() {
|
||||||
sched.scheduleSyncDelayedTask(plugin, new Runnable() {
|
Utils.teleportToSpawn(p);
|
||||||
|
}
|
||||||
@Override
|
});
|
||||||
public void run() {
|
|
||||||
plugin.getServer().getPluginManager().callEvent(tpEvent);
|
|
||||||
if (!tpEvent.isCancelled()) {
|
|
||||||
if (tpEvent.getTo() != null)
|
|
||||||
p.teleport(tpEvent.getTo());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (LimboCache.getInstance().hasLimboPlayer(name))
|
if (LimboCache.getInstance().hasLimboPlayer(name))
|
||||||
LimboCache.getInstance().deleteLimboPlayer(name);
|
LimboCache.getInstance().deleteLimboPlayer(name);
|
||||||
LimboCache.getInstance().addLimboPlayer(player);
|
LimboCache.getInstance().addLimboPlayer(player);
|
||||||
|
|||||||
@ -6,7 +6,6 @@ import org.bukkit.entity.Player;
|
|||||||
import org.bukkit.scheduler.BukkitTask;
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
|
|
||||||
import fr.xephi.authme.AuthMe;
|
import fr.xephi.authme.AuthMe;
|
||||||
import fr.xephi.authme.Utils;
|
|
||||||
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.cache.limbo.LimboCache;
|
import fr.xephi.authme.cache.limbo.LimboCache;
|
||||||
@ -14,6 +13,7 @@ import fr.xephi.authme.cache.limbo.LimboPlayer;
|
|||||||
import fr.xephi.authme.datasource.DataSource;
|
import fr.xephi.authme.datasource.DataSource;
|
||||||
import fr.xephi.authme.listener.AuthMePlayerListener;
|
import fr.xephi.authme.listener.AuthMePlayerListener;
|
||||||
import fr.xephi.authme.settings.Settings;
|
import fr.xephi.authme.settings.Settings;
|
||||||
|
import fr.xephi.authme.util.Utils;
|
||||||
|
|
||||||
public class AsyncronousQuit {
|
public class AsyncronousQuit {
|
||||||
|
|
||||||
|
|||||||
@ -1,10 +1,5 @@
|
|||||||
package fr.xephi.authme.process.register;
|
package fr.xephi.authme.process.register;
|
||||||
|
|
||||||
import java.security.NoSuchAlgorithmException;
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
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;
|
||||||
@ -13,95 +8,90 @@ import fr.xephi.authme.datasource.DataSource;
|
|||||||
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.entity.Player;
|
||||||
|
|
||||||
public class AsyncronousRegister {
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
public class AsyncRegister {
|
||||||
|
|
||||||
protected Player player;
|
protected Player player;
|
||||||
protected String name;
|
protected String name;
|
||||||
protected String password;
|
protected String password;
|
||||||
protected String email = "";
|
protected String email = "";
|
||||||
protected boolean allowRegister;
|
|
||||||
private AuthMe plugin;
|
private AuthMe plugin;
|
||||||
private DataSource database;
|
private DataSource database;
|
||||||
private Messages m = Messages.getInstance();
|
private Messages m = Messages.getInstance();
|
||||||
|
|
||||||
public AsyncronousRegister(Player player, String password, String email,
|
public AsyncRegister(Player player, String password, String email,
|
||||||
AuthMe plugin, DataSource data) {
|
AuthMe plugin, DataSource data) {
|
||||||
this.player = player;
|
this.player = player;
|
||||||
this.password = password;
|
this.password = password;
|
||||||
name = player.getName().toLowerCase();
|
name = player.getName().toLowerCase();
|
||||||
this.email = email;
|
this.email = email;
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
this.database = data;
|
this.database = data;
|
||||||
this.allowRegister = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String getIp() {
|
protected String getIp() {
|
||||||
return plugin.getIP(player);
|
return plugin.getIP(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void preRegister() {
|
protected boolean preRegisterCheck() throws Exception {
|
||||||
String lowpass = password.toLowerCase();
|
String lowpass = password.toLowerCase();
|
||||||
if (PlayerCache.getInstance().isAuthenticated(name)) {
|
if (PlayerCache.getInstance().isAuthenticated(name)) {
|
||||||
m.send(player, "logged_in");
|
m.send(player, "logged_in");
|
||||||
allowRegister = false;
|
return false;
|
||||||
}
|
} else if (!Settings.isRegistrationEnabled) {
|
||||||
|
|
||||||
else if (!Settings.isRegistrationEnabled) {
|
|
||||||
m.send(player, "reg_disabled");
|
m.send(player, "reg_disabled");
|
||||||
allowRegister = false;
|
return false;
|
||||||
}
|
} else if (lowpass.contains("delete") || lowpass.contains("where") || lowpass.contains("insert") || lowpass.contains("modify") || lowpass.contains("from") || lowpass.contains("select") || lowpass.contains(";") || lowpass.contains("null") || !lowpass.matches(Settings.getPassRegex)) {
|
||||||
|
|
||||||
else if (lowpass.contains("delete") || lowpass.contains("where") || lowpass.contains("insert") || lowpass.contains("modify") || lowpass.contains("from") || lowpass.contains("select") || lowpass.contains(";") || lowpass.contains("null") || !lowpass.matches(Settings.getPassRegex)) {
|
|
||||||
m.send(player, "password_error");
|
m.send(player, "password_error");
|
||||||
allowRegister = false;
|
return false;
|
||||||
}
|
} else if (lowpass.equalsIgnoreCase(player.getName())) {
|
||||||
|
|
||||||
else if (lowpass.equalsIgnoreCase(player.getName())) {
|
|
||||||
m.send(player, "password_error_nick");
|
m.send(player, "password_error_nick");
|
||||||
allowRegister = false;
|
return false;
|
||||||
}
|
} else if (password.length() < Settings.getPasswordMinLen || password.length() > Settings.passwordMaxLength) {
|
||||||
|
|
||||||
else if (password.length() < Settings.getPasswordMinLen || password.length() > Settings.passwordMaxLength) {
|
|
||||||
m.send(player, "pass_len");
|
m.send(player, "pass_len");
|
||||||
allowRegister = false;
|
return false;
|
||||||
}
|
} else if (!Settings.unsafePasswords.isEmpty() && Settings.unsafePasswords.contains(password.toLowerCase())) {
|
||||||
|
|
||||||
else if (!Settings.unsafePasswords.isEmpty() && Settings.unsafePasswords.contains(password.toLowerCase())) {
|
|
||||||
m.send(player, "password_error_unsafe");
|
m.send(player, "password_error_unsafe");
|
||||||
allowRegister = false;
|
return false;
|
||||||
} else if (database.isAuthAvailable(name)) {
|
} else if (database.isAuthAvailable(name)) {
|
||||||
m.send(player, "user_regged");
|
m.send(player, "user_regged");
|
||||||
allowRegister = false;
|
return false;
|
||||||
}
|
} else if (Settings.getmaxRegPerIp > 0) {
|
||||||
|
|
||||||
else if (Settings.getmaxRegPerIp > 0) {
|
|
||||||
if (!plugin.authmePermissible(player, "authme.allow2accounts") && database.getAllAuthsByIp(getIp()).size() >= Settings.getmaxRegPerIp && !getIp().equalsIgnoreCase("127.0.0.1") && !getIp().equalsIgnoreCase("localhost")) {
|
if (!plugin.authmePermissible(player, "authme.allow2accounts") && database.getAllAuthsByIp(getIp()).size() >= Settings.getmaxRegPerIp && !getIp().equalsIgnoreCase("127.0.0.1") && !getIp().equalsIgnoreCase("localhost")) {
|
||||||
m.send(player, "max_reg");
|
m.send(player, "max_reg");
|
||||||
allowRegister = false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void process() {
|
public void process() {
|
||||||
preRegister();
|
try {
|
||||||
if (!allowRegister)
|
if (!preRegisterCheck())
|
||||||
return;
|
return;
|
||||||
if (!email.isEmpty() && !email.equals("")) {
|
if (!email.isEmpty() && !email.equals("")) {
|
||||||
if (Settings.getmaxRegPerEmail > 0) {
|
if (Settings.getmaxRegPerEmail > 0) {
|
||||||
if (!plugin.authmePermissible(player, "authme.allow2accounts") && database.getAllAuthsByEmail(email).size() >= Settings.getmaxRegPerEmail) {
|
if (!plugin.authmePermissible(player, "authme.allow2accounts") && database.getAllAuthsByEmail(email).size() >= Settings.getmaxRegPerEmail) {
|
||||||
m.send(player, "max_reg");
|
m.send(player, "max_reg");
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
emailRegister();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
emailRegister();
|
passwordRegister();
|
||||||
return;
|
} catch (Exception e) {
|
||||||
|
ConsoleLogger.showError(e.getMessage());
|
||||||
|
ConsoleLogger.writeStackTrace(e);
|
||||||
|
m.send(player, "error");
|
||||||
}
|
}
|
||||||
passwordRegister();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void emailRegister() {
|
protected void emailRegister() throws Exception {
|
||||||
if (Settings.getmaxRegPerEmail > 0) {
|
if (Settings.getmaxRegPerEmail > 0) {
|
||||||
if (!plugin.authmePermissible(player, "authme.allow2accounts") && database.getAllAuthsByEmail(email).size() >= Settings.getmaxRegPerEmail) {
|
if (!plugin.authmePermissible(player, "authme.allow2accounts") && database.getAllAuthsByEmail(email).size() >= Settings.getmaxRegPerEmail) {
|
||||||
m.send(player, "max_reg");
|
m.send(player, "max_reg");
|
||||||
@ -109,14 +99,8 @@ public class AsyncronousRegister {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
PlayerAuth auth;
|
PlayerAuth auth;
|
||||||
try {
|
final String hashnew = PasswordSecurity.getHash(Settings.getPasswordHash, password, name);
|
||||||
final String hashnew = PasswordSecurity.getHash(Settings.getPasswordHash, password, name);
|
auth = new PlayerAuth(name, hashnew, getIp(), 0, (int) player.getLocation().getX(), (int) player.getLocation().getY(), (int) player.getLocation().getZ(), player.getLocation().getWorld().getName(), email, player.getName());
|
||||||
auth = new PlayerAuth(name, hashnew, getIp(), 0, (int) player.getLocation().getX(), (int) player.getLocation().getY(), (int) player.getLocation().getZ(), player.getLocation().getWorld().getName(), email, player.getName());
|
|
||||||
} catch (NoSuchAlgorithmException e) {
|
|
||||||
ConsoleLogger.showError(e.getMessage());
|
|
||||||
m.send(player, "error");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (PasswordSecurity.userSalt.containsKey(name)) {
|
if (PasswordSecurity.userSalt.containsKey(name)) {
|
||||||
auth.setSalt(PasswordSecurity.userSalt.get(name));
|
auth.setSalt(PasswordSecurity.userSalt.get(name));
|
||||||
}
|
}
|
||||||
@ -124,8 +108,9 @@ public class AsyncronousRegister {
|
|||||||
database.updateEmail(auth);
|
database.updateEmail(auth);
|
||||||
database.updateSession(auth);
|
database.updateSession(auth);
|
||||||
plugin.mail.main(auth, password);
|
plugin.mail.main(auth, password);
|
||||||
ProcessSyncronousEmailRegister syncronous = new ProcessSyncronousEmailRegister(player, plugin);
|
ProcessSyncEmailRegister syncronous = new ProcessSyncEmailRegister(player, plugin);
|
||||||
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, syncronous);
|
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, syncronous);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void passwordRegister() {
|
protected void passwordRegister() {
|
||||||
@ -6,22 +6,22 @@ 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.Utils;
|
|
||||||
import fr.xephi.authme.cache.limbo.LimboCache;
|
import fr.xephi.authme.cache.limbo.LimboCache;
|
||||||
import fr.xephi.authme.cache.limbo.LimboPlayer;
|
import fr.xephi.authme.cache.limbo.LimboPlayer;
|
||||||
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;
|
||||||
|
|
||||||
public class ProcessSyncronousEmailRegister implements Runnable {
|
public class ProcessSyncEmailRegister implements Runnable {
|
||||||
|
|
||||||
protected Player player;
|
protected Player player;
|
||||||
protected String name;
|
protected String name;
|
||||||
private AuthMe plugin;
|
private AuthMe plugin;
|
||||||
private Messages m = Messages.getInstance();
|
private Messages m = Messages.getInstance();
|
||||||
|
|
||||||
public ProcessSyncronousEmailRegister(Player player, AuthMe plugin) {
|
public ProcessSyncEmailRegister(Player player, AuthMe plugin) {
|
||||||
this.player = player;
|
this.player = player;
|
||||||
this.name = player.getName().toLowerCase();
|
this.name = player.getName().toLowerCase();
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
@ -10,7 +10,6 @@ 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.Utils;
|
|
||||||
import fr.xephi.authme.cache.limbo.LimboCache;
|
import fr.xephi.authme.cache.limbo.LimboCache;
|
||||||
import fr.xephi.authme.cache.limbo.LimboPlayer;
|
import fr.xephi.authme.cache.limbo.LimboPlayer;
|
||||||
import fr.xephi.authme.events.AuthMeTeleportEvent;
|
import fr.xephi.authme.events.AuthMeTeleportEvent;
|
||||||
@ -21,6 +20,7 @@ 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;
|
||||||
|
|
||||||
public class ProcessSyncronousPasswordRegister implements Runnable {
|
public class ProcessSyncronousPasswordRegister implements Runnable {
|
||||||
|
|
||||||
@ -48,17 +48,7 @@ public class ProcessSyncronousPasswordRegister implements Runnable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void forceLogin(Player player) {
|
protected void forceLogin(Player player) {
|
||||||
if (Settings.isTeleportToSpawnEnabled && !Settings.noTeleport) {
|
Utils.teleportToSpawn(player);
|
||||||
Location spawnLoc = plugin.getSpawnLocation(player);
|
|
||||||
AuthMeTeleportEvent tpEvent = new AuthMeTeleportEvent(player, spawnLoc);
|
|
||||||
plugin.getServer().getPluginManager().callEvent(tpEvent);
|
|
||||||
if (!tpEvent.isCancelled()) {
|
|
||||||
if (!tpEvent.getTo().getWorld().getChunkAt(tpEvent.getTo()).isLoaded()) {
|
|
||||||
tpEvent.getTo().getWorld().getChunkAt(tpEvent.getTo()).load();
|
|
||||||
}
|
|
||||||
player.teleport(tpEvent.getTo());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (LimboCache.getInstance().hasLimboPlayer(name))
|
if (LimboCache.getInstance().hasLimboPlayer(name))
|
||||||
LimboCache.getInstance().deleteLimboPlayer(name);
|
LimboCache.getInstance().deleteLimboPlayer(name);
|
||||||
LimboCache.getInstance().addLimboPlayer(player);
|
LimboCache.getInstance().addLimboPlayer(player);
|
||||||
@ -81,14 +71,7 @@ public class ProcessSyncronousPasswordRegister implements Runnable {
|
|||||||
LimboPlayer limbo = LimboCache.getInstance().getLimboPlayer(name);
|
LimboPlayer limbo = LimboCache.getInstance().getLimboPlayer(name);
|
||||||
if (limbo != null) {
|
if (limbo != null) {
|
||||||
player.setGameMode(limbo.getGameMode());
|
player.setGameMode(limbo.getGameMode());
|
||||||
if (Settings.isTeleportToSpawnEnabled && !Settings.noTeleport) {
|
Utils.teleportToSpawn(player);
|
||||||
Location loca = plugin.getSpawnLocation(player);
|
|
||||||
RegisterTeleportEvent tpEvent = new RegisterTeleportEvent(player, loca);
|
|
||||||
plugin.getServer().getPluginManager().callEvent(tpEvent);
|
|
||||||
if (!tpEvent.isCancelled() && tpEvent.getTo() != null) {
|
|
||||||
player.teleport(tpEvent.getTo());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Settings.protectInventoryBeforeLogInEnabled && plugin.inventoryProtector != null) {
|
if (Settings.protectInventoryBeforeLogInEnabled && plugin.inventoryProtector != null) {
|
||||||
RestoreInventoryEvent event = new RestoreInventoryEvent(player);
|
RestoreInventoryEvent event = new RestoreInventoryEvent(player);
|
||||||
|
|||||||
@ -11,8 +11,6 @@ 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.Utils;
|
|
||||||
import fr.xephi.authme.Utils.GroupType;
|
|
||||||
import fr.xephi.authme.cache.auth.PlayerCache;
|
import fr.xephi.authme.cache.auth.PlayerCache;
|
||||||
import fr.xephi.authme.cache.backup.JsonCache;
|
import fr.xephi.authme.cache.backup.JsonCache;
|
||||||
import fr.xephi.authme.cache.limbo.LimboCache;
|
import fr.xephi.authme.cache.limbo.LimboCache;
|
||||||
@ -22,6 +20,8 @@ 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.GroupType;
|
||||||
|
|
||||||
public class AsyncronousUnregister {
|
public class AsyncronousUnregister {
|
||||||
|
|
||||||
@ -55,15 +55,7 @@ public class AsyncronousUnregister {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (Settings.isForcedRegistrationEnabled) {
|
if (Settings.isForcedRegistrationEnabled) {
|
||||||
if (Settings.isTeleportToSpawnEnabled && !Settings.noTeleport) {
|
Utils.teleportToSpawn(player);
|
||||||
Location spawn = plugin.getSpawnLocation(player);
|
|
||||||
SpawnTeleportEvent tpEvent = new SpawnTeleportEvent(player, player.getLocation(), spawn, false);
|
|
||||||
plugin.getServer().getPluginManager().callEvent(tpEvent);
|
|
||||||
if (!tpEvent.isCancelled()) {
|
|
||||||
player.teleport(tpEvent.getTo());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
player.saveData();
|
player.saveData();
|
||||||
PlayerCache.getInstance().removePlayer(player.getName().toLowerCase());
|
PlayerCache.getInstance().removePlayer(player.getName().toLowerCase());
|
||||||
if (!Settings.getRegisteredGroup.isEmpty())
|
if (!Settings.getRegisteredGroup.isEmpty())
|
||||||
@ -98,22 +90,11 @@ public class AsyncronousUnregister {
|
|||||||
}
|
}
|
||||||
m.send(player, "unregistered");
|
m.send(player, "unregistered");
|
||||||
ConsoleLogger.info(player.getDisplayName() + " unregistered himself");
|
ConsoleLogger.info(player.getDisplayName() + " unregistered himself");
|
||||||
if (Settings.isTeleportToSpawnEnabled && !Settings.noTeleport) {
|
Utils.teleportToSpawn(player);
|
||||||
Location spawn = plugin.getSpawnLocation(player);
|
|
||||||
SpawnTeleportEvent tpEvent = new SpawnTeleportEvent(player, player.getLocation(), spawn, false);
|
|
||||||
plugin.getServer().getPluginManager().callEvent(tpEvent);
|
|
||||||
if (!tpEvent.isCancelled()) {
|
|
||||||
if (!tpEvent.getTo().getWorld().getChunkAt(tpEvent.getTo()).isLoaded()) {
|
|
||||||
tpEvent.getTo().getWorld().getChunkAt(tpEvent.getTo()).load();
|
|
||||||
}
|
|
||||||
player.teleport(tpEvent.getTo());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
} else {
|
} else {
|
||||||
m.send(player, "wrong_pwd");
|
m.send(player, "wrong_pwd");
|
||||||
}
|
}
|
||||||
} catch (NoSuchAlgorithmException ex) {
|
} catch (NoSuchAlgorithmException ignored) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,22 +1,16 @@
|
|||||||
package fr.xephi.authme.settings;
|
package fr.xephi.authme.settings;
|
||||||
|
|
||||||
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 java.util.ArrayList;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
|
||||||
|
|
||||||
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 fr.xephi.authme.datasource.DataSource.DataSourceType;
|
import fr.xephi.authme.datasource.DataSource.DataSourceType;
|
||||||
import fr.xephi.authme.security.HashAlgorithm;
|
import fr.xephi.authme.security.HashAlgorithm;
|
||||||
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public final class Settings extends YamlConfiguration {
|
public final class Settings extends YamlConfiguration {
|
||||||
|
|
||||||
@ -76,7 +70,7 @@ public final class Settings extends YamlConfiguration {
|
|||||||
purgeLimitedCreative, purgeAntiXray, purgePermissions,
|
purgeLimitedCreative, purgeAntiXray, purgePermissions,
|
||||||
enableProtection, enableAntiBot, recallEmail, useWelcomeMessage,
|
enableProtection, enableAntiBot, recallEmail, useWelcomeMessage,
|
||||||
broadcastWelcomeMessage, forceRegKick, forceRegLogin,
|
broadcastWelcomeMessage, forceRegKick, forceRegLogin,
|
||||||
checkVeryGames, delayJoinMessage, noTeleport, applyBlindEffect,
|
checkVeryGames, delayJoinLeaveMessages, noTeleport, applyBlindEffect,
|
||||||
customAttributes, generateImage, isRemoveSpeedEnabled, isMySQLWebsite;
|
customAttributes, generateImage, isRemoveSpeedEnabled, isMySQLWebsite;
|
||||||
|
|
||||||
public static String getNickRegex, getUnloggedinGroup, getMySQLHost,
|
public static String getNickRegex, getUnloggedinGroup, getMySQLHost,
|
||||||
@ -193,21 +187,22 @@ public final class Settings extends YamlConfiguration {
|
|||||||
backupWindowsPath = configFile.getString("BackupSystem.MysqlWindowsPath", "C:\\Program Files\\MySQL\\MySQL Server 5.1\\");
|
backupWindowsPath = configFile.getString("BackupSystem.MysqlWindowsPath", "C:\\Program Files\\MySQL\\MySQL Server 5.1\\");
|
||||||
isStopEnabled = configFile.getBoolean("Security.SQLProblem.stopServer", true);
|
isStopEnabled = configFile.getBoolean("Security.SQLProblem.stopServer", true);
|
||||||
reloadSupport = configFile.getBoolean("Security.ReloadCommand.useReloadCommandSupport", true);
|
reloadSupport = configFile.getBoolean("Security.ReloadCommand.useReloadCommandSupport", true);
|
||||||
allowCommands = configFile.getStringList("settings.restrictions.allowCommands");
|
allowCommands = new ArrayList<>();
|
||||||
if (configFile.contains("allowCommands")) {
|
for (String cmd : configFile.getStringList("settings.restrictions.allowCommands")) {
|
||||||
if (!allowCommands.contains("/login"))
|
allowCommands.add(cmd.toLowerCase());
|
||||||
allowCommands.add("/login");
|
|
||||||
if (!allowCommands.contains("/register"))
|
|
||||||
allowCommands.add("/register");
|
|
||||||
if (!allowCommands.contains("/l"))
|
|
||||||
allowCommands.add("/l");
|
|
||||||
if (!allowCommands.contains("/reg"))
|
|
||||||
allowCommands.add("/reg");
|
|
||||||
if (!allowCommands.contains("/email"))
|
|
||||||
allowCommands.add("/email");
|
|
||||||
if (!allowCommands.contains("/captcha"))
|
|
||||||
allowCommands.add("/captcha");
|
|
||||||
}
|
}
|
||||||
|
if (!allowCommands.contains("/login"))
|
||||||
|
allowCommands.add("/login");
|
||||||
|
if (!allowCommands.contains("/register"))
|
||||||
|
allowCommands.add("/register");
|
||||||
|
if (!allowCommands.contains("/l"))
|
||||||
|
allowCommands.add("/l");
|
||||||
|
if (!allowCommands.contains("/reg"))
|
||||||
|
allowCommands.add("/reg");
|
||||||
|
if (!allowCommands.contains("/email"))
|
||||||
|
allowCommands.add("/email");
|
||||||
|
if (!allowCommands.contains("/captcha"))
|
||||||
|
allowCommands.add("/captcha");
|
||||||
rakamakUsers = configFile.getString("Converter.Rakamak.fileName", "users.rak");
|
rakamakUsers = configFile.getString("Converter.Rakamak.fileName", "users.rak");
|
||||||
rakamakUsersIp = configFile.getString("Converter.Rakamak.ipFileName", "UsersIp.rak");
|
rakamakUsersIp = configFile.getString("Converter.Rakamak.ipFileName", "UsersIp.rak");
|
||||||
rakamakUseIp = configFile.getBoolean("Converter.Rakamak.useIp", false);
|
rakamakUseIp = configFile.getBoolean("Converter.Rakamak.useIp", false);
|
||||||
@ -273,7 +268,7 @@ public final class Settings extends YamlConfiguration {
|
|||||||
getMaxLoginPerIp = configFile.getInt("settings.restrictions.maxLoginPerIp", 0);
|
getMaxLoginPerIp = configFile.getInt("settings.restrictions.maxLoginPerIp", 0);
|
||||||
getMaxJoinPerIp = configFile.getInt("settings.restrictions.maxJoinPerIp", 0);
|
getMaxJoinPerIp = configFile.getInt("settings.restrictions.maxJoinPerIp", 0);
|
||||||
checkVeryGames = configFile.getBoolean("VeryGames.enableIpCheck", false);
|
checkVeryGames = configFile.getBoolean("VeryGames.enableIpCheck", false);
|
||||||
delayJoinMessage = configFile.getBoolean("settings.delayJoinMessage", false);
|
delayJoinLeaveMessages = configFile.getBoolean("settings.delayJoinLeaveMessage", false);
|
||||||
noTeleport = configFile.getBoolean("settings.restrictions.noTeleport", false);
|
noTeleport = configFile.getBoolean("settings.restrictions.noTeleport", false);
|
||||||
crazyloginFileName = configFile.getString("Converter.CrazyLogin.fileName", "accounts.db");
|
crazyloginFileName = configFile.getString("Converter.CrazyLogin.fileName", "accounts.db");
|
||||||
getPassRegex = configFile.getString("settings.restrictions.allowedPasswordCharacters", "[\\x21-\\x7E]*");
|
getPassRegex = configFile.getString("settings.restrictions.allowedPasswordCharacters", "[\\x21-\\x7E]*");
|
||||||
@ -402,8 +397,12 @@ public final class Settings extends YamlConfiguration {
|
|||||||
set("settings.restrictions.allowedNicknameCharacters", "[a-zA-Z0-9_]*");
|
set("settings.restrictions.allowedNicknameCharacters", "[a-zA-Z0-9_]*");
|
||||||
changes = true;
|
changes = true;
|
||||||
}
|
}
|
||||||
if (!contains("settings.delayJoinMessage")) {
|
if (contains("settings.delayJoinMessage")) {
|
||||||
set("settings.delayJoinMessage", false);
|
set("settings.delayJoinMessage", null);
|
||||||
|
changes = true;
|
||||||
|
}
|
||||||
|
if (!contains("settings.delayJoinLeaveMessages")) {
|
||||||
|
set("settings.delayJoinLeaveMessages", true);
|
||||||
changes = true;
|
changes = true;
|
||||||
}
|
}
|
||||||
if (!contains("settings.restrictions.noTeleport")) {
|
if (!contains("settings.restrictions.noTeleport")) {
|
||||||
@ -487,8 +486,8 @@ public final class Settings extends YamlConfiguration {
|
|||||||
changes = true;
|
changes = true;
|
||||||
}
|
}
|
||||||
if (!contains("DataSource.mySQLQueryCache")) {
|
if (!contains("DataSource.mySQLQueryCache")) {
|
||||||
set("DataSource.mySQLWebsite", false);
|
set("DataSource.mySQLWebsite", false);
|
||||||
changes = true;
|
changes = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (changes) {
|
if (changes) {
|
||||||
|
|||||||
@ -4,9 +4,9 @@ import org.bukkit.entity.Player;
|
|||||||
import org.bukkit.scheduler.BukkitTask;
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
|
|
||||||
import fr.xephi.authme.AuthMe;
|
import fr.xephi.authme.AuthMe;
|
||||||
import fr.xephi.authme.Utils;
|
|
||||||
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.util.Utils;
|
||||||
|
|
||||||
public class MessageTask implements Runnable {
|
public class MessageTask implements Runnable {
|
||||||
|
|
||||||
|
|||||||
75
src/main/java/fr/xephi/authme/util/ListUtils.java
Normal file
75
src/main/java/fr/xephi/authme/util/ListUtils.java
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
package fr.xephi.authme.util;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class ListUtils {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implode a list of elements into a single string, with a specified separator.
|
||||||
|
*
|
||||||
|
* @param elements The elements to implode.
|
||||||
|
* @param separator The separator to use.
|
||||||
|
*
|
||||||
|
* @return The result string.
|
||||||
|
*/
|
||||||
|
public static String implode(List<String> elements, String separator) {
|
||||||
|
// Create a string builder
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
|
||||||
|
// Append each element
|
||||||
|
for(String element : elements) {
|
||||||
|
// Make sure the element isn't empty
|
||||||
|
if(element.trim().length() == 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
// Prefix the separator if it isn't the first element
|
||||||
|
if(sb.length() > 0)
|
||||||
|
sb.append(separator);
|
||||||
|
|
||||||
|
// Append the element
|
||||||
|
sb.append(element);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return the result
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implode two lists of elements into a single string, with a specified separator.
|
||||||
|
*
|
||||||
|
* @param elements The first list of elements to implode.
|
||||||
|
* @param otherElements The second list of elements to implode.
|
||||||
|
* @param separator The separator to use.
|
||||||
|
*
|
||||||
|
* @return The result string.
|
||||||
|
*/
|
||||||
|
public static String implode(List<String> elements, List<String> otherElements, String separator) {
|
||||||
|
// Combine the lists
|
||||||
|
List<String> combined = new ArrayList<>();
|
||||||
|
combined.addAll(elements);
|
||||||
|
combined.addAll(otherElements);
|
||||||
|
|
||||||
|
// Implode and return the result
|
||||||
|
return implode(combined, separator);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implode two elements into a single string, with a specified separator.
|
||||||
|
*
|
||||||
|
* @param element The first element to implode.
|
||||||
|
* @param otherElement The second element to implode.
|
||||||
|
* @param separator The separator to use.
|
||||||
|
*
|
||||||
|
* @return The result string.
|
||||||
|
*/
|
||||||
|
public static String implode(String element, String otherElement, String separator) {
|
||||||
|
// Combine the lists
|
||||||
|
List<String> combined = new ArrayList<>();
|
||||||
|
combined.add(element);
|
||||||
|
combined.add(otherElement);
|
||||||
|
|
||||||
|
// Implode and return the result
|
||||||
|
return implode(combined, separator);
|
||||||
|
}
|
||||||
|
}
|
||||||
132
src/main/java/fr/xephi/authme/util/Profiler.java
Normal file
132
src/main/java/fr/xephi/authme/util/Profiler.java
Normal file
@ -0,0 +1,132 @@
|
|||||||
|
package fr.xephi.authme.util;
|
||||||
|
|
||||||
|
import java.text.DecimalFormat;
|
||||||
|
|
||||||
|
@SuppressWarnings("UnusedDeclaration")
|
||||||
|
public class Profiler {
|
||||||
|
|
||||||
|
/** Defines the past time in milliseconds. */
|
||||||
|
private long time = 0;
|
||||||
|
/** Defines the time in milliseconds the profiler last started at. */
|
||||||
|
private long start = -1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor. This won't start the profiler immediately.
|
||||||
|
*/
|
||||||
|
public Profiler() {
|
||||||
|
this(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor.
|
||||||
|
*
|
||||||
|
* @param start True to immediately start the profiler.
|
||||||
|
*/
|
||||||
|
public Profiler(boolean start) {
|
||||||
|
// Should the timer be started
|
||||||
|
if(start)
|
||||||
|
start();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Start the profiler.
|
||||||
|
*
|
||||||
|
* @return True if the profiler was started, false otherwise possibly due to an error.
|
||||||
|
* True will also be returned if the profiler was started already.
|
||||||
|
*/
|
||||||
|
public boolean start() {
|
||||||
|
// Make sure the timer isn't started already
|
||||||
|
if(isActive())
|
||||||
|
return true;
|
||||||
|
|
||||||
|
// Set the start time
|
||||||
|
this.start = System.currentTimeMillis();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This will start the profiler if it's not active, or will stop the profiler if it's currently active.
|
||||||
|
*
|
||||||
|
* @return True if the profiler has been started, false if the profiler has been stopped.
|
||||||
|
*/
|
||||||
|
public boolean pause() {
|
||||||
|
// Toggle the profiler state
|
||||||
|
if(isStarted())
|
||||||
|
stop();
|
||||||
|
else
|
||||||
|
start();
|
||||||
|
|
||||||
|
// Return the result
|
||||||
|
return isStarted();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stop the profiler if it's active.
|
||||||
|
*
|
||||||
|
* @return True will be returned if the profiler was stopped while it was active. False will be returned if the
|
||||||
|
* profiler was stopped already.
|
||||||
|
*/
|
||||||
|
public boolean stop() {
|
||||||
|
// Make sure the profiler is active
|
||||||
|
if(!isActive())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// Stop the profiler, calculate the passed time
|
||||||
|
this.time += System.currentTimeMillis() - this.start;
|
||||||
|
this.start = -1;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check whether the profiler has been started. The profiler doesn't need to be active right now.
|
||||||
|
*
|
||||||
|
* @return True if the profiler was started, false otherwise.
|
||||||
|
*/
|
||||||
|
public boolean isStarted() {
|
||||||
|
return isActive() || this.time > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check whether the profiler is currently active.
|
||||||
|
*
|
||||||
|
* @return True if the profiler is active, false otherwise.
|
||||||
|
*/
|
||||||
|
public boolean isActive() {
|
||||||
|
return this.start >= 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the passed time in milliseconds.
|
||||||
|
*
|
||||||
|
* @return The passed time in milliseconds.
|
||||||
|
*/
|
||||||
|
public long getTime() {
|
||||||
|
// Check whether the profiler is currently active
|
||||||
|
if(isActive())
|
||||||
|
return this.time + (System.currentTimeMillis() - this.start);
|
||||||
|
return this.time;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the passed time in a formatted string.
|
||||||
|
*
|
||||||
|
* @return The passed time in a formatted string.
|
||||||
|
*/
|
||||||
|
public String getTimeFormatted() {
|
||||||
|
// Get the passed time
|
||||||
|
long time = getTime();
|
||||||
|
|
||||||
|
// Return the time if it's less than one millisecond
|
||||||
|
if(time <= 0)
|
||||||
|
return "<1 ms";
|
||||||
|
|
||||||
|
// Return the time in milliseconds
|
||||||
|
if(time < 1000)
|
||||||
|
return time + " ms";
|
||||||
|
|
||||||
|
// Convert the time into seconds with a single decimal
|
||||||
|
double timeSeconds = ((double) time) / 1000;
|
||||||
|
DecimalFormat df = new DecimalFormat("#0.0");
|
||||||
|
return df.format(timeSeconds) + " s";
|
||||||
|
}
|
||||||
|
}
|
||||||
28
src/main/java/fr/xephi/authme/util/StringUtils.java
Normal file
28
src/main/java/fr/xephi/authme/util/StringUtils.java
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
package fr.xephi.authme.util;
|
||||||
|
|
||||||
|
import net.ricecode.similarity.LevenshteinDistanceStrategy;
|
||||||
|
import net.ricecode.similarity.StringSimilarityService;
|
||||||
|
import net.ricecode.similarity.StringSimilarityServiceImpl;
|
||||||
|
|
||||||
|
public class StringUtils {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the difference of two strings.
|
||||||
|
*
|
||||||
|
* @param first First string.
|
||||||
|
* @param second Second string.
|
||||||
|
*
|
||||||
|
* @return The difference value.
|
||||||
|
*/
|
||||||
|
public static double getDifference(String first, String second) {
|
||||||
|
// Make sure the strings are valid.
|
||||||
|
if(first == null || second == null)
|
||||||
|
return 1.0;
|
||||||
|
|
||||||
|
// Create a string similarity service instance, to allow comparison
|
||||||
|
StringSimilarityService service = new StringSimilarityServiceImpl(new LevenshteinDistanceStrategy());
|
||||||
|
|
||||||
|
// Determine the difference value, return the result
|
||||||
|
return Math.abs(service.score(first, second) - 1.0);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package fr.xephi.authme;
|
package fr.xephi.authme.util;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
@ -12,6 +12,8 @@ import java.util.Collection;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.zip.GZIPInputStream;
|
import java.util.zip.GZIPInputStream;
|
||||||
|
|
||||||
|
import fr.xephi.authme.events.SpawnTeleportEvent;
|
||||||
|
import fr.xephi.authme.settings.Spawn;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
@ -21,6 +23,8 @@ import org.bukkit.entity.Player;
|
|||||||
|
|
||||||
import com.maxmind.geoip.LookupService;
|
import com.maxmind.geoip.LookupService;
|
||||||
|
|
||||||
|
import fr.xephi.authme.AuthMe;
|
||||||
|
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.cache.limbo.LimboPlayer;
|
import fr.xephi.authme.cache.limbo.LimboPlayer;
|
||||||
@ -212,17 +216,15 @@ public class Utils {
|
|||||||
if (theWorld == null)
|
if (theWorld == null)
|
||||||
theWorld = pl.getWorld();
|
theWorld = pl.getWorld();
|
||||||
final World world = theWorld;
|
final World world = theWorld;
|
||||||
final Location locat = new Location(world, x, y, z);
|
final Location loc = new Location(world, x, y, z);
|
||||||
|
|
||||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
|
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
AuthMeTeleportEvent tpEvent = new AuthMeTeleportEvent(pl, locat);
|
AuthMeTeleportEvent tpEvent = new AuthMeTeleportEvent(pl, loc);
|
||||||
plugin.getServer().getPluginManager().callEvent(tpEvent);
|
plugin.getServer().getPluginManager().callEvent(tpEvent);
|
||||||
if (!tpEvent.isCancelled()) {
|
if (!tpEvent.isCancelled()) {
|
||||||
if (!tpEvent.getTo().getChunk().isLoaded())
|
|
||||||
tpEvent.getTo().getChunk().load();
|
|
||||||
pl.teleport(tpEvent.getTo());
|
pl.teleport(tpEvent.getTo());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -295,4 +297,15 @@ public class Utils {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void teleportToSpawn(Player player) {
|
||||||
|
if (Settings.isTeleportToSpawnEnabled && !Settings.noTeleport) {
|
||||||
|
Location spawn = plugin.getSpawnLocation(player);
|
||||||
|
AuthMeTeleportEvent tpEvent = new AuthMeTeleportEvent(player, spawn);
|
||||||
|
plugin.getServer().getPluginManager().callEvent(tpEvent);
|
||||||
|
if (!tpEvent.isCancelled()) {
|
||||||
|
player.teleport(tpEvent.getTo());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@ -10,7 +10,7 @@ DataSource:
|
|||||||
# Database Port
|
# Database Port
|
||||||
mySQLPort: '3306'
|
mySQLPort: '3306'
|
||||||
# MySql Max Connections
|
# MySql Max Connections
|
||||||
mySQLMaxConections: 25
|
mySQLMaxConections: 8
|
||||||
# Username about Database Connection Infos
|
# Username about Database Connection Infos
|
||||||
mySQLUsername: authme
|
mySQLUsername: authme
|
||||||
# Password about Database Connection Infos
|
# Password about Database Connection Infos
|
||||||
@ -253,8 +253,8 @@ settings:
|
|||||||
useWelcomeMessage: true
|
useWelcomeMessage: true
|
||||||
# Do we need to broadcast the welcome message to all server or only to the player? set true for server or false for player
|
# Do we need to broadcast the welcome message to all server or only to the player? set true for server or false for player
|
||||||
broadcastWelcomeMessage: false
|
broadcastWelcomeMessage: false
|
||||||
# Do we need to delay the X has joined the game after /login ?
|
# Do we need to delay the join/leave message to be displayed only when the player is authenticated ?
|
||||||
delayJoinMessage: false
|
delayJoinLeaveMessages: true
|
||||||
# Do we need to add potion effect Blinding before login/register ?
|
# Do we need to add potion effect Blinding before login/register ?
|
||||||
applyBlindEffect: false
|
applyBlindEffect: false
|
||||||
ExternalBoardOptions:
|
ExternalBoardOptions:
|
||||||
|
|||||||
@ -1,56 +1,56 @@
|
|||||||
unknown_user: Gebruiker is niet gevonden in database
|
unknown_user: Gebruiker is niet gevonden in de database
|
||||||
unsafe_spawn: De locatie waar je de vorige keer het spel verlied was gevaarlijk, je bent geteleporteert naar de Spawn
|
unsafe_spawn: De locatie waar je de vorige keer het spel verliet was gevaarlijk, je bent geteleporteerd naar de spawn
|
||||||
not_logged_in: '&cNiet ingelogt!'
|
not_logged_in: '&cNiet ingelogt!'
|
||||||
reg_voluntarily: Je kunt je gebruikersnaam registreren met "/register <wachtwoord> <herhaalWachtwoord>"
|
reg_voluntarily: Je kunt je gebruikersnaam registreren met "/register <wachtwoord> <herhaalWachtwoord>"
|
||||||
usage_log: '&cGebruik: /login <wachtwoord>'
|
usage_log: '&cGebruik: /login <wachtwoord>'
|
||||||
wrong_pwd: '&cFout wachtwoord'
|
wrong_pwd: '&cFout wachtwoord'
|
||||||
unregistered: '&cRegistratie succesvol ongedaan gemaakt!'
|
unregistered: '&cRegistratie succesvol ongedaan gemaakt!'
|
||||||
reg_disabled: '&cRegistratie is uitgeschakeld'
|
reg_disabled: '&cRegistratie is uitgeschakeld'
|
||||||
valid_session: '&cSessie ingelogt'
|
valid_session: '&cSessie ingelogd'
|
||||||
login: '&cSuccesvol ingelogt!'
|
login: '&cSuccesvol ingelogd!'
|
||||||
password_error_nick: '&fYou can''t use your name as password'
|
password_error_nick: '&fJe kunt je gebruikersnaam niet als wachtwoord gebruiken'
|
||||||
password_error_unsafe: '&fYou can''t use unsafe passwords'
|
password_error_unsafe: '&fJe kunt geen onveilige wachtwoorden gebruiken'
|
||||||
vb_nonActiv: Je accound is nog niet geactiveerd, controleer je mailbox!
|
vb_nonActiv: Je accound is nog niet geactiveerd, controleer je mailbox!
|
||||||
user_regged: '&cGebruikersnaam is al geregistreerd'
|
user_regged: '&cGebruikersnaam is al geregistreerd'
|
||||||
usage_reg: '&cGebruik: /register <wachtwoord> <herhaalWachtwoord>'
|
usage_reg: '&cGebruik: /register <wachtwoord> <herhaalWachtwoord>'
|
||||||
max_reg: Je hebt de maximale registraties van jouw account overschreden.
|
max_reg: Je hebt de maximale registraties van jouw account overschreden.
|
||||||
no_perm: '&cGeen toegang!'
|
no_perm: '&cGeen toegang!'
|
||||||
error: Error; neem contact op met een ADMIN!
|
error: Error: neem contact op met een administrator!
|
||||||
login_msg: '&cLog in met "/login <wachtwoord>"'
|
login_msg: '&cLog in met "/login <wachtwoord>"'
|
||||||
reg_msg: '&cRegistreer met "/register <wachtwoord> <herhaalWachtwoord>"'
|
reg_msg: '&cRegistreer met "/register <wachtwoord> <herhaalWachtwoord>"'
|
||||||
usage_unreg: '&cGebruik: /unregister password'
|
usage_unreg: '&cGebruik: /unregister password'
|
||||||
pwd_changed: '&cWachtwoord aangepast!'
|
pwd_changed: '&cWachtwoord aangepast!'
|
||||||
user_unknown: '&cGebruikersnaam niet geregistreerd'
|
user_unknown: '&cGebruikersnaam niet geregistreerd'
|
||||||
password_error: Wachtwoord incorrect!
|
password_error: Wachtwoord incorrect!
|
||||||
invalid_session: Sessie beschadigt, wacht tot de sessie is verlopen en join opnieuw.
|
invalid_session: Sessie beschadigd, wacht tot de sessie is verlopen en verbindt opnieuw.
|
||||||
reg_only: Alleen voor geregistreerde spelers! Bezoek http://example.com om te registreren
|
reg_only: Alleen voor geregistreerde spelers! Bezoek http://example.com om te registreren
|
||||||
logged_in: '&cJe bent al ingelogt!'
|
logged_in: '&cJe bent al ingelogd!'
|
||||||
logout: '&cJe bent succesvol uitgelogt'
|
logout: '&cJe bent succesvol uitgelogd'
|
||||||
same_nick: Er is al iemand met jou gebruikersnaam online.
|
same_nick: Er is al iemand met jou gebruikersnaam online.
|
||||||
registered: '&cSuccesvol geregistreerd!'
|
registered: '&cSuccesvol geregistreerd!'
|
||||||
pass_len: Je gekozen wachtwoord voldoet niet aan de minimum of maximum lengte
|
pass_len: Je gekozen wachtwoord voldoet niet aan de minimum of maximum lengte
|
||||||
reload: Configuratie en database is opnieuw opgestard
|
reload: Configuratie en database is opnieuw opgestard
|
||||||
timeout: Login time-out; het duurde telang voor je je inlogde.
|
timeout: Login time-out: het duurde telang voor je je inlogde.
|
||||||
usage_changepassword: 'Gebruik: /changepassword <oudWachtwoord> <nieuwWachtwoord>'
|
usage_changepassword: 'Gebruik: /changepassword <oudWachtwoord> <nieuwWachtwoord>'
|
||||||
name_len: '&cJouw gebruikersnaam is te kort'
|
name_len: '&cJe gebruikersnaam is te kort'
|
||||||
regex: '&cJouw gebruikersnaam bestaat uit illegale tekens. tegestaan chars: REG_EX'
|
regex: '&cJouw gebruikersnaam bevat illegale tekens. Toegestaane karakters: REG_EX'
|
||||||
add_email: '&cVoeg uw email toe Alstublieft met: /email add jouw wachtwoord herhaalwachtwoord'
|
add_email: '&cVoeg uw E-mail alstublieft toe met: /email add <E-mail> <wachtwoord> <herhaalWachtwoord>'
|
||||||
recovery_email: '&cWachtwoord vergeten? gebruik alstublieft /email recovery <Jouwemail>'
|
recovery_email: '&cWachtwoord vergeten? Gebruik alstublieft "/email recovery <E-mail>"'
|
||||||
usage_captcha: '&cGebruik: /captcha <deCaptcha>'
|
usage_captcha: '&cGebruik: /captcha <captcha>'
|
||||||
wrong_captcha: '&cverkeerde Captcha, Gebruik alstublieft : /captcha THE_CAPTCHA'
|
wrong_captcha: '&cVerkeerde Captcha, gebruik alstublieft: /captcha THE_CAPTCHA'
|
||||||
valid_captcha: '&cJouw captcha is geldig!'
|
valid_captcha: '&cDe captcha is geldig!'
|
||||||
kick_forvip: '&cA VIP Gebruiker ga naar de volledige server!'
|
kick_forvip: '&cEen VIP Gebruiker ga naar de volledige server!'
|
||||||
kick_fullserver: '&cDe server is eigenlijk vol, Sorry!'
|
kick_fullserver: '&cDe server is vol, sorry!'
|
||||||
usage_email_add: '&fGebruik: /email add <email> <herhaalEmail> '
|
usage_email_add: '&fGebruik: /email add <E-mail> <herhaalE-mail>'
|
||||||
usage_email_change: '&fGebruik: /email change <oudeEmail> <nieuweEmail> '
|
usage_email_change: '&fGebruik: /email change <oudeE-mail> <nieuweE-mail>'
|
||||||
usage_email_recovery: '&fGebruik: /email recovery <Email>'
|
usage_email_recovery: '&fGebruik: /email recovery <E-mail>'
|
||||||
new_email_invalid: '[AuthMe] Nieuw email ongeldig!'
|
new_email_invalid: '[AuthMe] Nieuwe E-mail ongeldig!'
|
||||||
old_email_invalid: '[AuthMe] Oud email ongeldig!'
|
old_email_invalid: '[AuthMe] Oude E-mail ongeldig!'
|
||||||
email_invalid: '[AuthMe] ongeldig Email'
|
email_invalid: '[AuthMe] Ongeldige E-mail'
|
||||||
email_added: '[AuthMe] Bevestig jouw Email !'
|
email_added: '[AuthMe] Bevestig jouw E-mail!'
|
||||||
email_confirm: '[AuthMe] Bevestig jouw Email !'
|
email_confirm: '[AuthMe] Bevestig jouw E-mail!'
|
||||||
email_changed: '[AuthMe] Email Veranderd !'
|
email_changed: '[AuthMe] Email Veranderd!'
|
||||||
email_send: '[AuthMe] Herstel Email Verzonden !'
|
email_send: '[AuthMe] Herstel E-mail Verzonden!'
|
||||||
country_banned: 'Your country is banned from this server'
|
country_banned: 'Jouw land is geband op deze server'
|
||||||
antibot_auto_enabled: '[AuthMe] AntiBotMod automatically enabled due to massive connections!'
|
antibot_auto_enabled: '[AuthMe] AntiBotMod automatisch aangezet vanewge veel verbindingen!'
|
||||||
antibot_auto_disabled: '[AuthMe] AntiBotMod automatically disabled after %m Minutes, hope invasion stopped'
|
antibot_auto_disabled: '[AuthMe] AntiBotMod automatisch uitgezet na %m minuten, hopelijk is de invasie gestopt'
|
||||||
|
|||||||
5
team.txt
5
team.txt
@ -1,13 +1,14 @@
|
|||||||
AuthMe-Team:
|
AuthMe-Team:
|
||||||
|
|
||||||
Active staff:
|
Active staff:
|
||||||
Xephi (Xephi59) - Leader, Main developer (temporary inactive)
|
Xephi (Xephi59) - Leader, Main developer
|
||||||
DNx5 - Developer
|
DNx5 - Developer
|
||||||
games647 - Developer
|
games647 - Developer
|
||||||
|
TimVisee - Developer
|
||||||
Gabriele C. (sgdc3) - Project Manager, Contributor
|
Gabriele C. (sgdc3) - Project Manager, Contributor
|
||||||
|
|
||||||
Staff to contact:
|
Staff to contact:
|
||||||
CryLegend - Contributor, AuthMeBridge Developer (Need activation)
|
CryLegend - Contributor, AuthMeBridge Developer (Needs activation)
|
||||||
|
|
||||||
External Contributors:
|
External Contributors:
|
||||||
Gnat008 - Contributor
|
Gnat008 - Contributor
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user