commit
ac5d2f4d33
13
.editorconfig
Normal file
13
.editorconfig
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
# Top-most EditorConfig file
|
||||||
|
root = true
|
||||||
|
|
||||||
|
# Unix-style newlines with a newline ending every file
|
||||||
|
[*]
|
||||||
|
end_of_line = lf
|
||||||
|
insert_final_newline = true
|
||||||
|
|
||||||
|
# Set the charset, and space indention
|
||||||
|
[*.java]
|
||||||
|
charset = utf-8
|
||||||
|
indent_style = space
|
||||||
|
indent_size = 4
|
||||||
3
.floo
Normal file
3
.floo
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"url": "https://floobits.com/AuthMe-Team/AuthMeReloaded"
|
||||||
|
}
|
||||||
123
.flooignore
Normal file
123
.flooignore
Normal file
@ -0,0 +1,123 @@
|
|||||||
|
### Java ###
|
||||||
|
*.class
|
||||||
|
|
||||||
|
# Mobile Tools for Java (J2ME)
|
||||||
|
.mtj.tmp/
|
||||||
|
|
||||||
|
# Package Files #
|
||||||
|
#*.jar
|
||||||
|
*.war
|
||||||
|
*.ear
|
||||||
|
|
||||||
|
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
||||||
|
hs_err_pid*
|
||||||
|
|
||||||
|
|
||||||
|
### Intellij ###
|
||||||
|
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm
|
||||||
|
|
||||||
|
*.iml
|
||||||
|
|
||||||
|
## Directory-based project format:
|
||||||
|
.idea/
|
||||||
|
# if you remove the above rule, at least ignore the following:
|
||||||
|
|
||||||
|
# User-specific stuff:
|
||||||
|
# .idea/workspace.xml
|
||||||
|
# .idea/tasks.xml
|
||||||
|
# .idea/dictionaries
|
||||||
|
|
||||||
|
# Sensitive or high-churn files:
|
||||||
|
# .idea/dataSources.ids
|
||||||
|
# .idea/dataSources.xml
|
||||||
|
# .idea/sqlDataSources.xml
|
||||||
|
# .idea/dynamic.xml
|
||||||
|
# .idea/uiDesigner.xml
|
||||||
|
|
||||||
|
# Gradle:
|
||||||
|
# .idea/gradle.xml
|
||||||
|
# .idea/libraries
|
||||||
|
|
||||||
|
# Mongo Explorer plugin:
|
||||||
|
# .idea/mongoSettings.xml
|
||||||
|
|
||||||
|
## File-based project format:
|
||||||
|
*.ipr
|
||||||
|
*.iws
|
||||||
|
|
||||||
|
## Plugin-specific files:
|
||||||
|
|
||||||
|
# IntelliJ
|
||||||
|
/out/
|
||||||
|
|
||||||
|
# mpeltonen/sbt-idea plugin
|
||||||
|
.idea_modules/
|
||||||
|
|
||||||
|
# JIRA plugin
|
||||||
|
atlassian-ide-plugin.xml
|
||||||
|
|
||||||
|
# Crashlytics plugin (for Android Studio and IntelliJ)
|
||||||
|
com_crashlytics_export_strings.xml
|
||||||
|
crashlytics.properties
|
||||||
|
crashlytics-build.properties
|
||||||
|
|
||||||
|
|
||||||
|
### Eclipse ###
|
||||||
|
*.pydevproject
|
||||||
|
.metadata
|
||||||
|
.gradle
|
||||||
|
bin/
|
||||||
|
tmp/
|
||||||
|
*.tmp
|
||||||
|
*.bak
|
||||||
|
*.swp
|
||||||
|
*~.nib
|
||||||
|
local.properties
|
||||||
|
.settings/
|
||||||
|
.loadpath
|
||||||
|
|
||||||
|
# Eclipse Core
|
||||||
|
.project
|
||||||
|
|
||||||
|
# External tool builders
|
||||||
|
.externalToolBuilders/
|
||||||
|
|
||||||
|
# Locally stored "Eclipse launch configurations"
|
||||||
|
*.launch
|
||||||
|
|
||||||
|
# CDT-specific
|
||||||
|
.cproject
|
||||||
|
|
||||||
|
# JDT-specific (Eclipse Java Development Tools)
|
||||||
|
.classpath
|
||||||
|
|
||||||
|
# PDT-specific
|
||||||
|
.buildpath
|
||||||
|
|
||||||
|
# sbteclipse plugin
|
||||||
|
.target
|
||||||
|
|
||||||
|
# TeXlipse plugin
|
||||||
|
.texlipse
|
||||||
|
|
||||||
|
|
||||||
|
### Maven ###
|
||||||
|
target/
|
||||||
|
pom.xml.tag
|
||||||
|
pom.xml.releaseBackup
|
||||||
|
pom.xml.versionsBackup
|
||||||
|
pom.xml.next
|
||||||
|
release.properties
|
||||||
|
dependency-reduced-pom.xml
|
||||||
|
buildNumber.properties
|
||||||
|
|
||||||
|
|
||||||
|
### NetBeans ###
|
||||||
|
nbproject/private/
|
||||||
|
build/
|
||||||
|
nbbuild/
|
||||||
|
dist/
|
||||||
|
nbdist/
|
||||||
|
nbactions.xml
|
||||||
|
nb-configuration.xml
|
||||||
|
.nb-gradle/
|
||||||
53
.gitignore
vendored
53
.gitignore
vendored
@ -1,12 +1,7 @@
|
|||||||
# Created by https://www.gitignore.io
|
### Java files ###
|
||||||
|
|
||||||
### Java ###
|
|
||||||
*.class
|
*.class
|
||||||
|
|
||||||
# Mobile Tools for Java (J2ME)
|
# Package Files
|
||||||
.mtj.tmp/
|
|
||||||
|
|
||||||
# Package Files #
|
|
||||||
#*.jar
|
#*.jar
|
||||||
*.war
|
*.war
|
||||||
*.ear
|
*.ear
|
||||||
@ -15,40 +10,27 @@
|
|||||||
hs_err_pid*
|
hs_err_pid*
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
### Intellij ###
|
### Intellij ###
|
||||||
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm
|
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm
|
||||||
|
# Ignore project files
|
||||||
*.iml
|
*.iml
|
||||||
|
|
||||||
## Directory-based project format:
|
# Ignore IDEA directory
|
||||||
.idea/
|
.idea/*
|
||||||
# if you remove the above rule, at least ignore the following:
|
|
||||||
|
|
||||||
# User-specific stuff:
|
# Include the project's code style settings file
|
||||||
# .idea/workspace.xml
|
!.idea/codeStyleSettings.xml
|
||||||
# .idea/tasks.xml
|
|
||||||
# .idea/dictionaries
|
|
||||||
|
|
||||||
# Sensitive or high-churn files:
|
# Include the project's dictionary
|
||||||
# .idea/dataSources.ids
|
!.idea/dictionaries/
|
||||||
# .idea/dataSources.xml
|
!.idea/dictionaries/*
|
||||||
# .idea/sqlDataSources.xml
|
|
||||||
# .idea/dynamic.xml
|
|
||||||
# .idea/uiDesigner.xml
|
|
||||||
|
|
||||||
# Gradle:
|
# File-based project format:
|
||||||
# .idea/gradle.xml
|
|
||||||
# .idea/libraries
|
|
||||||
|
|
||||||
# Mongo Explorer plugin:
|
|
||||||
# .idea/mongoSettings.xml
|
|
||||||
|
|
||||||
## File-based project format:
|
|
||||||
*.ipr
|
*.ipr
|
||||||
*.iws
|
*.iws
|
||||||
|
|
||||||
## Plugin-specific files:
|
### Plugin-specific files: ###
|
||||||
|
|
||||||
# IntelliJ
|
# IntelliJ
|
||||||
/out/
|
/out/
|
||||||
|
|
||||||
@ -64,6 +46,7 @@ crashlytics.properties
|
|||||||
crashlytics-build.properties
|
crashlytics-build.properties
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
### Eclipse ###
|
### Eclipse ###
|
||||||
*.pydevproject
|
*.pydevproject
|
||||||
.metadata
|
.metadata
|
||||||
@ -103,6 +86,7 @@ local.properties
|
|||||||
.texlipse
|
.texlipse
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
### Maven ###
|
### Maven ###
|
||||||
target/
|
target/
|
||||||
pom.xml.tag
|
pom.xml.tag
|
||||||
@ -114,6 +98,7 @@ dependency-reduced-pom.xml
|
|||||||
buildNumber.properties
|
buildNumber.properties
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
### NetBeans ###
|
### NetBeans ###
|
||||||
nbproject/private/
|
nbproject/private/
|
||||||
build/
|
build/
|
||||||
@ -123,3 +108,9 @@ nbdist/
|
|||||||
nbactions.xml
|
nbactions.xml
|
||||||
nb-configuration.xml
|
nb-configuration.xml
|
||||||
.nb-gradle/
|
.nb-gradle/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
### Git ###
|
||||||
|
# Don't exclude the .gitignore itself
|
||||||
|
!.gitignore
|
||||||
|
|||||||
18
.idea/codeStyleSettings.xml
generated
Normal file
18
.idea/codeStyleSettings.xml
generated
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectCodeStyleSettingsManager">
|
||||||
|
<option name="PER_PROJECT_SETTINGS">
|
||||||
|
<value>
|
||||||
|
<option name="AUTODETECT_INDENTS" value="false" />
|
||||||
|
<option name="LINE_SEPARATOR" value=" " />
|
||||||
|
<option name="JD_ADD_BLANK_AFTER_PARM_COMMENTS" value="true" />
|
||||||
|
<option name="JD_ADD_BLANK_AFTER_RETURN" value="true" />
|
||||||
|
<XML>
|
||||||
|
<option name="XML_LEGACY_SETTINGS_IMPORTED" value="true" />
|
||||||
|
</XML>
|
||||||
|
</value>
|
||||||
|
</option>
|
||||||
|
<option name="USE_PER_PROJECT_SETTINGS" value="true" />
|
||||||
|
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Project" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
7
.idea/dictionaries/Tim.xml
generated
Normal file
7
.idea/dictionaries/Tim.xml
generated
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<component name="ProjectDictionaryState">
|
||||||
|
<dictionary name="Tim">
|
||||||
|
<words>
|
||||||
|
<w>authme</w>
|
||||||
|
</words>
|
||||||
|
</dictionary>
|
||||||
|
</component>
|
||||||
@ -47,8 +47,7 @@ McStats: http://mcstats.org/plugin/AuthMe
|
|||||||
#####Running Requirements:
|
#####Running Requirements:
|
||||||
>- Java 1.7 (should work also with Java 1.8)
|
>- Java 1.7 (should work also with Java 1.8)
|
||||||
>- Spigot or CraftBukkit (1.7.10 or 1.8.X)
|
>- Spigot or CraftBukkit (1.7.10 or 1.8.X)
|
||||||
>- Vault
|
>- ProtocolLib (optional, required by the protectInventory feature)
|
||||||
>- Protocollib
|
|
||||||
|
|
||||||
<hr>
|
<hr>
|
||||||
###Plugin Description:
|
###Plugin Description:
|
||||||
@ -129,7 +128,7 @@ typing commands or use the inventory. It can also kick players with uncommon lon
|
|||||||
<hr>
|
<hr>
|
||||||
|
|
||||||
#####Donate
|
#####Donate
|
||||||
<p>Do you like my work? Do you want to buy me a coffee? :)<br>
|
<p>Do you like our work? Do you want to buy us a coffee? :)<br>
|
||||||
EUR: <a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=QLMM9SNCX825Y"><img src="https://www.paypalobjects.com/en_US/i/btn/btn_donate_LG.gif"></a>
|
EUR: <a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=QLMM9SNCX825Y"><img src="https://www.paypalobjects.com/en_US/i/btn/btn_donate_LG.gif"></a>
|
||||||
USD: <a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=PWQMYCP2SAH6L"><img src="https://www.paypalobjects.com/en_US/i/btn/btn_donate_LG.gif"></a></p>
|
USD: <a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=PWQMYCP2SAH6L"><img src="https://www.paypalobjects.com/en_US/i/btn/btn_donate_LG.gif"></a></p>
|
||||||
|
|
||||||
|
|||||||
BIN
lib/EssentialsGroupManager-2.13.1.jar
Normal file
BIN
lib/EssentialsGroupManager-2.13.1.jar
Normal file
Binary file not shown.
BIN
lib/Permission-3.1.6.jar
Normal file
BIN
lib/Permission-3.1.6.jar
Normal file
Binary file not shown.
BIN
lib/bPermissions-2.12-DEV.jar
Normal file
BIN
lib/bPermissions-2.12-DEV.jar
Normal file
Binary file not shown.
BIN
lib/zPermissions-1.3beta1.jar
Normal file
BIN
lib/zPermissions-1.3beta1.jar
Normal file
Binary file not shown.
99
src/main/java/fr/xephi/authme/AntiBot.java
Normal file
99
src/main/java/fr/xephi/authme/AntiBot.java
Normal file
@ -0,0 +1,99 @@
|
|||||||
|
package fr.xephi.authme;
|
||||||
|
|
||||||
|
import fr.xephi.authme.permission.UserPermission;
|
||||||
|
import fr.xephi.authme.settings.MessageKey;
|
||||||
|
import fr.xephi.authme.settings.Messages;
|
||||||
|
import fr.xephi.authme.settings.Settings;
|
||||||
|
import fr.xephi.authme.util.Wrapper;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The AntiBot Service Management class.
|
||||||
|
*/
|
||||||
|
public class AntiBot {
|
||||||
|
|
||||||
|
private static final Wrapper wrapper = Wrapper.getInstance();
|
||||||
|
private static final AuthMe plugin = wrapper.getAuthMe();
|
||||||
|
private static final Messages messages = wrapper.getMessages();
|
||||||
|
private static final List<String> antibotPlayers = new ArrayList<>();
|
||||||
|
private static AntiBotStatus antiBotStatus = AntiBotStatus.DISABLED;
|
||||||
|
|
||||||
|
public static void setupAntiBotService() {
|
||||||
|
if (!Settings.enableAntiBot) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
antiBotStatus = AntiBotStatus.LISTENING;
|
||||||
|
}
|
||||||
|
}, 2400);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void overrideAntiBotStatus(boolean activated) {
|
||||||
|
if (antiBotStatus == AntiBotStatus.DISABLED) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (activated) {
|
||||||
|
antiBotStatus = AntiBotStatus.ACTIVE;
|
||||||
|
} else {
|
||||||
|
antiBotStatus = AntiBotStatus.LISTENING;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static AntiBotStatus getAntiBotStatus() {
|
||||||
|
return antiBotStatus;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void activateAntiBot() {
|
||||||
|
antiBotStatus = AntiBotStatus.ACTIVE;
|
||||||
|
for (String s : messages.retrieve(MessageKey.ANTIBOT_AUTO_ENABLED_MESSAGE)) {
|
||||||
|
Bukkit.broadcastMessage(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
wrapper.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if (antiBotStatus == AntiBotStatus.ACTIVE) {
|
||||||
|
antiBotStatus = AntiBotStatus.LISTENING;
|
||||||
|
antibotPlayers.clear();
|
||||||
|
for (String s : messages.retrieve(MessageKey.ANTIBOT_AUTO_DISABLED_MESSAGE)) {
|
||||||
|
Bukkit.broadcastMessage(s.replace("%m", "" + Settings.antiBotDuration));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, Settings.antiBotDuration * 1200);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void checkAntiBot(final Player player) {
|
||||||
|
if (antiBotStatus == AntiBotStatus.ACTIVE || antiBotStatus == AntiBotStatus.DISABLED) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (plugin.getPermissionsManager().hasPermission(player, UserPermission.BYPASS_ANTIBOT)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
antibotPlayers.add(player.getName().toLowerCase());
|
||||||
|
if (antibotPlayers.size() > Settings.antiBotSensibility) {
|
||||||
|
activateAntiBot();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
antibotPlayers.remove(player.getName().toLowerCase());
|
||||||
|
}
|
||||||
|
}, 300);
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum AntiBotStatus {
|
||||||
|
LISTENING,
|
||||||
|
DISABLED,
|
||||||
|
ACTIVE
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
File diff suppressed because it is too large
Load Diff
@ -4,14 +4,23 @@ import java.util.logging.Filter;
|
|||||||
import java.util.logging.LogRecord;
|
import java.util.logging.LogRecord;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Console filter Class
|
||||||
*
|
*
|
||||||
* @author Xephi59
|
* @author Xephi59
|
||||||
|
* @version $Revision: 1.0 $
|
||||||
*/
|
*/
|
||||||
public class ConsoleFilter implements Filter {
|
public class ConsoleFilter implements Filter {
|
||||||
|
|
||||||
public ConsoleFilter() {
|
public ConsoleFilter() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method isLoggable.
|
||||||
|
*
|
||||||
|
* @param record LogRecord
|
||||||
|
*
|
||||||
|
* @return boolean * @see java.util.logging.Filter#isLoggable(LogRecord)
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean isLoggable(LogRecord record) {
|
public boolean isLoggable(LogRecord record) {
|
||||||
try {
|
try {
|
||||||
@ -22,8 +31,8 @@ public class ConsoleFilter implements Filter {
|
|||||||
return true;
|
return true;
|
||||||
if (!logM.contains("/login ") && !logM.contains("/l ") && !logM.contains("/reg ") && !logM.contains("/changepassword ") && !logM.contains("/unregister ") && !logM.contains("/authme register ") && !logM.contains("/authme changepassword ") && !logM.contains("/authme reg ") && !logM.contains("/authme cp ") && !logM.contains("/register "))
|
if (!logM.contains("/login ") && !logM.contains("/l ") && !logM.contains("/reg ") && !logM.contains("/changepassword ") && !logM.contains("/unregister ") && !logM.contains("/authme register ") && !logM.contains("/authme changepassword ") && !logM.contains("/authme reg ") && !logM.contains("/authme cp ") && !logM.contains("/register "))
|
||||||
return true;
|
return true;
|
||||||
String playername = record.getMessage().split(" ")[0];
|
String playerName = record.getMessage().split(" ")[0];
|
||||||
record.setMessage(playername + " issued an AuthMe command!");
|
record.setMessage(playerName + " issued an AuthMe command!");
|
||||||
return true;
|
return true;
|
||||||
} catch (NullPointerException npe) {
|
} catch (NullPointerException npe) {
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@ -1,61 +1,82 @@
|
|||||||
package fr.xephi.authme;
|
package fr.xephi.authme;
|
||||||
|
|
||||||
|
import com.google.common.base.Throwables;
|
||||||
|
import fr.xephi.authme.settings.Settings;
|
||||||
|
import fr.xephi.authme.util.StringUtils;
|
||||||
|
import fr.xephi.authme.util.Wrapper;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.StandardOpenOption;
|
import java.nio.file.StandardOpenOption;
|
||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
import com.google.common.base.Throwables;
|
/**
|
||||||
|
* The plugin's static logger.
|
||||||
|
*/
|
||||||
|
public final class ConsoleLogger {
|
||||||
|
|
||||||
import fr.xephi.authme.api.NewAPI;
|
private static Wrapper wrapper = Wrapper.getInstance();
|
||||||
import fr.xephi.authme.settings.Settings;
|
|
||||||
|
|
||||||
public class ConsoleLogger {
|
|
||||||
|
|
||||||
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]");
|
||||||
|
|
||||||
|
private ConsoleLogger() {
|
||||||
|
// Service class
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Print an info message.
|
||||||
|
*
|
||||||
|
* @param message String
|
||||||
|
*/
|
||||||
public static void info(String message) {
|
public static void info(String message) {
|
||||||
log.info("[AuthMe] " + message);
|
wrapper.getLogger().info(message);
|
||||||
if (Settings.useLogging) {
|
if (!Settings.useLogging) {
|
||||||
String dateTime;
|
return;
|
||||||
synchronized (df) {
|
|
||||||
dateTime = df.format(new Date());
|
|
||||||
}
|
|
||||||
writeLog(dateTime + " " + message);
|
|
||||||
}
|
}
|
||||||
|
writeLog("" + message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Print an error message.
|
||||||
|
*
|
||||||
|
* @param message String
|
||||||
|
*/
|
||||||
public static void showError(String message) {
|
public static void showError(String message) {
|
||||||
log.warning("[AuthMe] " + message);
|
wrapper.getLogger().warning(message);
|
||||||
if (Settings.useLogging) {
|
if (!Settings.useLogging) {
|
||||||
String dateTime;
|
return;
|
||||||
synchronized (df) {
|
|
||||||
dateTime = df.format(new Date());
|
|
||||||
}
|
|
||||||
writeLog(dateTime + " ERROR: " + message);
|
|
||||||
}
|
}
|
||||||
|
writeLog("ERROR: " + message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void writeLog(String message) {
|
/**
|
||||||
|
* Write a message into the log file with a TimeStamp.
|
||||||
|
*
|
||||||
|
* @param message String
|
||||||
|
*/
|
||||||
|
private static void writeLog(String message) {
|
||||||
|
String dateTime;
|
||||||
|
synchronized (df) {
|
||||||
|
dateTime = df.format(new Date());
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
Files.write(Settings.LOG_FILE.toPath(), (message + NewAPI.newline).getBytes(),
|
Files.write(Settings.LOG_FILE.toPath(), (dateTime + ": " + message + StringUtils.newline).getBytes(),
|
||||||
StandardOpenOption.APPEND,
|
StandardOpenOption.APPEND,
|
||||||
StandardOpenOption.CREATE);
|
StandardOpenOption.CREATE);
|
||||||
} catch (IOException ignored) {
|
} catch (IOException ignored) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Write a StackTrace into the log.
|
||||||
|
*
|
||||||
|
* @param ex Exception
|
||||||
|
*/
|
||||||
public static void writeStackTrace(Exception ex) {
|
public static void writeStackTrace(Exception ex) {
|
||||||
if (Settings.useLogging) {
|
if (!Settings.useLogging) {
|
||||||
String dateTime;
|
return;
|
||||||
synchronized (df) {
|
|
||||||
dateTime = df.format(new Date());
|
|
||||||
}
|
|
||||||
writeLog(dateTime + " " + Throwables.getStackTraceAsString(ex));
|
|
||||||
}
|
}
|
||||||
|
writeLog("" + Throwables.getStackTraceAsString(ex));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,196 +1,269 @@
|
|||||||
package fr.xephi.authme;
|
package fr.xephi.authme;
|
||||||
|
|
||||||
import java.io.File;
|
import fr.xephi.authme.permission.PermissionsManager;
|
||||||
import java.util.List;
|
import fr.xephi.authme.settings.Settings;
|
||||||
import java.util.concurrent.Callable;
|
import fr.xephi.authme.util.Utils;
|
||||||
import java.util.concurrent.ExecutorService;
|
import org.bukkit.Bukkit;
|
||||||
import java.util.concurrent.Executors;
|
import org.bukkit.OfflinePlayer;
|
||||||
import java.util.concurrent.Future;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import java.io.File;
|
||||||
import org.bukkit.OfflinePlayer;
|
import java.util.List;
|
||||||
import org.bukkit.entity.Player;
|
import java.util.concurrent.Callable;
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
import fr.xephi.authme.settings.Settings;
|
import java.util.concurrent.Executors;
|
||||||
import fr.xephi.authme.util.Utils;
|
import java.util.concurrent.Future;
|
||||||
import net.milkbowl.vault.permission.Permission;
|
|
||||||
|
/**
|
||||||
public class DataManager {
|
*/
|
||||||
|
public class DataManager {
|
||||||
public AuthMe plugin;
|
|
||||||
|
public final AuthMe plugin;
|
||||||
public DataManager(AuthMe plugin) {
|
|
||||||
this.plugin = plugin;
|
/**
|
||||||
}
|
* Constructor for DataManager.
|
||||||
|
*
|
||||||
public void run() {
|
* @param plugin AuthMe
|
||||||
}
|
*/
|
||||||
|
public DataManager(AuthMe plugin) {
|
||||||
public synchronized OfflinePlayer getOfflinePlayer(final String name) {
|
this.plugin = plugin;
|
||||||
ExecutorService executor = Executors.newSingleThreadExecutor();
|
}
|
||||||
Future<OfflinePlayer> result = executor.submit(new Callable<OfflinePlayer>() {
|
|
||||||
|
/**
|
||||||
public synchronized OfflinePlayer call() throws Exception {
|
* Method getOfflinePlayer.
|
||||||
OfflinePlayer result = null;
|
*
|
||||||
try {
|
* @param name String
|
||||||
for (OfflinePlayer op : Bukkit.getOfflinePlayers())
|
*
|
||||||
if (op.getName().equalsIgnoreCase(name)) {
|
* @return OfflinePlayer
|
||||||
result = op;
|
*/
|
||||||
break;
|
public synchronized OfflinePlayer getOfflinePlayer(final String name) {
|
||||||
}
|
ExecutorService executor = Executors.newSingleThreadExecutor();
|
||||||
} catch (Exception e) {
|
Future<OfflinePlayer> result = executor.submit(new Callable<OfflinePlayer>() {
|
||||||
}
|
|
||||||
return result;
|
public synchronized OfflinePlayer call() throws Exception {
|
||||||
}
|
OfflinePlayer result = null;
|
||||||
});
|
try {
|
||||||
try {
|
for (OfflinePlayer op : Bukkit.getOfflinePlayers())
|
||||||
return result.get();
|
if (op.getName().equalsIgnoreCase(name)) {
|
||||||
} catch (Exception e) {
|
result = op;
|
||||||
return (null);
|
break;
|
||||||
} finally {
|
}
|
||||||
executor.shutdown();
|
} catch (Exception ignored) {
|
||||||
}
|
}
|
||||||
}
|
return result;
|
||||||
|
}
|
||||||
public synchronized void purgeAntiXray(List<String> cleared) {
|
});
|
||||||
int i = 0;
|
try {
|
||||||
for (String name : cleared) {
|
return result.get();
|
||||||
try {
|
} catch (Exception e) {
|
||||||
org.bukkit.OfflinePlayer player = getOfflinePlayer(name);
|
return (null);
|
||||||
if (player == null)
|
} finally {
|
||||||
continue;
|
executor.shutdown();
|
||||||
String playerName = player.getName();
|
}
|
||||||
File playerFile = new File("." + File.separator + "plugins" + File.separator + "AntiXRayData" + File.separator + "PlayerData" + File.separator + playerName);
|
}
|
||||||
if (playerFile.exists()) {
|
|
||||||
playerFile.delete();
|
/**
|
||||||
i++;
|
* Method purgeAntiXray.
|
||||||
}
|
*
|
||||||
} catch (Exception e) {
|
* @param cleared List<String>
|
||||||
}
|
*/
|
||||||
}
|
public synchronized void purgeAntiXray(List<String> cleared) {
|
||||||
ConsoleLogger.info("AutoPurgeDatabase : Remove " + i + " AntiXRayData Files");
|
int i = 0;
|
||||||
}
|
for (String name : cleared) {
|
||||||
|
try {
|
||||||
public synchronized void purgeLimitedCreative(List<String> cleared) {
|
org.bukkit.OfflinePlayer player = getOfflinePlayer(name);
|
||||||
int i = 0;
|
if (player == null)
|
||||||
for (String name : cleared) {
|
continue;
|
||||||
try {
|
String playerName = player.getName();
|
||||||
org.bukkit.OfflinePlayer player = getOfflinePlayer(name);
|
File playerFile = new File("." + File.separator + "plugins" + File.separator + "AntiXRayData" + File.separator + "PlayerData" + File.separator + playerName);
|
||||||
if (player == null)
|
if (playerFile.exists()) {
|
||||||
continue;
|
//noinspection ResultOfMethodCallIgnored
|
||||||
String playerName = player.getName();
|
playerFile.delete();
|
||||||
File playerFile = new File("." + File.separator + "plugins" + File.separator + "LimitedCreative" + File.separator + "inventories" + File.separator + playerName + ".yml");
|
i++;
|
||||||
if (playerFile.exists()) {
|
}
|
||||||
playerFile.delete();
|
} catch (Exception ignored) {
|
||||||
i++;
|
}
|
||||||
}
|
}
|
||||||
playerFile = new File("." + File.separator + "plugins" + File.separator + "LimitedCreative" + File.separator + "inventories" + File.separator + playerName + "_creative.yml");
|
ConsoleLogger.info("AutoPurgeDatabase : Remove " + i + " AntiXRayData Files");
|
||||||
if (playerFile.exists()) {
|
}
|
||||||
playerFile.delete();
|
|
||||||
i++;
|
/**
|
||||||
}
|
* Method purgeLimitedCreative.
|
||||||
playerFile = new File("." + File.separator + "plugins" + File.separator + "LimitedCreative" + File.separator + "inventories" + File.separator + playerName + "_adventure.yml");
|
*
|
||||||
if (playerFile.exists()) {
|
* @param cleared List<String>
|
||||||
playerFile.delete();
|
*/
|
||||||
i++;
|
public synchronized void purgeLimitedCreative(List<String> cleared) {
|
||||||
}
|
int i = 0;
|
||||||
} catch (Exception e) {
|
for (String name : cleared) {
|
||||||
}
|
try {
|
||||||
}
|
org.bukkit.OfflinePlayer player = getOfflinePlayer(name);
|
||||||
ConsoleLogger.info("AutoPurgeDatabase : Remove " + i + " LimitedCreative Survival, Creative and Adventure files");
|
if (player == null)
|
||||||
}
|
continue;
|
||||||
|
String playerName = player.getName();
|
||||||
public synchronized void purgeDat(List<String> cleared) {
|
File playerFile = new File("." + File.separator + "plugins" + File.separator + "LimitedCreative" + File.separator + "inventories" + File.separator + playerName + ".yml");
|
||||||
int i = 0;
|
if (playerFile.exists()) {
|
||||||
for (String name : cleared) {
|
//noinspection ResultOfMethodCallIgnored
|
||||||
try {
|
playerFile.delete();
|
||||||
org.bukkit.OfflinePlayer player = getOfflinePlayer(name);
|
i++;
|
||||||
if (player == null) {
|
}
|
||||||
continue;
|
playerFile = new File("." + File.separator + "plugins" + File.separator + "LimitedCreative" + File.separator + "inventories" + File.separator + playerName + "_creative.yml");
|
||||||
}
|
if (playerFile.exists()) {
|
||||||
|
//noinspection ResultOfMethodCallIgnored
|
||||||
try {
|
playerFile.delete();
|
||||||
File playerFile = new File(plugin.getServer().getWorldContainer() + File.separator + Settings.defaultWorld + File.separator + "players" + File.separator + player.getUniqueId() + ".dat");
|
i++;
|
||||||
playerFile.delete();
|
}
|
||||||
i++;
|
playerFile = new File("." + File.separator + "plugins" + File.separator + "LimitedCreative" + File.separator + "inventories" + File.separator + playerName + "_adventure.yml");
|
||||||
} catch(Exception ignore) {
|
if (playerFile.exists()) {
|
||||||
File playerFile = new File(plugin.getServer().getWorldContainer() + File.separator + Settings.defaultWorld + File.separator + "players" + File.separator + player.getName() + ".dat");
|
//noinspection ResultOfMethodCallIgnored
|
||||||
if (playerFile.exists()) {
|
playerFile.delete();
|
||||||
playerFile.delete();
|
i++;
|
||||||
i++;
|
}
|
||||||
}
|
} catch (Exception ignored) {
|
||||||
}
|
}
|
||||||
} catch (Exception ignore) {
|
}
|
||||||
}
|
ConsoleLogger.info("AutoPurgeDatabase : Remove " + i + " LimitedCreative Survival, Creative and Adventure files");
|
||||||
}
|
}
|
||||||
ConsoleLogger.info("AutoPurgeDatabase : Remove " + i + " .dat Files");
|
|
||||||
}
|
/**
|
||||||
|
* Method purgeDat.
|
||||||
@SuppressWarnings("deprecation")
|
*
|
||||||
public void purgeEssentials(List<String> cleared) {
|
* @param cleared List<String>
|
||||||
int i = 0;
|
*/
|
||||||
for (String name : cleared) {
|
public synchronized void purgeDat(List<String> cleared) {
|
||||||
try {
|
int i = 0;
|
||||||
File playerFile = new File(plugin.ess.getDataFolder() + File.separator + "userdata" + File.separator + plugin.getServer().getOfflinePlayer(name).getUniqueId() + ".yml");
|
for (String name : cleared) {
|
||||||
playerFile.delete();
|
try {
|
||||||
i++;
|
org.bukkit.OfflinePlayer player = getOfflinePlayer(name);
|
||||||
} catch (Exception e) {
|
if (player == null) {
|
||||||
File playerFile = new File(plugin.ess.getDataFolder() + File.separator + "userdata" + File.separator + name + ".yml");
|
continue;
|
||||||
if (playerFile.exists()) {
|
}
|
||||||
playerFile.delete();
|
|
||||||
i++;
|
try {
|
||||||
}
|
File playerFile = new File(plugin.getServer().getWorldContainer() + File.separator + Settings.defaultWorld + File.separator + "players" + File.separator + player.getUniqueId() + ".dat");
|
||||||
}
|
//noinspection ResultOfMethodCallIgnored
|
||||||
}
|
playerFile.delete();
|
||||||
ConsoleLogger.info("AutoPurgeDatabase : Remove " + i + " EssentialsFiles");
|
i++;
|
||||||
}
|
} catch (Exception ignore) {
|
||||||
|
File playerFile = new File(plugin.getServer().getWorldContainer() + File.separator + Settings.defaultWorld + File.separator + "players" + File.separator + player.getName() + ".dat");
|
||||||
public synchronized void purgePermissions(List<String> cleared,
|
if (playerFile.exists()) {
|
||||||
Permission permission) {
|
//noinspection ResultOfMethodCallIgnored
|
||||||
int i = 0;
|
playerFile.delete();
|
||||||
for (String name : cleared) {
|
i++;
|
||||||
try {
|
}
|
||||||
OfflinePlayer p = this.getOfflinePlayer(name);
|
}
|
||||||
for (String group : permission.getPlayerGroups((Player) p)) {
|
} catch (Exception ignore) {
|
||||||
permission.playerRemoveGroup(null, p, group);
|
}
|
||||||
}
|
}
|
||||||
i++;
|
ConsoleLogger.info("AutoPurgeDatabase : Remove " + i + " .dat Files");
|
||||||
} catch (Exception e) {
|
}
|
||||||
}
|
|
||||||
}
|
/**
|
||||||
ConsoleLogger.info("AutoPurgeDatabase : Remove " + i + " Permissions");
|
* Method purgeEssentials.
|
||||||
}
|
*
|
||||||
|
* @param cleared List<String>
|
||||||
public boolean isOnline(Player player, final String name) {
|
*/
|
||||||
if (player.isOnline())
|
@SuppressWarnings("deprecation")
|
||||||
return true;
|
public void purgeEssentials(List<String> cleared) {
|
||||||
ExecutorService executor = Executors.newSingleThreadExecutor();
|
int i = 0;
|
||||||
Future<Boolean> result = executor.submit(new Callable<Boolean>() {
|
for (String name : cleared) {
|
||||||
|
try {
|
||||||
@Override
|
File playerFile = new File(plugin.ess.getDataFolder() + File.separator + "userdata" + File.separator + plugin.getServer().getOfflinePlayer(name).getUniqueId() + ".yml");
|
||||||
public synchronized Boolean call() throws Exception {
|
//noinspection ResultOfMethodCallIgnored
|
||||||
for (OfflinePlayer op : Utils.getOnlinePlayers())
|
playerFile.delete();
|
||||||
if (op.getName().equalsIgnoreCase(name)) {
|
i++;
|
||||||
return true;
|
} catch (Exception e) {
|
||||||
}
|
File playerFile = new File(plugin.ess.getDataFolder() + File.separator + "userdata" + File.separator + name + ".yml");
|
||||||
return false;
|
if (playerFile.exists()) {
|
||||||
}
|
//noinspection ResultOfMethodCallIgnored
|
||||||
});
|
playerFile.delete();
|
||||||
try {
|
i++;
|
||||||
return result.get();
|
}
|
||||||
} catch (Exception e) {
|
}
|
||||||
return false;
|
}
|
||||||
} finally {
|
ConsoleLogger.info("AutoPurgeDatabase : Remove " + i + " EssentialsFiles");
|
||||||
executor.shutdown();
|
}
|
||||||
}
|
|
||||||
}
|
// TODO: What is this method for? Is it correct?
|
||||||
|
|
||||||
public Player getOnlinePlayerLower(String name) {
|
/**
|
||||||
name = name.toLowerCase();
|
* @param cleared Cleared players.
|
||||||
for (Player player : Utils.getOnlinePlayers()) {
|
*/
|
||||||
if (player.getName().equalsIgnoreCase(name))
|
public synchronized void purgePermissions(List<String> cleared) {
|
||||||
return player;
|
// Get the permissions manager, and make sure it's valid
|
||||||
}
|
PermissionsManager permsMan = this.plugin.getPermissionsManager();
|
||||||
return null;
|
if (permsMan == null)
|
||||||
}
|
ConsoleLogger.showError("Unable to access permissions manager instance!");
|
||||||
}
|
assert permsMan != null;
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
for (String name : cleared) {
|
||||||
|
try {
|
||||||
|
permsMan.removeAllGroups(this.getOnlinePlayerLower(name.toLowerCase()));
|
||||||
|
i++;
|
||||||
|
} catch (Exception ignored) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ConsoleLogger.info("AutoPurgeDatabase : Removed " + i + " permissions");
|
||||||
|
|
||||||
|
/*int i = 0;
|
||||||
|
for (String name : cleared) {
|
||||||
|
try {
|
||||||
|
OfflinePlayer p = this.getOfflinePlayer(name);
|
||||||
|
for (String group : permission.getPlayerGroups((Player) p)) {
|
||||||
|
permission.playerRemoveGroup(null, p, group);
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
} catch (Exception e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ConsoleLogger.info("AutoPurgeDatabase : Remove " + i + " Permissions");*/
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method isOnline.
|
||||||
|
*
|
||||||
|
* @param player Player
|
||||||
|
* @param name String
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public boolean isOnline(Player player, final String name) {
|
||||||
|
if (player.isOnline())
|
||||||
|
return true;
|
||||||
|
ExecutorService executor = Executors.newSingleThreadExecutor();
|
||||||
|
Future<Boolean> result = executor.submit(new Callable<Boolean>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public synchronized Boolean call() throws Exception {
|
||||||
|
for (OfflinePlayer op : Utils.getOnlinePlayers())
|
||||||
|
if (op.getName().equalsIgnoreCase(name)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
try {
|
||||||
|
return result.get();
|
||||||
|
} catch (Exception e) {
|
||||||
|
return false;
|
||||||
|
} finally {
|
||||||
|
executor.shutdown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method getOnlinePlayerLower.
|
||||||
|
*
|
||||||
|
* @param name String
|
||||||
|
*
|
||||||
|
* @return Player
|
||||||
|
*/
|
||||||
|
public Player getOnlinePlayerLower(String name) {
|
||||||
|
name = name.toLowerCase();
|
||||||
|
for (Player player : Utils.getOnlinePlayers()) {
|
||||||
|
if (player.getName().equalsIgnoreCase(name))
|
||||||
|
return player;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -1,30 +1,40 @@
|
|||||||
package fr.xephi.authme;
|
package fr.xephi.authme;
|
||||||
|
|
||||||
import java.awt.Color;
|
import java.awt.*;
|
||||||
import java.awt.Font;
|
import java.awt.image.BufferedImage;
|
||||||
import java.awt.GradientPaint;
|
|
||||||
import java.awt.Graphics2D;
|
/**
|
||||||
import java.awt.image.BufferedImage;
|
*/
|
||||||
|
public class ImageGenerator {
|
||||||
public class ImageGenerator {
|
|
||||||
|
private final String pass;
|
||||||
private String pass;
|
|
||||||
public ImageGenerator(String pass) {
|
/**
|
||||||
this.pass = pass;
|
* Constructor for ImageGenerator.
|
||||||
}
|
*
|
||||||
|
* @param pass String
|
||||||
public BufferedImage generateImage() {
|
*/
|
||||||
BufferedImage image = new BufferedImage(200, 60, BufferedImage.TYPE_BYTE_INDEXED);
|
public ImageGenerator(String pass) {
|
||||||
Graphics2D graphics = image.createGraphics();
|
this.pass = pass;
|
||||||
graphics.setColor(Color.BLACK);
|
}
|
||||||
graphics.fillRect(0, 0, 200, 40);
|
|
||||||
GradientPaint gradientPaint = new GradientPaint(10, 5, Color.WHITE, 20, 10, Color.WHITE, true);
|
/**
|
||||||
graphics.setPaint(gradientPaint);
|
* Method generateImage.
|
||||||
Font font = new Font("Comic Sans MS", Font.BOLD, 30);
|
*
|
||||||
graphics.setFont(font);
|
* @return BufferedImage
|
||||||
graphics.drawString(pass, 5, 30);
|
*/
|
||||||
graphics.dispose();
|
public BufferedImage generateImage() {
|
||||||
image.flush();
|
BufferedImage image = new BufferedImage(200, 60, BufferedImage.TYPE_BYTE_INDEXED);
|
||||||
return image;
|
Graphics2D graphics = image.createGraphics();
|
||||||
}
|
graphics.setColor(Color.BLACK);
|
||||||
}
|
graphics.fillRect(0, 0, 200, 40);
|
||||||
|
GradientPaint gradientPaint = new GradientPaint(10, 5, Color.WHITE, 20, 10, Color.WHITE, true);
|
||||||
|
graphics.setPaint(gradientPaint);
|
||||||
|
Font font = new Font("Comic Sans MS", Font.BOLD, 30);
|
||||||
|
graphics.setFont(font);
|
||||||
|
graphics.drawString(pass, 5, 30);
|
||||||
|
graphics.dispose();
|
||||||
|
image.flush();
|
||||||
|
return image;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
package fr.xephi.authme;
|
package fr.xephi.authme;
|
||||||
|
|
||||||
|
import fr.xephi.authme.util.StringUtils;
|
||||||
import org.apache.logging.log4j.Level;
|
import org.apache.logging.log4j.Level;
|
||||||
import org.apache.logging.log4j.Marker;
|
import org.apache.logging.log4j.Marker;
|
||||||
import org.apache.logging.log4j.core.LogEvent;
|
import org.apache.logging.log4j.core.LogEvent;
|
||||||
@ -7,79 +8,90 @@ import org.apache.logging.log4j.core.Logger;
|
|||||||
import org.apache.logging.log4j.message.Message;
|
import org.apache.logging.log4j.message.Message;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Implements a filter for Log4j to skip sensitive AuthMe commands.
|
||||||
*
|
*
|
||||||
* @author Xephi59
|
* @author Xephi59
|
||||||
|
* @version $Revision: 1.0 $
|
||||||
*/
|
*/
|
||||||
public class Log4JFilter implements org.apache.logging.log4j.core.Filter {
|
public class Log4JFilter implements org.apache.logging.log4j.core.Filter {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* List of commands (lower-case) to skip.
|
||||||
|
*/
|
||||||
|
private static final String[] COMMANDS_TO_SKIP = {"/login ", "/l ", "/reg ", "/changepassword ",
|
||||||
|
"/unregister ", "/authme register ", "/authme changepassword ", "/authme reg ", "/authme cp ",
|
||||||
|
"/register "};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor.
|
||||||
|
*/
|
||||||
public Log4JFilter() {
|
public Log4JFilter() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validates a Message instance and returns the {@link Result} value
|
||||||
|
* depending depending on whether the message contains sensitive AuthMe
|
||||||
|
* data.
|
||||||
|
*
|
||||||
|
* @param message the Message object to verify
|
||||||
|
*
|
||||||
|
* @return the Result value
|
||||||
|
*/
|
||||||
|
private static Result validateMessage(Message message) {
|
||||||
|
if (message == null) {
|
||||||
|
return Result.NEUTRAL;
|
||||||
|
}
|
||||||
|
return validateMessage(message.getFormattedMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validates a message and returns the {@link Result} value depending
|
||||||
|
* depending on whether the message contains sensitive AuthMe data.
|
||||||
|
*
|
||||||
|
* @param message the message to verify
|
||||||
|
*
|
||||||
|
* @return the Result value
|
||||||
|
*/
|
||||||
|
private static Result validateMessage(String message) {
|
||||||
|
if (message == null) {
|
||||||
|
return Result.NEUTRAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
String lowerMessage = message.toLowerCase();
|
||||||
|
if (lowerMessage.contains("issued server command:")
|
||||||
|
&& StringUtils.containsAny(lowerMessage, COMMANDS_TO_SKIP)) {
|
||||||
|
return Result.DENY;
|
||||||
|
}
|
||||||
|
return Result.NEUTRAL;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Result filter(LogEvent record) {
|
public Result filter(LogEvent record) {
|
||||||
try {
|
if (record == null) {
|
||||||
if (record == null || record.getMessage() == null)
|
|
||||||
return Result.NEUTRAL;
|
|
||||||
String logM = record.getMessage().getFormattedMessage().toLowerCase();
|
|
||||||
if (!logM.contains("issued server command:"))
|
|
||||||
return Result.NEUTRAL;
|
|
||||||
if (!logM.contains("/login ") && !logM.contains("/l ") && !logM.contains("/reg ") && !logM.contains("/changepassword ") && !logM.contains("/unregister ") && !logM.contains("/authme register ") && !logM.contains("/authme changepassword ") && !logM.contains("/authme reg ") && !logM.contains("/authme cp ") && !logM.contains("/register "))
|
|
||||||
return Result.NEUTRAL;
|
|
||||||
return Result.DENY;
|
|
||||||
} catch (NullPointerException npe) {
|
|
||||||
return Result.NEUTRAL;
|
return Result.NEUTRAL;
|
||||||
}
|
}
|
||||||
|
return validateMessage(record.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Result filter(Logger arg0, Level arg1, Marker arg2, String message,
|
public Result filter(Logger arg0, Level arg1, Marker arg2, String message,
|
||||||
Object... arg4) {
|
Object... arg4) {
|
||||||
try {
|
return validateMessage(message);
|
||||||
if (message == null)
|
|
||||||
return Result.NEUTRAL;
|
|
||||||
String logM = message.toLowerCase();
|
|
||||||
if (!logM.contains("issued server command:"))
|
|
||||||
return Result.NEUTRAL;
|
|
||||||
if (!logM.contains("/login ") && !logM.contains("/l ") && !logM.contains("/reg ") && !logM.contains("/changepassword ") && !logM.contains("/unregister ") && !logM.contains("/authme register ") && !logM.contains("/authme changepassword ") && !logM.contains("/authme reg ") && !logM.contains("/authme cp ") && !logM.contains("/register "))
|
|
||||||
return Result.NEUTRAL;
|
|
||||||
return Result.DENY;
|
|
||||||
} catch (NullPointerException npe) {
|
|
||||||
return Result.NEUTRAL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Result filter(Logger arg0, Level arg1, Marker arg2, Object message,
|
public Result filter(Logger arg0, Level arg1, Marker arg2, Object message,
|
||||||
Throwable arg4) {
|
Throwable arg4) {
|
||||||
try {
|
if (message == null) {
|
||||||
if (message == null)
|
|
||||||
return Result.NEUTRAL;
|
|
||||||
String logM = message.toString().toLowerCase();
|
|
||||||
if (!logM.contains("issued server command:"))
|
|
||||||
return Result.NEUTRAL;
|
|
||||||
if (!logM.contains("/login ") && !logM.contains("/l ") && !logM.contains("/reg ") && !logM.contains("/changepassword ") && !logM.contains("/unregister ") && !logM.contains("/authme register ") && !logM.contains("/authme changepassword ") && !logM.contains("/authme reg ") && !logM.contains("/authme cp ") && !logM.contains("/register "))
|
|
||||||
return Result.NEUTRAL;
|
|
||||||
return Result.DENY;
|
|
||||||
} catch (NullPointerException npe) {
|
|
||||||
return Result.NEUTRAL;
|
return Result.NEUTRAL;
|
||||||
}
|
}
|
||||||
|
return validateMessage(message.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Result filter(Logger arg0, Level arg1, Marker arg2, Message message,
|
public Result filter(Logger arg0, Level arg1, Marker arg2, Message message,
|
||||||
Throwable arg4) {
|
Throwable arg4) {
|
||||||
try {
|
return validateMessage(message);
|
||||||
if (message == null)
|
|
||||||
return Result.NEUTRAL;
|
|
||||||
String logM = message.getFormattedMessage().toLowerCase();
|
|
||||||
if (!logM.contains("issued server command:"))
|
|
||||||
return Result.NEUTRAL;
|
|
||||||
if (!logM.contains("/login ") && !logM.contains("/l ") && !logM.contains("/reg ") && !logM.contains("/changepassword ") && !logM.contains("/unregister ") && !logM.contains("/authme register ") && !logM.contains("/authme changepassword ") && !logM.contains("/authme reg ") && !logM.contains("/authme cp ") && !logM.contains("/register "))
|
|
||||||
return Result.NEUTRAL;
|
|
||||||
return Result.DENY;
|
|
||||||
} catch (NullPointerException npe) {
|
|
||||||
return Result.NEUTRAL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -1,35 +1,71 @@
|
|||||||
package fr.xephi.authme;
|
package fr.xephi.authme;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.text.SimpleDateFormat;
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
import fr.xephi.authme.settings.Settings;
|
import fr.xephi.authme.settings.Settings;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* The backup management class
|
||||||
*
|
*
|
||||||
* @author stefano
|
* @author stefano
|
||||||
|
* @version $Revision: 1.0 $
|
||||||
*/
|
*/
|
||||||
public class PerformBackup {
|
public class PerformBackup {
|
||||||
|
|
||||||
private String dbName = Settings.getMySQLDatabase;
|
final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd_HH-mm");
|
||||||
private String dbUserName = Settings.getMySQLUsername;
|
final String dateString = format.format(new Date());
|
||||||
private String dbPassword = Settings.getMySQLPassword;
|
private final String dbName = Settings.getMySQLDatabase;
|
||||||
private String tblname = Settings.getMySQLTablename;
|
private final String dbUserName = Settings.getMySQLUsername;
|
||||||
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd_HH-mm");
|
private final String dbPassword = Settings.getMySQLPassword;
|
||||||
String dateString = format.format(new Date());
|
private final String tblname = Settings.getMySQLTablename;
|
||||||
private String path = AuthMe.getInstance().getDataFolder() + File.separator + "backups" + File.separator + "backup" + dateString;
|
private final String path = AuthMe.getInstance().getDataFolder() + File.separator + "backups" + File.separator + "backup" + dateString;
|
||||||
private AuthMe instance;
|
private AuthMe instance;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for PerformBackup.
|
||||||
|
*
|
||||||
|
* @param instance AuthMe
|
||||||
|
*/
|
||||||
public PerformBackup(AuthMe instance) {
|
public PerformBackup(AuthMe instance) {
|
||||||
this.setInstance(instance);
|
this.setInstance(instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Perform a backup with the given reason.
|
||||||
|
*
|
||||||
|
* @param cause BackupCause The cause of the backup.
|
||||||
|
*/
|
||||||
|
public void doBackup(BackupCause cause) {
|
||||||
|
if (!Settings.isBackupActivated) {
|
||||||
|
ConsoleLogger.showError("Can't perform a Backup: disabled in configuration. Cause of the Backup: " + cause.name());
|
||||||
|
}
|
||||||
|
// Check whether a backup should be made at the specified point in time
|
||||||
|
switch (cause) {
|
||||||
|
case START:
|
||||||
|
if (!Settings.isBackupOnStart)
|
||||||
|
return;
|
||||||
|
case STOP:
|
||||||
|
if (!Settings.isBackupOnStop)
|
||||||
|
return;
|
||||||
|
case COMMAND:
|
||||||
|
case OTHER:
|
||||||
|
}
|
||||||
|
|
||||||
|
// Do backup and check return value!
|
||||||
|
if (doBackup()) {
|
||||||
|
ConsoleLogger.info("A backup has been performed successfully. Cause of the Backup: " + cause.name());
|
||||||
|
} else {
|
||||||
|
ConsoleLogger.showError("Error while performing a backup! Cause of the Backup: " + cause.name());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method doBackup.
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
public boolean doBackup() {
|
public boolean doBackup() {
|
||||||
|
|
||||||
switch (Settings.getDataSource) {
|
switch (Settings.getDataSource) {
|
||||||
@ -44,6 +80,11 @@ public class PerformBackup {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method MySqlBackup.
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
private boolean MySqlBackup() {
|
private boolean MySqlBackup() {
|
||||||
File dirBackup = new File(AuthMe.getInstance().getDataFolder() + "/backups");
|
File dirBackup = new File(AuthMe.getInstance().getDataFolder() + "/backups");
|
||||||
|
|
||||||
@ -83,6 +124,13 @@ public class PerformBackup {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method FileBackup.
|
||||||
|
*
|
||||||
|
* @param backend String
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
private boolean FileBackup(String backend) {
|
private boolean FileBackup(String backend) {
|
||||||
File dirBackup = new File(AuthMe.getInstance().getDataFolder() + "/backups");
|
File dirBackup = new File(AuthMe.getInstance().getDataFolder() + "/backups");
|
||||||
|
|
||||||
@ -99,13 +147,16 @@ public class PerformBackup {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* Check if we are under Windows and correct location of mysqldump.exe
|
* Method checkWindows.
|
||||||
* otherwise return error.
|
*
|
||||||
|
* @param windowsPath String
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
private boolean checkWindows(String windowsPath) {
|
private boolean checkWindows(String windowsPath) {
|
||||||
String isWin = System.getProperty("os.name").toLowerCase();
|
String isWin = System.getProperty("os.name").toLowerCase();
|
||||||
if (isWin.indexOf("win") >= 0) {
|
if (isWin.contains("win")) {
|
||||||
if (new File(windowsPath + "\\bin\\mysqldump.exe").exists()) {
|
if (new File(windowsPath + "\\bin\\mysqldump.exe").exists()) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
@ -116,7 +167,17 @@ public class PerformBackup {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyr src bytefile into dst file
|
* Check if we are under Windows and correct location of mysqldump.exe
|
||||||
|
* otherwise return error.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method copy.
|
||||||
|
*
|
||||||
|
* @param src File
|
||||||
|
* @param dst File
|
||||||
|
*
|
||||||
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
void copy(File src, File dst) throws IOException {
|
void copy(File src, File dst) throws IOException {
|
||||||
InputStream in = new FileInputStream(src);
|
InputStream in = new FileInputStream(src);
|
||||||
@ -132,12 +193,36 @@ public class PerformBackup {
|
|||||||
out.close();
|
out.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setInstance(AuthMe instance) {
|
/*
|
||||||
this.instance = instance;
|
* Copyr src bytefile into dst file
|
||||||
}
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method getInstance.
|
||||||
|
*
|
||||||
|
* @return AuthMe
|
||||||
|
*/
|
||||||
public AuthMe getInstance() {
|
public AuthMe getInstance() {
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method setInstance.
|
||||||
|
*
|
||||||
|
* @param instance AuthMe
|
||||||
|
*/
|
||||||
|
public void setInstance(AuthMe instance) {
|
||||||
|
this.instance = instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Possible backup causes.
|
||||||
|
*/
|
||||||
|
public enum BackupCause {
|
||||||
|
START,
|
||||||
|
STOP,
|
||||||
|
COMMAND,
|
||||||
|
OTHER,
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,39 +1,48 @@
|
|||||||
package fr.xephi.authme;
|
package fr.xephi.authme;
|
||||||
|
|
||||||
import java.io.File;
|
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||||
|
import fr.xephi.authme.settings.Settings;
|
||||||
|
import org.apache.commons.mail.HtmlEmail;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
|
||||||
import javax.activation.DataSource;
|
import javax.activation.DataSource;
|
||||||
import javax.activation.FileDataSource;
|
import javax.activation.FileDataSource;
|
||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
|
import java.io.File;
|
||||||
import org.apache.commons.mail.HtmlEmail;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
|
|
||||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
|
||||||
import fr.xephi.authme.settings.Settings;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @author Xephi59
|
* @author Xephi59
|
||||||
|
* @version $Revision: 1.0 $
|
||||||
*/
|
*/
|
||||||
public class SendMailSSL {
|
public class SendMailSSL {
|
||||||
|
|
||||||
public AuthMe plugin;
|
public final AuthMe plugin;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for SendMailSSL.
|
||||||
|
*
|
||||||
|
* @param plugin AuthMe
|
||||||
|
*/
|
||||||
public SendMailSSL(AuthMe plugin) {
|
public SendMailSSL(AuthMe plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method main.
|
||||||
|
*
|
||||||
|
* @param auth PlayerAuth
|
||||||
|
* @param newPass String
|
||||||
|
*/
|
||||||
public void main(final PlayerAuth auth, final String newPass) {
|
public void main(final PlayerAuth auth, final String newPass) {
|
||||||
String sendername;
|
String senderName;
|
||||||
|
|
||||||
if (Settings.getmailSenderName == null || Settings.getmailSenderName.isEmpty()) {
|
if (Settings.getmailSenderName == null || Settings.getmailSenderName.isEmpty()) {
|
||||||
sendername = Settings.getmailAccount;
|
senderName = Settings.getmailAccount;
|
||||||
} else {
|
} else {
|
||||||
sendername = Settings.getmailSenderName;
|
senderName = Settings.getmailSenderName;
|
||||||
}
|
}
|
||||||
|
|
||||||
final String sender = sendername;
|
final String sender = senderName;
|
||||||
final int port = Settings.getMailPort;
|
final int port = Settings.getMailPort;
|
||||||
final String acc = Settings.getmailAccount;
|
final String acc = Settings.getmailAccount;
|
||||||
final String subject = Settings.getMailSubject;
|
final String subject = Settings.getMailSubject;
|
||||||
@ -81,6 +90,7 @@ public class SendMailSSL {
|
|||||||
ConsoleLogger.showError("Fail to send a mail to " + mail);
|
ConsoleLogger.showError("Fail to send a mail to " + mail);
|
||||||
}
|
}
|
||||||
if (file != null)
|
if (file != null)
|
||||||
|
//noinspection ResultOfMethodCallIgnored
|
||||||
file.delete();
|
file.delete();
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|||||||
@ -1,25 +1,31 @@
|
|||||||
package fr.xephi.authme.api;
|
package fr.xephi.authme.api;
|
||||||
|
|
||||||
import java.security.NoSuchAlgorithmException;
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
import org.bukkit.plugin.Plugin;
|
|
||||||
|
|
||||||
import fr.xephi.authme.AuthMe;
|
import fr.xephi.authme.AuthMe;
|
||||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||||
import fr.xephi.authme.cache.auth.PlayerCache;
|
import fr.xephi.authme.cache.auth.PlayerCache;
|
||||||
import fr.xephi.authme.security.PasswordSecurity;
|
import fr.xephi.authme.security.PasswordSecurity;
|
||||||
import fr.xephi.authme.settings.Settings;
|
import fr.xephi.authme.settings.Settings;
|
||||||
import fr.xephi.authme.util.Utils;
|
import fr.xephi.authme.util.Utils;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
public class API {
|
public class API {
|
||||||
|
|
||||||
public static final String newline = System.getProperty("line.separator");
|
public static final String newline = System.getProperty("line.separator");
|
||||||
public static AuthMe instance;
|
public static AuthMe instance;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for API.
|
||||||
|
*
|
||||||
|
* @param instance AuthMe
|
||||||
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public API(AuthMe instance) {
|
public API(AuthMe instance) {
|
||||||
API.instance = instance;
|
API.instance = instance;
|
||||||
@ -42,14 +48,9 @@ public class API {
|
|||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public AuthMe getPlugin() {
|
|
||||||
return instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @param player
|
* @param player
|
||||||
|
*
|
||||||
* @return true if player is authenticate
|
* @return true if player is authenticate
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
@ -58,28 +59,8 @@ public class API {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @param player
|
* @param player
|
||||||
* @return true if player is a npc
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public boolean isaNPC(Player player) {
|
|
||||||
return Utils.isNPC(player);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
*
|
||||||
* @param player
|
|
||||||
* @return true if player is a npc
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public boolean isNPC(Player player) {
|
|
||||||
return Utils.isNPC(player);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param player
|
|
||||||
* @return true if the player is unrestricted
|
* @return true if the player is unrestricted
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
@ -87,6 +68,13 @@ public class API {
|
|||||||
return Utils.isUnrestricted(player);
|
return Utils.isUnrestricted(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method getLastLocation.
|
||||||
|
*
|
||||||
|
* @param player Player
|
||||||
|
*
|
||||||
|
* @return Location
|
||||||
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public static Location getLastLocation(Player player) {
|
public static Location getLastLocation(Player player) {
|
||||||
try {
|
try {
|
||||||
@ -104,19 +92,26 @@ public class API {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method setPlayerInventory.
|
||||||
|
*
|
||||||
|
* @param player Player
|
||||||
|
* @param content ItemStack[]
|
||||||
|
* @param armor ItemStack[]
|
||||||
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public static void setPlayerInventory(Player player, ItemStack[] content,
|
public static void setPlayerInventory(Player player, ItemStack[] content,
|
||||||
ItemStack[] armor) {
|
ItemStack[] armor) {
|
||||||
try {
|
try {
|
||||||
player.getInventory().setContents(content);
|
player.getInventory().setContents(content);
|
||||||
player.getInventory().setArmorContents(armor);
|
player.getInventory().setArmorContents(armor);
|
||||||
} catch (NullPointerException npe) {
|
} catch (NullPointerException ignored) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @param playerName
|
* @param playerName
|
||||||
|
*
|
||||||
* @return true if player is registered
|
* @return true if player is registered
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
@ -126,13 +121,14 @@ public class API {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param String
|
* @param playerName String
|
||||||
* playerName, String passwordToCheck
|
* @param passwordToCheck String
|
||||||
|
*
|
||||||
* @return true if the password is correct , false else
|
* @return true if the password is correct , false else
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public static boolean checkPassword(String playerName,
|
public static boolean checkPassword(String playerName,
|
||||||
String passwordToCheck) {
|
String passwordToCheck) {
|
||||||
if (!isRegistered(playerName))
|
if (!isRegistered(playerName))
|
||||||
return false;
|
return false;
|
||||||
String player = playerName.toLowerCase();
|
String player = playerName.toLowerCase();
|
||||||
@ -147,8 +143,9 @@ public class API {
|
|||||||
/**
|
/**
|
||||||
* Register a player
|
* Register a player
|
||||||
*
|
*
|
||||||
* @param String
|
* @param playerName String
|
||||||
* playerName, String password
|
* @param password String
|
||||||
|
*
|
||||||
* @return true if the player is register correctly
|
* @return true if the player is register correctly
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
@ -160,10 +157,7 @@ public class API {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
PlayerAuth auth = new PlayerAuth(name, hash, "198.18.0.1", 0, "your@email.com", playerName);
|
PlayerAuth auth = new PlayerAuth(name, hash, "198.18.0.1", 0, "your@email.com", playerName);
|
||||||
if (!instance.database.saveAuth(auth)) {
|
return instance.database.saveAuth(auth);
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
} catch (NoSuchAlgorithmException ex) {
|
} catch (NoSuchAlgorithmException ex) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -172,12 +166,41 @@ public class API {
|
|||||||
/**
|
/**
|
||||||
* Force a player to login
|
* Force a player to login
|
||||||
*
|
*
|
||||||
* @param Player
|
* @param player * player
|
||||||
* player
|
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public static void forceLogin(Player player) {
|
public static void forceLogin(Player player) {
|
||||||
instance.management.performLogin(player, "dontneed", true);
|
instance.management.performLogin(player, "dontneed", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method getPlugin.
|
||||||
|
*
|
||||||
|
* @return AuthMe
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public AuthMe getPlugin() {
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param player
|
||||||
|
*
|
||||||
|
* @return true if player is a npc
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public boolean isaNPC(Player player) {
|
||||||
|
return Utils.isNPC(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param player
|
||||||
|
*
|
||||||
|
* @return true if player is a npc
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public boolean isNPC(Player player) {
|
||||||
|
return Utils.isNPC(player);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,32 +1,42 @@
|
|||||||
package fr.xephi.authme.api;
|
package fr.xephi.authme.api;
|
||||||
|
|
||||||
import java.security.NoSuchAlgorithmException;
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.Server;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.plugin.Plugin;
|
|
||||||
|
|
||||||
import fr.xephi.authme.AuthMe;
|
import fr.xephi.authme.AuthMe;
|
||||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||||
import fr.xephi.authme.cache.auth.PlayerCache;
|
import fr.xephi.authme.cache.auth.PlayerCache;
|
||||||
import fr.xephi.authme.security.PasswordSecurity;
|
import fr.xephi.authme.security.PasswordSecurity;
|
||||||
import fr.xephi.authme.settings.Settings;
|
import fr.xephi.authme.settings.Settings;
|
||||||
import fr.xephi.authme.util.Utils;
|
import fr.xephi.authme.util.Utils;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.Server;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
public class NewAPI {
|
public class NewAPI {
|
||||||
|
|
||||||
public static final String newline = System.getProperty("line.separator");
|
|
||||||
public static NewAPI singleton;
|
public static NewAPI singleton;
|
||||||
public AuthMe plugin;
|
public final AuthMe plugin;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for NewAPI.
|
||||||
|
*
|
||||||
|
* @param plugin AuthMe
|
||||||
|
*/
|
||||||
public NewAPI(AuthMe plugin) {
|
public NewAPI(AuthMe plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
public NewAPI(Server serv) {
|
/**
|
||||||
this.plugin = (AuthMe) serv.getPluginManager().getPlugin("AuthMe");
|
* Constructor for NewAPI.
|
||||||
|
*
|
||||||
|
* @param server Server
|
||||||
|
*/
|
||||||
|
public NewAPI(Server server) {
|
||||||
|
this.plugin = (AuthMe) server.getPluginManager().getPlugin("AuthMe");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -46,13 +56,18 @@ public class NewAPI {
|
|||||||
return singleton;
|
return singleton;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method getPlugin.
|
||||||
|
*
|
||||||
|
* @return AuthMe
|
||||||
|
*/
|
||||||
public AuthMe getPlugin() {
|
public AuthMe getPlugin() {
|
||||||
return plugin;
|
return plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @param player
|
* @param player
|
||||||
|
*
|
||||||
* @return true if player is authenticate
|
* @return true if player is authenticate
|
||||||
*/
|
*/
|
||||||
public boolean isAuthenticated(Player player) {
|
public boolean isAuthenticated(Player player) {
|
||||||
@ -60,8 +75,8 @@ public class NewAPI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @param player
|
* @param player
|
||||||
|
*
|
||||||
* @return true if player is a npc
|
* @return true if player is a npc
|
||||||
*/
|
*/
|
||||||
public boolean isNPC(Player player) {
|
public boolean isNPC(Player player) {
|
||||||
@ -69,14 +84,21 @@ public class NewAPI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @param player
|
* @param player
|
||||||
|
*
|
||||||
* @return true if the player is unrestricted
|
* @return true if the player is unrestricted
|
||||||
*/
|
*/
|
||||||
public boolean isUnrestricted(Player player) {
|
public boolean isUnrestricted(Player player) {
|
||||||
return Utils.isUnrestricted(player);
|
return Utils.isUnrestricted(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method getLastLocation.
|
||||||
|
*
|
||||||
|
* @param player Player
|
||||||
|
*
|
||||||
|
* @return Location
|
||||||
|
*/
|
||||||
public Location getLastLocation(Player player) {
|
public Location getLastLocation(Player player) {
|
||||||
try {
|
try {
|
||||||
PlayerAuth auth = PlayerCache.getInstance().getAuth(player.getName().toLowerCase());
|
PlayerAuth auth = PlayerCache.getInstance().getAuth(player.getName().toLowerCase());
|
||||||
@ -93,8 +115,8 @@ public class NewAPI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @param playerName
|
* @param playerName
|
||||||
|
*
|
||||||
* @return true if player is registered
|
* @return true if player is registered
|
||||||
*/
|
*/
|
||||||
public boolean isRegistered(String playerName) {
|
public boolean isRegistered(String playerName) {
|
||||||
@ -103,8 +125,9 @@ public class NewAPI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param String
|
* @param playerName String
|
||||||
* playerName, String passwordToCheck
|
* @param passwordToCheck String
|
||||||
|
*
|
||||||
* @return true if the password is correct , false else
|
* @return true if the password is correct , false else
|
||||||
*/
|
*/
|
||||||
public boolean checkPassword(String playerName, String passwordToCheck) {
|
public boolean checkPassword(String playerName, String passwordToCheck) {
|
||||||
@ -122,8 +145,9 @@ public class NewAPI {
|
|||||||
/**
|
/**
|
||||||
* Register a player
|
* Register a player
|
||||||
*
|
*
|
||||||
* @param String
|
* @param playerName String
|
||||||
* playerName, String password
|
* @param password String
|
||||||
|
*
|
||||||
* @return true if the player is register correctly
|
* @return true if the player is register correctly
|
||||||
*/
|
*/
|
||||||
public boolean registerPlayer(String playerName, String password) {
|
public boolean registerPlayer(String playerName, String password) {
|
||||||
@ -143,8 +167,7 @@ public class NewAPI {
|
|||||||
/**
|
/**
|
||||||
* Force a player to login
|
* Force a player to login
|
||||||
*
|
*
|
||||||
* @param Player
|
* @param player * player
|
||||||
* player
|
|
||||||
*/
|
*/
|
||||||
public void forceLogin(Player player) {
|
public void forceLogin(Player player) {
|
||||||
plugin.management.performLogin(player, "dontneed", true);
|
plugin.management.performLogin(player, "dontneed", true);
|
||||||
@ -153,35 +176,28 @@ public class NewAPI {
|
|||||||
/**
|
/**
|
||||||
* Force a player to logout
|
* Force a player to logout
|
||||||
*
|
*
|
||||||
* @param Player
|
* @param player * player
|
||||||
* player
|
|
||||||
*/
|
*/
|
||||||
public void forceLogout(Player player)
|
public void forceLogout(Player player) {
|
||||||
{
|
plugin.management.performLogout(player);
|
||||||
plugin.management.performLogout(player);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Force a player to register
|
* Force a player to register
|
||||||
*
|
*
|
||||||
* @param Player
|
* @param player * player
|
||||||
* player
|
* @param password String
|
||||||
* @param String
|
|
||||||
* password
|
|
||||||
*/
|
*/
|
||||||
public void forceRegister(Player player, String password)
|
public void forceRegister(Player player, String password) {
|
||||||
{
|
plugin.management.performRegister(player, password, null);
|
||||||
plugin.management.performRegister(player, password, null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Force a player to unregister
|
* Force a player to unregister
|
||||||
*
|
*
|
||||||
* @param Player
|
* @param player * player
|
||||||
* player
|
|
||||||
*/
|
*/
|
||||||
public void forceUnregister(Player player)
|
public void forceUnregister(Player player) {
|
||||||
{
|
plugin.management.performUnregister(player, "", true);
|
||||||
plugin.management.performUnregister(player, "", true);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,62 +3,167 @@ package fr.xephi.authme.cache.auth;
|
|||||||
import fr.xephi.authme.security.HashAlgorithm;
|
import fr.xephi.authme.security.HashAlgorithm;
|
||||||
import fr.xephi.authme.settings.Settings;
|
import fr.xephi.authme.settings.Settings;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
public class PlayerAuth {
|
public class PlayerAuth {
|
||||||
|
|
||||||
private String nickname = "";
|
private String nickname;
|
||||||
private String hash = "";
|
private String hash;
|
||||||
private String ip = "192.168.0.1";
|
private String ip;
|
||||||
private long lastLogin = 0;
|
private long lastLogin;
|
||||||
private double x = 0;
|
private double x;
|
||||||
private double y = 0;
|
private double y;
|
||||||
private double z = 0;
|
private double z;
|
||||||
private String world = "world";
|
private String world;
|
||||||
private String salt = "";
|
private String salt;
|
||||||
private String vBhash = null;
|
private int groupId;
|
||||||
private int groupId = -1;
|
private String email;
|
||||||
private String email = "your@email.com";
|
|
||||||
private String realName;
|
private String realName;
|
||||||
|
|
||||||
public PlayerAuth(String nickname, String hash, String ip, long lastLogin,
|
/**
|
||||||
String email, String realName) {
|
*
|
||||||
this.nickname = nickname;
|
*/
|
||||||
this.hash = hash;
|
public PlayerAuth(String serialized)
|
||||||
this.ip = ip;
|
{
|
||||||
this.lastLogin = lastLogin;
|
this.unserialize(serialized);
|
||||||
this.email = email;
|
|
||||||
this.realName = realName;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public PlayerAuth(String nickname, double x, double y, double z,
|
/**
|
||||||
String world, String realName) {
|
* Constructor for PlayerAuth.
|
||||||
this.nickname = nickname;
|
*
|
||||||
this.x = x;
|
* @param nickname String
|
||||||
this.y = y;
|
* @param ip String
|
||||||
this.z = z;
|
* @param lastLogin long
|
||||||
this.world = world;
|
* @param realName String
|
||||||
this.realName = realName;
|
*/
|
||||||
this.lastLogin = System.currentTimeMillis();
|
public PlayerAuth(String nickname, String ip, long lastLogin, String realName) {
|
||||||
|
this(nickname, "", "", -1, ip, lastLogin, 0, 0, 0, "world", "your@email.com", realName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public PlayerAuth(String nickname, String hash, String ip, long lastLogin,
|
/**
|
||||||
double x, double y, double z, String world, String email,
|
* Constructor for PlayerAuth.
|
||||||
String realName) {
|
*
|
||||||
this.nickname = nickname;
|
* @param nickname String
|
||||||
this.hash = hash;
|
* @param x double
|
||||||
this.ip = ip;
|
* @param y double
|
||||||
this.lastLogin = lastLogin;
|
* @param z double
|
||||||
this.x = x;
|
* @param world String
|
||||||
this.y = y;
|
* @param realName String
|
||||||
this.z = z;
|
*/
|
||||||
this.world = world;
|
public PlayerAuth(String nickname, double x, double y, double z, String world, String realName) {
|
||||||
this.email = email;
|
this(nickname, "", "", -1, "127.0.0.1", System.currentTimeMillis(), x, y, z, world, "your@email.com", realName);
|
||||||
this.realName = realName;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public PlayerAuth(String nickname, String hash, String salt, int groupId,
|
/**
|
||||||
String ip, long lastLogin, double x, double y, double z,
|
* Constructor for PlayerAuth.
|
||||||
String world, String email, String realName) {
|
*
|
||||||
|
* @param nickname String
|
||||||
|
* @param hash String
|
||||||
|
* @param ip String
|
||||||
|
* @param lastLogin long
|
||||||
|
* @param realName String
|
||||||
|
*/
|
||||||
|
public PlayerAuth(String nickname, String hash, String ip, long lastLogin, String realName) {
|
||||||
|
this(nickname, hash, "", -1, ip, lastLogin, 0, 0, 0, "world", "your@email.com", realName);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for PlayerAuth.
|
||||||
|
*
|
||||||
|
* @param nickname String
|
||||||
|
* @param hash String
|
||||||
|
* @param ip String
|
||||||
|
* @param lastLogin long
|
||||||
|
* @param email String
|
||||||
|
* @param realName String
|
||||||
|
*/
|
||||||
|
public PlayerAuth(String nickname, String hash, String ip, long lastLogin, String email, String realName) {
|
||||||
|
this(nickname, hash, "", -1, ip, lastLogin, 0, 0, 0, "world", email, realName);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for PlayerAuth.
|
||||||
|
*
|
||||||
|
* @param nickname String
|
||||||
|
* @param hash String
|
||||||
|
* @param salt String
|
||||||
|
* @param ip String
|
||||||
|
* @param lastLogin long
|
||||||
|
* @param realName String
|
||||||
|
*/
|
||||||
|
public PlayerAuth(String nickname, String hash, String salt, String ip, long lastLogin, String realName) {
|
||||||
|
this(nickname, hash, salt, -1, ip, lastLogin, 0, 0, 0, "world", "your@email.com", realName);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for PlayerAuth.
|
||||||
|
*
|
||||||
|
* @param nickname String
|
||||||
|
* @param hash String
|
||||||
|
* @param ip String
|
||||||
|
* @param lastLogin long
|
||||||
|
* @param x double
|
||||||
|
* @param y double
|
||||||
|
* @param z double
|
||||||
|
* @param world String
|
||||||
|
* @param email String
|
||||||
|
* @param realName String
|
||||||
|
*/
|
||||||
|
public PlayerAuth(String nickname, String hash, String ip, long lastLogin, double x, double y, double z, String world, String email, String realName) {
|
||||||
|
this(nickname, hash, "", -1, ip, lastLogin, x, y, z, world, email, realName);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for PlayerAuth.
|
||||||
|
*
|
||||||
|
* @param nickname String
|
||||||
|
* @param hash String
|
||||||
|
* @param salt String
|
||||||
|
* @param ip String
|
||||||
|
* @param lastLogin long
|
||||||
|
* @param x double
|
||||||
|
* @param y double
|
||||||
|
* @param z double
|
||||||
|
* @param world String
|
||||||
|
* @param email String
|
||||||
|
* @param realName String
|
||||||
|
*/
|
||||||
|
public PlayerAuth(String nickname, String hash, String salt, String ip, long lastLogin, double x, double y, double z, String world, String email, String realName) {
|
||||||
|
this(nickname, hash, salt, -1, ip, lastLogin, x, y, z, world, email, realName);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for PlayerAuth.
|
||||||
|
*
|
||||||
|
* @param nickname String
|
||||||
|
* @param hash String
|
||||||
|
* @param salt String
|
||||||
|
* @param groupId int
|
||||||
|
* @param ip String
|
||||||
|
* @param lastLogin long
|
||||||
|
* @param realName String
|
||||||
|
*/
|
||||||
|
public PlayerAuth(String nickname, String hash, String salt, int groupId, String ip, long lastLogin, String realName) {
|
||||||
|
this(nickname, hash, salt, groupId, ip, lastLogin, 0, 0, 0, "world", "your@email.com", realName);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for PlayerAuth.
|
||||||
|
*
|
||||||
|
* @param nickname String
|
||||||
|
* @param hash String
|
||||||
|
* @param salt String
|
||||||
|
* @param groupId int
|
||||||
|
* @param ip String
|
||||||
|
* @param lastLogin long
|
||||||
|
* @param x double
|
||||||
|
* @param y double
|
||||||
|
* @param z double
|
||||||
|
* @param world String
|
||||||
|
* @param email String
|
||||||
|
* @param realName String
|
||||||
|
*/
|
||||||
|
public PlayerAuth(String nickname, String hash, String salt, int groupId, String ip, long lastLogin, double x, double y, double z, String world, String email, String realName) {
|
||||||
this.nickname = nickname;
|
this.nickname = nickname;
|
||||||
this.hash = hash;
|
this.hash = hash;
|
||||||
this.ip = ip;
|
this.ip = ip;
|
||||||
@ -73,182 +178,11 @@ public class PlayerAuth {
|
|||||||
this.realName = realName;
|
this.realName = realName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PlayerAuth(String nickname, String hash, String salt, int groupId,
|
/**
|
||||||
String ip, long lastLogin, String realName) {
|
* Method set.
|
||||||
this.nickname = nickname;
|
*
|
||||||
this.hash = hash;
|
* @param auth PlayerAuth
|
||||||
this.ip = ip;
|
*/
|
||||||
this.lastLogin = lastLogin;
|
|
||||||
this.salt = salt;
|
|
||||||
this.groupId = groupId;
|
|
||||||
this.realName = realName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public PlayerAuth(String nickname, String hash, String salt, String ip,
|
|
||||||
long lastLogin, String realName) {
|
|
||||||
this.nickname = nickname;
|
|
||||||
this.hash = hash;
|
|
||||||
this.ip = ip;
|
|
||||||
this.lastLogin = lastLogin;
|
|
||||||
this.salt = salt;
|
|
||||||
this.realName = realName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public PlayerAuth(String nickname, String hash, String salt, String ip,
|
|
||||||
long lastLogin, double x, double y, double z, String world,
|
|
||||||
String email, String realName) {
|
|
||||||
this.nickname = nickname;
|
|
||||||
this.hash = hash;
|
|
||||||
this.ip = ip;
|
|
||||||
this.lastLogin = lastLogin;
|
|
||||||
this.x = x;
|
|
||||||
this.y = y;
|
|
||||||
this.z = z;
|
|
||||||
this.world = world;
|
|
||||||
this.salt = salt;
|
|
||||||
this.email = email;
|
|
||||||
this.realName = realName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public PlayerAuth(String nickname, String ip, long lastLogin,
|
|
||||||
String realName) {
|
|
||||||
this.nickname = nickname;
|
|
||||||
this.ip = ip;
|
|
||||||
this.lastLogin = lastLogin;
|
|
||||||
this.realName = realName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public PlayerAuth(String nickname, String hash, String ip, long lastLogin,
|
|
||||||
String realName) {
|
|
||||||
this.nickname = nickname;
|
|
||||||
this.ip = ip;
|
|
||||||
this.lastLogin = lastLogin;
|
|
||||||
this.hash = hash;
|
|
||||||
this.realName = realName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getIp() {
|
|
||||||
if (ip == null || ip.isEmpty())
|
|
||||||
ip = "127.0.0.1";
|
|
||||||
return ip;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getNickname() {
|
|
||||||
return nickname;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getHash() {
|
|
||||||
if (Settings.getPasswordHash == HashAlgorithm.MD5VB) {
|
|
||||||
if (salt != null && !salt.isEmpty() && Settings.getPasswordHash == HashAlgorithm.MD5VB) {
|
|
||||||
vBhash = "$MD5vb$" + salt + "$" + hash;
|
|
||||||
return vBhash;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return hash;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getSalt() {
|
|
||||||
return this.salt;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getGroupId() {
|
|
||||||
return groupId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public double getQuitLocX() {
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
|
|
||||||
public double getQuitLocY() {
|
|
||||||
return y;
|
|
||||||
}
|
|
||||||
|
|
||||||
public double getQuitLocZ() {
|
|
||||||
return z;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getEmail() {
|
|
||||||
return email;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setQuitLocX(double d) {
|
|
||||||
this.x = d;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setQuitLocY(double d) {
|
|
||||||
this.y = d;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setQuitLocZ(double d) {
|
|
||||||
this.z = d;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getLastLogin() {
|
|
||||||
try {
|
|
||||||
if (Long.valueOf(lastLogin) == null)
|
|
||||||
lastLogin = 0L;
|
|
||||||
} catch (NullPointerException e) {
|
|
||||||
lastLogin = 0L;
|
|
||||||
}
|
|
||||||
return lastLogin;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setHash(String hash) {
|
|
||||||
this.hash = hash;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setIp(String ip) {
|
|
||||||
this.ip = ip;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLastLogin(long lastLogin) {
|
|
||||||
this.lastLogin = lastLogin;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setEmail(String email) {
|
|
||||||
this.email = email;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSalt(String salt) {
|
|
||||||
this.salt = salt;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object obj) {
|
|
||||||
if (!(obj instanceof PlayerAuth)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
PlayerAuth other = (PlayerAuth) obj;
|
|
||||||
return other.getIp().equals(this.ip) && other.getNickname().equals(this.nickname);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
int hashCode = 7;
|
|
||||||
hashCode = 71 * hashCode + (this.nickname != null ? this.nickname.hashCode() : 0);
|
|
||||||
hashCode = 71 * hashCode + (this.ip != null ? this.ip.hashCode() : 0);
|
|
||||||
return hashCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setWorld(String world) {
|
|
||||||
this.world = world;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getWorld() {
|
|
||||||
return world;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
String s = "Player : " + nickname + " | " + realName + " ! IP : " + ip + " ! LastLogin : " + lastLogin + " ! LastPosition : " + x + "," + y + "," + z + "," + world + " ! Email : " + email + " ! Hash : " + hash + " ! Salt : " + salt;
|
|
||||||
return s;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setName(String nickname) {
|
|
||||||
this.nickname = nickname;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void set(PlayerAuth auth) {
|
public void set(PlayerAuth auth) {
|
||||||
this.setEmail(auth.getEmail());
|
this.setEmail(auth.getEmail());
|
||||||
this.setHash(auth.getHash());
|
this.setHash(auth.getHash());
|
||||||
@ -263,12 +197,304 @@ public class PlayerAuth {
|
|||||||
this.setRealName(auth.getRealName());
|
this.setRealName(auth.getRealName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method setName.
|
||||||
|
*
|
||||||
|
* @param nickname String
|
||||||
|
*/
|
||||||
|
public void setName(String nickname) {
|
||||||
|
this.nickname = nickname;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method getNickname.
|
||||||
|
*
|
||||||
|
* @return String
|
||||||
|
*/
|
||||||
|
public String getNickname() {
|
||||||
|
return nickname;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method getRealName.
|
||||||
|
*
|
||||||
|
* @return String
|
||||||
|
*/
|
||||||
public String getRealName() {
|
public String getRealName() {
|
||||||
return realName;
|
return realName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method setRealName.
|
||||||
|
*
|
||||||
|
* @param realName String
|
||||||
|
*/
|
||||||
public void setRealName(String realName) {
|
public void setRealName(String realName) {
|
||||||
this.realName = realName;
|
this.realName = realName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method getGroupId.
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public int getGroupId() {
|
||||||
|
return groupId;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method getQuitLocX.
|
||||||
|
*
|
||||||
|
* @return double
|
||||||
|
*/
|
||||||
|
public double getQuitLocX() {
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method setQuitLocX.
|
||||||
|
*
|
||||||
|
* @param d double
|
||||||
|
*/
|
||||||
|
public void setQuitLocX(double d) {
|
||||||
|
this.x = d;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method getQuitLocY.
|
||||||
|
*
|
||||||
|
* @return double
|
||||||
|
*/
|
||||||
|
public double getQuitLocY() {
|
||||||
|
return y;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method setQuitLocY.
|
||||||
|
*
|
||||||
|
* @param d double
|
||||||
|
*/
|
||||||
|
public void setQuitLocY(double d) {
|
||||||
|
this.y = d;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method getQuitLocZ.
|
||||||
|
*
|
||||||
|
* @return double
|
||||||
|
*/
|
||||||
|
public double getQuitLocZ() {
|
||||||
|
return z;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method setQuitLocZ.
|
||||||
|
*
|
||||||
|
* @param d double
|
||||||
|
*/
|
||||||
|
public void setQuitLocZ(double d) {
|
||||||
|
this.z = d;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method getWorld.
|
||||||
|
*
|
||||||
|
* @return String
|
||||||
|
*/
|
||||||
|
public String getWorld() {
|
||||||
|
return world;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method setWorld.
|
||||||
|
*
|
||||||
|
* @param world String
|
||||||
|
*/
|
||||||
|
public void setWorld(String world) {
|
||||||
|
this.world = world;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method getIp.
|
||||||
|
*
|
||||||
|
* @return String
|
||||||
|
*/
|
||||||
|
public String getIp() {
|
||||||
|
return ip;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method setIp.
|
||||||
|
*
|
||||||
|
* @param ip String
|
||||||
|
*/
|
||||||
|
public void setIp(String ip) {
|
||||||
|
this.ip = ip;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method getLastLogin.
|
||||||
|
*
|
||||||
|
* @return long
|
||||||
|
*/
|
||||||
|
public long getLastLogin() {
|
||||||
|
return lastLogin;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method setLastLogin.
|
||||||
|
*
|
||||||
|
* @param lastLogin long
|
||||||
|
*/
|
||||||
|
public void setLastLogin(long lastLogin) {
|
||||||
|
this.lastLogin = lastLogin;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method getEmail.
|
||||||
|
*
|
||||||
|
* @return String
|
||||||
|
*/
|
||||||
|
public String getEmail() {
|
||||||
|
return email;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method setEmail.
|
||||||
|
*
|
||||||
|
* @param email String
|
||||||
|
*/
|
||||||
|
public void setEmail(String email) {
|
||||||
|
this.email = email;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method getSalt.
|
||||||
|
*
|
||||||
|
* @return String
|
||||||
|
*/
|
||||||
|
public String getSalt() {
|
||||||
|
return this.salt;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method setSalt.
|
||||||
|
*
|
||||||
|
* @param salt String
|
||||||
|
*/
|
||||||
|
public void setSalt(String salt) {
|
||||||
|
this.salt = salt;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method getHash.
|
||||||
|
*
|
||||||
|
* @return String
|
||||||
|
*/
|
||||||
|
public String getHash() {
|
||||||
|
if (Settings.getPasswordHash == HashAlgorithm.MD5VB) {
|
||||||
|
if (salt != null && !salt.isEmpty() && Settings.getPasswordHash == HashAlgorithm.MD5VB) {
|
||||||
|
return "$MD5vb$" + salt + "$" + hash;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return hash;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method setHash.
|
||||||
|
*
|
||||||
|
* @param hash String
|
||||||
|
*/
|
||||||
|
public void setHash(String hash) {
|
||||||
|
this.hash = hash;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method equals.
|
||||||
|
*
|
||||||
|
* @param obj Object
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (!(obj instanceof PlayerAuth)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
PlayerAuth other = (PlayerAuth) obj;
|
||||||
|
return other.getIp().equals(this.ip) && other.getNickname().equals(this.nickname);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method hashCode.
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
int hashCode = 7;
|
||||||
|
hashCode = 71 * hashCode + (this.nickname != null ? this.nickname.hashCode() : 0);
|
||||||
|
hashCode = 71 * hashCode + (this.ip != null ? this.ip.hashCode() : 0);
|
||||||
|
return hashCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method toString.
|
||||||
|
*
|
||||||
|
* @return String
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return ("Player : " + nickname + " | " + realName
|
||||||
|
+ " ! IP : " + ip
|
||||||
|
+ " ! LastLogin : " + lastLogin
|
||||||
|
+ " ! LastPosition : " + x + "," + y + "," + z + "," + world
|
||||||
|
+ " ! Email : " + email
|
||||||
|
+ " ! Hash : " + hash
|
||||||
|
+ " ! Salt : " + salt);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method to serialize playerauth
|
||||||
|
*
|
||||||
|
* @return String
|
||||||
|
*/
|
||||||
|
public String serialize()
|
||||||
|
{
|
||||||
|
StringBuilder str = new StringBuilder();
|
||||||
|
str.append(this.nickname).append(';');
|
||||||
|
str.append(this.realName).append(';');
|
||||||
|
str.append(this.ip).append(';');
|
||||||
|
str.append(this.email).append(';');
|
||||||
|
str.append(this.hash).append(';');
|
||||||
|
str.append(this.salt).append(';');
|
||||||
|
str.append(this.groupId).append(';');
|
||||||
|
str.append(this.lastLogin).append(';');
|
||||||
|
str.append(this.world).append(';');
|
||||||
|
str.append(this.x).append(';');
|
||||||
|
str.append(this.y).append(';');
|
||||||
|
str.append(this.z);
|
||||||
|
return str.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method to unserialize playerauth
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public void unserialize(String str)
|
||||||
|
{
|
||||||
|
String[] args = str.split(";");
|
||||||
|
this.nickname = args[0];
|
||||||
|
this.realName = args[1];
|
||||||
|
this.ip = args[2];
|
||||||
|
this.email = args[3];
|
||||||
|
this.hash = args[4];
|
||||||
|
this.salt = args[5];
|
||||||
|
this.groupId = Integer.parseInt(args[6]);
|
||||||
|
this.lastLogin = Long.parseLong(args[7]);
|
||||||
|
this.world = args[8];
|
||||||
|
this.x = Double.parseDouble(args[9]);
|
||||||
|
this.y = Double.parseDouble(args[10]);
|
||||||
|
this.z = Double.parseDouble(args[11]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,36 +2,22 @@ package fr.xephi.authme.cache.auth;
|
|||||||
|
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
public class PlayerCache {
|
public class PlayerCache {
|
||||||
|
|
||||||
private volatile static PlayerCache singleton = null;
|
private volatile static PlayerCache singleton;
|
||||||
private ConcurrentHashMap<String, PlayerAuth> cache;
|
private final ConcurrentHashMap<String, PlayerAuth> cache;
|
||||||
|
|
||||||
private PlayerCache() {
|
private PlayerCache() {
|
||||||
cache = new ConcurrentHashMap<>();
|
cache = new ConcurrentHashMap<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addPlayer(PlayerAuth auth) {
|
/**
|
||||||
cache.put(auth.getNickname().toLowerCase(), auth);
|
* Method getInstance.
|
||||||
}
|
*
|
||||||
|
* @return PlayerCache
|
||||||
public void updatePlayer(PlayerAuth auth) {
|
*/
|
||||||
cache.remove(auth.getNickname().toLowerCase());
|
|
||||||
cache.put(auth.getNickname().toLowerCase(), auth);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void removePlayer(String user) {
|
|
||||||
cache.remove(user.toLowerCase());
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isAuthenticated(String user) {
|
|
||||||
return cache.containsKey(user.toLowerCase());
|
|
||||||
}
|
|
||||||
|
|
||||||
public PlayerAuth getAuth(String user) {
|
|
||||||
return cache.get(user.toLowerCase());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static PlayerCache getInstance() {
|
public static PlayerCache getInstance() {
|
||||||
if (singleton == null) {
|
if (singleton == null) {
|
||||||
singleton = new PlayerCache();
|
singleton = new PlayerCache();
|
||||||
@ -39,10 +25,70 @@ public class PlayerCache {
|
|||||||
return singleton;
|
return singleton;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method addPlayer.
|
||||||
|
*
|
||||||
|
* @param auth PlayerAuth
|
||||||
|
*/
|
||||||
|
public void addPlayer(PlayerAuth auth) {
|
||||||
|
cache.put(auth.getNickname().toLowerCase(), auth);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method updatePlayer.
|
||||||
|
*
|
||||||
|
* @param auth PlayerAuth
|
||||||
|
*/
|
||||||
|
public void updatePlayer(PlayerAuth auth) {
|
||||||
|
cache.remove(auth.getNickname().toLowerCase());
|
||||||
|
cache.put(auth.getNickname().toLowerCase(), auth);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method removePlayer.
|
||||||
|
*
|
||||||
|
* @param user String
|
||||||
|
*/
|
||||||
|
public void removePlayer(String user) {
|
||||||
|
cache.remove(user.toLowerCase());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method isAuthenticated.
|
||||||
|
*
|
||||||
|
* @param user String
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public boolean isAuthenticated(String user) {
|
||||||
|
return cache.containsKey(user.toLowerCase());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method getAuth.
|
||||||
|
*
|
||||||
|
* @param user String
|
||||||
|
*
|
||||||
|
* @return PlayerAuth
|
||||||
|
*/
|
||||||
|
public PlayerAuth getAuth(String user) {
|
||||||
|
return cache.get(user.toLowerCase());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method getLogged.
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
public int getLogged() {
|
public int getLogged() {
|
||||||
return cache.size();
|
return cache.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method getCache.
|
||||||
|
*
|
||||||
|
* @return ConcurrentHashMap<String,PlayerAuth>
|
||||||
|
*/
|
||||||
public ConcurrentHashMap<String, PlayerAuth> getCache() {
|
public ConcurrentHashMap<String, PlayerAuth> getCache() {
|
||||||
return this.cache;
|
return this.cache;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,25 +1,49 @@
|
|||||||
package fr.xephi.authme.cache.backup;
|
package fr.xephi.authme.cache.backup;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
public class DataFileCache {
|
public class DataFileCache {
|
||||||
|
|
||||||
private String group;
|
private final String group;
|
||||||
private boolean operator;
|
private final boolean operator;
|
||||||
private boolean flying;
|
private final boolean flying;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for DataFileCache.
|
||||||
|
*
|
||||||
|
* @param group String
|
||||||
|
* @param operator boolean
|
||||||
|
* @param flying boolean
|
||||||
|
*/
|
||||||
public DataFileCache(String group, boolean operator, boolean flying) {
|
public DataFileCache(String group, boolean operator, boolean flying) {
|
||||||
this.group = group;
|
this.group = group;
|
||||||
this.operator = operator;
|
this.operator = operator;
|
||||||
this.flying = flying;
|
this.flying = flying;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method getGroup.
|
||||||
|
*
|
||||||
|
* @return String
|
||||||
|
*/
|
||||||
public String getGroup() {
|
public String getGroup() {
|
||||||
return group;
|
return group;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method getOperator.
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
public boolean getOperator() {
|
public boolean getOperator() {
|
||||||
return operator;
|
return operator;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method isFlying.
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
public boolean isFlying() {
|
public boolean isFlying() {
|
||||||
return flying;
|
return flying;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,27 +1,19 @@
|
|||||||
package fr.xephi.authme.cache.backup;
|
package fr.xephi.authme.cache.backup;
|
||||||
|
|
||||||
|
import com.google.common.base.Charsets;
|
||||||
|
import com.google.common.io.Files;
|
||||||
|
import com.google.gson.*;
|
||||||
|
import fr.xephi.authme.ConsoleLogger;
|
||||||
|
import fr.xephi.authme.settings.Settings;
|
||||||
|
import fr.xephi.authme.util.Utils;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
/**
|
||||||
|
*/
|
||||||
import com.google.common.base.Charsets;
|
|
||||||
import com.google.common.io.Files;
|
|
||||||
import com.google.gson.Gson;
|
|
||||||
import com.google.gson.GsonBuilder;
|
|
||||||
import com.google.gson.JsonDeserializationContext;
|
|
||||||
import com.google.gson.JsonDeserializer;
|
|
||||||
import com.google.gson.JsonElement;
|
|
||||||
import com.google.gson.JsonObject;
|
|
||||||
import com.google.gson.JsonParseException;
|
|
||||||
import com.google.gson.JsonSerializationContext;
|
|
||||||
import com.google.gson.JsonSerializer;
|
|
||||||
|
|
||||||
import fr.xephi.authme.ConsoleLogger;
|
|
||||||
import fr.xephi.authme.settings.Settings;
|
|
||||||
import fr.xephi.authme.util.Utils;
|
|
||||||
|
|
||||||
public class JsonCache {
|
public class JsonCache {
|
||||||
|
|
||||||
private final Gson gson;
|
private final Gson gson;
|
||||||
@ -33,12 +25,18 @@ public class JsonCache {
|
|||||||
ConsoleLogger.showError("Failed to create cache directory.");
|
ConsoleLogger.showError("Failed to create cache directory.");
|
||||||
}
|
}
|
||||||
gson = new GsonBuilder()
|
gson = new GsonBuilder()
|
||||||
.registerTypeAdapter(DataFileCache.class, new PlayerDataSerializer())
|
.registerTypeAdapter(DataFileCache.class, new PlayerDataSerializer())
|
||||||
.registerTypeAdapter(DataFileCache.class, new PlayerDataDeserializer())
|
.registerTypeAdapter(DataFileCache.class, new PlayerDataDeserializer())
|
||||||
.setPrettyPrinting()
|
.setPrettyPrinting()
|
||||||
.create();
|
.create();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method createCache.
|
||||||
|
*
|
||||||
|
* @param player Player
|
||||||
|
* @param playerData DataFileCache
|
||||||
|
*/
|
||||||
public void createCache(Player player, DataFileCache playerData) {
|
public void createCache(Player player, DataFileCache playerData) {
|
||||||
if (player == null) {
|
if (player == null) {
|
||||||
return;
|
return;
|
||||||
@ -68,6 +66,13 @@ public class JsonCache {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method readCache.
|
||||||
|
*
|
||||||
|
* @param player Player
|
||||||
|
*
|
||||||
|
* @return DataFileCache
|
||||||
|
*/
|
||||||
public DataFileCache readCache(Player player) {
|
public DataFileCache readCache(Player player) {
|
||||||
String path;
|
String path;
|
||||||
try {
|
try {
|
||||||
@ -90,19 +95,57 @@ public class JsonCache {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class PlayerDataSerializer implements JsonSerializer<DataFileCache> {
|
/**
|
||||||
@Override
|
* Method removeCache.
|
||||||
public JsonElement serialize(DataFileCache dataFileCache, Type type, JsonSerializationContext jsonSerializationContext) {
|
*
|
||||||
JsonObject jsonObject = new JsonObject();
|
* @param player Player
|
||||||
jsonObject.addProperty("group", dataFileCache.getGroup());
|
*/
|
||||||
jsonObject.addProperty("operator", dataFileCache.getOperator());
|
public void removeCache(Player player) {
|
||||||
jsonObject.addProperty("flying", dataFileCache.isFlying());
|
String path;
|
||||||
|
try {
|
||||||
return jsonObject;
|
path = player.getUniqueId().toString();
|
||||||
|
} catch (Exception | Error e) {
|
||||||
|
path = player.getName().toLowerCase();
|
||||||
|
}
|
||||||
|
File file = new File(cacheDir, path);
|
||||||
|
if (file.exists()) {
|
||||||
|
Utils.purgeDirectory(file);
|
||||||
|
if (!file.delete()) {
|
||||||
|
ConsoleLogger.showError("Failed to remove" + player.getName() + "cache.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method doesCacheExist.
|
||||||
|
*
|
||||||
|
* @param player Player
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public boolean doesCacheExist(Player player) {
|
||||||
|
String path;
|
||||||
|
try {
|
||||||
|
path = player.getUniqueId().toString();
|
||||||
|
} catch (Exception | Error e) {
|
||||||
|
path = player.getName().toLowerCase();
|
||||||
|
}
|
||||||
|
File file = new File(cacheDir, path + File.separator + "cache.json");
|
||||||
|
return file.exists();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
private static class PlayerDataDeserializer implements JsonDeserializer<DataFileCache> {
|
private static class PlayerDataDeserializer implements JsonDeserializer<DataFileCache> {
|
||||||
|
/**
|
||||||
|
* Method deserialize.
|
||||||
|
*
|
||||||
|
* @param jsonElement JsonElement
|
||||||
|
* @param type Type
|
||||||
|
* @param jsonDeserializationContext JsonDeserializationContext
|
||||||
|
*
|
||||||
|
* @return DataFileCache * @throws JsonParseException * @see com.google.gson.JsonDeserializer#deserialize(JsonElement, Type, JsonDeserializationContext)
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public DataFileCache deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
|
public DataFileCache deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
|
||||||
JsonObject jsonObject = jsonElement.getAsJsonObject();
|
JsonObject jsonObject = jsonElement.getAsJsonObject();
|
||||||
@ -128,31 +171,27 @@ public class JsonCache {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeCache(Player player) {
|
/**
|
||||||
String path;
|
*/
|
||||||
try {
|
private class PlayerDataSerializer implements JsonSerializer<DataFileCache> {
|
||||||
path = player.getUniqueId().toString();
|
/**
|
||||||
} catch (Exception | Error e) {
|
* Method serialize.
|
||||||
path = player.getName().toLowerCase();
|
*
|
||||||
}
|
* @param dataFileCache DataFileCache
|
||||||
File file = new File(cacheDir, path);
|
* @param type Type
|
||||||
if (file.exists()) {
|
* @param jsonSerializationContext JsonSerializationContext
|
||||||
Utils.purgeDirectory(file);
|
*
|
||||||
if (!file.delete()) {
|
* @return JsonElement
|
||||||
ConsoleLogger.showError("Failed to remove" + player.getName() + "cache.");
|
*/
|
||||||
}
|
@Override
|
||||||
}
|
public JsonElement serialize(DataFileCache dataFileCache, Type type, JsonSerializationContext jsonSerializationContext) {
|
||||||
}
|
JsonObject jsonObject = new JsonObject();
|
||||||
|
jsonObject.addProperty("group", dataFileCache.getGroup());
|
||||||
|
jsonObject.addProperty("operator", dataFileCache.getOperator());
|
||||||
|
jsonObject.addProperty("flying", dataFileCache.isFlying());
|
||||||
|
|
||||||
public boolean doesCacheExist(Player player) {
|
return jsonObject;
|
||||||
String path;
|
|
||||||
try {
|
|
||||||
path = player.getUniqueId().toString();
|
|
||||||
} catch (Exception | Error e) {
|
|
||||||
path = player.getName().toLowerCase();
|
|
||||||
}
|
}
|
||||||
File file = new File(cacheDir, path + File.separator + "cache.json");
|
|
||||||
return file.exists();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,33 +1,56 @@
|
|||||||
package fr.xephi.authme.cache.limbo;
|
package fr.xephi.authme.cache.limbo;
|
||||||
|
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.GameMode;
|
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import fr.xephi.authme.AuthMe;
|
import fr.xephi.authme.AuthMe;
|
||||||
import fr.xephi.authme.ConsoleLogger;
|
import fr.xephi.authme.ConsoleLogger;
|
||||||
import fr.xephi.authme.cache.backup.DataFileCache;
|
import fr.xephi.authme.cache.backup.DataFileCache;
|
||||||
import fr.xephi.authme.cache.backup.JsonCache;
|
import fr.xephi.authme.cache.backup.JsonCache;
|
||||||
import fr.xephi.authme.events.ResetInventoryEvent;
|
import fr.xephi.authme.events.ResetInventoryEvent;
|
||||||
import fr.xephi.authme.events.StoreInventoryEvent;
|
import fr.xephi.authme.permission.PermissionsManager;
|
||||||
import fr.xephi.authme.settings.Settings;
|
import fr.xephi.authme.settings.Settings;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.GameMode;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
public class LimboCache {
|
public class LimboCache {
|
||||||
|
|
||||||
private volatile static LimboCache singleton;
|
private volatile static LimboCache singleton;
|
||||||
public ConcurrentHashMap<String, LimboPlayer> cache;
|
public final ConcurrentHashMap<String, LimboPlayer> cache;
|
||||||
private JsonCache playerData;
|
public final AuthMe plugin;
|
||||||
public AuthMe plugin;
|
private final JsonCache playerData;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for LimboCache.
|
||||||
|
*
|
||||||
|
* @param plugin AuthMe
|
||||||
|
*/
|
||||||
private LimboCache(AuthMe plugin) {
|
private LimboCache(AuthMe plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
this.cache = new ConcurrentHashMap<>();
|
this.cache = new ConcurrentHashMap<>();
|
||||||
this.playerData = new JsonCache();
|
this.playerData = new JsonCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method getInstance.
|
||||||
|
*
|
||||||
|
* @return LimboCache
|
||||||
|
*/
|
||||||
|
public static LimboCache getInstance() {
|
||||||
|
if (singleton == null) {
|
||||||
|
singleton = new LimboCache(AuthMe.getInstance());
|
||||||
|
}
|
||||||
|
return singleton;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a limbo player.
|
||||||
|
*
|
||||||
|
* @param player Player instance to add.
|
||||||
|
*/
|
||||||
public void addLimboPlayer(Player player) {
|
public void addLimboPlayer(Player player) {
|
||||||
String name = player.getName().toLowerCase();
|
String name = player.getName().toLowerCase();
|
||||||
Location loc = player.getLocation();
|
Location loc = player.getLocation();
|
||||||
@ -36,14 +59,13 @@ public class LimboCache {
|
|||||||
String playerGroup = "";
|
String playerGroup = "";
|
||||||
boolean flying = false;
|
boolean flying = false;
|
||||||
|
|
||||||
if (playerData.doesCacheExist(player)) {
|
// Get the permissions manager, and make sure it's valid
|
||||||
final StoreInventoryEvent event = new StoreInventoryEvent(player, playerData);
|
PermissionsManager permsMan = this.plugin.getPermissionsManager();
|
||||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
if (permsMan == null)
|
||||||
if (!event.isCancelled() && event.getInventory() != null && event.getArmor() != null) {
|
ConsoleLogger.showError("Unable to access permissions manager!");
|
||||||
player.getInventory().setContents(event.getInventory());
|
assert permsMan != null;
|
||||||
player.getInventory().setArmorContents(event.getArmor());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (playerData.doesCacheExist(player)) {
|
||||||
DataFileCache cache = playerData.readCache(player);
|
DataFileCache cache = playerData.readCache(player);
|
||||||
if (cache != null) {
|
if (cache != null) {
|
||||||
playerGroup = cache.getGroup();
|
playerGroup = cache.getGroup();
|
||||||
@ -51,23 +73,12 @@ public class LimboCache {
|
|||||||
flying = cache.isFlying();
|
flying = cache.isFlying();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
StoreInventoryEvent event = new StoreInventoryEvent(player);
|
|
||||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
|
||||||
if (!event.isCancelled() && event.getInventory() != null && event.getArmor() != null) {
|
|
||||||
player.getInventory().setContents(event.getInventory());
|
|
||||||
player.getInventory().setArmorContents(event.getArmor());
|
|
||||||
}
|
|
||||||
|
|
||||||
operator = player.isOp();
|
operator = player.isOp();
|
||||||
flying = player.isFlying();
|
flying = player.isFlying();
|
||||||
if (plugin.permission != null) {
|
|
||||||
try {
|
// Check whether groups are supported
|
||||||
playerGroup = plugin.permission.getPrimaryGroup(player);
|
if (permsMan.hasGroupSupport())
|
||||||
} catch (UnsupportedOperationException e) {
|
playerGroup = permsMan.getPrimaryGroup(player);
|
||||||
ConsoleLogger.showError("Your permission system (" + plugin.permission.getName() + ") do not support Group system with that config... unhook!");
|
|
||||||
plugin.permission = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Settings.isForceSurvivalModeEnabled) {
|
if (Settings.isForceSurvivalModeEnabled) {
|
||||||
@ -90,29 +101,52 @@ public class LimboCache {
|
|||||||
cache.put(name, new LimboPlayer(name, loc, gameMode, operator, playerGroup, flying));
|
cache.put(name, new LimboPlayer(name, loc, gameMode, operator, playerGroup, flying));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method addLimboPlayer.
|
||||||
|
*
|
||||||
|
* @param player Player
|
||||||
|
* @param group String
|
||||||
|
*/
|
||||||
public void addLimboPlayer(Player player, String group) {
|
public void addLimboPlayer(Player player, String group) {
|
||||||
cache.put(player.getName().toLowerCase(), new LimboPlayer(player.getName().toLowerCase(), group));
|
cache.put(player.getName().toLowerCase(), new LimboPlayer(player.getName().toLowerCase(), group));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method deleteLimboPlayer.
|
||||||
|
*
|
||||||
|
* @param name String
|
||||||
|
*/
|
||||||
public void deleteLimboPlayer(String name) {
|
public void deleteLimboPlayer(String name) {
|
||||||
cache.remove(name);
|
cache.remove(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method getLimboPlayer.
|
||||||
|
*
|
||||||
|
* @param name String
|
||||||
|
*
|
||||||
|
* @return LimboPlayer
|
||||||
|
*/
|
||||||
public LimboPlayer getLimboPlayer(String name) {
|
public LimboPlayer getLimboPlayer(String name) {
|
||||||
return cache.get(name);
|
return cache.get(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method hasLimboPlayer.
|
||||||
|
*
|
||||||
|
* @param name String
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
public boolean hasLimboPlayer(String name) {
|
public boolean hasLimboPlayer(String name) {
|
||||||
return cache.containsKey(name);
|
return cache.containsKey(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static LimboCache getInstance() {
|
/**
|
||||||
if (singleton == null) {
|
* Method updateLimboPlayer.
|
||||||
singleton = new LimboCache(AuthMe.getInstance());
|
*
|
||||||
}
|
* @param player Player
|
||||||
return singleton;
|
*/
|
||||||
}
|
|
||||||
|
|
||||||
public void updateLimboPlayer(Player player) {
|
public void updateLimboPlayer(Player player) {
|
||||||
if (this.hasLimboPlayer(player.getName().toLowerCase())) {
|
if (this.hasLimboPlayer(player.getName().toLowerCase())) {
|
||||||
this.deleteLimboPlayer(player.getName().toLowerCase());
|
this.deleteLimboPlayer(player.getName().toLowerCase());
|
||||||
|
|||||||
@ -4,9 +4,11 @@ import org.bukkit.GameMode;
|
|||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.scheduler.BukkitTask;
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
public class LimboPlayer {
|
public class LimboPlayer {
|
||||||
|
|
||||||
private String name;
|
private final String name;
|
||||||
private Location loc = null;
|
private Location loc = null;
|
||||||
private BukkitTask timeoutTaskId = null;
|
private BukkitTask timeoutTaskId = null;
|
||||||
private BukkitTask messageTaskId = null;
|
private BukkitTask messageTaskId = null;
|
||||||
@ -15,8 +17,18 @@ public class LimboPlayer {
|
|||||||
private String group = "";
|
private String group = "";
|
||||||
private boolean flying = false;
|
private boolean flying = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for LimboPlayer.
|
||||||
|
*
|
||||||
|
* @param name String
|
||||||
|
* @param loc Location
|
||||||
|
* @param gameMode GameMode
|
||||||
|
* @param operator boolean
|
||||||
|
* @param group String
|
||||||
|
* @param flying boolean
|
||||||
|
*/
|
||||||
public LimboPlayer(String name, Location loc, GameMode gameMode,
|
public LimboPlayer(String name, Location loc, GameMode gameMode,
|
||||||
boolean operator, String group, boolean flying) {
|
boolean operator, String group, boolean flying) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.loc = loc;
|
this.loc = loc;
|
||||||
this.gameMode = gameMode;
|
this.gameMode = gameMode;
|
||||||
@ -25,51 +37,107 @@ public class LimboPlayer {
|
|||||||
this.flying = flying;
|
this.flying = flying;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for LimboPlayer.
|
||||||
|
*
|
||||||
|
* @param name String
|
||||||
|
* @param group String
|
||||||
|
*/
|
||||||
public LimboPlayer(String name, String group) {
|
public LimboPlayer(String name, String group) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.group = group;
|
this.group = group;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method getName.
|
||||||
|
*
|
||||||
|
* @return String
|
||||||
|
*/
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method getLoc.
|
||||||
|
*
|
||||||
|
* @return Location
|
||||||
|
*/
|
||||||
public Location getLoc() {
|
public Location getLoc() {
|
||||||
return loc;
|
return loc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method getGameMode.
|
||||||
|
*
|
||||||
|
* @return GameMode
|
||||||
|
*/
|
||||||
public GameMode getGameMode() {
|
public GameMode getGameMode() {
|
||||||
return gameMode;
|
return gameMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method getOperator.
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
public boolean getOperator() {
|
public boolean getOperator() {
|
||||||
return operator;
|
return operator;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method getGroup.
|
||||||
|
*
|
||||||
|
* @return String
|
||||||
|
*/
|
||||||
public String getGroup() {
|
public String getGroup() {
|
||||||
return group;
|
return group;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method getTimeoutTaskId.
|
||||||
|
*
|
||||||
|
* @return BukkitTask
|
||||||
|
*/
|
||||||
|
public BukkitTask getTimeoutTaskId() {
|
||||||
|
return timeoutTaskId;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method setTimeoutTaskId.
|
||||||
|
*
|
||||||
|
* @param i BukkitTask
|
||||||
|
*/
|
||||||
public void setTimeoutTaskId(BukkitTask i) {
|
public void setTimeoutTaskId(BukkitTask i) {
|
||||||
if (this.timeoutTaskId != null)
|
if (this.timeoutTaskId != null)
|
||||||
this.timeoutTaskId.cancel();
|
this.timeoutTaskId.cancel();
|
||||||
this.timeoutTaskId = i;
|
this.timeoutTaskId = i;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BukkitTask getTimeoutTaskId() {
|
/**
|
||||||
return timeoutTaskId;
|
* Method getMessageTaskId.
|
||||||
|
*
|
||||||
|
* @return BukkitTask
|
||||||
|
*/
|
||||||
|
public BukkitTask getMessageTaskId() {
|
||||||
|
return messageTaskId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method setMessageTaskId.
|
||||||
|
*
|
||||||
|
* @param messageTaskId BukkitTask
|
||||||
|
*/
|
||||||
public void setMessageTaskId(BukkitTask messageTaskId) {
|
public void setMessageTaskId(BukkitTask messageTaskId) {
|
||||||
if (this.messageTaskId != null)
|
if (this.messageTaskId != null)
|
||||||
this.messageTaskId.cancel();
|
this.messageTaskId.cancel();
|
||||||
this.messageTaskId = messageTaskId;
|
this.messageTaskId = messageTaskId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BukkitTask getMessageTaskId() {
|
/**
|
||||||
return messageTaskId;
|
* Method isFlying.
|
||||||
}
|
*
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
public boolean isFlying() {
|
public boolean isFlying() {
|
||||||
return flying;
|
return flying;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,37 +1,35 @@
|
|||||||
package fr.xephi.authme.command;
|
package fr.xephi.authme.command;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
public class CommandArgumentDescription {
|
public class CommandArgumentDescription {
|
||||||
|
|
||||||
// TODO: Allow argument to consist of infinite parts. <label ...>
|
// TODO: Allow argument to consist of infinite parts. <label ...>
|
||||||
|
|
||||||
/** Argument label. */
|
/**
|
||||||
|
* Argument label (one-word description of the argument).
|
||||||
|
*/
|
||||||
private String label;
|
private String label;
|
||||||
/** Argument description. */
|
/**
|
||||||
|
* Argument description.
|
||||||
|
*/
|
||||||
private String description;
|
private String description;
|
||||||
/** Defines whether the argument is optional. */
|
/**
|
||||||
private boolean optional = false;
|
* Defines whether the argument is optional.
|
||||||
|
*/
|
||||||
|
private boolean isOptional = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*
|
*
|
||||||
* @param label The argument label.
|
* @param label The argument label.
|
||||||
* @param description The argument description.
|
* @param description The argument description.
|
||||||
|
* @param isOptional True if the argument is optional, false otherwise.
|
||||||
*/
|
*/
|
||||||
public CommandArgumentDescription(String label, String description) {
|
public CommandArgumentDescription(String label, String description, boolean isOptional) {
|
||||||
this(label, description, false);
|
this.label = label;
|
||||||
}
|
this.description = description;
|
||||||
|
this.isOptional = isOptional;
|
||||||
/**
|
|
||||||
* 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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -43,15 +41,6 @@ public class CommandArgumentDescription {
|
|||||||
return this.label;
|
return this.label;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the argument label.
|
|
||||||
*
|
|
||||||
* @param label Argument label.
|
|
||||||
*/
|
|
||||||
public void setLabel(String label) {
|
|
||||||
this.label = label;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the argument description.
|
* Get the argument description.
|
||||||
*
|
*
|
||||||
@ -61,30 +50,13 @@ public class CommandArgumentDescription {
|
|||||||
return description;
|
return description;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the argument description.
|
|
||||||
*
|
|
||||||
* @param description Argument description.
|
|
||||||
*/
|
|
||||||
public void setDescription(String description) {
|
|
||||||
this.description = description;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check whether the argument is optional.
|
* Check whether the argument is optional.
|
||||||
*
|
*
|
||||||
* @return True if the argument is optional, false otherwise.
|
* @return True if the argument is optional, false otherwise.
|
||||||
*/
|
*/
|
||||||
public boolean isOptional() {
|
public boolean isOptional() {
|
||||||
return optional;
|
return isOptional;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Set whether the argument is optional.
|
|
||||||
*
|
|
||||||
* @param optional True if the argument is optional, false otherwise.
|
|
||||||
*/
|
|
||||||
public void setOptional(boolean optional) {
|
|
||||||
this.optional = optional;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,56 +1,72 @@
|
|||||||
package fr.xephi.authme.command;
|
package fr.xephi.authme.command;
|
||||||
|
|
||||||
|
import fr.xephi.authme.permission.PermissionNode;
|
||||||
|
import fr.xephi.authme.util.StringUtils;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.bukkit.command.CommandSender;
|
/**
|
||||||
|
* Command description - defines which labels ("names") will lead to a command and points to the
|
||||||
import fr.xephi.authme.util.StringUtils;
|
* {@link ExecutableCommand} implementation that executes the logic of the command.
|
||||||
|
*
|
||||||
|
* CommandDescription is built hierarchically and have one parent or {@code null} for base commands (main commands
|
||||||
|
* such as /authme) and may have multiple children extending the mapping of the parent: e.g. if /authme has a child
|
||||||
|
* whose label is "register", then "/authme register" is the command that the child defines.
|
||||||
|
*/
|
||||||
public class CommandDescription {
|
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.
|
* Defines the labels to execute the command. For example, if labels are "register" and "r" and the parent is
|
||||||
*
|
* the command for "/authme", then both "/authme register" and "/authme r" will be handled by this command.
|
||||||
* @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) {
|
private List<String> labels;
|
||||||
this(executableCommand, label, description, parent, detailedDescription, null);
|
/**
|
||||||
}
|
* Command description.
|
||||||
|
*/
|
||||||
|
private String description;
|
||||||
|
/**
|
||||||
|
* Detailed description of the command.
|
||||||
|
*/
|
||||||
|
private String detailedDescription;
|
||||||
|
/**
|
||||||
|
* The executable command instance.
|
||||||
|
*/
|
||||||
|
private ExecutableCommand executableCommand;
|
||||||
|
/**
|
||||||
|
* The parent command.
|
||||||
|
*/
|
||||||
|
private CommandDescription parent;
|
||||||
|
/**
|
||||||
|
* The child commands that extend this command.
|
||||||
|
*/
|
||||||
|
private List<CommandDescription> children = new ArrayList<>();
|
||||||
|
/**
|
||||||
|
* The arguments the command takes.
|
||||||
|
*/
|
||||||
|
private List<CommandArgumentDescription> arguments;
|
||||||
|
/**
|
||||||
|
* Defines whether there is an argument maximum or not.
|
||||||
|
*/
|
||||||
|
private boolean noArgumentMaximum;
|
||||||
|
/**
|
||||||
|
* Defines the command permissions.
|
||||||
|
*/
|
||||||
|
private CommandPermissions permissions;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*
|
*
|
||||||
* @param executableCommand The executable command, or null.
|
* @param executableCommand The executable command, or null.
|
||||||
* @param labels List of command labels.
|
* @param labels List of command labels.
|
||||||
* @param description Command description.
|
* @param description Command description.
|
||||||
* @param detailedDescription Detailed comment description.
|
* @param detailedDescription Detailed comment description.
|
||||||
* @param parent Parent command.
|
* @param parent Parent command.
|
||||||
*/
|
*/
|
||||||
public CommandDescription(ExecutableCommand executableCommand, List<String> labels, String description, String detailedDescription, CommandDescription parent) {
|
public CommandDescription(ExecutableCommand executableCommand, List<String> labels, String description, String detailedDescription, CommandDescription parent) {
|
||||||
this(executableCommand, labels, description, detailedDescription, parent, null);
|
this(executableCommand, labels, description, detailedDescription, parent, null);
|
||||||
@ -59,55 +75,70 @@ public class CommandDescription {
|
|||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*
|
*
|
||||||
* @param executableCommand The executable command, or null.
|
* @param executableCommand The executable command, or null.
|
||||||
* @param label Command label.
|
* @param labels List of command labels.
|
||||||
* @param description Command description.
|
* @param description Command description.
|
||||||
* @param parent Parent command.
|
|
||||||
* @param detailedDescription Detailed comment description.
|
* @param detailedDescription Detailed comment description.
|
||||||
* @param arguments Command arguments.
|
* @param parent Parent command.
|
||||||
*/
|
* @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) {
|
public CommandDescription(ExecutableCommand executableCommand, List<String> labels, String description, String detailedDescription, CommandDescription parent, List<CommandArgumentDescription> arguments) {
|
||||||
setExecutableCommand(executableCommand);
|
setExecutableCommand(executableCommand);
|
||||||
setLabels(labels);
|
this.labels = labels;
|
||||||
setDescription(description);
|
this.description = description;
|
||||||
setDetailedDescription(detailedDescription);
|
this.detailedDescription = detailedDescription;
|
||||||
setParent(parent);
|
setParent(parent);
|
||||||
setArguments(arguments);
|
setArguments(arguments);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the first relative command label.
|
* Private constructor. Use {@link CommandDescription#builder()} to create instances of this class.
|
||||||
*
|
*
|
||||||
* @return First relative command label.
|
* @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 String getLabel() {
|
private CommandDescription(List<String> labels, String description, String detailedDescription,
|
||||||
// Ensure there's any item in the command list
|
ExecutableCommand executableCommand, CommandDescription parent,
|
||||||
if(this.labels.size() == 0)
|
List<CommandArgumentDescription> arguments, boolean noArgumentMaximum,
|
||||||
return "";
|
CommandPermissions permissions) {
|
||||||
|
this.labels = labels;
|
||||||
|
this.description = description;
|
||||||
|
this.detailedDescription = detailedDescription;
|
||||||
|
this.executableCommand = executableCommand;
|
||||||
|
this.parent = parent;
|
||||||
|
this.arguments = arguments;
|
||||||
|
this.noArgumentMaximum = noArgumentMaximum;
|
||||||
|
this.permissions = permissions;
|
||||||
|
|
||||||
// Return the first command on the list
|
if (parent != null) {
|
||||||
return this.labels.get(0);
|
// Passing `this` in constructor is not very nice; consider creating a "static create()" method instead
|
||||||
|
parent.addChild(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check whether two labels are equal to each other.
|
||||||
|
*
|
||||||
|
* @param commandLabel The first command label.
|
||||||
|
* @param otherCommandLabel The other command label.
|
||||||
|
*
|
||||||
|
* @return True if the labels are equal to each other.
|
||||||
|
*/
|
||||||
|
private static boolean commandLabelEquals(String commandLabel, String otherCommandLabel) {
|
||||||
|
// Trim the command labels from unwanted whitespaces
|
||||||
|
commandLabel = commandLabel.trim();
|
||||||
|
otherCommandLabel = otherCommandLabel.trim();
|
||||||
|
|
||||||
|
// Check whether the the two command labels are equal (case insensitive)
|
||||||
|
return (commandLabel.equalsIgnoreCase(otherCommandLabel));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the label most similar to the reference. The first label will be returned if no reference was supplied.
|
* Get the label most similar to the reference. The first label will be returned if no reference was supplied.
|
||||||
*
|
*
|
||||||
@ -117,11 +148,11 @@ public class CommandDescription {
|
|||||||
*/
|
*/
|
||||||
public String getLabel(CommandParts reference) {
|
public String getLabel(CommandParts reference) {
|
||||||
// Ensure there's any item in the command list
|
// Ensure there's any item in the command list
|
||||||
if(this.labels.size() == 0)
|
if (this.labels.size() == 0)
|
||||||
return "";
|
return "";
|
||||||
|
|
||||||
// Return the first label if we can't use the reference
|
// Return the first label if we can't use the reference
|
||||||
if(reference == null)
|
if (reference == null)
|
||||||
return this.labels.get(0);
|
return this.labels.get(0);
|
||||||
|
|
||||||
// Get the correct label from the reference
|
// Get the correct label from the reference
|
||||||
@ -130,9 +161,9 @@ public class CommandDescription {
|
|||||||
// Check whether the preferred label is in the label list
|
// Check whether the preferred label is in the label list
|
||||||
double currentDifference = -1;
|
double currentDifference = -1;
|
||||||
String currentLabel = this.labels.get(0);
|
String currentLabel = this.labels.get(0);
|
||||||
for(String entry : this.labels) {
|
for (String entry : this.labels) {
|
||||||
double entryDifference = StringUtils.getDifference(entry, preferred);
|
double entryDifference = StringUtils.getDifference(entry, preferred);
|
||||||
if(entryDifference < currentDifference || currentDifference < 0) {
|
if (entryDifference < currentDifference || currentDifference < 0) {
|
||||||
currentDifference = entryDifference;
|
currentDifference = entryDifference;
|
||||||
currentLabel = entry;
|
currentLabel = entry;
|
||||||
}
|
}
|
||||||
@ -151,83 +182,6 @@ public class CommandDescription {
|
|||||||
return this.labels;
|
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.
|
* Check whether this command description has a specific command.
|
||||||
*
|
*
|
||||||
@ -237,29 +191,14 @@ public class CommandDescription {
|
|||||||
*/
|
*/
|
||||||
public boolean hasLabel(String commandLabel) {
|
public boolean hasLabel(String commandLabel) {
|
||||||
// Check whether any command matches with the argument
|
// Check whether any command matches with the argument
|
||||||
for(String entry : this.labels)
|
for (String entry : this.labels)
|
||||||
if(commandLabelEquals(entry, commandLabel))
|
if (commandLabelEquals(entry, commandLabel))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
// No match found, return false
|
// No match found, return false
|
||||||
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
|
* Check whether this command label is applicable with a command reference. This doesn't check if the parent
|
||||||
* are suitable too.
|
* are suitable too.
|
||||||
@ -270,7 +209,7 @@ public class CommandDescription {
|
|||||||
*/
|
*/
|
||||||
public boolean isSuitableLabel(CommandParts commandReference) {
|
public boolean isSuitableLabel(CommandParts commandReference) {
|
||||||
// Make sure the command reference is valid
|
// Make sure the command reference is valid
|
||||||
if(commandReference.getCount() <= 0)
|
if (commandReference.getCount() <= 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Get the parent count
|
// Get the parent count
|
||||||
@ -281,30 +220,9 @@ public class CommandDescription {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check whether a label is valid to use.
|
* Get the absolute command label, without a starting slash.
|
||||||
*
|
*
|
||||||
* @param label The label to test.
|
* @return The absolute label
|
||||||
*
|
|
||||||
* @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() {
|
public String getAbsoluteLabel() {
|
||||||
return getAbsoluteLabel(false);
|
return getAbsoluteLabel(false);
|
||||||
@ -313,6 +231,8 @@ public class CommandDescription {
|
|||||||
/**
|
/**
|
||||||
* Get the absolute command label.
|
* Get the absolute command label.
|
||||||
*
|
*
|
||||||
|
* @param includeSlash boolean
|
||||||
|
*
|
||||||
* @return Absolute command label.
|
* @return Absolute command label.
|
||||||
*/
|
*/
|
||||||
public String getAbsoluteLabel(boolean includeSlash) {
|
public String getAbsoluteLabel(boolean includeSlash) {
|
||||||
@ -322,12 +242,15 @@ public class CommandDescription {
|
|||||||
/**
|
/**
|
||||||
* Get the absolute command label.
|
* Get the absolute command label.
|
||||||
*
|
*
|
||||||
|
* @param includeSlash
|
||||||
|
* @param reference
|
||||||
|
*
|
||||||
* @return Absolute command label.
|
* @return Absolute command label.
|
||||||
*/
|
*/
|
||||||
public String getAbsoluteLabel(boolean includeSlash, CommandParts reference) {
|
public String getAbsoluteLabel(boolean includeSlash, CommandParts reference) {
|
||||||
// Get the command reference, and make sure it is valid
|
// Get the command reference, and make sure it is valid
|
||||||
CommandParts out = getCommandReference(reference);
|
CommandParts out = getCommandReference(reference);
|
||||||
if(out == null)
|
if (out == null)
|
||||||
return "";
|
return "";
|
||||||
|
|
||||||
// Return the result
|
// Return the result
|
||||||
@ -346,7 +269,7 @@ public class CommandDescription {
|
|||||||
List<String> referenceList = new ArrayList<>();
|
List<String> referenceList = new ArrayList<>();
|
||||||
|
|
||||||
// Check whether this command has a parent, if so, add the absolute parent command
|
// Check whether this command has a parent, if so, add the absolute parent command
|
||||||
if(getParent() != null)
|
if (getParent() != null)
|
||||||
referenceList.addAll(getParent().getCommandReference(reference).getList());
|
referenceList.addAll(getParent().getCommandReference(reference).getList());
|
||||||
|
|
||||||
// Get the current label
|
// Get the current label
|
||||||
@ -370,14 +293,14 @@ public class CommandDescription {
|
|||||||
/**
|
/**
|
||||||
* Get the difference between this command and another command reference.
|
* Get the difference between this command and another command reference.
|
||||||
*
|
*
|
||||||
* @param other The other command reference.
|
* @param other The other command reference.
|
||||||
* @param fullCompare True to fully compare both command references.
|
* @param fullCompare True to fully compare both command references.
|
||||||
*
|
*
|
||||||
* @return The command difference. Zero if there's no difference. A negative number on error.
|
* @return The command difference. Zero if there's no difference. A negative number on error.
|
||||||
*/
|
*/
|
||||||
public double getCommandDifference(CommandParts other, boolean fullCompare) {
|
public double getCommandDifference(CommandParts other, boolean fullCompare) {
|
||||||
// Make sure the reference is valid
|
// Make sure the reference is valid
|
||||||
if(other == null)
|
if (other == null)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
// Get the command reference
|
// Get the command reference
|
||||||
@ -417,7 +340,7 @@ public class CommandDescription {
|
|||||||
/**
|
/**
|
||||||
* Execute the command, if possible.
|
* Execute the command, if possible.
|
||||||
*
|
*
|
||||||
* @param sender The command sender that triggered the execution of this command.
|
* @param sender The command sender that triggered the execution of this command.
|
||||||
* @param commandReference The command reference.
|
* @param commandReference The command reference.
|
||||||
* @param commandArguments The command arguments.
|
* @param commandArguments The command arguments.
|
||||||
*
|
*
|
||||||
@ -425,7 +348,7 @@ public class CommandDescription {
|
|||||||
*/
|
*/
|
||||||
public boolean execute(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
public boolean execute(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
||||||
// Make sure the command is executable
|
// Make sure the command is executable
|
||||||
if(!isExecutable())
|
if (!isExecutable())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Execute the command, return the result
|
// Execute the command, return the result
|
||||||
@ -448,7 +371,7 @@ public class CommandDescription {
|
|||||||
*/
|
*/
|
||||||
public int getParentCount() {
|
public int getParentCount() {
|
||||||
// Check whether the this description has a parent
|
// Check whether the this description has a parent
|
||||||
if(!hasParent())
|
if (!hasParent())
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
// Get the parent count of the parent, return the result
|
// Get the parent count of the parent, return the result
|
||||||
@ -464,14 +387,14 @@ public class CommandDescription {
|
|||||||
*/
|
*/
|
||||||
public boolean setParent(CommandDescription parent) {
|
public boolean setParent(CommandDescription parent) {
|
||||||
// Make sure the parent is different
|
// Make sure the parent is different
|
||||||
if(this.parent == parent)
|
if (this.parent == parent)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
// Set the parent
|
// Set the parent
|
||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
|
|
||||||
// Make sure the parent isn't null
|
// Make sure the parent isn't null
|
||||||
if(parent == null)
|
if (parent == null)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
// Add this description as a child to the parent
|
// Add this description as a child to the parent
|
||||||
@ -505,43 +428,27 @@ public class CommandDescription {
|
|||||||
*/
|
*/
|
||||||
public boolean addChild(CommandDescription commandDescription) {
|
public boolean addChild(CommandDescription commandDescription) {
|
||||||
// Make sure the description is valid
|
// Make sure the description is valid
|
||||||
if(commandDescription == null)
|
if (commandDescription == null)
|
||||||
return false;
|
|
||||||
if(!commandDescription.isValid())
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Make sure the child doesn't exist already
|
// Make sure the child doesn't exist already
|
||||||
if(isChild(commandDescription))
|
if (isChild(commandDescription))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
// The command description to add as a child
|
// The command description to add as a child
|
||||||
if(!this.children.add(commandDescription))
|
if (!this.children.add(commandDescription))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Set this description as parent on the child
|
// Set this description as parent on the child
|
||||||
return commandDescription.setParent(this);
|
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.
|
* Check whether this command has any child labels.
|
||||||
*
|
*
|
||||||
* @return True if this command has any child labels.
|
* @return True if this command has any child labels.
|
||||||
*/
|
*/
|
||||||
public boolean hasChilds() {
|
public boolean hasChildren() {
|
||||||
return (this.children.size() != 0);
|
return (this.children.size() != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -554,9 +461,7 @@ public class CommandDescription {
|
|||||||
*/
|
*/
|
||||||
public boolean isChild(CommandDescription commandDescription) {
|
public boolean isChild(CommandDescription commandDescription) {
|
||||||
// Make sure the description is valid
|
// Make sure the description is valid
|
||||||
if(commandDescription == null)
|
if (commandDescription == null) // TODO: After builder, commandDescription == null -> never
|
||||||
return false;
|
|
||||||
if(!commandDescription.isValid())
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Check whether this child exists, return the result
|
// Check whether this child exists, return the result
|
||||||
@ -572,11 +477,11 @@ public class CommandDescription {
|
|||||||
*/
|
*/
|
||||||
public boolean addArgument(CommandArgumentDescription argument) {
|
public boolean addArgument(CommandArgumentDescription argument) {
|
||||||
// Make sure the argument is valid
|
// Make sure the argument is valid
|
||||||
if(argument == null)
|
if (argument == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Make sure the argument isn't added already
|
// Make sure the argument isn't added already
|
||||||
if(hasArgument(argument))
|
if (hasArgument(argument))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
// Add the argument, return the result
|
// Add the argument, return the result
|
||||||
@ -599,11 +504,14 @@ public class CommandDescription {
|
|||||||
*/
|
*/
|
||||||
public void setArguments(List<CommandArgumentDescription> arguments) {
|
public void setArguments(List<CommandArgumentDescription> arguments) {
|
||||||
// Convert null into an empty argument list
|
// Convert null into an empty argument list
|
||||||
if(arguments == null)
|
if (arguments == null) {
|
||||||
this.arguments.clear();
|
// Note ljacqu 20151128: Temporary workaround to avoid null pointer exception. Soon we won't need setters
|
||||||
|
// on the main class (-> complete instantiation via Builder)
|
||||||
else
|
// TODO Remove this method once unused
|
||||||
|
this.arguments = new ArrayList<>();
|
||||||
|
} else {
|
||||||
this.arguments = arguments;
|
this.arguments = arguments;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -614,12 +522,7 @@ public class CommandDescription {
|
|||||||
* @return True if this argument already exists, false otherwise.
|
* @return True if this argument already exists, false otherwise.
|
||||||
*/
|
*/
|
||||||
public boolean hasArgument(CommandArgumentDescription argument) {
|
public boolean hasArgument(CommandArgumentDescription argument) {
|
||||||
// Make sure the argument is valid
|
return argument != null && arguments.contains(argument);
|
||||||
if(argument == null)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
// Check whether the argument exists, return the result
|
|
||||||
return this.arguments.contains(argument);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -628,7 +531,7 @@ public class CommandDescription {
|
|||||||
* @return True if this command has any arguments.
|
* @return True if this command has any arguments.
|
||||||
*/
|
*/
|
||||||
public boolean hasArguments() {
|
public boolean hasArguments() {
|
||||||
return (this.arguments.size() != 0);
|
return !arguments.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -642,9 +545,9 @@ public class CommandDescription {
|
|||||||
int optionalArgument = 0;
|
int optionalArgument = 0;
|
||||||
|
|
||||||
// Loop through each argument
|
// Loop through each argument
|
||||||
for(CommandArgumentDescription argument : this.arguments) {
|
for (CommandArgumentDescription argument : this.arguments) {
|
||||||
// Check whether the command is optional
|
// Check whether the command is optional
|
||||||
if(!argument.isOptional()) {
|
if (!argument.isOptional()) {
|
||||||
requiredArguments += optionalArgument + 1;
|
requiredArguments += optionalArgument + 1;
|
||||||
optionalArgument = 0;
|
optionalArgument = 0;
|
||||||
|
|
||||||
@ -663,22 +566,14 @@ public class CommandDescription {
|
|||||||
*/
|
*/
|
||||||
public int getMaximumArguments() {
|
public int getMaximumArguments() {
|
||||||
// Check whether there is a maximum set
|
// Check whether there is a maximum set
|
||||||
if(this.noArgumentMaximum)
|
if (this.noArgumentMaximum)
|
||||||
|
// TODO ljacqu 20151128: Magic number
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
// Return the maximum based on the registered arguments
|
// Return the maximum based on the registered arguments
|
||||||
return this.arguments.size();
|
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.
|
* Get the command description.
|
||||||
*
|
*
|
||||||
@ -688,26 +583,13 @@ public class CommandDescription {
|
|||||||
return hasDescription() ? this.description : this.detailedDescription;
|
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.
|
* Check whether this command has any description.
|
||||||
*
|
*
|
||||||
* @return True if this command has any description.
|
* @return True if this command has any description.
|
||||||
*/
|
*/
|
||||||
public boolean hasDescription() {
|
public boolean hasDescription() {
|
||||||
return (this.description.trim().length() != 0);
|
return !StringUtils.isEmpty(description);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -716,29 +598,7 @@ public class CommandDescription {
|
|||||||
* @return Command detailed description.
|
* @return Command detailed description.
|
||||||
*/
|
*/
|
||||||
public String getDetailedDescription() {
|
public String getDetailedDescription() {
|
||||||
return hasDetailedDescription() ? this.detailedDescription : this.description;
|
return !StringUtils.isEmpty(detailedDescription) ? 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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -750,31 +610,31 @@ public class CommandDescription {
|
|||||||
*/
|
*/
|
||||||
public FoundCommandResult findCommand(final CommandParts queryReference) {
|
public FoundCommandResult findCommand(final CommandParts queryReference) {
|
||||||
// Make sure the command reference is valid
|
// Make sure the command reference is valid
|
||||||
if(queryReference.getCount() <= 0)
|
if (queryReference.getCount() <= 0)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
// Check whether this description is for the last element in the command reference, if so return the current command
|
// Check whether this description is for the last element in the command reference, if so return the current command
|
||||||
if(queryReference.getCount() <= getParentCount() + 1)
|
if (queryReference.getCount() <= getParentCount() + 1)
|
||||||
return new FoundCommandResult(
|
return new FoundCommandResult(
|
||||||
this,
|
this,
|
||||||
getCommandReference(queryReference),
|
getCommandReference(queryReference),
|
||||||
new CommandParts(),
|
new CommandParts(),
|
||||||
queryReference);
|
queryReference);
|
||||||
|
|
||||||
// Get the new command reference and arguments
|
// Get the new command reference and arguments
|
||||||
CommandParts newReference = new CommandParts(queryReference.getRange(0, getParentCount() + 1));
|
CommandParts newReference = new CommandParts(queryReference.getRange(0, getParentCount() + 1));
|
||||||
CommandParts newArguments = new CommandParts(queryReference.getRange(getParentCount() + 1));
|
CommandParts newArguments = new CommandParts(queryReference.getRange(getParentCount() + 1));
|
||||||
|
|
||||||
// Handle the child's, if this command has any
|
// Handle the child's, if this command has any
|
||||||
if(getChildren().size() > 0) {
|
if (getChildren().size() > 0) {
|
||||||
// Get a new instance of the child's list, and sort them by their difference in comparison to the query reference
|
// Get a new instance of the child's list, and sort them by their difference in comparison to the query reference
|
||||||
List<CommandDescription> commandChildren = new ArrayList<>(getChildren());
|
List<CommandDescription> commandChildren = new ArrayList<>(getChildren());
|
||||||
Collections.sort(commandChildren, new Comparator<CommandDescription>() {
|
Collections.sort(commandChildren, new Comparator<CommandDescription>() {
|
||||||
@Override
|
@Override
|
||||||
public int compare(CommandDescription o1, CommandDescription o2) {
|
public int compare(CommandDescription o1, CommandDescription o2) {
|
||||||
return Double.compare(
|
return Double.compare(
|
||||||
o1.getCommandDifference(queryReference),
|
o1.getCommandDifference(queryReference),
|
||||||
o2.getCommandDifference(queryReference));
|
o2.getCommandDifference(queryReference));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -782,21 +642,21 @@ public class CommandDescription {
|
|||||||
double firstChildDifference = commandChildren.get(0).getCommandDifference(queryReference, true);
|
double firstChildDifference = commandChildren.get(0).getCommandDifference(queryReference, true);
|
||||||
|
|
||||||
// Check if the reference perfectly suits the arguments of the current command if it doesn't perfectly suits a child command
|
// Check if the reference perfectly suits the arguments of the current command if it doesn't perfectly suits a child command
|
||||||
if(firstChildDifference > 0.0)
|
if (firstChildDifference > 0.0)
|
||||||
if(getSuitableArgumentsDifference(queryReference) == 0)
|
if (getSuitableArgumentsDifference(queryReference) == 0)
|
||||||
return new FoundCommandResult(this, newReference, newArguments, queryReference);
|
return new FoundCommandResult(this, newReference, newArguments, queryReference);
|
||||||
|
|
||||||
// Loop through each child
|
// Loop through each child
|
||||||
for(CommandDescription child : commandChildren) {
|
for (CommandDescription child : commandChildren) {
|
||||||
// Get the best suitable command
|
// Get the best suitable command
|
||||||
FoundCommandResult result = child.findCommand(queryReference);
|
FoundCommandResult result = child.findCommand(queryReference);
|
||||||
if(result != null)
|
if (result != null)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if the remaining command reference elements fit the arguments for this command
|
// Check if the remaining command reference elements fit the arguments for this command
|
||||||
if(getSuitableArgumentsDifference(queryReference) >= 0)
|
if (getSuitableArgumentsDifference(queryReference) >= 0)
|
||||||
return new FoundCommandResult(this, newReference, newArguments, queryReference);
|
return new FoundCommandResult(this, newReference, newArguments, queryReference);
|
||||||
|
|
||||||
// No command found, return null
|
// No command found, return null
|
||||||
@ -835,26 +695,29 @@ public class CommandDescription {
|
|||||||
*/
|
*/
|
||||||
public int getSuitableArgumentsDifference(CommandParts commandReference) {
|
public int getSuitableArgumentsDifference(CommandParts commandReference) {
|
||||||
// Make sure the command reference is valid
|
// Make sure the command reference is valid
|
||||||
if(commandReference.getCount() <= 0)
|
if (commandReference.getCount() <= 0) {
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
// Get the remaining command reference element count
|
// Get the remaining command reference element count
|
||||||
int remainingElementCount = commandReference.getCount() - getParentCount() - 1;
|
int remainingElementCount = commandReference.getCount() - getParentCount() - 1;
|
||||||
|
|
||||||
// Check if there are too less arguments
|
// Check if there are too few arguments
|
||||||
if(getMinimumArguments() > remainingElementCount)
|
if (getMinimumArguments() > remainingElementCount) {
|
||||||
return Math.abs(getMinimumArguments() - remainingElementCount);
|
return Math.abs(getMinimumArguments() - remainingElementCount);
|
||||||
|
}
|
||||||
|
|
||||||
// Check if there are too many arguments
|
// Check if there are too many arguments
|
||||||
if(getMaximumArguments() < remainingElementCount && getMaximumArguments() >= 0)
|
if (getMaximumArguments() < remainingElementCount && getMaximumArguments() >= 0) {
|
||||||
return Math.abs(remainingElementCount - getMaximumArguments());
|
return Math.abs(remainingElementCount - getMaximumArguments());
|
||||||
|
}
|
||||||
|
|
||||||
// The arguments seem to be EQUALS, return the result
|
// The arguments seem to be EQUALS, return the result
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the command permissions.
|
* Get the command permissions. Return null if the command doesn't require any permission.
|
||||||
*
|
*
|
||||||
* @return The command permissions.
|
* @return The command permissions.
|
||||||
*/
|
*/
|
||||||
@ -865,54 +728,117 @@ public class CommandDescription {
|
|||||||
/**
|
/**
|
||||||
* Set the command permissions.
|
* Set the command permissions.
|
||||||
*
|
*
|
||||||
* @param commandPermissions The command permissions.
|
* @param permissionNode The permission node required.
|
||||||
*/
|
|
||||||
public void setCommandPermissions(CommandPermissions commandPermissions) {
|
|
||||||
this.permissions = commandPermissions;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the command permissions.
|
|
||||||
*
|
|
||||||
* @param permissionNode The permission node required.
|
|
||||||
* @param defaultPermission The default permission.
|
* @param defaultPermission The default permission.
|
||||||
*/
|
*/
|
||||||
public void setCommandPermissions(String permissionNode, CommandPermissions.DefaultPermission defaultPermission) {
|
public void setCommandPermissions(PermissionNode permissionNode, CommandPermissions.DefaultPermission defaultPermission) {
|
||||||
this.permissions = new CommandPermissions(permissionNode, defaultPermission);
|
this.permissions = new CommandPermissions(permissionNode, defaultPermission);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public static Builder builder() {
|
||||||
* Check whether two labels equal to each other.
|
return new Builder();
|
||||||
*
|
|
||||||
* @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));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public static final class Builder {
|
||||||
* Check whether the command description has been set up properly.
|
private List<String> labels;
|
||||||
*
|
private String description;
|
||||||
* @return True if the command description is valid, false otherwise.
|
private String detailedDescription;
|
||||||
*/
|
private ExecutableCommand executableCommand;
|
||||||
public boolean isValid() {
|
private CommandDescription parent;
|
||||||
// Make sure any command label is set
|
private List<CommandArgumentDescription> arguments = new ArrayList<>();
|
||||||
if(getLabels().size() == 0)
|
private boolean noArgumentMaximum;
|
||||||
return false;
|
private CommandPermissions permissions;
|
||||||
|
|
||||||
// Make sure the permissions are set up properly
|
/**
|
||||||
if(this.permissions == null)
|
* Build a CommandDescription from the builder.
|
||||||
return false;
|
*
|
||||||
|
* @return The generated CommandDescription object
|
||||||
|
*/
|
||||||
|
public CommandDescription build() {
|
||||||
|
return new CommandDescription(
|
||||||
|
getOrThrow(labels, "labels"),
|
||||||
|
firstNonNull(description, ""),
|
||||||
|
firstNonNull(detailedDescription, ""),
|
||||||
|
getOrThrow(executableCommand, "executableCommand"),
|
||||||
|
firstNonNull(parent, null),
|
||||||
|
arguments,
|
||||||
|
noArgumentMaximum,
|
||||||
|
firstNonNull(permissions, null)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder labels(List<String> labels) {
|
||||||
|
this.labels = labels;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder labels(String... labels) {
|
||||||
|
return labels(asMutableList(labels));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder description(String description) {
|
||||||
|
this.description = description;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder detailedDescription(String detailedDescription) {
|
||||||
|
this.detailedDescription = detailedDescription;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder executableCommand(ExecutableCommand executableCommand) {
|
||||||
|
this.executableCommand = executableCommand;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder parent(CommandDescription parent) {
|
||||||
|
this.parent = parent;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder withArgument(String label, String description, boolean isOptional) {
|
||||||
|
arguments.add(new CommandArgumentDescription(label, description, isOptional));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder noArgumentMaximum(boolean noArgumentMaximum) {
|
||||||
|
this.noArgumentMaximum = noArgumentMaximum;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder permissions(CommandPermissions.DefaultPermission defaultPermission,
|
||||||
|
PermissionNode... permissionNodes) {
|
||||||
|
this.permissions = new CommandPermissions(asMutableList(permissionNodes), defaultPermission);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SafeVarargs
|
||||||
|
private static <T> List<T> asMutableList(T... items) {
|
||||||
|
return new ArrayList<>(Arrays.asList(items));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static <T> T firstNonNull(T first, T second) {
|
||||||
|
return first != null ? first : second;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static <T> T getOrThrow(T element, String elementName) {
|
||||||
|
if (!isEmpty(element)) {
|
||||||
|
return element;
|
||||||
|
}
|
||||||
|
throw new RuntimeException("The element '" + elementName + "' may not be empty in CommandDescription");
|
||||||
|
}
|
||||||
|
|
||||||
|
private static <T> boolean isEmpty(T element) {
|
||||||
|
if (element == null) {
|
||||||
|
return true;
|
||||||
|
} else if (element instanceof Collection<?>) {
|
||||||
|
return ((Collection<?>) element).isEmpty();
|
||||||
|
} else if (element instanceof String) {
|
||||||
|
return StringUtils.isEmpty((String) element);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// Everything seems to be correct, return the result
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,18 +1,21 @@
|
|||||||
package fr.xephi.authme.command;
|
package fr.xephi.authme.command;
|
||||||
|
|
||||||
|
import fr.xephi.authme.AuthMe;
|
||||||
|
import fr.xephi.authme.command.help.HelpProvider;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
/**
|
||||||
import org.bukkit.command.CommandSender;
|
*/
|
||||||
|
|
||||||
import fr.xephi.authme.AuthMe;
|
|
||||||
import fr.xephi.authme.command.help.HelpProvider;
|
|
||||||
|
|
||||||
public class CommandHandler {
|
public class CommandHandler {
|
||||||
|
|
||||||
/** The command manager instance. */
|
/**
|
||||||
|
* The command manager instance.
|
||||||
|
*/
|
||||||
private CommandManager commandManager;
|
private CommandManager commandManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -22,7 +25,7 @@ public class CommandHandler {
|
|||||||
*/
|
*/
|
||||||
public CommandHandler(boolean init) {
|
public CommandHandler(boolean init) {
|
||||||
// Initialize
|
// Initialize
|
||||||
if(init)
|
if (init)
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -34,7 +37,7 @@ public class CommandHandler {
|
|||||||
*/
|
*/
|
||||||
public boolean init() {
|
public boolean init() {
|
||||||
// Make sure the handler isn't initialized already
|
// Make sure the handler isn't initialized already
|
||||||
if(isInit())
|
if (isInit())
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
// Initialize the command manager
|
// Initialize the command manager
|
||||||
@ -62,7 +65,7 @@ public class CommandHandler {
|
|||||||
*/
|
*/
|
||||||
public boolean destroy() {
|
public boolean destroy() {
|
||||||
// Make sure the command handler is initialized
|
// Make sure the command handler is initialized
|
||||||
if(!isInit())
|
if (!isInit())
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
// Unset the command manager
|
// Unset the command manager
|
||||||
@ -82,10 +85,10 @@ public class CommandHandler {
|
|||||||
/**
|
/**
|
||||||
* Process a command.
|
* Process a command.
|
||||||
*
|
*
|
||||||
* @param sender The command sender (Bukkit).
|
* @param sender The command sender (Bukkit).
|
||||||
* @param bukkitCommand The command (Bukkit).
|
* @param bukkitCommand The command (Bukkit).
|
||||||
* @param bukkitCommandLabel The command label (Bukkit).
|
* @param bukkitCommandLabel The command label (Bukkit).
|
||||||
* @param bukkitArgs The command arguments (Bukkit).
|
* @param bukkitArgs The command arguments (Bukkit).
|
||||||
*
|
*
|
||||||
* @return True if the command was executed, false otherwise.
|
* @return True if the command was executed, false otherwise.
|
||||||
*/
|
*/
|
||||||
@ -95,13 +98,13 @@ public class CommandHandler {
|
|||||||
|
|
||||||
// Create a command reference, and make sure at least one command part is available
|
// Create a command reference, and make sure at least one command part is available
|
||||||
CommandParts commandReference = new CommandParts(bukkitCommandLabel, args);
|
CommandParts commandReference = new CommandParts(bukkitCommandLabel, args);
|
||||||
if(commandReference.getCount() == 0)
|
if (commandReference.getCount() == 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Get a suitable command for this reference, and make sure it isn't null
|
// Get a suitable command for this reference, and make sure it isn't null
|
||||||
FoundCommandResult result = this.commandManager.findCommand(commandReference);
|
FoundCommandResult result = this.commandManager.findCommand(commandReference);
|
||||||
if(result == null) {
|
if (result == null) {
|
||||||
sender.sendMessage(ChatColor.DARK_RED + "Failed to parse " + AuthMe.PLUGIN_NAME + " command!");
|
sender.sendMessage(ChatColor.DARK_RED + "Failed to parse " + AuthMe.getPluginName() + " command!");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -110,13 +113,13 @@ public class CommandHandler {
|
|||||||
|
|
||||||
// Make sure the difference between the command reference and the actual command isn't too big
|
// Make sure the difference between the command reference and the actual command isn't too big
|
||||||
final double commandDifference = result.getDifference();
|
final double commandDifference = result.getDifference();
|
||||||
if(commandDifference > 0.12) {
|
if (commandDifference > 0.12) {
|
||||||
// Show the unknown command warning
|
// Show the unknown command warning
|
||||||
sender.sendMessage(ChatColor.DARK_RED + "Unknown command!");
|
sender.sendMessage(ChatColor.DARK_RED + "Unknown command!");
|
||||||
|
|
||||||
// Show a command suggestion if available and the difference isn't too big
|
// Show a command suggestion if available and the difference isn't too big
|
||||||
if(commandDifference < 0.75)
|
if (commandDifference < 0.75)
|
||||||
if(result.getCommandDescription() != null)
|
if (result.getCommandDescription() != null)
|
||||||
sender.sendMessage(ChatColor.YELLOW + "Did you mean " + ChatColor.GOLD + "/" + result.getCommandDescription().getCommandReference(commandReference) + ChatColor.YELLOW + "?");
|
sender.sendMessage(ChatColor.YELLOW + "Did you mean " + ChatColor.GOLD + "/" + result.getCommandDescription().getCommandReference(commandReference) + ChatColor.YELLOW + "?");
|
||||||
|
|
||||||
// Show the help command
|
// Show the help command
|
||||||
@ -125,17 +128,17 @@ public class CommandHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Show a message when the command handler is assuming a command
|
// Show a message when the command handler is assuming a command
|
||||||
if(commandDifference > 0) {
|
if (commandDifference > 0) {
|
||||||
// Get the suggested command
|
// Get the suggested command
|
||||||
CommandParts suggestedCommandParts = new CommandParts(result.getCommandDescription().getCommandReference(commandReference));
|
CommandParts suggestedCommandParts = new CommandParts(result.getCommandDescription().getCommandReference(commandReference));
|
||||||
|
|
||||||
// Show the suggested command
|
// Show the suggested command
|
||||||
sender.sendMessage(ChatColor.DARK_RED + "Unknown command, assuming " + ChatColor.GOLD + "/" + suggestedCommandParts +
|
sender.sendMessage(ChatColor.DARK_RED + "Unknown command, assuming " + ChatColor.GOLD + "/" + suggestedCommandParts +
|
||||||
ChatColor.DARK_RED + "!");
|
ChatColor.DARK_RED + "!");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make sure the command is executable
|
// Make sure the command is executable
|
||||||
if(!result.isExecutable()) {
|
if (!result.isExecutable()) {
|
||||||
// Get the command reference
|
// Get the command reference
|
||||||
CommandParts helpCommandReference = new CommandParts(result.getCommandReference().getRange(1));
|
CommandParts helpCommandReference = new CommandParts(result.getCommandReference().getRange(1));
|
||||||
|
|
||||||
@ -148,14 +151,14 @@ public class CommandHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Make sure the command sender has permission
|
// Make sure the command sender has permission
|
||||||
if(!result.hasPermission(sender)) {
|
if (!result.hasPermission(sender)) {
|
||||||
// Show the no permissions warning
|
// Show the no permissions warning
|
||||||
sender.sendMessage(ChatColor.DARK_RED + "You don't have permission to use this command!");
|
sender.sendMessage(ChatColor.DARK_RED + "You don't have permission to use this command!");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make sure the command sender has permission
|
// Make sure the command sender has permission
|
||||||
if(!result.hasProperArguments()) {
|
if (!result.hasProperArguments()) {
|
||||||
// Get the command and the suggested command reference
|
// Get the command and the suggested command reference
|
||||||
CommandParts suggestedCommandReference = new CommandParts(result.getCommandDescription().getCommandReference(commandReference));
|
CommandParts suggestedCommandReference = new CommandParts(result.getCommandDescription().getCommandReference(commandReference));
|
||||||
CommandParts helpCommandReference = new CommandParts(suggestedCommandReference.getRange(1));
|
CommandParts helpCommandReference = new CommandParts(suggestedCommandReference.getRange(1));
|
||||||
@ -187,12 +190,12 @@ public class CommandHandler {
|
|||||||
List<String> arguments = new ArrayList<>(Arrays.asList(args));
|
List<String> arguments = new ArrayList<>(Arrays.asList(args));
|
||||||
|
|
||||||
/// Remove all empty arguments
|
/// Remove all empty arguments
|
||||||
for(int i = 0; i < arguments.size(); i++) {
|
for (int i = 0; i < arguments.size(); i++) {
|
||||||
// Get the argument value
|
// Get the argument value
|
||||||
final String arg = arguments.get(i);
|
final String arg = arguments.get(i);
|
||||||
|
|
||||||
// Check whether the argument value is empty
|
// Check whether the argument value is empty
|
||||||
if(arg.trim().length() == 0) {
|
if (arg.trim().length() == 0) {
|
||||||
// Remove the current argument
|
// Remove the current argument
|
||||||
arguments.remove(i);
|
arguments.remove(i);
|
||||||
|
|
||||||
|
|||||||
@ -1,29 +1,7 @@
|
|||||||
package fr.xephi.authme.command;
|
package fr.xephi.authme.command;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import fr.xephi.authme.command.executable.HelpCommand;
|
import fr.xephi.authme.command.executable.HelpCommand;
|
||||||
import fr.xephi.authme.command.executable.authme.AccountsCommand;
|
import fr.xephi.authme.command.executable.authme.*;
|
||||||
import fr.xephi.authme.command.executable.authme.AuthMeCommand;
|
|
||||||
import fr.xephi.authme.command.executable.authme.ChangePasswordCommand;
|
|
||||||
import fr.xephi.authme.command.executable.authme.FirstSpawnCommand;
|
|
||||||
import fr.xephi.authme.command.executable.authme.ForceLoginCommand;
|
|
||||||
import fr.xephi.authme.command.executable.authme.GetEmailCommand;
|
|
||||||
import fr.xephi.authme.command.executable.authme.GetIpCommand;
|
|
||||||
import fr.xephi.authme.command.executable.authme.LastLoginCommand;
|
|
||||||
import fr.xephi.authme.command.executable.authme.PurgeBannedPlayersCommand;
|
|
||||||
import fr.xephi.authme.command.executable.authme.PurgeCommand;
|
|
||||||
import fr.xephi.authme.command.executable.authme.PurgeLastPositionCommand;
|
|
||||||
import fr.xephi.authme.command.executable.authme.RegisterCommand;
|
|
||||||
import fr.xephi.authme.command.executable.authme.ReloadCommand;
|
|
||||||
import fr.xephi.authme.command.executable.authme.SetEmailCommand;
|
|
||||||
import fr.xephi.authme.command.executable.authme.SetFirstSpawnCommand;
|
|
||||||
import fr.xephi.authme.command.executable.authme.SetSpawnCommand;
|
|
||||||
import fr.xephi.authme.command.executable.authme.SpawnCommand;
|
|
||||||
import fr.xephi.authme.command.executable.authme.SwitchAntiBotCommand;
|
|
||||||
import fr.xephi.authme.command.executable.authme.UnregisterCommand;
|
|
||||||
import fr.xephi.authme.command.executable.authme.VersionCommand;
|
|
||||||
import fr.xephi.authme.command.executable.captcha.CaptchaCommand;
|
import fr.xephi.authme.command.executable.captcha.CaptchaCommand;
|
||||||
import fr.xephi.authme.command.executable.converter.ConverterCommand;
|
import fr.xephi.authme.command.executable.converter.ConverterCommand;
|
||||||
import fr.xephi.authme.command.executable.email.AddEmailCommand;
|
import fr.xephi.authme.command.executable.email.AddEmailCommand;
|
||||||
@ -31,17 +9,29 @@ import fr.xephi.authme.command.executable.email.ChangeEmailCommand;
|
|||||||
import fr.xephi.authme.command.executable.email.RecoverEmailCommand;
|
import fr.xephi.authme.command.executable.email.RecoverEmailCommand;
|
||||||
import fr.xephi.authme.command.executable.login.LoginCommand;
|
import fr.xephi.authme.command.executable.login.LoginCommand;
|
||||||
import fr.xephi.authme.command.executable.logout.LogoutCommand;
|
import fr.xephi.authme.command.executable.logout.LogoutCommand;
|
||||||
|
import fr.xephi.authme.permission.AdminPermission;
|
||||||
|
import fr.xephi.authme.permission.UserPermission;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static fr.xephi.authme.command.CommandPermissions.DefaultPermission.ALLOWED;
|
||||||
|
import static fr.xephi.authme.command.CommandPermissions.DefaultPermission.OP_ONLY;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
public class CommandManager {
|
public class CommandManager {
|
||||||
|
|
||||||
/** The list of commandDescriptions. */
|
/**
|
||||||
private List<CommandDescription> commandDescriptions = new ArrayList<>();
|
* The list of commandDescriptions.
|
||||||
|
*/
|
||||||
|
private final List<CommandDescription> commandDescriptions = new ArrayList<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*
|
*
|
||||||
* @param registerCommands
|
* @param registerCommands True to register the commands, false otherwise.
|
||||||
* True to register the commands, false otherwise.
|
|
||||||
*/
|
*/
|
||||||
public CommandManager(boolean registerCommands) {
|
public CommandManager(boolean registerCommands) {
|
||||||
// Register the commands
|
// Register the commands
|
||||||
@ -52,103 +42,97 @@ public class CommandManager {
|
|||||||
/**
|
/**
|
||||||
* Register all commands.
|
* Register all commands.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings({ "serial" })
|
|
||||||
public void registerCommands() {
|
public void registerCommands() {
|
||||||
// Register the base AuthMe Reloaded command
|
// Create a list of help command labels
|
||||||
CommandDescription authMeBaseCommand = new CommandDescription(new AuthMeCommand(), new ArrayList<String>() {
|
final List<String> helpCommandLabels = Arrays.asList("help", "hlp", "h", "sos", "?");
|
||||||
|
ExecutableCommand helpCommandExecutable = new HelpCommand();
|
||||||
|
|
||||||
{
|
// Register the base AuthMe Reloaded command
|
||||||
add("authme");
|
CommandDescription authMeBaseCommand = CommandDescription.builder()
|
||||||
}
|
.executableCommand(new AuthMeCommand())
|
||||||
}, "Main command", "The main AuthMeReloaded command. The root for all admin commands.", null);
|
.labels("authme")
|
||||||
|
.description("Main command")
|
||||||
|
.detailedDescription("The main AuthMeReloaded command. The root for all admin commands.")
|
||||||
|
.parent(null)
|
||||||
|
.build();
|
||||||
|
|
||||||
// Register the help command
|
// Register the help command
|
||||||
CommandDescription authMeHelpCommand = new CommandDescription(new HelpCommand(), new ArrayList<String>() {
|
CommandDescription authMeHelpCommand = CommandDescription.builder()
|
||||||
|
.executableCommand(helpCommandExecutable)
|
||||||
{
|
.labels(helpCommandLabels)
|
||||||
add("help");
|
.description("View help")
|
||||||
add("hlp");
|
.detailedDescription("View detailed help pages about AuthMeReloaded commands.")
|
||||||
add("h");
|
.parent(authMeBaseCommand)
|
||||||
add("sos");
|
.withArgument("query", "The command or query to view help for.", true)
|
||||||
add("?");
|
.build();
|
||||||
}
|
|
||||||
}, "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
|
// Register the register command
|
||||||
CommandDescription registerCommand = new CommandDescription(new RegisterCommand(), new ArrayList<String>() {
|
CommandDescription registerCommand = CommandDescription.builder()
|
||||||
|
.executableCommand(new RegisterCommand())
|
||||||
{
|
.labels("register", "reg", "r")
|
||||||
add("register");
|
.description("Register a player")
|
||||||
add("reg");
|
.detailedDescription("Register the specified player with the specified password.")
|
||||||
add("r");
|
.parent(authMeBaseCommand)
|
||||||
}
|
.permissions(OP_ONLY, UserPermission.REGISTER)
|
||||||
}, "Register a player", "Register the specified player with the specified password.", authMeBaseCommand);
|
.withArgument("player", "Player name", false)
|
||||||
registerCommand.setCommandPermissions("authme.admin.register", CommandPermissions.DefaultPermission.OP_ONLY);
|
.withArgument("password", "Password", false)
|
||||||
registerCommand.addArgument(new CommandArgumentDescription("player", "Player name", false));
|
.build();
|
||||||
registerCommand.addArgument(new CommandArgumentDescription("password", "Password", false));
|
|
||||||
|
|
||||||
// Register the unregister command
|
// Register the unregister command
|
||||||
CommandDescription unregisterCommand = new CommandDescription(new UnregisterCommand(), new ArrayList<String>() {
|
CommandDescription unregisterCommand = CommandDescription.builder()
|
||||||
|
.executableCommand(new UnregisterCommand())
|
||||||
{
|
.labels("unregister", "unreg", "unr")
|
||||||
add("unregister");
|
.description("Unregister a player")
|
||||||
add("unreg");
|
.detailedDescription("Unregister the specified player.")
|
||||||
add("unr");
|
.parent(authMeBaseCommand)
|
||||||
add("delete");
|
.permissions(OP_ONLY, UserPermission.UNREGISTER)
|
||||||
add("del");
|
.withArgument("player", "Player name", false)
|
||||||
}
|
.build();
|
||||||
}, "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
|
// Register the forcelogin command
|
||||||
CommandDescription forceLoginCommand = new CommandDescription(new ForceLoginCommand(), new ArrayList<String>() {
|
CommandDescription forceLoginCommand = CommandDescription.builder()
|
||||||
|
.executableCommand(new ForceLoginCommand())
|
||||||
{
|
.labels("forcelogin", "login")
|
||||||
add("forcelogin");
|
.description("Enforce login player")
|
||||||
add("login");
|
.detailedDescription("Enforce the specified player to login.")
|
||||||
}
|
.parent(authMeBaseCommand)
|
||||||
}, "Enforce login player", "Enforce the specified player to login.", authMeBaseCommand);
|
.permissions(OP_ONLY, UserPermission.CAN_LOGIN_BE_FORCED)
|
||||||
forceLoginCommand.setCommandPermissions("authme.admin.forcelogin", CommandPermissions.DefaultPermission.OP_ONLY);
|
.withArgument("player", "Online player name", true)
|
||||||
forceLoginCommand.addArgument(new CommandArgumentDescription("player", "Online player name", true));
|
.build();
|
||||||
|
|
||||||
// Register the changepassword command
|
// Register the changepassword command
|
||||||
CommandDescription changePasswordCommand = new CommandDescription(new ChangePasswordCommand(), new ArrayList<String>() {
|
CommandDescription changePasswordCommand = CommandDescription.builder()
|
||||||
|
.executableCommand(new ChangePasswordCommand())
|
||||||
|
.labels("password", "changepassword", "changepass", "cp")
|
||||||
|
.description("Change a player's password")
|
||||||
|
.detailedDescription("Change the password of a player.")
|
||||||
|
.parent(authMeBaseCommand)
|
||||||
|
.permissions(OP_ONLY, UserPermission.CHANGE_PASSWORD)
|
||||||
|
.withArgument("player", "Player name", false)
|
||||||
|
.withArgument("pwd", "New password", false)
|
||||||
|
.build();
|
||||||
|
|
||||||
{
|
// Register the last login command
|
||||||
add("password");
|
CommandDescription lastLoginCommand = CommandDescription.builder()
|
||||||
add("changepassword");
|
.executableCommand(new LastLoginCommand())
|
||||||
add("changepass");
|
.labels("lastlogin", "ll")
|
||||||
add("cp");
|
.description("Player's last login")
|
||||||
}
|
.detailedDescription("View the date of the specified players last login.")
|
||||||
}, "Change player's password", "Change the password of a player.", authMeBaseCommand);
|
.parent(authMeBaseCommand)
|
||||||
changePasswordCommand.setCommandPermissions("authme.admin.changepassword", CommandPermissions.DefaultPermission.OP_ONLY);
|
.permissions(OP_ONLY, AdminPermission.LAST_LOGIN)
|
||||||
changePasswordCommand.addArgument(new CommandArgumentDescription("player", "Player name", false));
|
.withArgument("player", "Player name", true)
|
||||||
changePasswordCommand.addArgument(new CommandArgumentDescription("pwd", "New password", false));
|
.build();
|
||||||
|
|
||||||
// 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
|
// Register the accounts command
|
||||||
CommandDescription accountsCommand = new CommandDescription(new AccountsCommand(), new ArrayList<String>() {
|
CommandDescription accountsCommand = CommandDescription.builder()
|
||||||
|
.executableCommand(new AccountsCommand())
|
||||||
{
|
.labels("accounts", "account")
|
||||||
add("accounts");
|
.description("Display player accounts")
|
||||||
add("account");
|
.detailedDescription("Display all accounts of a player by his player name or IP.")
|
||||||
}
|
.parent(authMeBaseCommand)
|
||||||
}, "Display player accounts", "Display all accounts of a player by it's player name or IP.", authMeBaseCommand);
|
.permissions(OP_ONLY, AdminPermission.ACCOUNTS)
|
||||||
accountsCommand.setCommandPermissions("authme.admin.accounts", CommandPermissions.DefaultPermission.OP_ONLY);
|
.withArgument("player", "Player name or IP", true)
|
||||||
accountsCommand.addArgument(new CommandArgumentDescription("player", "Player name or IP", true));
|
.build();
|
||||||
|
|
||||||
// Register the getemail command
|
// Register the getemail command
|
||||||
CommandDescription getEmailCommand = new CommandDescription(new GetEmailCommand(), new ArrayList<String>() {
|
CommandDescription getEmailCommand = new CommandDescription(new GetEmailCommand(), new ArrayList<String>() {
|
||||||
@ -160,7 +144,7 @@ public class CommandManager {
|
|||||||
add("mail");
|
add("mail");
|
||||||
}
|
}
|
||||||
}, "Display player's email", "Display the email address of the specified player if set.", authMeBaseCommand);
|
}, "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.setCommandPermissions(AdminPermission.GET_EMAIL, OP_ONLY);
|
||||||
getEmailCommand.addArgument(new CommandArgumentDescription("player", "Player name", true));
|
getEmailCommand.addArgument(new CommandArgumentDescription("player", "Player name", true));
|
||||||
|
|
||||||
// Register the setemail command
|
// Register the setemail command
|
||||||
@ -173,7 +157,7 @@ public class CommandManager {
|
|||||||
add("setmail");
|
add("setmail");
|
||||||
}
|
}
|
||||||
}, "Change player's email", "Change the email address of the specified player.", authMeBaseCommand);
|
}, "Change player's email", "Change the email address of the specified player.", authMeBaseCommand);
|
||||||
setEmailCommand.setCommandPermissions("authme.admin.chgemail", CommandPermissions.DefaultPermission.OP_ONLY);
|
setEmailCommand.setCommandPermissions(AdminPermission.CHANGE_EMAIL, OP_ONLY);
|
||||||
setEmailCommand.addArgument(new CommandArgumentDescription("player", "Player name", false));
|
setEmailCommand.addArgument(new CommandArgumentDescription("player", "Player name", false));
|
||||||
setEmailCommand.addArgument(new CommandArgumentDescription("email", "Player email", false));
|
setEmailCommand.addArgument(new CommandArgumentDescription("email", "Player email", false));
|
||||||
|
|
||||||
@ -185,7 +169,7 @@ public class CommandManager {
|
|||||||
add("ip");
|
add("ip");
|
||||||
}
|
}
|
||||||
}, "Get player's IP", "Get the IP address of the specified online player.", authMeBaseCommand);
|
}, "Get player's IP", "Get the IP address of the specified online player.", authMeBaseCommand);
|
||||||
getIpCommand.setCommandPermissions("authme.admin.getip", CommandPermissions.DefaultPermission.OP_ONLY);
|
getIpCommand.setCommandPermissions(AdminPermission.GET_IP, OP_ONLY);
|
||||||
getIpCommand.addArgument(new CommandArgumentDescription("player", "Online player name", true));
|
getIpCommand.addArgument(new CommandArgumentDescription("player", "Online player name", true));
|
||||||
|
|
||||||
// Register the spawn command
|
// Register the spawn command
|
||||||
@ -196,7 +180,7 @@ public class CommandManager {
|
|||||||
add("home");
|
add("home");
|
||||||
}
|
}
|
||||||
}, "Teleport to spawn", "Teleport to the spawn.", authMeBaseCommand);
|
}, "Teleport to spawn", "Teleport to the spawn.", authMeBaseCommand);
|
||||||
spawnCommand.setCommandPermissions("authme.admin.spawn", CommandPermissions.DefaultPermission.OP_ONLY);
|
spawnCommand.setCommandPermissions(AdminPermission.SPAWN, OP_ONLY);
|
||||||
|
|
||||||
// Register the setspawn command
|
// Register the setspawn command
|
||||||
CommandDescription setSpawnCommand = new CommandDescription(new SetSpawnCommand(), new ArrayList<String>() {
|
CommandDescription setSpawnCommand = new CommandDescription(new SetSpawnCommand(), new ArrayList<String>() {
|
||||||
@ -206,7 +190,7 @@ public class CommandManager {
|
|||||||
add("chgspawn");
|
add("chgspawn");
|
||||||
}
|
}
|
||||||
}, "Change the spawn", "Change the player's spawn to your current position.", authMeBaseCommand);
|
}, "Change the spawn", "Change the player's spawn to your current position.", authMeBaseCommand);
|
||||||
setSpawnCommand.setCommandPermissions("authme.admin.setspawn", CommandPermissions.DefaultPermission.OP_ONLY);
|
setSpawnCommand.setCommandPermissions(AdminPermission.SET_SPAWN, OP_ONLY);
|
||||||
|
|
||||||
// Register the firstspawn command
|
// Register the firstspawn command
|
||||||
CommandDescription firstSpawnCommand = new CommandDescription(new FirstSpawnCommand(), new ArrayList<String>() {
|
CommandDescription firstSpawnCommand = new CommandDescription(new FirstSpawnCommand(), new ArrayList<String>() {
|
||||||
@ -216,7 +200,7 @@ public class CommandManager {
|
|||||||
add("firsthome");
|
add("firsthome");
|
||||||
}
|
}
|
||||||
}, "Teleport to first spawn", "Teleport to the first spawn.", authMeBaseCommand);
|
}, "Teleport to first spawn", "Teleport to the first spawn.", authMeBaseCommand);
|
||||||
firstSpawnCommand.setCommandPermissions("authme.admin.firstspawn", CommandPermissions.DefaultPermission.OP_ONLY);
|
firstSpawnCommand.setCommandPermissions(AdminPermission.FIRST_SPAWN, OP_ONLY);
|
||||||
|
|
||||||
// Register the setfirstspawn command
|
// Register the setfirstspawn command
|
||||||
CommandDescription setFirstSpawnCommand = new CommandDescription(new SetFirstSpawnCommand(), new ArrayList<String>() {
|
CommandDescription setFirstSpawnCommand = new CommandDescription(new SetFirstSpawnCommand(), new ArrayList<String>() {
|
||||||
@ -226,7 +210,7 @@ public class CommandManager {
|
|||||||
add("chgfirstspawn");
|
add("chgfirstspawn");
|
||||||
}
|
}
|
||||||
}, "Change the first spawn", "Change the first player's spawn to your current position.", authMeBaseCommand);
|
}, "Change the first spawn", "Change the first player's spawn to your current position.", authMeBaseCommand);
|
||||||
setFirstSpawnCommand.setCommandPermissions("authme.admin.setfirstspawn", CommandPermissions.DefaultPermission.OP_ONLY);
|
setFirstSpawnCommand.setCommandPermissions(AdminPermission.SET_FIRST_SPAWN, OP_ONLY);
|
||||||
|
|
||||||
// Register the purge command
|
// Register the purge command
|
||||||
CommandDescription purgeCommand = new CommandDescription(new PurgeCommand(), new ArrayList<String>() {
|
CommandDescription purgeCommand = new CommandDescription(new PurgeCommand(), new ArrayList<String>() {
|
||||||
@ -236,7 +220,7 @@ public class CommandManager {
|
|||||||
add("delete");
|
add("delete");
|
||||||
}
|
}
|
||||||
}, "Purge old data", "Purge old AuthMeReloaded data longer than the specified amount of days ago.", authMeBaseCommand);
|
}, "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.setCommandPermissions(AdminPermission.PURGE, OP_ONLY);
|
||||||
purgeCommand.addArgument(new CommandArgumentDescription("days", "Number of days", false));
|
purgeCommand.addArgument(new CommandArgumentDescription("days", "Number of days", false));
|
||||||
|
|
||||||
// Register the purgelastposition command
|
// Register the purgelastposition command
|
||||||
@ -251,7 +235,7 @@ public class CommandManager {
|
|||||||
add("resetlastpos");
|
add("resetlastpos");
|
||||||
}
|
}
|
||||||
}, "Purge player's last position", "Purge the last know position of the specified player.", authMeBaseCommand);
|
}, "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.setCommandPermissions(AdminPermission.PURGE_LAST_POSITION, OP_ONLY);
|
||||||
purgeLastPositionCommand.addArgument(new CommandArgumentDescription("player", "Player name", true));
|
purgeLastPositionCommand.addArgument(new CommandArgumentDescription("player", "Player name", true));
|
||||||
|
|
||||||
// Register the purgebannedplayers command
|
// Register the purgebannedplayers command
|
||||||
@ -264,7 +248,7 @@ public class CommandManager {
|
|||||||
add("deletebannedplayer");
|
add("deletebannedplayer");
|
||||||
}
|
}
|
||||||
}, "Purge banned palyers data", "Purge all AuthMeReloaded data for banned players.", authMeBaseCommand);
|
}, "Purge banned palyers data", "Purge all AuthMeReloaded data for banned players.", authMeBaseCommand);
|
||||||
purgeBannedPlayersCommand.setCommandPermissions("authme.admin.purgebannedplayers", CommandPermissions.DefaultPermission.OP_ONLY);
|
purgeBannedPlayersCommand.setCommandPermissions(AdminPermission.PURGE_BANNED_PLAYERS, OP_ONLY);
|
||||||
|
|
||||||
// Register the switchantibot command
|
// Register the switchantibot command
|
||||||
CommandDescription switchAntiBotCommand = new CommandDescription(new SwitchAntiBotCommand(), new ArrayList<String>() {
|
CommandDescription switchAntiBotCommand = new CommandDescription(new SwitchAntiBotCommand(), new ArrayList<String>() {
|
||||||
@ -275,7 +259,7 @@ public class CommandManager {
|
|||||||
add("antibot");
|
add("antibot");
|
||||||
}
|
}
|
||||||
}, "Switch AntiBot mode", "Switch or toggle the AntiBot mode to the specified state.", authMeBaseCommand);
|
}, "Switch AntiBot mode", "Switch or toggle the AntiBot mode to the specified state.", authMeBaseCommand);
|
||||||
switchAntiBotCommand.setCommandPermissions("authme.admin.switchantibot", CommandPermissions.DefaultPermission.OP_ONLY);
|
switchAntiBotCommand.setCommandPermissions(AdminPermission.SWITCH_ANTIBOT, OP_ONLY);
|
||||||
switchAntiBotCommand.addArgument(new CommandArgumentDescription("mode", "ON / OFF", true));
|
switchAntiBotCommand.addArgument(new CommandArgumentDescription("mode", "ON / OFF", true));
|
||||||
|
|
||||||
// // Register the resetname command
|
// // Register the resetname command
|
||||||
@ -299,45 +283,33 @@ public class CommandManager {
|
|||||||
add("rld");
|
add("rld");
|
||||||
}
|
}
|
||||||
}, "Reload plugin", "Reload the AuthMeReloaded plugin.", authMeBaseCommand);
|
}, "Reload plugin", "Reload the AuthMeReloaded plugin.", authMeBaseCommand);
|
||||||
reloadCommand.setCommandPermissions("authme.admin.reload", CommandPermissions.DefaultPermission.OP_ONLY);
|
reloadCommand.setCommandPermissions(AdminPermission.RELOAD, OP_ONLY);
|
||||||
|
|
||||||
// Register the version command
|
// Register the version command
|
||||||
CommandDescription versionCommand = new CommandDescription(new VersionCommand(), new ArrayList<String>() {
|
CommandDescription versionCommand = CommandDescription.builder()
|
||||||
|
.executableCommand(new VersionCommand())
|
||||||
|
.labels("version", "ver", "v", "about", "info")
|
||||||
|
.description("Version info")
|
||||||
|
.detailedDescription("Show detailed information about the installed AuthMeReloaded version, and shows the "
|
||||||
|
+ "developers, contributors, license and other information.")
|
||||||
|
.parent(authMeBaseCommand)
|
||||||
|
.build();
|
||||||
|
|
||||||
{
|
// Register the base login command
|
||||||
add("version");
|
CommandDescription loginBaseCommand = CommandDescription.builder()
|
||||||
add("ver");
|
.executableCommand(new LoginCommand())
|
||||||
add("v");
|
.labels("login", "l")
|
||||||
add("about");
|
.description("Login command")
|
||||||
add("info");
|
.detailedDescription("Command to log in using AuthMeReloaded.")
|
||||||
}
|
.parent(null)
|
||||||
}, "Version info", "Show detailed information about the installed AuthMeReloaded version, and shows the developers, contributors, license and other information.", authMeBaseCommand);
|
.permissions(ALLOWED, UserPermission.LOGIN)
|
||||||
versionCommand.setMaximumArguments(false);
|
.withArgument("password", "Login password", false)
|
||||||
|
.build();
|
||||||
// Register the base Dungeon Maze command
|
|
||||||
CommandDescription loginBaseCommand = new CommandDescription(new LoginCommand(), new ArrayList<String>() {
|
|
||||||
|
|
||||||
{
|
|
||||||
add("login");
|
|
||||||
add("l");
|
|
||||||
}
|
|
||||||
}, "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
|
// Register the help command
|
||||||
CommandDescription loginHelpCommand = new CommandDescription(new HelpCommand(), new ArrayList<String>() {
|
CommandDescription loginHelpCommand = new CommandDescription(helpCommandExecutable, helpCommandLabels,
|
||||||
|
"View help", "View detailed help pages about AuthMeReloaded login commands.", loginBaseCommand);
|
||||||
{
|
|
||||||
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.addArgument(new CommandArgumentDescription("query", "The command or query to view help for.", true));
|
||||||
loginHelpCommand.setMaximumArguments(false);
|
|
||||||
|
|
||||||
// Register the base logout command
|
// Register the base logout command
|
||||||
CommandDescription logoutBaseCommand = new CommandDescription(new LogoutCommand(), new ArrayList<String>() {
|
CommandDescription logoutBaseCommand = new CommandDescription(new LogoutCommand(), new ArrayList<String>() {
|
||||||
@ -346,21 +318,12 @@ public class CommandManager {
|
|||||||
add("logout");
|
add("logout");
|
||||||
}
|
}
|
||||||
}, "Logout command", "Command to logout using AuthMeReloaded.", null);
|
}, "Logout command", "Command to logout using AuthMeReloaded.", null);
|
||||||
logoutBaseCommand.setCommandPermissions("authme.logout", CommandPermissions.DefaultPermission.ALLOWED);
|
logoutBaseCommand.setCommandPermissions(UserPermission.LOGOUT, CommandPermissions.DefaultPermission.ALLOWED);
|
||||||
|
|
||||||
// Register the help command
|
// Register the help command
|
||||||
CommandDescription logoutHelpCommand = new CommandDescription(new HelpCommand(), new ArrayList<String>() {
|
CommandDescription logoutHelpCommand = new CommandDescription(helpCommandExecutable, helpCommandLabels,
|
||||||
|
"View help", "View detailed help pages about AuthMeReloaded logout commands.", logoutBaseCommand);
|
||||||
{
|
|
||||||
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.addArgument(new CommandArgumentDescription("query", "The command or query to view help for.", true));
|
||||||
logoutHelpCommand.setMaximumArguments(false);
|
|
||||||
|
|
||||||
// Register the base register command
|
// Register the base register command
|
||||||
CommandDescription registerBaseCommand = new CommandDescription(new fr.xephi.authme.command.executable.register.RegisterCommand(), new ArrayList<String>() {
|
CommandDescription registerBaseCommand = new CommandDescription(new fr.xephi.authme.command.executable.register.RegisterCommand(), new ArrayList<String>() {
|
||||||
@ -370,24 +333,14 @@ public class CommandManager {
|
|||||||
add("reg");
|
add("reg");
|
||||||
}
|
}
|
||||||
}, "Registration command", "Command to register using AuthMeReloaded.", null);
|
}, "Registration command", "Command to register using AuthMeReloaded.", null);
|
||||||
registerBaseCommand.setCommandPermissions("authme.register", CommandPermissions.DefaultPermission.ALLOWED);
|
registerBaseCommand.setCommandPermissions(UserPermission.REGISTER, CommandPermissions.DefaultPermission.ALLOWED);
|
||||||
registerBaseCommand.addArgument(new CommandArgumentDescription("password", "Password", false));
|
registerBaseCommand.addArgument(new CommandArgumentDescription("password", "Password", false));
|
||||||
registerBaseCommand.addArgument(new CommandArgumentDescription("verifyPassword", "Verify password", false));
|
registerBaseCommand.addArgument(new CommandArgumentDescription("verifyPassword", "Verify password", false));
|
||||||
registerBaseCommand.setMaximumArguments(false);
|
|
||||||
|
|
||||||
// Register the help command
|
// Register the help command
|
||||||
CommandDescription registerHelpCommand = new CommandDescription(new HelpCommand(), new ArrayList<String>() {
|
CommandDescription registerHelpCommand = new CommandDescription(helpCommandExecutable, helpCommandLabels,
|
||||||
|
"View help", "View detailed help pages about AuthMeReloaded register commands.", registerBaseCommand);
|
||||||
{
|
|
||||||
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.addArgument(new CommandArgumentDescription("query", "The command or query to view help for.", true));
|
||||||
registerHelpCommand.setMaximumArguments(false);
|
|
||||||
|
|
||||||
// Register the base unregister command
|
// Register the base unregister command
|
||||||
CommandDescription unregisterBaseCommand = new CommandDescription(new fr.xephi.authme.command.executable.unregister.UnregisterCommand(), new ArrayList<String>() {
|
CommandDescription unregisterBaseCommand = new CommandDescription(new fr.xephi.authme.command.executable.unregister.UnregisterCommand(), new ArrayList<String>() {
|
||||||
@ -397,22 +350,12 @@ public class CommandManager {
|
|||||||
add("unreg");
|
add("unreg");
|
||||||
}
|
}
|
||||||
}, "Unregistration command", "Command to unregister using AuthMeReloaded.", null);
|
}, "Unregistration command", "Command to unregister using AuthMeReloaded.", null);
|
||||||
unregisterBaseCommand.setCommandPermissions("authme.unregister", CommandPermissions.DefaultPermission.ALLOWED);
|
unregisterBaseCommand.setCommandPermissions(UserPermission.UNREGISTER, CommandPermissions.DefaultPermission.ALLOWED);
|
||||||
unregisterBaseCommand.addArgument(new CommandArgumentDescription("password", "Password", false));
|
unregisterBaseCommand.addArgument(new CommandArgumentDescription("password", "Password", false));
|
||||||
|
|
||||||
// Register the help command
|
// Register the help command
|
||||||
CommandDescription unregisterHelpCommand = new CommandDescription(new HelpCommand(), new ArrayList<String>() {
|
CommandDescription unregisterHelpCommand = new CommandDescription(helpCommandExecutable, helpCommandLabels, "View help", "View detailed help pages about AuthMeReloaded unregister commands.", unregisterBaseCommand);
|
||||||
|
|
||||||
{
|
|
||||||
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.addArgument(new CommandArgumentDescription("query", "The command or query to view help for.", true));
|
||||||
unregisterHelpCommand.setMaximumArguments(false);
|
|
||||||
|
|
||||||
// Register the base changepassword command
|
// Register the base changepassword command
|
||||||
CommandDescription changePasswordBaseCommand = new CommandDescription(new fr.xephi.authme.command.executable.changepassword.ChangePasswordCommand(), new ArrayList<String>() {
|
CommandDescription changePasswordBaseCommand = new CommandDescription(new fr.xephi.authme.command.executable.changepassword.ChangePasswordCommand(), new ArrayList<String>() {
|
||||||
@ -422,27 +365,17 @@ public class CommandManager {
|
|||||||
add("changepass");
|
add("changepass");
|
||||||
}
|
}
|
||||||
}, "Change password command", "Command to change your password using AuthMeReloaded.", null);
|
}, "Change password command", "Command to change your password using AuthMeReloaded.", null);
|
||||||
changePasswordBaseCommand.setCommandPermissions("authme.changepassword", CommandPermissions.DefaultPermission.ALLOWED);
|
changePasswordBaseCommand.setCommandPermissions(UserPermission.CHANGE_PASSWORD, CommandPermissions.DefaultPermission.ALLOWED);
|
||||||
changePasswordBaseCommand.addArgument(new CommandArgumentDescription("password", "Password", false));
|
changePasswordBaseCommand.addArgument(new CommandArgumentDescription("password", "Password", false));
|
||||||
changePasswordBaseCommand.addArgument(new CommandArgumentDescription("verifyPassword", "Verify password", false));
|
changePasswordBaseCommand.addArgument(new CommandArgumentDescription("verifyPassword", "Verify password", false));
|
||||||
changePasswordBaseCommand.setMaximumArguments(false);
|
|
||||||
|
|
||||||
// Register the help command
|
// Register the help command
|
||||||
CommandDescription changePasswordHelpCommand = new CommandDescription(new HelpCommand(), new ArrayList<String>() {
|
CommandDescription changePasswordHelpCommand = new CommandDescription(helpCommandExecutable, helpCommandLabels,
|
||||||
|
"View help", "View detailed help pages about AuthMeReloaded change password commands.", changePasswordBaseCommand);
|
||||||
{
|
|
||||||
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.addArgument(new CommandArgumentDescription("query", "The command or query to view help for.", true));
|
||||||
changePasswordHelpCommand.setMaximumArguments(false);
|
|
||||||
|
|
||||||
// Register the base Dungeon Maze command
|
// Register the base Dungeon Maze command
|
||||||
CommandDescription emailBaseCommand = new CommandDescription(new HelpCommand(), new ArrayList<String>() {
|
CommandDescription emailBaseCommand = new CommandDescription(helpCommandExecutable, new ArrayList<String>() {
|
||||||
|
|
||||||
{
|
{
|
||||||
add("email");
|
add("email");
|
||||||
@ -451,18 +384,9 @@ public class CommandManager {
|
|||||||
}, "E-mail command", "The AuthMe Reloaded E-mail command. The root for all E-mail commands.", null);
|
}, "E-mail command", "The AuthMe Reloaded E-mail command. The root for all E-mail commands.", null);
|
||||||
|
|
||||||
// Register the help command
|
// Register the help command
|
||||||
CommandDescription emailHelpCommand = new CommandDescription(new HelpCommand(), new ArrayList<String>() {
|
CommandDescription emailHelpCommand = new CommandDescription(helpCommandExecutable, helpCommandLabels,
|
||||||
|
"View help", "View detailed help pages about AuthMeReloaded help commands.", emailBaseCommand);
|
||||||
{
|
|
||||||
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.addArgument(new CommandArgumentDescription("query", "The command or query to view help for.", true));
|
||||||
emailHelpCommand.setMaximumArguments(false);
|
|
||||||
|
|
||||||
// Register the add command
|
// Register the add command
|
||||||
CommandDescription addEmailCommand = new CommandDescription(new AddEmailCommand(), new ArrayList<String>() {
|
CommandDescription addEmailCommand = new CommandDescription(new AddEmailCommand(), new ArrayList<String>() {
|
||||||
@ -473,7 +397,7 @@ public class CommandManager {
|
|||||||
add("addmail");
|
add("addmail");
|
||||||
}
|
}
|
||||||
}, "Add E-mail", "Add an new E-Mail address to your account.", emailBaseCommand);
|
}, "Add E-mail", "Add an new E-Mail address to your account.", emailBaseCommand);
|
||||||
addEmailCommand.setCommandPermissions("authme.email.add", CommandPermissions.DefaultPermission.ALLOWED);
|
addEmailCommand.setCommandPermissions(UserPermission.ADD_EMAIL, CommandPermissions.DefaultPermission.ALLOWED);
|
||||||
addEmailCommand.addArgument(new CommandArgumentDescription("email", "Email address", false));
|
addEmailCommand.addArgument(new CommandArgumentDescription("email", "Email address", false));
|
||||||
addEmailCommand.addArgument(new CommandArgumentDescription("verifyEmail", "Email address verification", false));
|
addEmailCommand.addArgument(new CommandArgumentDescription("verifyEmail", "Email address verification", false));
|
||||||
|
|
||||||
@ -486,7 +410,7 @@ public class CommandManager {
|
|||||||
add("changemail");
|
add("changemail");
|
||||||
}
|
}
|
||||||
}, "Change E-mail", "Change an E-Mail address of your account.", emailBaseCommand);
|
}, "Change E-mail", "Change an E-Mail address of your account.", emailBaseCommand);
|
||||||
changeEmailCommand.setCommandPermissions("authme.email.change", CommandPermissions.DefaultPermission.ALLOWED);
|
changeEmailCommand.setCommandPermissions(UserPermission.CHANGE_EMAIL, CommandPermissions.DefaultPermission.ALLOWED);
|
||||||
changeEmailCommand.addArgument(new CommandArgumentDescription("oldEmail", "Old email address", false));
|
changeEmailCommand.addArgument(new CommandArgumentDescription("oldEmail", "Old email address", false));
|
||||||
changeEmailCommand.addArgument(new CommandArgumentDescription("newEmail", "New email address", false));
|
changeEmailCommand.addArgument(new CommandArgumentDescription("newEmail", "New email address", false));
|
||||||
|
|
||||||
@ -500,7 +424,7 @@ public class CommandManager {
|
|||||||
add("recovermail");
|
add("recovermail");
|
||||||
}
|
}
|
||||||
}, "Recover using E-mail", "Recover your account using an E-mail address.", emailBaseCommand);
|
}, "Recover using E-mail", "Recover your account using an E-mail address.", emailBaseCommand);
|
||||||
recoverEmailCommand.setCommandPermissions("authme.email.recover", CommandPermissions.DefaultPermission.ALLOWED);
|
recoverEmailCommand.setCommandPermissions(UserPermission.RECOVER_EMAIL, CommandPermissions.DefaultPermission.ALLOWED);
|
||||||
recoverEmailCommand.addArgument(new CommandArgumentDescription("email", "Email address", false));
|
recoverEmailCommand.addArgument(new CommandArgumentDescription("email", "Email address", false));
|
||||||
|
|
||||||
// Register the base captcha command
|
// Register the base captcha command
|
||||||
@ -511,23 +435,13 @@ public class CommandManager {
|
|||||||
add("capt");
|
add("capt");
|
||||||
}
|
}
|
||||||
}, "Captcha command", "Captcha command for AuthMeReloaded.", null);
|
}, "Captcha command", "Captcha command for AuthMeReloaded.", null);
|
||||||
captchaBaseCommand.setCommandPermissions("authme.captcha", CommandPermissions.DefaultPermission.ALLOWED);
|
captchaBaseCommand.setCommandPermissions(UserPermission.CAPTCHA, CommandPermissions.DefaultPermission.ALLOWED);
|
||||||
captchaBaseCommand.addArgument(new CommandArgumentDescription("captcha", "The captcha", false));
|
captchaBaseCommand.addArgument(new CommandArgumentDescription("captcha", "The captcha", false));
|
||||||
captchaBaseCommand.setMaximumArguments(false);
|
|
||||||
|
|
||||||
// Register the help command
|
// Register the help command
|
||||||
CommandDescription captchaHelpCommand = new CommandDescription(new HelpCommand(), new ArrayList<String>() {
|
CommandDescription captchaHelpCommand = new CommandDescription(helpCommandExecutable, helpCommandLabels,
|
||||||
|
"View help", "View detailed help pages about AuthMeReloaded change captcha commands.", captchaBaseCommand);
|
||||||
{
|
|
||||||
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.addArgument(new CommandArgumentDescription("query", "The command or query to view help for.", true));
|
||||||
captchaHelpCommand.setMaximumArguments(false);
|
|
||||||
|
|
||||||
// Register the base converter command
|
// Register the base converter command
|
||||||
CommandDescription converterBaseCommand = new CommandDescription(new ConverterCommand(), new ArrayList<String>() {
|
CommandDescription converterBaseCommand = new CommandDescription(new ConverterCommand(), new ArrayList<String>() {
|
||||||
@ -538,23 +452,13 @@ public class CommandManager {
|
|||||||
add("conv");
|
add("conv");
|
||||||
}
|
}
|
||||||
}, "Convert command", "Convert command for AuthMeReloaded.", null);
|
}, "Convert command", "Convert command for AuthMeReloaded.", null);
|
||||||
converterBaseCommand.setCommandPermissions("authme.converter", CommandPermissions.DefaultPermission.OP_ONLY);
|
converterBaseCommand.setCommandPermissions(UserPermission.CONVERTER, OP_ONLY);
|
||||||
converterBaseCommand.addArgument(new CommandArgumentDescription("job", "Conversion job: flattosql / flattosqlite /| xauth / crazylogin / rakamak / royalauth / vauth / sqltoflat", false));
|
converterBaseCommand.addArgument(new CommandArgumentDescription("job", "Conversion job: flattosql / flattosqlite /| xauth / crazylogin / rakamak / royalauth / vauth / sqltoflat", false));
|
||||||
converterBaseCommand.setMaximumArguments(false);
|
|
||||||
|
|
||||||
// Register the help command
|
// Register the help command
|
||||||
CommandDescription converterHelpCommand = new CommandDescription(new HelpCommand(), new ArrayList<String>() {
|
CommandDescription converterHelpCommand = new CommandDescription(helpCommandExecutable, helpCommandLabels,
|
||||||
|
"View help", "View detailed help pages about AuthMeReloaded change captcha commands.", converterBaseCommand);
|
||||||
{
|
|
||||||
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.addArgument(new CommandArgumentDescription("query", "The command or query to view help for.", true));
|
||||||
converterHelpCommand.setMaximumArguments(false);
|
|
||||||
|
|
||||||
// Add the base commands to the commands array
|
// Add the base commands to the commands array
|
||||||
this.commandDescriptions.add(authMeBaseCommand);
|
this.commandDescriptions.add(authMeBaseCommand);
|
||||||
@ -589,8 +493,7 @@ public class CommandManager {
|
|||||||
/**
|
/**
|
||||||
* Find the best suitable command for the specified reference.
|
* Find the best suitable command for the specified reference.
|
||||||
*
|
*
|
||||||
* @param queryReference
|
* @param queryReference The query reference to find a command for.
|
||||||
* The query reference to find a command for.
|
|
||||||
*
|
*
|
||||||
* @return The command found, or null.
|
* @return The command found, or null.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -1,20 +1,24 @@
|
|||||||
package fr.xephi.authme.command;
|
package fr.xephi.authme.command;
|
||||||
|
|
||||||
|
import fr.xephi.authme.util.StringUtils;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import fr.xephi.authme.util.ListUtils;
|
/**
|
||||||
import fr.xephi.authme.util.StringUtils;
|
*/
|
||||||
|
|
||||||
public class CommandParts {
|
public class CommandParts {
|
||||||
|
|
||||||
/** The list of parts for this command. */
|
/**
|
||||||
private List<String> parts = new ArrayList<>();
|
* The list of parts for this command.
|
||||||
|
*/
|
||||||
|
private final List<String> parts = new ArrayList<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*/
|
*/
|
||||||
public CommandParts() { }
|
public CommandParts() {
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
@ -46,7 +50,7 @@ public class CommandParts {
|
|||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*
|
*
|
||||||
* @param base The base part.
|
* @param base The base part.
|
||||||
* @param parts The list of additional parts.
|
* @param parts The list of additional parts.
|
||||||
*/
|
*/
|
||||||
public CommandParts(String base, List<String> parts) {
|
public CommandParts(String base, List<String> parts) {
|
||||||
@ -93,7 +97,7 @@ public class CommandParts {
|
|||||||
* @return The result.
|
* @return The result.
|
||||||
*/
|
*/
|
||||||
public boolean add(String[] parts) {
|
public boolean add(String[] parts) {
|
||||||
for(String entry : parts)
|
for (String entry : parts)
|
||||||
add(entry);
|
add(entry);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -116,7 +120,7 @@ public class CommandParts {
|
|||||||
*/
|
*/
|
||||||
public String get(int i) {
|
public String get(int i) {
|
||||||
// Make sure the index is in-bound
|
// Make sure the index is in-bound
|
||||||
if(i < 0 || i >= getCount())
|
if (i < 0 || i >= getCount())
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
// Get and return the argument
|
// Get and return the argument
|
||||||
@ -147,10 +151,10 @@ public class CommandParts {
|
|||||||
List<String> elements = new ArrayList<>();
|
List<String> elements = new ArrayList<>();
|
||||||
|
|
||||||
// Get the range
|
// Get the range
|
||||||
for(int i = start; i < start + count; i++) {
|
for (int i = start; i < start + count; i++) {
|
||||||
// Get the part and add it if it's valid
|
// Get the part and add it if it's valid
|
||||||
String element = get(i);
|
String element = get(i);
|
||||||
if(element != null)
|
if (element != null)
|
||||||
elements.add(element);
|
elements.add(element);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -172,21 +176,21 @@ public class CommandParts {
|
|||||||
/**
|
/**
|
||||||
* Get the difference value between two references.
|
* Get the difference value between two references.
|
||||||
*
|
*
|
||||||
* @param other The other reference.
|
* @param other The other reference.
|
||||||
* @param fullCompare True to compare the full references as far as the range reaches.
|
* @param fullCompare True to compare the full references as far as the range reaches.
|
||||||
*
|
*
|
||||||
* @return The result from zero to above. A negative number will be returned on error.
|
* @return The result from zero to above. A negative number will be returned on error.
|
||||||
*/
|
*/
|
||||||
public double getDifference(CommandParts other, boolean fullCompare) {
|
public double getDifference(CommandParts other, boolean fullCompare) {
|
||||||
// Make sure the other reference is correct
|
// Make sure the other reference is correct
|
||||||
if(other == null)
|
if (other == null)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
// Get the range to use
|
// Get the range to use
|
||||||
int range = Math.min(this.getCount(), other.getCount());
|
int range = Math.min(this.getCount(), other.getCount());
|
||||||
|
|
||||||
// Get and the difference
|
// Get and the difference
|
||||||
if(fullCompare)
|
if (fullCompare)
|
||||||
return StringUtils.getDifference(this.toString(), other.toString());
|
return StringUtils.getDifference(this.toString(), other.toString());
|
||||||
return StringUtils.getDifference(this.getRange(range - 1, 1).toString(), other.getRange(range - 1, 1).toString());
|
return StringUtils.getDifference(this.getRange(range - 1, 1).toString(), other.getRange(range - 1, 1).toString());
|
||||||
}
|
}
|
||||||
@ -198,6 +202,6 @@ public class CommandParts {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return ListUtils.implode(this.parts, " ");
|
return StringUtils.join(" ", this.parts);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,34 +1,35 @@
|
|||||||
package fr.xephi.authme.command;
|
package fr.xephi.authme.command;
|
||||||
|
|
||||||
|
import fr.xephi.authme.AuthMe;
|
||||||
|
import fr.xephi.authme.permission.PermissionsManager;
|
||||||
|
import fr.xephi.authme.permission.PermissionNode;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
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 {
|
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.
|
* Defines the permission nodes required to have permission to execute this command.
|
||||||
*/
|
*/
|
||||||
public CommandPermissions() { }
|
private List<PermissionNode> permissionNodes;
|
||||||
|
/**
|
||||||
|
* Defines the default permission if the permission nodes couldn't be used.
|
||||||
|
*/
|
||||||
|
private DefaultPermission defaultPermission;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*
|
*
|
||||||
* @param permissionNode The permission node required to execute a command.
|
* @param permissionNode The permission node required to execute a command.
|
||||||
* @param defaultPermission The default permission if the permission nodes couldn't be used.
|
* @param defaultPermission The default permission if the permission nodes couldn't be used.
|
||||||
*/
|
*/
|
||||||
public CommandPermissions(String permissionNode, DefaultPermission defaultPermission) {
|
public CommandPermissions(PermissionNode permissionNode, DefaultPermission defaultPermission) {
|
||||||
|
this.permissionNodes = new ArrayList<>();
|
||||||
this.permissionNodes.add(permissionNode);
|
this.permissionNodes.add(permissionNode);
|
||||||
this.defaultPermission = defaultPermission;
|
this.defaultPermission = defaultPermission;
|
||||||
}
|
}
|
||||||
@ -36,45 +37,12 @@ public class CommandPermissions {
|
|||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*
|
*
|
||||||
* @param permissionNodes The permission nodes required to execute a command.
|
* @param permissionNodes The permission nodes required to execute a command.
|
||||||
* @param defaultPermission The default permission if the permission nodes couldn't be used.
|
* @param defaultPermission The default permission if the permission nodes couldn't be used.
|
||||||
*/
|
*/
|
||||||
public CommandPermissions(List<String> permissionNodes, DefaultPermission defaultPermission) {
|
public CommandPermissions(List<PermissionNode> permissionNodes, DefaultPermission defaultPermission) {
|
||||||
this.permissionNodes.addAll(permissionNodes);
|
this.permissionNodes = permissionNodes;
|
||||||
}
|
this.defaultPermission = defaultPermission;
|
||||||
|
|
||||||
/**
|
|
||||||
* 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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -82,10 +50,11 @@ public class CommandPermissions {
|
|||||||
*
|
*
|
||||||
* @return The permission nodes required to execute this command.
|
* @return The permission nodes required to execute this command.
|
||||||
*/
|
*/
|
||||||
public List<String> getPermissionNodes() {
|
public List<PermissionNode> getPermissionNodes() {
|
||||||
return this.permissionNodes;
|
return this.permissionNodes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the number of permission nodes set.
|
* Get the number of permission nodes set.
|
||||||
*
|
*
|
||||||
@ -95,44 +64,39 @@ public class CommandPermissions {
|
|||||||
return this.permissionNodes.size();
|
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.
|
* Check whether this command requires any permission to be executed. This is based on the getPermission() method.
|
||||||
*
|
*
|
||||||
|
* @param sender CommandSender
|
||||||
|
*
|
||||||
* @return True if this command requires any permission to be executed by a player.
|
* @return True if this command requires any permission to be executed by a player.
|
||||||
*/
|
*/
|
||||||
public boolean hasPermission(CommandSender sender) {
|
public boolean hasPermission(CommandSender sender) {
|
||||||
// Make sure any permission node is set
|
// Make sure any permission node is set
|
||||||
if(getPermissionNodeCount() == 0)
|
if (getPermissionNodeCount() == 0)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
// Get the default permission
|
// Get the default permission
|
||||||
final boolean defaultPermission = getDefaultPermissionCommandSender(sender);
|
final boolean defaultPermission = getDefaultPermissionCommandSender(sender);
|
||||||
|
|
||||||
// Make sure the command sender is a player, if not use the default
|
// Make sure the command sender is a player, if not use the default
|
||||||
if(!(sender instanceof Player))
|
if (!(sender instanceof Player))
|
||||||
return defaultPermission;
|
return defaultPermission;
|
||||||
|
|
||||||
// Get the player instance
|
// Get the player instance
|
||||||
Player player = (Player) sender;
|
Player player = (Player) sender;
|
||||||
|
|
||||||
// // Get the permissions manager, and make sure it's instance is valid
|
// Get the permissions manager, and make sure it's instance is valid
|
||||||
// PermissionsManager permissionsManager = Core.getPermissionsManager();
|
PermissionsManager permissionsManager = AuthMe.getInstance().getPermissionsManager();
|
||||||
// if(permissionsManager == null)
|
if (permissionsManager == null)
|
||||||
// return false;
|
return false;
|
||||||
|
|
||||||
// Check whether the player has permission, return the result
|
// Check whether the player has permission, return the result
|
||||||
for(String node : this.permissionNodes)
|
for (PermissionNode node : this.permissionNodes) {
|
||||||
if(!AuthMe.getInstance().authmePermissible(player, node))
|
if (!permissionsManager.hasPermission(player, node, defaultPermission)) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -162,19 +126,21 @@ public class CommandPermissions {
|
|||||||
* @return True if the command sender has permission by default, false otherwise.
|
* @return True if the command sender has permission by default, false otherwise.
|
||||||
*/
|
*/
|
||||||
public boolean getDefaultPermissionCommandSender(CommandSender sender) {
|
public boolean getDefaultPermissionCommandSender(CommandSender sender) {
|
||||||
switch(getDefaultPermission()) {
|
switch (getDefaultPermission()) {
|
||||||
case ALLOWED:
|
case ALLOWED:
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
case OP_ONLY:
|
case OP_ONLY:
|
||||||
return sender.isOp();
|
return sender.isOp();
|
||||||
|
|
||||||
case NOT_ALLOWED:
|
case NOT_ALLOWED:
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
public enum DefaultPermission {
|
public enum DefaultPermission {
|
||||||
NOT_ALLOWED,
|
NOT_ALLOWED,
|
||||||
OP_ONLY,
|
OP_ONLY,
|
||||||
|
|||||||
@ -2,12 +2,15 @@ package fr.xephi.authme.command;
|
|||||||
|
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Base class for AuthMe commands that can be executed.
|
||||||
|
*/
|
||||||
public abstract class ExecutableCommand {
|
public abstract class ExecutableCommand {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute the command.
|
* Execute the command.
|
||||||
*
|
*
|
||||||
* @param sender The command sender.
|
* @param sender The command sender.
|
||||||
* @param commandReference The command reference.
|
* @param commandReference The command reference.
|
||||||
* @param commandArguments The command arguments.
|
* @param commandArguments The command arguments.
|
||||||
*
|
*
|
||||||
|
|||||||
@ -2,24 +2,34 @@ package fr.xephi.authme.command;
|
|||||||
|
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
public class FoundCommandResult {
|
public class FoundCommandResult {
|
||||||
|
|
||||||
/** The command description instance. */
|
/**
|
||||||
|
* The command description instance.
|
||||||
|
*/
|
||||||
private CommandDescription commandDescription;
|
private CommandDescription commandDescription;
|
||||||
/** The command reference. */
|
/**
|
||||||
private CommandParts commandReference;
|
* The command reference.
|
||||||
/** The command arguments. */
|
*/
|
||||||
private CommandParts commandArguments;
|
private final CommandParts commandReference;
|
||||||
/** The original search query reference. */
|
/**
|
||||||
private CommandParts queryReference;
|
* The command arguments.
|
||||||
|
*/
|
||||||
|
private final CommandParts commandArguments;
|
||||||
|
/**
|
||||||
|
* The original search query reference.
|
||||||
|
*/
|
||||||
|
private final CommandParts queryReference;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*
|
*
|
||||||
* @param commandDescription The command description.
|
* @param commandDescription The command description.
|
||||||
* @param commandReference The command reference.
|
* @param commandReference The command reference.
|
||||||
* @param commandArguments The command arguments.
|
* @param commandArguments The command arguments.
|
||||||
* @param queryReference The original query reference.
|
* @param queryReference The original query reference.
|
||||||
*/
|
*/
|
||||||
public FoundCommandResult(CommandDescription commandDescription, CommandParts commandReference, CommandParts commandArguments, CommandParts queryReference) {
|
public FoundCommandResult(CommandDescription commandDescription, CommandParts commandReference, CommandParts commandArguments, CommandParts queryReference) {
|
||||||
this.commandDescription = commandDescription;
|
this.commandDescription = commandDescription;
|
||||||
@ -35,7 +45,7 @@ public class FoundCommandResult {
|
|||||||
*/
|
*/
|
||||||
public boolean hasProperArguments() {
|
public boolean hasProperArguments() {
|
||||||
// Make sure the command description is set
|
// Make sure the command description is set
|
||||||
if(this.commandDescription == null)
|
if (this.commandDescription == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Get and return the result
|
// Get and return the result
|
||||||
@ -55,7 +65,6 @@ public class FoundCommandResult {
|
|||||||
* Set the command description.
|
* Set the command description.
|
||||||
*
|
*
|
||||||
* @param commandDescription The command description.
|
* @param commandDescription The command description.
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public void setCommandDescription(CommandDescription commandDescription) {
|
public void setCommandDescription(CommandDescription commandDescription) {
|
||||||
this.commandDescription = commandDescription;
|
this.commandDescription = commandDescription;
|
||||||
@ -68,7 +77,7 @@ public class FoundCommandResult {
|
|||||||
*/
|
*/
|
||||||
public boolean isExecutable() {
|
public boolean isExecutable() {
|
||||||
// Make sure the command description is valid
|
// Make sure the command description is valid
|
||||||
if(this.commandDescription == null)
|
if (this.commandDescription == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Check whether the command is executable, return the result
|
// Check whether the command is executable, return the result
|
||||||
@ -84,7 +93,7 @@ public class FoundCommandResult {
|
|||||||
*/
|
*/
|
||||||
public boolean executeCommand(CommandSender sender) {
|
public boolean executeCommand(CommandSender sender) {
|
||||||
// Make sure the command description is valid
|
// Make sure the command description is valid
|
||||||
if(this.commandDescription == null)
|
if (this.commandDescription == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Execute the command
|
// Execute the command
|
||||||
@ -99,12 +108,15 @@ public class FoundCommandResult {
|
|||||||
* @return True if the command sender has permission, false otherwise.
|
* @return True if the command sender has permission, false otherwise.
|
||||||
*/
|
*/
|
||||||
public boolean hasPermission(CommandSender sender) {
|
public boolean hasPermission(CommandSender sender) {
|
||||||
// Make sure the command description is valid
|
if (commandDescription == null) {
|
||||||
if(this.commandDescription == null)
|
|
||||||
return false;
|
return false;
|
||||||
|
} else if (commandDescription.getCommandPermissions() == null) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
// Get and return the permission
|
// TODO: Move permissions check to the permission package; command package should not define permission-checking
|
||||||
return this.commandDescription.getCommandPermissions().hasPermission(sender);
|
// API
|
||||||
|
return commandDescription.getCommandPermissions().hasPermission(sender);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -141,7 +153,7 @@ public class FoundCommandResult {
|
|||||||
*/
|
*/
|
||||||
public double getDifference() {
|
public double getDifference() {
|
||||||
// Get the difference through the command found
|
// Get the difference through the command found
|
||||||
if(this.commandDescription != null)
|
if (this.commandDescription != null)
|
||||||
return this.commandDescription.getCommandDifference(this.queryReference);
|
return this.commandDescription.getCommandDifference(this.queryReference);
|
||||||
|
|
||||||
// Get the difference from the query reference
|
// Get the difference from the query reference
|
||||||
|
|||||||
@ -1,38 +1,27 @@
|
|||||||
package fr.xephi.authme.command.executable;
|
package fr.xephi.authme.command.executable;
|
||||||
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
|
|
||||||
import fr.xephi.authme.command.CommandParts;
|
import fr.xephi.authme.command.CommandParts;
|
||||||
import fr.xephi.authme.command.ExecutableCommand;
|
import fr.xephi.authme.command.ExecutableCommand;
|
||||||
import fr.xephi.authme.command.help.HelpProvider;
|
import fr.xephi.authme.command.help.HelpProvider;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
public class HelpCommand extends ExecutableCommand {
|
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
|
@Override
|
||||||
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
||||||
// Check whether quick help should be shown
|
// Check whether quick help should be shown
|
||||||
boolean quickHelp = commandArguments.getCount() == 0;
|
boolean quickHelp = commandArguments.getCount() == 0;
|
||||||
|
|
||||||
// Set the proper command arguments for the quick help
|
// Set the proper command arguments for the quick help and show it
|
||||||
if(quickHelp)
|
if (quickHelp) {
|
||||||
commandArguments = new CommandParts(commandReference.get(0));
|
commandArguments = new CommandParts(commandReference.get(0));
|
||||||
|
|
||||||
// Show the new help
|
|
||||||
if(quickHelp)
|
|
||||||
HelpProvider.showHelp(sender, commandReference, commandArguments, false, false, false, false, false, true);
|
HelpProvider.showHelp(sender, commandReference, commandArguments, false, false, false, false, false, true);
|
||||||
else
|
} else {
|
||||||
HelpProvider.showHelp(sender, commandReference, commandArguments);
|
HelpProvider.showHelp(sender, commandReference, commandArguments);
|
||||||
|
}
|
||||||
|
|
||||||
// Return the result
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,39 +1,32 @@
|
|||||||
package fr.xephi.authme.command.executable.authme;
|
package fr.xephi.authme.command.executable.authme;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
|
|
||||||
import fr.xephi.authme.AuthMe;
|
import fr.xephi.authme.AuthMe;
|
||||||
import fr.xephi.authme.ConsoleLogger;
|
import fr.xephi.authme.ConsoleLogger;
|
||||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||||
import fr.xephi.authme.command.CommandParts;
|
import fr.xephi.authme.command.CommandParts;
|
||||||
import fr.xephi.authme.command.ExecutableCommand;
|
import fr.xephi.authme.command.ExecutableCommand;
|
||||||
|
import fr.xephi.authme.settings.MessageKey;
|
||||||
import fr.xephi.authme.settings.Messages;
|
import fr.xephi.authme.settings.Messages;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
public class AccountsCommand extends ExecutableCommand {
|
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
|
@Override
|
||||||
public boolean executeCommand(final CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
public boolean executeCommand(final CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
||||||
// AuthMe plugin instance
|
// AuthMe plugin instance
|
||||||
final AuthMe plugin = AuthMe.getInstance();
|
final AuthMe plugin = AuthMe.getInstance();
|
||||||
|
|
||||||
// Messages instance
|
// Messages instance
|
||||||
final Messages m = Messages.getInstance();
|
final Messages m = plugin.getMessages();
|
||||||
|
|
||||||
// Get the player query
|
// Get the player query
|
||||||
String playerQuery = sender.getName();
|
String playerQuery = sender.getName();
|
||||||
if(commandArguments.getCount() >= 1)
|
if (commandArguments.getCount() >= 1)
|
||||||
playerQuery = commandArguments.get(0);
|
playerQuery = commandArguments.get(0);
|
||||||
final String playerQueryFinal = playerQuery;
|
final String playerQueryFinal = playerQuery;
|
||||||
|
|
||||||
@ -48,16 +41,16 @@ public class AccountsCommand extends ExecutableCommand {
|
|||||||
try {
|
try {
|
||||||
auth = plugin.database.getAuth(playerQueryFinal.toLowerCase());
|
auth = plugin.database.getAuth(playerQueryFinal.toLowerCase());
|
||||||
} catch (NullPointerException npe) {
|
} catch (NullPointerException npe) {
|
||||||
m.send(sender, "unknown_user");
|
m.send(sender, MessageKey.UNKNOWN_USER);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (auth == null) {
|
if (auth == null) {
|
||||||
m.send(sender, "unknown_user");
|
m.send(sender, MessageKey.UNKNOWN_USER);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
List<String> accountList = plugin.database.getAllAuthsByName(auth);
|
List<String> accountList = plugin.database.getAllAuthsByName(auth);
|
||||||
if (accountList == null || accountList.isEmpty()) {
|
if (accountList == null || accountList.isEmpty()) {
|
||||||
m.send(sender, "user_unknown");
|
m.send(sender, MessageKey.USER_NOT_REGISTERED);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (accountList.size() == 1) {
|
if (accountList.size() == 1) {
|
||||||
@ -71,7 +64,7 @@ public class AccountsCommand extends ExecutableCommand {
|
|||||||
if (i != accountList.size()) {
|
if (i != accountList.size()) {
|
||||||
message.append(", ");
|
message.append(", ");
|
||||||
} else {
|
} else {
|
||||||
message.append(".");
|
message.append('.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sender.sendMessage("[AuthMe] " + playerQueryFinal + " has " + String.valueOf(accountList.size()) + " accounts");
|
sender.sendMessage("[AuthMe] " + playerQueryFinal + " has " + String.valueOf(accountList.size()) + " accounts");
|
||||||
@ -89,7 +82,7 @@ public class AccountsCommand extends ExecutableCommand {
|
|||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
ConsoleLogger.showError(e.getMessage());
|
ConsoleLogger.showError(e.getMessage());
|
||||||
ConsoleLogger.writeStackTrace(e);
|
ConsoleLogger.writeStackTrace(e);
|
||||||
m.send(sender, "error");
|
m.send(sender, MessageKey.ERROR);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -109,7 +102,7 @@ public class AccountsCommand extends ExecutableCommand {
|
|||||||
if (i != accountList.size()) {
|
if (i != accountList.size()) {
|
||||||
message.append(", ");
|
message.append(", ");
|
||||||
} else {
|
} else {
|
||||||
message.append(".");
|
message.append('.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sender.sendMessage("[AuthMe] " + playerQueryFinal + " has " + String.valueOf(accountList.size()) + " accounts");
|
sender.sendMessage("[AuthMe] " + playerQueryFinal + " has " + String.valueOf(accountList.size()) + " accounts");
|
||||||
|
|||||||
@ -1,27 +1,19 @@
|
|||||||
package fr.xephi.authme.command.executable.authme;
|
package fr.xephi.authme.command.executable.authme;
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
|
|
||||||
import fr.xephi.authme.AuthMe;
|
import fr.xephi.authme.AuthMe;
|
||||||
import fr.xephi.authme.command.CommandParts;
|
import fr.xephi.authme.command.CommandParts;
|
||||||
import fr.xephi.authme.command.ExecutableCommand;
|
import fr.xephi.authme.command.ExecutableCommand;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
public class AuthMeCommand extends 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
|
@Override
|
||||||
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
||||||
// Show some version info
|
// Show some version info
|
||||||
sender.sendMessage(ChatColor.GREEN + "This server is running " + AuthMe.PLUGIN_NAME + " v" + AuthMe.getVersionName() + "! " + ChatColor.RED + "<3");
|
sender.sendMessage(ChatColor.GREEN + "This server is running " + AuthMe.getPluginName() + " v" + AuthMe.getPluginVersion() + " b" + AuthMe.getPluginBuildNumber()+ "! " + ChatColor.RED + "<3");
|
||||||
sender.sendMessage(ChatColor.YELLOW + "Use the command " + ChatColor.GOLD + "/" + commandReference.get(0) + " help" + ChatColor.YELLOW + " to view help.");
|
sender.sendMessage(ChatColor.YELLOW + "Use the command " + ChatColor.GOLD + "/" + commandReference.get(0) + " help" + ChatColor.YELLOW + " to view help.");
|
||||||
sender.sendMessage(ChatColor.YELLOW + "Use the command " + ChatColor.GOLD + "/" + commandReference.get(0) + " about" + ChatColor.YELLOW + " to view about.");
|
sender.sendMessage(ChatColor.YELLOW + "Use the command " + ChatColor.GOLD + "/" + commandReference.get(0) + " about" + ChatColor.YELLOW + " to view about.");
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@ -1,10 +1,5 @@
|
|||||||
package fr.xephi.authme.command.executable.authme;
|
package fr.xephi.authme.command.executable.authme;
|
||||||
|
|
||||||
import java.security.NoSuchAlgorithmException;
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
|
|
||||||
import fr.xephi.authme.AuthMe;
|
import fr.xephi.authme.AuthMe;
|
||||||
import fr.xephi.authme.ConsoleLogger;
|
import fr.xephi.authme.ConsoleLogger;
|
||||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||||
@ -12,27 +7,23 @@ import fr.xephi.authme.cache.auth.PlayerCache;
|
|||||||
import fr.xephi.authme.command.CommandParts;
|
import fr.xephi.authme.command.CommandParts;
|
||||||
import fr.xephi.authme.command.ExecutableCommand;
|
import fr.xephi.authme.command.ExecutableCommand;
|
||||||
import fr.xephi.authme.security.PasswordSecurity;
|
import fr.xephi.authme.security.PasswordSecurity;
|
||||||
|
import fr.xephi.authme.settings.MessageKey;
|
||||||
import fr.xephi.authme.settings.Messages;
|
import fr.xephi.authme.settings.Messages;
|
||||||
import fr.xephi.authme.settings.Settings;
|
import fr.xephi.authme.settings.Settings;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
public class ChangePasswordCommand extends ExecutableCommand {
|
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
|
@Override
|
||||||
public boolean executeCommand(final CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
public boolean executeCommand(final CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
||||||
// AuthMe plugin instance
|
|
||||||
final AuthMe plugin = AuthMe.getInstance();
|
final AuthMe plugin = AuthMe.getInstance();
|
||||||
|
|
||||||
// Messages instance
|
// Messages instance
|
||||||
final Messages m = Messages.getInstance();
|
final Messages m = plugin.getMessages();
|
||||||
|
|
||||||
// Get the player and password
|
// Get the player and password
|
||||||
String playerName = commandArguments.get(0);
|
String playerName = commandArguments.get(0);
|
||||||
@ -41,24 +32,23 @@ public class ChangePasswordCommand extends ExecutableCommand {
|
|||||||
// Validate the password
|
// Validate the password
|
||||||
String playerPassLowerCase = playerPass.toLowerCase();
|
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)) {
|
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");
|
m.send(sender, MessageKey.PASSWORD_IS_USERNAME_ERROR);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (playerPassLowerCase.equalsIgnoreCase(playerName)) {
|
if (playerPassLowerCase.equalsIgnoreCase(playerName)) {
|
||||||
m.send(sender, "password_error_nick");
|
m.send(sender, MessageKey.PASSWORD_IS_USERNAME_ERROR);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (playerPassLowerCase.length() < Settings.getPasswordMinLen || playerPassLowerCase.length() > Settings.passwordMaxLength) {
|
if (playerPassLowerCase.length() < Settings.getPasswordMinLen || playerPassLowerCase.length() > Settings.passwordMaxLength) {
|
||||||
m.send(sender, "pass_len");
|
m.send(sender, MessageKey.INVALID_PASSWORD_LENGTH);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (!Settings.unsafePasswords.isEmpty()) {
|
if (!Settings.unsafePasswords.isEmpty()) {
|
||||||
if (Settings.unsafePasswords.contains(playerPassLowerCase)) {
|
if (Settings.unsafePasswords.contains(playerPassLowerCase)) {
|
||||||
m.send(sender, "password_error_unsafe");
|
m.send(sender, MessageKey.PASSWORD_UNSAFE_ERROR);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the password
|
// Set the password
|
||||||
final String playerNameLowerCase = playerName.toLowerCase();
|
final String playerNameLowerCase = playerName.toLowerCase();
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {
|
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {
|
||||||
@ -69,7 +59,7 @@ public class ChangePasswordCommand extends ExecutableCommand {
|
|||||||
try {
|
try {
|
||||||
hash = PasswordSecurity.getHash(Settings.getPasswordHash, playerPass, playerNameLowerCase);
|
hash = PasswordSecurity.getHash(Settings.getPasswordHash, playerPass, playerNameLowerCase);
|
||||||
} catch (NoSuchAlgorithmException e) {
|
} catch (NoSuchAlgorithmException e) {
|
||||||
m.send(sender, "error");
|
m.send(sender, MessageKey.ERROR);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
PlayerAuth auth = null;
|
PlayerAuth auth = null;
|
||||||
@ -79,7 +69,7 @@ public class ChangePasswordCommand extends ExecutableCommand {
|
|||||||
auth = plugin.database.getAuth(playerNameLowerCase);
|
auth = plugin.database.getAuth(playerNameLowerCase);
|
||||||
}
|
}
|
||||||
if (auth == null) {
|
if (auth == null) {
|
||||||
m.send(sender, "unknown_user");
|
m.send(sender, MessageKey.UNKNOWN_USER);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
auth.setHash(hash);
|
auth.setHash(hash);
|
||||||
@ -88,7 +78,7 @@ public class ChangePasswordCommand extends ExecutableCommand {
|
|||||||
plugin.database.updateSalt(auth);
|
plugin.database.updateSalt(auth);
|
||||||
}
|
}
|
||||||
if (!plugin.database.updatePassword(auth)) {
|
if (!plugin.database.updatePassword(auth)) {
|
||||||
m.send(sender, "error");
|
m.send(sender, MessageKey.ERROR);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
sender.sendMessage("pwd_changed");
|
sender.sendMessage("pwd_changed");
|
||||||
|
|||||||
@ -1,24 +1,16 @@
|
|||||||
package fr.xephi.authme.command.executable.authme;
|
package fr.xephi.authme.command.executable.authme;
|
||||||
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import fr.xephi.authme.ConsoleLogger;
|
import fr.xephi.authme.ConsoleLogger;
|
||||||
import fr.xephi.authme.command.CommandParts;
|
import fr.xephi.authme.command.CommandParts;
|
||||||
import fr.xephi.authme.command.ExecutableCommand;
|
import fr.xephi.authme.command.ExecutableCommand;
|
||||||
import fr.xephi.authme.settings.Spawn;
|
import fr.xephi.authme.settings.Spawn;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
public class FirstSpawnCommand extends ExecutableCommand {
|
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
|
@Override
|
||||||
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
||||||
// Make sure the command executor is a player
|
// Make sure the command executor is a player
|
||||||
@ -31,6 +23,7 @@ public class FirstSpawnCommand extends ExecutableCommand {
|
|||||||
sender.sendMessage("[AuthMe] Please use that command in game");
|
sender.sendMessage("[AuthMe] Please use that command in game");
|
||||||
}
|
}
|
||||||
} catch (NullPointerException ex) {
|
} catch (NullPointerException ex) {
|
||||||
|
// TODO ljacqu 20151119: Catching NullPointerException is never a good idea. Find what can cause one instead
|
||||||
ConsoleLogger.showError(ex.getMessage());
|
ConsoleLogger.showError(ex.getMessage());
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@ -1,24 +1,17 @@
|
|||||||
package fr.xephi.authme.command.executable.authme;
|
package fr.xephi.authme.command.executable.authme;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import fr.xephi.authme.AuthMe;
|
import fr.xephi.authme.AuthMe;
|
||||||
import fr.xephi.authme.command.CommandParts;
|
import fr.xephi.authme.command.CommandParts;
|
||||||
import fr.xephi.authme.command.ExecutableCommand;
|
import fr.xephi.authme.command.ExecutableCommand;
|
||||||
|
import fr.xephi.authme.permission.UserPermission;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
public class ForceLoginCommand extends 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
|
@Override
|
||||||
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
||||||
// AuthMe plugin instance
|
// AuthMe plugin instance
|
||||||
@ -26,7 +19,7 @@ public class ForceLoginCommand extends ExecutableCommand {
|
|||||||
|
|
||||||
// Get the player query
|
// Get the player query
|
||||||
String playerName = sender.getName();
|
String playerName = sender.getName();
|
||||||
if(commandArguments.getCount() >= 1)
|
if (commandArguments.getCount() >= 1)
|
||||||
playerName = commandArguments.get(0);
|
playerName = commandArguments.get(0);
|
||||||
|
|
||||||
// Command logic
|
// Command logic
|
||||||
@ -37,7 +30,7 @@ public class ForceLoginCommand extends ExecutableCommand {
|
|||||||
sender.sendMessage("Player needs to be online!");
|
sender.sendMessage("Player needs to be online!");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (!plugin.authmePermissible(player, "authme.canbeforced")) {
|
if (!plugin.getPermissionsManager().hasPermission(player, UserPermission.CAN_LOGIN_BE_FORCED)) {
|
||||||
sender.sendMessage("You cannot force login for the player " + playerName + "!");
|
sender.sendMessage("You cannot force login for the player " + playerName + "!");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,13 +1,15 @@
|
|||||||
package fr.xephi.authme.command.executable.authme;
|
package fr.xephi.authme.command.executable.authme;
|
||||||
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
|
|
||||||
import fr.xephi.authme.AuthMe;
|
import fr.xephi.authme.AuthMe;
|
||||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||||
import fr.xephi.authme.command.CommandParts;
|
import fr.xephi.authme.command.CommandParts;
|
||||||
import fr.xephi.authme.command.ExecutableCommand;
|
import fr.xephi.authme.command.ExecutableCommand;
|
||||||
|
import fr.xephi.authme.settings.MessageKey;
|
||||||
import fr.xephi.authme.settings.Messages;
|
import fr.xephi.authme.settings.Messages;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
public class GetEmailCommand extends ExecutableCommand {
|
public class GetEmailCommand extends ExecutableCommand {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -21,21 +23,17 @@ public class GetEmailCommand extends ExecutableCommand {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
||||||
// AuthMe plugin instance
|
|
||||||
AuthMe plugin = AuthMe.getInstance();
|
|
||||||
|
|
||||||
// Messages instance
|
|
||||||
Messages m = Messages.getInstance();
|
|
||||||
|
|
||||||
// Get the player name
|
// Get the player name
|
||||||
String playerName = sender.getName();
|
String playerName = sender.getName();
|
||||||
if(commandArguments.getCount() >= 1)
|
if (commandArguments.getCount() >= 1)
|
||||||
playerName = commandArguments.get(0);
|
playerName = commandArguments.get(0);
|
||||||
|
|
||||||
// Get the authenticated user
|
// Get the authenticated user
|
||||||
|
AuthMe plugin = AuthMe.getInstance();
|
||||||
|
Messages m = plugin.getMessages();
|
||||||
PlayerAuth auth = plugin.database.getAuth(playerName.toLowerCase());
|
PlayerAuth auth = plugin.database.getAuth(playerName.toLowerCase());
|
||||||
if (auth == null) {
|
if (auth == null) {
|
||||||
m.send(sender, "unknown_user");
|
m.send(sender, MessageKey.UNKNOWN_USER);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,24 +1,16 @@
|
|||||||
package fr.xephi.authme.command.executable.authme;
|
package fr.xephi.authme.command.executable.authme;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import fr.xephi.authme.AuthMe;
|
import fr.xephi.authme.AuthMe;
|
||||||
import fr.xephi.authme.command.CommandParts;
|
import fr.xephi.authme.command.CommandParts;
|
||||||
import fr.xephi.authme.command.ExecutableCommand;
|
import fr.xephi.authme.command.ExecutableCommand;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
public class GetIpCommand extends 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
|
@Override
|
||||||
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
||||||
// AuthMe plugin instance
|
// AuthMe plugin instance
|
||||||
@ -26,7 +18,7 @@ public class GetIpCommand extends ExecutableCommand {
|
|||||||
|
|
||||||
// Get the player query
|
// Get the player query
|
||||||
String playerName = sender.getName();
|
String playerName = sender.getName();
|
||||||
if(commandArguments.getCount() >= 1)
|
if (commandArguments.getCount() >= 1)
|
||||||
playerName = commandArguments.get(0);
|
playerName = commandArguments.get(0);
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
|
|||||||
@ -1,49 +1,39 @@
|
|||||||
package fr.xephi.authme.command.executable.authme;
|
package fr.xephi.authme.command.executable.authme;
|
||||||
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
|
|
||||||
import fr.xephi.authme.AuthMe;
|
import fr.xephi.authme.AuthMe;
|
||||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||||
import fr.xephi.authme.command.CommandParts;
|
import fr.xephi.authme.command.CommandParts;
|
||||||
import fr.xephi.authme.command.ExecutableCommand;
|
import fr.xephi.authme.command.ExecutableCommand;
|
||||||
|
import fr.xephi.authme.settings.MessageKey;
|
||||||
import fr.xephi.authme.settings.Messages;
|
import fr.xephi.authme.settings.Messages;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
public class LastLoginCommand extends ExecutableCommand {
|
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
|
@Override
|
||||||
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
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
|
// Get the player
|
||||||
String playerName = sender.getName();
|
String playerName = sender.getName();
|
||||||
if(commandArguments.getCount() >= 1)
|
if (commandArguments.getCount() >= 1)
|
||||||
playerName = commandArguments.get(0);
|
playerName = commandArguments.get(0);
|
||||||
|
|
||||||
// Validate the player
|
// Validate the player
|
||||||
|
AuthMe plugin = AuthMe.getInstance();
|
||||||
|
Messages m = plugin.getMessages();
|
||||||
|
|
||||||
PlayerAuth auth;
|
PlayerAuth auth;
|
||||||
try {
|
try {
|
||||||
auth = plugin.database.getAuth(playerName.toLowerCase());
|
auth = plugin.database.getAuth(playerName.toLowerCase());
|
||||||
} catch (NullPointerException e) {
|
} catch (NullPointerException e) {
|
||||||
m.send(sender, "unknown_user");
|
m.send(sender, MessageKey.UNKNOWN_USER);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (auth == null) {
|
if (auth == null) {
|
||||||
m.send(sender, "user_unknown");
|
m.send(sender, MessageKey.USER_NOT_REGISTERED);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,16 +1,17 @@
|
|||||||
package fr.xephi.authme.command.executable.authme;
|
package fr.xephi.authme.command.executable.authme;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.bukkit.OfflinePlayer;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
|
|
||||||
import fr.xephi.authme.AuthMe;
|
import fr.xephi.authme.AuthMe;
|
||||||
import fr.xephi.authme.command.CommandParts;
|
import fr.xephi.authme.command.CommandParts;
|
||||||
import fr.xephi.authme.command.ExecutableCommand;
|
import fr.xephi.authme.command.ExecutableCommand;
|
||||||
import fr.xephi.authme.settings.Settings;
|
import fr.xephi.authme.settings.Settings;
|
||||||
|
import org.bukkit.OfflinePlayer;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
public class PurgeBannedPlayersCommand extends ExecutableCommand {
|
public class PurgeBannedPlayersCommand extends ExecutableCommand {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -1,16 +1,17 @@
|
|||||||
package fr.xephi.authme.command.executable.authme;
|
package fr.xephi.authme.command.executable.authme;
|
||||||
|
|
||||||
import java.util.Calendar;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
|
|
||||||
import fr.xephi.authme.AuthMe;
|
import fr.xephi.authme.AuthMe;
|
||||||
import fr.xephi.authme.command.CommandParts;
|
import fr.xephi.authme.command.CommandParts;
|
||||||
import fr.xephi.authme.command.ExecutableCommand;
|
import fr.xephi.authme.command.ExecutableCommand;
|
||||||
import fr.xephi.authme.settings.Settings;
|
import fr.xephi.authme.settings.Settings;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
public class PurgeCommand extends ExecutableCommand {
|
public class PurgeCommand extends ExecutableCommand {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -34,13 +35,13 @@ public class PurgeCommand extends ExecutableCommand {
|
|||||||
int days;
|
int days;
|
||||||
try {
|
try {
|
||||||
days = Integer.valueOf(daysStr);
|
days = Integer.valueOf(daysStr);
|
||||||
} catch(Exception ex) {
|
} catch (Exception ex) {
|
||||||
sender.sendMessage(ChatColor.RED + "The value you've entered is invalid!");
|
sender.sendMessage(ChatColor.RED + "The value you've entered is invalid!");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate the value
|
// Validate the value
|
||||||
if(days < 30) {
|
if (days < 30) {
|
||||||
sender.sendMessage(ChatColor.RED + "You can only purge data older than 30 days");
|
sender.sendMessage(ChatColor.RED + "You can only purge data older than 30 days");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -57,13 +58,13 @@ public class PurgeCommand extends ExecutableCommand {
|
|||||||
sender.sendMessage(ChatColor.GOLD + "Deleted " + purged.size() + " user accounts");
|
sender.sendMessage(ChatColor.GOLD + "Deleted " + purged.size() + " user accounts");
|
||||||
|
|
||||||
// Purge other data
|
// Purge other data
|
||||||
if(Settings.purgeEssentialsFile && plugin.ess != null)
|
if (Settings.purgeEssentialsFile && plugin.ess != null)
|
||||||
plugin.dataManager.purgeEssentials(purged);
|
plugin.dataManager.purgeEssentials(purged);
|
||||||
if(Settings.purgePlayerDat)
|
if (Settings.purgePlayerDat)
|
||||||
plugin.dataManager.purgeDat(purged);
|
plugin.dataManager.purgeDat(purged);
|
||||||
if(Settings.purgeLimitedCreative)
|
if (Settings.purgeLimitedCreative)
|
||||||
plugin.dataManager.purgeLimitedCreative(purged);
|
plugin.dataManager.purgeLimitedCreative(purged);
|
||||||
if(Settings.purgeAntiXray)
|
if (Settings.purgeAntiXray)
|
||||||
plugin.dataManager.purgeAntiXray(purged);
|
plugin.dataManager.purgeAntiXray(purged);
|
||||||
|
|
||||||
// Show a status message
|
// Show a status message
|
||||||
|
|||||||
@ -1,15 +1,17 @@
|
|||||||
package fr.xephi.authme.command.executable.authme;
|
package fr.xephi.authme.command.executable.authme;
|
||||||
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import fr.xephi.authme.AuthMe;
|
import fr.xephi.authme.AuthMe;
|
||||||
import fr.xephi.authme.ConsoleLogger;
|
import fr.xephi.authme.ConsoleLogger;
|
||||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||||
import fr.xephi.authme.command.CommandParts;
|
import fr.xephi.authme.command.CommandParts;
|
||||||
import fr.xephi.authme.command.ExecutableCommand;
|
import fr.xephi.authme.command.ExecutableCommand;
|
||||||
|
import fr.xephi.authme.settings.MessageKey;
|
||||||
import fr.xephi.authme.settings.Messages;
|
import fr.xephi.authme.settings.Messages;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
public class PurgeLastPositionCommand extends ExecutableCommand {
|
public class PurgeLastPositionCommand extends ExecutableCommand {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -27,11 +29,11 @@ public class PurgeLastPositionCommand extends ExecutableCommand {
|
|||||||
final AuthMe plugin = AuthMe.getInstance();
|
final AuthMe plugin = AuthMe.getInstance();
|
||||||
|
|
||||||
// Messages instance
|
// Messages instance
|
||||||
final Messages m = Messages.getInstance();
|
final Messages m = plugin.getMessages();
|
||||||
|
|
||||||
// Get the player
|
// Get the player
|
||||||
String playerName = sender.getName();
|
String playerName = sender.getName();
|
||||||
if(commandArguments.getCount() >= 1)
|
if (commandArguments.getCount() >= 1)
|
||||||
playerName = commandArguments.get(0);
|
playerName = commandArguments.get(0);
|
||||||
String playerNameLowerCase = playerName.toLowerCase();
|
String playerNameLowerCase = playerName.toLowerCase();
|
||||||
|
|
||||||
@ -40,7 +42,7 @@ public class PurgeLastPositionCommand extends ExecutableCommand {
|
|||||||
// Get the user auth and make sure the user exists
|
// Get the user auth and make sure the user exists
|
||||||
PlayerAuth auth = plugin.database.getAuth(playerNameLowerCase);
|
PlayerAuth auth = plugin.database.getAuth(playerNameLowerCase);
|
||||||
if (auth == null) {
|
if (auth == null) {
|
||||||
m.send(sender, "unknown_user");
|
m.send(sender, MessageKey.UNKNOWN_USER);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,19 +1,21 @@
|
|||||||
package fr.xephi.authme.command.executable.authme;
|
package fr.xephi.authme.command.executable.authme;
|
||||||
|
|
||||||
import java.security.NoSuchAlgorithmException;
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
|
|
||||||
import fr.xephi.authme.AuthMe;
|
import fr.xephi.authme.AuthMe;
|
||||||
import fr.xephi.authme.ConsoleLogger;
|
import fr.xephi.authme.ConsoleLogger;
|
||||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||||
import fr.xephi.authme.command.CommandParts;
|
import fr.xephi.authme.command.CommandParts;
|
||||||
import fr.xephi.authme.command.ExecutableCommand;
|
import fr.xephi.authme.command.ExecutableCommand;
|
||||||
import fr.xephi.authme.security.PasswordSecurity;
|
import fr.xephi.authme.security.PasswordSecurity;
|
||||||
|
import fr.xephi.authme.settings.MessageKey;
|
||||||
import fr.xephi.authme.settings.Messages;
|
import fr.xephi.authme.settings.Messages;
|
||||||
import fr.xephi.authme.settings.Settings;
|
import fr.xephi.authme.settings.Settings;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
public class RegisterCommand extends ExecutableCommand {
|
public class RegisterCommand extends ExecutableCommand {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -31,7 +33,7 @@ public class RegisterCommand extends ExecutableCommand {
|
|||||||
final AuthMe plugin = AuthMe.getInstance();
|
final AuthMe plugin = AuthMe.getInstance();
|
||||||
|
|
||||||
// Messages instance
|
// Messages instance
|
||||||
final Messages m = Messages.getInstance();
|
final Messages m = plugin.getMessages();
|
||||||
|
|
||||||
// Get the player name and password
|
// Get the player name and password
|
||||||
final String playerName = commandArguments.get(0);
|
final String playerName = commandArguments.get(0);
|
||||||
@ -41,20 +43,20 @@ public class RegisterCommand extends ExecutableCommand {
|
|||||||
|
|
||||||
// Command logic
|
// 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)) {
|
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");
|
m.send(sender, MessageKey.PASSWORD_IS_USERNAME_ERROR);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (playerPassLowerCase.equalsIgnoreCase(playerName)) {
|
if (playerPassLowerCase.equalsIgnoreCase(playerName)) {
|
||||||
m.send(sender, "password_error_nick");
|
m.send(sender, MessageKey.PASSWORD_IS_USERNAME_ERROR);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (playerPassLowerCase.length() < Settings.getPasswordMinLen || playerPassLowerCase.length() > Settings.passwordMaxLength) {
|
if (playerPassLowerCase.length() < Settings.getPasswordMinLen || playerPassLowerCase.length() > Settings.passwordMaxLength) {
|
||||||
m.send(sender, "pass_len");
|
m.send(sender, MessageKey.INVALID_PASSWORD_LENGTH);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (!Settings.unsafePasswords.isEmpty()) {
|
if (!Settings.unsafePasswords.isEmpty()) {
|
||||||
if (Settings.unsafePasswords.contains(playerPassLowerCase)) {
|
if (Settings.unsafePasswords.contains(playerPassLowerCase)) {
|
||||||
m.send(sender, "password_error_unsafe");
|
m.send(sender, MessageKey.PASSWORD_UNSAFE_ERROR);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -64,26 +66,26 @@ public class RegisterCommand extends ExecutableCommand {
|
|||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
if (plugin.database.isAuthAvailable(playerNameLowerCase)) {
|
if (plugin.database.isAuthAvailable(playerNameLowerCase)) {
|
||||||
m.send(sender, "user_regged");
|
m.send(sender, MessageKey.NAME_ALREADY_REGISTERED);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String hash = PasswordSecurity.getHash(Settings.getPasswordHash, playerPassLowerCase, playerNameLowerCase);
|
String hash = PasswordSecurity.getHash(Settings.getPasswordHash, playerPass, playerNameLowerCase);
|
||||||
PlayerAuth auth = new PlayerAuth(playerNameLowerCase, hash, "192.168.0.1", 0L, "your@email.com", playerName);
|
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)
|
if (PasswordSecurity.userSalt.containsKey(playerNameLowerCase) && PasswordSecurity.userSalt.get(playerNameLowerCase) != null)
|
||||||
auth.setSalt(PasswordSecurity.userSalt.get(playerNameLowerCase));
|
auth.setSalt(PasswordSecurity.userSalt.get(playerNameLowerCase));
|
||||||
else auth.setSalt("");
|
else auth.setSalt("");
|
||||||
if (!plugin.database.saveAuth(auth)) {
|
if (!plugin.database.saveAuth(auth)) {
|
||||||
m.send(sender, "error");
|
m.send(sender, MessageKey.ERROR);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
plugin.database.setUnlogged(playerNameLowerCase);
|
plugin.database.setUnlogged(playerNameLowerCase);
|
||||||
if (Bukkit.getPlayerExact(playerName) != null)
|
if (Bukkit.getPlayerExact(playerName) != null)
|
||||||
Bukkit.getPlayerExact(playerName).kickPlayer("An admin just registered you, please log again");
|
Bukkit.getPlayerExact(playerName).kickPlayer("An admin just registered you, please log again");
|
||||||
m.send(sender, "registered");
|
m.send(sender, MessageKey.REGISTER_SUCCESS);
|
||||||
ConsoleLogger.info(playerNameLowerCase + " registered");
|
ConsoleLogger.info(playerNameLowerCase + " registered");
|
||||||
} catch (NoSuchAlgorithmException ex) {
|
} catch (NoSuchAlgorithmException ex) {
|
||||||
ConsoleLogger.showError(ex.getMessage());
|
ConsoleLogger.showError(ex.getMessage());
|
||||||
m.send(sender, "error");
|
m.send(sender, MessageKey.ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,16 +1,19 @@
|
|||||||
package fr.xephi.authme.command.executable.authme;
|
package fr.xephi.authme.command.executable.authme;
|
||||||
|
|
||||||
//import org.bukkit.ChatColor;
|
//import org.bukkit.ChatColor;
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
|
|
||||||
import fr.xephi.authme.AuthMe;
|
import fr.xephi.authme.AuthMe;
|
||||||
import fr.xephi.authme.ConsoleLogger;
|
import fr.xephi.authme.ConsoleLogger;
|
||||||
import fr.xephi.authme.command.CommandParts;
|
import fr.xephi.authme.command.CommandParts;
|
||||||
import fr.xephi.authme.command.ExecutableCommand;
|
import fr.xephi.authme.command.ExecutableCommand;
|
||||||
|
import fr.xephi.authme.settings.MessageKey;
|
||||||
import fr.xephi.authme.settings.Messages;
|
import fr.xephi.authme.settings.Messages;
|
||||||
import fr.xephi.authme.settings.Settings;
|
import fr.xephi.authme.settings.Settings;
|
||||||
import fr.xephi.authme.util.Profiler;
|
import fr.xephi.authme.util.Profiler;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
public class ReloadCommand extends ExecutableCommand {
|
public class ReloadCommand extends ExecutableCommand {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -31,15 +34,15 @@ public class ReloadCommand extends ExecutableCommand {
|
|||||||
AuthMe plugin = AuthMe.getInstance();
|
AuthMe plugin = AuthMe.getInstance();
|
||||||
|
|
||||||
// Messages instance
|
// Messages instance
|
||||||
Messages m = Messages.getInstance();
|
Messages m = plugin.getMessages();
|
||||||
|
|
||||||
// Show a status message
|
// Show a status message
|
||||||
// sender.sendMessage(ChatColor.YELLOW + "Reloading AuthMeReloaded...");
|
// sender.sendMessage(ChatColor.YELLOW + "Reloading AuthMeReloaded...");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Settings.reload();
|
Settings.reload();
|
||||||
|
plugin.setMessages(new Messages(Settings.messageFile, Settings.messagesLanguage));
|
||||||
plugin.getModuleManager().reloadModules();
|
plugin.getModuleManager().reloadModules();
|
||||||
Messages.getInstance().reloadMessages();
|
|
||||||
plugin.setupDatabase();
|
plugin.setupDatabase();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
ConsoleLogger.showError("Fatal error occurred! AuthMe instance ABORTED!");
|
ConsoleLogger.showError("Fatal error occurred! AuthMe instance ABORTED!");
|
||||||
@ -50,7 +53,7 @@ public class ReloadCommand extends ExecutableCommand {
|
|||||||
|
|
||||||
// Show a status message
|
// Show a status message
|
||||||
// TODO: add the profiler result
|
// TODO: add the profiler result
|
||||||
m.send(sender, "reload");
|
m.send(sender, MessageKey.CONFIG_RELOAD_SUCCESS);
|
||||||
|
|
||||||
// AuthMeReloaded reloaded, show a status message
|
// AuthMeReloaded reloaded, show a status message
|
||||||
// sender.sendMessage(ChatColor.GREEN + "AuthMeReloaded has been reloaded successfully, took " + p.getTimeFormatted() + "!");
|
// sender.sendMessage(ChatColor.GREEN + "AuthMeReloaded has been reloaded successfully, took " + p.getTimeFormatted() + "!");
|
||||||
|
|||||||
@ -1,15 +1,16 @@
|
|||||||
package fr.xephi.authme.command.executable.authme;
|
package fr.xephi.authme.command.executable.authme;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
|
|
||||||
import fr.xephi.authme.AuthMe;
|
import fr.xephi.authme.AuthMe;
|
||||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||||
import fr.xephi.authme.command.CommandParts;
|
import fr.xephi.authme.command.CommandParts;
|
||||||
import fr.xephi.authme.command.ExecutableCommand;
|
import fr.xephi.authme.command.ExecutableCommand;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
public class ResetNameCommand extends ExecutableCommand {
|
public class ResetNameCommand extends ExecutableCommand {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -31,7 +32,7 @@ public class ResetNameCommand extends ExecutableCommand {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
List<PlayerAuth> authentications = plugin.database.getAllAuths();
|
List<PlayerAuth> authentications = plugin.database.getAllAuths();
|
||||||
for(PlayerAuth auth : authentications) {
|
for (PlayerAuth auth : authentications) {
|
||||||
auth.setRealName("Player");
|
auth.setRealName("Player");
|
||||||
plugin.database.updateSession(auth);
|
plugin.database.updateSession(auth);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,15 +1,17 @@
|
|||||||
package fr.xephi.authme.command.executable.authme;
|
package fr.xephi.authme.command.executable.authme;
|
||||||
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
|
|
||||||
import fr.xephi.authme.AuthMe;
|
import fr.xephi.authme.AuthMe;
|
||||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||||
import fr.xephi.authme.cache.auth.PlayerCache;
|
import fr.xephi.authme.cache.auth.PlayerCache;
|
||||||
import fr.xephi.authme.command.CommandParts;
|
import fr.xephi.authme.command.CommandParts;
|
||||||
import fr.xephi.authme.command.ExecutableCommand;
|
import fr.xephi.authme.command.ExecutableCommand;
|
||||||
|
import fr.xephi.authme.settings.MessageKey;
|
||||||
import fr.xephi.authme.settings.Messages;
|
import fr.xephi.authme.settings.Messages;
|
||||||
import fr.xephi.authme.settings.Settings;
|
import fr.xephi.authme.settings.Settings;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
public class SetEmailCommand extends ExecutableCommand {
|
public class SetEmailCommand extends ExecutableCommand {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -27,7 +29,7 @@ public class SetEmailCommand extends ExecutableCommand {
|
|||||||
AuthMe plugin = AuthMe.getInstance();
|
AuthMe plugin = AuthMe.getInstance();
|
||||||
|
|
||||||
// Messages instance
|
// Messages instance
|
||||||
Messages m = Messages.getInstance();
|
Messages m = plugin.getMessages();
|
||||||
|
|
||||||
// Get the player name and email address
|
// Get the player name and email address
|
||||||
String playerName = commandArguments.get(0);
|
String playerName = commandArguments.get(0);
|
||||||
@ -35,21 +37,21 @@ public class SetEmailCommand extends ExecutableCommand {
|
|||||||
|
|
||||||
// Validate the email address
|
// Validate the email address
|
||||||
if (!Settings.isEmailCorrect(playerEmail)) {
|
if (!Settings.isEmailCorrect(playerEmail)) {
|
||||||
m.send(sender, "email_invalid");
|
m.send(sender, MessageKey.INVALID_EMAIL);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate the user
|
// Validate the user
|
||||||
PlayerAuth auth = plugin.database.getAuth(playerName.toLowerCase());
|
PlayerAuth auth = plugin.database.getAuth(playerName.toLowerCase());
|
||||||
if (auth == null) {
|
if (auth == null) {
|
||||||
m.send(sender, "unknown_user");
|
m.send(sender, MessageKey.UNKNOWN_USER);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the email address
|
// Set the email address
|
||||||
auth.setEmail(playerEmail);
|
auth.setEmail(playerEmail);
|
||||||
if (!plugin.database.updateEmail(auth)) {
|
if (!plugin.database.updateEmail(auth)) {
|
||||||
m.send(sender, "error");
|
m.send(sender, MessageKey.ERROR);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,7 +60,7 @@ public class SetEmailCommand extends ExecutableCommand {
|
|||||||
PlayerCache.getInstance().updatePlayer(auth);
|
PlayerCache.getInstance().updatePlayer(auth);
|
||||||
|
|
||||||
// Show a status message
|
// Show a status message
|
||||||
m.send(sender, "email_changed");
|
m.send(sender, MessageKey.EMAIL_CHANGED_SUCCESS);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,13 +1,14 @@
|
|||||||
package fr.xephi.authme.command.executable.authme;
|
package fr.xephi.authme.command.executable.authme;
|
||||||
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import fr.xephi.authme.ConsoleLogger;
|
import fr.xephi.authme.ConsoleLogger;
|
||||||
import fr.xephi.authme.command.CommandParts;
|
import fr.xephi.authme.command.CommandParts;
|
||||||
import fr.xephi.authme.command.ExecutableCommand;
|
import fr.xephi.authme.command.ExecutableCommand;
|
||||||
import fr.xephi.authme.settings.Spawn;
|
import fr.xephi.authme.settings.Spawn;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
public class SetFirstSpawnCommand extends ExecutableCommand {
|
public class SetFirstSpawnCommand extends ExecutableCommand {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -1,13 +1,14 @@
|
|||||||
package fr.xephi.authme.command.executable.authme;
|
package fr.xephi.authme.command.executable.authme;
|
||||||
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import fr.xephi.authme.ConsoleLogger;
|
import fr.xephi.authme.ConsoleLogger;
|
||||||
import fr.xephi.authme.command.CommandParts;
|
import fr.xephi.authme.command.CommandParts;
|
||||||
import fr.xephi.authme.command.ExecutableCommand;
|
import fr.xephi.authme.command.ExecutableCommand;
|
||||||
import fr.xephi.authme.settings.Spawn;
|
import fr.xephi.authme.settings.Spawn;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
public class SetSpawnCommand extends ExecutableCommand {
|
public class SetSpawnCommand extends ExecutableCommand {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -1,13 +1,14 @@
|
|||||||
package fr.xephi.authme.command.executable.authme;
|
package fr.xephi.authme.command.executable.authme;
|
||||||
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import fr.xephi.authme.ConsoleLogger;
|
import fr.xephi.authme.ConsoleLogger;
|
||||||
import fr.xephi.authme.command.CommandParts;
|
import fr.xephi.authme.command.CommandParts;
|
||||||
import fr.xephi.authme.command.ExecutableCommand;
|
import fr.xephi.authme.command.ExecutableCommand;
|
||||||
import fr.xephi.authme.settings.Spawn;
|
import fr.xephi.authme.settings.Spawn;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
public class SpawnCommand extends ExecutableCommand {
|
public class SpawnCommand extends ExecutableCommand {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -1,13 +1,14 @@
|
|||||||
package fr.xephi.authme.command.executable.authme;
|
package fr.xephi.authme.command.executable.authme;
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
import fr.xephi.authme.AntiBot;
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
|
|
||||||
import fr.xephi.authme.AuthMe;
|
|
||||||
import fr.xephi.authme.command.CommandParts;
|
import fr.xephi.authme.command.CommandParts;
|
||||||
import fr.xephi.authme.command.ExecutableCommand;
|
import fr.xephi.authme.command.ExecutableCommand;
|
||||||
import fr.xephi.authme.command.help.HelpProvider;
|
import fr.xephi.authme.command.help.HelpProvider;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
public class SwitchAntiBotCommand extends ExecutableCommand {
|
public class SwitchAntiBotCommand extends ExecutableCommand {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -21,25 +22,26 @@ public class SwitchAntiBotCommand extends ExecutableCommand {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean executeCommand(final CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
public boolean executeCommand(final CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
||||||
// AuthMe plugin instance
|
|
||||||
final AuthMe plugin = AuthMe.getInstance();
|
|
||||||
|
|
||||||
// Get the new state
|
// Get the new state
|
||||||
String newState = plugin.getAntiBotModMode() ? "OFF" : "ON";
|
String newState = null;
|
||||||
if(commandArguments.getCount() >= 1)
|
if (commandArguments.getCount() == 1) {
|
||||||
newState = commandArguments.get(0);
|
newState = commandArguments.get(0);
|
||||||
|
} else if(commandArguments.getCount() == 0) {
|
||||||
|
sender.sendMessage("[AuthMe] AntiBot status: " + AntiBot.getAntiBotStatus().name());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
// Enable the mod
|
// Enable the mod
|
||||||
if(newState.equalsIgnoreCase("ON")) {
|
if (newState.equalsIgnoreCase("ON")) {
|
||||||
plugin.switchAntiBotMod(true);
|
AntiBot.overrideAntiBotStatus(true);
|
||||||
sender.sendMessage("[AuthMe] AntiBotMod enabled");
|
sender.sendMessage("[AuthMe] AntiBot Manual Ovverride: enabled!");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Disable the mod
|
// Disable the mod
|
||||||
if(newState.equalsIgnoreCase("OFF")) {
|
if (newState.equalsIgnoreCase("OFF")) {
|
||||||
plugin.switchAntiBotMod(false);
|
AntiBot.overrideAntiBotStatus(false);
|
||||||
sender.sendMessage("[AuthMe] AntiBotMod disabled");
|
sender.sendMessage("[AuthMe] AntiBotMod Manual Ovverride: disabled!");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,17 @@
|
|||||||
package fr.xephi.authme.command.executable.authme;
|
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.settings.MessageKey;
|
||||||
|
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.Bukkit;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -8,18 +20,8 @@ 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 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.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;
|
|
||||||
|
|
||||||
public class UnregisterCommand extends ExecutableCommand {
|
public class UnregisterCommand extends ExecutableCommand {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -28,6 +30,7 @@ public class UnregisterCommand extends ExecutableCommand {
|
|||||||
* @param sender The command sender.
|
* @param sender The command sender.
|
||||||
* @param commandReference The command reference.
|
* @param commandReference The command reference.
|
||||||
* @param commandArguments The command arguments.
|
* @param commandArguments The command arguments.
|
||||||
|
*
|
||||||
* @return True if the command was executed successfully, false otherwise.
|
* @return True if the command was executed successfully, false otherwise.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@ -36,7 +39,7 @@ public class UnregisterCommand extends ExecutableCommand {
|
|||||||
final AuthMe plugin = AuthMe.getInstance();
|
final AuthMe plugin = AuthMe.getInstance();
|
||||||
|
|
||||||
// Messages instance
|
// Messages instance
|
||||||
final Messages m = Messages.getInstance();
|
final Messages m = plugin.getMessages();
|
||||||
|
|
||||||
// Get the player name
|
// Get the player name
|
||||||
String playerName = commandArguments.get(0);
|
String playerName = commandArguments.get(0);
|
||||||
@ -44,18 +47,17 @@ public class UnregisterCommand extends ExecutableCommand {
|
|||||||
|
|
||||||
// Make sure the user is valid
|
// Make sure the user is valid
|
||||||
if (!plugin.database.isAuthAvailable(playerNameLowerCase)) {
|
if (!plugin.database.isAuthAvailable(playerNameLowerCase)) {
|
||||||
m.send(sender, "user_unknown");
|
m.send(sender, MessageKey.UNKNOWN_USER);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove the player
|
// Remove the player
|
||||||
if (!plugin.database.removeAuth(playerNameLowerCase)) {
|
if (!plugin.database.removeAuth(playerNameLowerCase)) {
|
||||||
m.send(sender, "error");
|
m.send(sender, MessageKey.ERROR);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unregister the player
|
// Unregister the player
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
Player target = Bukkit.getPlayer(playerNameLowerCase);
|
Player target = Bukkit.getPlayer(playerNameLowerCase);
|
||||||
PlayerCache.getInstance().removePlayer(playerNameLowerCase);
|
PlayerCache.getInstance().removePlayer(playerNameLowerCase);
|
||||||
Utils.setGroup(target, Utils.GroupType.UNREGISTERED);
|
Utils.setGroup(target, Utils.GroupType.UNREGISTERED);
|
||||||
@ -69,19 +71,21 @@ public class UnregisterCommand extends ExecutableCommand {
|
|||||||
BukkitTask id = scheduler.runTaskLaterAsynchronously(plugin, new TimeoutTask(plugin, playerNameLowerCase, target), delay);
|
BukkitTask id = scheduler.runTaskLaterAsynchronously(plugin, new TimeoutTask(plugin, playerNameLowerCase, target), delay);
|
||||||
LimboCache.getInstance().getLimboPlayer(playerNameLowerCase).setTimeoutTaskId(id);
|
LimboCache.getInstance().getLimboPlayer(playerNameLowerCase).setTimeoutTaskId(id);
|
||||||
}
|
}
|
||||||
LimboCache.getInstance().getLimboPlayer(playerNameLowerCase).setMessageTaskId(scheduler.runTaskAsynchronously(plugin, new MessageTask(plugin, playerNameLowerCase, m.send("reg_msg"), interval)));
|
LimboCache.getInstance().getLimboPlayer(playerNameLowerCase).setMessageTaskId(
|
||||||
|
scheduler.runTaskAsynchronously(plugin,
|
||||||
|
new MessageTask(plugin, playerNameLowerCase, m.retrieve(MessageKey.REGISTER_MESSAGE), interval)));
|
||||||
if (Settings.applyBlindEffect)
|
if (Settings.applyBlindEffect)
|
||||||
target.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, Settings.getRegistrationTimeout * 20, 2));
|
target.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, Settings.getRegistrationTimeout * 20, 2));
|
||||||
if (!Settings.isMovementAllowed && Settings.isRemoveSpeedEnabled) {
|
if (!Settings.isMovementAllowed && Settings.isRemoveSpeedEnabled) {
|
||||||
target.setWalkSpeed(0.0f);
|
target.setWalkSpeed(0.0f);
|
||||||
target.setFlySpeed(0.0f);
|
target.setFlySpeed(0.0f);
|
||||||
}
|
}
|
||||||
m.send(target, "unregistered");
|
m.send(target, MessageKey.UNREGISTERED_SUCCESS);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Show a status message
|
// Show a status message
|
||||||
m.send(sender, "unregistered");
|
m.send(sender, MessageKey.UNREGISTERED_SUCCESS);
|
||||||
ConsoleLogger.info(playerName + " unregistered");
|
ConsoleLogger.info(playerName + " unregistered");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,14 +1,17 @@
|
|||||||
package fr.xephi.authme.command.executable.authme;
|
package fr.xephi.authme.command.executable.authme;
|
||||||
|
|
||||||
|
import fr.xephi.authme.AuthMe;
|
||||||
|
import fr.xephi.authme.command.CommandParts;
|
||||||
|
import fr.xephi.authme.command.ExecutableCommand;
|
||||||
|
import fr.xephi.authme.settings.Settings;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
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 {
|
public class VersionCommand extends ExecutableCommand {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -23,8 +26,8 @@ public class VersionCommand extends ExecutableCommand {
|
|||||||
@Override
|
@Override
|
||||||
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
||||||
// Show some version info
|
// Show some version info
|
||||||
sender.sendMessage(ChatColor.GOLD + "==========[ " + AuthMe.PLUGIN_NAME.toUpperCase() + " ABOUT ]==========");
|
sender.sendMessage(ChatColor.GOLD + "==========[ " + Settings.helpHeader.toUpperCase() + " ABOUT ]==========");
|
||||||
sender.sendMessage(ChatColor.GOLD + "Version: " + ChatColor.WHITE + AuthMe.PLUGIN_NAME + " v" + AuthMe.getVersionName() + ChatColor.GRAY + " (code: " + AuthMe.getVersionCode() + ")");
|
sender.sendMessage(ChatColor.GOLD + "Version: " + ChatColor.WHITE + AuthMe.getPluginName() + " v" + AuthMe.getPluginVersion() + ChatColor.GRAY + " (build: " + AuthMe.getPluginBuildNumber() + ")");
|
||||||
sender.sendMessage(ChatColor.GOLD + "Developers:");
|
sender.sendMessage(ChatColor.GOLD + "Developers:");
|
||||||
printDeveloper(sender, "Xephi", "xephi59", "Lead Developer");
|
printDeveloper(sender, "Xephi", "xephi59", "Lead Developer");
|
||||||
printDeveloper(sender, "DNx5", "DNx5", "Developer");
|
printDeveloper(sender, "DNx5", "DNx5", "Developer");
|
||||||
@ -40,10 +43,10 @@ public class VersionCommand extends ExecutableCommand {
|
|||||||
/**
|
/**
|
||||||
* Print a developer with proper styling.
|
* Print a developer with proper styling.
|
||||||
*
|
*
|
||||||
* @param sender The command sender.
|
* @param sender The command sender.
|
||||||
* @param name The display name of the developer.
|
* @param name The display name of the developer.
|
||||||
* @param minecraftName The Minecraft username of the developer, if available.
|
* @param minecraftName The Minecraft username of the developer, if available.
|
||||||
* @param function The function of the developer.
|
* @param function The function of the developer.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("StringConcatenationInsideStringBufferAppend")
|
@SuppressWarnings("StringConcatenationInsideStringBufferAppend")
|
||||||
private void printDeveloper(CommandSender sender, String name, String minecraftName, String function) {
|
private void printDeveloper(CommandSender sender, String name, String minecraftName, String function) {
|
||||||
@ -53,13 +56,13 @@ public class VersionCommand extends ExecutableCommand {
|
|||||||
msg.append(name);
|
msg.append(name);
|
||||||
|
|
||||||
// Append the Minecraft name, if available
|
// Append the Minecraft name, if available
|
||||||
if(minecraftName.length() != 0)
|
if (minecraftName.length() != 0)
|
||||||
msg.append(ChatColor.GRAY + " // " + ChatColor.WHITE + minecraftName);
|
msg.append(ChatColor.GRAY + " // " + ChatColor.WHITE + minecraftName);
|
||||||
msg.append(ChatColor.GRAY + "" + ChatColor.ITALIC + " (" + function + ")");
|
msg.append(ChatColor.GRAY + "" + ChatColor.ITALIC + " (" + function + ")");
|
||||||
|
|
||||||
// Show the online status
|
// Show the online status
|
||||||
if(minecraftName.length() != 0)
|
if (minecraftName.length() != 0)
|
||||||
if(isPlayerOnline(minecraftName))
|
if (isPlayerOnline(minecraftName))
|
||||||
msg.append(ChatColor.GREEN + "" + ChatColor.ITALIC + " (In-Game)");
|
msg.append(ChatColor.GREEN + "" + ChatColor.ITALIC + " (In-Game)");
|
||||||
|
|
||||||
// Print the message
|
// Print the message
|
||||||
@ -74,9 +77,13 @@ public class VersionCommand extends ExecutableCommand {
|
|||||||
* @return True if the player is online, false otherwise.
|
* @return True if the player is online, false otherwise.
|
||||||
*/
|
*/
|
||||||
private boolean isPlayerOnline(String minecraftName) {
|
private boolean isPlayerOnline(String minecraftName) {
|
||||||
for(Player player : Bukkit.getOnlinePlayers())
|
// Note ljacqu 20151121: Generally you should use Utils#getOnlinePlayers to retrieve the list of online players.
|
||||||
if(player.getName().equalsIgnoreCase(minecraftName))
|
// If it's only used in a for-each loop such as here, it's fine. For other purposes, go through the Utils class.
|
||||||
|
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||||
|
if (player.getName().equalsIgnoreCase(minecraftName)) {
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,43 +1,24 @@
|
|||||||
package fr.xephi.authme.command.executable.captcha;
|
package fr.xephi.authme.command.executable.captcha;
|
||||||
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import fr.xephi.authme.AuthMe;
|
import fr.xephi.authme.AuthMe;
|
||||||
import fr.xephi.authme.cache.auth.PlayerCache;
|
import fr.xephi.authme.cache.auth.PlayerCache;
|
||||||
import fr.xephi.authme.command.CommandParts;
|
import fr.xephi.authme.command.CommandParts;
|
||||||
import fr.xephi.authme.command.ExecutableCommand;
|
import fr.xephi.authme.command.ExecutableCommand;
|
||||||
import fr.xephi.authme.security.RandomString;
|
import fr.xephi.authme.security.RandomString;
|
||||||
|
import fr.xephi.authme.settings.MessageKey;
|
||||||
import fr.xephi.authme.settings.Messages;
|
import fr.xephi.authme.settings.Messages;
|
||||||
import fr.xephi.authme.settings.Settings;
|
import fr.xephi.authme.settings.Settings;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
public class CaptchaCommand extends ExecutableCommand {
|
public class CaptchaCommand extends ExecutableCommand {
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute the command.
|
|
||||||
*
|
|
||||||
* @param sender The command sender.
|
|
||||||
* @param commandReference The command reference.
|
|
||||||
* @param commandArguments The command arguments.
|
|
||||||
*
|
|
||||||
* @return True if the command was executed successfully, false otherwise.
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
||||||
// AuthMe plugin instance
|
|
||||||
final AuthMe plugin = AuthMe.getInstance();
|
|
||||||
|
|
||||||
// Messages instance
|
|
||||||
final Messages m = Messages.getInstance();
|
|
||||||
|
|
||||||
// Random string instance, for captcha generation (I think) -- timvisee
|
|
||||||
RandomString randStr = new RandomString(Settings.captchaLength);
|
|
||||||
|
|
||||||
// Get the parameter values
|
|
||||||
String captcha = commandArguments.get(0);
|
|
||||||
|
|
||||||
// Make sure the current command executor is a player
|
// Make sure the current command executor is a player
|
||||||
if(!(sender instanceof Player)) {
|
if (!(sender instanceof Player)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,39 +26,48 @@ public class CaptchaCommand extends ExecutableCommand {
|
|||||||
final Player player = (Player) sender;
|
final Player player = (Player) sender;
|
||||||
final String playerNameLowerCase = player.getName().toLowerCase();
|
final String playerNameLowerCase = player.getName().toLowerCase();
|
||||||
|
|
||||||
|
// Get the parameter values
|
||||||
|
String captcha = commandArguments.get(0);
|
||||||
|
|
||||||
|
// AuthMe plugin instance
|
||||||
|
final AuthMe plugin = AuthMe.getInstance();
|
||||||
|
|
||||||
|
// Messages instance
|
||||||
|
final Messages m = plugin.getMessages();
|
||||||
|
|
||||||
// Command logic
|
// Command logic
|
||||||
if (PlayerCache.getInstance().isAuthenticated(playerNameLowerCase)) {
|
if (PlayerCache.getInstance().isAuthenticated(playerNameLowerCase)) {
|
||||||
m.send(player, "logged_in");
|
m.send(player, MessageKey.ALREADY_LOGGED_IN_ERROR);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Settings.useCaptcha) {
|
if (!Settings.useCaptcha) {
|
||||||
m.send(player, "usage_log");
|
m.send(player, MessageKey.USAGE_LOGIN);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (!plugin.cap.containsKey(playerNameLowerCase)) {
|
if (!plugin.cap.containsKey(playerNameLowerCase)) {
|
||||||
m.send(player, "usage_log");
|
m.send(player, MessageKey.USAGE_LOGIN);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Settings.useCaptcha && !captcha.equals(plugin.cap.get(playerNameLowerCase))) {
|
if (Settings.useCaptcha && !captcha.equals(plugin.cap.get(playerNameLowerCase))) {
|
||||||
plugin.cap.remove(playerNameLowerCase);
|
plugin.cap.remove(playerNameLowerCase);
|
||||||
plugin.cap.put(playerNameLowerCase, randStr.nextString());
|
String randStr = new RandomString(Settings.captchaLength).nextString();
|
||||||
for (String s : m.send("wrong_captcha")) {
|
plugin.cap.put(playerNameLowerCase, randStr);
|
||||||
|
for (String s : m.retrieve(MessageKey.CAPTCHA_WRONG_ERROR)) {
|
||||||
player.sendMessage(s.replace("THE_CAPTCHA", plugin.cap.get(playerNameLowerCase)));
|
player.sendMessage(s.replace("THE_CAPTCHA", plugin.cap.get(playerNameLowerCase)));
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
plugin.captcha.remove(playerNameLowerCase);
|
||||||
plugin.captcha.remove(playerNameLowerCase);
|
plugin.cap.remove(playerNameLowerCase);
|
||||||
plugin.cap.remove(playerNameLowerCase);
|
|
||||||
} catch (NullPointerException ignored) { }
|
|
||||||
|
|
||||||
// Show a status message
|
// Show a status message
|
||||||
m.send(player, "valid_captcha");
|
m.send(player, MessageKey.CAPTCHA_SUCCESS);
|
||||||
m.send(player, "login_msg");
|
m.send(player, MessageKey.LOGIN_MESSAGE);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,75 +1,73 @@
|
|||||||
package fr.xephi.authme.command.executable.changepassword;
|
package fr.xephi.authme.command.executable.changepassword;
|
||||||
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import fr.xephi.authme.AuthMe;
|
import fr.xephi.authme.AuthMe;
|
||||||
import fr.xephi.authme.cache.auth.PlayerCache;
|
import fr.xephi.authme.cache.auth.PlayerCache;
|
||||||
import fr.xephi.authme.command.CommandParts;
|
import fr.xephi.authme.command.CommandParts;
|
||||||
import fr.xephi.authme.command.ExecutableCommand;
|
import fr.xephi.authme.command.ExecutableCommand;
|
||||||
|
import fr.xephi.authme.settings.MessageKey;
|
||||||
import fr.xephi.authme.settings.Messages;
|
import fr.xephi.authme.settings.Messages;
|
||||||
import fr.xephi.authme.settings.Settings;
|
import fr.xephi.authme.settings.Settings;
|
||||||
import fr.xephi.authme.task.ChangePasswordTask;
|
import fr.xephi.authme.task.ChangePasswordTask;
|
||||||
|
import fr.xephi.authme.util.Wrapper;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
public class ChangePasswordCommand extends ExecutableCommand {
|
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
|
@Override
|
||||||
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
||||||
// AuthMe plugin instance
|
// Make sure the current command executor is a player
|
||||||
final AuthMe plugin = AuthMe.getInstance();
|
if (!(sender instanceof Player)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
// Messages instance
|
final Wrapper wrapper = Wrapper.getInstance();
|
||||||
final Messages m = Messages.getInstance();
|
final Messages m = wrapper.getMessages();
|
||||||
|
|
||||||
// Get the passwords
|
// Get the passwords
|
||||||
String playerPass = commandArguments.get(0);
|
String playerPass = commandArguments.get(0);
|
||||||
String playerPassVerify = commandArguments.get(1);
|
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
|
// Get the player instance and make sure it's authenticated
|
||||||
Player player = (Player) sender;
|
Player player = (Player) sender;
|
||||||
String name = player.getName().toLowerCase();
|
String name = player.getName().toLowerCase();
|
||||||
if (!PlayerCache.getInstance().isAuthenticated(name)) {
|
final PlayerCache playerCache = wrapper.getPlayerCache();
|
||||||
m.send(player, "not_logged_in");
|
if (!playerCache.isAuthenticated(name)) {
|
||||||
|
m.send(player, MessageKey.NOT_LOGGED_IN);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make sure the password is allowed
|
// Make sure the password is allowed
|
||||||
|
// TODO ljacqu 20151121: The password confirmation appears to be never verified
|
||||||
String playerPassLowerCase = playerPass.toLowerCase();
|
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)) {
|
if (playerPassLowerCase.contains("delete") || playerPassLowerCase.contains("where")
|
||||||
m.send(player, "password_error");
|
|| playerPassLowerCase.contains("insert") || playerPassLowerCase.contains("modify")
|
||||||
|
|| playerPassLowerCase.contains("from") || playerPassLowerCase.contains("select")
|
||||||
|
|| playerPassLowerCase.contains(";") || playerPassLowerCase.contains("null")
|
||||||
|
|| !playerPassLowerCase.matches(Settings.getPassRegex)) {
|
||||||
|
m.send(player, MessageKey.PASSWORD_MATCH_ERROR);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (playerPassLowerCase.equalsIgnoreCase(name)) {
|
if (playerPassLowerCase.equalsIgnoreCase(name)) {
|
||||||
m.send(player, "password_error_nick");
|
m.send(player, MessageKey.PASSWORD_IS_USERNAME_ERROR);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (playerPassLowerCase.length() < Settings.getPasswordMinLen || playerPassLowerCase.length() > Settings.passwordMaxLength) {
|
if (playerPassLowerCase.length() < Settings.getPasswordMinLen
|
||||||
m.send(player, "pass_len");
|
|| playerPassLowerCase.length() > Settings.passwordMaxLength) {
|
||||||
|
m.send(player, MessageKey.INVALID_PASSWORD_LENGTH);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (!Settings.unsafePasswords.isEmpty()) {
|
if (!Settings.unsafePasswords.isEmpty() && Settings.unsafePasswords.contains(playerPassLowerCase)) {
|
||||||
if (Settings.unsafePasswords.contains(playerPassLowerCase)) {
|
m.send(player, MessageKey.PASSWORD_UNSAFE_ERROR);
|
||||||
m.send(player, "password_error_unsafe");
|
return true;
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the password
|
// Set the password
|
||||||
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new ChangePasswordTask(plugin, player, playerPass, playerPassVerify));
|
final AuthMe plugin = wrapper.getAuthMe();
|
||||||
|
wrapper.getServer().getScheduler().runTaskAsynchronously(plugin,
|
||||||
|
new ChangePasswordTask(plugin, player, playerPass, playerPassVerify));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,28 +1,22 @@
|
|||||||
package fr.xephi.authme.command.executable.converter;
|
package fr.xephi.authme.command.executable.converter;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
|
|
||||||
import fr.xephi.authme.AuthMe;
|
import fr.xephi.authme.AuthMe;
|
||||||
import fr.xephi.authme.command.CommandParts;
|
import fr.xephi.authme.command.CommandParts;
|
||||||
import fr.xephi.authme.command.ExecutableCommand;
|
import fr.xephi.authme.command.ExecutableCommand;
|
||||||
import fr.xephi.authme.converter.Converter;
|
import fr.xephi.authme.converter.*;
|
||||||
import fr.xephi.authme.converter.CrazyLoginConverter;
|
import fr.xephi.authme.settings.MessageKey;
|
||||||
import fr.xephi.authme.converter.FlatToSql;
|
|
||||||
import fr.xephi.authme.converter.FlatToSqlite;
|
|
||||||
import fr.xephi.authme.converter.RakamakConverter;
|
|
||||||
import fr.xephi.authme.converter.RoyalAuthConverter;
|
|
||||||
import fr.xephi.authme.converter.SqlToFlat;
|
|
||||||
import fr.xephi.authme.converter.vAuthConverter;
|
|
||||||
import fr.xephi.authme.converter.xAuthConverter;
|
|
||||||
import fr.xephi.authme.settings.Messages;
|
import fr.xephi.authme.settings.Messages;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
public class ConverterCommand extends ExecutableCommand {
|
public class ConverterCommand extends ExecutableCommand {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute the command.
|
* Execute the command.
|
||||||
*
|
*
|
||||||
* @param sender The command sender.
|
* @param sender The command sender.
|
||||||
* @param commandReference The command reference.
|
* @param commandReference The command reference.
|
||||||
* @param commandArguments The command arguments.
|
* @param commandArguments The command arguments.
|
||||||
*
|
*
|
||||||
@ -34,7 +28,7 @@ public class ConverterCommand extends ExecutableCommand {
|
|||||||
final AuthMe plugin = AuthMe.getInstance();
|
final AuthMe plugin = AuthMe.getInstance();
|
||||||
|
|
||||||
// Messages instance
|
// Messages instance
|
||||||
final Messages m = Messages.getInstance();
|
final Messages m = plugin.getMessages();
|
||||||
|
|
||||||
// Get the conversion job
|
// Get the conversion job
|
||||||
String job = commandArguments.get(0);
|
String job = commandArguments.get(0);
|
||||||
@ -42,39 +36,39 @@ public class ConverterCommand extends ExecutableCommand {
|
|||||||
// Determine the job type
|
// Determine the job type
|
||||||
ConvertType jobType = ConvertType.fromName(job);
|
ConvertType jobType = ConvertType.fromName(job);
|
||||||
if (jobType == null) {
|
if (jobType == null) {
|
||||||
m.send(sender, "error");
|
m.send(sender, MessageKey.ERROR);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the proper converter instance
|
// Get the proper converter instance
|
||||||
Converter converter = null;
|
Converter converter = null;
|
||||||
switch (jobType) {
|
switch (jobType) {
|
||||||
case ftsql:
|
case ftsql:
|
||||||
converter = new FlatToSql();
|
converter = new FlatToSql();
|
||||||
break;
|
break;
|
||||||
case ftsqlite:
|
case ftsqlite:
|
||||||
converter = new FlatToSqlite(sender);
|
converter = new FlatToSqlite(sender);
|
||||||
break;
|
break;
|
||||||
case xauth:
|
case xauth:
|
||||||
converter = new xAuthConverter(plugin, sender);
|
converter = new xAuthConverter(plugin, sender);
|
||||||
break;
|
break;
|
||||||
case crazylogin:
|
case crazylogin:
|
||||||
converter = new CrazyLoginConverter(plugin, sender);
|
converter = new CrazyLoginConverter(plugin, sender);
|
||||||
break;
|
break;
|
||||||
case rakamak:
|
case rakamak:
|
||||||
converter = new RakamakConverter(plugin, sender);
|
converter = new RakamakConverter(plugin, sender);
|
||||||
break;
|
break;
|
||||||
case royalauth:
|
case royalauth:
|
||||||
converter = new RoyalAuthConverter(plugin);
|
converter = new RoyalAuthConverter(plugin);
|
||||||
break;
|
break;
|
||||||
case vauth:
|
case vauth:
|
||||||
converter = new vAuthConverter(plugin, sender);
|
converter = new vAuthConverter(plugin, sender);
|
||||||
break;
|
break;
|
||||||
case sqltoflat:
|
case sqltoflat:
|
||||||
converter = new SqlToFlat(plugin, sender);
|
converter = new SqlToFlat(plugin, sender);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run the convert job
|
// Run the convert job
|
||||||
@ -85,6 +79,8 @@ public class ConverterCommand extends ExecutableCommand {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
public enum ConvertType {
|
public enum ConvertType {
|
||||||
ftsql("flattosql"),
|
ftsql("flattosql"),
|
||||||
ftsqlite("flattosqlite"),
|
ftsqlite("flattosqlite"),
|
||||||
@ -95,16 +91,24 @@ public class ConverterCommand extends ExecutableCommand {
|
|||||||
vauth("vauth"),
|
vauth("vauth"),
|
||||||
sqltoflat("sqltoflat");
|
sqltoflat("sqltoflat");
|
||||||
|
|
||||||
String name;
|
final String name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for ConvertType.
|
||||||
|
*
|
||||||
|
* @param name String
|
||||||
|
*/
|
||||||
ConvertType(String name) {
|
ConvertType(String name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
String getName() {
|
/**
|
||||||
return this.name;
|
* Method fromName.
|
||||||
}
|
*
|
||||||
|
* @param name String
|
||||||
|
*
|
||||||
|
* @return ConvertType
|
||||||
|
*/
|
||||||
public static ConvertType fromName(String name) {
|
public static ConvertType fromName(String name) {
|
||||||
for (ConvertType type : ConvertType.values()) {
|
for (ConvertType type : ConvertType.values()) {
|
||||||
if (type.getName().equalsIgnoreCase(name))
|
if (type.getName().equalsIgnoreCase(name))
|
||||||
@ -112,5 +116,14 @@ public class ConverterCommand extends ExecutableCommand {
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method getName.
|
||||||
|
*
|
||||||
|
* @return String
|
||||||
|
*/
|
||||||
|
String getName() {
|
||||||
|
return this.name;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,46 +1,31 @@
|
|||||||
package fr.xephi.authme.command.executable.email;
|
package fr.xephi.authme.command.executable.email;
|
||||||
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import fr.xephi.authme.AuthMe;
|
import fr.xephi.authme.AuthMe;
|
||||||
import fr.xephi.authme.command.CommandParts;
|
import fr.xephi.authme.command.CommandParts;
|
||||||
import fr.xephi.authme.command.ExecutableCommand;
|
import fr.xephi.authme.command.ExecutableCommand;
|
||||||
import fr.xephi.authme.settings.Messages;
|
import fr.xephi.authme.util.Wrapper;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
public class AddEmailCommand extends ExecutableCommand {
|
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
|
@Override
|
||||||
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
||||||
// AuthMe plugin instance
|
|
||||||
final AuthMe plugin = AuthMe.getInstance();
|
|
||||||
|
|
||||||
// Messages instance
|
|
||||||
final Messages m = Messages.getInstance();
|
|
||||||
|
|
||||||
// Get the parameter values
|
|
||||||
String playerMail = commandArguments.get(0);
|
|
||||||
String playerMailVerify = commandArguments.get(1);
|
|
||||||
|
|
||||||
// Make sure the current command executor is a player
|
// Make sure the current command executor is a player
|
||||||
if (!(sender instanceof Player)) {
|
if (!(sender instanceof Player)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the player instance and name
|
// Get the parameter values
|
||||||
final Player player = (Player) sender;
|
String playerMail = commandArguments.get(0);
|
||||||
final String playerName = player.getName().toLowerCase();
|
String playerMailVerify = commandArguments.get(1);
|
||||||
|
|
||||||
// Command logic
|
// Get the player and perform email addition
|
||||||
plugin.management.performAddEmail(player, playerMail, playerMailVerify);
|
final AuthMe plugin = Wrapper.getInstance().getAuthMe();
|
||||||
|
final Player player = (Player) sender;
|
||||||
|
plugin.getManagement().performAddEmail(player, playerMail, playerMailVerify);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,46 +1,31 @@
|
|||||||
package fr.xephi.authme.command.executable.email;
|
package fr.xephi.authme.command.executable.email;
|
||||||
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import fr.xephi.authme.AuthMe;
|
import fr.xephi.authme.AuthMe;
|
||||||
import fr.xephi.authme.command.CommandParts;
|
import fr.xephi.authme.command.CommandParts;
|
||||||
import fr.xephi.authme.command.ExecutableCommand;
|
import fr.xephi.authme.command.ExecutableCommand;
|
||||||
import fr.xephi.authme.settings.Messages;
|
import fr.xephi.authme.util.Wrapper;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
public class ChangeEmailCommand extends ExecutableCommand {
|
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
|
@Override
|
||||||
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
||||||
// AuthMe plugin instance
|
|
||||||
final AuthMe plugin = AuthMe.getInstance();
|
|
||||||
|
|
||||||
// Messages instance
|
|
||||||
final Messages m = Messages.getInstance();
|
|
||||||
|
|
||||||
// Get the parameter values
|
|
||||||
String playerMailOld = commandArguments.get(0);
|
|
||||||
String playerMailNew = commandArguments.get(1);
|
|
||||||
|
|
||||||
// Make sure the current command executor is a player
|
// Make sure the current command executor is a player
|
||||||
if (!(sender instanceof Player)) {
|
if (!(sender instanceof Player)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the player instance and name
|
// Get the parameter values
|
||||||
final Player player = (Player) sender;
|
String playerMailOld = commandArguments.get(0);
|
||||||
final String playerName = player.getName();
|
String playerMailNew = commandArguments.get(1);
|
||||||
|
|
||||||
// Command logic
|
// Get the player instance and execute action
|
||||||
plugin.management.performChangeEmail(player, playerMailOld, playerMailNew);
|
final AuthMe plugin = Wrapper.getInstance().getAuthMe();
|
||||||
|
final Player player = (Player) sender;
|
||||||
|
plugin.getManagement().performChangeEmail(player, playerMailOld, playerMailNew);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,10 +1,5 @@
|
|||||||
package fr.xephi.authme.command.executable.email;
|
package fr.xephi.authme.command.executable.email;
|
||||||
|
|
||||||
import java.security.NoSuchAlgorithmException;
|
|
||||||
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import fr.xephi.authme.AuthMe;
|
import fr.xephi.authme.AuthMe;
|
||||||
import fr.xephi.authme.ConsoleLogger;
|
import fr.xephi.authme.ConsoleLogger;
|
||||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||||
@ -13,48 +8,45 @@ import fr.xephi.authme.command.CommandParts;
|
|||||||
import fr.xephi.authme.command.ExecutableCommand;
|
import fr.xephi.authme.command.ExecutableCommand;
|
||||||
import fr.xephi.authme.security.PasswordSecurity;
|
import fr.xephi.authme.security.PasswordSecurity;
|
||||||
import fr.xephi.authme.security.RandomString;
|
import fr.xephi.authme.security.RandomString;
|
||||||
|
import fr.xephi.authme.settings.MessageKey;
|
||||||
import fr.xephi.authme.settings.Messages;
|
import fr.xephi.authme.settings.Messages;
|
||||||
import fr.xephi.authme.settings.Settings;
|
import fr.xephi.authme.settings.Settings;
|
||||||
|
import fr.xephi.authme.util.Wrapper;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
public class RecoverEmailCommand extends ExecutableCommand {
|
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
|
@Override
|
||||||
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
||||||
// AuthMe plugin instance
|
// Make sure the current command executor is a player
|
||||||
final AuthMe plugin = AuthMe.getInstance();
|
if (!(sender instanceof Player)) {
|
||||||
|
return true;
|
||||||
// Messages instance
|
}
|
||||||
final Messages m = Messages.getInstance();
|
|
||||||
|
|
||||||
// Get the parameter values
|
// Get the parameter values
|
||||||
String playerMail = commandArguments.get(0);
|
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
|
// Get the player instance and name
|
||||||
final Player player = (Player) sender;
|
final Player player = (Player) sender;
|
||||||
final String playerName = player.getName();
|
final String playerName = player.getName();
|
||||||
|
|
||||||
// Command logic
|
// Command logic
|
||||||
|
final Wrapper wrapper = Wrapper.getInstance();
|
||||||
|
final AuthMe plugin = wrapper.getAuthMe();
|
||||||
|
final Messages m = wrapper.getMessages();
|
||||||
|
|
||||||
if (plugin.mail == null) {
|
if (plugin.mail == null) {
|
||||||
m.send(player, "error");
|
m.send(player, MessageKey.ERROR);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (plugin.database.isAuthAvailable(playerName)) {
|
if (plugin.database.isAuthAvailable(playerName)) {
|
||||||
if (PlayerCache.getInstance().isAuthenticated(playerName)) {
|
if (PlayerCache.getInstance().isAuthenticated(playerName)) {
|
||||||
m.send(player, "logged_in");
|
m.send(player, MessageKey.ALREADY_LOGGED_IN_ERROR);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
@ -67,29 +59,29 @@ public class RecoverEmailCommand extends ExecutableCommand {
|
|||||||
} else if (plugin.database.isAuthAvailable(playerName)) {
|
} else if (plugin.database.isAuthAvailable(playerName)) {
|
||||||
auth = plugin.database.getAuth(playerName);
|
auth = plugin.database.getAuth(playerName);
|
||||||
} else {
|
} else {
|
||||||
m.send(player, "unknown_user");
|
m.send(player, MessageKey.UNKNOWN_USER);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (Settings.getmailAccount.equals("") || Settings.getmailAccount.isEmpty()) {
|
if (Settings.getmailAccount.equals("") || Settings.getmailAccount.isEmpty()) {
|
||||||
m.send(player, "error");
|
m.send(player, MessageKey.ERROR);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!playerMail.equalsIgnoreCase(auth.getEmail()) || playerMail.equalsIgnoreCase("your@email.com") || auth.getEmail().equalsIgnoreCase("your@email.com")) {
|
if (!playerMail.equalsIgnoreCase(auth.getEmail()) || playerMail.equalsIgnoreCase("your@email.com") || auth.getEmail().equalsIgnoreCase("your@email.com")) {
|
||||||
m.send(player, "email_invalid");
|
m.send(player, MessageKey.INVALID_EMAIL);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
auth.setHash(hashNew);
|
auth.setHash(hashNew);
|
||||||
plugin.database.updatePassword(auth);
|
plugin.database.updatePassword(auth);
|
||||||
plugin.mail.main(auth, thePass);
|
plugin.mail.main(auth, thePass);
|
||||||
m.send(player, "email_send");
|
m.send(player, MessageKey.RECOVERY_EMAIL_SENT_MESSAGE);
|
||||||
} catch (NoSuchAlgorithmException | NoClassDefFoundError ex) {
|
} catch (NoSuchAlgorithmException | NoClassDefFoundError ex) {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
ConsoleLogger.showError(ex.getMessage());
|
ConsoleLogger.showError(ex.getMessage());
|
||||||
m.send(sender, "error");
|
m.send(sender, MessageKey.ERROR);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
m.send(player, "reg_email_msg");
|
m.send(player, MessageKey.REGISTER_EMAIL_MESSAGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@ -1,41 +1,30 @@
|
|||||||
package fr.xephi.authme.command.executable.login;
|
package fr.xephi.authme.command.executable.login;
|
||||||
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import fr.xephi.authme.AuthMe;
|
import fr.xephi.authme.AuthMe;
|
||||||
import fr.xephi.authme.command.CommandParts;
|
import fr.xephi.authme.command.CommandParts;
|
||||||
import fr.xephi.authme.command.ExecutableCommand;
|
import fr.xephi.authme.command.ExecutableCommand;
|
||||||
|
import fr.xephi.authme.util.Wrapper;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
public class LoginCommand extends 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
|
@Override
|
||||||
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
||||||
// AuthMe plugin instance
|
|
||||||
final AuthMe plugin = AuthMe.getInstance();
|
|
||||||
|
|
||||||
// Make sure the current command executor is a player
|
// Make sure the current command executor is a player
|
||||||
if(!(sender instanceof Player)) {
|
if (!(sender instanceof Player)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the player instance
|
// Get the necessary objects
|
||||||
|
final AuthMe plugin = Wrapper.getInstance().getAuthMe();
|
||||||
final Player player = (Player) sender;
|
final Player player = (Player) sender;
|
||||||
|
final String password = commandArguments.get(0);
|
||||||
|
|
||||||
// Get the password
|
// Log the player in
|
||||||
String playerPass = commandArguments.get(0);
|
plugin.getManagement().performLogin(player, password, false);
|
||||||
|
|
||||||
// Login the player
|
|
||||||
plugin.management.performLogin(player, playerPass, false);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,38 +1,29 @@
|
|||||||
package fr.xephi.authme.command.executable.logout;
|
package fr.xephi.authme.command.executable.logout;
|
||||||
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import fr.xephi.authme.AuthMe;
|
import fr.xephi.authme.AuthMe;
|
||||||
import fr.xephi.authme.command.CommandParts;
|
import fr.xephi.authme.command.CommandParts;
|
||||||
import fr.xephi.authme.command.ExecutableCommand;
|
import fr.xephi.authme.command.ExecutableCommand;
|
||||||
|
import fr.xephi.authme.util.Wrapper;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
public class LogoutCommand extends 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
|
@Override
|
||||||
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
||||||
// AuthMe plugin instance
|
|
||||||
final AuthMe plugin = AuthMe.getInstance();
|
|
||||||
|
|
||||||
// Make sure the current command executor is a player
|
// Make sure the current command executor is a player
|
||||||
if(!(sender instanceof Player)) {
|
if (!(sender instanceof Player)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the player instance
|
// Get the player instance
|
||||||
|
final AuthMe plugin = Wrapper.getInstance().getAuthMe();
|
||||||
final Player player = (Player) sender;
|
final Player player = (Player) sender;
|
||||||
|
|
||||||
// Logout the player
|
// Logout the player
|
||||||
plugin.management.performLogout(player);
|
plugin.getManagement().performLogout(player);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,33 +1,23 @@
|
|||||||
package fr.xephi.authme.command.executable.register;
|
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.AuthMe;
|
||||||
import fr.xephi.authme.command.CommandParts;
|
import fr.xephi.authme.command.CommandParts;
|
||||||
import fr.xephi.authme.command.ExecutableCommand;
|
import fr.xephi.authme.command.ExecutableCommand;
|
||||||
|
import fr.xephi.authme.process.Management;
|
||||||
import fr.xephi.authme.security.RandomString;
|
import fr.xephi.authme.security.RandomString;
|
||||||
|
import fr.xephi.authme.settings.MessageKey;
|
||||||
import fr.xephi.authme.settings.Messages;
|
import fr.xephi.authme.settings.Messages;
|
||||||
import fr.xephi.authme.settings.Settings;
|
import fr.xephi.authme.settings.Settings;
|
||||||
|
import fr.xephi.authme.util.Wrapper;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
public class RegisterCommand extends ExecutableCommand {
|
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
|
@Override
|
||||||
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
||||||
// AuthMe plugin instance
|
|
||||||
final AuthMe plugin = AuthMe.getInstance();
|
|
||||||
|
|
||||||
// Messages instance
|
|
||||||
final Messages m = Messages.getInstance();
|
|
||||||
|
|
||||||
// Make sure the sender is a player
|
// Make sure the sender is a player
|
||||||
if (!(sender instanceof Player)) {
|
if (!(sender instanceof Player)) {
|
||||||
@ -35,36 +25,41 @@ public class RegisterCommand extends ExecutableCommand {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final Wrapper wrapper = Wrapper.getInstance();
|
||||||
|
final AuthMe plugin = wrapper.getAuthMe();
|
||||||
|
final Messages m = wrapper.getMessages();
|
||||||
|
|
||||||
// Make sure the command arguments are valid
|
// Make sure the command arguments are valid
|
||||||
final Player player = (Player) sender;
|
final Player player = (Player) sender;
|
||||||
if (commandArguments.getCount() == 0 || (Settings.getEnablePasswordVerifier && commandArguments.getCount() < 2)) {
|
if (commandArguments.getCount() == 0 || (Settings.getEnablePasswordVerifier && commandArguments.getCount() < 2)) {
|
||||||
m.send(player, "usage_reg");
|
m.send(player, MessageKey.USAGE_REGISTER);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final Management management = plugin.getManagement();
|
||||||
if (Settings.emailRegistration && !Settings.getmailAccount.isEmpty()) {
|
if (Settings.emailRegistration && !Settings.getmailAccount.isEmpty()) {
|
||||||
if (Settings.doubleEmailCheck) {
|
if (Settings.doubleEmailCheck) {
|
||||||
if (commandArguments.getCount() < 2 || !commandArguments.get(0).equals(commandArguments.get(1))) {
|
if (commandArguments.getCount() < 2 || !commandArguments.get(0).equals(commandArguments.get(1))) {
|
||||||
m.send(player, "usage_reg");
|
m.send(player, MessageKey.USAGE_REGISTER);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
final String email = commandArguments.get(0);
|
final String email = commandArguments.get(0);
|
||||||
if (!Settings.isEmailCorrect(email)) {
|
if (!Settings.isEmailCorrect(email)) {
|
||||||
m.send(player, "email_invalid");
|
m.send(player, MessageKey.INVALID_EMAIL);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
RandomString rand = new RandomString(Settings.getRecoveryPassLength);
|
final String thePass = new RandomString(Settings.getRecoveryPassLength).nextString();
|
||||||
final String thePass = rand.nextString();
|
management.performRegister(player, thePass, email);
|
||||||
plugin.management.performRegister(player, thePass, email);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (commandArguments.getCount() > 1 && Settings.getEnablePasswordVerifier)
|
if (commandArguments.getCount() > 1 && Settings.getEnablePasswordVerifier) {
|
||||||
if (!commandArguments.get(0).equals(commandArguments.get(1))) {
|
if (!commandArguments.get(0).equals(commandArguments.get(1))) {
|
||||||
m.send(player, "password_error");
|
m.send(player, MessageKey.PASSWORD_IS_USERNAME_ERROR);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
plugin.management.performRegister(player, commandArguments.get(0), "");
|
}
|
||||||
|
management.performRegister(player, commandArguments.get(0), "");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,20 +1,22 @@
|
|||||||
package fr.xephi.authme.command.executable.unregister;
|
package fr.xephi.authme.command.executable.unregister;
|
||||||
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import fr.xephi.authme.AuthMe;
|
import fr.xephi.authme.AuthMe;
|
||||||
import fr.xephi.authme.cache.auth.PlayerCache;
|
import fr.xephi.authme.cache.auth.PlayerCache;
|
||||||
import fr.xephi.authme.command.CommandParts;
|
import fr.xephi.authme.command.CommandParts;
|
||||||
import fr.xephi.authme.command.ExecutableCommand;
|
import fr.xephi.authme.command.ExecutableCommand;
|
||||||
|
import fr.xephi.authme.settings.MessageKey;
|
||||||
import fr.xephi.authme.settings.Messages;
|
import fr.xephi.authme.settings.Messages;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
public class UnregisterCommand extends ExecutableCommand {
|
public class UnregisterCommand extends ExecutableCommand {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute the command.
|
* Execute the command.
|
||||||
*
|
*
|
||||||
* @param sender The command sender.
|
* @param sender The command sender.
|
||||||
* @param commandReference The command reference.
|
* @param commandReference The command reference.
|
||||||
* @param commandArguments The command arguments.
|
* @param commandArguments The command arguments.
|
||||||
*
|
*
|
||||||
@ -26,10 +28,10 @@ public class UnregisterCommand extends ExecutableCommand {
|
|||||||
final AuthMe plugin = AuthMe.getInstance();
|
final AuthMe plugin = AuthMe.getInstance();
|
||||||
|
|
||||||
// Messages instance
|
// Messages instance
|
||||||
final Messages m = Messages.getInstance();
|
final Messages m = plugin.getMessages();
|
||||||
|
|
||||||
// Make sure the current command executor is a player
|
// Make sure the current command executor is a player
|
||||||
if(!(sender instanceof Player)) {
|
if (!(sender instanceof Player)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -42,7 +44,7 @@ public class UnregisterCommand extends ExecutableCommand {
|
|||||||
|
|
||||||
// Make sure the player is authenticated
|
// Make sure the player is authenticated
|
||||||
if (!PlayerCache.getInstance().isAuthenticated(playerNameLowerCase)) {
|
if (!PlayerCache.getInstance().isAuthenticated(playerNameLowerCase)) {
|
||||||
m.send(player, "not_logged_in");
|
m.send(player, MessageKey.NOT_LOGGED_IN);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,28 +1,30 @@
|
|||||||
package fr.xephi.authme.command.help;
|
package fr.xephi.authme.command.help;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import fr.xephi.authme.AuthMe;
|
import fr.xephi.authme.AuthMe;
|
||||||
import fr.xephi.authme.command.CommandArgumentDescription;
|
import fr.xephi.authme.command.CommandArgumentDescription;
|
||||||
import fr.xephi.authme.command.CommandDescription;
|
import fr.xephi.authme.command.CommandDescription;
|
||||||
import fr.xephi.authme.command.CommandParts;
|
import fr.xephi.authme.command.CommandParts;
|
||||||
import fr.xephi.authme.command.CommandPermissions;
|
import fr.xephi.authme.command.CommandPermissions;
|
||||||
|
import fr.xephi.authme.permission.PermissionNode;
|
||||||
import fr.xephi.authme.util.StringUtils;
|
import fr.xephi.authme.util.StringUtils;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
public class HelpPrinter {
|
public class HelpPrinter {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Print the command help information.
|
* Print the command help information.
|
||||||
*
|
*
|
||||||
* @param sender The command sender to print the help to.
|
* @param sender The command sender to print the help to.
|
||||||
* @param command The command to print.
|
* @param command The command to print.
|
||||||
* @param commandReference The command reference used.
|
* @param commandReference The command reference used.
|
||||||
*/
|
*/
|
||||||
public static void printCommand(CommandSender sender, CommandDescription command, CommandParts commandReference) {
|
public static void printCommand(CommandSender sender, CommandDescription command, CommandParts commandReference) {
|
||||||
@ -33,16 +35,16 @@ public class HelpPrinter {
|
|||||||
/**
|
/**
|
||||||
* Print the command help description information. This will print both the short, as the detailed description if available.
|
* Print the command help description information. This will print both the short, as the detailed description if available.
|
||||||
*
|
*
|
||||||
* @param sender The command sender to print the help to.
|
* @param sender The command sender to print the help to.
|
||||||
* @param command The command to print the description help for.
|
* @param command The command to print the description help for.
|
||||||
*/
|
*/
|
||||||
public static void printCommandDescription(CommandSender sender, CommandDescription command) {
|
public static void printCommandDescription(CommandSender sender, CommandDescription command) {
|
||||||
// Print the regular description, if available
|
// Print the regular description, if available
|
||||||
if(command.hasDescription())
|
if (command.hasDescription())
|
||||||
sender.sendMessage(ChatColor.GOLD + "Short Description: " + ChatColor.WHITE + command.getDescription());
|
sender.sendMessage(ChatColor.GOLD + "Short Description: " + ChatColor.WHITE + command.getDescription());
|
||||||
|
|
||||||
// Print the detailed description, if available
|
// Print the detailed description, if available
|
||||||
if(command.hasDetailedDescription()) {
|
if (!StringUtils.isEmpty(command.getDetailedDescription())) {
|
||||||
sender.sendMessage(ChatColor.GOLD + "Detailed Description:");
|
sender.sendMessage(ChatColor.GOLD + "Detailed Description:");
|
||||||
sender.sendMessage(ChatColor.WHITE + " " + command.getDetailedDescription());
|
sender.sendMessage(ChatColor.WHITE + " " + command.getDetailedDescription());
|
||||||
}
|
}
|
||||||
@ -51,26 +53,26 @@ public class HelpPrinter {
|
|||||||
/**
|
/**
|
||||||
* Print the command help arguments information if available.
|
* Print the command help arguments information if available.
|
||||||
*
|
*
|
||||||
* @param sender The command sender to print the help to.
|
* @param sender The command sender to print the help to.
|
||||||
* @param command The command to print the argument help for.
|
* @param command The command to print the argument help for.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("StringConcatenationInsideStringBufferAppend")
|
@SuppressWarnings("StringConcatenationInsideStringBufferAppend")
|
||||||
public static void printArguments(CommandSender sender, CommandDescription command) {
|
public static void printArguments(CommandSender sender, CommandDescription command) {
|
||||||
// Make sure there are any commands to print
|
// Make sure there are any commands to print
|
||||||
if(!command.hasArguments() && command.getMaximumArguments() >= 0)
|
if (!command.hasArguments() && command.getMaximumArguments() >= 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Print the header
|
// Print the header
|
||||||
sender.sendMessage(ChatColor.GOLD + "Arguments:");
|
sender.sendMessage(ChatColor.GOLD + "Arguments:");
|
||||||
|
|
||||||
// Print each argument
|
// Print each argument
|
||||||
for(CommandArgumentDescription arg : command.getArguments()) {
|
for (CommandArgumentDescription arg : command.getArguments()) {
|
||||||
// Create a string builder to build the syntax in
|
// Create a string builder to build the syntax in
|
||||||
StringBuilder argString = new StringBuilder();
|
StringBuilder argString = new StringBuilder();
|
||||||
argString.append(" " + ChatColor.YELLOW + ChatColor.ITALIC + arg.getLabel() + " : " + ChatColor.WHITE + arg.getDescription());
|
argString.append(" " + ChatColor.YELLOW + ChatColor.ITALIC + arg.getLabel() + " : " + ChatColor.WHITE + arg.getDescription());
|
||||||
|
|
||||||
// Suffix a note if the command is optional
|
// Suffix a note if the command is optional
|
||||||
if(arg.isOptional())
|
if (arg.isOptional())
|
||||||
argString.append(ChatColor.GRAY + "" + ChatColor.ITALIC + " (Optional)");
|
argString.append(ChatColor.GRAY + "" + ChatColor.ITALIC + " (Optional)");
|
||||||
|
|
||||||
// Print the syntax
|
// Print the syntax
|
||||||
@ -78,57 +80,57 @@ public class HelpPrinter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Show the unlimited arguments argument
|
// Show the unlimited arguments argument
|
||||||
if(command.getMaximumArguments() < 0)
|
if (command.getMaximumArguments() < 0)
|
||||||
sender.sendMessage(" " + ChatColor.YELLOW + ChatColor.ITALIC + "... : " + ChatColor.WHITE + "Any additional arguments." + ChatColor.GRAY + ChatColor.ITALIC + " (Optional)");
|
sender.sendMessage(" " + ChatColor.YELLOW + ChatColor.ITALIC + "... : " + ChatColor.WHITE + "Any additional arguments." + ChatColor.GRAY + ChatColor.ITALIC + " (Optional)");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Print the command help permissions information if available.
|
* Print the command help permissions information if available.
|
||||||
*
|
*
|
||||||
* @param sender The command sender to print the help to.
|
* @param sender The command sender to print the help to.
|
||||||
* @param command The command to print the permissions help for.
|
* @param command The command to print the permissions help for.
|
||||||
*/
|
*/
|
||||||
public static void printPermissions(CommandSender sender, CommandDescription command) {
|
public static void printPermissions(CommandSender sender, CommandDescription command) {
|
||||||
// Get the permissions and make sure it isn't null
|
// Get the permissions and make sure it isn't null
|
||||||
CommandPermissions permissions = command.getCommandPermissions();
|
CommandPermissions permissions = command.getCommandPermissions();
|
||||||
if(permissions == null)
|
if (permissions == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Make sure any permission node is set
|
// Make sure any permission node is set
|
||||||
if(permissions.getPermissionNodeCount() <= 0)
|
if (permissions.getPermissionNodeCount() <= 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Print the header
|
// Print the header
|
||||||
sender.sendMessage(ChatColor.GOLD + "Permissions:");
|
sender.sendMessage(ChatColor.GOLD + "Permissions:");
|
||||||
|
|
||||||
// Print each node
|
// Print each node
|
||||||
for(String node : permissions.getPermissionNodes()) {
|
for (PermissionNode node : permissions.getPermissionNodes()) {
|
||||||
boolean nodePermission = true;
|
boolean nodePermission = true;
|
||||||
if(sender instanceof Player)
|
if (sender instanceof Player)
|
||||||
nodePermission = AuthMe.getInstance().authmePermissible((Player) sender, node);
|
nodePermission = AuthMe.getInstance().getPermissionsManager().hasPermission((Player) sender, node);
|
||||||
final String nodePermsString = ChatColor.GRAY + (nodePermission ? ChatColor.ITALIC + " (Permission!)" : ChatColor.ITALIC + " (No Permission!)");
|
final String nodePermsString = ChatColor.GRAY + (nodePermission ? ChatColor.ITALIC + " (Permission!)" : ChatColor.ITALIC + " (No Permission!)");
|
||||||
sender.sendMessage(" " + ChatColor.YELLOW + ChatColor.ITALIC + node + nodePermsString);
|
sender.sendMessage(" " + ChatColor.YELLOW + ChatColor.ITALIC + node + nodePermsString);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Print the default permission
|
// Print the default permission
|
||||||
switch(permissions.getDefaultPermission()) {
|
switch (permissions.getDefaultPermission()) {
|
||||||
case ALLOWED:
|
case ALLOWED:
|
||||||
sender.sendMessage(ChatColor.GOLD + " Default: " + ChatColor.GRAY + ChatColor.ITALIC + "Permission!");
|
sender.sendMessage(ChatColor.GOLD + " Default: " + ChatColor.GRAY + ChatColor.ITALIC + "Permission!");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case OP_ONLY:
|
case OP_ONLY:
|
||||||
final String defaultPermsString = ChatColor.GRAY + (permissions.getDefaultPermissionCommandSender(sender) ? ChatColor.ITALIC + " (Permission!)" : ChatColor.ITALIC + " (No Permission!)");
|
final String defaultPermsString = ChatColor.GRAY + (permissions.getDefaultPermissionCommandSender(sender) ? ChatColor.ITALIC + " (Permission!)" : ChatColor.ITALIC + " (No Permission!)");
|
||||||
sender.sendMessage(ChatColor.GOLD + " Default: " + ChatColor.YELLOW + ChatColor.ITALIC + "OP's Only!" + defaultPermsString);
|
sender.sendMessage(ChatColor.GOLD + " Default: " + ChatColor.YELLOW + ChatColor.ITALIC + "OP's Only!" + defaultPermsString);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case NOT_ALLOWED:
|
case NOT_ALLOWED:
|
||||||
default:
|
default:
|
||||||
sender.sendMessage(ChatColor.GOLD + " Default: " + ChatColor.GRAY + ChatColor.ITALIC + "No Permission!");
|
sender.sendMessage(ChatColor.GOLD + " Default: " + ChatColor.GRAY + ChatColor.ITALIC + "No Permission!");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Print the permission result
|
// Print the permission result
|
||||||
if(permissions.hasPermission(sender))
|
if (permissions.hasPermission(sender))
|
||||||
sender.sendMessage(ChatColor.GOLD + " Result: " + ChatColor.GREEN + ChatColor.ITALIC + "Permission!");
|
sender.sendMessage(ChatColor.GOLD + " Result: " + ChatColor.GREEN + ChatColor.ITALIC + "Permission!");
|
||||||
else
|
else
|
||||||
sender.sendMessage(ChatColor.GOLD + " Result: " + ChatColor.DARK_RED + ChatColor.ITALIC + "No Permission!");
|
sender.sendMessage(ChatColor.GOLD + " Result: " + ChatColor.DARK_RED + ChatColor.ITALIC + "No Permission!");
|
||||||
@ -137,13 +139,13 @@ public class HelpPrinter {
|
|||||||
/**
|
/**
|
||||||
* Print the command help alternatives information if available.
|
* Print the command help alternatives information if available.
|
||||||
*
|
*
|
||||||
* @param sender The command sender to print the help to.
|
* @param sender The command sender to print the help to.
|
||||||
* @param command The command used.
|
* @param command The command used.
|
||||||
* @param commandReference The original command reference used for this command.
|
* @param commandReference The original command reference used for this command.
|
||||||
*/
|
*/
|
||||||
public static void printAlternatives(CommandSender sender, CommandDescription command, CommandParts commandReference) {
|
public static void printAlternatives(CommandSender sender, CommandDescription command, CommandParts commandReference) {
|
||||||
// Make sure there are any alternatives
|
// Make sure there are any alternatives
|
||||||
if(command.getLabels().size() <= 1)
|
if (command.getLabels().size() <= 1)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Print the header
|
// Print the header
|
||||||
@ -154,9 +156,9 @@ public class HelpPrinter {
|
|||||||
|
|
||||||
// Create a list of alternatives
|
// Create a list of alternatives
|
||||||
List<String> alternatives = new ArrayList<>();
|
List<String> alternatives = new ArrayList<>();
|
||||||
for(String entry : command.getLabels()) {
|
for (String entry : command.getLabels()) {
|
||||||
// Exclude the proper argument
|
// Exclude the proper argument
|
||||||
if(entry.equalsIgnoreCase(usedLabel))
|
if (entry.equalsIgnoreCase(usedLabel))
|
||||||
continue;
|
continue;
|
||||||
alternatives.add(entry);
|
alternatives.add(entry);
|
||||||
}
|
}
|
||||||
@ -170,27 +172,27 @@ public class HelpPrinter {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Print each alternative with proper syntax
|
// Print each alternative with proper syntax
|
||||||
for(String alternative : alternatives)
|
for (String alternative : alternatives)
|
||||||
sender.sendMessage(" " + HelpSyntaxHelper.getCommandSyntax(command, commandReference, alternative, true));
|
sender.sendMessage(" " + HelpSyntaxHelper.getCommandSyntax(command, commandReference, alternative, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Print the command help child's information if available.
|
* Print the command help child's information if available.
|
||||||
*
|
*
|
||||||
* @param sender The command sender to print the help to.
|
* @param sender The command sender to print the help to.
|
||||||
* @param command The command to print the help for.
|
* @param command The command to print the help for.
|
||||||
* @param commandReference The original command reference used for this command.
|
* @param commandReference The original command reference used for this command.
|
||||||
*/
|
*/
|
||||||
public static void printChildren(CommandSender sender, CommandDescription command, CommandParts commandReference) {
|
public static void printChildren(CommandSender sender, CommandDescription command, CommandParts commandReference) {
|
||||||
// Make sure there are child's
|
// Make sure there are child's
|
||||||
if(command.getChildren().size() <= 0)
|
if (command.getChildren().size() <= 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Print the header
|
// Print the header
|
||||||
sender.sendMessage(ChatColor.GOLD + "Commands:");
|
sender.sendMessage(ChatColor.GOLD + "Commands:");
|
||||||
|
|
||||||
// Loop through each child
|
// Loop through each child
|
||||||
for(CommandDescription child : command.getChildren())
|
for (CommandDescription child : command.getChildren())
|
||||||
sender.sendMessage(" " + HelpSyntaxHelper.getCommandSyntax(child, commandReference, null, false) + ChatColor.GRAY + ChatColor.ITALIC + " : " + child.getDescription());
|
sender.sendMessage(" " + HelpSyntaxHelper.getCommandSyntax(child, commandReference, null, false) + ChatColor.GRAY + ChatColor.ITALIC + " : " + child.getDescription());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,19 +1,22 @@
|
|||||||
package fr.xephi.authme.command.help;
|
package fr.xephi.authme.command.help;
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
|
|
||||||
import fr.xephi.authme.AuthMe;
|
import fr.xephi.authme.AuthMe;
|
||||||
import fr.xephi.authme.command.CommandDescription;
|
import fr.xephi.authme.command.CommandDescription;
|
||||||
import fr.xephi.authme.command.CommandParts;
|
import fr.xephi.authme.command.CommandParts;
|
||||||
import fr.xephi.authme.command.FoundCommandResult;
|
import fr.xephi.authme.command.FoundCommandResult;
|
||||||
|
import fr.xephi.authme.settings.Settings;
|
||||||
|
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
public class HelpProvider {
|
public class HelpProvider {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show help for a specific command.
|
* Show help for a specific command.
|
||||||
*
|
*
|
||||||
* @param sender The command sender the help needs to be shown to.
|
* @param sender The command sender the help needs to be shown to.
|
||||||
* @param reference The command reference to the help command.
|
* @param reference The command reference to the help command.
|
||||||
* @param helpQuery The query to show help for.
|
* @param helpQuery The query to show help for.
|
||||||
*/
|
*/
|
||||||
@ -24,31 +27,31 @@ public class HelpProvider {
|
|||||||
/**
|
/**
|
||||||
* Show help for a specific command.
|
* Show help for a specific command.
|
||||||
*
|
*
|
||||||
* @param sender The command sender the help needs to be shown to.
|
* @param sender The command sender the help needs to be shown to.
|
||||||
* @param reference The command reference to the help command.
|
* @param reference The command reference to the help command.
|
||||||
* @param helpQuery The query to show help for.
|
* @param helpQuery The query to show help for.
|
||||||
* @param showCommand True to show the command.
|
* @param showCommand True to show the command.
|
||||||
* @param showDescription True to show the command description, both the short and detailed description.
|
* @param showDescription True to show the command description, both the short and detailed description.
|
||||||
* @param showArguments True to show the command argument help.
|
* @param showArguments True to show the command argument help.
|
||||||
* @param showPermissions True to show the command permission help.
|
* @param showPermissions True to show the command permission help.
|
||||||
* @param showAlternatives True to show the command alternatives.
|
* @param showAlternatives True to show the command alternatives.
|
||||||
* @param showCommands True to show the child commands.
|
* @param showCommands True to show the child commands.
|
||||||
*/
|
*/
|
||||||
public static void showHelp(CommandSender sender, CommandParts reference, CommandParts helpQuery, boolean showCommand, boolean showDescription, boolean showArguments, boolean showPermissions, boolean showAlternatives, boolean showCommands) {
|
public static void showHelp(CommandSender sender, CommandParts reference, CommandParts helpQuery, boolean showCommand, boolean showDescription, boolean showArguments, boolean showPermissions, boolean showAlternatives, boolean showCommands) {
|
||||||
// Find the command for this help query, one with and one without a prefixed base command
|
// Find the command for this help query, one with and one without a prefixed base command
|
||||||
FoundCommandResult result = AuthMe.getInstance().getCommandHandler().getCommandManager().findCommand(new CommandParts(helpQuery.getList()));
|
FoundCommandResult result = AuthMe.getInstance().getCommandHandler().getCommandManager().findCommand(new CommandParts(helpQuery.getList()));
|
||||||
CommandParts commandReferenceOther = new CommandParts(reference.get(0), helpQuery.getList());
|
CommandParts commandReferenceOther = new CommandParts(reference.get(0), helpQuery.getList());
|
||||||
FoundCommandResult resultOther = AuthMe.getInstance().getCommandHandler().getCommandManager().findCommand(commandReferenceOther);
|
FoundCommandResult resultOther = AuthMe.getInstance().getCommandHandler().getCommandManager().findCommand(commandReferenceOther);
|
||||||
if(resultOther != null) {
|
if (resultOther != null) {
|
||||||
if(result == null)
|
if (result == null)
|
||||||
result = resultOther;
|
result = resultOther;
|
||||||
|
|
||||||
else if(result.getDifference() > resultOther.getDifference())
|
else if (result.getDifference() > resultOther.getDifference())
|
||||||
result = resultOther;
|
result = resultOther;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make sure a result was found
|
// Make sure a result was found
|
||||||
if(result == null) {
|
if (result == null) {
|
||||||
// Show a warning message
|
// Show a warning message
|
||||||
sender.sendMessage(ChatColor.DARK_RED + "" + ChatColor.ITALIC + helpQuery);
|
sender.sendMessage(ChatColor.DARK_RED + "" + ChatColor.ITALIC + helpQuery);
|
||||||
sender.sendMessage(ChatColor.DARK_RED + "Couldn't show any help information for this help query.");
|
sender.sendMessage(ChatColor.DARK_RED + "Couldn't show any help information for this help query.");
|
||||||
@ -57,7 +60,7 @@ public class HelpProvider {
|
|||||||
|
|
||||||
// Get the command description, and make sure it's valid
|
// Get the command description, and make sure it's valid
|
||||||
CommandDescription command = result.getCommandDescription();
|
CommandDescription command = result.getCommandDescription();
|
||||||
if(command == null) {
|
if (command == null) {
|
||||||
// Show a warning message
|
// Show a warning message
|
||||||
sender.sendMessage(ChatColor.DARK_RED + "Failed to retrieve any help information!");
|
sender.sendMessage(ChatColor.DARK_RED + "Failed to retrieve any help information!");
|
||||||
return;
|
return;
|
||||||
@ -71,7 +74,7 @@ public class HelpProvider {
|
|||||||
|
|
||||||
// Make sure the difference between the command reference and the actual command isn't too big
|
// Make sure the difference between the command reference and the actual command isn't too big
|
||||||
final double commandDifference = result.getDifference();
|
final double commandDifference = result.getDifference();
|
||||||
if(commandDifference > 0.20) {
|
if (commandDifference > 0.20) {
|
||||||
// Show the unknown command warning
|
// Show the unknown command warning
|
||||||
sender.sendMessage(ChatColor.DARK_RED + "No help found for '" + helpQuery + "'!");
|
sender.sendMessage(ChatColor.DARK_RED + "No help found for '" + helpQuery + "'!");
|
||||||
|
|
||||||
@ -79,8 +82,8 @@ public class HelpProvider {
|
|||||||
CommandParts suggestedCommandParts = new CommandParts(result.getCommandDescription().getCommandReference(commandReference).getRange(1));
|
CommandParts suggestedCommandParts = new CommandParts(result.getCommandDescription().getCommandReference(commandReference).getRange(1));
|
||||||
|
|
||||||
// Show a command suggestion if available and the difference isn't too big
|
// Show a command suggestion if available and the difference isn't too big
|
||||||
if(commandDifference < 0.75)
|
if (commandDifference < 0.75)
|
||||||
if(result.getCommandDescription() != null)
|
if (result.getCommandDescription() != null)
|
||||||
sender.sendMessage(ChatColor.YELLOW + "Did you mean " + ChatColor.GOLD + "/" + baseCommand + " help " + suggestedCommandParts + ChatColor.YELLOW + "?");
|
sender.sendMessage(ChatColor.YELLOW + "Did you mean " + ChatColor.GOLD + "/" + baseCommand + " help " + suggestedCommandParts + ChatColor.YELLOW + "?");
|
||||||
|
|
||||||
// Show the help command
|
// Show the help command
|
||||||
@ -89,7 +92,7 @@ public class HelpProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Show a message when the command handler is assuming a command
|
// Show a message when the command handler is assuming a command
|
||||||
if(commandDifference > 0) {
|
if (commandDifference > 0) {
|
||||||
// Get the suggested command
|
// Get the suggested command
|
||||||
CommandParts suggestedCommandParts = new CommandParts(result.getCommandDescription().getCommandReference(commandReference).getRange(1));
|
CommandParts suggestedCommandParts = new CommandParts(result.getCommandDescription().getCommandReference(commandReference).getRange(1));
|
||||||
|
|
||||||
@ -98,20 +101,20 @@ public class HelpProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Print the help header
|
// Print the help header
|
||||||
sender.sendMessage(ChatColor.GOLD + "==========[ " + AuthMe.PLUGIN_NAME.toUpperCase() + " HELP ]==========");
|
sender.sendMessage(ChatColor.GOLD + "==========[ " + Settings.helpHeader.toUpperCase() + " HELP ]==========");
|
||||||
|
|
||||||
// Print the command help information
|
// Print the command help information
|
||||||
if(showCommand)
|
if (showCommand)
|
||||||
HelpPrinter.printCommand(sender, command, commandReference);
|
HelpPrinter.printCommand(sender, command, commandReference);
|
||||||
if(showDescription)
|
if (showDescription)
|
||||||
HelpPrinter.printCommandDescription(sender, command);
|
HelpPrinter.printCommandDescription(sender, command);
|
||||||
if(showArguments)
|
if (showArguments)
|
||||||
HelpPrinter.printArguments(sender, command);
|
HelpPrinter.printArguments(sender, command);
|
||||||
if(showPermissions)
|
if (showPermissions)
|
||||||
HelpPrinter.printPermissions(sender, command);
|
HelpPrinter.printPermissions(sender, command);
|
||||||
if(showAlternatives)
|
if (showAlternatives)
|
||||||
HelpPrinter.printAlternatives(sender, command, commandReference);
|
HelpPrinter.printAlternatives(sender, command, commandReference);
|
||||||
if(showCommands)
|
if (showCommands)
|
||||||
HelpPrinter.printChildren(sender, command, commandReference);
|
HelpPrinter.printChildren(sender, command, commandReference);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,61 +1,79 @@
|
|||||||
package fr.xephi.authme.command.help;
|
package fr.xephi.authme.command.help;
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
|
|
||||||
import fr.xephi.authme.command.CommandArgumentDescription;
|
import fr.xephi.authme.command.CommandArgumentDescription;
|
||||||
import fr.xephi.authme.command.CommandDescription;
|
import fr.xephi.authme.command.CommandDescription;
|
||||||
import fr.xephi.authme.command.CommandParts;
|
import fr.xephi.authme.command.CommandParts;
|
||||||
import fr.xephi.authme.util.ListUtils;
|
import fr.xephi.authme.util.StringUtils;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
|
||||||
public class HelpSyntaxHelper {
|
/**
|
||||||
|
* Helper class for formatting a command's structure (name and arguments)
|
||||||
|
* for a Minecraft user.
|
||||||
|
*/
|
||||||
|
public final class HelpSyntaxHelper {
|
||||||
|
|
||||||
|
private HelpSyntaxHelper() {
|
||||||
|
// Helper class
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the proper syntax for a command.
|
* Get the formatted syntax for a command.
|
||||||
*
|
*
|
||||||
* @param commandDescription The command to get the syntax for.
|
* @param commandDescription The command to build the syntax for.
|
||||||
* @param commandReference The reference of the command.
|
* @param commandReference The reference of the command.
|
||||||
* @param alternativeLabel The alternative label to use for this command syntax.
|
* @param alternativeLabel The alternative label to use for this command syntax.
|
||||||
* @param highlight True to highlight the important parts of this command.
|
* @param highlight True to highlight the important parts of this command.
|
||||||
*
|
*
|
||||||
* @return The command with proper syntax.
|
* @return The command with proper syntax.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("StringConcatenationInsideStringBufferAppend")
|
public static String getCommandSyntax(CommandDescription commandDescription, CommandParts commandReference,
|
||||||
public static String getCommandSyntax(CommandDescription commandDescription, CommandParts commandReference, String alternativeLabel, boolean highlight) {
|
String alternativeLabel, boolean highlight) {
|
||||||
// Create a string builder to build the command
|
// Create a string builder with white color and prefixed slash
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder()
|
||||||
|
.append(ChatColor.WHITE)
|
||||||
// Set the color and prefix a slash
|
.append("/");
|
||||||
sb.append(ChatColor.WHITE + "/");
|
|
||||||
|
|
||||||
// Get the help command reference, and the command label
|
// Get the help command reference, and the command label
|
||||||
CommandParts helpCommandReference = commandDescription.getCommandReference(commandReference);
|
CommandParts helpCommandReference = commandDescription.getCommandReference(commandReference);
|
||||||
final String parentCommand = (new CommandParts(helpCommandReference.getRange(0, helpCommandReference.getCount() - 1))).toString();
|
final String parentCommand = new CommandParts(
|
||||||
String commandLabel = helpCommandReference.get(helpCommandReference.getCount() - 1);
|
helpCommandReference.getRange(0, helpCommandReference.getCount() - 1)).toString();
|
||||||
|
|
||||||
// Check whether the alternative label should be used
|
// Check whether the alternative label should be used
|
||||||
if(alternativeLabel != null)
|
String commandLabel;
|
||||||
if(alternativeLabel.trim().length() > 0)
|
if (StringUtils.isEmpty(alternativeLabel)) {
|
||||||
commandLabel = alternativeLabel;
|
commandLabel = helpCommandReference.get(helpCommandReference.getCount() - 1);
|
||||||
|
} else {
|
||||||
|
commandLabel = alternativeLabel;
|
||||||
|
}
|
||||||
|
|
||||||
// Show the important bit of the command, highlight this part if required
|
// Show the important bit of the command, highlight this part if required
|
||||||
sb.append(ListUtils.implode(parentCommand, (highlight ? ChatColor.YELLOW + "" + ChatColor.BOLD : "") + commandLabel, " "));
|
sb.append(parentCommand)
|
||||||
if(highlight)
|
.append(" ")
|
||||||
sb.append(ChatColor.YELLOW);
|
.append(highlight ? ChatColor.YELLOW.toString() + ChatColor.BOLD : "")
|
||||||
|
.append(commandLabel);
|
||||||
|
|
||||||
// Add each command arguments
|
if (highlight) {
|
||||||
for(CommandArgumentDescription arg : commandDescription.getArguments()) {
|
sb.append(ChatColor.YELLOW);
|
||||||
// Add the argument as optional or non-optional argument
|
}
|
||||||
if(!arg.isOptional())
|
|
||||||
sb.append(ChatColor.ITALIC + " <" + arg.getLabel() + ">");
|
// Add each command argument
|
||||||
else
|
for (CommandArgumentDescription arg : commandDescription.getArguments()) {
|
||||||
sb.append(ChatColor.ITALIC + " [" + arg.getLabel() + "]");
|
sb.append(ChatColor.ITALIC).append(formatArgument(arg));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add some dots if the command allows unlimited arguments
|
// Add some dots if the command allows unlimited arguments
|
||||||
if(commandDescription.getMaximumArguments() < 0)
|
if (commandDescription.getMaximumArguments() < 0) {
|
||||||
sb.append(ChatColor.ITALIC + " ...");
|
sb.append(ChatColor.ITALIC).append(" ...");
|
||||||
|
}
|
||||||
|
|
||||||
// Return the build command syntax
|
// Return the build command syntax
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static String formatArgument(CommandArgumentDescription argument) {
|
||||||
|
if (argument.isOptional()) {
|
||||||
|
return " [" + argument.getLabel() + "]";
|
||||||
|
}
|
||||||
|
return " <" + argument.getLabel() + ">";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,6 @@
|
|||||||
package fr.xephi.authme.converter;
|
package fr.xephi.authme.converter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
public interface Converter extends Runnable {
|
public interface Converter extends Runnable {
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,37 +1,53 @@
|
|||||||
package fr.xephi.authme.converter;
|
package fr.xephi.authme.converter;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileReader;
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
|
|
||||||
import fr.xephi.authme.AuthMe;
|
import fr.xephi.authme.AuthMe;
|
||||||
import fr.xephi.authme.ConsoleLogger;
|
import fr.xephi.authme.ConsoleLogger;
|
||||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||||
import fr.xephi.authme.datasource.DataSource;
|
import fr.xephi.authme.datasource.DataSource;
|
||||||
import fr.xephi.authme.settings.Settings;
|
import fr.xephi.authme.settings.Settings;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Xephi59
|
* @author Xephi59
|
||||||
|
* @version $Revision: 1.0 $
|
||||||
*/
|
*/
|
||||||
public class CrazyLoginConverter implements Converter {
|
public class CrazyLoginConverter implements Converter {
|
||||||
|
|
||||||
public AuthMe instance;
|
public final AuthMe instance;
|
||||||
public DataSource database;
|
public final DataSource database;
|
||||||
public CommandSender sender;
|
public final CommandSender sender;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for CrazyLoginConverter.
|
||||||
|
*
|
||||||
|
* @param instance AuthMe
|
||||||
|
* @param sender CommandSender
|
||||||
|
*/
|
||||||
public CrazyLoginConverter(AuthMe instance, CommandSender sender) {
|
public CrazyLoginConverter(AuthMe instance, CommandSender sender) {
|
||||||
this.instance = instance;
|
this.instance = instance;
|
||||||
this.database = instance.database;
|
this.database = instance.database;
|
||||||
this.sender = sender;
|
this.sender = sender;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method getInstance.
|
||||||
|
*
|
||||||
|
* @return CrazyLoginConverter
|
||||||
|
*/
|
||||||
public CrazyLoginConverter getInstance() {
|
public CrazyLoginConverter getInstance() {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method run.
|
||||||
|
*
|
||||||
|
* @see java.lang.Runnable#run()
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
String fileName = Settings.crazyloginFileName;
|
String fileName = Settings.crazyloginFileName;
|
||||||
|
|||||||
@ -1,18 +1,14 @@
|
|||||||
package fr.xephi.authme.converter;
|
package fr.xephi.authme.converter;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.BufferedWriter;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileReader;
|
|
||||||
import java.io.FileWriter;
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import fr.xephi.authme.AuthMe;
|
import fr.xephi.authme.AuthMe;
|
||||||
import fr.xephi.authme.ConsoleLogger;
|
import fr.xephi.authme.ConsoleLogger;
|
||||||
import fr.xephi.authme.settings.Settings;
|
import fr.xephi.authme.settings.Settings;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Xephi59
|
* @author Xephi59
|
||||||
|
* @version $Revision: 1.0 $
|
||||||
*/
|
*/
|
||||||
public class FlatToSql implements Converter {
|
public class FlatToSql implements Converter {
|
||||||
|
|
||||||
@ -44,6 +40,11 @@ public class FlatToSql implements Converter {
|
|||||||
columnID = Settings.getMySQLColumnId;
|
columnID = Settings.getMySQLColumnId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method run.
|
||||||
|
*
|
||||||
|
* @see java.lang.Runnable#run()
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@ -1,24 +1,20 @@
|
|||||||
package fr.xephi.authme.converter;
|
package fr.xephi.authme.converter;
|
||||||
|
|
||||||
|
import fr.xephi.authme.ConsoleLogger;
|
||||||
|
import fr.xephi.authme.settings.Settings;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileReader;
|
import java.io.FileReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.sql.Connection;
|
import java.sql.*;
|
||||||
import java.sql.DriverManager;
|
|
||||||
import java.sql.PreparedStatement;
|
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.sql.Statement;
|
|
||||||
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
|
|
||||||
import fr.xephi.authme.ConsoleLogger;
|
|
||||||
import fr.xephi.authme.settings.Settings;
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
public class FlatToSqlite implements Converter {
|
public class FlatToSqlite implements Converter {
|
||||||
|
|
||||||
public CommandSender sender;
|
public final CommandSender sender;
|
||||||
private String tableName;
|
private String tableName;
|
||||||
private String columnName;
|
private String columnName;
|
||||||
private String columnPassword;
|
private String columnPassword;
|
||||||
@ -32,10 +28,21 @@ public class FlatToSqlite implements Converter {
|
|||||||
private String database;
|
private String database;
|
||||||
private String columnID;
|
private String columnID;
|
||||||
private Connection con;
|
private Connection con;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for FlatToSqlite.
|
||||||
|
*
|
||||||
|
* @param sender CommandSender
|
||||||
|
*/
|
||||||
public FlatToSqlite(CommandSender sender) {
|
public FlatToSqlite(CommandSender sender) {
|
||||||
this.sender = sender;
|
this.sender = sender;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method close.
|
||||||
|
*
|
||||||
|
* @param o AutoCloseable
|
||||||
|
*/
|
||||||
private static void close(AutoCloseable o) {
|
private static void close(AutoCloseable o) {
|
||||||
if (o != null) {
|
if (o != null) {
|
||||||
try {
|
try {
|
||||||
@ -46,6 +53,11 @@ public class FlatToSqlite implements Converter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method run.
|
||||||
|
*
|
||||||
|
* @see java.lang.Runnable#run()
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
database = Settings.getMySQLDatabase;
|
database = Settings.getMySQLDatabase;
|
||||||
@ -105,11 +117,21 @@ public class FlatToSqlite implements Converter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method connect.
|
||||||
|
*
|
||||||
|
* @throws ClassNotFoundException * @throws SQLException
|
||||||
|
*/
|
||||||
private synchronized void connect() throws ClassNotFoundException, SQLException {
|
private synchronized void connect() throws ClassNotFoundException, SQLException {
|
||||||
Class.forName("org.sqlite.JDBC");
|
Class.forName("org.sqlite.JDBC");
|
||||||
con = DriverManager.getConnection("jdbc:sqlite:plugins/AuthMe/" + database + ".db");
|
con = DriverManager.getConnection("jdbc:sqlite:plugins/AuthMe/" + database + ".db");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method setup.
|
||||||
|
*
|
||||||
|
* @throws SQLException
|
||||||
|
*/
|
||||||
private synchronized void setup() throws SQLException {
|
private synchronized void setup() throws SQLException {
|
||||||
Statement st = null;
|
Statement st = null;
|
||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
@ -153,6 +175,13 @@ public class FlatToSqlite implements Converter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method saveAuth.
|
||||||
|
*
|
||||||
|
* @param s String
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
private synchronized boolean saveAuth(String s) {
|
private synchronized boolean saveAuth(String s) {
|
||||||
PreparedStatement pst = null;
|
PreparedStatement pst = null;
|
||||||
try {
|
try {
|
||||||
|
|||||||
@ -7,13 +7,27 @@ import fr.xephi.authme.datasource.DataSource;
|
|||||||
import fr.xephi.authme.datasource.SQLite;
|
import fr.xephi.authme.datasource.SQLite;
|
||||||
import fr.xephi.authme.settings.Settings;
|
import fr.xephi.authme.settings.Settings;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
public class ForceFlatToSqlite implements Converter {
|
public class ForceFlatToSqlite implements Converter {
|
||||||
|
|
||||||
private DataSource data;
|
private final DataSource data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for ForceFlatToSqlite.
|
||||||
|
*
|
||||||
|
* @param data DataSource
|
||||||
|
* @param plugin AuthMe
|
||||||
|
*/
|
||||||
public ForceFlatToSqlite(DataSource data, AuthMe plugin) {
|
public ForceFlatToSqlite(DataSource data, AuthMe plugin) {
|
||||||
this.data = data;
|
this.data = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method run.
|
||||||
|
*
|
||||||
|
* @see java.lang.Runnable#run()
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
DataSource sqlite = null;
|
DataSource sqlite = null;
|
||||||
|
|||||||
@ -1,5 +1,14 @@
|
|||||||
package fr.xephi.authme.converter;
|
package fr.xephi.authme.converter;
|
||||||
|
|
||||||
|
import fr.xephi.authme.AuthMe;
|
||||||
|
import fr.xephi.authme.ConsoleLogger;
|
||||||
|
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||||
|
import fr.xephi.authme.datasource.DataSource;
|
||||||
|
import fr.xephi.authme.security.HashAlgorithm;
|
||||||
|
import fr.xephi.authme.security.PasswordSecurity;
|
||||||
|
import fr.xephi.authme.settings.Settings;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileReader;
|
import java.io.FileReader;
|
||||||
@ -8,35 +17,42 @@ import java.security.NoSuchAlgorithmException;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
|
|
||||||
import fr.xephi.authme.AuthMe;
|
|
||||||
import fr.xephi.authme.ConsoleLogger;
|
|
||||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
|
||||||
import fr.xephi.authme.datasource.DataSource;
|
|
||||||
import fr.xephi.authme.security.HashAlgorithm;
|
|
||||||
import fr.xephi.authme.security.PasswordSecurity;
|
|
||||||
import fr.xephi.authme.settings.Settings;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Xephi59
|
* @author Xephi59
|
||||||
|
* @version $Revision: 1.0 $
|
||||||
*/
|
*/
|
||||||
public class RakamakConverter implements Converter {
|
public class RakamakConverter implements Converter {
|
||||||
|
|
||||||
public AuthMe instance;
|
public final AuthMe instance;
|
||||||
public DataSource database;
|
public final DataSource database;
|
||||||
public CommandSender sender;
|
public final CommandSender sender;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for RakamakConverter.
|
||||||
|
*
|
||||||
|
* @param instance AuthMe
|
||||||
|
* @param sender CommandSender
|
||||||
|
*/
|
||||||
public RakamakConverter(AuthMe instance, CommandSender sender) {
|
public RakamakConverter(AuthMe instance, CommandSender sender) {
|
||||||
this.instance = instance;
|
this.instance = instance;
|
||||||
this.database = instance.database;
|
this.database = instance.database;
|
||||||
this.sender = sender;
|
this.sender = sender;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method getInstance.
|
||||||
|
*
|
||||||
|
* @return RakamakConverter
|
||||||
|
*/
|
||||||
public RakamakConverter getInstance() {
|
public RakamakConverter getInstance() {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method run.
|
||||||
|
*
|
||||||
|
* @see java.lang.Runnable#run()
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
HashAlgorithm hash = Settings.getPasswordHash;
|
HashAlgorithm hash = Settings.getPasswordHash;
|
||||||
|
|||||||
@ -1,24 +1,35 @@
|
|||||||
package fr.xephi.authme.converter;
|
package fr.xephi.authme.converter;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
import org.bukkit.OfflinePlayer;
|
|
||||||
|
|
||||||
import fr.xephi.authme.AuthMe;
|
import fr.xephi.authme.AuthMe;
|
||||||
import fr.xephi.authme.ConsoleLogger;
|
import fr.xephi.authme.ConsoleLogger;
|
||||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||||
import fr.xephi.authme.datasource.DataSource;
|
import fr.xephi.authme.datasource.DataSource;
|
||||||
|
import org.bukkit.OfflinePlayer;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
public class RoyalAuthConverter implements Converter {
|
public class RoyalAuthConverter implements Converter {
|
||||||
|
|
||||||
public AuthMe plugin;
|
public final AuthMe plugin;
|
||||||
private DataSource data;
|
private final DataSource data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for RoyalAuthConverter.
|
||||||
|
*
|
||||||
|
* @param plugin AuthMe
|
||||||
|
*/
|
||||||
public RoyalAuthConverter(AuthMe plugin) {
|
public RoyalAuthConverter(AuthMe plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
this.data = plugin.database;
|
this.data = plugin.database;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method run.
|
||||||
|
*
|
||||||
|
* @see java.lang.Runnable#run()
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
for (OfflinePlayer o : plugin.getServer().getOfflinePlayers()) {
|
for (OfflinePlayer o : plugin.getServer().getOfflinePlayers()) {
|
||||||
|
|||||||
@ -1,21 +1,38 @@
|
|||||||
package fr.xephi.authme.converter;
|
package fr.xephi.authme.converter;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
import fr.xephi.authme.settings.CustomConfiguration;
|
import fr.xephi.authme.settings.CustomConfiguration;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
public class RoyalAuthYamlReader extends CustomConfiguration {
|
public class RoyalAuthYamlReader extends CustomConfiguration {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for RoyalAuthYamlReader.
|
||||||
|
*
|
||||||
|
* @param file File
|
||||||
|
*/
|
||||||
public RoyalAuthYamlReader(File file) {
|
public RoyalAuthYamlReader(File file) {
|
||||||
super(file);
|
super(file);
|
||||||
load();
|
load();
|
||||||
save();
|
save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method getLastLogin.
|
||||||
|
*
|
||||||
|
* @return long
|
||||||
|
*/
|
||||||
public long getLastLogin() {
|
public long getLastLogin() {
|
||||||
return getLong("timestamps.quit");
|
return getLong("timestamps.quit");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method getHash.
|
||||||
|
*
|
||||||
|
* @return String
|
||||||
|
*/
|
||||||
public String getHash() {
|
public String getHash() {
|
||||||
return getString("login.password");
|
return getString("login.password");
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,28 +1,40 @@
|
|||||||
package fr.xephi.authme.converter;
|
package fr.xephi.authme.converter;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
|
|
||||||
import fr.xephi.authme.AuthMe;
|
import fr.xephi.authme.AuthMe;
|
||||||
import fr.xephi.authme.ConsoleLogger;
|
import fr.xephi.authme.ConsoleLogger;
|
||||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||||
import fr.xephi.authme.datasource.DataSource;
|
import fr.xephi.authme.datasource.DataSource;
|
||||||
import fr.xephi.authme.datasource.FlatFile;
|
import fr.xephi.authme.datasource.FlatFile;
|
||||||
import fr.xephi.authme.settings.Messages;
|
import fr.xephi.authme.settings.MessageKey;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
public class SqlToFlat implements Converter {
|
public class SqlToFlat implements Converter {
|
||||||
|
|
||||||
public AuthMe plugin;
|
public final AuthMe plugin;
|
||||||
public DataSource database;
|
public final DataSource database;
|
||||||
public CommandSender sender;
|
public final CommandSender sender;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for SqlToFlat.
|
||||||
|
*
|
||||||
|
* @param plugin AuthMe
|
||||||
|
* @param sender CommandSender
|
||||||
|
*/
|
||||||
public SqlToFlat(AuthMe plugin, CommandSender sender) {
|
public SqlToFlat(AuthMe plugin, CommandSender sender) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
this.database = plugin.database;
|
this.database = plugin.database;
|
||||||
this.sender = sender;
|
this.sender = sender;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method run.
|
||||||
|
*
|
||||||
|
* @see java.lang.Runnable#run()
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
@ -40,7 +52,7 @@ public class SqlToFlat implements Converter {
|
|||||||
sender.sendMessage("Successfully convert from SQL table to file auths.db");
|
sender.sendMessage("Successfully convert from SQL table to file auths.db");
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
ConsoleLogger.showError(ex.getMessage());
|
ConsoleLogger.showError(ex.getMessage());
|
||||||
Messages.getInstance().send(sender, "error");
|
plugin.getMessages().send(sender, MessageKey.ERROR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,23 +1,35 @@
|
|||||||
package fr.xephi.authme.converter;
|
package fr.xephi.authme.converter;
|
||||||
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
|
|
||||||
import fr.xephi.authme.AuthMe;
|
import fr.xephi.authme.AuthMe;
|
||||||
import fr.xephi.authme.ConsoleLogger;
|
import fr.xephi.authme.ConsoleLogger;
|
||||||
import fr.xephi.authme.datasource.DataSource;
|
import fr.xephi.authme.datasource.DataSource;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
public class vAuthConverter implements Converter {
|
public class vAuthConverter implements Converter {
|
||||||
|
|
||||||
public AuthMe plugin;
|
public final AuthMe plugin;
|
||||||
public DataSource database;
|
public final DataSource database;
|
||||||
public CommandSender sender;
|
public final CommandSender sender;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for vAuthConverter.
|
||||||
|
*
|
||||||
|
* @param plugin AuthMe
|
||||||
|
* @param sender CommandSender
|
||||||
|
*/
|
||||||
public vAuthConverter(AuthMe plugin, CommandSender sender) {
|
public vAuthConverter(AuthMe plugin, CommandSender sender) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
this.database = plugin.database;
|
this.database = plugin.database;
|
||||||
this.sender = sender;
|
this.sender = sender;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method run.
|
||||||
|
*
|
||||||
|
* @see java.lang.Runnable#run()
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@ -1,32 +1,38 @@
|
|||||||
package fr.xephi.authme.converter;
|
package fr.xephi.authme.converter;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Scanner;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.OfflinePlayer;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
|
|
||||||
import fr.xephi.authme.AuthMe;
|
import fr.xephi.authme.AuthMe;
|
||||||
import fr.xephi.authme.ConsoleLogger;
|
import fr.xephi.authme.ConsoleLogger;
|
||||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||||
import fr.xephi.authme.datasource.DataSource;
|
import fr.xephi.authme.datasource.DataSource;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.OfflinePlayer;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.Scanner;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
public class vAuthFileReader {
|
public class vAuthFileReader {
|
||||||
|
|
||||||
public AuthMe plugin;
|
public final AuthMe plugin;
|
||||||
public DataSource database;
|
public final DataSource database;
|
||||||
public CommandSender sender;
|
public final CommandSender sender;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for vAuthFileReader.
|
||||||
|
*
|
||||||
|
* @param plugin AuthMe
|
||||||
|
* @param sender CommandSender
|
||||||
|
*/
|
||||||
public vAuthFileReader(AuthMe plugin, CommandSender sender) {
|
public vAuthFileReader(AuthMe plugin, CommandSender sender) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
this.database = plugin.database;
|
this.database = plugin.database;
|
||||||
this.sender = sender;
|
this.sender = sender;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void convert() throws IOException {
|
public void convert() {
|
||||||
final File file = new File(plugin.getDataFolder().getParent() + "" + File.separator + "vAuth" + File.separator + "passwords.yml");
|
final File file = new File(plugin.getDataFolder().getParent() + "" + File.separator + "vAuth" + File.separator + "passwords.yml");
|
||||||
Scanner scanner;
|
Scanner scanner;
|
||||||
try {
|
try {
|
||||||
@ -37,32 +43,47 @@ public class vAuthFileReader {
|
|||||||
String password = line.split(": ")[1];
|
String password = line.split(": ")[1];
|
||||||
PlayerAuth auth;
|
PlayerAuth auth;
|
||||||
if (isUUIDinstance(password)) {
|
if (isUUIDinstance(password)) {
|
||||||
String pname;
|
String playerName;
|
||||||
try {
|
try {
|
||||||
pname = Bukkit.getOfflinePlayer(UUID.fromString(name)).getName();
|
playerName = Bukkit.getOfflinePlayer(UUID.fromString(name)).getName();
|
||||||
} catch (Exception | NoSuchMethodError e) {
|
} catch (Exception | NoSuchMethodError e) {
|
||||||
pname = getName(UUID.fromString(name));
|
playerName = getName(UUID.fromString(name));
|
||||||
}
|
}
|
||||||
if (pname == null)
|
if (playerName == null)
|
||||||
continue;
|
continue;
|
||||||
auth = new PlayerAuth(pname.toLowerCase(), password, "127.0.0.1", System.currentTimeMillis(), "your@email.com", pname);
|
auth = new PlayerAuth(playerName.toLowerCase(), password, "127.0.0.1", System.currentTimeMillis(), "your@email.com", playerName);
|
||||||
} else {
|
} else {
|
||||||
auth = new PlayerAuth(name.toLowerCase(), password, "127.0.0.1", System.currentTimeMillis(), "your@email.com", name);
|
auth = new PlayerAuth(name.toLowerCase(), password, "127.0.0.1", System.currentTimeMillis(), "your@email.com", name);
|
||||||
}
|
}
|
||||||
database.saveAuth(auth);
|
database.saveAuth(auth);
|
||||||
}
|
}
|
||||||
|
scanner.close();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
ConsoleLogger.writeStackTrace(e);
|
ConsoleLogger.writeStackTrace(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method isUUIDinstance.
|
||||||
|
*
|
||||||
|
* @param s String
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
private boolean isUUIDinstance(String s) {
|
private boolean isUUIDinstance(String s) {
|
||||||
if (String.valueOf(s.charAt(8)).equalsIgnoreCase("-"))
|
if (String.valueOf(s.charAt(8)).equalsIgnoreCase("-"))
|
||||||
return true;
|
return true;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method getName.
|
||||||
|
*
|
||||||
|
* @param uuid UUID
|
||||||
|
*
|
||||||
|
* @return String
|
||||||
|
*/
|
||||||
private String getName(UUID uuid) {
|
private String getName(UUID uuid) {
|
||||||
try {
|
try {
|
||||||
for (OfflinePlayer op : Bukkit.getOfflinePlayers()) {
|
for (OfflinePlayer op : Bukkit.getOfflinePlayers()) {
|
||||||
|
|||||||
@ -1,19 +1,31 @@
|
|||||||
package fr.xephi.authme.converter;
|
package fr.xephi.authme.converter;
|
||||||
|
|
||||||
|
import fr.xephi.authme.AuthMe;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
import fr.xephi.authme.AuthMe;
|
/**
|
||||||
|
*/
|
||||||
public class xAuthConverter implements Converter {
|
public class xAuthConverter implements Converter {
|
||||||
|
|
||||||
public AuthMe plugin;
|
public final AuthMe plugin;
|
||||||
public CommandSender sender;
|
public final CommandSender sender;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for xAuthConverter.
|
||||||
|
*
|
||||||
|
* @param plugin AuthMe
|
||||||
|
* @param sender CommandSender
|
||||||
|
*/
|
||||||
public xAuthConverter(AuthMe plugin, CommandSender sender) {
|
public xAuthConverter(AuthMe plugin, CommandSender sender) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
this.sender = sender;
|
this.sender = sender;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method run.
|
||||||
|
*
|
||||||
|
* @see java.lang.Runnable#run()
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@ -1,5 +1,13 @@
|
|||||||
package fr.xephi.authme.converter;
|
package fr.xephi.authme.converter;
|
||||||
|
|
||||||
|
import de.luricos.bukkit.xAuth.database.DatabaseTables;
|
||||||
|
import de.luricos.bukkit.xAuth.utils.xAuthLog;
|
||||||
|
import de.luricos.bukkit.xAuth.xAuth;
|
||||||
|
import fr.xephi.authme.AuthMe;
|
||||||
|
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||||
|
import fr.xephi.authme.datasource.DataSource;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
@ -8,27 +16,31 @@ import java.sql.SQLException;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.bukkit.command.CommandSender;
|
/**
|
||||||
|
*/
|
||||||
import de.luricos.bukkit.xAuth.xAuth;
|
|
||||||
import de.luricos.bukkit.xAuth.database.DatabaseTables;
|
|
||||||
import de.luricos.bukkit.xAuth.utils.xAuthLog;
|
|
||||||
import fr.xephi.authme.AuthMe;
|
|
||||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
|
||||||
import fr.xephi.authme.datasource.DataSource;
|
|
||||||
|
|
||||||
public class xAuthToFlat {
|
public class xAuthToFlat {
|
||||||
|
|
||||||
public AuthMe instance;
|
public final AuthMe instance;
|
||||||
public DataSource database;
|
public final DataSource database;
|
||||||
public CommandSender sender;
|
public final CommandSender sender;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for xAuthToFlat.
|
||||||
|
*
|
||||||
|
* @param instance AuthMe
|
||||||
|
* @param sender CommandSender
|
||||||
|
*/
|
||||||
public xAuthToFlat(AuthMe instance, CommandSender sender) {
|
public xAuthToFlat(AuthMe instance, CommandSender sender) {
|
||||||
this.instance = instance;
|
this.instance = instance;
|
||||||
this.database = instance.database;
|
this.database = instance.database;
|
||||||
this.sender = sender;
|
this.sender = sender;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method convert.
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
public boolean convert() {
|
public boolean convert() {
|
||||||
if (instance.getServer().getPluginManager().getPlugin("xAuth") == null) {
|
if (instance.getServer().getPluginManager().getPlugin("xAuth") == null) {
|
||||||
sender.sendMessage("[AuthMe] xAuth plugin not found");
|
sender.sendMessage("[AuthMe] xAuth plugin not found");
|
||||||
@ -52,13 +64,20 @@ public class xAuthToFlat {
|
|||||||
database.saveAuth(auth);
|
database.saveAuth(auth);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sender.sendMessage("[AuthMe] Successfull convert from xAuth database");
|
sender.sendMessage("[AuthMe] Successfully convert from xAuth database");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
sender.sendMessage("[AuthMe] An error has been thrown while import xAuth database, the import hadn't fail but can be not complete ");
|
sender.sendMessage("[AuthMe] An error has been thrown while import xAuth database, the import hadn't fail but can be not complete ");
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method getIdPlayer.
|
||||||
|
*
|
||||||
|
* @param id int
|
||||||
|
*
|
||||||
|
* @return String
|
||||||
|
*/
|
||||||
public String getIdPlayer(int id) {
|
public String getIdPlayer(int id) {
|
||||||
String realPass = "";
|
String realPass = "";
|
||||||
Connection conn = xAuth.getPlugin().getDatabaseController().getConnection();
|
Connection conn = xAuth.getPlugin().getDatabaseController().getConnection();
|
||||||
@ -81,6 +100,11 @@ public class xAuthToFlat {
|
|||||||
return realPass;
|
return realPass;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method getXAuthPlayers.
|
||||||
|
*
|
||||||
|
* @return List<Integer>
|
||||||
|
*/
|
||||||
public List<Integer> getXAuthPlayers() {
|
public List<Integer> getXAuthPlayers() {
|
||||||
List<Integer> xP = new ArrayList<>();
|
List<Integer> xP = new ArrayList<>();
|
||||||
Connection conn = xAuth.getPlugin().getDatabaseController().getConnection();
|
Connection conn = xAuth.getPlugin().getDatabaseController().getConnection();
|
||||||
@ -102,6 +126,13 @@ public class xAuthToFlat {
|
|||||||
return xP;
|
return xP;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method getPassword.
|
||||||
|
*
|
||||||
|
* @param accountId int
|
||||||
|
*
|
||||||
|
* @return String
|
||||||
|
*/
|
||||||
public String getPassword(int accountId) {
|
public String getPassword(int accountId) {
|
||||||
String realPass = "";
|
String realPass = "";
|
||||||
Connection conn = xAuth.getPlugin().getDatabaseController().getConnection();
|
Connection conn = xAuth.getPlugin().getDatabaseController().getConnection();
|
||||||
|
|||||||
@ -1,378 +1,561 @@
|
|||||||
package fr.xephi.authme.datasource;
|
package fr.xephi.authme.datasource;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import fr.xephi.authme.AuthMe;
|
||||||
import java.util.List;
|
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||||
import java.util.Map;
|
import fr.xephi.authme.cache.auth.PlayerCache;
|
||||||
import java.util.concurrent.Callable;
|
import fr.xephi.authme.util.Utils;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import org.bukkit.entity.Player;
|
||||||
import java.util.concurrent.ExecutorService;
|
|
||||||
import java.util.concurrent.Executors;
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
import org.bukkit.entity.Player;
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.Callable;
|
||||||
import fr.xephi.authme.AuthMe;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
import java.util.concurrent.ExecutorService;
|
||||||
import fr.xephi.authme.cache.auth.PlayerCache;
|
import java.util.concurrent.Executors;
|
||||||
import fr.xephi.authme.util.Utils;
|
|
||||||
|
/**
|
||||||
public class CacheDataSource implements DataSource {
|
*/
|
||||||
|
public class CacheDataSource implements DataSource {
|
||||||
private final DataSource source;
|
|
||||||
private final ExecutorService exec;
|
private final DataSource source;
|
||||||
private final ConcurrentHashMap<String, PlayerAuth> cache = new ConcurrentHashMap<>();
|
private final ExecutorService exec;
|
||||||
|
private final ConcurrentHashMap<String, PlayerAuth> cache = new ConcurrentHashMap<>();
|
||||||
public CacheDataSource(final AuthMe pl, DataSource src) {
|
|
||||||
this.source = src;
|
/**
|
||||||
this.exec = Executors.newCachedThreadPool();
|
* Constructor for CacheDataSource.
|
||||||
pl.setCanConnect(false);
|
*
|
||||||
|
* @param pl AuthMe
|
||||||
/*
|
* @param src DataSource
|
||||||
* We need to load all players in cache ... It will took more time to
|
*/
|
||||||
* load the server, but it will be much easier to check for an
|
public CacheDataSource(final AuthMe pl, DataSource src) {
|
||||||
* isAuthAvailable !
|
this.source = src;
|
||||||
*/
|
this.exec = Executors.newCachedThreadPool();
|
||||||
exec.execute(new Runnable() {
|
pl.setCanConnect(false);
|
||||||
@Override
|
|
||||||
public void run() {
|
/*
|
||||||
for (PlayerAuth auth : source.getAllAuths()) {
|
* We need to load all players in cache ... It will took more time to
|
||||||
cache.put(auth.getNickname().toLowerCase(), auth);
|
* load the server, but it will be much easier to check for an
|
||||||
}
|
* isAuthAvailable !
|
||||||
pl.setCanConnect(true);
|
*/
|
||||||
}
|
exec.execute(new Runnable() {
|
||||||
});
|
@Override
|
||||||
}
|
public void run() {
|
||||||
|
for (PlayerAuth auth : source.getAllAuths()) {
|
||||||
@Override
|
cache.put(auth.getNickname().toLowerCase(), auth);
|
||||||
public synchronized boolean isAuthAvailable(String user) {
|
}
|
||||||
return cache.containsKey(user.toLowerCase());
|
pl.setCanConnect(true);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
@Override
|
}
|
||||||
public synchronized PlayerAuth getAuth(String user) {
|
|
||||||
user = user.toLowerCase();
|
/**
|
||||||
if (cache.containsKey(user)) {
|
* Method isAuthAvailable.
|
||||||
return cache.get(user);
|
*
|
||||||
}
|
* @param user String
|
||||||
return null;
|
*
|
||||||
}
|
* @return boolean * @see fr.xephi.authme.datasource.DataSource#isAuthAvailable(String)
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public synchronized boolean saveAuth(final PlayerAuth auth) {
|
public synchronized boolean isAuthAvailable(String user) {
|
||||||
cache.put(auth.getNickname(), auth);
|
return cache.containsKey(user.toLowerCase());
|
||||||
exec.execute(new Runnable() {
|
}
|
||||||
@Override
|
|
||||||
public void run() {
|
/**
|
||||||
if (!source.saveAuth(auth)) {
|
* Method getAuth.
|
||||||
cache.remove(auth.getNickname());
|
*
|
||||||
}
|
* @param user String
|
||||||
}
|
*
|
||||||
});
|
* @return PlayerAuth * @see fr.xephi.authme.datasource.DataSource#getAuth(String)
|
||||||
return true;
|
*/
|
||||||
}
|
@Override
|
||||||
|
public synchronized PlayerAuth getAuth(String user) {
|
||||||
@Override
|
user = user.toLowerCase();
|
||||||
public synchronized boolean updatePassword(final PlayerAuth auth) {
|
if (cache.containsKey(user)) {
|
||||||
if (!cache.containsKey(auth.getNickname())) {
|
return cache.get(user);
|
||||||
return false;
|
}
|
||||||
}
|
return null;
|
||||||
final String oldHash = cache.get(auth.getNickname()).getHash();
|
}
|
||||||
cache.get(auth.getNickname()).setHash(auth.getHash());
|
|
||||||
exec.execute(new Runnable() {
|
/**
|
||||||
@Override
|
* Method saveAuth.
|
||||||
public void run() {
|
*
|
||||||
if (!source.updatePassword(auth)) {
|
* @param auth PlayerAuth
|
||||||
if (cache.containsKey(auth.getNickname())) {
|
*
|
||||||
cache.get(auth.getNickname()).setHash(oldHash);
|
* @return boolean * @see fr.xephi.authme.datasource.DataSource#saveAuth(PlayerAuth)
|
||||||
}
|
*/
|
||||||
}
|
@Override
|
||||||
}
|
public synchronized boolean saveAuth(final PlayerAuth auth) {
|
||||||
});
|
cache.put(auth.getNickname(), auth);
|
||||||
return true;
|
exec.execute(new Runnable() {
|
||||||
}
|
@Override
|
||||||
|
public void run() {
|
||||||
@Override
|
if (!source.saveAuth(auth)) {
|
||||||
public boolean updateSession(final PlayerAuth auth) {
|
cache.remove(auth.getNickname());
|
||||||
if (!cache.containsKey(auth.getNickname())) {
|
}
|
||||||
return false;
|
}
|
||||||
}
|
});
|
||||||
PlayerAuth cachedAuth = cache.get(auth.getNickname());
|
return true;
|
||||||
final String oldIp = cachedAuth.getIp();
|
}
|
||||||
final long oldLastLogin = cachedAuth.getLastLogin();
|
|
||||||
final String oldRealName = cachedAuth.getRealName();
|
/**
|
||||||
|
* Method updatePassword.
|
||||||
cachedAuth.setIp(auth.getIp());
|
*
|
||||||
cachedAuth.setLastLogin(auth.getLastLogin());
|
* @param auth PlayerAuth
|
||||||
cachedAuth.setRealName(auth.getRealName());
|
*
|
||||||
exec.execute(new Runnable() {
|
* @return boolean * @see fr.xephi.authme.datasource.DataSource#updatePassword(PlayerAuth)
|
||||||
@Override
|
*/
|
||||||
public void run() {
|
@Override
|
||||||
if (!source.updateSession(auth)) {
|
public synchronized boolean updatePassword(final PlayerAuth auth) {
|
||||||
if (cache.containsKey(auth.getNickname())) {
|
if (!cache.containsKey(auth.getNickname())) {
|
||||||
PlayerAuth cachedAuth = cache.get(auth.getNickname());
|
return false;
|
||||||
cachedAuth.setIp(oldIp);
|
}
|
||||||
cachedAuth.setLastLogin(oldLastLogin);
|
final String oldHash = cache.get(auth.getNickname()).getHash();
|
||||||
cachedAuth.setRealName(oldRealName);
|
cache.get(auth.getNickname()).setHash(auth.getHash());
|
||||||
}
|
exec.execute(new Runnable() {
|
||||||
}
|
@Override
|
||||||
}
|
public void run() {
|
||||||
});
|
if (!source.updatePassword(auth)) {
|
||||||
return true;
|
if (cache.containsKey(auth.getNickname())) {
|
||||||
}
|
cache.get(auth.getNickname()).setHash(oldHash);
|
||||||
|
}
|
||||||
@Override
|
}
|
||||||
public boolean updateQuitLoc(final PlayerAuth auth) {
|
}
|
||||||
if (!cache.containsKey(auth.getNickname())) {
|
});
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
final PlayerAuth cachedAuth = cache.get(auth.getNickname());
|
|
||||||
final double oldX = cachedAuth.getQuitLocX();
|
/**
|
||||||
final double oldY = cachedAuth.getQuitLocY();
|
* Method updateSession.
|
||||||
final double oldZ = cachedAuth.getQuitLocZ();
|
*
|
||||||
final String oldWorld = cachedAuth.getWorld();
|
* @param auth PlayerAuth
|
||||||
|
*
|
||||||
cachedAuth.setQuitLocX(auth.getQuitLocX());
|
* @return boolean * @see fr.xephi.authme.datasource.DataSource#updateSession(PlayerAuth)
|
||||||
cachedAuth.setQuitLocY(auth.getQuitLocY());
|
*/
|
||||||
cachedAuth.setQuitLocZ(auth.getQuitLocZ());
|
@Override
|
||||||
cachedAuth.setWorld(auth.getWorld());
|
public boolean updateSession(final PlayerAuth auth) {
|
||||||
exec.execute(new Runnable() {
|
if (!cache.containsKey(auth.getNickname())) {
|
||||||
@Override
|
return false;
|
||||||
public void run() {
|
}
|
||||||
if (!source.updateQuitLoc(auth)) {
|
PlayerAuth cachedAuth = cache.get(auth.getNickname());
|
||||||
if (cache.containsKey(auth.getNickname())) {
|
final String oldIp = cachedAuth.getIp();
|
||||||
PlayerAuth cachedAuth = cache.get(auth.getNickname());
|
final long oldLastLogin = cachedAuth.getLastLogin();
|
||||||
cachedAuth.setQuitLocX(oldX);
|
final String oldRealName = cachedAuth.getRealName();
|
||||||
cachedAuth.setQuitLocY(oldY);
|
|
||||||
cachedAuth.setQuitLocZ(oldZ);
|
cachedAuth.setIp(auth.getIp());
|
||||||
cachedAuth.setWorld(oldWorld);
|
cachedAuth.setLastLogin(auth.getLastLogin());
|
||||||
}
|
cachedAuth.setRealName(auth.getRealName());
|
||||||
}
|
exec.execute(new Runnable() {
|
||||||
}
|
@Override
|
||||||
});
|
public void run() {
|
||||||
return true;
|
if (!source.updateSession(auth)) {
|
||||||
}
|
if (cache.containsKey(auth.getNickname())) {
|
||||||
|
PlayerAuth cachedAuth = cache.get(auth.getNickname());
|
||||||
@Override
|
cachedAuth.setIp(oldIp);
|
||||||
public int getIps(String ip) {
|
cachedAuth.setLastLogin(oldLastLogin);
|
||||||
int count = 0;
|
cachedAuth.setRealName(oldRealName);
|
||||||
for (Map.Entry<String, PlayerAuth> p : cache.entrySet()) {
|
}
|
||||||
if (p.getValue().getIp().equals(ip)) {
|
}
|
||||||
count++;
|
}
|
||||||
}
|
});
|
||||||
}
|
return true;
|
||||||
return count;
|
}
|
||||||
}
|
|
||||||
|
/**
|
||||||
@Override
|
* Method updateQuitLoc.
|
||||||
public int purgeDatabase(long until) {
|
*
|
||||||
int cleared = source.purgeDatabase(until);
|
* @param auth PlayerAuth
|
||||||
if (cleared > 0) {
|
*
|
||||||
for (PlayerAuth auth : cache.values()) {
|
* @return boolean * @see fr.xephi.authme.datasource.DataSource#updateQuitLoc(PlayerAuth)
|
||||||
if (auth.getLastLogin() < until) {
|
*/
|
||||||
cache.remove(auth.getNickname());
|
@Override
|
||||||
}
|
public boolean updateQuitLoc(final PlayerAuth auth) {
|
||||||
}
|
if (!cache.containsKey(auth.getNickname())) {
|
||||||
}
|
return false;
|
||||||
return cleared;
|
}
|
||||||
}
|
final PlayerAuth cachedAuth = cache.get(auth.getNickname());
|
||||||
|
final double oldX = cachedAuth.getQuitLocX();
|
||||||
@Override
|
final double oldY = cachedAuth.getQuitLocY();
|
||||||
public List<String> autoPurgeDatabase(long until) {
|
final double oldZ = cachedAuth.getQuitLocZ();
|
||||||
List<String> cleared = source.autoPurgeDatabase(until);
|
final String oldWorld = cachedAuth.getWorld();
|
||||||
if (cleared.size() > 0) {
|
|
||||||
for (PlayerAuth auth : cache.values()) {
|
cachedAuth.setQuitLocX(auth.getQuitLocX());
|
||||||
if (auth.getLastLogin() < until) {
|
cachedAuth.setQuitLocY(auth.getQuitLocY());
|
||||||
cache.remove(auth.getNickname());
|
cachedAuth.setQuitLocZ(auth.getQuitLocZ());
|
||||||
}
|
cachedAuth.setWorld(auth.getWorld());
|
||||||
}
|
exec.execute(new Runnable() {
|
||||||
}
|
@Override
|
||||||
return cleared;
|
public void run() {
|
||||||
}
|
if (!source.updateQuitLoc(auth)) {
|
||||||
|
if (cache.containsKey(auth.getNickname())) {
|
||||||
@Override
|
PlayerAuth cachedAuth = cache.get(auth.getNickname());
|
||||||
public synchronized boolean removeAuth(String username) {
|
cachedAuth.setQuitLocX(oldX);
|
||||||
final String user = username.toLowerCase();
|
cachedAuth.setQuitLocY(oldY);
|
||||||
final PlayerAuth auth = cache.get(user);
|
cachedAuth.setQuitLocZ(oldZ);
|
||||||
cache.remove(user);
|
cachedAuth.setWorld(oldWorld);
|
||||||
exec.execute(new Runnable() {
|
}
|
||||||
@Override
|
}
|
||||||
public void run() {
|
}
|
||||||
if (!source.removeAuth(user)) {
|
});
|
||||||
cache.put(user, auth);
|
return true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
/**
|
||||||
return true;
|
* Method getIps.
|
||||||
}
|
*
|
||||||
|
* @param ip String
|
||||||
@Override
|
*
|
||||||
public synchronized void close() {
|
* @return int * @see fr.xephi.authme.datasource.DataSource#getIps(String)
|
||||||
exec.shutdown();
|
*/
|
||||||
source.close();
|
@Override
|
||||||
}
|
public int getIps(String ip) {
|
||||||
|
int count = 0;
|
||||||
@Override
|
for (Map.Entry<String, PlayerAuth> p : cache.entrySet()) {
|
||||||
public void reload() {
|
if (p.getValue().getIp().equals(ip)) {
|
||||||
exec.execute(new Runnable() {
|
count++;
|
||||||
@Override
|
}
|
||||||
public void run() {
|
}
|
||||||
cache.clear();
|
return count;
|
||||||
source.reload();
|
}
|
||||||
for (Player player : Utils.getOnlinePlayers()) {
|
|
||||||
String user = player.getName().toLowerCase();
|
/**
|
||||||
if (PlayerCache.getInstance().isAuthenticated(user)) {
|
* Method purgeDatabase.
|
||||||
PlayerAuth auth = source.getAuth(user);
|
*
|
||||||
cache.put(user, auth);
|
* @param until long
|
||||||
}
|
*
|
||||||
}
|
* @return int * @see fr.xephi.authme.datasource.DataSource#purgeDatabase(long)
|
||||||
}
|
*/
|
||||||
});
|
@Override
|
||||||
}
|
public int purgeDatabase(long until) {
|
||||||
|
int cleared = source.purgeDatabase(until);
|
||||||
@Override
|
if (cleared > 0) {
|
||||||
public synchronized boolean updateEmail(final PlayerAuth auth) {
|
for (PlayerAuth auth : cache.values()) {
|
||||||
try {
|
if (auth.getLastLogin() < until) {
|
||||||
return exec.submit(new Callable<Boolean>() {
|
cache.remove(auth.getNickname());
|
||||||
public Boolean call() {
|
}
|
||||||
return source.updateEmail(auth);
|
}
|
||||||
}
|
}
|
||||||
}).get();
|
return cleared;
|
||||||
} catch (Exception e) {
|
}
|
||||||
return false;
|
|
||||||
}
|
/**
|
||||||
}
|
* Method autoPurgeDatabase.
|
||||||
|
*
|
||||||
@Override
|
* @param until long
|
||||||
public synchronized boolean updateSalt(final PlayerAuth auth) {
|
*
|
||||||
if (!cache.containsKey(auth.getNickname())) {
|
* @return List<String> * @see fr.xephi.authme.datasource.DataSource#autoPurgeDatabase(long)
|
||||||
return false;
|
*/
|
||||||
}
|
@Override
|
||||||
PlayerAuth cachedAuth = cache.get(auth.getNickname());
|
public List<String> autoPurgeDatabase(long until) {
|
||||||
final String oldSalt = cachedAuth.getSalt();
|
List<String> cleared = source.autoPurgeDatabase(until);
|
||||||
cachedAuth.setSalt(auth.getSalt());
|
if (cleared.size() > 0) {
|
||||||
exec.execute(new Runnable() {
|
for (PlayerAuth auth : cache.values()) {
|
||||||
@Override
|
if (auth.getLastLogin() < until) {
|
||||||
public void run() {
|
cache.remove(auth.getNickname());
|
||||||
if (!source.updateSalt(auth)) {
|
}
|
||||||
if (cache.containsKey(auth.getNickname())) {
|
}
|
||||||
cache.get(auth.getNickname()).setSalt(oldSalt);
|
}
|
||||||
}
|
return cleared;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
/**
|
||||||
return true;
|
* Method removeAuth.
|
||||||
}
|
*
|
||||||
|
* @param username String
|
||||||
@Override
|
*
|
||||||
public synchronized List<String> getAllAuthsByName(PlayerAuth auth) {
|
* @return boolean * @see fr.xephi.authme.datasource.DataSource#removeAuth(String)
|
||||||
List<String> result = new ArrayList<>();
|
*/
|
||||||
for (Map.Entry<String, PlayerAuth> stringPlayerAuthEntry : cache.entrySet()) {
|
@Override
|
||||||
PlayerAuth p = stringPlayerAuthEntry.getValue();
|
public synchronized boolean removeAuth(String username) {
|
||||||
if (p.getIp().equals(auth.getIp()))
|
final String user = username.toLowerCase();
|
||||||
result.add(p.getNickname());
|
final PlayerAuth auth = cache.get(user);
|
||||||
}
|
cache.remove(user);
|
||||||
return result;
|
exec.execute(new Runnable() {
|
||||||
}
|
@Override
|
||||||
|
public void run() {
|
||||||
@Override
|
if (!source.removeAuth(user)) {
|
||||||
public synchronized List<String> getAllAuthsByIp(final String ip) throws Exception {
|
cache.put(user, auth);
|
||||||
return exec.submit(new Callable<List<String>>() {
|
}
|
||||||
public List<String> call() throws Exception {
|
}
|
||||||
return source.getAllAuthsByIp(ip);
|
});
|
||||||
}
|
return true;
|
||||||
}).get();
|
}
|
||||||
}
|
|
||||||
|
/**
|
||||||
@Override
|
* Method close.
|
||||||
public synchronized List<String> getAllAuthsByEmail(final String email) throws Exception {
|
*
|
||||||
return exec.submit(new Callable<List<String>>() {
|
* @see fr.xephi.authme.datasource.DataSource#close()
|
||||||
public List<String> call() throws Exception {
|
*/
|
||||||
return source.getAllAuthsByEmail(email);
|
@Override
|
||||||
}
|
public synchronized void close() {
|
||||||
}).get();
|
exec.shutdown();
|
||||||
}
|
source.close();
|
||||||
|
}
|
||||||
@Override
|
|
||||||
public synchronized void purgeBanned(final List<String> banned) {
|
/**
|
||||||
exec.execute(new Runnable() {
|
* Method reload.
|
||||||
@Override
|
*
|
||||||
public void run() {
|
* @see fr.xephi.authme.datasource.DataSource#reload()
|
||||||
source.purgeBanned(banned);
|
*/
|
||||||
for (PlayerAuth auth : cache.values()) {
|
@Override
|
||||||
if (banned.contains(auth.getNickname())) {
|
public void reload() {
|
||||||
cache.remove(auth.getNickname());
|
exec.execute(new Runnable() {
|
||||||
}
|
@Override
|
||||||
}
|
public void run() {
|
||||||
}
|
cache.clear();
|
||||||
});
|
source.reload();
|
||||||
}
|
for (Player player : Utils.getOnlinePlayers()) {
|
||||||
|
String user = player.getName().toLowerCase();
|
||||||
@Override
|
if (PlayerCache.getInstance().isAuthenticated(user)) {
|
||||||
public DataSourceType getType() {
|
PlayerAuth auth = source.getAuth(user);
|
||||||
return source.getType();
|
cache.put(user, auth);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
@Override
|
}
|
||||||
public boolean isLogged(String user) {
|
});
|
||||||
user = user.toLowerCase();
|
}
|
||||||
return PlayerCache.getInstance().getCache().containsKey(user);
|
|
||||||
}
|
/**
|
||||||
|
* Method updateEmail.
|
||||||
@Override
|
*
|
||||||
public void setLogged(final String user) {
|
* @param auth PlayerAuth
|
||||||
exec.execute(new Runnable() {
|
*
|
||||||
@Override
|
* @return boolean * @see fr.xephi.authme.datasource.DataSource#updateEmail(PlayerAuth)
|
||||||
public void run() {
|
*/
|
||||||
source.setLogged(user.toLowerCase());
|
@Override
|
||||||
}
|
public synchronized boolean updateEmail(final PlayerAuth auth) {
|
||||||
});
|
try {
|
||||||
}
|
return exec.submit(new Callable<Boolean>() {
|
||||||
|
public Boolean call() {
|
||||||
@Override
|
return source.updateEmail(auth);
|
||||||
public void setUnlogged(final String user) {
|
}
|
||||||
exec.execute(new Runnable() {
|
}).get();
|
||||||
@Override
|
} catch (Exception e) {
|
||||||
public void run() {
|
return false;
|
||||||
source.setUnlogged(user.toLowerCase());
|
}
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
/**
|
||||||
|
* Method updateSalt.
|
||||||
@Override
|
*
|
||||||
public void purgeLogged() {
|
* @param auth PlayerAuth
|
||||||
exec.execute(new Runnable() {
|
*
|
||||||
@Override
|
* @return boolean * @see fr.xephi.authme.datasource.DataSource#updateSalt(PlayerAuth)
|
||||||
public void run() {
|
*/
|
||||||
source.purgeLogged();
|
@Override
|
||||||
}
|
public synchronized boolean updateSalt(final PlayerAuth auth) {
|
||||||
});
|
if (!cache.containsKey(auth.getNickname())) {
|
||||||
}
|
return false;
|
||||||
|
}
|
||||||
@Override
|
PlayerAuth cachedAuth = cache.get(auth.getNickname());
|
||||||
public int getAccountsRegistered() {
|
final String oldSalt = cachedAuth.getSalt();
|
||||||
return cache.size();
|
cachedAuth.setSalt(auth.getSalt());
|
||||||
}
|
exec.execute(new Runnable() {
|
||||||
|
@Override
|
||||||
@Override
|
public void run() {
|
||||||
public void updateName(final String oldone, final String newone) {
|
if (!source.updateSalt(auth)) {
|
||||||
if (cache.containsKey(oldone)) {
|
if (cache.containsKey(auth.getNickname())) {
|
||||||
cache.put(newone, cache.get(oldone));
|
cache.get(auth.getNickname()).setSalt(oldSalt);
|
||||||
cache.remove(oldone);
|
}
|
||||||
}
|
}
|
||||||
exec.execute(new Runnable() {
|
}
|
||||||
@Override
|
});
|
||||||
public void run() {
|
return true;
|
||||||
source.updateName(oldone, newone);
|
}
|
||||||
}
|
|
||||||
});
|
/**
|
||||||
}
|
* Method getAllAuthsByName.
|
||||||
|
*
|
||||||
@Override
|
* @param auth PlayerAuth
|
||||||
public List<PlayerAuth> getAllAuths() {
|
*
|
||||||
return new ArrayList<>(cache.values());
|
* @return List<String> * @see fr.xephi.authme.datasource.DataSource#getAllAuthsByName(PlayerAuth)
|
||||||
}
|
*/
|
||||||
|
@Override
|
||||||
@Override
|
public synchronized List<String> getAllAuthsByName(PlayerAuth auth) {
|
||||||
public List<PlayerAuth> getLoggedPlayers() {
|
List<String> result = new ArrayList<>();
|
||||||
return new ArrayList<>(PlayerCache.getInstance().getCache().values());
|
for (Map.Entry<String, PlayerAuth> stringPlayerAuthEntry : cache.entrySet()) {
|
||||||
}
|
PlayerAuth p = stringPlayerAuthEntry.getValue();
|
||||||
}
|
if (p.getIp().equals(auth.getIp()))
|
||||||
|
result.add(p.getNickname());
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method getAllAuthsByIp.
|
||||||
|
*
|
||||||
|
* @param ip String
|
||||||
|
*
|
||||||
|
* @return List<String> * @throws Exception * @see fr.xephi.authme.datasource.DataSource#getAllAuthsByIp(String)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public synchronized List<String> getAllAuthsByIp(final String ip) throws Exception {
|
||||||
|
return exec.submit(new Callable<List<String>>() {
|
||||||
|
public List<String> call() throws Exception {
|
||||||
|
return source.getAllAuthsByIp(ip);
|
||||||
|
}
|
||||||
|
}).get();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method getAllAuthsByEmail.
|
||||||
|
*
|
||||||
|
* @param email String
|
||||||
|
*
|
||||||
|
* @return List<String> * @throws Exception * @see fr.xephi.authme.datasource.DataSource#getAllAuthsByEmail(String)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public synchronized List<String> getAllAuthsByEmail(final String email) throws Exception {
|
||||||
|
return exec.submit(new Callable<List<String>>() {
|
||||||
|
public List<String> call() throws Exception {
|
||||||
|
return source.getAllAuthsByEmail(email);
|
||||||
|
}
|
||||||
|
}).get();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method purgeBanned.
|
||||||
|
*
|
||||||
|
* @param banned List<String>
|
||||||
|
*
|
||||||
|
* @see fr.xephi.authme.datasource.DataSource#purgeBanned(List<String>)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public synchronized void purgeBanned(final List<String> banned) {
|
||||||
|
exec.execute(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
source.purgeBanned(banned);
|
||||||
|
for (PlayerAuth auth : cache.values()) {
|
||||||
|
if (banned.contains(auth.getNickname())) {
|
||||||
|
cache.remove(auth.getNickname());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method getType.
|
||||||
|
*
|
||||||
|
* @return DataSourceType * @see fr.xephi.authme.datasource.DataSource#getType()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public DataSourceType getType() {
|
||||||
|
return source.getType();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method isLogged.
|
||||||
|
*
|
||||||
|
* @param user String
|
||||||
|
*
|
||||||
|
* @return boolean * @see fr.xephi.authme.datasource.DataSource#isLogged(String)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean isLogged(String user) {
|
||||||
|
user = user.toLowerCase();
|
||||||
|
return PlayerCache.getInstance().getCache().containsKey(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method setLogged.
|
||||||
|
*
|
||||||
|
* @param user String
|
||||||
|
*
|
||||||
|
* @see fr.xephi.authme.datasource.DataSource#setLogged(String)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void setLogged(final String user) {
|
||||||
|
exec.execute(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
source.setLogged(user.toLowerCase());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method setUnlogged.
|
||||||
|
*
|
||||||
|
* @param user String
|
||||||
|
*
|
||||||
|
* @see fr.xephi.authme.datasource.DataSource#setUnlogged(String)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void setUnlogged(final String user) {
|
||||||
|
exec.execute(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
source.setUnlogged(user.toLowerCase());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method purgeLogged.
|
||||||
|
*
|
||||||
|
* @see fr.xephi.authme.datasource.DataSource#purgeLogged()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void purgeLogged() {
|
||||||
|
exec.execute(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
source.purgeLogged();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method getAccountsRegistered.
|
||||||
|
*
|
||||||
|
* @return int * @see fr.xephi.authme.datasource.DataSource#getAccountsRegistered()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public int getAccountsRegistered() {
|
||||||
|
return cache.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method updateName.
|
||||||
|
*
|
||||||
|
* @param oldOne String
|
||||||
|
* @param newOne String
|
||||||
|
*
|
||||||
|
* @see fr.xephi.authme.datasource.DataSource#updateName(String, String)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void updateName(final String oldOne, final String newOne) {
|
||||||
|
if (cache.containsKey(oldOne)) {
|
||||||
|
cache.put(newOne, cache.get(oldOne));
|
||||||
|
cache.remove(oldOne);
|
||||||
|
}
|
||||||
|
exec.execute(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
source.updateName(oldOne, newOne);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method getAllAuths.
|
||||||
|
*
|
||||||
|
* @return List<PlayerAuth> * @see fr.xephi.authme.datasource.DataSource#getAllAuths()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<PlayerAuth> getAllAuths() {
|
||||||
|
return new ArrayList<>(cache.values());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method getLoggedPlayers.
|
||||||
|
*
|
||||||
|
* @return List<PlayerAuth> * @see fr.xephi.authme.datasource.DataSource#getLoggedPlayers()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<PlayerAuth> getLoggedPlayers() {
|
||||||
|
return new ArrayList<>(PlayerCache.getInstance().getCache().values());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -1,69 +1,223 @@
|
|||||||
package fr.xephi.authme.datasource;
|
package fr.xephi.authme.datasource;
|
||||||
|
|
||||||
import java.util.List;
|
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||||
|
|
||||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
import java.util.List;
|
||||||
|
|
||||||
public interface DataSource {
|
/**
|
||||||
|
*/
|
||||||
enum DataSourceType {
|
public interface DataSource {
|
||||||
MYSQL,
|
|
||||||
FILE,
|
/**
|
||||||
SQLITE
|
* Method isAuthAvailable.
|
||||||
}
|
*
|
||||||
|
* @param user String
|
||||||
boolean isAuthAvailable(String user);
|
*
|
||||||
|
* @return boolean
|
||||||
PlayerAuth getAuth(String user);
|
*/
|
||||||
|
boolean isAuthAvailable(String user);
|
||||||
boolean saveAuth(PlayerAuth auth);
|
|
||||||
|
/**
|
||||||
boolean updateSession(PlayerAuth auth);
|
* Method getAuth.
|
||||||
|
*
|
||||||
boolean updatePassword(PlayerAuth auth);
|
* @param user String
|
||||||
|
*
|
||||||
int purgeDatabase(long until);
|
* @return PlayerAuth
|
||||||
|
*/
|
||||||
List<String> autoPurgeDatabase(long until);
|
PlayerAuth getAuth(String user);
|
||||||
|
|
||||||
boolean removeAuth(String user);
|
/**
|
||||||
|
* Method saveAuth.
|
||||||
boolean updateQuitLoc(PlayerAuth auth);
|
*
|
||||||
|
* @param auth PlayerAuth
|
||||||
int getIps(String ip);
|
*
|
||||||
|
* @return boolean
|
||||||
List<String> getAllAuthsByName(PlayerAuth auth);
|
*/
|
||||||
|
boolean saveAuth(PlayerAuth auth);
|
||||||
List<String> getAllAuthsByIp(String ip) throws Exception;
|
|
||||||
|
/**
|
||||||
List<String> getAllAuthsByEmail(String email) throws Exception;
|
* Method updateSession.
|
||||||
|
*
|
||||||
boolean updateEmail(PlayerAuth auth);
|
* @param auth PlayerAuth
|
||||||
|
*
|
||||||
boolean updateSalt(PlayerAuth auth);
|
* @return boolean
|
||||||
|
*/
|
||||||
void close();
|
boolean updateSession(PlayerAuth auth);
|
||||||
|
|
||||||
void reload();
|
/**
|
||||||
|
* Method updatePassword.
|
||||||
void purgeBanned(List<String> banned);
|
*
|
||||||
|
* @param auth PlayerAuth
|
||||||
DataSourceType getType();
|
*
|
||||||
|
* @return boolean
|
||||||
boolean isLogged(String user);
|
*/
|
||||||
|
boolean updatePassword(PlayerAuth auth);
|
||||||
void setLogged(String user);
|
|
||||||
|
/**
|
||||||
void setUnlogged(String user);
|
* Method purgeDatabase.
|
||||||
|
*
|
||||||
void purgeLogged();
|
* @param until long
|
||||||
|
*
|
||||||
int getAccountsRegistered();
|
* @return int
|
||||||
|
*/
|
||||||
void updateName(String oldone, String newone);
|
int purgeDatabase(long until);
|
||||||
|
|
||||||
List<PlayerAuth> getAllAuths();
|
/**
|
||||||
|
* Method autoPurgeDatabase.
|
||||||
List<PlayerAuth> getLoggedPlayers();
|
*
|
||||||
|
* @param until long
|
||||||
}
|
*
|
||||||
|
* @return List<String>
|
||||||
|
*/
|
||||||
|
List<String> autoPurgeDatabase(long until);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method removeAuth.
|
||||||
|
*
|
||||||
|
* @param user String
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
boolean removeAuth(String user);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method updateQuitLoc.
|
||||||
|
*
|
||||||
|
* @param auth PlayerAuth
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
boolean updateQuitLoc(PlayerAuth auth);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method getIps.
|
||||||
|
*
|
||||||
|
* @param ip String
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
int getIps(String ip);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method getAllAuthsByName.
|
||||||
|
*
|
||||||
|
* @param auth PlayerAuth
|
||||||
|
*
|
||||||
|
* @return List<String>
|
||||||
|
*/
|
||||||
|
List<String> getAllAuthsByName(PlayerAuth auth);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method getAllAuthsByIp.
|
||||||
|
*
|
||||||
|
* @param ip String
|
||||||
|
*
|
||||||
|
* @return List<String> * @throws Exception
|
||||||
|
*/
|
||||||
|
List<String> getAllAuthsByIp(String ip) throws Exception;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method getAllAuthsByEmail.
|
||||||
|
*
|
||||||
|
* @param email String
|
||||||
|
*
|
||||||
|
* @return List<String> * @throws Exception
|
||||||
|
*/
|
||||||
|
List<String> getAllAuthsByEmail(String email) throws Exception;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method updateEmail.
|
||||||
|
*
|
||||||
|
* @param auth PlayerAuth
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
boolean updateEmail(PlayerAuth auth);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method updateSalt.
|
||||||
|
*
|
||||||
|
* @param auth PlayerAuth
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
boolean updateSalt(PlayerAuth auth);
|
||||||
|
|
||||||
|
void close();
|
||||||
|
|
||||||
|
void reload();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method purgeBanned.
|
||||||
|
*
|
||||||
|
* @param banned List<String>
|
||||||
|
*/
|
||||||
|
void purgeBanned(List<String> banned);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method getType.
|
||||||
|
*
|
||||||
|
* @return DataSourceType
|
||||||
|
*/
|
||||||
|
DataSourceType getType();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method isLogged.
|
||||||
|
*
|
||||||
|
* @param user String
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
boolean isLogged(String user);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method setLogged.
|
||||||
|
*
|
||||||
|
* @param user String
|
||||||
|
*/
|
||||||
|
void setLogged(String user);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method setUnlogged.
|
||||||
|
*
|
||||||
|
* @param user String
|
||||||
|
*/
|
||||||
|
void setUnlogged(String user);
|
||||||
|
|
||||||
|
void purgeLogged();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method getAccountsRegistered.
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
int getAccountsRegistered();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method updateName.
|
||||||
|
*
|
||||||
|
* @param oldOne String
|
||||||
|
* @param newOne String
|
||||||
|
*/
|
||||||
|
void updateName(String oldOne, String newOne);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method getAllAuths.
|
||||||
|
*
|
||||||
|
* @return List<PlayerAuth>
|
||||||
|
*/
|
||||||
|
List<PlayerAuth> getAllAuths();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method getLoggedPlayers.
|
||||||
|
*
|
||||||
|
* @return List<PlayerAuth>
|
||||||
|
*/
|
||||||
|
List<PlayerAuth> getLoggedPlayers();
|
||||||
|
|
||||||
|
enum DataSourceType {
|
||||||
|
MYSQL,
|
||||||
|
FILE,
|
||||||
|
SQLITE
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -1,330 +1,513 @@
|
|||||||
package fr.xephi.authme.datasource;
|
package fr.xephi.authme.datasource;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||||
import java.util.List;
|
|
||||||
import java.util.concurrent.Callable;
|
import java.util.ArrayList;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.List;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Callable;
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
import java.util.concurrent.Executors;
|
||||||
|
|
||||||
public class DatabaseCalls implements DataSource {
|
/**
|
||||||
|
*/
|
||||||
private DataSource database;
|
public class DatabaseCalls implements DataSource {
|
||||||
private final ExecutorService exec;
|
|
||||||
|
private final ExecutorService exec;
|
||||||
public DatabaseCalls(DataSource database) {
|
private final DataSource database;
|
||||||
this.database = database;
|
|
||||||
this.exec = Executors.newCachedThreadPool();
|
/**
|
||||||
}
|
* Constructor for DatabaseCalls.
|
||||||
|
*
|
||||||
@Override
|
* @param database DataSource
|
||||||
public synchronized boolean isAuthAvailable(final String user) {
|
*/
|
||||||
try {
|
public DatabaseCalls(DataSource database) {
|
||||||
return exec.submit(new Callable<Boolean>() {
|
this.database = database;
|
||||||
public Boolean call() throws Exception {
|
this.exec = Executors.newCachedThreadPool();
|
||||||
return database.isAuthAvailable(user);
|
}
|
||||||
}
|
|
||||||
}).get();
|
/**
|
||||||
} catch (Exception e) {
|
* Method isAuthAvailable.
|
||||||
return false;
|
*
|
||||||
}
|
* @param user String
|
||||||
}
|
*
|
||||||
|
* @return boolean * @see fr.xephi.authme.datasource.DataSource#isAuthAvailable(String)
|
||||||
@Override
|
*/
|
||||||
public synchronized PlayerAuth getAuth(final String user) {
|
@Override
|
||||||
try {
|
public synchronized boolean isAuthAvailable(final String user) {
|
||||||
return exec.submit(new Callable<PlayerAuth>() {
|
try {
|
||||||
public PlayerAuth call() throws Exception {
|
return exec.submit(new Callable<Boolean>() {
|
||||||
return database.getAuth(user);
|
public Boolean call() throws Exception {
|
||||||
}
|
return database.isAuthAvailable(user);
|
||||||
}).get();
|
}
|
||||||
} catch (Exception e) {
|
}).get();
|
||||||
return null;
|
} catch (Exception e) {
|
||||||
}
|
return false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
@Override
|
|
||||||
public synchronized boolean saveAuth(final PlayerAuth auth) {
|
/**
|
||||||
try {
|
* Method getAuth.
|
||||||
return exec.submit(new Callable<Boolean>() {
|
*
|
||||||
public Boolean call() throws Exception {
|
* @param user String
|
||||||
return database.saveAuth(auth);
|
*
|
||||||
}
|
* @return PlayerAuth * @see fr.xephi.authme.datasource.DataSource#getAuth(String)
|
||||||
}).get();
|
*/
|
||||||
} catch (Exception e) {
|
@Override
|
||||||
return false;
|
public synchronized PlayerAuth getAuth(final String user) {
|
||||||
}
|
try {
|
||||||
}
|
return exec.submit(new Callable<PlayerAuth>() {
|
||||||
|
public PlayerAuth call() throws Exception {
|
||||||
@Override
|
return database.getAuth(user);
|
||||||
public synchronized boolean updateSession(final PlayerAuth auth) {
|
}
|
||||||
try {
|
}).get();
|
||||||
return exec.submit(new Callable<Boolean>() {
|
} catch (Exception e) {
|
||||||
public Boolean call() throws Exception {
|
return null;
|
||||||
return database.updateSession(auth);
|
}
|
||||||
}
|
}
|
||||||
}).get();
|
|
||||||
} catch (Exception e) {
|
/**
|
||||||
return false;
|
* Method saveAuth.
|
||||||
}
|
*
|
||||||
}
|
* @param auth PlayerAuth
|
||||||
|
*
|
||||||
@Override
|
* @return boolean * @see fr.xephi.authme.datasource.DataSource#saveAuth(PlayerAuth)
|
||||||
public synchronized boolean updatePassword(final PlayerAuth auth) {
|
*/
|
||||||
try {
|
@Override
|
||||||
return exec.submit(new Callable<Boolean>() {
|
public synchronized boolean saveAuth(final PlayerAuth auth) {
|
||||||
public Boolean call() throws Exception {
|
try {
|
||||||
return database.updatePassword(auth);
|
return exec.submit(new Callable<Boolean>() {
|
||||||
}
|
public Boolean call() throws Exception {
|
||||||
}).get();
|
return database.saveAuth(auth);
|
||||||
} catch (Exception e) {
|
}
|
||||||
return false;
|
}).get();
|
||||||
}
|
} catch (Exception e) {
|
||||||
}
|
return false;
|
||||||
|
}
|
||||||
@Override
|
}
|
||||||
public synchronized int purgeDatabase(final long until) {
|
|
||||||
try {
|
/**
|
||||||
return exec.submit(new Callable<Integer>() {
|
* Method updateSession.
|
||||||
public Integer call() throws Exception {
|
*
|
||||||
return database.purgeDatabase(until);
|
* @param auth PlayerAuth
|
||||||
}
|
*
|
||||||
}).get();
|
* @return boolean * @see fr.xephi.authme.datasource.DataSource#updateSession(PlayerAuth)
|
||||||
} catch (Exception e) {
|
*/
|
||||||
return -1;
|
@Override
|
||||||
}
|
public synchronized boolean updateSession(final PlayerAuth auth) {
|
||||||
}
|
try {
|
||||||
|
return exec.submit(new Callable<Boolean>() {
|
||||||
@Override
|
public Boolean call() throws Exception {
|
||||||
public synchronized List<String> autoPurgeDatabase(final long until) {
|
return database.updateSession(auth);
|
||||||
try {
|
}
|
||||||
return exec.submit(new Callable<List<String>>() {
|
}).get();
|
||||||
public List<String> call() throws Exception {
|
} catch (Exception e) {
|
||||||
return database.autoPurgeDatabase(until);
|
return false;
|
||||||
}
|
}
|
||||||
}).get();
|
}
|
||||||
} catch (Exception e) {
|
|
||||||
return new ArrayList<>();
|
/**
|
||||||
}
|
* Method updatePassword.
|
||||||
}
|
*
|
||||||
|
* @param auth PlayerAuth
|
||||||
@Override
|
*
|
||||||
public synchronized boolean removeAuth(final String user) {
|
* @return boolean * @see fr.xephi.authme.datasource.DataSource#updatePassword(PlayerAuth)
|
||||||
try {
|
*/
|
||||||
return exec.submit(new Callable<Boolean>() {
|
@Override
|
||||||
public Boolean call() throws Exception {
|
public synchronized boolean updatePassword(final PlayerAuth auth) {
|
||||||
return database.removeAuth(user);
|
try {
|
||||||
}
|
return exec.submit(new Callable<Boolean>() {
|
||||||
}).get();
|
public Boolean call() throws Exception {
|
||||||
} catch (Exception e) {
|
return database.updatePassword(auth);
|
||||||
return false;
|
}
|
||||||
}
|
}).get();
|
||||||
}
|
} catch (Exception e) {
|
||||||
|
return false;
|
||||||
@Override
|
}
|
||||||
public synchronized boolean updateQuitLoc(final PlayerAuth auth) {
|
}
|
||||||
try {
|
|
||||||
return exec.submit(new Callable<Boolean>() {
|
/**
|
||||||
public Boolean call() throws Exception {
|
* Method purgeDatabase.
|
||||||
return database.updateQuitLoc(auth);
|
*
|
||||||
}
|
* @param until long
|
||||||
}).get();
|
*
|
||||||
} catch (Exception e) {
|
* @return int * @see fr.xephi.authme.datasource.DataSource#purgeDatabase(long)
|
||||||
return false;
|
*/
|
||||||
}
|
@Override
|
||||||
}
|
public synchronized int purgeDatabase(final long until) {
|
||||||
|
try {
|
||||||
@Override
|
return exec.submit(new Callable<Integer>() {
|
||||||
public synchronized int getIps(final String ip) {
|
public Integer call() throws Exception {
|
||||||
try {
|
return database.purgeDatabase(until);
|
||||||
return exec.submit(new Callable<Integer>() {
|
}
|
||||||
|
}).get();
|
||||||
public Integer call() throws Exception {
|
} catch (Exception e) {
|
||||||
return database.getIps(ip);
|
return -1;
|
||||||
}
|
}
|
||||||
}).get();
|
}
|
||||||
} catch (Exception e) {
|
|
||||||
return -1;
|
/**
|
||||||
}
|
* Method autoPurgeDatabase.
|
||||||
}
|
*
|
||||||
|
* @param until long
|
||||||
@Override
|
*
|
||||||
public synchronized List<String> getAllAuthsByName(final PlayerAuth auth) {
|
* @return List<String> * @see fr.xephi.authme.datasource.DataSource#autoPurgeDatabase(long)
|
||||||
try {
|
*/
|
||||||
return exec.submit(new Callable<List<String>>() {
|
@Override
|
||||||
public List<String> call() throws Exception {
|
public synchronized List<String> autoPurgeDatabase(final long until) {
|
||||||
return database.getAllAuthsByName(auth);
|
try {
|
||||||
}
|
return exec.submit(new Callable<List<String>>() {
|
||||||
}).get();
|
public List<String> call() throws Exception {
|
||||||
} catch (Exception e) {
|
return database.autoPurgeDatabase(until);
|
||||||
return new ArrayList<>();
|
}
|
||||||
}
|
}).get();
|
||||||
}
|
} catch (Exception e) {
|
||||||
|
return new ArrayList<>();
|
||||||
@Override
|
}
|
||||||
public synchronized List<String> getAllAuthsByIp(final String ip) {
|
}
|
||||||
try {
|
|
||||||
return exec.submit(new Callable<List<String>>() {
|
/**
|
||||||
public List<String> call() throws Exception {
|
* Method removeAuth.
|
||||||
return database.getAllAuthsByIp(ip);
|
*
|
||||||
}
|
* @param user String
|
||||||
}).get();
|
*
|
||||||
} catch (Exception e) {
|
* @return boolean * @see fr.xephi.authme.datasource.DataSource#removeAuth(String)
|
||||||
return new ArrayList<>();
|
*/
|
||||||
}
|
@Override
|
||||||
}
|
public synchronized boolean removeAuth(final String user) {
|
||||||
|
try {
|
||||||
@Override
|
return exec.submit(new Callable<Boolean>() {
|
||||||
public synchronized List<String> getAllAuthsByEmail(final String email) {
|
public Boolean call() throws Exception {
|
||||||
try {
|
return database.removeAuth(user);
|
||||||
return exec.submit(new Callable<List<String>>() {
|
}
|
||||||
public List<String> call() throws Exception {
|
}).get();
|
||||||
return database.getAllAuthsByEmail(email);
|
} catch (Exception e) {
|
||||||
}
|
return false;
|
||||||
}).get();
|
}
|
||||||
} catch (Exception e) {
|
}
|
||||||
return new ArrayList<>();
|
|
||||||
}
|
/**
|
||||||
}
|
* Method updateQuitLoc.
|
||||||
|
*
|
||||||
@Override
|
* @param auth PlayerAuth
|
||||||
public synchronized boolean updateEmail(final PlayerAuth auth) {
|
*
|
||||||
try {
|
* @return boolean * @see fr.xephi.authme.datasource.DataSource#updateQuitLoc(PlayerAuth)
|
||||||
return exec.submit(new Callable<Boolean>() {
|
*/
|
||||||
public Boolean call() throws Exception {
|
@Override
|
||||||
return database.updateEmail(auth);
|
public synchronized boolean updateQuitLoc(final PlayerAuth auth) {
|
||||||
}
|
try {
|
||||||
}).get();
|
return exec.submit(new Callable<Boolean>() {
|
||||||
} catch (Exception e) {
|
public Boolean call() throws Exception {
|
||||||
return false;
|
return database.updateQuitLoc(auth);
|
||||||
}
|
}
|
||||||
}
|
}).get();
|
||||||
|
} catch (Exception e) {
|
||||||
@Override
|
return false;
|
||||||
public synchronized boolean updateSalt(final PlayerAuth auth) {
|
}
|
||||||
try {
|
}
|
||||||
return exec.submit(new Callable<Boolean>() {
|
|
||||||
public Boolean call() throws Exception {
|
/**
|
||||||
return database.updateSalt(auth);
|
* Method getIps.
|
||||||
}
|
*
|
||||||
}).get();
|
* @param ip String
|
||||||
} catch (Exception e) {
|
*
|
||||||
return false;
|
* @return int * @see fr.xephi.authme.datasource.DataSource#getIps(String)
|
||||||
}
|
*/
|
||||||
}
|
@Override
|
||||||
|
public synchronized int getIps(final String ip) {
|
||||||
@Override
|
try {
|
||||||
public synchronized void close() {
|
return exec.submit(new Callable<Integer>() {
|
||||||
exec.shutdown();
|
|
||||||
database.close();
|
public Integer call() throws Exception {
|
||||||
}
|
return database.getIps(ip);
|
||||||
|
}
|
||||||
@Override
|
}).get();
|
||||||
public synchronized void reload() {
|
} catch (Exception e) {
|
||||||
database.reload();
|
return -1;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
@Override
|
|
||||||
public synchronized void purgeBanned(final List<String> banned) {
|
/**
|
||||||
new Thread(new Runnable() {
|
* Method getAllAuthsByName.
|
||||||
public synchronized void run() {
|
*
|
||||||
database.purgeBanned(banned);
|
* @param auth PlayerAuth
|
||||||
}
|
*
|
||||||
}).start();
|
* @return List<String> * @see fr.xephi.authme.datasource.DataSource#getAllAuthsByName(PlayerAuth)
|
||||||
}
|
*/
|
||||||
|
@Override
|
||||||
@Override
|
public synchronized List<String> getAllAuthsByName(final PlayerAuth auth) {
|
||||||
public synchronized DataSourceType getType() {
|
try {
|
||||||
return database.getType();
|
return exec.submit(new Callable<List<String>>() {
|
||||||
}
|
public List<String> call() throws Exception {
|
||||||
|
return database.getAllAuthsByName(auth);
|
||||||
@Override
|
}
|
||||||
public synchronized boolean isLogged(final String user) {
|
}).get();
|
||||||
try {
|
} catch (Exception e) {
|
||||||
return exec.submit(new Callable<Boolean>() {
|
return new ArrayList<>();
|
||||||
public Boolean call() throws Exception {
|
}
|
||||||
return database.isLogged(user);
|
}
|
||||||
}
|
|
||||||
}).get();
|
/**
|
||||||
} catch (Exception e) {
|
* Method getAllAuthsByIp.
|
||||||
return false;
|
*
|
||||||
}
|
* @param ip String
|
||||||
}
|
*
|
||||||
|
* @return List<String> * @see fr.xephi.authme.datasource.DataSource#getAllAuthsByIp(String)
|
||||||
@Override
|
*/
|
||||||
public synchronized void setLogged(final String user) {
|
@Override
|
||||||
exec.execute(new Runnable() {
|
public synchronized List<String> getAllAuthsByIp(final String ip) {
|
||||||
public synchronized void run() {
|
try {
|
||||||
database.setLogged(user);
|
return exec.submit(new Callable<List<String>>() {
|
||||||
}
|
public List<String> call() throws Exception {
|
||||||
});
|
return database.getAllAuthsByIp(ip);
|
||||||
}
|
}
|
||||||
|
}).get();
|
||||||
@Override
|
} catch (Exception e) {
|
||||||
public synchronized void setUnlogged(final String user) {
|
return new ArrayList<>();
|
||||||
exec.execute(new Runnable() {
|
}
|
||||||
public synchronized void run() {
|
}
|
||||||
database.setUnlogged(user);
|
|
||||||
}
|
/**
|
||||||
});
|
* Method getAllAuthsByEmail.
|
||||||
}
|
*
|
||||||
|
* @param email String
|
||||||
@Override
|
*
|
||||||
public synchronized void purgeLogged() {
|
* @return List<String> * @see fr.xephi.authme.datasource.DataSource#getAllAuthsByEmail(String)
|
||||||
exec.execute(new Runnable() {
|
*/
|
||||||
public synchronized void run() {
|
@Override
|
||||||
database.purgeLogged();
|
public synchronized List<String> getAllAuthsByEmail(final String email) {
|
||||||
}
|
try {
|
||||||
});
|
return exec.submit(new Callable<List<String>>() {
|
||||||
}
|
public List<String> call() throws Exception {
|
||||||
|
return database.getAllAuthsByEmail(email);
|
||||||
@Override
|
}
|
||||||
public synchronized int getAccountsRegistered() {
|
}).get();
|
||||||
try {
|
} catch (Exception e) {
|
||||||
return exec.submit(new Callable<Integer>() {
|
return new ArrayList<>();
|
||||||
public Integer call() throws Exception {
|
}
|
||||||
return database.getAccountsRegistered();
|
}
|
||||||
}
|
|
||||||
}).get();
|
/**
|
||||||
} catch (Exception e) {
|
* Method updateEmail.
|
||||||
return -1;
|
*
|
||||||
}
|
* @param auth PlayerAuth
|
||||||
}
|
*
|
||||||
|
* @return boolean * @see fr.xephi.authme.datasource.DataSource#updateEmail(PlayerAuth)
|
||||||
@Override
|
*/
|
||||||
public synchronized void updateName(final String oldone, final String newone) {
|
@Override
|
||||||
exec.execute(new Runnable() {
|
public synchronized boolean updateEmail(final PlayerAuth auth) {
|
||||||
public synchronized void run() {
|
try {
|
||||||
database.updateName(oldone, newone);
|
return exec.submit(new Callable<Boolean>() {
|
||||||
}
|
public Boolean call() throws Exception {
|
||||||
});
|
return database.updateEmail(auth);
|
||||||
}
|
}
|
||||||
|
}).get();
|
||||||
@Override
|
} catch (Exception e) {
|
||||||
public synchronized List<PlayerAuth> getAllAuths() {
|
return false;
|
||||||
try {
|
}
|
||||||
return exec.submit(new Callable<List<PlayerAuth>>() {
|
}
|
||||||
public List<PlayerAuth> call() throws Exception {
|
|
||||||
return database.getAllAuths();
|
/**
|
||||||
}
|
* Method updateSalt.
|
||||||
}).get();
|
*
|
||||||
} catch (Exception e) {
|
* @param auth PlayerAuth
|
||||||
return new ArrayList<>();
|
*
|
||||||
}
|
* @return boolean * @see fr.xephi.authme.datasource.DataSource#updateSalt(PlayerAuth)
|
||||||
}
|
*/
|
||||||
|
@Override
|
||||||
@Override
|
public synchronized boolean updateSalt(final PlayerAuth auth) {
|
||||||
public List<PlayerAuth> getLoggedPlayers() {
|
try {
|
||||||
try {
|
return exec.submit(new Callable<Boolean>() {
|
||||||
return exec.submit(new Callable<List<PlayerAuth>>() {
|
public Boolean call() throws Exception {
|
||||||
public List<PlayerAuth> call() throws Exception {
|
return database.updateSalt(auth);
|
||||||
return database.getLoggedPlayers();
|
}
|
||||||
}
|
}).get();
|
||||||
}).get();
|
} catch (Exception e) {
|
||||||
} catch (Exception e) {
|
return false;
|
||||||
return new ArrayList<>();
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
/**
|
||||||
}
|
* Method close.
|
||||||
|
*
|
||||||
|
* @see fr.xephi.authme.datasource.DataSource#close()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public synchronized void close() {
|
||||||
|
exec.shutdown();
|
||||||
|
database.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method reload.
|
||||||
|
*
|
||||||
|
* @see fr.xephi.authme.datasource.DataSource#reload()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public synchronized void reload() {
|
||||||
|
database.reload();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method purgeBanned.
|
||||||
|
*
|
||||||
|
* @param banned List<String>
|
||||||
|
*
|
||||||
|
* @see fr.xephi.authme.datasource.DataSource#purgeBanned(List<String>)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public synchronized void purgeBanned(final List<String> banned) {
|
||||||
|
new Thread(new Runnable() {
|
||||||
|
public synchronized void run() {
|
||||||
|
database.purgeBanned(banned);
|
||||||
|
}
|
||||||
|
}).start();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method getType.
|
||||||
|
*
|
||||||
|
* @return DataSourceType * @see fr.xephi.authme.datasource.DataSource#getType()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public synchronized DataSourceType getType() {
|
||||||
|
return database.getType();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method isLogged.
|
||||||
|
*
|
||||||
|
* @param user String
|
||||||
|
*
|
||||||
|
* @return boolean * @see fr.xephi.authme.datasource.DataSource#isLogged(String)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public synchronized boolean isLogged(final String user) {
|
||||||
|
try {
|
||||||
|
return exec.submit(new Callable<Boolean>() {
|
||||||
|
public Boolean call() throws Exception {
|
||||||
|
return database.isLogged(user);
|
||||||
|
}
|
||||||
|
}).get();
|
||||||
|
} catch (Exception e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method setLogged.
|
||||||
|
*
|
||||||
|
* @param user String
|
||||||
|
*
|
||||||
|
* @see fr.xephi.authme.datasource.DataSource#setLogged(String)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public synchronized void setLogged(final String user) {
|
||||||
|
exec.execute(new Runnable() {
|
||||||
|
public synchronized void run() {
|
||||||
|
database.setLogged(user);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method setUnlogged.
|
||||||
|
*
|
||||||
|
* @param user String
|
||||||
|
*
|
||||||
|
* @see fr.xephi.authme.datasource.DataSource#setUnlogged(String)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public synchronized void setUnlogged(final String user) {
|
||||||
|
exec.execute(new Runnable() {
|
||||||
|
public synchronized void run() {
|
||||||
|
database.setUnlogged(user);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method purgeLogged.
|
||||||
|
*
|
||||||
|
* @see fr.xephi.authme.datasource.DataSource#purgeLogged()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public synchronized void purgeLogged() {
|
||||||
|
exec.execute(new Runnable() {
|
||||||
|
public synchronized void run() {
|
||||||
|
database.purgeLogged();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method getAccountsRegistered.
|
||||||
|
*
|
||||||
|
* @return int * @see fr.xephi.authme.datasource.DataSource#getAccountsRegistered()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public synchronized int getAccountsRegistered() {
|
||||||
|
try {
|
||||||
|
return exec.submit(new Callable<Integer>() {
|
||||||
|
public Integer call() throws Exception {
|
||||||
|
return database.getAccountsRegistered();
|
||||||
|
}
|
||||||
|
}).get();
|
||||||
|
} catch (Exception e) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method updateName.
|
||||||
|
*
|
||||||
|
* @param oldOne String
|
||||||
|
* @param newOne String
|
||||||
|
*
|
||||||
|
* @see fr.xephi.authme.datasource.DataSource#updateName(String, String)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public synchronized void updateName(final String oldOne, final String newOne) {
|
||||||
|
exec.execute(new Runnable() {
|
||||||
|
public synchronized void run() {
|
||||||
|
database.updateName(oldOne, newOne);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method getAllAuths.
|
||||||
|
*
|
||||||
|
* @return List<PlayerAuth> * @see fr.xephi.authme.datasource.DataSource#getAllAuths()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public synchronized List<PlayerAuth> getAllAuths() {
|
||||||
|
try {
|
||||||
|
return exec.submit(new Callable<List<PlayerAuth>>() {
|
||||||
|
public List<PlayerAuth> call() throws Exception {
|
||||||
|
return database.getAllAuths();
|
||||||
|
}
|
||||||
|
}).get();
|
||||||
|
} catch (Exception e) {
|
||||||
|
return new ArrayList<>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method getLoggedPlayers.
|
||||||
|
*
|
||||||
|
* @return List<PlayerAuth> * @see fr.xephi.authme.datasource.DataSource#getLoggedPlayers()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<PlayerAuth> getLoggedPlayers() {
|
||||||
|
try {
|
||||||
|
return exec.submit(new Callable<List<PlayerAuth>>() {
|
||||||
|
public List<PlayerAuth> call() throws Exception {
|
||||||
|
return database.getLoggedPlayers();
|
||||||
|
}
|
||||||
|
}).get();
|
||||||
|
} catch (Exception e) {
|
||||||
|
return new ArrayList<>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
@ -1,21 +1,17 @@
|
|||||||
package fr.xephi.authme.datasource;
|
package fr.xephi.authme.datasource;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.BufferedWriter;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.FileReader;
|
|
||||||
import java.io.FileWriter;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import fr.xephi.authme.AuthMe;
|
import fr.xephi.authme.AuthMe;
|
||||||
import fr.xephi.authme.ConsoleLogger;
|
import fr.xephi.authme.ConsoleLogger;
|
||||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||||
import fr.xephi.authme.cache.auth.PlayerCache;
|
import fr.xephi.authme.cache.auth.PlayerCache;
|
||||||
import fr.xephi.authme.settings.Settings;
|
import fr.xephi.authme.settings.Settings;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
public class FlatFile implements DataSource {
|
public class FlatFile implements DataSource {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -29,7 +25,7 @@ public class FlatFile implements DataSource {
|
|||||||
* :LASTPOSZ:LASTPOSWORLD PLAYERNAME:HASHSUM:IP:LOGININMILLIESECONDS
|
* :LASTPOSZ:LASTPOSWORLD PLAYERNAME:HASHSUM:IP:LOGININMILLIESECONDS
|
||||||
* PLAYERNAME:HASHSUM:IP PLAYERNAME:HASHSUM
|
* PLAYERNAME:HASHSUM:IP PLAYERNAME:HASHSUM
|
||||||
*/
|
*/
|
||||||
private File source;
|
private final File source;
|
||||||
|
|
||||||
public FlatFile() {
|
public FlatFile() {
|
||||||
source = Settings.AUTH_FILE;
|
source = Settings.AUTH_FILE;
|
||||||
@ -48,6 +44,13 @@ public class FlatFile implements DataSource {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method isAuthAvailable.
|
||||||
|
*
|
||||||
|
* @param user String
|
||||||
|
*
|
||||||
|
* @return boolean * @see fr.xephi.authme.datasource.DataSource#isAuthAvailable(String)
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public synchronized boolean isAuthAvailable(String user) {
|
public synchronized boolean isAuthAvailable(String user) {
|
||||||
BufferedReader br = null;
|
BufferedReader br = null;
|
||||||
@ -70,13 +73,20 @@ public class FlatFile implements DataSource {
|
|||||||
if (br != null) {
|
if (br != null) {
|
||||||
try {
|
try {
|
||||||
br.close();
|
br.close();
|
||||||
} catch (IOException ex) {
|
} catch (IOException ignored) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method saveAuth.
|
||||||
|
*
|
||||||
|
* @param auth PlayerAuth
|
||||||
|
*
|
||||||
|
* @return boolean * @see fr.xephi.authme.datasource.DataSource#saveAuth(PlayerAuth)
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public synchronized boolean saveAuth(PlayerAuth auth) {
|
public synchronized boolean saveAuth(PlayerAuth auth) {
|
||||||
if (isAuthAvailable(auth.getNickname())) {
|
if (isAuthAvailable(auth.getNickname())) {
|
||||||
@ -93,13 +103,20 @@ public class FlatFile implements DataSource {
|
|||||||
if (bw != null) {
|
if (bw != null) {
|
||||||
try {
|
try {
|
||||||
bw.close();
|
bw.close();
|
||||||
} catch (IOException ex) {
|
} catch (IOException ignored) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method updatePassword.
|
||||||
|
*
|
||||||
|
* @param auth PlayerAuth
|
||||||
|
*
|
||||||
|
* @return boolean * @see fr.xephi.authme.datasource.DataSource#updatePassword(PlayerAuth)
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public synchronized boolean updatePassword(PlayerAuth auth) {
|
public synchronized boolean updatePassword(PlayerAuth auth) {
|
||||||
if (!isAuthAvailable(auth.getNickname())) {
|
if (!isAuthAvailable(auth.getNickname())) {
|
||||||
@ -148,7 +165,7 @@ public class FlatFile implements DataSource {
|
|||||||
if (br != null) {
|
if (br != null) {
|
||||||
try {
|
try {
|
||||||
br.close();
|
br.close();
|
||||||
} catch (IOException ex) {
|
} catch (IOException ignored) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -159,6 +176,13 @@ public class FlatFile implements DataSource {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method updateSession.
|
||||||
|
*
|
||||||
|
* @param auth PlayerAuth
|
||||||
|
*
|
||||||
|
* @return boolean * @see fr.xephi.authme.datasource.DataSource#updateSession(PlayerAuth)
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean updateSession(PlayerAuth auth) {
|
public boolean updateSession(PlayerAuth auth) {
|
||||||
if (!isAuthAvailable(auth.getNickname())) {
|
if (!isAuthAvailable(auth.getNickname())) {
|
||||||
@ -207,7 +231,7 @@ public class FlatFile implements DataSource {
|
|||||||
if (br != null) {
|
if (br != null) {
|
||||||
try {
|
try {
|
||||||
br.close();
|
br.close();
|
||||||
} catch (IOException ex) {
|
} catch (IOException ignored) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -218,6 +242,13 @@ public class FlatFile implements DataSource {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method updateQuitLoc.
|
||||||
|
*
|
||||||
|
* @param auth PlayerAuth
|
||||||
|
*
|
||||||
|
* @return boolean * @see fr.xephi.authme.datasource.DataSource#updateQuitLoc(PlayerAuth)
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean updateQuitLoc(PlayerAuth auth) {
|
public boolean updateQuitLoc(PlayerAuth auth) {
|
||||||
if (!isAuthAvailable(auth.getNickname())) {
|
if (!isAuthAvailable(auth.getNickname())) {
|
||||||
@ -245,7 +276,7 @@ public class FlatFile implements DataSource {
|
|||||||
if (br != null) {
|
if (br != null) {
|
||||||
try {
|
try {
|
||||||
br.close();
|
br.close();
|
||||||
} catch (IOException ex) {
|
} catch (IOException ignored) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -256,6 +287,13 @@ public class FlatFile implements DataSource {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method getIps.
|
||||||
|
*
|
||||||
|
* @param ip String
|
||||||
|
*
|
||||||
|
* @return int * @see fr.xephi.authme.datasource.DataSource#getIps(String)
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public int getIps(String ip) {
|
public int getIps(String ip) {
|
||||||
BufferedReader br = null;
|
BufferedReader br = null;
|
||||||
@ -280,12 +318,19 @@ public class FlatFile implements DataSource {
|
|||||||
if (br != null) {
|
if (br != null) {
|
||||||
try {
|
try {
|
||||||
br.close();
|
br.close();
|
||||||
} catch (IOException ex) {
|
} catch (IOException ignored) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method purgeDatabase.
|
||||||
|
*
|
||||||
|
* @param until long
|
||||||
|
*
|
||||||
|
* @return int * @see fr.xephi.authme.datasource.DataSource#purgeDatabase(long)
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public int purgeDatabase(long until) {
|
public int purgeDatabase(long until) {
|
||||||
BufferedReader br = null;
|
BufferedReader br = null;
|
||||||
@ -319,19 +364,26 @@ public class FlatFile implements DataSource {
|
|||||||
if (br != null) {
|
if (br != null) {
|
||||||
try {
|
try {
|
||||||
br.close();
|
br.close();
|
||||||
} catch (IOException ex) {
|
} catch (IOException ignored) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (bw != null) {
|
if (bw != null) {
|
||||||
try {
|
try {
|
||||||
bw.close();
|
bw.close();
|
||||||
} catch (IOException ex) {
|
} catch (IOException ignored) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return cleared;
|
return cleared;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method autoPurgeDatabase.
|
||||||
|
*
|
||||||
|
* @param until long
|
||||||
|
*
|
||||||
|
* @return List<String> * @see fr.xephi.authme.datasource.DataSource#autoPurgeDatabase(long)
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<String> autoPurgeDatabase(long until) {
|
public List<String> autoPurgeDatabase(long until) {
|
||||||
BufferedReader br = null;
|
BufferedReader br = null;
|
||||||
@ -365,19 +417,26 @@ public class FlatFile implements DataSource {
|
|||||||
if (br != null) {
|
if (br != null) {
|
||||||
try {
|
try {
|
||||||
br.close();
|
br.close();
|
||||||
} catch (IOException ex) {
|
} catch (IOException ignored) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (bw != null) {
|
if (bw != null) {
|
||||||
try {
|
try {
|
||||||
bw.close();
|
bw.close();
|
||||||
} catch (IOException ex) {
|
} catch (IOException ignored) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return cleared;
|
return cleared;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method removeAuth.
|
||||||
|
*
|
||||||
|
* @param user String
|
||||||
|
*
|
||||||
|
* @return boolean * @see fr.xephi.authme.datasource.DataSource#removeAuth(String)
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public synchronized boolean removeAuth(String user) {
|
public synchronized boolean removeAuth(String user) {
|
||||||
if (!isAuthAvailable(user)) {
|
if (!isAuthAvailable(user)) {
|
||||||
@ -409,19 +468,26 @@ public class FlatFile implements DataSource {
|
|||||||
if (br != null) {
|
if (br != null) {
|
||||||
try {
|
try {
|
||||||
br.close();
|
br.close();
|
||||||
} catch (IOException ex) {
|
} catch (IOException ignored) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (bw != null) {
|
if (bw != null) {
|
||||||
try {
|
try {
|
||||||
bw.close();
|
bw.close();
|
||||||
} catch (IOException ex) {
|
} catch (IOException ignored) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method getAuth.
|
||||||
|
*
|
||||||
|
* @param user String
|
||||||
|
*
|
||||||
|
* @return PlayerAuth * @see fr.xephi.authme.datasource.DataSource#getAuth(String)
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public synchronized PlayerAuth getAuth(String user) {
|
public synchronized PlayerAuth getAuth(String user) {
|
||||||
BufferedReader br = null;
|
BufferedReader br = null;
|
||||||
@ -457,21 +523,38 @@ public class FlatFile implements DataSource {
|
|||||||
if (br != null) {
|
if (br != null) {
|
||||||
try {
|
try {
|
||||||
br.close();
|
br.close();
|
||||||
} catch (IOException ex) {
|
} catch (IOException ignored) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method close.
|
||||||
|
*
|
||||||
|
* @see fr.xephi.authme.datasource.DataSource#close()
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public synchronized void close() {
|
public synchronized void close() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method reload.
|
||||||
|
*
|
||||||
|
* @see fr.xephi.authme.datasource.DataSource#reload()
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void reload() {
|
public void reload() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method updateEmail.
|
||||||
|
*
|
||||||
|
* @param auth PlayerAuth
|
||||||
|
*
|
||||||
|
* @return boolean * @see fr.xephi.authme.datasource.DataSource#updateEmail(PlayerAuth)
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean updateEmail(PlayerAuth auth) {
|
public boolean updateEmail(PlayerAuth auth) {
|
||||||
if (!isAuthAvailable(auth.getNickname())) {
|
if (!isAuthAvailable(auth.getNickname())) {
|
||||||
@ -499,7 +582,7 @@ public class FlatFile implements DataSource {
|
|||||||
if (br != null) {
|
if (br != null) {
|
||||||
try {
|
try {
|
||||||
br.close();
|
br.close();
|
||||||
} catch (IOException ex) {
|
} catch (IOException ignored) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -510,11 +593,25 @@ public class FlatFile implements DataSource {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method updateSalt.
|
||||||
|
*
|
||||||
|
* @param auth PlayerAuth
|
||||||
|
*
|
||||||
|
* @return boolean * @see fr.xephi.authme.datasource.DataSource#updateSalt(PlayerAuth)
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean updateSalt(PlayerAuth auth) {
|
public boolean updateSalt(PlayerAuth auth) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method getAllAuthsByName.
|
||||||
|
*
|
||||||
|
* @param auth PlayerAuth
|
||||||
|
*
|
||||||
|
* @return List<String> * @see fr.xephi.authme.datasource.DataSource#getAllAuthsByName(PlayerAuth)
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<String> getAllAuthsByName(PlayerAuth auth) {
|
public List<String> getAllAuthsByName(PlayerAuth auth) {
|
||||||
BufferedReader br = null;
|
BufferedReader br = null;
|
||||||
@ -539,12 +636,19 @@ public class FlatFile implements DataSource {
|
|||||||
if (br != null) {
|
if (br != null) {
|
||||||
try {
|
try {
|
||||||
br.close();
|
br.close();
|
||||||
} catch (IOException ex) {
|
} catch (IOException ignored) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method getAllAuthsByIp.
|
||||||
|
*
|
||||||
|
* @param ip String
|
||||||
|
*
|
||||||
|
* @return List<String> * @see fr.xephi.authme.datasource.DataSource#getAllAuthsByIp(String)
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<String> getAllAuthsByIp(String ip) {
|
public List<String> getAllAuthsByIp(String ip) {
|
||||||
BufferedReader br = null;
|
BufferedReader br = null;
|
||||||
@ -569,12 +673,19 @@ public class FlatFile implements DataSource {
|
|||||||
if (br != null) {
|
if (br != null) {
|
||||||
try {
|
try {
|
||||||
br.close();
|
br.close();
|
||||||
} catch (IOException ex) {
|
} catch (IOException ignored) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method getAllAuthsByEmail.
|
||||||
|
*
|
||||||
|
* @param email String
|
||||||
|
*
|
||||||
|
* @return List<String> * @see fr.xephi.authme.datasource.DataSource#getAllAuthsByEmail(String)
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<String> getAllAuthsByEmail(String email) {
|
public List<String> getAllAuthsByEmail(String email) {
|
||||||
BufferedReader br = null;
|
BufferedReader br = null;
|
||||||
@ -599,12 +710,19 @@ public class FlatFile implements DataSource {
|
|||||||
if (br != null) {
|
if (br != null) {
|
||||||
try {
|
try {
|
||||||
br.close();
|
br.close();
|
||||||
} catch (IOException ex) {
|
} catch (IOException ignored) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method purgeBanned.
|
||||||
|
*
|
||||||
|
* @param banned List<String>
|
||||||
|
*
|
||||||
|
* @see fr.xephi.authme.datasource.DataSource#purgeBanned(List<String>)
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void purgeBanned(List<String> banned) {
|
public void purgeBanned(List<String> banned) {
|
||||||
BufferedReader br = null;
|
BufferedReader br = null;
|
||||||
@ -619,58 +737,91 @@ public class FlatFile implements DataSource {
|
|||||||
if (banned.contains(args[0])) {
|
if (banned.contains(args[0])) {
|
||||||
lines.add(line);
|
lines.add(line);
|
||||||
}
|
}
|
||||||
} catch (NullPointerException | ArrayIndexOutOfBoundsException exc) {
|
} catch (NullPointerException | ArrayIndexOutOfBoundsException ignored) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
bw = new BufferedWriter(new FileWriter(source));
|
bw = new BufferedWriter(new FileWriter(source));
|
||||||
for (String l : lines) {
|
for (String l : lines) {
|
||||||
bw.write(l + "\n");
|
bw.write(l + "\n");
|
||||||
}
|
}
|
||||||
} catch (FileNotFoundException ex) {
|
|
||||||
ConsoleLogger.showError(ex.getMessage());
|
|
||||||
return;
|
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
ConsoleLogger.showError(ex.getMessage());
|
ConsoleLogger.showError(ex.getMessage());
|
||||||
return;
|
|
||||||
} finally {
|
} finally {
|
||||||
if (br != null) {
|
if (br != null) {
|
||||||
try {
|
try {
|
||||||
br.close();
|
br.close();
|
||||||
} catch (IOException ex) {
|
} catch (IOException ignored) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (bw != null) {
|
if (bw != null) {
|
||||||
try {
|
try {
|
||||||
bw.close();
|
bw.close();
|
||||||
} catch (IOException ex) {
|
} catch (IOException ignored) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method getType.
|
||||||
|
*
|
||||||
|
* @return DataSourceType * @see fr.xephi.authme.datasource.DataSource#getType()
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public DataSourceType getType() {
|
public DataSourceType getType() {
|
||||||
return DataSourceType.FILE;
|
return DataSourceType.FILE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method isLogged.
|
||||||
|
*
|
||||||
|
* @param user String
|
||||||
|
*
|
||||||
|
* @return boolean * @see fr.xephi.authme.datasource.DataSource#isLogged(String)
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean isLogged(String user) {
|
public boolean isLogged(String user) {
|
||||||
return PlayerCache.getInstance().isAuthenticated(user);
|
return PlayerCache.getInstance().isAuthenticated(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method setLogged.
|
||||||
|
*
|
||||||
|
* @param user String
|
||||||
|
*
|
||||||
|
* @see fr.xephi.authme.datasource.DataSource#setLogged(String)
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void setLogged(String user) {
|
public void setLogged(String user) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method setUnlogged.
|
||||||
|
*
|
||||||
|
* @param user String
|
||||||
|
*
|
||||||
|
* @see fr.xephi.authme.datasource.DataSource#setUnlogged(String)
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void setUnlogged(String user) {
|
public void setUnlogged(String user) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method purgeLogged.
|
||||||
|
*
|
||||||
|
* @see fr.xephi.authme.datasource.DataSource#purgeLogged()
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void purgeLogged() {
|
public void purgeLogged() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method getAccountsRegistered.
|
||||||
|
*
|
||||||
|
* @return int * @see fr.xephi.authme.datasource.DataSource#getAccountsRegistered()
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public int getAccountsRegistered() {
|
public int getAccountsRegistered() {
|
||||||
BufferedReader br = null;
|
BufferedReader br = null;
|
||||||
@ -687,21 +838,34 @@ public class FlatFile implements DataSource {
|
|||||||
if (br != null) {
|
if (br != null) {
|
||||||
try {
|
try {
|
||||||
br.close();
|
br.close();
|
||||||
} catch (IOException ex) {
|
} catch (IOException ignored) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method updateName.
|
||||||
|
*
|
||||||
|
* @param oldOne String
|
||||||
|
* @param newOne String
|
||||||
|
*
|
||||||
|
* @see fr.xephi.authme.datasource.DataSource#updateName(String, String)
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void updateName(String oldone, String newone) {
|
public void updateName(String oldOne, String newOne) {
|
||||||
PlayerAuth auth = this.getAuth(oldone);
|
PlayerAuth auth = this.getAuth(oldOne);
|
||||||
auth.setName(newone);
|
auth.setName(newOne);
|
||||||
this.saveAuth(auth);
|
this.saveAuth(auth);
|
||||||
this.removeAuth(oldone);
|
this.removeAuth(oldOne);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method getAllAuths.
|
||||||
|
*
|
||||||
|
* @return List<PlayerAuth> * @see fr.xephi.authme.datasource.DataSource#getAllAuths()
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<PlayerAuth> getAllAuths() {
|
public List<PlayerAuth> getAllAuths() {
|
||||||
BufferedReader br = null;
|
BufferedReader br = null;
|
||||||
@ -742,13 +906,18 @@ public class FlatFile implements DataSource {
|
|||||||
if (br != null) {
|
if (br != null) {
|
||||||
try {
|
try {
|
||||||
br.close();
|
br.close();
|
||||||
} catch (IOException ex) {
|
} catch (IOException ignored) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return auths;
|
return auths;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method getLoggedPlayers.
|
||||||
|
*
|
||||||
|
* @return List<PlayerAuth> * @see fr.xephi.authme.datasource.DataSource#getLoggedPlayers()
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<PlayerAuth> getLoggedPlayers() {
|
public List<PlayerAuth> getLoggedPlayers() {
|
||||||
return new ArrayList<>();
|
return new ArrayList<>();
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -5,34 +5,59 @@ import org.bukkit.event.Event;
|
|||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* This event is call when a player try to /login
|
* This event is call when a player try to /login
|
||||||
*
|
*
|
||||||
* @author Xephi59
|
* @author Xephi59
|
||||||
|
* @version $Revision: 1.0 $
|
||||||
*/
|
*/
|
||||||
public class AuthMeAsyncPreLoginEvent extends Event {
|
public class AuthMeAsyncPreLoginEvent extends Event {
|
||||||
|
|
||||||
private Player player;
|
|
||||||
private boolean canLogin = true;
|
|
||||||
private static final HandlerList handlers = new HandlerList();
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
private final Player player;
|
||||||
|
private boolean canLogin = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for AuthMeAsyncPreLoginEvent.
|
||||||
|
*
|
||||||
|
* @param player Player
|
||||||
|
*/
|
||||||
public AuthMeAsyncPreLoginEvent(Player player) {
|
public AuthMeAsyncPreLoginEvent(Player player) {
|
||||||
super(true);
|
super(true);
|
||||||
this.player = player;
|
this.player = player;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method getPlayer.
|
||||||
|
*
|
||||||
|
* @return Player
|
||||||
|
*/
|
||||||
public Player getPlayer() {
|
public Player getPlayer() {
|
||||||
return player;
|
return player;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method canLogin.
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
public boolean canLogin() {
|
public boolean canLogin() {
|
||||||
return canLogin;
|
return canLogin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method setCanLogin.
|
||||||
|
*
|
||||||
|
* @param canLogin boolean
|
||||||
|
*/
|
||||||
public void setCanLogin(boolean canLogin) {
|
public void setCanLogin(boolean canLogin) {
|
||||||
this.canLogin = canLogin;
|
this.canLogin = canLogin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method getHandlers.
|
||||||
|
*
|
||||||
|
* @return HandlerList
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public HandlerList getHandlers() {
|
public HandlerList getHandlers() {
|
||||||
return handlers;
|
return handlers;
|
||||||
|
|||||||
@ -4,35 +4,61 @@ import org.bukkit.Location;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* This event is call when AuthMe try to teleport a player
|
* This event is call when AuthMe try to teleport a player
|
||||||
*
|
*
|
||||||
* @author Xephi59
|
* @author Xephi59
|
||||||
|
* @version $Revision: 1.0 $
|
||||||
*/
|
*/
|
||||||
public class AuthMeTeleportEvent extends CustomEvent {
|
public class AuthMeTeleportEvent extends CustomEvent {
|
||||||
|
|
||||||
private Player player;
|
private final Player player;
|
||||||
private Location to;
|
private Location to;
|
||||||
private Location from;
|
private final Location from;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for AuthMeTeleportEvent.
|
||||||
|
*
|
||||||
|
* @param player Player
|
||||||
|
* @param to Location
|
||||||
|
*/
|
||||||
public AuthMeTeleportEvent(Player player, Location to) {
|
public AuthMeTeleportEvent(Player player, Location to) {
|
||||||
this.player = player;
|
this.player = player;
|
||||||
this.from = player.getLocation();
|
this.from = player.getLocation();
|
||||||
this.to = to;
|
this.to = to;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method getPlayer.
|
||||||
|
*
|
||||||
|
* @return Player
|
||||||
|
*/
|
||||||
public Player getPlayer() {
|
public Player getPlayer() {
|
||||||
return player;
|
return player;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTo(Location to) {
|
/**
|
||||||
this.to = to;
|
* Method getTo.
|
||||||
}
|
*
|
||||||
|
* @return Location
|
||||||
|
*/
|
||||||
public Location getTo() {
|
public Location getTo() {
|
||||||
return to;
|
return to;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method setTo.
|
||||||
|
*
|
||||||
|
* @param to Location
|
||||||
|
*/
|
||||||
|
public void setTo(Location to) {
|
||||||
|
this.to = to;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method getFrom.
|
||||||
|
*
|
||||||
|
* @return Location
|
||||||
|
*/
|
||||||
public Location getFrom() {
|
public Location getFrom() {
|
||||||
return from;
|
return from;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,34 +5,61 @@ import org.bukkit.event.Event;
|
|||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @author Xephi59
|
* @author Xephi59
|
||||||
|
* @version $Revision: 1.0 $
|
||||||
*/
|
*/
|
||||||
public class CustomEvent extends Event implements Cancellable {
|
public class CustomEvent extends Event implements Cancellable {
|
||||||
|
|
||||||
private boolean isCancelled;
|
|
||||||
private static final HandlerList handlers = new HandlerList();
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
private boolean isCancelled;
|
||||||
|
|
||||||
public CustomEvent() {
|
public CustomEvent() {
|
||||||
super(false);
|
super(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for CustomEvent.
|
||||||
|
*
|
||||||
|
* @param b boolean
|
||||||
|
*/
|
||||||
public CustomEvent(boolean b) {
|
public CustomEvent(boolean b) {
|
||||||
super(b);
|
super(b);
|
||||||
}
|
}
|
||||||
|
|
||||||
public HandlerList getHandlers() {
|
/**
|
||||||
return handlers;
|
* Method getHandlerList.
|
||||||
}
|
*
|
||||||
|
* @return HandlerList
|
||||||
|
*/
|
||||||
public static HandlerList getHandlerList() {
|
public static HandlerList getHandlerList() {
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method getHandlers.
|
||||||
|
*
|
||||||
|
* @return HandlerList
|
||||||
|
*/
|
||||||
|
public HandlerList getHandlers() {
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method isCancelled.
|
||||||
|
*
|
||||||
|
* @return boolean * @see org.bukkit.event.Cancellable#isCancelled()
|
||||||
|
*/
|
||||||
public boolean isCancelled() {
|
public boolean isCancelled() {
|
||||||
return this.isCancelled;
|
return this.isCancelled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method setCancelled.
|
||||||
|
*
|
||||||
|
* @param cancelled boolean
|
||||||
|
*
|
||||||
|
* @see org.bukkit.event.Cancellable#setCancelled(boolean)
|
||||||
|
*/
|
||||||
public void setCancelled(boolean cancelled) {
|
public void setCancelled(boolean cancelled) {
|
||||||
this.isCancelled = cancelled;
|
this.isCancelled = cancelled;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,17 +4,24 @@ import org.bukkit.Location;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* Called if a player is teleported to the authme first spawn
|
* Called if a player is teleported to the authme first spawn
|
||||||
*
|
*
|
||||||
* @author Xephi59
|
* @author Xephi59
|
||||||
|
* @version $Revision: 1.0 $
|
||||||
*/
|
*/
|
||||||
public class FirstSpawnTeleportEvent extends CustomEvent {
|
public class FirstSpawnTeleportEvent extends CustomEvent {
|
||||||
|
|
||||||
private Player player;
|
private final Player player;
|
||||||
private Location to;
|
private Location to;
|
||||||
private Location from;
|
private final Location from;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for FirstSpawnTeleportEvent.
|
||||||
|
*
|
||||||
|
* @param player Player
|
||||||
|
* @param from Location
|
||||||
|
* @param to Location
|
||||||
|
*/
|
||||||
public FirstSpawnTeleportEvent(Player player, Location from, Location to) {
|
public FirstSpawnTeleportEvent(Player player, Location from, Location to) {
|
||||||
super(true);
|
super(true);
|
||||||
this.player = player;
|
this.player = player;
|
||||||
@ -22,18 +29,38 @@ public class FirstSpawnTeleportEvent extends CustomEvent {
|
|||||||
this.to = to;
|
this.to = to;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method getPlayer.
|
||||||
|
*
|
||||||
|
* @return Player
|
||||||
|
*/
|
||||||
public Player getPlayer() {
|
public Player getPlayer() {
|
||||||
return player;
|
return player;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTo(Location to) {
|
/**
|
||||||
this.to = to;
|
* Method getTo.
|
||||||
}
|
*
|
||||||
|
* @return Location
|
||||||
|
*/
|
||||||
public Location getTo() {
|
public Location getTo() {
|
||||||
return to;
|
return to;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method setTo.
|
||||||
|
*
|
||||||
|
* @param to Location
|
||||||
|
*/
|
||||||
|
public void setTo(Location to) {
|
||||||
|
this.to = to;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method getFrom.
|
||||||
|
*
|
||||||
|
* @return Location
|
||||||
|
*/
|
||||||
public Location getFrom() {
|
public Location getFrom() {
|
||||||
return from;
|
return from;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,47 +5,83 @@ import org.bukkit.event.Event;
|
|||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* This event is called when a player login or register through AuthMe. The
|
* This event is called when a player login or register through AuthMe. The
|
||||||
* boolean 'isLogin' will be false if, and only if, login/register failed.
|
* boolean 'isLogin' will be false if, and only if, login/register failed.
|
||||||
*
|
*
|
||||||
* @author Xephi59
|
* @author Xephi59
|
||||||
|
* @version $Revision: 1.0 $
|
||||||
*/
|
*/
|
||||||
public class LoginEvent extends Event {
|
public class LoginEvent extends Event {
|
||||||
|
|
||||||
|
private static final HandlerList handlers = new HandlerList();
|
||||||
private Player player;
|
private Player player;
|
||||||
private boolean isLogin;
|
private boolean isLogin;
|
||||||
private static final HandlerList handlers = new HandlerList();
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for LoginEvent.
|
||||||
|
*
|
||||||
|
* @param player Player
|
||||||
|
* @param isLogin boolean
|
||||||
|
*/
|
||||||
public LoginEvent(Player player, boolean isLogin) {
|
public LoginEvent(Player player, boolean isLogin) {
|
||||||
this.player = player;
|
this.player = player;
|
||||||
this.isLogin = isLogin;
|
this.isLogin = isLogin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method getHandlerList.
|
||||||
|
*
|
||||||
|
* @return HandlerList
|
||||||
|
*/
|
||||||
|
public static HandlerList getHandlerList() {
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method getPlayer.
|
||||||
|
*
|
||||||
|
* @return Player
|
||||||
|
*/
|
||||||
public Player getPlayer() {
|
public Player getPlayer() {
|
||||||
return this.player;
|
return this.player;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method setPlayer.
|
||||||
|
*
|
||||||
|
* @param player Player
|
||||||
|
*/
|
||||||
public void setPlayer(Player player) {
|
public void setPlayer(Player player) {
|
||||||
this.player = player;
|
this.player = player;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method isLogin.
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public boolean isLogin() {
|
||||||
|
return isLogin;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method setLogin.
|
||||||
|
*
|
||||||
|
* @param isLogin boolean
|
||||||
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public void setLogin(boolean isLogin) {
|
public void setLogin(boolean isLogin) {
|
||||||
this.isLogin = isLogin;
|
this.isLogin = isLogin;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isLogin() {
|
/**
|
||||||
return isLogin;
|
* Method getHandlers.
|
||||||
}
|
*
|
||||||
|
* @return HandlerList
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public HandlerList getHandlers() {
|
public HandlerList getHandlers() {
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static HandlerList getHandlerList() {
|
|
||||||
return handlers;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,35 +5,60 @@ import org.bukkit.event.Event;
|
|||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* This event is called when a player logout through AuthMe.
|
* This event is called when a player logout through AuthMe.
|
||||||
*
|
*
|
||||||
* @author Xephi59
|
* @author Xephi59
|
||||||
|
* @version $Revision: 1.0 $
|
||||||
*/
|
*/
|
||||||
public class LogoutEvent extends Event {
|
public class LogoutEvent extends Event {
|
||||||
|
|
||||||
private Player player;
|
|
||||||
private static final HandlerList handlers = new HandlerList();
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
private Player player;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for LogoutEvent.
|
||||||
|
*
|
||||||
|
* @param player Player
|
||||||
|
*/
|
||||||
public LogoutEvent(Player player) {
|
public LogoutEvent(Player player) {
|
||||||
this.player = player;
|
this.player = player;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method getHandlerList.
|
||||||
|
*
|
||||||
|
* @return HandlerList
|
||||||
|
*/
|
||||||
|
public static HandlerList getHandlerList() {
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method getPlayer.
|
||||||
|
*
|
||||||
|
* @return Player
|
||||||
|
*/
|
||||||
public Player getPlayer() {
|
public Player getPlayer() {
|
||||||
return this.player;
|
return this.player;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method setPlayer.
|
||||||
|
*
|
||||||
|
* @param player Player
|
||||||
|
*/
|
||||||
public void setPlayer(Player player) {
|
public void setPlayer(Player player) {
|
||||||
this.player = player;
|
this.player = player;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method getHandlers.
|
||||||
|
*
|
||||||
|
* @return HandlerList
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public HandlerList getHandlers() {
|
public HandlerList getHandlers() {
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static HandlerList getHandlerList() {
|
|
||||||
return handlers;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,19 +1,18 @@
|
|||||||
package fr.xephi.authme.events;
|
package fr.xephi.authme.events;
|
||||||
|
|
||||||
|
import fr.xephi.authme.security.crypts.EncryptionMethod;
|
||||||
import org.bukkit.event.Event;
|
import org.bukkit.event.Event;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
import fr.xephi.authme.security.crypts.EncryptionMethod;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
* This event is called when we need to compare or get an hash password, for set
|
* This event is called when we need to compare or get an hash password, for set
|
||||||
* a custom EncryptionMethod
|
* a custom EncryptionMethod
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @see fr.xephi.authme.security.crypts.EncryptionMethod
|
|
||||||
*
|
|
||||||
* @author Xephi59
|
* @author Xephi59
|
||||||
|
* @version $Revision: 1.0 $
|
||||||
|
* @see fr.xephi.authme.security.crypts.EncryptionMethod
|
||||||
*/
|
*/
|
||||||
public class PasswordEncryptionEvent extends Event {
|
public class PasswordEncryptionEvent extends Event {
|
||||||
|
|
||||||
@ -21,31 +20,62 @@ public class PasswordEncryptionEvent extends Event {
|
|||||||
private EncryptionMethod method = null;
|
private EncryptionMethod method = null;
|
||||||
private String playerName = "";
|
private String playerName = "";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for PasswordEncryptionEvent.
|
||||||
|
*
|
||||||
|
* @param method EncryptionMethod
|
||||||
|
* @param playerName String
|
||||||
|
*/
|
||||||
public PasswordEncryptionEvent(EncryptionMethod method, String playerName) {
|
public PasswordEncryptionEvent(EncryptionMethod method, String playerName) {
|
||||||
super(false);
|
super(false);
|
||||||
this.method = method;
|
this.method = method;
|
||||||
this.playerName = playerName;
|
this.playerName = playerName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method getHandlerList.
|
||||||
|
*
|
||||||
|
* @return HandlerList
|
||||||
|
*/
|
||||||
|
public static HandlerList getHandlerList() {
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method getHandlers.
|
||||||
|
*
|
||||||
|
* @return HandlerList
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public HandlerList getHandlers() {
|
public HandlerList getHandlers() {
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMethod(EncryptionMethod method) {
|
/**
|
||||||
this.method = method;
|
* Method getMethod.
|
||||||
}
|
*
|
||||||
|
* @return EncryptionMethod
|
||||||
|
*/
|
||||||
public EncryptionMethod getMethod() {
|
public EncryptionMethod getMethod() {
|
||||||
return method;
|
return method;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method setMethod.
|
||||||
|
*
|
||||||
|
* @param method EncryptionMethod
|
||||||
|
*/
|
||||||
|
public void setMethod(EncryptionMethod method) {
|
||||||
|
this.method = method;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method getPlayerName.
|
||||||
|
*
|
||||||
|
* @return String
|
||||||
|
*/
|
||||||
public String getPlayerName() {
|
public String getPlayerName() {
|
||||||
return playerName;
|
return playerName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static HandlerList getHandlerList() {
|
|
||||||
return handlers;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,20 +4,25 @@ import org.bukkit.entity.Player;
|
|||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* This event is call just after store inventory into cache and will empty the
|
* This event is call just after store inventory into cache and will empty the
|
||||||
* player inventory.
|
* player inventory.
|
||||||
*
|
*
|
||||||
* @author Xephi59
|
* @author Xephi59
|
||||||
|
* @version $Revision: 1.0 $
|
||||||
*/
|
*/
|
||||||
public class ProtectInventoryEvent extends CustomEvent {
|
public class ProtectInventoryEvent extends CustomEvent {
|
||||||
|
|
||||||
private ItemStack[] storedinventory;
|
private final ItemStack[] storedinventory;
|
||||||
private ItemStack[] storedarmor;
|
private final ItemStack[] storedarmor;
|
||||||
private ItemStack[] emptyInventory = null;
|
private ItemStack[] emptyInventory = null;
|
||||||
private ItemStack[] emptyArmor = null;
|
private ItemStack[] emptyArmor = null;
|
||||||
private Player player;
|
private final Player player;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for ProtectInventoryEvent.
|
||||||
|
*
|
||||||
|
* @param player Player
|
||||||
|
*/
|
||||||
public ProtectInventoryEvent(Player player) {
|
public ProtectInventoryEvent(Player player) {
|
||||||
super(true);
|
super(true);
|
||||||
this.player = player;
|
this.player = player;
|
||||||
@ -27,30 +32,65 @@ public class ProtectInventoryEvent extends CustomEvent {
|
|||||||
this.emptyArmor = new ItemStack[4];
|
this.emptyArmor = new ItemStack[4];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method getStoredInventory.
|
||||||
|
*
|
||||||
|
* @return ItemStack[]
|
||||||
|
*/
|
||||||
public ItemStack[] getStoredInventory() {
|
public ItemStack[] getStoredInventory() {
|
||||||
return this.storedinventory;
|
return this.storedinventory;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method getStoredArmor.
|
||||||
|
*
|
||||||
|
* @return ItemStack[]
|
||||||
|
*/
|
||||||
public ItemStack[] getStoredArmor() {
|
public ItemStack[] getStoredArmor() {
|
||||||
return this.storedarmor;
|
return this.storedarmor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method getPlayer.
|
||||||
|
*
|
||||||
|
* @return Player
|
||||||
|
*/
|
||||||
public Player getPlayer() {
|
public Player getPlayer() {
|
||||||
return this.player;
|
return this.player;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method setNewInventory.
|
||||||
|
*
|
||||||
|
* @param emptyInventory ItemStack[]
|
||||||
|
*/
|
||||||
public void setNewInventory(ItemStack[] emptyInventory) {
|
public void setNewInventory(ItemStack[] emptyInventory) {
|
||||||
this.emptyInventory = emptyInventory;
|
this.emptyInventory = emptyInventory;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method getEmptyInventory.
|
||||||
|
*
|
||||||
|
* @return ItemStack[]
|
||||||
|
*/
|
||||||
public ItemStack[] getEmptyInventory() {
|
public ItemStack[] getEmptyInventory() {
|
||||||
return this.emptyInventory;
|
return this.emptyInventory;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method setNewArmor.
|
||||||
|
*
|
||||||
|
* @param emptyArmor ItemStack[]
|
||||||
|
*/
|
||||||
public void setNewArmor(ItemStack[] emptyArmor) {
|
public void setNewArmor(ItemStack[] emptyArmor) {
|
||||||
this.emptyArmor = emptyArmor;
|
this.emptyArmor = emptyArmor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method getEmptyArmor.
|
||||||
|
*
|
||||||
|
* @return ItemStack[]
|
||||||
|
*/
|
||||||
public ItemStack[] getEmptyArmor() {
|
public ItemStack[] getEmptyArmor() {
|
||||||
return this.emptyArmor;
|
return this.emptyArmor;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,36 +4,62 @@ import org.bukkit.Location;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* This event is call if, and only if, a player is teleported just after a
|
* This event is call if, and only if, a player is teleported just after a
|
||||||
* register.
|
* register.
|
||||||
*
|
*
|
||||||
* @author Xephi59
|
* @author Xephi59
|
||||||
|
* @version $Revision: 1.0 $
|
||||||
*/
|
*/
|
||||||
public class RegisterTeleportEvent extends CustomEvent {
|
public class RegisterTeleportEvent extends CustomEvent {
|
||||||
|
|
||||||
private Player player;
|
private final Player player;
|
||||||
private Location to;
|
private Location to;
|
||||||
private Location from;
|
private final Location from;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for RegisterTeleportEvent.
|
||||||
|
*
|
||||||
|
* @param player Player
|
||||||
|
* @param to Location
|
||||||
|
*/
|
||||||
public RegisterTeleportEvent(Player player, Location to) {
|
public RegisterTeleportEvent(Player player, Location to) {
|
||||||
this.player = player;
|
this.player = player;
|
||||||
this.from = player.getLocation();
|
this.from = player.getLocation();
|
||||||
this.to = to;
|
this.to = to;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method getPlayer.
|
||||||
|
*
|
||||||
|
* @return Player
|
||||||
|
*/
|
||||||
public Player getPlayer() {
|
public Player getPlayer() {
|
||||||
return player;
|
return player;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTo(Location to) {
|
/**
|
||||||
this.to = to;
|
* Method getTo.
|
||||||
}
|
*
|
||||||
|
* @return Location
|
||||||
|
*/
|
||||||
public Location getTo() {
|
public Location getTo() {
|
||||||
return to;
|
return to;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method setTo.
|
||||||
|
*
|
||||||
|
* @param to Location
|
||||||
|
*/
|
||||||
|
public void setTo(Location to) {
|
||||||
|
this.to = to;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method getFrom.
|
||||||
|
*
|
||||||
|
* @return Location
|
||||||
|
*/
|
||||||
public Location getFrom() {
|
public Location getFrom() {
|
||||||
return from;
|
return from;
|
||||||
}
|
}
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user