mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2024-12-26 10:37:39 +01:00
Merge pull request #332 from AuthMe-Team/master
[Partial] Stuff from DEV repo in realtime
This commit is contained in:
commit
9ec404d51f
123
.flooignore
123
.flooignore
@ -1,123 +0,0 @@
|
||||
### 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/
|
@ -8,7 +8,8 @@ cache:
|
||||
- '$HOME/.m2/repository'
|
||||
|
||||
script:
|
||||
- mvn clean install -B && mvn clean -B
|
||||
- mvn dependency:purge-local-repository -DactTransitively=false -DreResolve=false
|
||||
- mvn clean install -B -U
|
||||
|
||||
notifications:
|
||||
webhooks:
|
||||
|
49
README.md
49
README.md
@ -2,24 +2,25 @@
|
||||
<p align="center"><strong>The most used authentication plugin for CraftBukkit/Spigot!</strong></p>
|
||||
<hr>
|
||||
|
||||
####Development history:
|
||||
[![Guava AuthMe History Video](http://img.youtube.com/vi/hJRzNfYyd9k/hqdefault.jpg)](https://www.youtube.com/watch?v=hJRzNfYyd9k)
|
||||
|
||||
#####Development tools:
|
||||
|
||||
- DEVELOPMENT TEAM REPO (<strong>please send PRs here!</strong>): <a href="https://github.com/AuthMe-Team/AuthMeReloaded">Github Development Page</a>
|
||||
|
||||
- Developers ChatRoom: [![Join the chat at https://gitter.im/Xephi/AuthMeReloaded](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/Xephi/AuthMeReloaded?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
||||
|
||||
- Build status: [![Build Status](https://travis-ci.org/Xephi/AuthMeReloaded.svg?branch=master)](https://travis-ci.org/Xephi/AuthMeReloaded) [![Dependency Status](https://www.versioneye.com/user/projects/55bab9e8653762002000190a/badge.svg?style=flat)](https://www.versioneye.com/user/projects/55bab9e8653762002000190a)
|
||||
- Build Server (<strong>DEVELOPMENT BUILDS</strong>): <a href="http://ci.xephi.fr/job/AuthMeReloaded">Xephi's Jenkins</a>
|
||||
|
||||
- Build status (CircleCI): [![Circle CI](https://circleci.com/gh/Xephi/AuthMeReloaded.svg?style=svg)](https://circleci.com/gh/Xephi/AuthMeReloaded)
|
||||
- Build status: [![Build Status](https://travis-ci.org/AuthMe-Team/AuthMeReloaded.svg?branch=master)](https://travis-ci.org/AuthMe-Team/AuthMeReloaded) [![Dependency Status](https://www.versioneye.com/user/projects/55bab9e8653762002000190a/badge.svg?style=flat)](https://www.versioneye.com/user/projects/55bab9e8653762002000190a)
|
||||
|
||||
- Build status (CircleCI): [![Circle CI](https://circleci.com/gh/AuthMe-Team/AuthMeReloaded.svg?style=svg)](https://circleci.com/gh/AuthMe-Team/AuthMeReloaded)
|
||||
- Alternative Dev Build download link (via CircleCi): <a href="https://circleci-tkn.rhcloud.com/api/v1/project/AuthMe-Team/AuthMeReloaded/tree/master/latest/artifacts/AuthMe.jar">Download</a>
|
||||
- JitPack (just in case): [![](https://jitpack.io/v/AuthMe-Team/AuthMeReloaded.svg)](https://jitpack.io/#AuthMe-Team/AuthMeReloaded)
|
||||
|
||||
- Code Coverage: [![Coverage Status](https://coveralls.io/repos/AuthMe-Team/AuthMeReloaded/badge.svg?branch=master&service=github)](https://coveralls.io/github/AuthMe-Team/AuthMeReloaded?branch=master)
|
||||
|
||||
- Issue Tracking : [![Stories in Ready](https://badge.waffle.io/Xephi/AuthMeReloaded.png?label=ready&title=Ready)](https://waffle.io/Xephi/AuthMeReloaded) [![Stories in Bugs](https://badge.waffle.io/Xephi/AuthMeReloaded.png?label=bugs&title=Bugs)](https://waffle.io/Xephi/AuthMeReloaded) [![Stories in In%20Progress](https://badge.waffle.io/Xephi/AuthMeReloaded.png?label=in%20progress&title=In%20Progress)](https://waffle.io/Xephi/AuthMeReloaded)
|
||||
|
||||
- Build Server (<strong>DEVELOPMENT BUILDS</strong>): <a href="http://ci.xephi.fr/job/AuthMeReloaded">Xephi's Jenkins</a>
|
||||
|
||||
- JavaDocs: <a href="http://xephi.github.io/AuthMeReloaded/index.html">AuthMe Javadoc</a>
|
||||
- JavaDoc: <a href="http://ci.xephi.fr/job/AuthMeReloaded/javadoc/">AuthMe Javadoc</a>
|
||||
|
||||
- Maven Repo: <a href="http://ci.xephi.fr/plugin/repository/everything/">AuthMe Repo</a>
|
||||
|
||||
@ -33,6 +34,9 @@ McStats: http://mcstats.org/plugin/AuthMe
|
||||
|
||||
<img src="http://i.mcstats.org/AuthMe/Version+Demographics.borderless.png">
|
||||
|
||||
#####Development history:
|
||||
[![Gource AuthMe History Video](http://img.youtube.com/vi/hJRzNfYyd9k/hqdefault.jpg)](https://www.youtube.com/watch?v=hJRzNfYyd9k)
|
||||
|
||||
<hr>
|
||||
|
||||
#####Compiling Requirements:
|
||||
@ -54,12 +58,12 @@ McStats: http://mcstats.org/plugin/AuthMe
|
||||
|
||||
#####"The best authentication plugin for the Bukkit/Spigot API!"
|
||||
|
||||
<p>Prevent username stealing on your server! Full compatible with UUIDs and Craftbukkit/Spigot 1.8.X!<br>
|
||||
Use it to secure your Offline mode server or to incrase your Online mode server's protection!</p>
|
||||
<p>Prevent username stealing on your server! Fully compatible with UUIDs and Craftbukkit/Spigot 1.8.X!<br>
|
||||
Use it to secure your Offline mode server or to increase your Online mode server's protection!</p>
|
||||
|
||||
<p>AuthMeReloaded disallows players who aren't authenticated to do actions like placing blocks, moving,<br>
|
||||
typing commands or use the inventory. It can also kick players with uncommon long or short player names or kick players from banned countries.</p>
|
||||
<p>With the Session Login feature you don't have to execute the authentication command everytime you connect to the server! Each command and every feature can be enabled or disabled from our well structured configuration file.</p>
|
||||
typing commands or using the inventory. It can also kick players with uncommonly long or short player names or kick players from banned countries.</p>
|
||||
<p>With the Session Login feature you don't have to execute the authentication command every time you connect to the server! Each command and every feature can be enabled or disabled from our well structured configuration file.</p>
|
||||
<p>You can also create your own translation file and, if you want, you can share it with us! :)</p>
|
||||
|
||||
####Features:
|
||||
@ -76,12 +80,12 @@ typing commands or use the inventory. It can also kick players with uncommon lon
|
||||
<li>Supported password encryption algorithms: MD5, SHA1, SHA256, <a href="https://github.com/CypherX/xAuth/wiki/Password-Hashing">xAuth</a>, <a href="http://en.wikipedia.org/wiki/Whirlpool_(cryptography)">Whirlpool</a></li>
|
||||
<li>Supported alternative registration methods:<br>
|
||||
<ul>
|
||||
<li>PHPBB, VBullettin: MD5VB - PHPBB</li>
|
||||
<li>PHPBB, VBulletin: MD5VB - PHPBB</li>
|
||||
<li>Xenforo: XFBCRYPT</li>
|
||||
<li>MyBB: MYBB</li>
|
||||
<li>IPB3: IPB3</li>
|
||||
<li>IPB4: IPB4</li>
|
||||
<li>PhpFusion: PHPFUSION</li>
|
||||
<li><del>Xenforo SHA1: XFSHA1</del> <strong>(Deprecated)</strong></li>
|
||||
<li><del>Xenforo SHA256: XFSHA256</del> <strong>(Deprecated)</strong></li>
|
||||
<li>Joomla: JOOMLA</li>
|
||||
<li>WBB3: WBB3*</li>
|
||||
<li>SHA512: SHA512</li>
|
||||
@ -90,13 +94,13 @@ typing commands or use the inventory. It can also kick players with uncommon lon
|
||||
</ul></li>
|
||||
<li>Custom MySQL tables/columns names (useful with forums databases)</li>
|
||||
<li><strong>Cached database queries!</strong></li>
|
||||
<li><strong>Full compatible with Citizens2, CombatTag, CombatTagPlus and ChestShop!</strong></li>
|
||||
<li><strong>Fully compatible with Citizens2, CombatTag, CombatTagPlus and ChestShop!</strong></li>
|
||||
<li>Compatible with Minecraft mods like <strong>BuildCraft or RedstoneCraft</strong></li>
|
||||
<li>Restricted users (associate a Username with an IP)</li>
|
||||
<li>Protect player's inventory until a correct Authentication</li>
|
||||
<li>Saves the quit location of the player</li>
|
||||
<li>Automatic database Backup</li>
|
||||
<li>Avariable languages: en, de, br, cz, pl, fr, uk, ru, hu, sk, es, fi, zhtw, zhhk, zhcn, lt, it, ko, pt, nl, gl, bg, eu, tr (feel free to send new translations)</li>
|
||||
<li>Available languages: en, de, br, cz, pl, fr, uk, ru, hu, sk, es, fi, zhtw, zhhk, zhcn, lt, it, ko, pt, nl, gl, bg, eu, tr, vn (feel free to send new translations)</li>
|
||||
<li>Built-in Deprecated FlatFile (auths.db) to SQL (authme.sql) converter!</li>
|
||||
<li><strong>Import your old database from other plugins like Rakamak, xAuth, CrazyLogin, RoyalAuth and vAuth!</strong></li>
|
||||
</ul>
|
||||
@ -108,18 +112,17 @@ typing commands or use the inventory. It can also kick players with uncommon lon
|
||||
####Commands
|
||||
<a href="http://dev.bukkit.org/server-mods/authme-reloaded/pages/command/">Command list and usage</a>
|
||||
####Permissions
|
||||
<ul><li>authme.player.* - for all user command
|
||||
</li><li>authme.admin.* - for all admin command
|
||||
</li><li>authme.* - for all user and admin command
|
||||
<ul><li>authme.player.* - for all user commands
|
||||
</li><li>authme.admin.* - for all admin commands
|
||||
</li><li><a href="http://dev.bukkit.org/server-mods/authme-reloaded/pages/permissions/">List of all single permissions</a>
|
||||
</li></ul>
|
||||
####How To
|
||||
<ul><li><a href="http://dev.bukkit.org/server-mods/authme-reloaded/pages/how-to-install-and-initial-configuration/">How to Install and Setup</a>
|
||||
</li><li><a href="http://dev.bukkit.org/server-mods/authme-reloaded/pages/how-to-import-database-from-xauth/">How to import database from xAuth</a>
|
||||
</li><li><a href="http://dev.bukkit.org/server-mods/authme-reloaded/pages/web-site-integration/">WebSite Integration</a>
|
||||
</li><li><a href="http://dev.bukkit.org/server-mods/authme-reloaded/pages/web-site-integration/">Website Integration</a>
|
||||
</li><li><a href="https://raw.githubusercontent.com/Xephi/AuthMeReloaded/master/src/main/resources/config.yml">Click here for an example of the Config file</a>
|
||||
</li><li><a href="http://dev.bukkit.org/server-mods/authme-reloaded/pages/how-to-import-database-from-rakamak/">How to convert from Rakamak</a>
|
||||
</li><li>Convert from FlatFile (auths.db but not the sqlite one ) to MySQL: /converter
|
||||
</li><li>Convert from FlatFile (auths.db but not the sqlite one) to MySQL: /authme converter
|
||||
</li></ul>
|
||||
<hr>
|
||||
|
||||
@ -138,5 +141,5 @@ GameHosting.it is leader in Italy as Game Server Provider. With its own DataCent
|
||||
|
||||
#####Credits
|
||||
<p>Team members: look at the <a href="https://github.com/AuthMe-Team/AuthMeReloaded/blob/master/team.txt">team.txt file</a>
|
||||
<p>Credit for old version of the plugin to: d4rkwarriors, fabe1337 , Whoami2 and pomo4ka</p>
|
||||
<p>Credit for old version of the plugin to: d4rkwarriors, fabe1337, Whoami2 and pomo4ka</p>
|
||||
<p>Thanks also to: AS1LV3RN1NJA, Hoeze and eprimex</p>
|
||||
|
@ -7,3 +7,10 @@ general:
|
||||
test:
|
||||
override:
|
||||
- mvn clean install -B
|
||||
post:
|
||||
- cp ./target/AuthMe-*-SNAPSHOT-spigot.jar $CIRCLE_ARTIFACTS
|
||||
- cp ./target/AuthMe-*-SNAPSHOT-legacy.jar $CIRCLE_ARTIFACTS
|
||||
- cp ./target/AuthMe-*-SNAPSHOT-spigot.jar $CIRCLE_ARTIFACTS/AuthMe.jar
|
||||
notify:
|
||||
webhooks:
|
||||
- url: https://webhooks.gitter.im/e/7b92ac1a1741748b26bf
|
||||
|
80
docs/commands.md
Normal file
80
docs/commands.md
Normal file
@ -0,0 +1,80 @@
|
||||
<!-- AUTO-GENERATED FILE! Do not edit this directly -->
|
||||
<!-- File auto-generated on Sun Feb 14 19:00:30 CET 2016. See commands/commands.tpl.md -->
|
||||
|
||||
## AuthMe Commands
|
||||
You can use the following commands to use the features of AuthMe. Mandatory arguments are marked with `< >`
|
||||
brackets; optional arguments are enclosed in square brackets (`[ ]`).
|
||||
|
||||
- **/authme**: The main AuthMeReloaded command. The root for all admin commands.
|
||||
- **/authme register** <player> <password>: Register the specified player with the specified password.
|
||||
<br />Requires `authme.admin.register`
|
||||
- **/authme unregister** <player>: Unregister the specified player.
|
||||
<br />Requires `authme.admin.unregister`
|
||||
- **/authme forcelogin** [player]: Enforce the specified player to login.
|
||||
<br />Requires `authme.player.canbeforced`
|
||||
- **/authme password** <player> <pwd>: Change the password of a player.
|
||||
<br />Requires `authme.admin.changepassword`
|
||||
- **/authme lastlogin** [player]: View the date of the specified players last login.
|
||||
<br />Requires `authme.admin.lastlogin`
|
||||
- **/authme accounts** [player]: Display all accounts of a player by his player name or IP.
|
||||
<br />Requires `authme.admin.accounts`
|
||||
- **/authme email** [player]: Display the email address of the specified player if set.
|
||||
<br />Requires `authme.admin.getemail`
|
||||
- **/authme setemail** <player> <email>: Change the email address of the specified player.
|
||||
<br />Requires `authme.admin.changemail`
|
||||
- **/authme getip** <player>: Get the IP address of the specified online player.
|
||||
<br />Requires `authme.admin.getip`
|
||||
- **/authme spawn** <player>: Teleport to the spawn.
|
||||
<br />Requires `authme.admin.spawn`
|
||||
- **/authme setspawn**: Change the player's spawn to your current position.
|
||||
<br />Requires `authme.admin.setspawn`
|
||||
- **/authme firstspawn**: Teleport to the first spawn.
|
||||
<br />Requires `authme.admin.firstspawn`
|
||||
- **/authme setfirstspawn**: Change the first player's spawn to your current position.
|
||||
<br />Requires `authme.admin.setfirstspawn`
|
||||
- **/authme purge** <days>: Purge old AuthMeReloaded data longer than the specified amount of days ago.
|
||||
<br />Requires `authme.admin.purge`
|
||||
- **/authme resetpos** <player/*>: Purge the last know position of the specified player or all of them.
|
||||
<br />Requires `authme.admin.purgelastpos`
|
||||
- **/authme purgebannedplayers**: Purge all AuthMeReloaded data for banned players.
|
||||
<br />Requires `authme.admin.purgebannedplayers`
|
||||
- **/authme switchantibot** [mode]: Switch or toggle the AntiBot mode to the specified state.
|
||||
<br />Requires `authme.admin.switchantibot`
|
||||
- **/authme reload**: Reload the AuthMeReloaded plugin.
|
||||
<br />Requires `authme.admin.reload`
|
||||
- **/authme version**: Show detailed information about the installed AuthMeReloaded version, the developers, contributors, and license.
|
||||
- **/authme help** [query]: View detailed help for /authme commands.
|
||||
- **/login** <password>: Command to log in using AuthMeReloaded.
|
||||
<br />Requires `authme.player.login`
|
||||
- **/login help** [query]: View detailed help for /login commands.
|
||||
- **/logout**: Command to logout using AuthMeReloaded.
|
||||
<br />Requires `authme.player.logout`
|
||||
- **/logout help** [query]: View detailed help for /logout commands.
|
||||
- **/register** [password] [verifyPassword]: Command to register using AuthMeReloaded.
|
||||
<br />Requires `authme.player.register`
|
||||
- **/register help** [query]: View detailed help for /register commands.
|
||||
- **/unreg** <password>: Command to unregister using AuthMeReloaded.
|
||||
<br />Requires `authme.player.unregister`
|
||||
- **/unreg help** [query]: View detailed help for /unreg commands.
|
||||
- **/changepassword** <oldPassword> <newPassword>: Command to change your password using AuthMeReloaded.
|
||||
<br />Requires `authme.player.changepassword`
|
||||
- **/changepassword help** [query]: View detailed help for /changepassword commands.
|
||||
- **/email**: The AuthMeReloaded Email command base.
|
||||
- **/email add** <email> <verifyEmail>: Add a new email address to your account.
|
||||
<br />Requires `authme.player.email.add`
|
||||
- **/email change** <oldEmail> <newEmail>: Change an email address of your account.
|
||||
<br />Requires `authme.player.email.change`
|
||||
- **/email recover** <email>: Recover your account using an Email address by sending a mail containing a new password.
|
||||
<br />Requires `authme.player.email.recover`
|
||||
- **/email help** [query]: View detailed help for /email commands.
|
||||
- **/captcha** <captcha>: Captcha command for AuthMeReloaded.
|
||||
<br />Requires `authme.player.captcha`
|
||||
- **/captcha help** [query]: View detailed help for /captcha commands.
|
||||
- **/converter** <job>: Converter command for AuthMeReloaded.
|
||||
<br />Requires `authme.admin.converter`
|
||||
- **/converter help** [query]: View detailed help for /converter commands.
|
||||
|
||||
|
||||
---
|
||||
|
||||
This page was automatically generated on the [AuthMe-Team/AuthMeReloaded repository](https://github.com/AuthMe-Team/AuthMeReloaded/tree/master/docs/) on Sun Feb 14 19:00:30 CET 2016
|
85
docs/hash_algorithms.md
Normal file
85
docs/hash_algorithms.md
Normal file
@ -0,0 +1,85 @@
|
||||
<!-- AUTO-GENERATED FILE! Do not edit this directly -->
|
||||
<!-- File auto-generated on Sun Feb 14 19:00:32 CET 2016. See hashmethods/hash_algorithms.tpl.md -->
|
||||
|
||||
## Hash Algorithms
|
||||
AuthMe supports the following hash algorithms for storing your passwords safely.
|
||||
|
||||
|
||||
Algorithm | Recommendation | Hash length | ASCII | | Salt type | Length | Separate?
|
||||
--------- | -------------- | ----------- | ----- | --- | --------- | ------ | ---------
|
||||
BCRYPT | Recommended | 60 | | | Text | |
|
||||
BCRYPT2Y | Recommended | 60 | | | Text | 22 |
|
||||
CRAZYCRYPT1 | Do not use | 128 | | | Username | |
|
||||
DOUBLEMD5 | Do not use | 32 | | | None | |
|
||||
IPB3 | Acceptable | 32 | | | Text | 5 | Y
|
||||
IPB4 | Does not work | 60 | | | Text | 22 | Y
|
||||
JOOMLA | Recommended | 65 | | | Text | 32 |
|
||||
MD5 | Do not use | 32 | | | None | |
|
||||
MD5VB | Acceptable | 56 | | | Text | 16 |
|
||||
MYBB | Acceptable | 32 | | | Text | 8 | Y
|
||||
PBKDF2 | Does not work | 330 | | | Text | 12 |
|
||||
PBKDF2DJANGO | Acceptable | 77 | Y | | Text | 12 |
|
||||
PHPBB | Acceptable | 34 | | | Text | 16 |
|
||||
PHPFUSION | Do not use | 64 | Y | | | | Y
|
||||
ROYALAUTH | Do not use | 128 | | | None | |
|
||||
SALTED2MD5 | Acceptable | 32 | | | Text | | Y
|
||||
SALTEDSHA512 | Recommended | 128 | | | | | Y
|
||||
SHA1 | Do not use | 40 | | | None | |
|
||||
SHA256 | Recommended | 86 | | | Text | 16 |
|
||||
SHA512 | Do not use | 128 | | | None | |
|
||||
SMF | Do not use | 40 | | | Username | |
|
||||
TWO_FACTOR | Does not work | 16 | | | None | |
|
||||
WBB3 | Acceptable | 40 | | | Text | 40 | Y
|
||||
WBB4 | Recommended | 60 | | | Text | 8 |
|
||||
WHIRLPOOL | Do not use | 128 | | | None | |
|
||||
WORDPRESS | Acceptable | 34 | | | Text | 9 |
|
||||
XAUTH | Recommended | 140 | | | Text | 12 |
|
||||
XFBCRYPT | | 60 | | | | |
|
||||
CUSTOM | | | | | | | |
|
||||
|
||||
<!-- AUTO-GENERATED FILE! Do not edit this directly -->
|
||||
|
||||
### Columns
|
||||
#### Algorithm
|
||||
The algorithm is the hashing algorithm used to store passwords with. Default is SHA256 and is recommended.
|
||||
You can change the hashing algorithm in the config.yml: under `security`, locate `passwordHash`.
|
||||
|
||||
#### Recommendation
|
||||
The recommendation lists our usage recommendation in terms of how secure it is (not how _well_ the algorithm works!).
|
||||
- Recommended: The hash algorithm appears to be cryptographically secure and is one we recommend.
|
||||
- Acceptable: There are safer algorithms that can be chosen but using the algorithm is generally OK.
|
||||
- Do not use: Hash algorithm isn't sufficiently secure. Use only if required to hook into another system.
|
||||
- Does not work: The algorithm does not work properly; do not use.
|
||||
|
||||
#### Hash Length
|
||||
The length of the hashes the algorithm produces. Note that the hash length is not (primarily) indicative of
|
||||
whether an algorithm is secure or not.
|
||||
|
||||
#### ASCII
|
||||
If denoted with a **y**, means that the algorithm is restricted to ASCII characters only, i.e. it will simply ignore
|
||||
"special characters" such as `ÿ` or `Â`. Note that we do not recommend the use of "special characters" in passwords.
|
||||
|
||||
#### Salt Columns
|
||||
Before hashing, a _salt_ may be appended to the password to make the hash more secure. The following columns describe
|
||||
the salt the algorithm uses.
|
||||
<!-- AUTO-GENERATED FILE! Do not edit this directly -->
|
||||
|
||||
##### Salt Type
|
||||
We do not recommend the usage
|
||||
of any algorithm that doesn't use a randomly generated text as salt. This "salt type" column indicates what type of
|
||||
salt the algorithm uses:
|
||||
- Text: randomly generated text (see also the following column, "Length")
|
||||
- Username: the salt is constructed from the username (bad)
|
||||
- None: the algorithm uses no salt (bad)
|
||||
|
||||
##### Length
|
||||
If applicable (salt type is "Text"), indicates the length of the generated salt. The longer the better.
|
||||
If this column is empty when the salt type is "Text", it typically means the salt length can be defined in config.yml.
|
||||
|
||||
##### Separate
|
||||
If denoted with a **y**, it means that the salt is stored in a separate column in the database. This is neither good
|
||||
or bad.
|
||||
|
||||
---
|
||||
|
||||
This page was automatically generated on the [AuthMe-Team/AuthMeReloaded repository](https://github.com/AuthMe-Team/AuthMeReloaded/tree/master/docs/) on Sun Feb 14 19:00:32 CET 2016
|
@ -1,5 +1,5 @@
|
||||
<!-- AUTO-GENERATED FILE! Do not edit this directly -->
|
||||
<!-- File auto-generated on Sat Dec 05 21:18:25 CET 2015. See permissions/permission_nodes.tpl.md -->
|
||||
<!-- File auto-generated on Sun Feb 14 19:00:34 CET 2016. See permissions/permission_nodes.tpl.md -->
|
||||
|
||||
## AuthMe Permission Nodes
|
||||
The following are the permission nodes that are currently supported by the latest dev builds.
|
||||
@ -19,15 +19,16 @@ The following are the permission nodes that are currently supported by the lates
|
||||
- **authme.admin.purgelastpos** – Administrator command to purge the last position of a user.
|
||||
- **authme.admin.register** – Administrator command to register a new user.
|
||||
- **authme.admin.reload** – Administrator command to reload the plugin configuration.
|
||||
- **authme.admin.seeotheraccounts** – Permission to see the other accounts of the players that log in.
|
||||
- **authme.admin.setfirstspawn** – Administrator command to set the first AuthMe spawn.
|
||||
- **authme.admin.setspawn** – Administrator command to set the AuthMe spawn.
|
||||
- **authme.admin.spawn** – Administrator command to teleport to the AuthMe spawn.
|
||||
- **authme.admin.switchantibot** – Administrator command to toggle the AntiBot protection status.
|
||||
- **authme.admin.unregister** – Administrator command to unregister an existing user.
|
||||
- **authme.allowmultipleaccounts** – Permission to be able to register multiple accounts.
|
||||
- **authme.bypassantibot** – Permission node to bypass AntiBot protection.
|
||||
- **authme.bypassforcesurvival** – Permission for users to bypass force-survival mode.
|
||||
- **authme.player.*** – Permission to use all player (non-admin) commands.
|
||||
- **authme.player.allow2accounts** – Permission for users to allow two accounts.
|
||||
- **authme.player.bypassantibot** – Permission node to bypass AntiBot protection.
|
||||
- **authme.player.bypassforcesurvival** – Permission for users to bypass force-survival mode.
|
||||
- **authme.player.canbeforced** – Permission for users a login can be forced to.
|
||||
- **authme.player.captcha** – Command permission to use captcha.
|
||||
- **authme.player.changepassword** – Command permission to change the password.
|
||||
@ -37,7 +38,11 @@ The following are the permission nodes that are currently supported by the lates
|
||||
- **authme.player.login** – Command permission to login.
|
||||
- **authme.player.logout** – Command permission to logout.
|
||||
- **authme.player.register** – Command permission to register.
|
||||
- **authme.player.seeotheraccounts** – Permission for user to see other accounts.
|
||||
- **authme.player.seeownaccounts** – Permission to use to see own other accounts.
|
||||
- **authme.player.unregister** – Command permission to unregister.
|
||||
- **authme.player.vip** – Permission node to identify VIP users.
|
||||
- **authme.vip** – Permission node to identify VIP users.
|
||||
|
||||
|
||||
---
|
||||
|
||||
This page was automatically generated on the [AuthMe-Team/AuthMeReloaded repository](https://github.com/AuthMe-Team/AuthMeReloaded/tree/master/docs/) on Sun Feb 14 19:00:34 CET 2016
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
333
pom.xml
333
pom.xml
@ -1,5 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
@ -51,6 +52,7 @@
|
||||
|
||||
<!-- Project Properties -->
|
||||
<pluginName>AuthMe</pluginName>
|
||||
<jarName>${pluginName}-${project.version}</jarName>
|
||||
<mainClass>fr.xephi.authme.AuthMe</mainClass>
|
||||
<pluginAuthors>Xephi, sgdc3, DNx5, timvisee, games647, ljacqu</pluginAuthors>
|
||||
<buildNumber>Unknown</buildNumber>
|
||||
@ -77,7 +79,7 @@
|
||||
</profiles>
|
||||
|
||||
<build>
|
||||
<finalName>AuthMe-${project.version}</finalName>
|
||||
<finalName>${jarName}-noshade</finalName>
|
||||
<sourceDirectory>src/main/java</sourceDirectory>
|
||||
<testSourceDirectory>src/test/java</testSourceDirectory>
|
||||
|
||||
@ -90,6 +92,15 @@
|
||||
<include>plugin.yml</include>
|
||||
</includes>
|
||||
</resource>
|
||||
<resource>
|
||||
<targetPath>.</targetPath>
|
||||
<filtering>true</filtering>
|
||||
<directory>src/main/resources/</directory>
|
||||
<includes>
|
||||
<include>email.html</include>
|
||||
<include>welcome.txt</include>
|
||||
</includes>
|
||||
</resource>
|
||||
<resource>
|
||||
<targetPath>.</targetPath>
|
||||
<filtering>false</filtering>
|
||||
@ -116,111 +127,174 @@
|
||||
</testResource>
|
||||
</testResources>
|
||||
|
||||
<!-- Just to keep Eclipse compatibility... -->
|
||||
<pluginManagement>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.eclipse.m2e</groupId>
|
||||
<artifactId>lifecycle-mapping</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<configuration>
|
||||
<lifecycleMappingMetadata>
|
||||
<pluginExecutions>
|
||||
<pluginExecution>
|
||||
<pluginExecutionFilter>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>buildnumber-maven-plugin</artifactId>
|
||||
<versionRange>[1.0,)</versionRange>
|
||||
<goals>
|
||||
<goal>create-timestamp</goal>
|
||||
</goals>
|
||||
</pluginExecutionFilter>
|
||||
<action>
|
||||
<execute>
|
||||
<runOnConfiguration>true</runOnConfiguration>
|
||||
<runOnIncremental>true</runOnIncremental>
|
||||
</execute>
|
||||
</action>
|
||||
</pluginExecution>
|
||||
</pluginExecutions>
|
||||
</lifecycleMappingMetadata>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</pluginManagement>
|
||||
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.3</version>
|
||||
<version>3.5.1</version>
|
||||
<configuration>
|
||||
<source>1.7</source>
|
||||
<target>${javaVersion}</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>buildnumber-maven-plugin</artifactId>
|
||||
<version>1.4</version>
|
||||
<configuration>
|
||||
<timestampFormat>dd-MM-yy_HH-mm</timestampFormat>
|
||||
<timestampPropertyName>build.time</timestampPropertyName>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>generate-resources</phase>
|
||||
<goals>
|
||||
<goal>create-timestamp</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
<!-- TODO: we need also to relocate the other libs -->
|
||||
<plugin>
|
||||
<!--Relocate all lib we use in order to fix class loading errors if we use different versions
|
||||
than already loaded libs (i.e. by Mojang -> gson)-->
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>2.4.2</version>
|
||||
<version>2.4.3</version>
|
||||
<configuration>
|
||||
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||
<minimizeJar>false</minimizeJar>
|
||||
<relocations>
|
||||
<relocation>
|
||||
<pattern>org.mcstats</pattern>
|
||||
<shadedPattern>fr.xephi.authme</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>com.google.gson</pattern>
|
||||
<shadedPattern>fr.xephi.authme.libs.gson</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>com.zaxxer.hikari</pattern>
|
||||
<shadedPattern>fr.xephi.authme.libs.hikari</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>org.slf4j</pattern>
|
||||
<shadedPattern>fr.xephi.authme.libs.slf4j</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>com.maxmind.geoip</pattern>
|
||||
<shadedPattern>fr.xephi.authme.libs.geoip</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>net.ricecode.similarity</pattern>
|
||||
<shadedPattern>fr.xephi.authme.libs.similarity</shadedPattern>
|
||||
</relocation>
|
||||
</relocations>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>spigot-shade</id>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<artifactSet>
|
||||
<excludes>
|
||||
<exclude>com.google.guava:guava</exclude>
|
||||
</excludes>
|
||||
</artifactSet>
|
||||
<relocations>
|
||||
<!--We use a newer version of gson so include it to the jar and reference to the new version-->
|
||||
<relocation>
|
||||
<pattern>com.google.gson</pattern>
|
||||
<shadedPattern>fr.xephi.authme.libs.google</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>org.mcstats</pattern>
|
||||
<shadedPattern>fr.xephi.authme</shadedPattern>
|
||||
</relocation>
|
||||
<!--
|
||||
<relocation>
|
||||
<pattern>org.apache</pattern>
|
||||
<shadedPattern>fr.xephi.authme.libs.apache</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>javax.mail</pattern>
|
||||
<shadedPattern>fr.xephi.authme.libs.javax.mail</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>javax.activation</pattern>
|
||||
<shadedPattern>fr.xephi.authme.libs.javax.activation</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>com.sun</pattern>
|
||||
<shadedPattern>fr.xephi.authme.libs.sun</shadedPattern>
|
||||
</relocation>
|
||||
-->
|
||||
<relocation>
|
||||
<pattern>com.zaxxer.hikari</pattern>
|
||||
<shadedPattern>fr.xephi.authme.libs.hikari</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>org.slf4j</pattern>
|
||||
<shadedPattern>fr.xephi.authme.libs.slf4j</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>com.maxmind.geoip</pattern>
|
||||
<shadedPattern>fr.xephi.authme.libs.geoip</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>net.ricecode.similarity</pattern>
|
||||
<shadedPattern>fr.xephi.authme.libs.similarity</shadedPattern>
|
||||
</relocation>
|
||||
</relocations>
|
||||
<outputFile>target/${jarName}-spigot.jar</outputFile>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>legacy-shade</id>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<!--Include all google libraries, because they are not avaialbe before 1.8-->
|
||||
<relocations>
|
||||
<relocation>
|
||||
<pattern>com.google</pattern>
|
||||
<shadedPattern>fr.xephi.authme.libs.google</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>org.mcstats</pattern>
|
||||
<shadedPattern>fr.xephi.authme</shadedPattern>
|
||||
</relocation>
|
||||
<!--
|
||||
<relocation>
|
||||
<pattern>org.apache</pattern>
|
||||
<shadedPattern>fr.xephi.authme.libs.apache</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>javax.mail</pattern>
|
||||
<shadedPattern>fr.xephi.authme.libs.javax.mail</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>javax.activation</pattern>
|
||||
<shadedPattern>fr.xephi.authme.libs.javax.activation</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>com.sun</pattern>
|
||||
<shadedPattern>fr.xephi.authme.libs.sun</shadedPattern>
|
||||
</relocation>
|
||||
-->
|
||||
<relocation>
|
||||
<pattern>com.zaxxer.hikari</pattern>
|
||||
<shadedPattern>fr.xephi.authme.libs.hikari</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>org.slf4j</pattern>
|
||||
<shadedPattern>fr.xephi.authme.libs.slf4j</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>com.maxmind.geoip</pattern>
|
||||
<shadedPattern>fr.xephi.authme.libs.geoip</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>net.ricecode.similarity</pattern>
|
||||
<shadedPattern>fr.xephi.authme.libs.similarity</shadedPattern>
|
||||
</relocation>
|
||||
</relocations>
|
||||
<outputFile>target/${jarName}-legacy.jar</outputFile>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.jacoco</groupId>
|
||||
<artifactId>jacoco-maven-plugin</artifactId>
|
||||
<version>0.7.5.201505241946</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>prepare-agent</id>
|
||||
<goals>
|
||||
<goal>prepare-agent</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.eluder.coveralls</groupId>
|
||||
<artifactId>coveralls-maven-plugin</artifactId>
|
||||
<version>4.1.0</version>
|
||||
<!-- Token is provided by mvn command -->
|
||||
</plugin>
|
||||
<!-- Javadocs settings -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
<version>2.10.3</version>
|
||||
<configuration>
|
||||
<charset>UTF-8</charset>
|
||||
<docencoding>UTF-8</docencoding>
|
||||
<docfilessubdirs>true</docfilessubdirs>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
@ -228,7 +302,7 @@
|
||||
<!-- SpigotMC Repo (Bukkit and SpigotAPI) -->
|
||||
<repository>
|
||||
<id>spigot-repo</id>
|
||||
<url>http://hub.spigotmc.org/nexus/content/groups/public</url>
|
||||
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots</url>
|
||||
</repository>
|
||||
|
||||
<!-- EssentialsX Repo -->
|
||||
@ -273,10 +347,10 @@
|
||||
<url>http://ci.xephi.fr/plugin/repository/everything/</url>
|
||||
</repository>
|
||||
|
||||
<!-- PermissionsEx Repo -->
|
||||
<!-- PermissionsEx Repo (Re-added, since Xephi's repo was down) -->
|
||||
<repository>
|
||||
<id>pex-repo</id>
|
||||
<url>http://pex-repo.aoeu.xyz/</url>
|
||||
<url>https://pex-repo.aoeu.xyz/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
@ -298,7 +372,7 @@
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-jdk14</artifactId>
|
||||
<version>1.7.13</version>
|
||||
<version>1.7.16</version>
|
||||
<scope>compile</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
@ -326,7 +400,16 @@
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
<version>2.4</version>
|
||||
<version>2.6.1</version>
|
||||
<scope>compile</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<!-- Guava (required to provide 1.7.10 and below compatibility) -->
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
<version>17.0</version>
|
||||
<scope>compile</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
@ -335,7 +418,7 @@
|
||||
<dependency>
|
||||
<groupId>com.maxmind.geoip</groupId>
|
||||
<artifactId>geoip-api</artifactId>
|
||||
<version>1.2.15</version>
|
||||
<version>1.3.1</version>
|
||||
<scope>compile</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
@ -379,6 +462,10 @@
|
||||
<artifactId>persistence-api</artifactId>
|
||||
<groupId>javax.persistence</groupId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<artifactId>guava</artifactId>
|
||||
<groupId>com.google.guava</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
@ -430,19 +517,29 @@
|
||||
<!-- GroupManager plugin -->
|
||||
<dependency>
|
||||
<groupId>org.anjocaido</groupId>
|
||||
<artifactId>groupmanager</artifactId>
|
||||
<version>2.13.1</version>
|
||||
<scope>system</scope>
|
||||
<systemPath>${basedir}/lib/EssentialsGroupManager-2.13.1.jar</systemPath>
|
||||
<artifactId>groupmanagerx</artifactId>
|
||||
<version>2.2-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>bukkit</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<!-- bPermissions plugin -->
|
||||
<dependency>
|
||||
<groupId>de.bananaco</groupId>
|
||||
<artifactId>bpermissions</artifactId>
|
||||
<version>1.12-DEV</version>
|
||||
<scope>system</scope>
|
||||
<systemPath>${basedir}/lib/bPermissions-2.12-DEV.jar</systemPath>
|
||||
<artifactId>bPermissions</artifactId>
|
||||
<version>2.12-DEV</version>
|
||||
<scope>provided</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>bukkit</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<!-- zPermissions plugin -->
|
||||
@ -450,17 +547,33 @@
|
||||
<groupId>org.tyrannyofheaven.bukkit</groupId>
|
||||
<artifactId>zPermissions</artifactId>
|
||||
<version>1.3-SNAPSHOT</version>
|
||||
<scope>system</scope>
|
||||
<systemPath>${basedir}/lib/zPermissions-1.3beta1.jar</systemPath>
|
||||
</dependency>
|
||||
|
||||
<!-- Permissions plugin (obsolete) -->
|
||||
<dependency>
|
||||
<groupId>com.nijiko</groupId>
|
||||
<artifactId>permissions</artifactId>
|
||||
<version>3.1.6</version>
|
||||
<scope>system</scope>
|
||||
<systemPath>${basedir}/lib/Permission-3.1.6.jar</systemPath>
|
||||
<scope>provided</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>bukkit</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>com.sk89q</groupId>
|
||||
<artifactId>worldguard</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>com.sk89q</groupId>
|
||||
<artifactId>worldedit</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<artifactId>VaultAPI</artifactId>
|
||||
<groupId>net.milkbowl.vault</groupId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<artifactId>uuidprovider</artifactId>
|
||||
<groupId>net.kaikk.mc</groupId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<artifactId>ToHPluginUtils</artifactId>
|
||||
<groupId>org.tyrannyofheaven.bukkit</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<!-- Vault, http://dev.bukkit.org/bukkit-plugins/vault/ -->
|
||||
@ -692,6 +805,12 @@
|
||||
<scope>test</scope>
|
||||
<version>2.0.5-beta</version>
|
||||
<optional>true</optional>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>hamcrest-core</artifactId>
|
||||
<groupId>org.hamcrest</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<!-- String comparison library. Used for dynamic help system. -->
|
||||
|
572
samples/NewConfig.yml
Normal file
572
samples/NewConfig.yml
Normal file
@ -0,0 +1,572 @@
|
||||
# =======================================================================================================
|
||||
# _____ __ .__ _____ __________ .__ .___ .___
|
||||
# / _ \ __ ___/ |_| |__ / \ ____\______ \ ____ | | _________ __| _/____ __| _/
|
||||
# / /_\ \| | \ __| | \ / \ / \_/ __ \| __/ __ \| | / _ \__ \ / __ _/ __ \ / __ |
|
||||
# / | | | /| | | Y / Y \ ___/| | \ ___/| |_( <_> / __ \/ /_/ \ ___// /_/ |
|
||||
# \____|__ |____/ |__| |___| \____|__ /\___ |____|_ /\___ |____/\____(____ \____ |\___ \____ |
|
||||
# \/ \/ \/ \/ \/ \/ \/ \/ \/ \/
|
||||
#
|
||||
# =======================================================================================================
|
||||
#
|
||||
# Authme Main Configuration File.
|
||||
#
|
||||
# =======================================================================================================
|
||||
|
||||
# Plugin infos (overwritten on start, just a simple way to find out your plugin version).
|
||||
authors: ${pluginAuthors}
|
||||
version: ${project.version}
|
||||
buildNumber: ${buildNumber}
|
||||
|
||||
# Set this setting to true when you have configured the plugin,
|
||||
# when false the server will be stopped with a warning message.
|
||||
enabled: false
|
||||
|
||||
# Database settings.
|
||||
data_source:
|
||||
# ===========================
|
||||
# Database general settings.
|
||||
# ===========================
|
||||
|
||||
# Database backend (sqlite, mysql).
|
||||
backend: sqlite
|
||||
# Enable database queries caching, should improve performance.
|
||||
caching: true
|
||||
|
||||
# ===========================
|
||||
# SqLite db parameters.
|
||||
# ===========================
|
||||
|
||||
sqlite:
|
||||
# The name of the database storage file.
|
||||
filename: 'authme.db'
|
||||
|
||||
# ===========================
|
||||
# MySql db parameters.
|
||||
# ===========================
|
||||
|
||||
mysql:
|
||||
# Connection parameters.
|
||||
host: '127.0.0.1'
|
||||
port: 3306
|
||||
username: 'change_me'
|
||||
password: 'change_me'
|
||||
database: 'my_minecraft_server'
|
||||
tablename: 'authme'
|
||||
|
||||
# Column names.
|
||||
column_names:
|
||||
id: id
|
||||
# Column for storing nicknames (ignore case nickname).
|
||||
name: username
|
||||
# Column for storing the realname (case sensitive nickname).
|
||||
real_name: realname
|
||||
# Column for storing passwords.
|
||||
password: password
|
||||
# Column for storing email addresses.
|
||||
email: email
|
||||
# Column for storing the authentication status (logged or not).
|
||||
login_status: isLogged
|
||||
# Column for storing player IPs.
|
||||
ip: ip
|
||||
# Column for storing lastlogins date and time.
|
||||
last_login_timestamp: lastlogin
|
||||
# Latest logout location of the players.
|
||||
last_location:
|
||||
world: world
|
||||
x: x
|
||||
y: y
|
||||
z: z
|
||||
# Enabled only if the bungeecord integration is activated.
|
||||
server: world
|
||||
|
||||
# Support for registrations via WebInterfaces/CSM.
|
||||
# Disable some backend caching parameters.
|
||||
disableAggressiveCaching: false
|
||||
|
||||
# Main settings
|
||||
settings:
|
||||
|
||||
# ===========================
|
||||
# Bungeecord integration
|
||||
# ===========================
|
||||
|
||||
bungeecord:
|
||||
# Enable bungeecord integration features
|
||||
enabled: true
|
||||
|
||||
# Server name (must be unique, please use the name in the bungeecord configuration).
|
||||
# Use 'auto' for auto configuration (requires the bungeecord module).
|
||||
serverName: LoginLobby1
|
||||
# Keep the auth status when the player moves between servers.
|
||||
# Required if you're using the bungeecord module.
|
||||
keepAuthBetweenServers: true
|
||||
|
||||
# Target server after login
|
||||
send_after_login:
|
||||
enabled: false
|
||||
message: ''
|
||||
delay: 5
|
||||
# Server name ("ServerName") or group ("G:GroupName")
|
||||
# Groups are avariable only when the bungeecord module is avariable.
|
||||
# If the server change fails the player will be kicked.
|
||||
target: Lobby1
|
||||
failKickMessage: 'Failed to connect to the lobby! Please try to join the server again!'
|
||||
# Target server after logout
|
||||
send_after_logout:
|
||||
enabled: false
|
||||
message: ''
|
||||
delay: 5
|
||||
# Server name ("ServerName") or group ("G:GroupName")
|
||||
# Groups are avariable only when the bungeecord module is avariable.
|
||||
# If the server change fails the player will be kicked.
|
||||
target: LoginLobby1
|
||||
failKickMessage: 'Failed to connect to the lobby! Please try to join the server again!'
|
||||
|
||||
# Variables:
|
||||
# %p playername
|
||||
bungee_commands:
|
||||
player_command_after_register:
|
||||
enabled: false
|
||||
cmd: ''
|
||||
console_command_after_register:
|
||||
enabled: false
|
||||
cmd: 'alert %p joined for the first time the network!'
|
||||
player_command_after_login:
|
||||
enabled: false
|
||||
cmd: 'glist'
|
||||
console_command_after_login:
|
||||
enabled: false
|
||||
cmd: 'alert %p logged in correctly!'
|
||||
player_command_after_join:
|
||||
enabled: false
|
||||
cmd: ''
|
||||
console_command_after_join:
|
||||
enabled: false
|
||||
cmd: 'alert %p joined the network!'
|
||||
player_command_first_join:
|
||||
enabled: false
|
||||
cmd: ''
|
||||
console_command_first_join:
|
||||
enabled: false
|
||||
cmd: 'alert %p joined for the first time the network!'
|
||||
|
||||
# ===========================
|
||||
# Sessions configuration.
|
||||
# ===========================
|
||||
|
||||
sessions:
|
||||
# Enable sessions.
|
||||
# When a player is authenticated, his IP and his nickname is saved.
|
||||
# The next time the player will join the server, if his IP is the same
|
||||
# of the last time, and the timeout time hasn't expired, he will be
|
||||
# automatically authenticated.
|
||||
enabled: false
|
||||
# Session timeout.
|
||||
# 0 for unlimited time (Very dangerous, use it at your own risk!)
|
||||
# Consider that if player's ip has changed but the timeout hasn't
|
||||
# expired, player will be kicked out of the sever!
|
||||
timeout: 10
|
||||
# When enabled a player's session will expire if someone tries to
|
||||
# login with a different IP Address.
|
||||
expire_on_ip_change: true
|
||||
|
||||
# ===========================
|
||||
# Registration settings.
|
||||
# ===========================
|
||||
|
||||
registration:
|
||||
# After how many time unregistered players should be kicked?
|
||||
# Set to 0 to disable. (default: 30)
|
||||
timeout: 30
|
||||
|
||||
nickname:
|
||||
min_length: 4
|
||||
max_lenght: 16
|
||||
# Regex syntax.
|
||||
allowed_characters: '[a-zA-Z0-9_]*'
|
||||
|
||||
password:
|
||||
# Enable double check of password on registration:
|
||||
# /register <password> <confirmPassword>
|
||||
double_check: true
|
||||
# Minimum password lenght.
|
||||
min_length: 5
|
||||
# Regex syntax.
|
||||
allowed_characters: '[\x21-\x7E]*'
|
||||
# Denied unsafe passwords.
|
||||
unsafePasswords:
|
||||
- '123456'
|
||||
- 'password'
|
||||
- 'qwerty'
|
||||
- '12345'
|
||||
- '54321'
|
||||
|
||||
# ===========================
|
||||
# Login settings.
|
||||
# ===========================
|
||||
|
||||
login:
|
||||
# After how many time unlogged players should be kicked?
|
||||
# Set to 0 to disable. (default: 30)
|
||||
timeout: 30
|
||||
|
||||
|
||||
|
||||
# ===========================
|
||||
# Encryption parameters.
|
||||
# ===========================
|
||||
|
||||
password_encryption:
|
||||
# The hashing algorithm.
|
||||
# Possible values: MD5, SHA1, SHA256, WHIRLPOOL, XAUTH, MD5VB, PHPBB, MYBB, IPB3,
|
||||
# PHPFUSION, SMF, XENFORO, SALTED2MD5, JOOMLA, BCRYPT, WBB3, SHA512, DOUBLEMD5,
|
||||
# PBKDF2, PBKDF2DJANGO, WORDPRESS, ROYALAUTH, CUSTOM (developpers only).
|
||||
encryption_algorithm: SHA256
|
||||
# The salt length for the SALTED2MD5 and MD5(MD5(password)+salt) algorithms.
|
||||
md5_salt_length: 8
|
||||
# If password check fails try all the other hash algorithm.
|
||||
# AuthMe will update the password to the new passwordHash.
|
||||
enable_convertion: false
|
||||
|
||||
# ===========================
|
||||
# Unlogged user restrictions.
|
||||
# ===========================
|
||||
|
||||
unlogged_restrictions:
|
||||
# Deny chat messages send for unlogged users.
|
||||
deny_chat: true
|
||||
# Hide chat to unlogged users.
|
||||
# Only player messages, plugins will be able to send messages to the player anyway.
|
||||
hide_chat: false
|
||||
|
||||
# Deny any command message not in the whitelist below.
|
||||
deny_commands: true
|
||||
command_whitelist:
|
||||
- /login
|
||||
- /register
|
||||
- /l
|
||||
- /reg
|
||||
- /email
|
||||
- /captcha
|
||||
|
||||
movements:
|
||||
# Restrict player movements.
|
||||
restrict: true
|
||||
# Allowed radius.
|
||||
allowed_radius: 0
|
||||
# Should unlogged players have speed = 0?
|
||||
# After the login the walking/flying speeed will be reset to the default value.
|
||||
removeSpeed: true
|
||||
|
||||
# End is there atm xD
|
||||
|
||||
# This option will save the quit location of the players.
|
||||
SaveQuitLocation: false
|
||||
# Should not logged in players be teleported to the spawn?
|
||||
# After the authentication, if SaveQuitLocation is enabled,
|
||||
# they will be teleported back to their normal position.
|
||||
teleportUnAuthedToSpawn: false
|
||||
|
||||
# If enabled, after the login, if the ForceSpawnOnTheseWorlds setting contains
|
||||
# the player's world, he will be teleported to the world spawnpoint.
|
||||
# The quit location of the player will be overwritten.
|
||||
# This is different from "teleportUnAuthedToSpawn" that teleports player
|
||||
# back to his quit location after the authentication.
|
||||
ForceSpawnLocOnJoinEnabled: false
|
||||
# WorldNames where we need to force the spawn location
|
||||
# Warning: This setting is Case Sensitive!
|
||||
ForceSpawnOnTheseWorlds:
|
||||
- world
|
||||
- world_nether
|
||||
- world_the_end
|
||||
|
||||
# this is very important options,
|
||||
# every time player join the server,
|
||||
# if they are registered, AuthMe will switch him
|
||||
# to unLoggedInGroup, this
|
||||
# should prevent all major exploit.
|
||||
# So you can set up on your Permission Plugin
|
||||
# this special group with 0 permissions, or permissions to chat,
|
||||
# or permission to
|
||||
# send private message or all other perms that you want,
|
||||
# the better way is to set up
|
||||
# this group with few permissions,
|
||||
# so if player try to exploit some account,
|
||||
# they can
|
||||
# do anything except what you set in perm Group.
|
||||
# After a correct logged-in player will be
|
||||
# moved to his correct permissions group!
|
||||
# Pay attention group name is case sensitive,
|
||||
# so Admin is different from admin,
|
||||
# otherwise your group will be wiped,
|
||||
# and player join in default group []!
|
||||
# Example unLoggedinGroup: NotLogged
|
||||
unLoggedinGroup: unLoggedinGroup
|
||||
|
||||
# ===========================
|
||||
# Address restrictions
|
||||
# ===========================
|
||||
|
||||
# Max number of registrations per IP (default: 1)
|
||||
maxRegPerIp: 1
|
||||
# Maximum allowed number of Logins per IP, 0 to disable (default: 0)
|
||||
maxLoginPerIp: 0
|
||||
# Maximum allowed number of Joins per IP, 0 to disable (default: 0)
|
||||
maxJoinPerIp: 0
|
||||
|
||||
# When this setting is enabled, online players can't be kicked out
|
||||
# due to "Logged in from another Location"
|
||||
# This setting will prevent potetial security exploits.
|
||||
ForceSingleSession: true
|
||||
|
||||
# To activate the restricted user feature you need
|
||||
# to enable this option and configure the
|
||||
# AllowedRestrctedUser field.
|
||||
AllowRestrictedUser: false
|
||||
# The restricted user feature will kick players listed below
|
||||
# if they dont match of the defined ip address.
|
||||
# Example:
|
||||
# AllowedRestrictedUser:
|
||||
# - playername;127.0.0.1
|
||||
AllowedRestrictedUser:
|
||||
- playername;127.0.0.
|
||||
# Ban ip when the ip is not the ip registered in database
|
||||
banUnsafedIP: false
|
||||
|
||||
|
||||
|
||||
# ===============================
|
||||
# Other restrictions
|
||||
# ===============================
|
||||
|
||||
# Should we protect the player inventory before logging in?
|
||||
# Warning: Requires the latest version of ProtocolLib!
|
||||
ProtectInventoryBeforeLogIn: true
|
||||
|
||||
# Should unregistered players be kicked immediately?
|
||||
kickNonRegistered: false
|
||||
# Should players be kicked on wrong password?
|
||||
kickOnWrongPassword: false
|
||||
|
||||
# Should we display all other accounts of a player when he joins?
|
||||
# Required permission: authme.admin.accounts
|
||||
displayOtherAccounts: true
|
||||
|
||||
# ===============================
|
||||
# Restrictions compatibility
|
||||
# ===============================
|
||||
|
||||
# Spawn Priority. Avariable values : authme, essentials, multiverse, default
|
||||
spawnPriority: authme,essentials,multiverse,default
|
||||
# AuthMe will NEVER teleport players!
|
||||
noTeleport: false
|
||||
|
||||
GameMode:
|
||||
# Do you want to set player's gamemode to survival when he joins?
|
||||
# This enables also the settings below.
|
||||
ForceSurvivalMode: false
|
||||
# Do you want to reset player's inventory if player joins with creative mode?
|
||||
ResetInventoryIfCreative: false
|
||||
# Do you want to force the survival mode ONLY after the /login process?
|
||||
ForceOnlyAfterLogin: false
|
||||
|
||||
# sgdc3: Ok, our configuration is shit.... xD Today I will stop there
|
||||
|
||||
|
||||
registration:
|
||||
# enable registration on the server?
|
||||
enabled: true
|
||||
# Send every X seconds a message to a player to
|
||||
# remind him that he has to login/register
|
||||
messageInterval: 5
|
||||
# Only registered and logged in players can play.
|
||||
# See restrictions for exceptions
|
||||
force: true
|
||||
# Does we replace password registration by an Email registration method ?
|
||||
enableEmailRegistrationSystem: false
|
||||
# Enable double check of email when you register
|
||||
# when it's true, registration require that kind of command:
|
||||
# /register <email> <confirmEmail>
|
||||
doubleEmailCheck: false
|
||||
# Do we force kicking player after a successful registration ?
|
||||
# Do not use with login feature below
|
||||
forceKickAfterRegister: false
|
||||
# Does AuthMe need to enforce a /login after a successful registration ?
|
||||
forceLoginAfterRegister: false
|
||||
unrestrictions:
|
||||
# below you can list all your account name, that
|
||||
# AuthMe will ignore for registration or login, configure it
|
||||
# at your own risk!! Remember that if you are going to add
|
||||
# nickname with [], you have to delimit name with ' '.
|
||||
# this option add compatibility with BuildCraft and some
|
||||
# other mods.
|
||||
# It is CaseSensitive!
|
||||
UnrestrictedName: []
|
||||
# Message language, available : en, de, br, cz, pl, fr, ru, hu, sk, es, zhtw, fi, zhcn, lt, it, ko, pt
|
||||
messagesLanguage: en
|
||||
# Force these commands after /login, without any '/', use %p for replace with player name
|
||||
forceCommands: []
|
||||
# Force these commands after /login as a server console, without any '/', use %p for replace with player name
|
||||
forceCommandsAsConsole: []
|
||||
# Force these commands after /register, without any '/', use %p for replace with player name
|
||||
forceRegisterCommands: []
|
||||
# Force these commands after /register as a server console, without any '/', use %p for replace with player name
|
||||
forceRegisterCommandsAsConsole: []
|
||||
# Do we need to display the welcome message (welcome.txt) after a register or a login?
|
||||
# You can use colors in this welcome.txt + some replaced strings :
|
||||
# {PLAYER} : player name, {ONLINE} : display number of online players, {MAXPLAYERS} : display server slots,
|
||||
# {IP} : player ip, {LOGINS} : number of players logged, {WORLD} : player current world, {SERVER} : server name
|
||||
# {VERSION} : get current bukkit version, {COUNTRY} : player country
|
||||
useWelcomeMessage: true
|
||||
# Do we need to broadcast the welcome message to all server or only to the player? set true for server or false for player
|
||||
broadcastWelcomeMessage: false
|
||||
# Do we need to delay the join/leave message to be displayed only when the player is authenticated ?
|
||||
delayJoinMessage: false
|
||||
removeJoinMessage: false
|
||||
removeLeaveMessage: false
|
||||
# Do we need to add potion effect Blinding before login/register ?
|
||||
applyBlindEffect: false
|
||||
ExternalBoardOptions:
|
||||
# MySQL column for the salt , needed for some forum/cms support
|
||||
mySQLColumnSalt: ''
|
||||
# MySQL column for the group, needed for some forum/cms support
|
||||
mySQLColumnGroup: ''
|
||||
# -1 mean disabled. If u want that only
|
||||
# activated player can login in your server
|
||||
# u can put in this options the group number
|
||||
# of unactivated user, needed for some forum/cms support
|
||||
nonActivedUserGroup: -1
|
||||
# Other MySQL columns where we need to put the Username (case sensitive)
|
||||
mySQLOtherUsernameColumns: []
|
||||
# How much Log to Round needed in BCrypt(do not change it if you do not know what's your doing)
|
||||
bCryptLog2Round: 10
|
||||
# phpBB prefix defined during phpbb installation process
|
||||
phpbbTablePrefix: 'phpbb_'
|
||||
# phpBB activated group id , 2 is default registered group defined by phpbb
|
||||
phpbbActivatedGroupId: 2
|
||||
# WordPress prefix defined during WordPress installation process
|
||||
wordpressTablePrefix: 'wp_'
|
||||
permission:
|
||||
# Take care with this options, if you dont want
|
||||
# to use Vault and Group Switching of
|
||||
# AuthMe for unloggedIn players put true
|
||||
# below, default is false.
|
||||
EnablePermissionCheck: false
|
||||
BackupSystem:
|
||||
# Enable or Disable Automatic Backup
|
||||
ActivateBackup: false
|
||||
# set Backup at every start of Server
|
||||
OnServerStart: false
|
||||
# set Backup at every stop of Server
|
||||
OnServerStop: true
|
||||
# Windows only mysql installation Path
|
||||
MysqlWindowsPath: 'C:\\Program Files\\MySQL\\MySQL Server 5.1\\'
|
||||
Security:
|
||||
SQLProblem:
|
||||
# Stop the server if we can't contact the sql database
|
||||
# Take care with this, if you set that to false,
|
||||
# AuthMe automatically disable and the server is not protected!
|
||||
stopServer: true
|
||||
ReloadCommand:
|
||||
# /reload support
|
||||
useReloadCommandSupport: true
|
||||
console:
|
||||
# Remove spam console
|
||||
noConsoleSpam: false
|
||||
# Replace passwords in the console when player type a command like /login
|
||||
removePassword: true
|
||||
captcha:
|
||||
# Player need to put a captcha when he fails too lot the password
|
||||
useCaptcha: false
|
||||
# Max allowed tries before request a captcha
|
||||
maxLoginTry: 5
|
||||
# Captcha length
|
||||
captchaLength: 5
|
||||
Converter:
|
||||
Rakamak:
|
||||
# Rakamak file name
|
||||
fileName: users.rak
|
||||
# Rakamak use ip ?
|
||||
useIP: false
|
||||
# IP file name for rakamak
|
||||
ipFileName: UsersIp.rak
|
||||
CrazyLogin:
|
||||
# CrazyLogin database file
|
||||
fileName: accounts.db
|
||||
Email:
|
||||
# Email SMTP server host
|
||||
mailSMTP: smtp.gmail.com
|
||||
# Email SMTP server port
|
||||
mailPort: 465
|
||||
# Email account that send the mail
|
||||
mailAccount: ''
|
||||
# Email account password
|
||||
mailPassword: ''
|
||||
# Custom SenderName, that replace the mailAccount name in the email
|
||||
mailSenderName: ''
|
||||
# Random password length
|
||||
RecoveryPasswordLength: 8
|
||||
# Email subject of password get
|
||||
mailSubject: 'Your new AuthMe Password'
|
||||
# Email text here
|
||||
mailText: 'Dear <playername>, <br /><br /> This is your new AuthMe password for the server <br /><br /> <servername> : <br /><br /> <generatedpass><br /><br />Do not forget to change password after login! <br /> /changepassword <generatedpass> newPassword'
|
||||
# Like maxRegPerIp but with email
|
||||
maxRegPerEmail: 1
|
||||
# Recall players to add an email ?
|
||||
recallPlayers: false
|
||||
# Delay in minute for the recall scheduler
|
||||
delayRecall: 5
|
||||
# Blacklist these domains for emails
|
||||
emailBlacklisted:
|
||||
- 10minutemail.com
|
||||
# WhiteList only these domains for emails
|
||||
emailWhitelisted: []
|
||||
# Do we need to send new password draw in an image ?
|
||||
generateImage: false
|
||||
Hooks:
|
||||
# Do we need to hook with multiverse for spawn checking?
|
||||
multiverse: true
|
||||
# Do we need to hook with BungeeCord for get the real Player ip ?
|
||||
bungeecord: false
|
||||
# Do we need to disable Essentials SocialSpy on join ?
|
||||
disableSocialSpy: true
|
||||
# Do we need to force /motd Essentials command on join ?
|
||||
useEssentialsMotd: false
|
||||
# Do we need to cache custom Attributes ?
|
||||
customAttributes: false
|
||||
Purge:
|
||||
# On Enable , does AuthMe need to purge automatically old accounts unused ?
|
||||
useAutoPurge: false
|
||||
# Number of Days an account become Unused
|
||||
daysBeforeRemovePlayer: 60
|
||||
# Do we need to remove the player.dat file during purge process ?
|
||||
removePlayerDat: false
|
||||
# Do we need to remove the Essentials/users/player.yml file during purge process ?
|
||||
removeEssentialsFile: false
|
||||
# World where are players.dat stores
|
||||
defaultWorld: 'world'
|
||||
# Do we need to remove LimitedCreative/inventories/player.yml , player_creative.yml files during purge process ?
|
||||
removeLimitedCreativesInventories: false
|
||||
# Do we need to remove the AntiXRayData/PlayerData/player file during purge process ?
|
||||
removeAntiXRayFile: false
|
||||
# Do we need to remove permissions ?
|
||||
removePermissions: false
|
||||
Protection:
|
||||
# Enable some servers protection ( country based login, antibot )
|
||||
enableProtection: false
|
||||
# Countries allowed to join the server and register, see http://dev.bukkit.org/bukkit-plugins/authme-reloaded/pages/countries-codes/ for countries' codes
|
||||
countries:
|
||||
- US
|
||||
- GB
|
||||
# Countries blacklisted automatically ( without any needed to enable protection )
|
||||
countriesBlacklist:
|
||||
- A1
|
||||
# Do we need to enable automatic antibot system?
|
||||
enableAntiBot: false
|
||||
# Max number of player allowed to login in 5 secs before enable AntiBot system automatically
|
||||
antiBotSensibility: 5
|
||||
# Duration in minutes of the antibot automatic system
|
||||
antiBotDuration: 10
|
||||
VeryGames:
|
||||
# These features are only available on VeryGames Server Provider
|
||||
enableIpCheck: false
|
199
samples/NewPlugin.yml
Normal file
199
samples/NewPlugin.yml
Normal file
@ -0,0 +1,199 @@
|
||||
name: ${pluginName}
|
||||
authors: [${pluginAuthors}]
|
||||
website: ${project.url}
|
||||
description: ${project.description}
|
||||
main: ${mainClass}
|
||||
version: ${project.version}-b${buildNumber}
|
||||
softdepend:
|
||||
- Vault
|
||||
- PermissionsBukkit
|
||||
- PermissionsEX
|
||||
- EssentialsGroupManager
|
||||
- Multiverse-Core
|
||||
- Essentials
|
||||
- EssentialsSpawn
|
||||
- ProtocolLib
|
||||
commands:
|
||||
authme:
|
||||
description: AuthMe admin commands
|
||||
usage: '/authme reload|register playername password|changepassword playername password|unregister playername|version|converter datatype'
|
||||
permission: authme.admin
|
||||
register:
|
||||
description: Register an account
|
||||
usage: /register password confirmpassword
|
||||
aliases: [reg]
|
||||
permission: authme.player.register
|
||||
login:
|
||||
description: Login into a account
|
||||
usage: /login password
|
||||
aliases: [l,log]
|
||||
permission: authme.player.login
|
||||
changepassword:
|
||||
description: Change password of a account
|
||||
usage: /changepassword oldPassword newPassword
|
||||
permission: authme.player.changepassword
|
||||
logout:
|
||||
description: Logout from the server
|
||||
usage: /logout
|
||||
permission: authme.player.logout
|
||||
unregister:
|
||||
description: unregister your account
|
||||
usage: /unregister password
|
||||
permission: authme.player.unregister
|
||||
email:
|
||||
description: Add Email or recover password
|
||||
usage: '/email add your@email.com your@email.com|change oldEmail newEmail|recovery your@email.com'
|
||||
permission: authme.player.email
|
||||
captcha:
|
||||
description: Captcha command
|
||||
usage: /captcha theCaptcha
|
||||
permission: authme.player.captcha
|
||||
permissions:
|
||||
authme.canbeforced:
|
||||
description: Allow the user to be forced-logged via API
|
||||
default: true
|
||||
authme.player:
|
||||
description: Gives access to all authme player commands
|
||||
default: true
|
||||
children:
|
||||
authme.player.login: true
|
||||
authme.player.logout: true
|
||||
authme.player.register: true
|
||||
authme.player.unregister: true
|
||||
authme.player.changepassword: true
|
||||
authme.player.captcha: true
|
||||
authme.player.email: true
|
||||
authme.player.register:
|
||||
description: Register your account
|
||||
default: false
|
||||
authme.player.unregister:
|
||||
description: Unregister your account
|
||||
default: false
|
||||
authme.player.login:
|
||||
description: Login into your account
|
||||
default: false
|
||||
authme.player.logout:
|
||||
description: Logout from your account
|
||||
default: false
|
||||
authme.player.changepassword:
|
||||
description: Change password of your account
|
||||
default: false
|
||||
authme.player.email:
|
||||
description: Gives access to player's email commands
|
||||
default: false
|
||||
children:
|
||||
authme.player.email.add: true
|
||||
authme.player.email.change: true
|
||||
authme.player.email.recover: true
|
||||
authme.player.email.add:
|
||||
description: Add an email to your account
|
||||
default: false
|
||||
authme.player.email.change:
|
||||
description: Change email of your account
|
||||
default: false
|
||||
authme.player.email.recover:
|
||||
description: Recover your account
|
||||
default: false
|
||||
authme.player.captcha:
|
||||
description: Captcha command
|
||||
default: false
|
||||
authme.admin:
|
||||
description: Gives access to all authme admin commands
|
||||
default: op
|
||||
children:
|
||||
authme.admin.forcelogin: true
|
||||
authme.admin.forcelogout: true
|
||||
authme.admin.register: true
|
||||
authme.admin.unregister: true
|
||||
authme.admin.changemail: true
|
||||
authme.admin.changepassword: true
|
||||
authme.admin.lastlogin: true
|
||||
authme.admin.accounts: true
|
||||
authme.admin.getemail: true
|
||||
authme.admin.getip: true
|
||||
authme.admin.setspawn: true
|
||||
authme.admin.spawn: true
|
||||
authme.admin.setfirstspawn: true
|
||||
authme.admin.firstspawn: true
|
||||
authme.admin.purge: true
|
||||
authme.admin.purgebannedplayers: true
|
||||
authme.admin.purgelastpos: true
|
||||
authme.admin.converter: true
|
||||
authme.admin.reload: true
|
||||
authme.admin.switchantibot: true
|
||||
authme.admin.seeotheraccounts: true
|
||||
authme.admin.register:
|
||||
description: Register an account
|
||||
default: false
|
||||
authme.admin.unregister:
|
||||
description: Unregister an account
|
||||
default: false
|
||||
authme.admin.forcelogin:
|
||||
description: Force login for that player
|
||||
default: false
|
||||
authme.admin.forcelogout:
|
||||
description: Force logout for that player
|
||||
default: false
|
||||
authme.admin.changepassword:
|
||||
description: Change the password of an account
|
||||
default: false
|
||||
authme.admin.getemail:
|
||||
description: Get last email about a player
|
||||
default: false
|
||||
authme.admin.changeemail:
|
||||
description: Change a player email
|
||||
default: false
|
||||
authme.admin.accounts:
|
||||
description: Display Players Accounts
|
||||
default: false
|
||||
authme.admin.seeotheraccounts:
|
||||
description: Display other accounts about a player when he logs in
|
||||
default: false
|
||||
authme.admin.lastlogin:
|
||||
description: Get last login date about a player
|
||||
default: false
|
||||
authme.admin.getip:
|
||||
description: Get IP from a player (fake and real)
|
||||
default: false
|
||||
authme.admin.setspawn:
|
||||
description: Set the AuthMe spawn point
|
||||
default: false
|
||||
authme.admin.spawn:
|
||||
description: Teleport to AuthMe spawn point
|
||||
default: false
|
||||
authme.admin.setfirstspawn:
|
||||
description: Set the AuthMe First Spawn Point
|
||||
default: false
|
||||
authme.admin.firstspawn:
|
||||
description: Teleport to AuthMe First Spawn Point
|
||||
default: false
|
||||
authme.admin.switchantibot:
|
||||
description: Switch AntiBot mode on/off
|
||||
default: false
|
||||
authme.admin.purge:
|
||||
description: Database purge command
|
||||
default: false
|
||||
authme.admin.purgebannedplayers:
|
||||
description: Purge banned players
|
||||
default: false
|
||||
authme.admin.purgelastpos:
|
||||
description: Purge last position of a player/players
|
||||
default: false
|
||||
authme.admin.converter:
|
||||
description: Allow the /authme converter command
|
||||
default: false
|
||||
authme.admin.reload:
|
||||
description: Reload the plugin
|
||||
default: false
|
||||
authme.vip:
|
||||
description: Allow vip slot when the server is full
|
||||
default: false
|
||||
authme.bypassantibot:
|
||||
description: Bypass the AntiBot check
|
||||
default: false
|
||||
authme.allowmultipleaccounts:
|
||||
description: Allow more accounts for same ip
|
||||
default: false
|
||||
authme.bypassforcesurvival:
|
||||
description: Bypass all ForceSurvival features
|
||||
default: false
|
45798
samples/databases/xenforo.sql
Normal file
45798
samples/databases/xenforo.sql
Normal file
File diff suppressed because one or more lines are too long
86
samples/website_integration/bcrypt/form.php
Normal file
86
samples/website_integration/bcrypt/form.php
Normal file
@ -0,0 +1,86 @@
|
||||
<!--
|
||||
This is a demo page for AuthMe website integration with BCrypt.
|
||||
See integration.php for the PHP code you need.
|
||||
-->
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<title>AuthMe Integration Sample</title>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
</head>
|
||||
<body>
|
||||
<?php
|
||||
error_reporting(E_ALL);
|
||||
|
||||
$action = get_from_post_or_empty('action');
|
||||
$user = get_from_post_or_empty('username');
|
||||
$pass = get_from_post_or_empty('password');
|
||||
|
||||
$was_successful = false;
|
||||
if ($action && $user && $pass) {
|
||||
require_once('integration.php');
|
||||
if ($action === 'Log in') {
|
||||
$was_successful = process_login($user, $pass);
|
||||
} else if ($action === 'Register') {
|
||||
$was_successful = process_register($user, $pass);
|
||||
}
|
||||
}
|
||||
|
||||
if (!$was_successful) {
|
||||
echo '<h1>Login sample</h1>
|
||||
This is a demo form for AuthMe website integration. Enter your AuthMe login details
|
||||
into the following form to test it.
|
||||
<form method="post">
|
||||
<table>
|
||||
<tr><td>Name</td><td><input type="text" value="' . htmlspecialchars($user) . '" name="username" /></td></tr>
|
||||
<tr><td>Pass</td><td><input type="password" value="' . htmlspecialchars($pass) . '" name="password" /></td></tr>
|
||||
<tr>
|
||||
<td><input type="submit" name="action" value="Log in" /></td>
|
||||
<td><input type="submit" name="action" value="Register" /></td>
|
||||
</tr>
|
||||
</table>
|
||||
</form>';
|
||||
}
|
||||
|
||||
function get_from_post_or_empty($index_name) {
|
||||
return trim(
|
||||
filter_input(INPUT_POST, $index_name, FILTER_UNSAFE_RAW, FILTER_REQUIRE_SCALAR | FILTER_FLAG_STRIP_LOW)
|
||||
?: '');
|
||||
}
|
||||
|
||||
|
||||
// Login logic
|
||||
function process_login($user, $pass) {
|
||||
if (authme_check_password($user, $pass)) {
|
||||
printf('<h1>Hello, %s!</h1>', htmlspecialchars($user));
|
||||
echo 'Successful login. Nice to have you back!'
|
||||
. '<br /><a href="form.php">Back to form</a>';
|
||||
return true;
|
||||
} else {
|
||||
echo '<h1>Error</h1> Invalid username or password.';
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Register logic
|
||||
function process_register($user, $pass) {
|
||||
if (authme_has_user($user)) {
|
||||
echo '<h1>Error</h1> This user already exists.';
|
||||
} else {
|
||||
// Note that we don't validate the password or username at all in this demo...
|
||||
$register_success = authme_register($user, $pass);
|
||||
if ($register_success) {
|
||||
printf('<h1>Welcome, %s!</h1>Thanks for registering', htmlspecialchars($user));
|
||||
echo '<br /><a href="form.php">Back to form</a>';
|
||||
return true;
|
||||
} else {
|
||||
echo '<h1>Error</h1>Unfortunately, there was an error during the registration.';
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
</body>
|
||||
</html>
|
107
samples/website_integration/bcrypt/integration.php
Normal file
107
samples/website_integration/bcrypt/integration.php
Normal file
@ -0,0 +1,107 @@
|
||||
<?php
|
||||
/*****************************************************************************
|
||||
* AuthMe website integration logic for BCrypt *
|
||||
* -------------------------------- *
|
||||
* Check with authme_check_password() whether the received username and *
|
||||
* password match the AuthMe MySQL database. Don't forget to adjust the *
|
||||
* database info in authme_get_hash(). *
|
||||
* *
|
||||
* Source: https://github.com/AuthMe-Team/AuthMeReloaded/ *
|
||||
*****************************************************************************/
|
||||
|
||||
/** The name of the authme MySQL table. */
|
||||
define('AUTHME_TABLE', 'authme');
|
||||
|
||||
|
||||
/**
|
||||
* Entry point function to check supplied credentials against the AuthMe database.
|
||||
*
|
||||
* @param string $username the username
|
||||
* @param string $password the password
|
||||
* @return bool true iff the data is correct, false otherwise
|
||||
*/
|
||||
function authme_check_password($username, $password) {
|
||||
if (is_scalar($username) && is_scalar($password)) {
|
||||
$hash = authme_get_hash($username);
|
||||
if ($hash) {
|
||||
return password_verify($password, $hash);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a connection to the database.
|
||||
*
|
||||
* @return mysqli|null the mysqli object or null upon error
|
||||
*/
|
||||
function authme_get_mysqli() {
|
||||
$mysqli = new mysqli('localhost', 'root', '', 'authme');
|
||||
if (mysqli_connect_error()) {
|
||||
printf('Could not connect to AuthMe database. Errno: %d, error: "%s"',
|
||||
mysqli_connect_errno(), mysqli_connect_error());
|
||||
return null;
|
||||
}
|
||||
return $mysqli;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the hash associated with the given user from the database.
|
||||
*
|
||||
* @param string $username the username whose hash should be retrieved
|
||||
* @return string|null the hash, or null if unavailable (e.g. username doesn't exist)
|
||||
*/
|
||||
function authme_get_hash($username) {
|
||||
// Add here your database host, username, password and database name
|
||||
$mysqli = authme_get_mysqli();
|
||||
if ($mysqli !== null) {
|
||||
$stmt = $mysqli->prepare('SELECT password FROM ' . AUTHME_TABLE . ' WHERE username = ?');
|
||||
$stmt->bind_param('s', $username);
|
||||
$stmt->execute();
|
||||
$stmt->bind_result($password);
|
||||
if ($stmt->fetch()) {
|
||||
return $password;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the user exists in the database or not.
|
||||
*
|
||||
* @param string $username the username to check
|
||||
* @return bool true if the user exists; false otherwise
|
||||
*/
|
||||
function authme_has_user($username) {
|
||||
$mysqli = authme_get_mysqli();
|
||||
if ($mysqli !== null) {
|
||||
$stmt = $mysqli->prepare('SELECT 1 FROM ' . AUTHME_TABLE . ' WHERE username = ?');
|
||||
$stmt->bind_param('s', $username);
|
||||
$stmt->execute();
|
||||
return $stmt->fetch();
|
||||
}
|
||||
|
||||
// Defensive default to true; we actually don't know
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a player with the given username.
|
||||
*
|
||||
* @param string $username the username to register
|
||||
* @param string $password the password to associate to the user
|
||||
* @return bool whether or not the registration was successful
|
||||
*/
|
||||
function authme_register($username, $password) {
|
||||
$mysqli = authme_get_mysqli();
|
||||
if ($mysqli !== null) {
|
||||
$hash = password_hash($password, PASSWORD_BCRYPT);
|
||||
$stmt = $mysqli->prepare('INSERT INTO ' . AUTHME_TABLE . ' (username, realname, password, ip) '
|
||||
. 'VALUES (?, ?, ?, ?)');
|
||||
$username_low = strtolower($username);
|
||||
$stmt->bind_param('ssss', $username, $username_low, $hash, $_SERVER['REMOTE_ADDR']);
|
||||
return $stmt->execute();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
52
samples/website_integration/sha256/form.php
Normal file
52
samples/website_integration/sha256/form.php
Normal file
@ -0,0 +1,52 @@
|
||||
<!--
|
||||
This is a demo page for AuthMe website integration with SHA256.
|
||||
See integration.php for the PHP code you need.
|
||||
-->
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<title>AuthMe Integration Sample</title>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
</head>
|
||||
<body>
|
||||
<?php
|
||||
error_reporting(E_ALL);
|
||||
|
||||
$user = get_from_post_or_empty('username');
|
||||
$pass = get_from_post_or_empty('password');
|
||||
|
||||
$was_successful = false;
|
||||
if ($user && $pass) {
|
||||
require_once('integration.php');
|
||||
if (authme_check_password($user, $pass)) {
|
||||
printf('<h1>Hello, %s!</h1>', htmlspecialchars($user));
|
||||
echo 'Successful login. Nice to have you back!'
|
||||
. '<br /><a href="form.php">Back to form</a>';
|
||||
$was_successful = true;
|
||||
} else {
|
||||
echo '<h1>Error</h1> Invalid username or password.';
|
||||
}
|
||||
}
|
||||
|
||||
if (!$was_successful) {
|
||||
echo '<h1>Login sample</h1>
|
||||
This is a demo form for AuthMe website integration. Enter your AuthMe login details
|
||||
into the following form to test it.
|
||||
<form method="post">
|
||||
<table>
|
||||
<tr><td>Name</td><td><input type="text" value="' . htmlspecialchars($user) . '" name="username" /></td></tr>
|
||||
<tr><td>Pass</td><td><input type="password" value="' . htmlspecialchars($pass) . '" name="password" /></td></tr>
|
||||
<tr><td colspan="2"><input type="submit" value=" Log in " /></td></tr>
|
||||
</table>
|
||||
</form>';
|
||||
}
|
||||
|
||||
function get_from_post_or_empty($index_name) {
|
||||
return trim(
|
||||
filter_input(INPUT_POST, $index_name, FILTER_UNSAFE_RAW, FILTER_REQUIRE_SCALAR | FILTER_FLAG_STRIP_LOW)
|
||||
?: '');
|
||||
}
|
||||
?>
|
||||
|
||||
</body>
|
||||
</html>
|
67
samples/website_integration/sha256/integration.php
Normal file
67
samples/website_integration/sha256/integration.php
Normal file
@ -0,0 +1,67 @@
|
||||
<?php
|
||||
/*****************************************************************************
|
||||
* AuthMe website integration logic for SHA256 *
|
||||
* -------------------------------- *
|
||||
* Check with authme_check_password() whether the received username and *
|
||||
* password match the AuthMe MySQL database. Don't forget to adjust the *
|
||||
* database info in authme_get_hash(). *
|
||||
* *
|
||||
* Source: https://github.com/AuthMe-Team/AuthMeReloaded/ *
|
||||
*****************************************************************************/
|
||||
|
||||
/**
|
||||
* Entry point function to check supplied credentials against the AuthMe database.
|
||||
*
|
||||
* @param string $username the username
|
||||
* @param string $password the password
|
||||
* @return bool true iff the data is correct, false otherwise
|
||||
*/
|
||||
function authme_check_password($username, $password) {
|
||||
if (is_scalar($username) && is_scalar($password)) {
|
||||
$hash = authme_get_hash($username);
|
||||
if ($hash) {
|
||||
return authme_check_hash($password, $hash);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the hash associated with the given user from the database.
|
||||
*
|
||||
* @param string $username the username whose hash should be retrieved
|
||||
* @return string|null the hash, or null if unavailable (e.g. username doesn't exist)
|
||||
*/
|
||||
function authme_get_hash($username) {
|
||||
// Add here your database host, username, password and database name
|
||||
$mysqli = new mysqli('HOST', 'USER', 'PWD', 'DB');
|
||||
$authme_table = 'authme';
|
||||
|
||||
if (mysqli_connect_error()) {
|
||||
printf('Could not connect to AuthMe database. Errno: %d, error: "%s"',
|
||||
mysqli_connect_errno(), mysqli_connect_error());
|
||||
} else {
|
||||
$stmt = $mysqli->prepare("SELECT password FROM $authme_table WHERE username = ?");
|
||||
$stmt->bind_param('s', $username);
|
||||
$stmt->execute();
|
||||
$stmt->bind_result($password);
|
||||
if ($stmt->fetch()) {
|
||||
return $password;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the given clear-text password against the hash.
|
||||
*
|
||||
* @param string $password the clear-text password to check
|
||||
* @param string $hash the hash to check the password against
|
||||
* @return bool true iff the password matches the hash, false otherwise
|
||||
*/
|
||||
function authme_check_hash($password, $hash) {
|
||||
// $SHA$salt$hash, where hash := sha256(sha256(password) . salt)
|
||||
$parts = explode('$', $hash);
|
||||
return count($parts) === 4
|
||||
&& $parts[3] === hash('sha256', hash('sha256', $password) . $parts[2]);
|
||||
}
|
@ -1,8 +1,8 @@
|
||||
package fr.xephi.authme;
|
||||
|
||||
import fr.xephi.authme.permission.PlayerPermission;
|
||||
import fr.xephi.authme.output.MessageKey;
|
||||
import fr.xephi.authme.output.Messages;
|
||||
import fr.xephi.authme.permission.PlayerStatePermission;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.util.Wrapper;
|
||||
import org.bukkit.Bukkit;
|
||||
@ -73,7 +73,7 @@ public class AntiBot {
|
||||
if (antiBotStatus == AntiBotStatus.ACTIVE || antiBotStatus == AntiBotStatus.DISABLED) {
|
||||
return;
|
||||
}
|
||||
if (plugin.getPermissionsManager().hasPermission(player, PlayerPermission.BYPASS_ANTIBOT)) {
|
||||
if (plugin.getPermissionsManager().hasPermission(player, PlayerStatePermission.BYPASS_ANTIBOT)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,8 @@
|
||||
package fr.xephi.authme;
|
||||
|
||||
import com.earth2me.essentials.Essentials;
|
||||
import com.google.common.base.Charsets;
|
||||
import com.google.common.io.Resources;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import fr.xephi.authme.api.API;
|
||||
import fr.xephi.authme.api.NewAPI;
|
||||
@ -9,27 +11,54 @@ import fr.xephi.authme.cache.auth.PlayerCache;
|
||||
import fr.xephi.authme.cache.backup.JsonCache;
|
||||
import fr.xephi.authme.cache.limbo.LimboCache;
|
||||
import fr.xephi.authme.cache.limbo.LimboPlayer;
|
||||
import fr.xephi.authme.command.CommandDescription;
|
||||
import fr.xephi.authme.command.CommandHandler;
|
||||
import fr.xephi.authme.command.CommandInitializer;
|
||||
import fr.xephi.authme.converter.Converter;
|
||||
import fr.xephi.authme.converter.ForceFlatToSqlite;
|
||||
import fr.xephi.authme.datasource.*;
|
||||
import fr.xephi.authme.command.CommandMapper;
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.command.help.HelpProvider;
|
||||
import fr.xephi.authme.datasource.CacheDataSource;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
import fr.xephi.authme.datasource.DataSourceType;
|
||||
import fr.xephi.authme.datasource.FlatFile;
|
||||
import fr.xephi.authme.datasource.MySQL;
|
||||
import fr.xephi.authme.datasource.SQLite;
|
||||
import fr.xephi.authme.hooks.BungeeCordMessage;
|
||||
import fr.xephi.authme.hooks.EssSpawn;
|
||||
import fr.xephi.authme.listener.*;
|
||||
import fr.xephi.authme.modules.ModuleManager;
|
||||
import fr.xephi.authme.listener.AuthMeBlockListener;
|
||||
import fr.xephi.authme.listener.AuthMeEntityListener;
|
||||
import fr.xephi.authme.listener.AuthMeInventoryPacketAdapter;
|
||||
import fr.xephi.authme.listener.AuthMePlayerListener;
|
||||
import fr.xephi.authme.listener.AuthMePlayerListener16;
|
||||
import fr.xephi.authme.listener.AuthMePlayerListener18;
|
||||
import fr.xephi.authme.listener.AuthMeServerListener;
|
||||
import fr.xephi.authme.listener.AuthMeTabCompletePacketAdapter;
|
||||
import fr.xephi.authme.listener.AuthMeTablistPacketAdapter;
|
||||
import fr.xephi.authme.mail.SendMailSSL;
|
||||
import fr.xephi.authme.output.ConsoleFilter;
|
||||
import fr.xephi.authme.output.Log4JFilter;
|
||||
import fr.xephi.authme.output.MessageKey;
|
||||
import fr.xephi.authme.output.Messages;
|
||||
import fr.xephi.authme.permission.PermissionsManager;
|
||||
import fr.xephi.authme.permission.PlayerPermission;
|
||||
import fr.xephi.authme.permission.PlayerStatePermission;
|
||||
import fr.xephi.authme.process.Management;
|
||||
import fr.xephi.authme.settings.*;
|
||||
import fr.xephi.authme.security.PasswordSecurity;
|
||||
import fr.xephi.authme.security.crypts.SHA256;
|
||||
import fr.xephi.authme.settings.NewSetting;
|
||||
import fr.xephi.authme.settings.OtherAccounts;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.settings.SettingsMigrationService;
|
||||
import fr.xephi.authme.settings.Spawn;
|
||||
import fr.xephi.authme.settings.properties.DatabaseSettings;
|
||||
import fr.xephi.authme.settings.properties.HooksSettings;
|
||||
import fr.xephi.authme.settings.properties.PluginSettings;
|
||||
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
||||
import fr.xephi.authme.settings.properties.SecuritySettings;
|
||||
import fr.xephi.authme.util.CollectionUtils;
|
||||
import fr.xephi.authme.util.GeoLiteAPI;
|
||||
import fr.xephi.authme.util.MigrationService;
|
||||
import fr.xephi.authme.util.StringUtils;
|
||||
import fr.xephi.authme.util.Utils;
|
||||
import fr.xephi.authme.util.Wrapper;
|
||||
import net.minelink.ctplus.CombatTagPlus;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.bukkit.Bukkit;
|
||||
@ -42,72 +71,80 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
import org.mcstats.Metrics;
|
||||
import org.mcstats.Metrics.Graph;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Calendar;
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import static fr.xephi.authme.settings.properties.EmailSettings.MAIL_ACCOUNT;
|
||||
import static fr.xephi.authme.settings.properties.EmailSettings.MAIL_PASSWORD;
|
||||
import static fr.xephi.authme.settings.properties.EmailSettings.RECALL_PLAYERS;
|
||||
import static fr.xephi.authme.settings.properties.PluginSettings.HELP_HEADER;
|
||||
|
||||
/**
|
||||
* The AuthMe main class.
|
||||
*/
|
||||
public class AuthMe extends JavaPlugin {
|
||||
|
||||
/**
|
||||
* Defines the name of the plugin.
|
||||
*/
|
||||
// Defines the name of the plugin.
|
||||
private static final String PLUGIN_NAME = "AuthMeReloaded";
|
||||
|
||||
// Default version and build number values;
|
||||
private static String pluginVersion = "N/D";
|
||||
private static String pluginBuildNumber = "Unknown";
|
||||
|
||||
// Private Instances
|
||||
private static AuthMe plugin;
|
||||
private static Server server;
|
||||
private static Wrapper wrapper = Wrapper.getInstance();
|
||||
|
||||
private Management management;
|
||||
private CommandHandler commandHandler = null;
|
||||
private PermissionsManager permsMan = null;
|
||||
private NewSetting newSettings;
|
||||
private Messages messages;
|
||||
private JsonCache playerBackup;
|
||||
private PasswordSecurity passwordSecurity;
|
||||
private DataSource database;
|
||||
|
||||
/*
|
||||
* Public Instances
|
||||
* TODO #432: Encapsulation
|
||||
*/
|
||||
public NewAPI api;
|
||||
public SendMailSSL mail;
|
||||
public DataManager dataManager;
|
||||
public DataSource database;
|
||||
public OtherAccounts otherAccounts;
|
||||
public Location essentialsSpawn;
|
||||
|
||||
// Hooks TODO: Move into modules
|
||||
/*
|
||||
* Plugin Hooks
|
||||
* TODO: Move into modules
|
||||
*/
|
||||
public Essentials ess;
|
||||
public MultiverseCore multiverse;
|
||||
public CombatTagPlus combatTagPlus;
|
||||
public AuthMeInventoryPacketAdapter inventoryProtector;
|
||||
public AuthMeTabCompletePacketAdapter tabComplete;
|
||||
public AuthMeTablistPacketAdapter tablistHider;
|
||||
|
||||
// Data maps and stuff
|
||||
// TODO: Move into a manager
|
||||
/*
|
||||
* Maps and stuff
|
||||
* TODO: Clean up and Move into a manager
|
||||
*/
|
||||
public final ConcurrentHashMap<String, BukkitTask> sessions = new ConcurrentHashMap<>();
|
||||
public final ConcurrentHashMap<String, Integer> captcha = new ConcurrentHashMap<>();
|
||||
public final ConcurrentHashMap<String, String> cap = new ConcurrentHashMap<>();
|
||||
public final ConcurrentHashMap<String, String> realIp = new ConcurrentHashMap<>();
|
||||
|
||||
// If cache is enabled, prevent any connection before the players data caching is completed.
|
||||
// TODO: Move somewhere
|
||||
private boolean canConnect = true;
|
||||
|
||||
private CommandHandler commandHandler = null;
|
||||
private PermissionsManager permsMan = null;
|
||||
private Settings settings;
|
||||
private Messages messages;
|
||||
private JsonCache playerBackup;
|
||||
private ModuleManager moduleManager;
|
||||
|
||||
/**
|
||||
* Returns the plugin's instance.
|
||||
* Get the plugin's instance.
|
||||
*
|
||||
* @return AuthMe
|
||||
*/
|
||||
@ -118,79 +155,50 @@ public class AuthMe extends JavaPlugin {
|
||||
/**
|
||||
* Get the plugin's name.
|
||||
*
|
||||
* @return Plugin name.
|
||||
* @return The plugin's name.
|
||||
*/
|
||||
public static String getPluginName() {
|
||||
return PLUGIN_NAME;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current installed AuthMeReloaded version name.
|
||||
* Get the plugin's version.
|
||||
*
|
||||
* @return The version name of the currently installed AuthMeReloaded instance.
|
||||
* @return The plugin's version.
|
||||
*/
|
||||
public static String getPluginVersion() {
|
||||
return pluginVersion;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current installed AuthMeReloaded version code.
|
||||
* Get the plugin's build number.
|
||||
*
|
||||
* @return The version code of the currently installed AuthMeReloaded instance.
|
||||
* @return The plugin's build number.
|
||||
*/
|
||||
public static String getPluginBuildNumber() {
|
||||
return pluginBuildNumber;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the plugin's Settings.
|
||||
* Get the Messages instance.
|
||||
*
|
||||
* @return Settings
|
||||
* @return Plugin's messages.
|
||||
*/
|
||||
public Settings getSettings() {
|
||||
return settings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Messages instance.
|
||||
*
|
||||
* @return Messages
|
||||
*/
|
||||
|
||||
public Messages getMessages() {
|
||||
return messages;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the Messages instance.
|
||||
* Get the plugin's NewSetting instance.
|
||||
*
|
||||
* @param m Messages
|
||||
* @return NewSetting.
|
||||
*/
|
||||
public void setMessages(Messages m) {
|
||||
this.messages = m;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns if players are allowed to join the server.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public boolean canConnect() {
|
||||
return canConnect;
|
||||
}
|
||||
|
||||
/**
|
||||
* Define if players are allowed to join the server.
|
||||
*
|
||||
* @param canConnect boolean
|
||||
*/
|
||||
public void setCanConnect(boolean canConnect) {
|
||||
this.canConnect = canConnect;
|
||||
public NewSetting getSettings() {
|
||||
return newSettings;
|
||||
}
|
||||
|
||||
// Get version and build number of the plugin
|
||||
// TODO: enhance this
|
||||
private void setupConstants() {
|
||||
private void setPluginInfos() {
|
||||
String versionRaw = this.getDescription().getVersion();
|
||||
int index = versionRaw.lastIndexOf("-");
|
||||
if (index != -1) {
|
||||
@ -204,40 +212,58 @@ public class AuthMe extends JavaPlugin {
|
||||
|
||||
/**
|
||||
* Method called when the server enables the plugin.
|
||||
*
|
||||
* @see org.bukkit.plugin.Plugin#onEnable()
|
||||
*/
|
||||
@Override
|
||||
public void onEnable() {
|
||||
// Set various instances
|
||||
server = getServer();
|
||||
plugin = this;
|
||||
setupConstants();
|
||||
ConsoleLogger.setLogger(getLogger());
|
||||
|
||||
// Set up the permissions manager
|
||||
setupPermissionsManager();
|
||||
|
||||
// Set up and initialize the command handler
|
||||
setupCommandHandler();
|
||||
|
||||
// Set up the module manager
|
||||
setupModuleManager();
|
||||
setPluginInfos();
|
||||
|
||||
// Load settings and custom configurations, if it fails, stop the server due to security reasons.
|
||||
if (loadSettings()) {
|
||||
newSettings = createNewSetting();
|
||||
if (newSettings == null) {
|
||||
ConsoleLogger.showError("Could not load configuration. Aborting.");
|
||||
server.shutdown();
|
||||
return;
|
||||
}
|
||||
ConsoleLogger.setLoggingOptions(newSettings.getProperty(SecuritySettings.USE_LOGGING),
|
||||
new File(getDataFolder(), "authme.log"));
|
||||
|
||||
// Old settings manager
|
||||
if (!loadSettings()) {
|
||||
server.shutdown();
|
||||
setEnabled(false);
|
||||
return;
|
||||
}
|
||||
|
||||
messages = new Messages(newSettings.getMessagesFile(), newSettings.getDefaultMessagesFile());
|
||||
|
||||
// Connect to the database and setup tables
|
||||
try {
|
||||
setupDatabase(newSettings);
|
||||
} catch (Exception e) {
|
||||
ConsoleLogger.logException("Fatal error occurred during database connection! "
|
||||
+ "Authme initialization aborted!", e);
|
||||
stopOrUnload();
|
||||
return;
|
||||
}
|
||||
|
||||
MigrationService.changePlainTextToSha256(newSettings, database, new SHA256());
|
||||
passwordSecurity = new PasswordSecurity(getDataSource(), newSettings.getProperty(SecuritySettings.PASSWORD_HASH),
|
||||
Bukkit.getPluginManager(), newSettings.getProperty(SecuritySettings.SUPPORT_OLD_PASSWORD_HASH));
|
||||
|
||||
// Set up the permissions manager and command handler
|
||||
permsMan = initializePermissionsManager();
|
||||
commandHandler = initializeCommandHandler(permsMan, messages, passwordSecurity, newSettings);
|
||||
|
||||
// Setup otherAccounts file
|
||||
this.otherAccounts = OtherAccounts.getInstance();
|
||||
|
||||
// Setup messages
|
||||
this.messages = Messages.getInstance();
|
||||
|
||||
// Set up Metrics
|
||||
setupMetrics();
|
||||
MetricsStarter.setupMetrics(plugin, newSettings);
|
||||
|
||||
// Set console filter
|
||||
setupConsoleFilter();
|
||||
@ -267,18 +293,8 @@ public class AuthMe extends JavaPlugin {
|
||||
// End of Hooks
|
||||
|
||||
// Do a backup on start
|
||||
new PerformBackup(plugin).doBackup(PerformBackup.BackupCause.START);
|
||||
new PerformBackup(plugin, newSettings).doBackup(PerformBackup.BackupCause.START);
|
||||
|
||||
// Connect to the database and setup tables
|
||||
try {
|
||||
setupDatabase();
|
||||
} catch (Exception e) {
|
||||
ConsoleLogger.writeStackTrace(e);
|
||||
ConsoleLogger.showError(e.getMessage());
|
||||
ConsoleLogger.showError("Fatal error occurred during database connection! Authme initialization ABORTED!");
|
||||
stopOrUnload();
|
||||
return;
|
||||
}
|
||||
|
||||
// Setup the inventory backup
|
||||
playerBackup = new JsonCache();
|
||||
@ -290,7 +306,7 @@ public class AuthMe extends JavaPlugin {
|
||||
setupApi();
|
||||
|
||||
// Set up the management
|
||||
management = new Management(this);
|
||||
management = new Management(this, newSettings);
|
||||
|
||||
// Set up the BungeeCord hook
|
||||
setupBungeeCordHook();
|
||||
@ -305,7 +321,7 @@ public class AuthMe extends JavaPlugin {
|
||||
autoPurge();
|
||||
|
||||
// Start Email recall task if needed
|
||||
recallEmail();
|
||||
scheduleRecallEmailTask();
|
||||
|
||||
// Show settings warnings
|
||||
showSettingsWarnings();
|
||||
@ -319,32 +335,14 @@ public class AuthMe extends JavaPlugin {
|
||||
ConsoleLogger.info("AuthMe " + this.getDescription().getVersion() + " correctly enabled!");
|
||||
}
|
||||
|
||||
/**
|
||||
* Set up the module manager.
|
||||
*/
|
||||
private void setupModuleManager() {
|
||||
// TODO: Clean this up!
|
||||
// TODO: split the plugin in more modules
|
||||
// TODO: log number of loaded modules
|
||||
|
||||
// Define the module manager instance
|
||||
moduleManager = new ModuleManager(this);
|
||||
|
||||
// Load the modules
|
||||
// int loaded = moduleManager.loadModules();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set up the mail API, if enabled.
|
||||
*/
|
||||
private void setupMailApi() {
|
||||
// Make sure the mail API is enabled
|
||||
if (Settings.getmailAccount.isEmpty() || Settings.getmailPassword.isEmpty()) {
|
||||
return;
|
||||
if (!newSettings.getProperty(MAIL_ACCOUNT).isEmpty() && !newSettings.getProperty(MAIL_PASSWORD).isEmpty()) {
|
||||
this.mail = new SendMailSSL(this, newSettings);
|
||||
}
|
||||
|
||||
// Set up the mail API
|
||||
this.mail = new SendMailSSL(this);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -352,12 +350,13 @@ public class AuthMe extends JavaPlugin {
|
||||
*/
|
||||
private void showSettingsWarnings() {
|
||||
// Force single session disabled
|
||||
if (!Settings.isForceSingleSessionEnabled) {
|
||||
if (!newSettings.getProperty(RestrictionSettings.FORCE_SINGLE_SESSION)) {
|
||||
ConsoleLogger.showError("WARNING!!! By disabling ForceSingleSession, your server protection is inadequate!");
|
||||
}
|
||||
|
||||
// Session timeout disabled
|
||||
if (Settings.getSessionTimeout == 0 && Settings.isSessionsEnabled) {
|
||||
if (newSettings.getProperty(PluginSettings.SESSIONS_TIMEOUT) == 0
|
||||
&& newSettings.getProperty(PluginSettings.SESSIONS_ENABLED)) {
|
||||
ConsoleLogger.showError("WARNING!!! You set session timeout to 0, this may cause security issues!");
|
||||
}
|
||||
}
|
||||
@ -371,21 +370,21 @@ public class AuthMe extends JavaPlugin {
|
||||
|
||||
// Register event listeners
|
||||
pluginManager.registerEvents(new AuthMePlayerListener(this), this);
|
||||
pluginManager.registerEvents(new AuthMeBlockListener(this), this);
|
||||
pluginManager.registerEvents(new AuthMeEntityListener(this), this);
|
||||
pluginManager.registerEvents(new AuthMeBlockListener(), this);
|
||||
pluginManager.registerEvents(new AuthMeEntityListener(), this);
|
||||
pluginManager.registerEvents(new AuthMeServerListener(this), this);
|
||||
|
||||
// Try to register 1.6 player listeners
|
||||
try {
|
||||
Class.forName("org.bukkit.event.player.PlayerEditBookEvent");
|
||||
pluginManager.registerEvents(new AuthMePlayerListener16(this), this);
|
||||
pluginManager.registerEvents(new AuthMePlayerListener16(), this);
|
||||
} catch (ClassNotFoundException ignore) {
|
||||
}
|
||||
|
||||
// Try to register 1.8 player listeners
|
||||
try {
|
||||
Class.forName("org.bukkit.event.player.PlayerInteractAtEntityEvent");
|
||||
pluginManager.registerEvents(new AuthMePlayerListener18(this), this);
|
||||
pluginManager.registerEvents(new AuthMePlayerListener18(), this);
|
||||
} catch (ClassNotFoundException ignore) {
|
||||
}
|
||||
}
|
||||
@ -412,12 +411,22 @@ public class AuthMe extends JavaPlugin {
|
||||
* Set up the BungeeCord hook.
|
||||
*/
|
||||
private void setupBungeeCordHook() {
|
||||
if (Settings.bungee) {
|
||||
if (newSettings.getProperty(HooksSettings.BUNGEECORD)) {
|
||||
Bukkit.getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
|
||||
Bukkit.getMessenger().registerIncomingPluginChannel(this, "BungeeCord", new BungeeCordMessage(this));
|
||||
}
|
||||
}
|
||||
|
||||
private CommandHandler initializeCommandHandler(PermissionsManager permissionsManager, Messages messages,
|
||||
PasswordSecurity passwordSecurity, NewSetting settings) {
|
||||
HelpProvider helpProvider = new HelpProvider(permissionsManager, settings.getProperty(HELP_HEADER));
|
||||
Set<CommandDescription> baseCommands = CommandInitializer.buildCommands();
|
||||
CommandMapper mapper = new CommandMapper(baseCommands, permissionsManager);
|
||||
CommandService commandService = new CommandService(
|
||||
this, mapper, helpProvider, messages, passwordSecurity, permissionsManager, settings);
|
||||
return new CommandHandler(commandService);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set up the API. This sets up the new and the old API.
|
||||
*/
|
||||
@ -426,36 +435,34 @@ public class AuthMe extends JavaPlugin {
|
||||
// Set up the API
|
||||
api = new NewAPI(this);
|
||||
|
||||
// Setup the old deprecated API
|
||||
// Set up the deprecated API
|
||||
new API(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set up the command handler.
|
||||
*/
|
||||
private void setupCommandHandler() {
|
||||
this.commandHandler = new CommandHandler(CommandInitializer.getBaseCommands());
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the plugin's settings.
|
||||
*
|
||||
* @return True on success, false on failure.
|
||||
*/
|
||||
private boolean loadSettings() {
|
||||
// TODO: new configuration style (more files)
|
||||
try {
|
||||
settings = new Settings(this);
|
||||
Settings.reload();
|
||||
} catch (Exception e) {
|
||||
ConsoleLogger.writeStackTrace(e);
|
||||
ConsoleLogger.showError("Can't load the configuration file... Something went wrong, to avoid security issues the server will shutdown!");
|
||||
server.shutdown();
|
||||
new Settings(this);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
ConsoleLogger.logException("Can't load the configuration file... Something went wrong. "
|
||||
+ "To avoid security issues the server will shut down!", e);
|
||||
server.shutdown();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private NewSetting createNewSetting() {
|
||||
File configFile = new File(getDataFolder(), "config.yml");
|
||||
return SettingsMigrationService.copyFileFromResource(configFile, "config.yml")
|
||||
? new NewSetting(configFile, getDataFolder())
|
||||
: null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set up the console filter.
|
||||
*/
|
||||
@ -475,65 +482,18 @@ public class AuthMe extends JavaPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set up Metrics.
|
||||
*/
|
||||
private void setupMetrics() {
|
||||
try {
|
||||
Metrics metrics = new Metrics(this);
|
||||
Graph messagesLanguage = metrics.createGraph("Messages language");
|
||||
Graph databaseBackend = metrics.createGraph("Database backend");
|
||||
|
||||
// Custom graphs
|
||||
if (Settings.messageFile.exists()) {
|
||||
messagesLanguage.addPlotter(new Metrics.Plotter(Settings.messagesLanguage) {
|
||||
|
||||
@Override
|
||||
public int getValue() {
|
||||
return 1;
|
||||
}
|
||||
});
|
||||
}
|
||||
databaseBackend.addPlotter(new Metrics.Plotter(Settings.getDataSource.toString()) {
|
||||
|
||||
@Override
|
||||
public int getValue() {
|
||||
return 1;
|
||||
}
|
||||
});
|
||||
|
||||
metrics.start();
|
||||
ConsoleLogger.info("Metrics started successfully!");
|
||||
} catch (Exception e) {
|
||||
// Failed to submit the metrics data
|
||||
ConsoleLogger.writeStackTrace(e);
|
||||
ConsoleLogger.showError("Can't start Metrics! The plugin will work anyway...");
|
||||
}
|
||||
}
|
||||
|
||||
// Show the exception message and stop/unload the server/plugin as defined
|
||||
// in the configuration
|
||||
|
||||
/**
|
||||
* Method onDisable.
|
||||
*
|
||||
* @see org.bukkit.plugin.Plugin#onDisable()
|
||||
*/
|
||||
@Override
|
||||
public void onDisable() {
|
||||
// Save player data
|
||||
Collection<? extends Player> players = Utils.getOnlinePlayers();
|
||||
if (players != null) {
|
||||
for (Player player : players) {
|
||||
this.savePlayer(player);
|
||||
}
|
||||
for (Player player : players) {
|
||||
savePlayer(player);
|
||||
}
|
||||
|
||||
// Do backup on stop if enabled
|
||||
new PerformBackup(plugin).doBackup(PerformBackup.BackupCause.STOP);
|
||||
|
||||
// Unload modules
|
||||
moduleManager.unloadModules();
|
||||
if (newSettings != null) {
|
||||
new PerformBackup(plugin, newSettings).doBackup(PerformBackup.BackupCause.STOP);
|
||||
}
|
||||
|
||||
// Close the database
|
||||
if (database != null) {
|
||||
@ -544,12 +504,10 @@ public class AuthMe extends JavaPlugin {
|
||||
ConsoleLogger.info("AuthMe " + this.getDescription().getVersion() + " disabled!");
|
||||
}
|
||||
|
||||
// Initialize and setup the database
|
||||
|
||||
// Stop/unload the server/plugin as defined in the configuration
|
||||
public void stopOrUnload() {
|
||||
if (Settings.isStopEnabled) {
|
||||
ConsoleLogger.showError("THE SERVER IS GOING TO SHUTDOWN AS DEFINED IN THE CONFIGURATION!");
|
||||
ConsoleLogger.showError("THE SERVER IS GOING TO SHUT DOWN AS DEFINED IN THE CONFIGURATION!");
|
||||
server.shutdown();
|
||||
} else {
|
||||
server.getPluginManager().disablePlugin(AuthMe.getInstance());
|
||||
@ -557,58 +515,61 @@ public class AuthMe extends JavaPlugin {
|
||||
}
|
||||
|
||||
/**
|
||||
* Method setupDatabase.
|
||||
* Sets up the data source.
|
||||
*
|
||||
* @param settings The settings instance
|
||||
* @see AuthMe#database
|
||||
*/
|
||||
public void setupDatabase() throws Exception {
|
||||
if (database != null)
|
||||
database.close();
|
||||
// Backend MYSQL - FILE - SQLITE - SQLITEHIKARI
|
||||
boolean isSQLite = false;
|
||||
switch (Settings.getDataSource) {
|
||||
case FILE:
|
||||
database = new FlatFile();
|
||||
break;
|
||||
case MYSQL:
|
||||
database = new MySQL();
|
||||
break;
|
||||
case SQLITE:
|
||||
database = new SQLite();
|
||||
isSQLite = true;
|
||||
break;
|
||||
public void setupDatabase(NewSetting settings) throws ClassNotFoundException, SQLException {
|
||||
if (this.database != null) {
|
||||
this.database.close();
|
||||
}
|
||||
|
||||
if (isSQLite) {
|
||||
server.getScheduler().runTaskAsynchronously(this, new Runnable() {
|
||||
DataSourceType dataSourceType = settings.getProperty(DatabaseSettings.BACKEND);
|
||||
DataSource dataSource;
|
||||
switch (dataSourceType) {
|
||||
case FILE:
|
||||
dataSource = new FlatFile();
|
||||
break;
|
||||
case MYSQL:
|
||||
dataSource = new MySQL(settings);
|
||||
break;
|
||||
case SQLITE:
|
||||
dataSource = new SQLite(settings);
|
||||
break;
|
||||
default:
|
||||
throw new UnsupportedOperationException("Unknown data source type '" + dataSourceType + "'");
|
||||
}
|
||||
|
||||
DataSource convertedSource = MigrationService.convertFlatfileToSqlite(newSettings, dataSource);
|
||||
dataSource = convertedSource == null ? dataSource : convertedSource;
|
||||
|
||||
if (newSettings.getProperty(DatabaseSettings.USE_CACHING)) {
|
||||
dataSource = new CacheDataSource(dataSource);
|
||||
}
|
||||
|
||||
database = dataSource;
|
||||
if (DataSourceType.SQLITE == dataSourceType) {
|
||||
server.getScheduler().runTaskAsynchronously(this, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
int accounts = database.getAccountsRegistered();
|
||||
if (accounts >= 4000)
|
||||
ConsoleLogger.showError("YOU'RE USING THE SQLITE DATABASE WITH " + accounts + "+ ACCOUNTS, FOR BETTER PERFORMANCES, PLEASE UPGRADE TO MYSQL!!");
|
||||
if (accounts >= 4000) {
|
||||
ConsoleLogger.showError("YOU'RE USING THE SQLITE DATABASE WITH "
|
||||
+ accounts + "+ ACCOUNTS; FOR BETTER PERFORMANCE, PLEASE UPGRADE TO MYSQL!!");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (Settings.isCachingEnabled) {
|
||||
database = new CacheDataSource(this, database);
|
||||
} else {
|
||||
database = new DatabaseCalls(database);
|
||||
}
|
||||
|
||||
if (Settings.getDataSource == DataSource.DataSourceType.FILE) {
|
||||
Converter converter = new ForceFlatToSqlite(database, this);
|
||||
server.getScheduler().runTaskAsynchronously(this, converter);
|
||||
ConsoleLogger.showError("FlatFile backend has been detected and is now deprecated, next time server starts up, it will be changed to SQLite... Conversion will be started Asynchronously, it will not drop down your performance !");
|
||||
ConsoleLogger.showError("If you want to keep FlatFile, set file again into config at backend, but this message and this change will appear again at the next restart");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set up the permissions manager.
|
||||
*/
|
||||
public void setupPermissionsManager() {
|
||||
this.permsMan = new PermissionsManager(Bukkit.getServer(), this, getLogger());
|
||||
this.permsMan.setup();
|
||||
private PermissionsManager initializePermissionsManager() {
|
||||
PermissionsManager manager = new PermissionsManager(Bukkit.getServer(), this, getLogger());
|
||||
manager.setup();
|
||||
return manager;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -688,30 +649,34 @@ public class AuthMe extends JavaPlugin {
|
||||
// Check the presence of the ProtocolLib plugin
|
||||
public void checkProtocolLib() {
|
||||
if (!server.getPluginManager().isPluginEnabled("ProtocolLib")) {
|
||||
if (Settings.protectInventoryBeforeLogInEnabled) {
|
||||
ConsoleLogger.showError("WARNING!!! The protectInventory feature requires ProtocolLib! Disabling it...");
|
||||
if (newSettings.getProperty(RestrictionSettings.PROTECT_INVENTORY_BEFORE_LOGIN)) {
|
||||
ConsoleLogger.showError("WARNING! The protectInventory feature requires ProtocolLib! Disabling it...");
|
||||
Settings.protectInventoryBeforeLogInEnabled = false;
|
||||
getSettings().set("settings.restrictions.ProtectInventoryBeforeLogIn", false);
|
||||
newSettings.setProperty(RestrictionSettings.PROTECT_INVENTORY_BEFORE_LOGIN, false);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (Settings.protectInventoryBeforeLogInEnabled) {
|
||||
if (inventoryProtector == null) {
|
||||
inventoryProtector = new AuthMeInventoryPacketAdapter(this);
|
||||
inventoryProtector.register();
|
||||
}
|
||||
} else {
|
||||
if (inventoryProtector != null) {
|
||||
inventoryProtector.unregister();
|
||||
inventoryProtector = null;
|
||||
}
|
||||
if (newSettings.getProperty(RestrictionSettings.PROTECT_INVENTORY_BEFORE_LOGIN) && inventoryProtector == null) {
|
||||
inventoryProtector = new AuthMeInventoryPacketAdapter(this);
|
||||
inventoryProtector.register();
|
||||
} else if (inventoryProtector != null) {
|
||||
inventoryProtector.unregister();
|
||||
inventoryProtector = null;
|
||||
}
|
||||
if (tabComplete == null && newSettings.getProperty(RestrictionSettings.DENY_TABCOMPLETE_BEFORE_LOGIN)) {
|
||||
tabComplete = new AuthMeTabCompletePacketAdapter(this);
|
||||
tabComplete.register();
|
||||
}
|
||||
if (tablistHider == null && newSettings.getProperty(RestrictionSettings.HIDE_TABLIST_BEFORE_LOGIN)) {
|
||||
tablistHider = new AuthMeTablistPacketAdapter(this);
|
||||
tablistHider.register();
|
||||
}
|
||||
}
|
||||
|
||||
// Save Player Data
|
||||
public void savePlayer(Player player) {
|
||||
if ((Utils.isNPC(player)) || (Utils.isUnrestricted(player))) {
|
||||
private void savePlayer(Player player) {
|
||||
if (Utils.isNPC(player) || Utils.isUnrestricted(player)) {
|
||||
return;
|
||||
}
|
||||
String name = player.getName().toLowerCase();
|
||||
@ -734,19 +699,16 @@ public class AuthMe extends JavaPlugin {
|
||||
}
|
||||
}
|
||||
PlayerCache.getInstance().removePlayer(name);
|
||||
player.saveData();
|
||||
}
|
||||
|
||||
// Select the player to kick when a vip player join the server when full
|
||||
// Select the player to kick when a vip player joins the server when full
|
||||
public Player generateKickPlayer(Collection<? extends Player> collection) {
|
||||
Player player = null;
|
||||
for (Player p : collection) {
|
||||
if (!getPermissionsManager().hasPermission(p, PlayerPermission.IS_VIP)) {
|
||||
player = p;
|
||||
break;
|
||||
for (Player player : collection) {
|
||||
if (!getPermissionsManager().hasPermission(player, PlayerStatePermission.IS_VIP)) {
|
||||
return player;
|
||||
}
|
||||
}
|
||||
return player;
|
||||
return null;
|
||||
}
|
||||
|
||||
// Purge inactive players from the database, as defined in the configuration
|
||||
@ -758,10 +720,7 @@ public class AuthMe extends JavaPlugin {
|
||||
calendar.add(Calendar.DATE, -(Settings.purgeDelay));
|
||||
long until = calendar.getTimeInMillis();
|
||||
List<String> cleared = database.autoPurgeDatabase(until);
|
||||
if (cleared == null) {
|
||||
return;
|
||||
}
|
||||
if (cleared.isEmpty()) {
|
||||
if (CollectionUtils.isEmpty(cleared)) {
|
||||
return;
|
||||
}
|
||||
ConsoleLogger.info("AutoPurging the Database: " + cleared.size() + " accounts removed!");
|
||||
@ -826,31 +785,29 @@ public class AuthMe extends JavaPlugin {
|
||||
|
||||
// Return the AuthMe spawn point
|
||||
private Location getAuthMeSpawn(Player player) {
|
||||
if ((!database.isAuthAvailable(player.getName().toLowerCase()) || !player.hasPlayedBefore()) && (Spawn.getInstance().getFirstSpawn() != null)) {
|
||||
if ((!database.isAuthAvailable(player.getName().toLowerCase()) || !player.hasPlayedBefore())
|
||||
&& (Spawn.getInstance().getFirstSpawn() != null)) {
|
||||
return Spawn.getInstance().getFirstSpawn();
|
||||
}
|
||||
if (Spawn.getInstance().getSpawn() != null) {
|
||||
} else if (Spawn.getInstance().getSpawn() != null) {
|
||||
return Spawn.getInstance().getSpawn();
|
||||
}
|
||||
return player.getWorld().getSpawnLocation();
|
||||
}
|
||||
|
||||
private void recallEmail() {
|
||||
if (!Settings.recallEmail)
|
||||
private void scheduleRecallEmailTask() {
|
||||
if (!newSettings.getProperty(RECALL_PLAYERS)) {
|
||||
return;
|
||||
Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
|
||||
|
||||
}
|
||||
Bukkit.getScheduler().runTaskTimerAsynchronously(this, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
for (Player player : Utils.getOnlinePlayers()) {
|
||||
if (player.isOnline()) {
|
||||
String name = player.getName().toLowerCase();
|
||||
if (database.isAuthAvailable(name))
|
||||
if (PlayerCache.getInstance().isAuthenticated(name)) {
|
||||
String email = database.getAuth(name).getEmail();
|
||||
if (email == null || email.isEmpty() || email.equalsIgnoreCase("your@email.com"))
|
||||
messages.send(player, MessageKey.ADD_EMAIL_MESSAGE);
|
||||
}
|
||||
for (PlayerAuth auth : database.getLoggedPlayers()) {
|
||||
String email = auth.getEmail();
|
||||
if (email == null || email.isEmpty() || email.equalsIgnoreCase("your@email.com")) {
|
||||
Player player = Utils.getPlayer(auth.getRealName());
|
||||
if (player != null) {
|
||||
messages.send(player, MessageKey.ADD_EMAIL_MESSAGE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -858,30 +815,52 @@ public class AuthMe extends JavaPlugin {
|
||||
}
|
||||
|
||||
public String replaceAllInfo(String message, Player player) {
|
||||
int playersOnline = Utils.getOnlinePlayers().size();
|
||||
message = message.replace("&", "\u00a7");
|
||||
message = message.replace("{PLAYER}", player.getName());
|
||||
message = message.replace("{ONLINE}", "" + playersOnline);
|
||||
message = message.replace("{MAXPLAYERS}", "" + server.getMaxPlayers());
|
||||
message = message.replace("{IP}", getIP(player));
|
||||
message = message.replace("{LOGINS}", "" + PlayerCache.getInstance().getLogged());
|
||||
message = message.replace("{WORLD}", player.getWorld().getName());
|
||||
message = message.replace("{SERVER}", server.getServerName());
|
||||
message = message.replace("{VERSION}", server.getBukkitVersion());
|
||||
message = message.replace("{COUNTRY}", GeoLiteAPI.getCountryName(getIP(player)));
|
||||
return message;
|
||||
String playersOnline = Integer.toString(Utils.getOnlinePlayers().size());
|
||||
return message
|
||||
.replace("&", "\u00a7")
|
||||
.replace("{PLAYER}", player.getName())
|
||||
.replace("{ONLINE}", playersOnline)
|
||||
.replace("{MAXPLAYERS}", Integer.toString(server.getMaxPlayers()))
|
||||
.replace("{IP}", getIP(player))
|
||||
.replace("{LOGINS}", Integer.toString(PlayerCache.getInstance().getLogged()))
|
||||
.replace("{WORLD}", player.getWorld().getName())
|
||||
.replace("{SERVER}", server.getServerName())
|
||||
.replace("{VERSION}", server.getBukkitVersion())
|
||||
.replace("{COUNTRY}", GeoLiteAPI.getCountryName(getIP(player)));
|
||||
}
|
||||
|
||||
public String getIP(Player player) {
|
||||
String name = player.getName().toLowerCase();
|
||||
String ip = player.getAddress().getAddress().getHostAddress();
|
||||
if (Settings.bungee) {
|
||||
if (realIp.containsKey(name))
|
||||
ip = realIp.get(name);
|
||||
/**
|
||||
* Gets a player's real IP through VeryGames method.
|
||||
*
|
||||
* @param player The player to process.
|
||||
*/
|
||||
@Deprecated
|
||||
public void getVerygamesIp(final Player player) {
|
||||
final String name = player.getName().toLowerCase();
|
||||
String currentIp = player.getAddress().getAddress().getHostAddress();
|
||||
if (realIp.containsKey(name)) {
|
||||
currentIp = realIp.get(name);
|
||||
}
|
||||
String sUrl = "http://monitor-1.verygames.net/api/?action=ipclean-real-ip&out=raw&ip=%IP%&port=%PORT%";
|
||||
sUrl = sUrl.replace("%IP%", currentIp).replace("%PORT%", "" + player.getAddress().getPort());
|
||||
try {
|
||||
String result = Resources.toString(new URL(sUrl), Charsets.UTF_8);
|
||||
if (!StringUtils.isEmpty(result) && !result.equalsIgnoreCase("error") && !result.contains("error")) {
|
||||
currentIp = result;
|
||||
realIp.put(name, currentIp);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
ConsoleLogger.showError("Could not fetch Very Games API with URL '" +
|
||||
sUrl + "' - " + StringUtils.formatException(e));
|
||||
}
|
||||
}
|
||||
|
||||
public String getIP(final Player player) {
|
||||
final String name = player.getName().toLowerCase();
|
||||
String ip = player.getAddress().getAddress().getHostAddress();
|
||||
if (realIp.containsKey(name)) {
|
||||
ip = realIp.get(name);
|
||||
}
|
||||
if (Settings.checkVeryGames)
|
||||
if (getVeryGamesIp(player) != null)
|
||||
ip = getVeryGamesIp(player);
|
||||
return ip;
|
||||
}
|
||||
|
||||
@ -903,47 +882,6 @@ public class AuthMe extends JavaPlugin {
|
||||
return count >= Settings.getMaxJoinPerIp;
|
||||
}
|
||||
|
||||
public ModuleManager getModuleManager() {
|
||||
return moduleManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a player's real IP through VeryGames method.
|
||||
*
|
||||
* @param player The player to process.
|
||||
*
|
||||
* @return The real IP of the player.
|
||||
*/
|
||||
// TODO: Cache the result or run it async, it can cause trouble if verygames server isn't responding.
|
||||
@Deprecated
|
||||
public String getVeryGamesIp(Player player) {
|
||||
String realIP = player.getAddress().getAddress().getHostAddress();
|
||||
String sUrl = "http://monitor-1.verygames.net/api/?action=ipclean-real-ip&out=raw&ip=%IP%&port=%PORT%";
|
||||
sUrl = sUrl.replace("%IP%", player.getAddress().getAddress().getHostAddress())
|
||||
.replace("%PORT%", "" + player.getAddress().getPort());
|
||||
try {
|
||||
URL url = new URL(sUrl);
|
||||
URLConnection urlCon = url.openConnection();
|
||||
try (BufferedReader in = new BufferedReader(new InputStreamReader(urlCon.getInputStream()))) {
|
||||
String inputLine = in.readLine();
|
||||
if (!StringUtils.isEmpty(inputLine) && !inputLine.equalsIgnoreCase("error")
|
||||
&& !inputLine.contains("error")) {
|
||||
realIP = inputLine;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
ConsoleLogger.showError("Could not read from Very Games API - " + StringUtils.formatException(e));
|
||||
}
|
||||
} catch (IOException e) {
|
||||
ConsoleLogger.showError("Could not fetch Very Games API with URL '" + sUrl + "' - "
|
||||
+ StringUtils.formatException(e));
|
||||
}
|
||||
return realIP;
|
||||
}
|
||||
|
||||
public CommandHandler getCommandHandler() {
|
||||
return this.commandHandler;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle Bukkit commands.
|
||||
*
|
||||
@ -959,7 +897,7 @@ public class AuthMe extends JavaPlugin {
|
||||
String commandLabel, String[] args) {
|
||||
// Make sure the command handler has been initialized
|
||||
if (commandHandler == null) {
|
||||
wrapper.getLogger().severe("AuthMe command handler is not available");
|
||||
getLogger().severe("AuthMe command handler is not available");
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -969,9 +907,19 @@ public class AuthMe extends JavaPlugin {
|
||||
|
||||
/**
|
||||
* Return the management instance.
|
||||
*
|
||||
* @return management The Management
|
||||
*/
|
||||
public Management getManagement() {
|
||||
return management;
|
||||
}
|
||||
|
||||
public DataSource getDataSource() {
|
||||
return database;
|
||||
}
|
||||
|
||||
public PasswordSecurity getPasswordSecurity() {
|
||||
return passwordSecurity;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,15 +1,16 @@
|
||||
package fr.xephi.authme;
|
||||
|
||||
import com.google.common.base.Throwables;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.util.Wrapper;
|
||||
import fr.xephi.authme.util.StringUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.StandardOpenOption;
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* The plugin's static logger.
|
||||
@ -18,24 +19,33 @@ public final class ConsoleLogger {
|
||||
|
||||
private static final String NEW_LINE = System.getProperty("line.separator");
|
||||
private static final DateFormat DATE_FORMAT = new SimpleDateFormat("[MM-dd HH:mm:ss]");
|
||||
|
||||
private static Wrapper wrapper = Wrapper.getInstance();
|
||||
private static Logger logger;
|
||||
private static boolean useLogging = false;
|
||||
private static File logFile;
|
||||
|
||||
private ConsoleLogger() {
|
||||
// Service class
|
||||
}
|
||||
|
||||
public static void setLogger(Logger logger) {
|
||||
ConsoleLogger.logger = logger;
|
||||
}
|
||||
|
||||
public static void setLoggingOptions(boolean useLogging, File logFile) {
|
||||
ConsoleLogger.useLogging = useLogging;
|
||||
ConsoleLogger.logFile = logFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Print an info message.
|
||||
*
|
||||
* @param message String
|
||||
*/
|
||||
public static void info(String message) {
|
||||
wrapper.getLogger().info(message);
|
||||
if (!Settings.useLogging) {
|
||||
return;
|
||||
logger.info(message);
|
||||
if (useLogging) {
|
||||
writeLog(message);
|
||||
}
|
||||
writeLog("" + message);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -44,11 +54,10 @@ public final class ConsoleLogger {
|
||||
* @param message String
|
||||
*/
|
||||
public static void showError(String message) {
|
||||
wrapper.getLogger().warning(message);
|
||||
if (!Settings.useLogging) {
|
||||
return;
|
||||
logger.warning(message);
|
||||
if (useLogging) {
|
||||
writeLog("ERROR: " + message);
|
||||
}
|
||||
writeLog("ERROR: " + message);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -62,7 +71,7 @@ public final class ConsoleLogger {
|
||||
dateTime = DATE_FORMAT.format(new Date());
|
||||
}
|
||||
try {
|
||||
Files.write(Settings.LOG_FILE.toPath(), (dateTime + ": " + message + NEW_LINE).getBytes(),
|
||||
Files.write(logFile.toPath(), (dateTime + ": " + message + NEW_LINE).getBytes(),
|
||||
StandardOpenOption.APPEND,
|
||||
StandardOpenOption.CREATE);
|
||||
} catch (IOException ignored) {
|
||||
@ -72,12 +81,22 @@ public final class ConsoleLogger {
|
||||
/**
|
||||
* Write a StackTrace into the log.
|
||||
*
|
||||
* @param ex Exception
|
||||
* @param th The Throwable whose stack trace should be logged
|
||||
*/
|
||||
public static void writeStackTrace(Exception ex) {
|
||||
if (!Settings.useLogging) {
|
||||
return;
|
||||
public static void writeStackTrace(Throwable th) {
|
||||
if (useLogging) {
|
||||
writeLog(Throwables.getStackTraceAsString(th));
|
||||
}
|
||||
writeLog(Throwables.getStackTraceAsString(ex));
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs a Throwable with the provided message and saves the stack trace to the log file.
|
||||
*
|
||||
* @param message The message to accompany the exception
|
||||
* @param th The Throwable to log
|
||||
*/
|
||||
public static void logException(String message, Throwable th) {
|
||||
showError(message + " " + StringUtils.formatException(th));
|
||||
writeStackTrace(th);
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,5 @@
|
||||
package fr.xephi.authme;
|
||||
|
||||
import fr.xephi.authme.permission.PermissionsManager;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.util.Utils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Callable;
|
||||
@ -14,6 +7,14 @@ import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import fr.xephi.authme.permission.PermissionsManager;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.util.Utils;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class DataManager {
|
||||
@ -65,7 +66,7 @@ public class DataManager {
|
||||
/**
|
||||
* Method purgeAntiXray.
|
||||
*
|
||||
* @param cleared List<String>
|
||||
* @param cleared List of String
|
||||
*/
|
||||
public synchronized void purgeAntiXray(List<String> cleared) {
|
||||
int i = 0;
|
||||
@ -90,7 +91,7 @@ public class DataManager {
|
||||
/**
|
||||
* Method purgeLimitedCreative.
|
||||
*
|
||||
* @param cleared List<String>
|
||||
* @param cleared List of String
|
||||
*/
|
||||
public synchronized void purgeLimitedCreative(List<String> cleared) {
|
||||
int i = 0;
|
||||
@ -127,7 +128,7 @@ public class DataManager {
|
||||
/**
|
||||
* Method purgeDat.
|
||||
*
|
||||
* @param cleared List<String>
|
||||
* @param cleared List of String
|
||||
*/
|
||||
public synchronized void purgeDat(List<String> cleared) {
|
||||
int i = 0;
|
||||
@ -160,7 +161,7 @@ public class DataManager {
|
||||
/**
|
||||
* Method purgeEssentials.
|
||||
*
|
||||
* @param cleared List<String>
|
||||
* @param cleared List of String
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public void purgeEssentials(List<String> cleared) {
|
||||
@ -203,7 +204,7 @@ public class DataManager {
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
ConsoleLogger.info("AutoPurgeDatabase : Removed " + i + " permissions");
|
||||
ConsoleLogger.info("AutoPurgeDatabase : Removed " + i + "permissions");
|
||||
|
||||
/*int i = 0;
|
||||
for (String name : cleared) {
|
||||
|
45
src/main/java/fr/xephi/authme/MetricsStarter.java
Normal file
45
src/main/java/fr/xephi/authme/MetricsStarter.java
Normal file
@ -0,0 +1,45 @@
|
||||
package fr.xephi.authme;
|
||||
|
||||
import fr.xephi.authme.settings.NewSetting;
|
||||
import fr.xephi.authme.settings.properties.DatabaseSettings;
|
||||
import fr.xephi.authme.settings.properties.PluginSettings;
|
||||
import org.mcstats.Metrics;
|
||||
import org.mcstats.Metrics.Graph;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class MetricsStarter {
|
||||
|
||||
private MetricsStarter() {
|
||||
}
|
||||
|
||||
public static void setupMetrics(AuthMe plugin, NewSetting settings) {
|
||||
try {
|
||||
final Metrics metrics = new Metrics(plugin);
|
||||
|
||||
final Graph languageGraph = metrics.createGraph("Messages Language");
|
||||
final String messagesLanguage = settings.getProperty(PluginSettings.MESSAGES_LANGUAGE);
|
||||
languageGraph.addPlotter(new Metrics.Plotter(messagesLanguage) {
|
||||
@Override
|
||||
public int getValue() {
|
||||
return 1;
|
||||
}
|
||||
});
|
||||
|
||||
final Graph databaseBackend = metrics.createGraph("Database Backend");
|
||||
final String dataSource = settings.getProperty(DatabaseSettings.BACKEND).toString();
|
||||
databaseBackend.addPlotter(new Metrics.Plotter(dataSource) {
|
||||
@Override
|
||||
public int getValue() {
|
||||
return 1;
|
||||
}
|
||||
});
|
||||
|
||||
// Submit metrics
|
||||
metrics.start();
|
||||
} catch (IOException e) {
|
||||
// Failed to submit the metrics data
|
||||
ConsoleLogger.logException("Can't start Metrics! The plugin will work anyway...", e);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,8 +1,17 @@
|
||||
package fr.xephi.authme;
|
||||
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.datasource.DataSourceType;
|
||||
import fr.xephi.authme.settings.NewSetting;
|
||||
import fr.xephi.authme.settings.properties.BackupSettings;
|
||||
import fr.xephi.authme.settings.properties.DatabaseSettings;
|
||||
import fr.xephi.authme.util.StringUtils;
|
||||
|
||||
import java.io.*;
|
||||
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;
|
||||
|
||||
@ -10,47 +19,57 @@ import java.util.Date;
|
||||
* The backup management class
|
||||
*
|
||||
* @author stefano
|
||||
* @version $Revision: 1.0 $
|
||||
*/
|
||||
public class PerformBackup {
|
||||
|
||||
final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd_HH-mm");
|
||||
final String dateString = format.format(new Date());
|
||||
private final String dbName = Settings.getMySQLDatabase;
|
||||
private final String dbUserName = Settings.getMySQLUsername;
|
||||
private final String dbPassword = Settings.getMySQLPassword;
|
||||
private final String tblname = Settings.getMySQLTablename;
|
||||
private final String path = AuthMe.getInstance().getDataFolder() + File.separator + "backups" + File.separator + "backup" + dateString;
|
||||
private AuthMe instance;
|
||||
private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd_HH-mm");
|
||||
|
||||
private final String dbName;
|
||||
private final String dbUserName;
|
||||
private final String dbPassword;
|
||||
private final String tblname;
|
||||
private final String path;
|
||||
private final File dataFolder;
|
||||
private final NewSetting settings;
|
||||
|
||||
/**
|
||||
* Constructor for PerformBackup.
|
||||
*
|
||||
* @param instance AuthMe
|
||||
* @param settings The plugin settings
|
||||
*/
|
||||
public PerformBackup(AuthMe instance) {
|
||||
this.setInstance(instance);
|
||||
public PerformBackup(AuthMe instance, NewSetting settings) {
|
||||
this.dataFolder = instance.getDataFolder();
|
||||
this.settings = settings;
|
||||
this.dbName = settings.getProperty(DatabaseSettings.MYSQL_DATABASE);
|
||||
this.dbUserName = settings.getProperty(DatabaseSettings.MYSQL_USERNAME);
|
||||
this.dbPassword = settings.getProperty(DatabaseSettings.MYSQL_PASSWORD);
|
||||
this.tblname = settings.getProperty(DatabaseSettings.MYSQL_TABLE);
|
||||
|
||||
String dateString = DATE_FORMAT.format(new Date());
|
||||
this.path = StringUtils.join(File.separator,
|
||||
instance.getDataFolder().getPath(), "backups", "backup" + dateString);
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform a backup with the given reason.
|
||||
*
|
||||
* @param cause BackupCause The cause of the backup.
|
||||
* @param cause 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());
|
||||
if (!settings.getProperty(BackupSettings.ENABLED)) {
|
||||
// Print a warning if the backup was requested via command or by another plugin
|
||||
if (cause == BackupCause.COMMAND || cause == BackupCause.OTHER) {
|
||||
ConsoleLogger.showError("Can't perform a Backup: disabled in configuration. Cause of the Backup: "
|
||||
+ cause.name());
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// 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:
|
||||
if (BackupCause.START.equals(cause) && !settings.getProperty(BackupSettings.ON_SERVER_START)
|
||||
|| BackupCause.STOP.equals(cause) && !settings.getProperty(BackupSettings.ON_SERVER_STOP)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Do backup and check return value!
|
||||
@ -61,37 +80,31 @@ public class PerformBackup {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method doBackup.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public boolean doBackup() {
|
||||
|
||||
switch (Settings.getDataSource) {
|
||||
DataSourceType dataSourceType = settings.getProperty(DatabaseSettings.BACKEND);
|
||||
switch (dataSourceType) {
|
||||
case FILE:
|
||||
return FileBackup("auths.db");
|
||||
return fileBackup("auths.db");
|
||||
case MYSQL:
|
||||
return MySqlBackup();
|
||||
return mySqlBackup();
|
||||
case SQLITE:
|
||||
return FileBackup(Settings.getMySQLDatabase + ".db");
|
||||
return fileBackup(dbName + ".db");
|
||||
default:
|
||||
ConsoleLogger.showError("Unknown data source type '" + dataSourceType + "' for backup");
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method MySqlBackup.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
private boolean MySqlBackup() {
|
||||
File dirBackup = new File(AuthMe.getInstance().getDataFolder() + "/backups");
|
||||
private boolean mySqlBackup() {
|
||||
File dirBackup = new File(dataFolder + File.separator + "backups");
|
||||
|
||||
if (!dirBackup.exists())
|
||||
if (!dirBackup.exists()) {
|
||||
dirBackup.mkdir();
|
||||
if (checkWindows(Settings.backupWindowsPath)) {
|
||||
String executeCmd = Settings.backupWindowsPath + "\\bin\\mysqldump.exe -u " + dbUserName + " -p" + dbPassword + " " + dbName + " --tables " + tblname + " -r " + path + ".sql";
|
||||
}
|
||||
String backupWindowsPath = settings.getProperty(BackupSettings.MYSQL_WINDOWS_PATH);
|
||||
if (checkWindows(backupWindowsPath)) {
|
||||
String executeCmd = backupWindowsPath + "\\bin\\mysqldump.exe -u " + dbUserName + " -p" + dbPassword + " " + dbName + " --tables " + tblname + " -r " + path + ".sql";
|
||||
Process runtimeProcess;
|
||||
try {
|
||||
runtimeProcess = Runtime.getRuntime().exec(executeCmd);
|
||||
@ -100,10 +113,10 @@ public class PerformBackup {
|
||||
ConsoleLogger.info("Backup created successfully.");
|
||||
return true;
|
||||
} else {
|
||||
ConsoleLogger.showError("Could not create the backup!");
|
||||
ConsoleLogger.showError("Could not create the backup! (Windows)");
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
} catch (IOException | InterruptedException e) {
|
||||
ConsoleLogger.logException("Error during Windows backup:", e);
|
||||
}
|
||||
} else {
|
||||
String executeCmd = "mysqldump -u " + dbUserName + " -p" + dbPassword + " " + dbName + " --tables " + tblname + " -r " + path + ".sql";
|
||||
@ -117,69 +130,50 @@ public class PerformBackup {
|
||||
} else {
|
||||
ConsoleLogger.showError("Could not create the backup!");
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
} catch (IOException | InterruptedException e) {
|
||||
ConsoleLogger.logException("Error during backup:", e);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method FileBackup.
|
||||
*
|
||||
* @param backend String
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
private boolean FileBackup(String backend) {
|
||||
File dirBackup = new File(AuthMe.getInstance().getDataFolder() + "/backups");
|
||||
private boolean fileBackup(String backend) {
|
||||
File dirBackup = new File(dataFolder + File.separator + "backups");
|
||||
|
||||
if (!dirBackup.exists())
|
||||
dirBackup.mkdir();
|
||||
|
||||
try {
|
||||
copy(new File("plugins" + File.separator + "AuthMe" + File.separator + backend), new File(path + ".db"));
|
||||
copy("plugins" + File.separator + "AuthMe" + File.separator + backend, path + ".db");
|
||||
return true;
|
||||
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
} catch (IOException ex) {
|
||||
ConsoleLogger.showError("Encountered an error during file backup: " + StringUtils.formatException(ex));
|
||||
ConsoleLogger.writeStackTrace(ex);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method checkWindows.
|
||||
* Check if we are under Windows and correct location of mysqldump.exe
|
||||
* otherwise return error.
|
||||
*
|
||||
* @param windowsPath String
|
||||
*
|
||||
* @return boolean
|
||||
* @param windowsPath The path to check
|
||||
* @return True if the path is correct, false if it is incorrect or the OS is not Windows
|
||||
*/
|
||||
private boolean checkWindows(String windowsPath) {
|
||||
private static boolean checkWindows(String windowsPath) {
|
||||
String isWin = System.getProperty("os.name").toLowerCase();
|
||||
if (isWin.contains("win")) {
|
||||
if (new File(windowsPath + "\\bin\\mysqldump.exe").exists()) {
|
||||
return true;
|
||||
} else {
|
||||
ConsoleLogger.showError("Mysql Windows Path is incorrect please check it");
|
||||
return true;
|
||||
ConsoleLogger.showError("Mysql Windows Path is incorrect. Please check it");
|
||||
return false;
|
||||
}
|
||||
} else return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* 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 {
|
||||
private static void copy(String src, String dst) throws IOException {
|
||||
InputStream in = new FileInputStream(src);
|
||||
OutputStream out = new FileOutputStream(dst);
|
||||
|
||||
@ -193,27 +187,6 @@ public class PerformBackup {
|
||||
out.close();
|
||||
}
|
||||
|
||||
/*
|
||||
* Copyr src bytefile into dst file
|
||||
*/
|
||||
|
||||
/**
|
||||
* Method getInstance.
|
||||
*
|
||||
* @return AuthMe
|
||||
*/
|
||||
public AuthMe getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method setInstance.
|
||||
*
|
||||
* @param instance AuthMe
|
||||
*/
|
||||
public void setInstance(AuthMe instance) {
|
||||
this.instance = instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Possible backup causes.
|
||||
@ -222,7 +195,7 @@ public class PerformBackup {
|
||||
START,
|
||||
STOP,
|
||||
COMMAND,
|
||||
OTHER,
|
||||
OTHER
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,104 +0,0 @@
|
||||
package fr.xephi.authme;
|
||||
|
||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import org.apache.commons.mail.HtmlEmail;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import javax.activation.DataSource;
|
||||
import javax.activation.FileDataSource;
|
||||
import javax.imageio.ImageIO;
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* @author Xephi59
|
||||
* @version $Revision: 1.0 $
|
||||
*/
|
||||
public class SendMailSSL {
|
||||
|
||||
public final AuthMe plugin;
|
||||
|
||||
/**
|
||||
* Constructor for SendMailSSL.
|
||||
*
|
||||
* @param plugin AuthMe
|
||||
*/
|
||||
public SendMailSSL(AuthMe plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method main.
|
||||
*
|
||||
* @param auth PlayerAuth
|
||||
* @param newPass String
|
||||
*/
|
||||
public void main(final PlayerAuth auth, final String newPass) {
|
||||
String senderName;
|
||||
|
||||
if (Settings.getmailSenderName == null || Settings.getmailSenderName.isEmpty()) {
|
||||
senderName = Settings.getmailAccount;
|
||||
} else {
|
||||
senderName = Settings.getmailSenderName;
|
||||
}
|
||||
|
||||
final String sender = senderName;
|
||||
final int port = Settings.getMailPort;
|
||||
final String acc = Settings.getmailAccount;
|
||||
final String subject = Settings.getMailSubject;
|
||||
final String smtp = Settings.getmailSMTP;
|
||||
final String password = Settings.getmailPassword;
|
||||
final String mailText = Settings.getMailText.replace("%playername%", auth.getNickname()).replace("%servername%", plugin.getServer().getServerName()).replace("%generatedpass%", newPass);
|
||||
final String mail = auth.getEmail();
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
|
||||
HtmlEmail email = new HtmlEmail();
|
||||
email.setSmtpPort(port);
|
||||
email.setHostName(smtp);
|
||||
email.addTo(mail);
|
||||
email.setFrom(acc, sender);
|
||||
email.setSubject(subject);
|
||||
email.setAuthentication(acc, password);
|
||||
email.setStartTLSEnabled(true);
|
||||
email.setStartTLSRequired(true);
|
||||
email.setSSLCheckServerIdentity(true);
|
||||
String content = mailText;
|
||||
// Generate an image ?
|
||||
File file = null;
|
||||
if (Settings.generateImage) {
|
||||
try {
|
||||
ImageGenerator gen = new ImageGenerator(newPass);
|
||||
file = new File(plugin.getDataFolder() + File.separator + auth.getNickname() + "_new_pass.jpg");
|
||||
ImageIO.write(gen.generateImage(), "jpg", file);
|
||||
DataSource source = new FileDataSource(file);
|
||||
String tag = email.embed(source, auth.getNickname() + "_new_pass.jpg");
|
||||
content = content.replace("%image%", "<img src=\"cid:" + tag + "\">");
|
||||
} catch (Exception e) {
|
||||
ConsoleLogger.showError("Unable to send new password as image! Using normal text! Dest: " + mail);
|
||||
}
|
||||
}
|
||||
email.setHtmlMsg(content);
|
||||
email.setTextMsg(content);
|
||||
try {
|
||||
email.send();
|
||||
} catch (Exception e) {
|
||||
ConsoleLogger.showError("Fail to send a mail to " + mail + " cause " + e.getLocalizedMessage());
|
||||
}
|
||||
if (file != null)
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
file.delete();
|
||||
|
||||
} catch (Exception e) {
|
||||
// Print the stack trace
|
||||
e.printStackTrace();
|
||||
ConsoleLogger.showError("Some error occurred while trying to send a email to " + mail);
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
}
|
@ -4,7 +4,7 @@ import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||
import fr.xephi.authme.cache.auth.PlayerCache;
|
||||
import fr.xephi.authme.security.PasswordSecurity;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.security.crypts.HashedPassword;
|
||||
import fr.xephi.authme.util.Utils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
@ -12,34 +12,37 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
/**
|
||||
* Deprecated API of AuthMe. Please use {@link NewAPI} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public class API {
|
||||
|
||||
public static final String newline = System.getProperty("line.separator");
|
||||
public static AuthMe instance;
|
||||
private static PasswordSecurity passwordSecurity;
|
||||
|
||||
/**
|
||||
* Constructor for API.
|
||||
* Constructor for the deprecated API.
|
||||
*
|
||||
* @param instance AuthMe
|
||||
*/
|
||||
@Deprecated
|
||||
public API(AuthMe instance) {
|
||||
API.instance = instance;
|
||||
passwordSecurity = instance.getPasswordSecurity();
|
||||
}
|
||||
|
||||
/**
|
||||
* Hook into AuthMe
|
||||
* Hook into AuthMe.
|
||||
*
|
||||
* @return AuthMe instance
|
||||
*/
|
||||
@Deprecated
|
||||
public static AuthMe hookAuthMe() {
|
||||
if (instance != null)
|
||||
if (instance != null) {
|
||||
return instance;
|
||||
}
|
||||
Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin("AuthMe");
|
||||
if (plugin == null || !(plugin instanceof AuthMe)) {
|
||||
return null;
|
||||
@ -49,9 +52,10 @@ public class API {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param player
|
||||
* Return whether the player is authenticated.
|
||||
*
|
||||
* @return true if player is authenticate
|
||||
* @param player The player to verify
|
||||
* @return true if the player is authenticated
|
||||
*/
|
||||
@Deprecated
|
||||
public static boolean isAuthenticated(Player player) {
|
||||
@ -59,8 +63,9 @@ public class API {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param player
|
||||
* Return whether the player is unrestricted.
|
||||
*
|
||||
* @param player The player to verify
|
||||
* @return true if the player is unrestricted
|
||||
*/
|
||||
@Deprecated
|
||||
@ -68,13 +73,6 @@ public class API {
|
||||
return Utils.isUnrestricted(player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method getLastLocation.
|
||||
*
|
||||
* @param player Player
|
||||
*
|
||||
* @return Location
|
||||
*/
|
||||
@Deprecated
|
||||
public static Location getLastLocation(Player player) {
|
||||
try {
|
||||
@ -92,13 +90,6 @@ public class API {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method setPlayerInventory.
|
||||
*
|
||||
* @param player Player
|
||||
* @param content ItemStack[]
|
||||
* @param armor ItemStack[]
|
||||
*/
|
||||
@Deprecated
|
||||
public static void setPlayerInventory(Player player, ItemStack[] content,
|
||||
ItemStack[] armor) {
|
||||
@ -110,93 +101,72 @@ public class API {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param playerName
|
||||
* Check whether the given player name is registered.
|
||||
*
|
||||
* @param playerName The player name to verify
|
||||
* @return true if player is registered
|
||||
*/
|
||||
@Deprecated
|
||||
public static boolean isRegistered(String playerName) {
|
||||
String player = playerName.toLowerCase();
|
||||
return instance.database.isAuthAvailable(player);
|
||||
return instance.getDataSource().isAuthAvailable(player);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param playerName String
|
||||
* @param passwordToCheck String
|
||||
* Check the password for the given player.
|
||||
*
|
||||
* @return true if the password is correct , false else
|
||||
* @param playerName The name of the player
|
||||
* @param passwordToCheck The password to check
|
||||
* @return true if the password is correct, false otherwise
|
||||
*/
|
||||
@Deprecated
|
||||
public static boolean checkPassword(String playerName,
|
||||
String passwordToCheck) {
|
||||
if (!isRegistered(playerName))
|
||||
return false;
|
||||
String player = playerName.toLowerCase();
|
||||
PlayerAuth auth = instance.database.getAuth(player);
|
||||
try {
|
||||
return PasswordSecurity.comparePasswordWithHash(passwordToCheck, auth.getHash(), playerName);
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
return false;
|
||||
}
|
||||
public static boolean checkPassword(String playerName, String passwordToCheck) {
|
||||
return isRegistered(playerName) && passwordSecurity.comparePassword(passwordToCheck, playerName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a player
|
||||
* Register a player.
|
||||
*
|
||||
* @param playerName String
|
||||
* @param password String
|
||||
*
|
||||
* @return true if the player is register correctly
|
||||
* @param playerName The name of the player
|
||||
* @param password The password
|
||||
* @return true if the player was registered correctly
|
||||
*/
|
||||
@Deprecated
|
||||
public static boolean registerPlayer(String playerName, String password) {
|
||||
try {
|
||||
String name = playerName.toLowerCase();
|
||||
String hash = PasswordSecurity.getHash(Settings.getPasswordHash, password, name);
|
||||
if (isRegistered(name)) {
|
||||
return false;
|
||||
}
|
||||
PlayerAuth auth = new PlayerAuth(name, hash, "198.18.0.1", 0, "your@email.com", playerName);
|
||||
return instance.database.saveAuth(auth);
|
||||
} catch (NoSuchAlgorithmException ex) {
|
||||
String name = playerName.toLowerCase();
|
||||
HashedPassword hashedPassword = passwordSecurity.computeHash(password, name);
|
||||
if (isRegistered(name)) {
|
||||
return false;
|
||||
}
|
||||
PlayerAuth auth = PlayerAuth.builder()
|
||||
.name(name)
|
||||
.password(hashedPassword)
|
||||
.lastLogin(0)
|
||||
.realName(playerName)
|
||||
.build();
|
||||
return instance.getDataSource().saveAuth(auth);
|
||||
}
|
||||
|
||||
/**
|
||||
* Force a player to login
|
||||
* Force a player to log in.
|
||||
*
|
||||
* @param player * player
|
||||
* @param player The player to log in
|
||||
*/
|
||||
@Deprecated
|
||||
public static void forceLogin(Player player) {
|
||||
instance.getManagement().performLogin(player, "dontneed", true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method getPlugin.
|
||||
*
|
||||
* @return AuthMe
|
||||
*/
|
||||
@Deprecated
|
||||
public AuthMe getPlugin() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param player
|
||||
* Check whether the player is an NPC.
|
||||
*
|
||||
* @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
|
||||
* @param player The player to verify
|
||||
* @return true if player is an npc
|
||||
*/
|
||||
@Deprecated
|
||||
public boolean isNPC(Player player) {
|
||||
|
@ -1,20 +1,19 @@
|
||||
package fr.xephi.authme.api;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||
import fr.xephi.authme.cache.auth.PlayerCache;
|
||||
import fr.xephi.authme.security.PasswordSecurity;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.util.Utils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||
import fr.xephi.authme.cache.auth.PlayerCache;
|
||||
import fr.xephi.authme.security.crypts.HashedPassword;
|
||||
import fr.xephi.authme.util.Utils;
|
||||
|
||||
/**
|
||||
* The current API of AuthMe.
|
||||
*/
|
||||
public class NewAPI {
|
||||
|
||||
@ -42,40 +41,43 @@ public class NewAPI {
|
||||
/**
|
||||
* Hook into AuthMe
|
||||
*
|
||||
* @return AuthMe plugin
|
||||
* @return The API object
|
||||
*/
|
||||
public static NewAPI getInstance() {
|
||||
if (singleton != null)
|
||||
if (singleton != null) {
|
||||
return singleton;
|
||||
}
|
||||
Plugin p = Bukkit.getServer().getPluginManager().getPlugin("AuthMe");
|
||||
if (p == null || !(p instanceof AuthMe)) {
|
||||
return null;
|
||||
}
|
||||
AuthMe authme = (AuthMe) p;
|
||||
singleton = (new NewAPI(authme));
|
||||
singleton = new NewAPI(authme);
|
||||
return singleton;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method getPlugin.
|
||||
* Return the plugin instance.
|
||||
*
|
||||
* @return AuthMe
|
||||
* @return The AuthMe instance
|
||||
*/
|
||||
public AuthMe getPlugin() {
|
||||
return plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param player
|
||||
* Return whether the given player is authenticated.
|
||||
*
|
||||
* @return true if player is authenticate
|
||||
* @param player The player to verify
|
||||
*
|
||||
* @return true if the player is authenticated
|
||||
*/
|
||||
public boolean isAuthenticated(Player player) {
|
||||
return PlayerCache.getInstance().isAuthenticated(player.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param player
|
||||
* @param player a Player
|
||||
*
|
||||
* @return true if player is a npc
|
||||
*/
|
||||
@ -84,7 +86,7 @@ public class NewAPI {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param player
|
||||
* @param player a Player
|
||||
*
|
||||
* @return true if the player is unrestricted
|
||||
*/
|
||||
@ -93,15 +95,15 @@ public class NewAPI {
|
||||
}
|
||||
|
||||
/**
|
||||
* Method getLastLocation.
|
||||
* Get the last location of a player.
|
||||
*
|
||||
* @param player Player
|
||||
* @param player Player The player to process
|
||||
*
|
||||
* @return Location
|
||||
* @return Location The location of the player
|
||||
*/
|
||||
public Location getLastLocation(Player player) {
|
||||
try {
|
||||
PlayerAuth auth = PlayerCache.getInstance().getAuth(player.getName().toLowerCase());
|
||||
PlayerAuth auth = PlayerCache.getInstance().getAuth(player.getName());
|
||||
|
||||
if (auth != null) {
|
||||
return new Location(Bukkit.getWorld(auth.getWorld()), auth.getQuitLocX(), auth.getQuitLocY(), auth.getQuitLocZ());
|
||||
@ -115,87 +117,83 @@ public class NewAPI {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param playerName
|
||||
* Return whether the player is registered.
|
||||
*
|
||||
* @return true if player is registered
|
||||
* @param playerName The player name to check
|
||||
*
|
||||
* @return true if player is registered, false otherwise
|
||||
*/
|
||||
public boolean isRegistered(String playerName) {
|
||||
String player = playerName.toLowerCase();
|
||||
return plugin.database.isAuthAvailable(player);
|
||||
return plugin.getDataSource().isAuthAvailable(player);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param playerName String
|
||||
* @param passwordToCheck String
|
||||
* Check the password for the given player.
|
||||
*
|
||||
* @return true if the password is correct , false else
|
||||
* @param playerName The player to check the password for
|
||||
* @param passwordToCheck The password to check
|
||||
*
|
||||
* @return true if the password is correct, false otherwise
|
||||
*/
|
||||
public boolean checkPassword(String playerName, String passwordToCheck) {
|
||||
if (!isRegistered(playerName))
|
||||
return false;
|
||||
String player = playerName.toLowerCase();
|
||||
PlayerAuth auth = plugin.database.getAuth(player);
|
||||
try {
|
||||
return PasswordSecurity.comparePasswordWithHash(passwordToCheck, auth.getHash(), playerName);
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
return false;
|
||||
}
|
||||
return isRegistered(playerName) && plugin.getPasswordSecurity().comparePassword(passwordToCheck, playerName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a player
|
||||
* Register a player.
|
||||
*
|
||||
* @param playerName String
|
||||
* @param password String
|
||||
* @param playerName The player to register
|
||||
* @param password The password to register the player with
|
||||
*
|
||||
* @return true if the player is register correctly
|
||||
* @return true if the player was registered successfully
|
||||
*/
|
||||
public boolean registerPlayer(String playerName, String password) {
|
||||
try {
|
||||
String name = playerName.toLowerCase();
|
||||
String hash = PasswordSecurity.getHash(Settings.getPasswordHash, password, name);
|
||||
if (isRegistered(name)) {
|
||||
return false;
|
||||
}
|
||||
PlayerAuth auth = new PlayerAuth(name, hash, "192.168.0.1", 0, "your@email.com", playerName);
|
||||
return plugin.database.saveAuth(auth);
|
||||
} catch (NoSuchAlgorithmException ex) {
|
||||
String name = playerName.toLowerCase();
|
||||
HashedPassword result = plugin.getPasswordSecurity().computeHash(password, name);
|
||||
if (isRegistered(name)) {
|
||||
return false;
|
||||
}
|
||||
PlayerAuth auth = PlayerAuth.builder()
|
||||
.name(name)
|
||||
.password(result)
|
||||
.realName(playerName)
|
||||
.build();
|
||||
return plugin.getDataSource().saveAuth(auth);
|
||||
}
|
||||
|
||||
/**
|
||||
* Force a player to login
|
||||
* Force a player to login.
|
||||
*
|
||||
* @param player * player
|
||||
* @param player The player to log in
|
||||
*/
|
||||
public void forceLogin(Player player) {
|
||||
plugin.getManagement().performLogin(player, "dontneed", true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Force a player to logout
|
||||
* Force a player to logout.
|
||||
*
|
||||
* @param player * player
|
||||
* @param player The player to log out
|
||||
*/
|
||||
public void forceLogout(Player player) {
|
||||
plugin.getManagement().performLogout(player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Force a player to register
|
||||
* Force a player to register.
|
||||
*
|
||||
* @param player * player
|
||||
* @param password String
|
||||
* @param player The player to register
|
||||
* @param password The password to use
|
||||
*/
|
||||
public void forceRegister(Player player, String password) {
|
||||
plugin.getManagement().performRegister(player, password, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Force a player to unregister
|
||||
* Force a player to unregister.
|
||||
*
|
||||
* @param player * player
|
||||
* @param player The player to unregister
|
||||
*/
|
||||
public void forceUnregister(Player player) {
|
||||
plugin.getManagement().performUnregister(player, "", true);
|
||||
|
@ -1,27 +1,31 @@
|
||||
package fr.xephi.authme.cache.auth;
|
||||
|
||||
import fr.xephi.authme.security.HashAlgorithm;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import static com.google.common.base.Objects.firstNonNull;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import org.bukkit.Location;
|
||||
|
||||
import fr.xephi.authme.security.crypts.HashedPassword;
|
||||
|
||||
|
||||
/**
|
||||
*/
|
||||
public class PlayerAuth {
|
||||
|
||||
private String nickname;
|
||||
private String hash;
|
||||
private HashedPassword password;
|
||||
private String ip;
|
||||
private long lastLogin;
|
||||
private double x;
|
||||
private double y;
|
||||
private double z;
|
||||
private String world;
|
||||
private String salt;
|
||||
private int groupId;
|
||||
private String email;
|
||||
private String realName;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param serialized String
|
||||
*/
|
||||
public PlayerAuth(String serialized) {
|
||||
this.deserialize(serialized);
|
||||
@ -36,7 +40,7 @@ public class PlayerAuth {
|
||||
* @param realName String
|
||||
*/
|
||||
public PlayerAuth(String nickname, String ip, long lastLogin, String realName) {
|
||||
this(nickname, "", "", -1, ip, lastLogin, 0, 0, 0, "world", "your@email.com", realName);
|
||||
this(nickname, new HashedPassword(""), -1, ip, lastLogin, 0, 0, 0, "world", "your@email.com", realName);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -50,7 +54,8 @@ public class PlayerAuth {
|
||||
* @param realName String
|
||||
*/
|
||||
public PlayerAuth(String nickname, double x, double y, double z, String world, String realName) {
|
||||
this(nickname, "", "", -1, "127.0.0.1", System.currentTimeMillis(), x, y, z, world, "your@email.com", realName);
|
||||
this(nickname, new HashedPassword(""), -1, "127.0.0.1", System.currentTimeMillis(), x, y, z, world,
|
||||
"your@email.com", realName);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -63,7 +68,7 @@ public class PlayerAuth {
|
||||
* @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);
|
||||
this(nickname, new HashedPassword(hash), -1, ip, lastLogin, 0, 0, 0, "world", "your@email.com", realName);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -77,7 +82,7 @@ public class PlayerAuth {
|
||||
* @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);
|
||||
this(nickname, new HashedPassword(hash), -1, ip, lastLogin, 0, 0, 0, "world", email, realName);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -91,7 +96,7 @@ public class PlayerAuth {
|
||||
* @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);
|
||||
this(nickname, new HashedPassword(hash, salt), -1, ip, lastLogin, 0, 0, 0, "world", "your@email.com", realName);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -108,8 +113,9 @@ public class PlayerAuth {
|
||||
* @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);
|
||||
public PlayerAuth(String nickname, String hash, String ip, long lastLogin, double x, double y, double z,
|
||||
String world, String email, String realName) {
|
||||
this(nickname, new HashedPassword(hash), -1, ip, lastLogin, x, y, z, world, email, realName);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -127,8 +133,10 @@ public class PlayerAuth {
|
||||
* @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);
|
||||
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, new HashedPassword(hash, salt), -1, ip, lastLogin,
|
||||
x, y, z, world, email, realName);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -142,38 +150,37 @@ public class PlayerAuth {
|
||||
* @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) {
|
||||
long lastLogin, String realName) {
|
||||
this(nickname, new HashedPassword(hash, salt), groupId, ip, lastLogin,
|
||||
0, 0, 0, "world", "your@email.com", realName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for PlayerAuth.
|
||||
*
|
||||
* @param nickname String
|
||||
* @param password 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, HashedPassword password, int groupId, String ip, long lastLogin,
|
||||
double x, double y, double z, String world, String email, String realName) {
|
||||
this.nickname = nickname.toLowerCase();
|
||||
this.hash = hash;
|
||||
this.password = password;
|
||||
this.ip = ip;
|
||||
this.lastLogin = lastLogin;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.world = world;
|
||||
this.salt = salt;
|
||||
this.groupId = groupId;
|
||||
this.email = email;
|
||||
this.realName = realName;
|
||||
@ -186,237 +193,102 @@ public class PlayerAuth {
|
||||
*/
|
||||
public void set(PlayerAuth auth) {
|
||||
this.setEmail(auth.getEmail());
|
||||
this.setHash(auth.getHash());
|
||||
this.setPassword(auth.getPassword());
|
||||
this.setIp(auth.getIp());
|
||||
this.setLastLogin(auth.getLastLogin());
|
||||
this.setName(auth.getNickname());
|
||||
this.setNickname(auth.getNickname());
|
||||
this.setQuitLocX(auth.getQuitLocX());
|
||||
this.setQuitLocY(auth.getQuitLocY());
|
||||
this.setQuitLocZ(auth.getQuitLocZ());
|
||||
this.setSalt(auth.getSalt());
|
||||
this.setWorld(auth.getWorld());
|
||||
this.setRealName(auth.getRealName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Method setName.
|
||||
*
|
||||
* @param nickname String
|
||||
*/
|
||||
public void setName(String nickname) {
|
||||
|
||||
public void setNickname(String nickname) {
|
||||
this.nickname = nickname.toLowerCase();
|
||||
}
|
||||
|
||||
/**
|
||||
* Method getNickname.
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
public String getNickname() {
|
||||
return nickname;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method getRealName.
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
public String getRealName() {
|
||||
return realName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method setRealName.
|
||||
*
|
||||
* @param realName String
|
||||
*/
|
||||
public void setRealName(String 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;
|
||||
public HashedPassword getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method setSalt.
|
||||
*
|
||||
* @param salt String
|
||||
*/
|
||||
public void setSalt(String salt) {
|
||||
this.salt = salt;
|
||||
public void setPassword(HashedPassword password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)) {
|
||||
@ -426,11 +298,6 @@ public class PlayerAuth {
|
||||
return other.getIp().equals(this.ip) && other.getNickname().equals(this.nickname);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method hashCode.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hashCode = 7;
|
||||
@ -439,20 +306,14 @@ public class PlayerAuth {
|
||||
return hashCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method toString.
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return ("Player : " + nickname + " | " + realName
|
||||
return "Player : " + nickname + " | " + realName
|
||||
+ " ! IP : " + ip
|
||||
+ " ! LastLogin : " + lastLogin
|
||||
+ " ! LastPosition : " + x + "," + y + "," + z + "," + world
|
||||
+ " ! Email : " + email
|
||||
+ " ! Hash : " + hash
|
||||
+ " ! Salt : " + salt);
|
||||
+ " ! Password : {" + password.getHash() + ", " + password.getSalt() + "}";
|
||||
}
|
||||
|
||||
/**
|
||||
@ -461,14 +322,14 @@ public class PlayerAuth {
|
||||
* @return String
|
||||
*/
|
||||
public String serialize() {
|
||||
StringBuilder str = new StringBuilder();
|
||||
StringBuffer str = new StringBuffer();
|
||||
char d = ';';
|
||||
str.append(this.nickname).append(d);
|
||||
str.append(this.realName).append(d);
|
||||
str.append(this.ip).append(d);
|
||||
str.append(this.email).append(d);
|
||||
str.append(this.hash).append(d);
|
||||
str.append(this.salt).append(d);
|
||||
str.append(this.password.getHash()).append(d);
|
||||
str.append(this.password.getSalt()).append(d);
|
||||
str.append(this.groupId).append(d);
|
||||
str.append(this.lastLogin).append(d);
|
||||
str.append(this.world).append(d);
|
||||
@ -480,6 +341,8 @@ public class PlayerAuth {
|
||||
|
||||
/**
|
||||
* Method to deserialize PlayerAuth
|
||||
*
|
||||
* @param str String
|
||||
*/
|
||||
public void deserialize(String str) {
|
||||
String[] args = str.split(";");
|
||||
@ -487,8 +350,7 @@ public class PlayerAuth {
|
||||
this.realName = args[1];
|
||||
this.ip = args[2];
|
||||
this.email = args[3];
|
||||
this.hash = args[4];
|
||||
this.salt = args[5];
|
||||
this.password = new HashedPassword(args[4], args[5]);
|
||||
this.groupId = Integer.parseInt(args[6]);
|
||||
this.lastLogin = Long.parseLong(args[7]);
|
||||
this.world = args[8];
|
||||
@ -503,34 +365,33 @@ public class PlayerAuth {
|
||||
|
||||
public static final class Builder {
|
||||
private String name;
|
||||
private String realName = "Player";
|
||||
private String hash = "";
|
||||
private String salt = "";
|
||||
private String ip = "127.0.0.1";
|
||||
private String world = "world";
|
||||
private String realName;
|
||||
private HashedPassword password;
|
||||
private String ip;
|
||||
private String world;
|
||||
private String email;
|
||||
private int groupId = -1;
|
||||
private double x = 0.0f;
|
||||
private double y = 0.0f;
|
||||
private double z = 0.0f;
|
||||
private long lastLogin = System.currentTimeMillis();
|
||||
private int groupId = -1;
|
||||
private String email = "your@email.com";
|
||||
|
||||
public PlayerAuth build() {
|
||||
return new PlayerAuth(
|
||||
name,
|
||||
hash,
|
||||
salt,
|
||||
checkNotNull(name),
|
||||
firstNonNull(password, new HashedPassword("")),
|
||||
groupId,
|
||||
ip,
|
||||
firstNonNull(ip, "127.0.0.1"),
|
||||
lastLogin,
|
||||
x, y, z, world,
|
||||
email,
|
||||
realName
|
||||
x, y, z,
|
||||
firstNonNull(world, "world"),
|
||||
firstNonNull(email, "your@email.com"),
|
||||
firstNonNull(realName, "Player")
|
||||
);
|
||||
}
|
||||
|
||||
public Builder name(String name) {
|
||||
this.name = name.toLowerCase();
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -539,14 +400,13 @@ public class PlayerAuth {
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder hash(String hash) {
|
||||
this.hash = hash;
|
||||
public Builder password(HashedPassword password) {
|
||||
this.password = password;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder salt(String salt) {
|
||||
this.salt = salt;
|
||||
return this;
|
||||
public Builder password(String hash, String salt) {
|
||||
return password(new HashedPassword(hash, salt));
|
||||
}
|
||||
|
||||
public Builder ip(String ip) {
|
||||
@ -554,6 +414,14 @@ public class PlayerAuth {
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder location(Location location) {
|
||||
this.x = location.getX();
|
||||
this.y = location.getY();
|
||||
this.z = location.getZ();
|
||||
this.world = location.getWorld().getName();
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder locWorld(String world) {
|
||||
this.world = world;
|
||||
return this;
|
||||
|
@ -40,8 +40,7 @@ public class PlayerCache {
|
||||
* @param auth PlayerAuth
|
||||
*/
|
||||
public void updatePlayer(PlayerAuth auth) {
|
||||
cache.remove(auth.getNickname().toLowerCase());
|
||||
cache.put(auth.getNickname().toLowerCase(), auth);
|
||||
cache.put(auth.getNickname(), auth);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -87,7 +86,7 @@ public class PlayerCache {
|
||||
/**
|
||||
* Method getCache.
|
||||
*
|
||||
* @return ConcurrentHashMap<String,PlayerAuth>
|
||||
* @return ConcurrentHashMap
|
||||
*/
|
||||
public ConcurrentHashMap<String, PlayerAuth> getCache() {
|
||||
return this.cache;
|
||||
|
@ -6,19 +6,16 @@ public class DataFileCache {
|
||||
|
||||
private final String group;
|
||||
private final boolean operator;
|
||||
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) {
|
||||
this.group = group;
|
||||
this.operator = operator;
|
||||
this.flying = flying;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -38,13 +35,4 @@ public class DataFileCache {
|
||||
public boolean getOperator() {
|
||||
return operator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method isFlying.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public boolean isFlying() {
|
||||
return flying;
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,6 @@ 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;
|
||||
@ -109,7 +108,7 @@ public class JsonCache {
|
||||
}
|
||||
File file = new File(cacheDir, path);
|
||||
if (file.exists()) {
|
||||
Utils.purgeDirectory(file);
|
||||
purgeDirectory(file);
|
||||
if (!file.delete()) {
|
||||
ConsoleLogger.showError("Failed to remove" + player.getName() + "cache.");
|
||||
}
|
||||
@ -155,7 +154,6 @@ public class JsonCache {
|
||||
JsonElement e;
|
||||
String group = null;
|
||||
boolean operator = false;
|
||||
boolean flying = false;
|
||||
|
||||
if ((e = jsonObject.get("group")) != null) {
|
||||
group = e.getAsString();
|
||||
@ -163,11 +161,8 @@ public class JsonCache {
|
||||
if ((e = jsonObject.get("operator")) != null) {
|
||||
operator = e.getAsBoolean();
|
||||
}
|
||||
if ((e = jsonObject.get("flying")) != null) {
|
||||
flying = e.getAsBoolean();
|
||||
}
|
||||
|
||||
return new DataFileCache(group, operator, flying);
|
||||
return new DataFileCache(group, operator);
|
||||
}
|
||||
}
|
||||
|
||||
@ -188,10 +183,30 @@ public class JsonCache {
|
||||
JsonObject jsonObject = new JsonObject();
|
||||
jsonObject.addProperty("group", dataFileCache.getGroup());
|
||||
jsonObject.addProperty("operator", dataFileCache.getOperator());
|
||||
jsonObject.addProperty("flying", dataFileCache.isFlying());
|
||||
|
||||
return jsonObject;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a given directory and all its content.
|
||||
*
|
||||
* @param directory The directory to remove
|
||||
*/
|
||||
private static void purgeDirectory(File directory) {
|
||||
if (!directory.isDirectory()) {
|
||||
return;
|
||||
}
|
||||
File[] files = directory.listFiles();
|
||||
if (files == null) {
|
||||
return;
|
||||
}
|
||||
for (File target : files) {
|
||||
if (target.isDirectory()) {
|
||||
purgeDirectory(target);
|
||||
}
|
||||
target.delete();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -4,11 +4,7 @@ import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.cache.backup.DataFileCache;
|
||||
import fr.xephi.authme.cache.backup.JsonCache;
|
||||
import fr.xephi.authme.events.ResetInventoryEvent;
|
||||
import fr.xephi.authme.permission.PermissionsManager;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@ -56,10 +52,8 @@ public class LimboCache {
|
||||
public void addLimboPlayer(Player player) {
|
||||
String name = player.getName().toLowerCase();
|
||||
Location loc = player.getLocation();
|
||||
GameMode gameMode = player.getGameMode();
|
||||
boolean operator = false;
|
||||
String playerGroup = "";
|
||||
boolean flying = false;
|
||||
|
||||
// Get the permissions manager, and make sure it's valid
|
||||
PermissionsManager permsMan = this.plugin.getPermissionsManager();
|
||||
@ -72,35 +66,20 @@ public class LimboCache {
|
||||
if (cache != null) {
|
||||
playerGroup = cache.getGroup();
|
||||
operator = cache.getOperator();
|
||||
flying = cache.isFlying();
|
||||
}
|
||||
} else {
|
||||
operator = player.isOp();
|
||||
flying = player.isFlying();
|
||||
|
||||
// Check whether groups are supported
|
||||
if (permsMan.hasGroupSupport())
|
||||
playerGroup = permsMan.getPrimaryGroup(player);
|
||||
}
|
||||
|
||||
if (Settings.isForceSurvivalModeEnabled) {
|
||||
if (Settings.isResetInventoryIfCreative && gameMode == GameMode.CREATIVE) {
|
||||
ResetInventoryEvent event = new ResetInventoryEvent(player);
|
||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||
if (!event.isCancelled()) {
|
||||
player.getInventory().clear();
|
||||
player.sendMessage("Your inventory has been cleaned!");
|
||||
}
|
||||
}
|
||||
if (gameMode == GameMode.CREATIVE) {
|
||||
flying = false;
|
||||
}
|
||||
gameMode = GameMode.SURVIVAL;
|
||||
}
|
||||
if (player.isDead()) {
|
||||
loc = plugin.getSpawnLocation(player);
|
||||
}
|
||||
cache.put(name, new LimboPlayer(name, loc, gameMode, operator, playerGroup, flying));
|
||||
|
||||
cache.put(name, new LimboPlayer(name, loc, operator, playerGroup));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,6 +1,5 @@
|
||||
package fr.xephi.authme.cache.limbo;
|
||||
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
@ -12,29 +11,23 @@ public class LimboPlayer {
|
||||
private Location loc = null;
|
||||
private BukkitTask timeoutTaskId = null;
|
||||
private BukkitTask messageTaskId = null;
|
||||
private GameMode gameMode = GameMode.SURVIVAL;
|
||||
private boolean operator = false;
|
||||
private String group = "";
|
||||
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,
|
||||
boolean operator, String group, boolean flying) {
|
||||
public LimboPlayer(String name, Location loc,
|
||||
boolean operator, String group) {
|
||||
this.name = name;
|
||||
this.loc = loc;
|
||||
this.gameMode = gameMode;
|
||||
this.operator = operator;
|
||||
this.group = group;
|
||||
this.flying = flying;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -66,15 +59,6 @@ public class LimboPlayer {
|
||||
return loc;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method getGameMode.
|
||||
*
|
||||
* @return GameMode
|
||||
*/
|
||||
public GameMode getGameMode() {
|
||||
return gameMode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method getOperator.
|
||||
*
|
||||
@ -149,13 +133,4 @@ public class LimboPlayer {
|
||||
}
|
||||
timeoutTaskId = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method isFlying.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public boolean isFlying() {
|
||||
return flying;
|
||||
}
|
||||
}
|
||||
|
@ -6,9 +6,9 @@ package fr.xephi.authme.command;
|
||||
public class CommandArgumentDescription {
|
||||
|
||||
/**
|
||||
* Argument label (one-word description of the argument).
|
||||
* Argument name (one-word description of the argument).
|
||||
*/
|
||||
private final String label;
|
||||
private final String name;
|
||||
/**
|
||||
* Argument description.
|
||||
*/
|
||||
@ -21,23 +21,23 @@ public class CommandArgumentDescription {
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param label The argument label.
|
||||
* @param name The argument name.
|
||||
* @param description The argument description.
|
||||
* @param isOptional True if the argument is optional, false otherwise.
|
||||
*/
|
||||
public CommandArgumentDescription(String label, String description, boolean isOptional) {
|
||||
this.label = label;
|
||||
public CommandArgumentDescription(String name, String description, boolean isOptional) {
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.isOptional = isOptional;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the argument label.
|
||||
* Get the argument name.
|
||||
*
|
||||
* @return Argument label.
|
||||
* @return Argument name.
|
||||
*/
|
||||
public String getLabel() {
|
||||
return this.label;
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -4,22 +4,21 @@ import fr.xephi.authme.permission.DefaultPermission;
|
||||
import fr.xephi.authme.permission.PermissionNode;
|
||||
import fr.xephi.authme.util.CollectionUtils;
|
||||
import fr.xephi.authme.util.StringUtils;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static java.util.Arrays.asList;
|
||||
|
||||
/**
|
||||
* Command description - defines which labels ("names") will lead to a command and points to the
|
||||
* Command description – defines which labels ("names") will lead to a command and points to the
|
||||
* {@link ExecutableCommand} implementation that executes the logic of the command.
|
||||
*
|
||||
* CommandDescription instances are 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.
|
||||
* CommandDescription instances are built hierarchically: they have one parent, or {@code null} for base commands
|
||||
* (main commands such as {@code /authme}), and may have multiple children extending the mapping of the parent: e.g. if
|
||||
* {@code /authme} has a child whose label is {@code "register"}, then {@code /authme register} is the command that
|
||||
* the child defines.
|
||||
*/
|
||||
public class CommandDescription {
|
||||
|
||||
@ -29,15 +28,15 @@ public class CommandDescription {
|
||||
*/
|
||||
private List<String> labels;
|
||||
/**
|
||||
* Command description.
|
||||
* Short description of the command.
|
||||
*/
|
||||
private String description;
|
||||
/**
|
||||
* Detailed description of the command.
|
||||
* Detailed description of what the command does.
|
||||
*/
|
||||
private String detailedDescription;
|
||||
/**
|
||||
* The executable command instance.
|
||||
* The executable command instance described by this object.
|
||||
*/
|
||||
private ExecutableCommand executableCommand;
|
||||
/**
|
||||
@ -53,7 +52,7 @@ public class CommandDescription {
|
||||
*/
|
||||
private List<CommandArgumentDescription> arguments;
|
||||
/**
|
||||
* Defines the command permissions.
|
||||
* Command permissions required to execute this command.
|
||||
*/
|
||||
private CommandPermissions permissions;
|
||||
|
||||
@ -67,7 +66,7 @@ public class CommandDescription {
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an instance for internal use.
|
||||
* Create an instance.
|
||||
*
|
||||
* @param labels List of command labels.
|
||||
* @param description Command description.
|
||||
@ -99,58 +98,30 @@ public class CommandDescription {
|
||||
return instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the label most similar to the reference. The first label will be returned if no reference was supplied.
|
||||
*
|
||||
* @param reference The command reference.
|
||||
*
|
||||
* @return The most similar label, or the first label. An empty label will be returned if no label was set.
|
||||
*/
|
||||
public String getLabel(CommandParts reference) {
|
||||
// Ensure there's any item in the command list
|
||||
if (this.labels.size() == 0)
|
||||
return "";
|
||||
|
||||
// Return the first label if we can't use the reference
|
||||
if (reference == null)
|
||||
return this.labels.get(0);
|
||||
|
||||
// Get the correct label from the reference
|
||||
String preferred = reference.get(getParentCount());
|
||||
|
||||
// Check whether the preferred label is in the label list
|
||||
double currentDifference = -1;
|
||||
String currentLabel = this.labels.get(0);
|
||||
for (String entry : this.labels) {
|
||||
double entryDifference = StringUtils.getDifference(entry, preferred);
|
||||
if (entryDifference < currentDifference || currentDifference < 0) {
|
||||
currentDifference = entryDifference;
|
||||
currentLabel = entry;
|
||||
}
|
||||
}
|
||||
|
||||
// Return the most similar label
|
||||
return currentLabel;
|
||||
private void addChild(CommandDescription command) {
|
||||
children.add(command);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all relative command labels.
|
||||
* Return all relative labels of this command. For example, if this object describes {@code /authme register} and
|
||||
* {@code /authme r}, then it will return a list with {@code register} and {@code r}. The parent label
|
||||
* {@code authme} is not returned.
|
||||
*
|
||||
* @return All relative labels labels.
|
||||
* @return All labels of the command description.
|
||||
*/
|
||||
public List<String> getLabels() {
|
||||
return this.labels;
|
||||
return labels;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether this command description has a specific command.
|
||||
*
|
||||
* @param commandLabel Command to check for.
|
||||
* @param commandLabel The label to check for.
|
||||
*
|
||||
* @return True if this command label equals to the param command.
|
||||
* @return {@code true} if this command contains the given label, {@code false} otherwise.
|
||||
*/
|
||||
public boolean hasLabel(String commandLabel) {
|
||||
for (String label : this.labels) {
|
||||
for (String label : labels) {
|
||||
if (label.equalsIgnoreCase(commandLabel)) {
|
||||
return true;
|
||||
}
|
||||
@ -159,263 +130,55 @@ public class CommandDescription {
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether this command label is applicable with a command reference. This doesn't check if the parent
|
||||
* are suitable too.
|
||||
* Return the {@link ExecutableCommand} instance defined by the command description.
|
||||
*
|
||||
* @param commandReference The command reference.
|
||||
*
|
||||
* @return True if the command reference is suitable to this command label, false otherwise.
|
||||
*/
|
||||
public boolean isSuitableLabel(CommandParts commandReference) {
|
||||
// Get the parent count
|
||||
//getParent() = getParent().getParentCount() + 1
|
||||
String element = commandReference.get(getParentCount());
|
||||
|
||||
// Check whether this command description has this command label
|
||||
for (String label : labels) {
|
||||
if (label.equalsIgnoreCase(element)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the command reference.
|
||||
*
|
||||
* @param reference The reference to use as template, which is used to choose the most similar reference.
|
||||
*
|
||||
* @return Command reference.
|
||||
*/
|
||||
public CommandParts getCommandReference(CommandParts reference) {
|
||||
// Build the reference
|
||||
List<String> referenceList = new ArrayList<>();
|
||||
|
||||
// Check whether this command has a parent, if so, add the absolute parent command
|
||||
if (getParent() != null) {
|
||||
referenceList.addAll(getParent().getCommandReference(reference).getList());
|
||||
}
|
||||
|
||||
// Get the current label
|
||||
referenceList.add(getLabel(reference));
|
||||
|
||||
// Return the reference
|
||||
return new CommandParts(referenceList);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the difference between this command and another command reference.
|
||||
*
|
||||
* @param other The other command reference.
|
||||
*
|
||||
* @return The command difference. Zero if there's no difference. A negative number on error.
|
||||
*/
|
||||
public double getCommandDifference(CommandParts other) {
|
||||
return getCommandDifference(other, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the difference between this command and another command reference.
|
||||
*
|
||||
* @param other The other command reference.
|
||||
* @param fullCompare True to fully compare both command references.
|
||||
*
|
||||
* @return The command difference. Zero if there's no difference. A negative number on error.
|
||||
*/
|
||||
public double getCommandDifference(CommandParts other, boolean fullCompare) {
|
||||
// Make sure the reference is valid
|
||||
if (other == null)
|
||||
return -1;
|
||||
|
||||
// Get the command reference
|
||||
CommandParts reference = getCommandReference(other);
|
||||
|
||||
// Compare the two references, return the result
|
||||
return CommandUtils.getDifference(reference.getList(),
|
||||
CollectionUtils.getRange(other.getList(), 0, reference.getList().size()), fullCompare);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the executable command.
|
||||
*
|
||||
* @return The executable command.
|
||||
* @return The executable command object.
|
||||
*/
|
||||
public ExecutableCommand getExecutableCommand() {
|
||||
return this.executableCommand;
|
||||
return executableCommand;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the executable command.
|
||||
* Return the parent.
|
||||
*
|
||||
* @param executableCommand The executable command.
|
||||
*/
|
||||
public void setExecutableCommand(ExecutableCommand executableCommand) {
|
||||
this.executableCommand = executableCommand;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the command, if possible.
|
||||
*
|
||||
* @param sender The command sender that triggered the execution of this command.
|
||||
* @param commandReference The command reference.
|
||||
* @param commandArguments The command arguments.
|
||||
*
|
||||
* @return True on success, false on failure.
|
||||
*/
|
||||
public boolean execute(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
||||
// Execute the command, return the result
|
||||
return getExecutableCommand().executeCommand(sender, commandReference, commandArguments);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the parent command if this command description has a parent.
|
||||
*
|
||||
* @return Parent command, or null
|
||||
* @return The parent command, or null for base commands.
|
||||
*/
|
||||
public CommandDescription getParent() {
|
||||
return this.parent;
|
||||
return parent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of parent this description has.
|
||||
* Return the number of labels necessary to get to this command. This corresponds to the number of parents + 1.
|
||||
*
|
||||
* @return The number of parents.
|
||||
* @return The number of labels, e.g. for "/authme abc def" the label count is 3
|
||||
*/
|
||||
public int getParentCount() {
|
||||
// Check whether the this description has a parent
|
||||
if (!hasParent())
|
||||
return 0;
|
||||
|
||||
// Get the parent count of the parent, return the result
|
||||
return getParent().getParentCount() + 1;
|
||||
public int getLabelCount() {
|
||||
if (parent == null) {
|
||||
return 1;
|
||||
}
|
||||
return parent.getLabelCount() + 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the parent command.
|
||||
*
|
||||
* @param parent Parent command.
|
||||
*
|
||||
* @return True on success, false on failure.
|
||||
*/
|
||||
public boolean setParent(CommandDescription parent) {
|
||||
// Make sure the parent is different
|
||||
if (this.parent == parent)
|
||||
return true;
|
||||
|
||||
// Set the parent
|
||||
this.parent = parent;
|
||||
|
||||
// Make sure the parent isn't null
|
||||
if (parent == null)
|
||||
return true;
|
||||
|
||||
// Add this description as a child to the parent
|
||||
return parent.addChild(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether the plugin description has a parent command.
|
||||
*
|
||||
* @return True if the description has a parent command, false otherwise.
|
||||
*/
|
||||
public boolean hasParent() {
|
||||
return this.parent != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all command children.
|
||||
* Return all command children.
|
||||
*
|
||||
* @return Command children.
|
||||
*/
|
||||
public List<CommandDescription> getChildren() {
|
||||
return this.children;
|
||||
return children;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a child to the command description.
|
||||
*
|
||||
* @param commandDescription The child to add.
|
||||
*
|
||||
* @return True on success, false on failure.
|
||||
*/
|
||||
public boolean addChild(CommandDescription commandDescription) {
|
||||
// Make sure the description is valid
|
||||
if (commandDescription == null)
|
||||
return false;
|
||||
|
||||
// Make sure the child doesn't exist already
|
||||
if (isChild(commandDescription))
|
||||
return true;
|
||||
|
||||
// The command description to add as a child
|
||||
if (!this.children.add(commandDescription))
|
||||
return false;
|
||||
|
||||
// Set this description as parent on the child
|
||||
return commandDescription.setParent(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether this command has any child labels.
|
||||
*
|
||||
* @return True if this command has any child labels.
|
||||
*/
|
||||
public boolean hasChildren() {
|
||||
return (this.children.size() != 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if this command description has a specific child.
|
||||
*
|
||||
* @param commandDescription The command description to check for.
|
||||
*
|
||||
* @return True if this command description has the specific child, false otherwise.
|
||||
*/
|
||||
public boolean isChild(CommandDescription commandDescription) {
|
||||
// Make sure the description is valid
|
||||
if (commandDescription == null)
|
||||
return false;
|
||||
|
||||
// Check whether this child exists, return the result
|
||||
return this.children.contains(commandDescription);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an argument.
|
||||
*
|
||||
* @param argument The argument to add.
|
||||
*
|
||||
* @return True if succeed, false if failed.
|
||||
*/
|
||||
public boolean addArgument(CommandArgumentDescription argument) {
|
||||
// Make sure the argument is valid
|
||||
if (argument == null)
|
||||
return false;
|
||||
|
||||
// Add the argument, return the result
|
||||
return this.arguments.add(argument);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all command arguments.
|
||||
* Return all arguments the command takes.
|
||||
*
|
||||
* @return Command arguments.
|
||||
*/
|
||||
public List<CommandArgumentDescription> getArguments() {
|
||||
return this.arguments;
|
||||
return arguments;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether this command has any arguments.
|
||||
*
|
||||
* @return True if this command has any arguments.
|
||||
*/
|
||||
public boolean hasArguments() {
|
||||
return !getArguments().isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the command description.
|
||||
* Return a short description of the command.
|
||||
*
|
||||
* @return Command description.
|
||||
*/
|
||||
@ -424,119 +187,28 @@ public class CommandDescription {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the command detailed description.
|
||||
* Return a detailed description of the command.
|
||||
*
|
||||
* @return Command detailed description.
|
||||
* @return Detailed description.
|
||||
*/
|
||||
public String getDetailedDescription() {
|
||||
return detailedDescription;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the best suitable command for a query reference.
|
||||
* Return the permissions required to execute the command.
|
||||
*
|
||||
* @param queryReference The query reference to find a command for.
|
||||
*
|
||||
* @return The command found, or null.
|
||||
*/
|
||||
public FoundCommandResult findCommand(final CommandParts queryReference) {
|
||||
// Make sure the command reference is valid
|
||||
if (queryReference.getCount() <= 0)
|
||||
return null;
|
||||
|
||||
// Check whether this description is for the last element in the command reference, if so return the current command
|
||||
if (queryReference.getCount() <= getParentCount() + 1) {
|
||||
return new FoundCommandResult(
|
||||
this,
|
||||
getCommandReference(queryReference),
|
||||
new CommandParts(new ArrayList<String>()),
|
||||
queryReference);
|
||||
}
|
||||
|
||||
// Get the new command reference and arguments
|
||||
CommandParts newReference = new CommandParts(CollectionUtils.getRange(queryReference.getList(), 0, getParentCount() + 1));
|
||||
CommandParts newArguments = new CommandParts(CollectionUtils.getRange(queryReference.getList(), getParentCount() + 1));
|
||||
|
||||
// Handle the child's, if this command has any
|
||||
if (getChildren().size() > 0) {
|
||||
// Get a new instance of the child's list, and sort them by their difference in comparison to the query reference
|
||||
List<CommandDescription> commandChildren = new ArrayList<>(getChildren());
|
||||
Collections.sort(commandChildren, new Comparator<CommandDescription>() {
|
||||
@Override
|
||||
public int compare(CommandDescription o1, CommandDescription o2) {
|
||||
return Double.compare(
|
||||
o1.getCommandDifference(queryReference),
|
||||
o2.getCommandDifference(queryReference));
|
||||
}
|
||||
});
|
||||
|
||||
// Get the difference of the first child in the list
|
||||
double firstChildDifference = commandChildren.get(0).getCommandDifference(queryReference, true);
|
||||
|
||||
// Check if the reference perfectly suits the arguments of the current command if it doesn't perfectly suits a child command
|
||||
if (firstChildDifference > 0.0)
|
||||
if (getSuitableArgumentsDifference(queryReference) == 0)
|
||||
return new FoundCommandResult(this, newReference, newArguments, queryReference);
|
||||
|
||||
// Loop through each child
|
||||
for (CommandDescription child : commandChildren) {
|
||||
// Get the best suitable command
|
||||
FoundCommandResult result = child.findCommand(queryReference);
|
||||
if (result != null)
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
// Check if the remaining command reference elements fit the arguments for this command
|
||||
if (getSuitableArgumentsDifference(queryReference) >= 0)
|
||||
return new FoundCommandResult(this, newReference, newArguments, queryReference);
|
||||
|
||||
// No command found, return null
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the remaining command reference elements are suitable with arguments of the current command description,
|
||||
* and get the difference in argument count.
|
||||
*
|
||||
* @param commandReference The command reference.
|
||||
*
|
||||
* @return The difference in argument count between the reference and the actual command.
|
||||
*/
|
||||
public int getSuitableArgumentsDifference(CommandParts commandReference) {
|
||||
// Make sure the command reference is valid
|
||||
if (commandReference.getCount() <= 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Get the remaining command reference element count
|
||||
int remainingElementCount = commandReference.getCount() - getParentCount() - 1;
|
||||
|
||||
// Check if there are too few arguments
|
||||
int minArguments = CommandUtils.getMinNumberOfArguments(this);
|
||||
if (minArguments > remainingElementCount) {
|
||||
return Math.abs(minArguments - remainingElementCount);
|
||||
}
|
||||
|
||||
// Check if there are too many arguments
|
||||
int maxArguments = CommandUtils.getMaxNumberOfArguments(this);
|
||||
if (maxArguments >= 0 && maxArguments < remainingElementCount) {
|
||||
return Math.abs(remainingElementCount - maxArguments);
|
||||
}
|
||||
|
||||
// The argument count is the same
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the command permissions. Return null if the command doesn't require any permission.
|
||||
*
|
||||
* @return The command permissions.
|
||||
* @return The command permissions, or null if none are required to execute the command.
|
||||
*/
|
||||
public CommandPermissions getCommandPermissions() {
|
||||
return this.permissions;
|
||||
return permissions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a builder instance to create a new command description.
|
||||
*
|
||||
* @return The builder
|
||||
*/
|
||||
public static CommandBuilder builder() {
|
||||
return new CommandBuilder();
|
||||
}
|
||||
@ -554,21 +226,20 @@ public class CommandDescription {
|
||||
private CommandPermissions permissions;
|
||||
|
||||
/**
|
||||
* Build a CommandDescription from the builder or throw an exception if mandatory
|
||||
* fields have not been set.
|
||||
* Build a CommandDescription from the builder or throw an exception if a mandatory
|
||||
* field has not been set.
|
||||
*
|
||||
* @return The generated CommandDescription object
|
||||
*/
|
||||
public CommandDescription build() {
|
||||
return createInstance(
|
||||
getOrThrow(labels, "labels"),
|
||||
firstNonNull(description, ""),
|
||||
firstNonNull(detailedDescription, ""),
|
||||
getOrThrow(executableCommand, "executableCommand"),
|
||||
firstNonNull(parent, null),
|
||||
arguments,
|
||||
firstNonNull(permissions, null)
|
||||
);
|
||||
checkArgument(!CollectionUtils.isEmpty(labels), "Labels may not be empty");
|
||||
checkArgument(!StringUtils.isEmpty(description), "Description may not be empty");
|
||||
checkArgument(!StringUtils.isEmpty(detailedDescription), "Detailed description may not be empty");
|
||||
checkArgument(executableCommand != null, "Executable command must be set");
|
||||
// parents and permissions may be null; arguments may be empty
|
||||
|
||||
return createInstance(labels, description, detailedDescription, executableCommand,
|
||||
parent, arguments, permissions);
|
||||
}
|
||||
|
||||
public CommandBuilder labels(List<String> labels) {
|
||||
@ -577,7 +248,7 @@ public class CommandDescription {
|
||||
}
|
||||
|
||||
public CommandBuilder labels(String... labels) {
|
||||
return labels(asMutableList(labels));
|
||||
return labels(asList(labels));
|
||||
}
|
||||
|
||||
public CommandBuilder description(String description) {
|
||||
@ -606,7 +277,7 @@ public class CommandDescription {
|
||||
*
|
||||
* @param label The label of the argument (single word name of the argument)
|
||||
* @param description The description of the argument
|
||||
* @param isOptional True if the argument is option, false if it is mandatory
|
||||
* @param isOptional True if the argument is optional, false if it is mandatory
|
||||
*
|
||||
* @return The builder
|
||||
*/
|
||||
@ -617,37 +288,9 @@ public class CommandDescription {
|
||||
|
||||
public CommandBuilder permissions(DefaultPermission defaultPermission,
|
||||
PermissionNode... permissionNodes) {
|
||||
this.permissions = new CommandPermissions(asMutableList(permissionNodes), defaultPermission);
|
||||
this.permissions = new CommandPermissions(asList(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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,15 +1,14 @@
|
||||
package fr.xephi.authme.command;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.command.help.HelpProvider;
|
||||
import fr.xephi.authme.util.CollectionUtils;
|
||||
import fr.xephi.authme.util.StringUtils;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.command.help.HelpProvider;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import fr.xephi.authme.util.StringUtils;
|
||||
|
||||
/**
|
||||
* The AuthMe command handler, responsible for mapping incoming commands to the correct {@link CommandDescription}
|
||||
@ -17,78 +16,75 @@ import java.util.Set;
|
||||
*/
|
||||
public class CommandHandler {
|
||||
|
||||
/**
|
||||
* The threshold for assuming an existing command. If the difference is below this value, we assume
|
||||
* that the user meant the similar command and we will run it.
|
||||
*/
|
||||
private static final double ASSUME_COMMAND_THRESHOLD = 0.12;
|
||||
|
||||
/**
|
||||
* The threshold for suggesting a similar command. If the difference is below this value, we will
|
||||
* ask the player whether he meant the similar command.
|
||||
*/
|
||||
private static final double SUGGEST_COMMAND_THRESHOLD = 0.75;
|
||||
|
||||
private final Set<CommandDescription> commands;
|
||||
private final CommandService commandService;
|
||||
|
||||
/**
|
||||
* Create a command handler.
|
||||
*
|
||||
* @param commands The collection of available AuthMe commands
|
||||
*
|
||||
* @param commandService The CommandService instance
|
||||
*/
|
||||
public CommandHandler(Set<CommandDescription> commands) {
|
||||
this.commands = commands;
|
||||
public CommandHandler(CommandService commandService) {
|
||||
this.commandService = commandService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Map a command that was invoked to the proper {@link CommandDescription} or return a useful error
|
||||
* message upon failure.
|
||||
*
|
||||
* @param sender The command sender (Bukkit).
|
||||
* @param sender The command sender.
|
||||
* @param bukkitCommandLabel The command label (Bukkit).
|
||||
* @param bukkitArgs The command arguments (Bukkit).
|
||||
*
|
||||
* @return True if the command was executed, false otherwise.
|
||||
*/
|
||||
public boolean processCommand(CommandSender sender, String bukkitCommandLabel, String[] bukkitArgs) {
|
||||
List<String> commandArgs = skipEmptyArguments(bukkitArgs);
|
||||
// Add the Bukkit command label to the front so we get a list like [authme, register, pass, passConfirm]
|
||||
commandArgs.add(0, bukkitCommandLabel);
|
||||
// Add the Bukkit command label to the front so we get a list like [authme, register, bobby, mysecret]
|
||||
List<String> parts = skipEmptyArguments(bukkitArgs);
|
||||
parts.add(0, bukkitCommandLabel);
|
||||
|
||||
// TODO: remove commandParts
|
||||
CommandParts commandReference = new CommandParts(commandArgs);
|
||||
FoundCommandResult result = commandService.mapPartsToCommand(sender, parts);
|
||||
handleCommandResult(sender, result);
|
||||
return !FoundResultStatus.MISSING_BASE_COMMAND.equals(result.getResultStatus());
|
||||
}
|
||||
|
||||
// Get a suitable command for this reference, and make sure it isn't null
|
||||
FoundCommandResult result = findCommand(commandReference);
|
||||
if (result == null) {
|
||||
// TODO ljacqu 20151204: Log more information to the console (bukkitCommandLabel)
|
||||
sender.sendMessage(ChatColor.DARK_RED + "Failed to parse " + AuthMe.getPluginName() + " command!");
|
||||
return false;
|
||||
private void handleCommandResult(CommandSender sender, FoundCommandResult result) {
|
||||
switch (result.getResultStatus()) {
|
||||
case SUCCESS:
|
||||
executeCommand(sender, result);
|
||||
break;
|
||||
case MISSING_BASE_COMMAND:
|
||||
sender.sendMessage(ChatColor.DARK_RED + "Failed to parse " + AuthMe.getPluginName() + " command!");
|
||||
break;
|
||||
case INCORRECT_ARGUMENTS:
|
||||
sendImproperArgumentsMessage(sender, result);
|
||||
break;
|
||||
case UNKNOWN_LABEL:
|
||||
sendUnknownCommandMessage(sender, result);
|
||||
break;
|
||||
case NO_PERMISSION:
|
||||
sendPermissionDeniedError(sender);
|
||||
break;
|
||||
default:
|
||||
throw new IllegalStateException("Unknown result status '" + result.getResultStatus() + "'");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
String baseCommand = commandArgs.get(0);
|
||||
|
||||
// Make sure the difference between the command reference and the actual command isn't too big
|
||||
final double commandDifference = result.getDifference();
|
||||
if (commandDifference <= ASSUME_COMMAND_THRESHOLD) {
|
||||
|
||||
// Show a message when the command handler is assuming a command
|
||||
if (commandDifference > 0) {
|
||||
sendCommandAssumptionMessage(sender, result, commandReference);
|
||||
}
|
||||
|
||||
if (!result.hasPermission(sender)) {
|
||||
sender.sendMessage(ChatColor.DARK_RED + "You don't have permission to use this command!");
|
||||
} else if (!result.hasProperArguments()) {
|
||||
sendImproperArgumentsMessage(sender, result, commandReference, baseCommand);
|
||||
} else {
|
||||
return result.executeCommand(sender);
|
||||
}
|
||||
} else {
|
||||
sendUnknownCommandMessage(sender, commandDifference, result, baseCommand);
|
||||
}
|
||||
return true;
|
||||
/**
|
||||
* Execute the command for the given command sender.
|
||||
*
|
||||
* @param sender The sender which initiated the command
|
||||
* @param result The mapped result
|
||||
*/
|
||||
private void executeCommand(CommandSender sender, FoundCommandResult result) {
|
||||
ExecutableCommand executableCommand = result.getCommandDescription().getExecutableCommand();
|
||||
List<String> arguments = result.getArguments();
|
||||
executableCommand.executeCommand(sender, arguments, commandService);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -98,7 +94,7 @@ public class CommandHandler {
|
||||
* @return List of the items that are not empty
|
||||
*/
|
||||
private static List<String> skipEmptyArguments(String[] args) {
|
||||
List<String> cleanArguments = new ArrayList<>(args.length);
|
||||
List<String> cleanArguments = new ArrayList<>();
|
||||
for (String argument : args) {
|
||||
if (!StringUtils.isEmpty(argument)) {
|
||||
cleanArguments.add(argument);
|
||||
@ -107,131 +103,46 @@ public class CommandHandler {
|
||||
return cleanArguments;
|
||||
}
|
||||
|
||||
|
||||
private static CommandDescription mapToBase(String commandLabel) {
|
||||
for (CommandDescription command : CommandInitializer.getBaseCommands()) {
|
||||
if (command.getLabels().contains(commandLabel)) {
|
||||
return command;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the best suitable command for the specified reference.
|
||||
*
|
||||
* @param queryReference The query reference to find a command for.
|
||||
*
|
||||
* @return The command found, or null.
|
||||
*/
|
||||
public FoundCommandResult findCommand(CommandParts queryReference) {
|
||||
// Make sure the command reference is valid
|
||||
if (queryReference.getCount() <= 0)
|
||||
return null;
|
||||
|
||||
for (CommandDescription commandDescription : commands) {
|
||||
// Check whether there's a command description available for the
|
||||
// current command
|
||||
if (!commandDescription.isSuitableLabel(queryReference))
|
||||
continue;
|
||||
|
||||
// Find the command reference, return the result
|
||||
return commandDescription.findCommand(queryReference);
|
||||
}
|
||||
|
||||
// No applicable command description found, return false
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the best suitable command for the specified reference.
|
||||
*
|
||||
* @param commandParts The query reference to find a command for.
|
||||
*
|
||||
* @return The command found, or null.
|
||||
*/
|
||||
private CommandDescription findCommand(List<String> commandParts) {
|
||||
// Make sure the command reference is valid
|
||||
if (commandParts.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// TODO ljacqu 20151129: Since we only use .contains() on the CommandDescription#labels after init, change
|
||||
// the type to set for faster lookup
|
||||
Iterable<CommandDescription> commandsToScan = CommandInitializer.getBaseCommands();
|
||||
CommandDescription result = null;
|
||||
for (String label : commandParts) {
|
||||
result = findLabel(label, commandsToScan);
|
||||
if (result == null) {
|
||||
return null;
|
||||
}
|
||||
commandsToScan = result.getChildren();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static CommandDescription findLabel(String label, Iterable<CommandDescription> commands) {
|
||||
if (commands == null) {
|
||||
return null;
|
||||
}
|
||||
for (CommandDescription command : commands) {
|
||||
if (command.getLabels().contains(label)) { // TODO ljacqu should be case-insensitive
|
||||
return command;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show an "unknown command" to the user and suggests an existing command if its similarity is within
|
||||
* Show an "unknown command" message to the user and suggest an existing command if its similarity is within
|
||||
* the defined threshold.
|
||||
*
|
||||
* @param sender The command sender
|
||||
* @param commandDifference The difference between the invoked command and the existing one
|
||||
* @param result The command that was found during the mapping process
|
||||
* @param baseCommand The base command (TODO: This is probably already in FoundCommandResult)
|
||||
*/
|
||||
private static void sendUnknownCommandMessage(CommandSender sender, double commandDifference,
|
||||
FoundCommandResult result, String baseCommand) {
|
||||
CommandParts commandReference = result.getCommandReference();
|
||||
private static void sendUnknownCommandMessage(CommandSender sender, FoundCommandResult result) {
|
||||
sender.sendMessage(ChatColor.DARK_RED + "Unknown command!");
|
||||
|
||||
|
||||
// Show a command suggestion if available and the difference isn't too big
|
||||
if (commandDifference < SUGGEST_COMMAND_THRESHOLD && result.getCommandDescription() != null) {
|
||||
sender.sendMessage(ChatColor.YELLOW + "Did you mean " + ChatColor.GOLD + "/"
|
||||
+ result.getCommandDescription().getCommandReference(commandReference) + ChatColor.YELLOW + "?");
|
||||
if (result.getDifference() <= SUGGEST_COMMAND_THRESHOLD && result.getCommandDescription() != null) {
|
||||
sender.sendMessage(ChatColor.YELLOW + "Did you mean " + ChatColor.GOLD
|
||||
+ CommandUtils.constructCommandPath(result.getCommandDescription()) + ChatColor.YELLOW + "?");
|
||||
}
|
||||
|
||||
sender.sendMessage(ChatColor.YELLOW + "Use the command " + ChatColor.GOLD + "/" + baseCommand + " help"
|
||||
+ ChatColor.YELLOW + " to view help.");
|
||||
sender.sendMessage(ChatColor.YELLOW + "Use the command " + ChatColor.GOLD + "/" + result.getLabels().get(0)
|
||||
+ " help" + ChatColor.YELLOW + " to view help.");
|
||||
}
|
||||
|
||||
private static void sendImproperArgumentsMessage(CommandSender sender, FoundCommandResult result,
|
||||
CommandParts commandReference, String baseCommand) {
|
||||
// Get the command and the suggested command reference
|
||||
List<String> suggestedCommandReference =
|
||||
result.getCommandDescription().getCommandReference(commandReference).getList();
|
||||
List<String> helpCommandReference = CollectionUtils.getRange(suggestedCommandReference, 1);
|
||||
|
||||
// Show the invalid arguments warning
|
||||
sender.sendMessage(ChatColor.DARK_RED + "Incorrect command arguments!");
|
||||
private void sendImproperArgumentsMessage(CommandSender sender, FoundCommandResult result) {
|
||||
CommandDescription command = result.getCommandDescription();
|
||||
if (!commandService.getPermissionsManager().hasPermission(sender, command)) {
|
||||
sendPermissionDeniedError(sender);
|
||||
return;
|
||||
}
|
||||
|
||||
// Show the command argument help
|
||||
HelpProvider.showHelp(sender, commandReference, new CommandParts(suggestedCommandReference),
|
||||
true, false, true, false, false, false);
|
||||
sender.sendMessage(ChatColor.DARK_RED + "Incorrect command arguments!");
|
||||
commandService.outputHelp(sender, result, HelpProvider.SHOW_ARGUMENTS);
|
||||
|
||||
// Show the command to use for detailed help
|
||||
sender.sendMessage(ChatColor.GOLD + "Detailed help: " + ChatColor.WHITE + "/" + baseCommand
|
||||
+ " help " + CommandUtils.labelsToString(helpCommandReference));
|
||||
List<String> labels = result.getLabels();
|
||||
String childLabel = labels.size() >= 2 ? labels.get(1) : "";
|
||||
sender.sendMessage(ChatColor.GOLD + "Detailed help: " + ChatColor.WHITE
|
||||
+ "/" + labels.get(0) + " help " + childLabel);
|
||||
}
|
||||
|
||||
private static void sendCommandAssumptionMessage(CommandSender sender, FoundCommandResult result,
|
||||
CommandParts commandReference) {
|
||||
List<String> assumedCommandParts =
|
||||
result.getCommandDescription().getCommandReference(commandReference).getList();
|
||||
|
||||
sender.sendMessage(ChatColor.DARK_RED + "Unknown command, assuming " + ChatColor.GOLD + "/"
|
||||
+ CommandUtils.labelsToString(assumedCommandParts) + ChatColor.DARK_RED + "!");
|
||||
// TODO ljacqu 20151212: Remove me once I am a MessageKey
|
||||
private static void sendPermissionDeniedError(CommandSender sender) {
|
||||
sender.sendMessage(ChatColor.DARK_RED + "You don't have permission to use this command!");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,9 +1,11 @@
|
||||
package fr.xephi.authme.command;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import fr.xephi.authme.command.executable.HelpCommand;
|
||||
import fr.xephi.authme.command.executable.authme.AccountsCommand;
|
||||
import fr.xephi.authme.command.executable.authme.AuthMeCommand;
|
||||
import fr.xephi.authme.command.executable.authme.ChangePasswordAdminCommand;
|
||||
import fr.xephi.authme.command.executable.authme.ConverterCommand;
|
||||
import fr.xephi.authme.command.executable.authme.FirstSpawnCommand;
|
||||
import fr.xephi.authme.command.executable.authme.ForceLoginCommand;
|
||||
import fr.xephi.authme.command.executable.authme.GetEmailCommand;
|
||||
@ -23,9 +25,9 @@ import fr.xephi.authme.command.executable.authme.UnregisterAdminCommand;
|
||||
import fr.xephi.authme.command.executable.authme.VersionCommand;
|
||||
import fr.xephi.authme.command.executable.captcha.CaptchaCommand;
|
||||
import fr.xephi.authme.command.executable.changepassword.ChangePasswordCommand;
|
||||
import fr.xephi.authme.command.executable.converter.ConverterCommand;
|
||||
import fr.xephi.authme.command.executable.email.AddEmailCommand;
|
||||
import fr.xephi.authme.command.executable.email.ChangeEmailCommand;
|
||||
import fr.xephi.authme.command.executable.email.EmailBaseCommand;
|
||||
import fr.xephi.authme.command.executable.email.RecoverEmailCommand;
|
||||
import fr.xephi.authme.command.executable.login.LoginCommand;
|
||||
import fr.xephi.authme.command.executable.logout.LogoutCommand;
|
||||
@ -33,9 +35,11 @@ import fr.xephi.authme.command.executable.register.RegisterCommand;
|
||||
import fr.xephi.authme.command.executable.unregister.UnregisterCommand;
|
||||
import fr.xephi.authme.permission.AdminPermission;
|
||||
import fr.xephi.authme.permission.PlayerPermission;
|
||||
import fr.xephi.authme.util.Wrapper;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static fr.xephi.authme.permission.DefaultPermission.ALLOWED;
|
||||
import static fr.xephi.authme.permission.DefaultPermission.OP_ONLY;
|
||||
@ -45,25 +49,11 @@ import static fr.xephi.authme.permission.DefaultPermission.OP_ONLY;
|
||||
*/
|
||||
public final class CommandInitializer {
|
||||
|
||||
private static Set<CommandDescription> baseCommands;
|
||||
|
||||
private CommandInitializer() {
|
||||
// Helper class
|
||||
}
|
||||
|
||||
public static Set<CommandDescription> getBaseCommands() {
|
||||
if (baseCommands == null) {
|
||||
Wrapper.getInstance().getLogger().info("Initializing AuthMe commands");
|
||||
initializeCommands();
|
||||
}
|
||||
return baseCommands;
|
||||
}
|
||||
|
||||
private static void initializeCommands() {
|
||||
// Create a list of help command labels
|
||||
final List<String> helpCommandLabels = Arrays.asList("help", "hlp", "h", "sos", "?");
|
||||
final ExecutableCommand helpCommandExecutable = new HelpCommand();
|
||||
|
||||
public static Set<CommandDescription> buildCommands() {
|
||||
// Register the base AuthMe Reloaded command
|
||||
final CommandDescription AUTHME_BASE = CommandDescription.builder()
|
||||
.labels("authme")
|
||||
@ -72,16 +62,6 @@ public final class CommandInitializer {
|
||||
.executableCommand(new AuthMeCommand())
|
||||
.build();
|
||||
|
||||
// Register the help command
|
||||
CommandDescription.builder()
|
||||
.parent(AUTHME_BASE)
|
||||
.labels(helpCommandLabels)
|
||||
.description("View help")
|
||||
.detailedDescription("View detailed help pages about AuthMeReloaded commands.")
|
||||
.withArgument("query", "The command or query to view help for.", true)
|
||||
.executableCommand(helpCommandExecutable)
|
||||
.build();
|
||||
|
||||
// Register the register command
|
||||
CommandDescription.builder()
|
||||
.parent(AUTHME_BASE)
|
||||
@ -153,182 +133,173 @@ public final class CommandInitializer {
|
||||
// Register the getemail command
|
||||
CommandDescription.builder()
|
||||
.parent(AUTHME_BASE)
|
||||
.labels("getemail", "getmail", "email", "mail")
|
||||
.labels("email", "mail", "getemail", "getmail")
|
||||
.description("Display player's email")
|
||||
.detailedDescription("Display the email address of the specified player if set.")
|
||||
.permissions(OP_ONLY, AdminPermission.GET_EMAIL)
|
||||
.withArgument("player", "Player name", true)
|
||||
.permissions(OP_ONLY, AdminPermission.GET_EMAIL)
|
||||
.executableCommand(new GetEmailCommand())
|
||||
.build();
|
||||
|
||||
// Register the setemail command
|
||||
CommandDescription.builder()
|
||||
.executableCommand(new SetEmailCommand())
|
||||
.parent(AUTHME_BASE)
|
||||
.labels("chgemail", "chgmail", "setemail", "setmail")
|
||||
.labels("setemail", "setmail", "chgemail", "chgmail")
|
||||
.description("Change player's email")
|
||||
.detailedDescription("Change the email address of the specified player.")
|
||||
.permissions(OP_ONLY, AdminPermission.CHANGE_EMAIL)
|
||||
.withArgument("player", "Player name", false)
|
||||
.withArgument("email", "Player email", false)
|
||||
.permissions(OP_ONLY, AdminPermission.CHANGE_EMAIL)
|
||||
.executableCommand(new SetEmailCommand())
|
||||
.build();
|
||||
|
||||
// Register the getip command
|
||||
CommandDescription.builder()
|
||||
.executableCommand(new GetIpCommand())
|
||||
.parent(AUTHME_BASE)
|
||||
.labels("getip", "ip")
|
||||
.description("Get player's IP")
|
||||
.detailedDescription("Get the IP address of the specified online player.")
|
||||
.permissions(OP_ONLY, AdminPermission.GET_IP)
|
||||
.withArgument("player", "Player Name", false)
|
||||
.build();
|
||||
.parent(AUTHME_BASE)
|
||||
.labels("getip", "ip")
|
||||
.description("Get player's IP")
|
||||
.detailedDescription("Get the IP address of the specified online player.")
|
||||
.withArgument("player", "Player Name", false)
|
||||
.permissions(OP_ONLY, AdminPermission.GET_IP)
|
||||
.executableCommand(new GetIpCommand())
|
||||
.build();
|
||||
|
||||
// Register the spawn command
|
||||
CommandDescription.builder()
|
||||
.executableCommand(new SpawnCommand())
|
||||
.parent(AUTHME_BASE)
|
||||
.labels("spawn", "home")
|
||||
.description("Teleport to spawn")
|
||||
.detailedDescription("Teleport to the spawn.")
|
||||
.permissions(OP_ONLY, AdminPermission.SPAWN)
|
||||
.withArgument("player", "Player Name", false)
|
||||
.build();
|
||||
.parent(AUTHME_BASE)
|
||||
.labels("spawn", "home")
|
||||
.description("Teleport to spawn")
|
||||
.detailedDescription("Teleport to the spawn.")
|
||||
.withArgument("player", "Player Name", false)
|
||||
.permissions(OP_ONLY, AdminPermission.SPAWN)
|
||||
.executableCommand(new SpawnCommand())
|
||||
.build();
|
||||
|
||||
// Register the setspawn command
|
||||
CommandDescription.builder()
|
||||
.executableCommand(new SetSpawnCommand())
|
||||
.parent(AUTHME_BASE)
|
||||
.labels("setspawn", "chgspawn")
|
||||
.description("Change the spawn")
|
||||
.detailedDescription("Change the player's spawn to your current position.")
|
||||
.permissions(OP_ONLY, AdminPermission.SET_SPAWN)
|
||||
.build();
|
||||
.parent(AUTHME_BASE)
|
||||
.labels("setspawn", "chgspawn")
|
||||
.description("Change the spawn")
|
||||
.detailedDescription("Change the player's spawn to your current position.")
|
||||
.permissions(OP_ONLY, AdminPermission.SET_SPAWN)
|
||||
.executableCommand(new SetSpawnCommand())
|
||||
.build();
|
||||
|
||||
// Register the firstspawn command
|
||||
CommandDescription.builder()
|
||||
.executableCommand(new FirstSpawnCommand())
|
||||
.parent(AUTHME_BASE)
|
||||
.labels("firstspawn", "firsthome")
|
||||
.description("Teleport to first spawn")
|
||||
.detailedDescription("Teleport to the first spawn.")
|
||||
.permissions(OP_ONLY, AdminPermission.FIRST_SPAWN)
|
||||
.build();
|
||||
.parent(AUTHME_BASE)
|
||||
.labels("firstspawn", "firsthome")
|
||||
.description("Teleport to first spawn")
|
||||
.detailedDescription("Teleport to the first spawn.")
|
||||
.permissions(OP_ONLY, AdminPermission.FIRST_SPAWN)
|
||||
.executableCommand(new FirstSpawnCommand())
|
||||
.build();
|
||||
|
||||
// Register the setfirstspawn command
|
||||
CommandDescription.builder()
|
||||
.executableCommand(new SetFirstSpawnCommand())
|
||||
.parent(AUTHME_BASE)
|
||||
.labels("setfirstspawn", "chgfirstspawn")
|
||||
.description("Change the first spawn")
|
||||
.detailedDescription("Change the first player's spawn to your current position.")
|
||||
.permissions(OP_ONLY, AdminPermission.SET_FIRST_SPAWN)
|
||||
.build();
|
||||
.parent(AUTHME_BASE)
|
||||
.labels("setfirstspawn", "chgfirstspawn")
|
||||
.description("Change the first spawn")
|
||||
.detailedDescription("Change the first player's spawn to your current position.")
|
||||
.permissions(OP_ONLY, AdminPermission.SET_FIRST_SPAWN)
|
||||
.executableCommand(new SetFirstSpawnCommand())
|
||||
.build();
|
||||
|
||||
// Register the purge command
|
||||
CommandDescription.builder()
|
||||
.executableCommand(new PurgeCommand())
|
||||
.parent(AUTHME_BASE)
|
||||
.labels("purge", "delete")
|
||||
.description("Purge old data")
|
||||
.detailedDescription("Purge old AuthMeReloaded data longer than the specified amount of days ago.")
|
||||
.permissions(OP_ONLY, AdminPermission.PURGE)
|
||||
.withArgument("days", "Number of days", false)
|
||||
.build();
|
||||
.parent(AUTHME_BASE)
|
||||
.labels("purge", "delete")
|
||||
.description("Purge old data")
|
||||
.detailedDescription("Purge old AuthMeReloaded data longer than the specified amount of days ago.")
|
||||
.withArgument("days", "Number of days", false)
|
||||
.permissions(OP_ONLY, AdminPermission.PURGE)
|
||||
.executableCommand(new PurgeCommand())
|
||||
.build();
|
||||
|
||||
// Register the purgelastposition command
|
||||
CommandDescription.builder()
|
||||
.executableCommand(new PurgeLastPositionCommand())
|
||||
.parent(AUTHME_BASE)
|
||||
.labels("resetpos", "purgelastposition", "purgelastpos", "resetposition",
|
||||
"resetlastposition", "resetlastpos")
|
||||
.description("Purge player's last position")
|
||||
.detailedDescription("Purge the last know position of the specified player.")
|
||||
.permissions(OP_ONLY, AdminPermission.PURGE_LAST_POSITION)
|
||||
.withArgument("player", "Player name", false)
|
||||
.build();
|
||||
.parent(AUTHME_BASE)
|
||||
.labels("resetpos", "purgelastposition", "purgelastpos", "resetposition",
|
||||
"resetlastposition", "resetlastpos")
|
||||
.description("Purge player's last position")
|
||||
.detailedDescription("Purge the last know position of the specified player or all of them.")
|
||||
.withArgument("player/*", "Player name or * for all players", false)
|
||||
.permissions(OP_ONLY, AdminPermission.PURGE_LAST_POSITION)
|
||||
.executableCommand(new PurgeLastPositionCommand())
|
||||
.build();
|
||||
|
||||
// Register the purgebannedplayers command
|
||||
CommandDescription.builder()
|
||||
.executableCommand(new PurgeBannedPlayersCommand())
|
||||
.parent(AUTHME_BASE)
|
||||
.labels("purgebannedplayers", "purgebannedplayer", "deletebannedplayers", "deletebannedplayer")
|
||||
.description("Purge banned players data")
|
||||
.detailedDescription("Purge all AuthMeReloaded data for banned players.")
|
||||
.permissions(OP_ONLY, AdminPermission.PURGE_BANNED_PLAYERS)
|
||||
.build();
|
||||
.parent(AUTHME_BASE)
|
||||
.labels("purgebannedplayers", "purgebannedplayer", "deletebannedplayers", "deletebannedplayer")
|
||||
.description("Purge banned players data")
|
||||
.detailedDescription("Purge all AuthMeReloaded data for banned players.")
|
||||
.permissions(OP_ONLY, AdminPermission.PURGE_BANNED_PLAYERS)
|
||||
.executableCommand(new PurgeBannedPlayersCommand())
|
||||
.build();
|
||||
|
||||
// Register the switchantibot command
|
||||
CommandDescription.builder()
|
||||
.executableCommand(new SwitchAntiBotCommand())
|
||||
.parent(AUTHME_BASE)
|
||||
.labels("switchantibot", "toggleantibot", "antibot")
|
||||
.description("Switch AntiBot mode")
|
||||
.detailedDescription("Switch or toggle the AntiBot mode to the specified state.")
|
||||
.permissions(OP_ONLY, AdminPermission.SWITCH_ANTIBOT)
|
||||
.withArgument("mode", "ON / OFF", true)
|
||||
.build();
|
||||
.parent(AUTHME_BASE)
|
||||
.labels("switchantibot", "toggleantibot", "antibot")
|
||||
.description("Switch AntiBot mode")
|
||||
.detailedDescription("Switch or toggle the AntiBot mode to the specified state.")
|
||||
.withArgument("mode", "ON / OFF", true)
|
||||
.permissions(OP_ONLY, AdminPermission.SWITCH_ANTIBOT)
|
||||
.executableCommand(new SwitchAntiBotCommand())
|
||||
.build();
|
||||
|
||||
// Register the reload command
|
||||
CommandDescription.builder()
|
||||
.executableCommand(new ReloadCommand())
|
||||
.parent(AUTHME_BASE)
|
||||
.labels("reload", "rld")
|
||||
.description("Reload plugin")
|
||||
.detailedDescription("Reload the AuthMeReloaded plugin.")
|
||||
.permissions(OP_ONLY, AdminPermission.RELOAD)
|
||||
.build();
|
||||
.parent(AUTHME_BASE)
|
||||
.labels("reload", "rld")
|
||||
.description("Reload plugin")
|
||||
.detailedDescription("Reload the AuthMeReloaded plugin.")
|
||||
.permissions(OP_ONLY, AdminPermission.RELOAD)
|
||||
.executableCommand(new ReloadCommand())
|
||||
.build();
|
||||
|
||||
// Register the version command
|
||||
CommandDescription.builder()
|
||||
.parent(AUTHME_BASE)
|
||||
.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.")
|
||||
.detailedDescription("Show detailed information about the installed AuthMeReloaded version, the "
|
||||
+ "developers, contributors, and license.")
|
||||
.executableCommand(new VersionCommand())
|
||||
.build();
|
||||
|
||||
CommandDescription.builder()
|
||||
.parent(AUTHME_BASE)
|
||||
.labels("converter", "convert", "conv")
|
||||
.description("Converter Command")
|
||||
.detailedDescription("Converter command for AuthMeReloaded.")
|
||||
.withArgument("job", "Conversion job: xauth / crazylogin / rakamak / " +
|
||||
"royalauth / vauth / sqlitetosql", false)
|
||||
.permissions(OP_ONLY, AdminPermission.CONVERTER)
|
||||
.executableCommand(new ConverterCommand())
|
||||
.build();
|
||||
|
||||
// Register the base login command
|
||||
final CommandDescription LOGIN_BASE = CommandDescription.builder()
|
||||
.executableCommand(new LoginCommand())
|
||||
.parent(null)
|
||||
.labels("login", "l")
|
||||
.description("Login command")
|
||||
.detailedDescription("Command to log in using AuthMeReloaded.")
|
||||
.parent(null)
|
||||
.permissions(ALLOWED, PlayerPermission.LOGIN)
|
||||
.withArgument("password", "Login password", false)
|
||||
.permissions(ALLOWED, PlayerPermission.LOGIN)
|
||||
.executableCommand(new LoginCommand())
|
||||
.build();
|
||||
|
||||
// Register the help command
|
||||
CommandDescription.builder()
|
||||
.executableCommand(helpCommandExecutable)
|
||||
.parent(LOGIN_BASE)
|
||||
.labels(helpCommandLabels)
|
||||
.description("View Help")
|
||||
.detailedDescription("View detailed help pages about AuthMeReloaded login commands.")
|
||||
.withArgument("query", "The command or query to view help for.", true)
|
||||
.build();
|
||||
|
||||
// Register the base logout command
|
||||
CommandDescription LOGOUT_BASE = CommandDescription.builder()
|
||||
.executableCommand(new LogoutCommand())
|
||||
.parent(null)
|
||||
.labels("logout")
|
||||
.description("Logout command")
|
||||
.detailedDescription("Command to logout using AuthMeReloaded.")
|
||||
.permissions(ALLOWED, PlayerPermission.LOGOUT)
|
||||
.build();
|
||||
|
||||
// Register the help command
|
||||
CommandDescription.builder()
|
||||
.executableCommand(helpCommandExecutable)
|
||||
.parent(LOGOUT_BASE)
|
||||
.labels(helpCommandLabels)
|
||||
.description("View help")
|
||||
.detailedDescription("View detailed help pages about AuthMeReloaded logout commands.")
|
||||
.withArgument("query", "The command or query to view help for.", true)
|
||||
.build();
|
||||
.parent(null)
|
||||
.labels("logout")
|
||||
.description("Logout command")
|
||||
.detailedDescription("Command to logout using AuthMeReloaded.")
|
||||
.permissions(ALLOWED, PlayerPermission.LOGOUT)
|
||||
.executableCommand(new LogoutCommand())
|
||||
.build();
|
||||
|
||||
// Register the base register command
|
||||
final CommandDescription REGISTER_BASE = CommandDescription.builder()
|
||||
@ -336,166 +307,92 @@ public final class CommandInitializer {
|
||||
.labels("register", "reg")
|
||||
.description("Registration command")
|
||||
.detailedDescription("Command to register using AuthMeReloaded.")
|
||||
.withArgument("password", "Password", false)
|
||||
.withArgument("verifyPassword", "Verify password", false)
|
||||
.withArgument("password", "Password", true)
|
||||
.withArgument("verifyPassword", "Verify password", true)
|
||||
.permissions(ALLOWED, PlayerPermission.REGISTER)
|
||||
.executableCommand(new RegisterCommand())
|
||||
.build();
|
||||
|
||||
// Register the help command
|
||||
CommandDescription.builder()
|
||||
.executableCommand(helpCommandExecutable)
|
||||
.parent(REGISTER_BASE)
|
||||
.labels(helpCommandLabels)
|
||||
.description("View help")
|
||||
.detailedDescription("View detailed help pages about AuthMeReloaded register commands.")
|
||||
.withArgument("query", "The command or query to view help for.", true)
|
||||
.build();
|
||||
|
||||
// Register the base unregister command
|
||||
CommandDescription UNREGISTER_BASE = CommandDescription.builder()
|
||||
.executableCommand(new UnregisterCommand())
|
||||
.parent(null)
|
||||
.labels("unreg", "unregister")
|
||||
.description("Unregistration Command")
|
||||
.detailedDescription("Command to unregister using AuthMeReloaded.")
|
||||
.permissions(ALLOWED, PlayerPermission.UNREGISTER)
|
||||
.withArgument("password", "Password", false)
|
||||
.build();
|
||||
|
||||
// Register the help command
|
||||
CommandDescription.builder()
|
||||
.executableCommand(helpCommandExecutable)
|
||||
.parent(UNREGISTER_BASE)
|
||||
.labels(helpCommandLabels)
|
||||
.description("View help")
|
||||
.detailedDescription("View detailed help pages about AuthMeReloaded unregister commands.")
|
||||
.withArgument("query", "The command or query to view help for.", true)
|
||||
.build();
|
||||
.parent(null)
|
||||
.labels("unreg", "unregister")
|
||||
.description("Unregistration Command")
|
||||
.detailedDescription("Command to unregister using AuthMeReloaded.")
|
||||
.withArgument("password", "Password", false)
|
||||
.permissions(ALLOWED, PlayerPermission.UNREGISTER)
|
||||
.executableCommand(new UnregisterCommand())
|
||||
.build();
|
||||
|
||||
// Register the base changepassword command
|
||||
final CommandDescription CHANGE_PASSWORD_BASE = CommandDescription.builder()
|
||||
.executableCommand(new ChangePasswordCommand())
|
||||
.parent(null)
|
||||
.labels("changepassword", "changepass", "cp")
|
||||
.description("Change password Command")
|
||||
.detailedDescription("Command to change your password using AuthMeReloaded.")
|
||||
.permissions(ALLOWED, PlayerPermission.CHANGE_PASSWORD)
|
||||
.withArgument("password", "Password", false)
|
||||
.withArgument("verifyPassword", "Verify password.", false)
|
||||
.build();
|
||||
|
||||
// Register the help command
|
||||
CommandDescription.builder()
|
||||
.executableCommand(helpCommandExecutable)
|
||||
.parent(CHANGE_PASSWORD_BASE)
|
||||
.labels(helpCommandLabels)
|
||||
.description("View help")
|
||||
.detailedDescription("View detailed help pages about AuthMeReloaded changepassword commands.")
|
||||
.withArgument("query", "The command or query to view help for.", true)
|
||||
.build();
|
||||
.parent(null)
|
||||
.labels("changepassword", "changepass", "cp")
|
||||
.description("Change password Command")
|
||||
.detailedDescription("Command to change your password using AuthMeReloaded.")
|
||||
.withArgument("oldPassword", "Old Password", false)
|
||||
.withArgument("newPassword", "New Password.", false)
|
||||
.permissions(ALLOWED, PlayerPermission.CHANGE_PASSWORD)
|
||||
.executableCommand(new ChangePasswordCommand())
|
||||
.build();
|
||||
|
||||
// Register the base Email command
|
||||
CommandDescription EMAIL_BASE = CommandDescription.builder()
|
||||
.executableCommand(helpCommandExecutable)
|
||||
.parent(null)
|
||||
.labels("email", "mail")
|
||||
.description("Email command")
|
||||
.detailedDescription("The AuthMeReloaded Email command base.")
|
||||
.build();
|
||||
|
||||
// Register the help command
|
||||
CommandDescription.builder()
|
||||
.executableCommand(helpCommandExecutable)
|
||||
.parent(EMAIL_BASE)
|
||||
.labels(helpCommandLabels)
|
||||
.description("View help")
|
||||
.detailedDescription("View detailed help pages about AuthMeReloaded email commands.")
|
||||
.withArgument("query", "The command or query to view help for.", true)
|
||||
.build();
|
||||
.parent(null)
|
||||
.labels("email", "mail")
|
||||
.description("Email command")
|
||||
.detailedDescription("The AuthMeReloaded Email command base.")
|
||||
.executableCommand(new EmailBaseCommand())
|
||||
.build();
|
||||
|
||||
// Register the add command
|
||||
CommandDescription.builder()
|
||||
.executableCommand(new AddEmailCommand())
|
||||
.parent(EMAIL_BASE)
|
||||
.labels("add", "addemail", "addmail")
|
||||
.description("Add Email")
|
||||
.detailedDescription("Add a new email address to your account.")
|
||||
.permissions(ALLOWED, PlayerPermission.ADD_EMAIL)
|
||||
.withArgument("email", "Email address", false)
|
||||
.withArgument("verifyEmail", "Email address verification", false)
|
||||
.build();
|
||||
.parent(EMAIL_BASE)
|
||||
.labels("add", "addemail", "addmail")
|
||||
.description("Add Email")
|
||||
.detailedDescription("Add a new email address to your account.")
|
||||
.withArgument("email", "Email address", false)
|
||||
.withArgument("verifyEmail", "Email address verification", false)
|
||||
.permissions(ALLOWED, PlayerPermission.ADD_EMAIL)
|
||||
.executableCommand(new AddEmailCommand())
|
||||
.build();
|
||||
|
||||
// Register the change command
|
||||
CommandDescription.builder()
|
||||
.executableCommand(new ChangeEmailCommand())
|
||||
.parent(EMAIL_BASE)
|
||||
.labels("change", "changeemail", "changemail")
|
||||
.description("Change Email")
|
||||
.detailedDescription("Change an email address of your account.")
|
||||
.permissions(ALLOWED, PlayerPermission.CHANGE_EMAIL)
|
||||
.withArgument("oldEmail", "Old email address", false)
|
||||
.withArgument("newEmail", "New email address", false)
|
||||
.build();
|
||||
|
||||
.parent(EMAIL_BASE)
|
||||
.labels("change", "changeemail", "changemail")
|
||||
.description("Change Email")
|
||||
.detailedDescription("Change an email address of your account.")
|
||||
.withArgument("oldEmail", "Old email address", false)
|
||||
.withArgument("newEmail", "New email address", false)
|
||||
.permissions(ALLOWED, PlayerPermission.CHANGE_EMAIL)
|
||||
.executableCommand(new ChangeEmailCommand())
|
||||
.build();
|
||||
|
||||
// Register the recover command
|
||||
CommandDescription.builder()
|
||||
.executableCommand(new RecoverEmailCommand())
|
||||
.parent(EMAIL_BASE)
|
||||
.labels("recover", "recovery", "recoveremail", "recovermail")
|
||||
.description("Recover password using Email")
|
||||
.detailedDescription("Recover your account using an Email address by sending a mail containing " +
|
||||
"a new password.")
|
||||
.permissions(ALLOWED, PlayerPermission.RECOVER_EMAIL)
|
||||
.withArgument("email", "Email address", false)
|
||||
.build();
|
||||
.parent(EMAIL_BASE)
|
||||
.labels("recover", "recovery", "recoveremail", "recovermail")
|
||||
.description("Recover password using Email")
|
||||
.detailedDescription("Recover your account using an Email address by sending a mail containing " +
|
||||
"a new password.")
|
||||
.withArgument("email", "Email address", false)
|
||||
.permissions(ALLOWED, PlayerPermission.RECOVER_EMAIL)
|
||||
.executableCommand(new RecoverEmailCommand())
|
||||
.build();
|
||||
|
||||
// Register the base captcha command
|
||||
CommandDescription CAPTCHA_BASE = CommandDescription.builder()
|
||||
.executableCommand(new CaptchaCommand())
|
||||
.parent(null)
|
||||
.labels("captcha", "capt")
|
||||
.description("Captcha Command")
|
||||
.detailedDescription("Captcha command for AuthMeReloaded.")
|
||||
.permissions(ALLOWED, PlayerPermission.CAPTCHA)
|
||||
.withArgument("captcha", "The Captcha", false)
|
||||
.build();
|
||||
.parent(null)
|
||||
.labels("captcha", "capt")
|
||||
.description("Captcha Command")
|
||||
.detailedDescription("Captcha command for AuthMeReloaded.")
|
||||
.withArgument("captcha", "The Captcha", false)
|
||||
.permissions(ALLOWED, PlayerPermission.CAPTCHA)
|
||||
.executableCommand(new CaptchaCommand())
|
||||
.build();
|
||||
|
||||
// Register the help command
|
||||
CommandDescription.builder()
|
||||
.executableCommand(helpCommandExecutable)
|
||||
.parent(CAPTCHA_BASE)
|
||||
.labels(helpCommandLabels)
|
||||
.description("View help")
|
||||
.detailedDescription("View detailed help pages about AuthMeReloaded captcha commands.")
|
||||
.withArgument("query", "The command or query to view help for.", true)
|
||||
.build();
|
||||
|
||||
// Register the base converter command
|
||||
CommandDescription CONVERTER_BASE = CommandDescription.builder()
|
||||
.executableCommand(new ConverterCommand())
|
||||
.parent(null)
|
||||
.labels("converter", "convert", "conv")
|
||||
.description("Converter Command")
|
||||
.detailedDescription("Converter command for AuthMeReloaded.")
|
||||
.permissions(OP_ONLY, AdminPermission.CONVERTER)
|
||||
.withArgument("job", "Conversion job: flattosql / flattosqlite /| xauth / crazylogin / rakamak / " +
|
||||
"royalauth / vauth / sqltoflat", false)
|
||||
.build();
|
||||
|
||||
// Register the help command
|
||||
CommandDescription.builder()
|
||||
.executableCommand(helpCommandExecutable)
|
||||
.parent(CONVERTER_BASE)
|
||||
.labels(helpCommandLabels)
|
||||
.description("View help")
|
||||
.detailedDescription("View detailed help pages about AuthMeReloaded converter commands.")
|
||||
.withArgument("query", "The command or query to view help for.", true)
|
||||
.build();
|
||||
|
||||
// Add the base commands to the commands array
|
||||
baseCommands = new HashSet<>(Arrays.asList(
|
||||
Set<CommandDescription> baseCommands = ImmutableSet.of(
|
||||
AUTHME_BASE,
|
||||
LOGIN_BASE,
|
||||
LOGOUT_BASE,
|
||||
@ -503,7 +400,30 @@ public final class CommandInitializer {
|
||||
UNREGISTER_BASE,
|
||||
CHANGE_PASSWORD_BASE,
|
||||
EMAIL_BASE,
|
||||
CAPTCHA_BASE,
|
||||
CONVERTER_BASE));
|
||||
CAPTCHA_BASE);
|
||||
|
||||
setHelpOnAllBases(baseCommands);
|
||||
return baseCommands;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the help command on all base commands, e.g. to register /authme help or /register help.
|
||||
*
|
||||
* @param commands The list of base commands to register a help child command on
|
||||
*/
|
||||
private static void setHelpOnAllBases(Collection<CommandDescription> commands) {
|
||||
final HelpCommand helpCommandExecutable = new HelpCommand();
|
||||
final List<String> helpCommandLabels = Arrays.asList("help", "hlp", "h", "sos", "?");
|
||||
|
||||
for (CommandDescription base : commands) {
|
||||
CommandDescription.builder()
|
||||
.parent(base)
|
||||
.labels(helpCommandLabels)
|
||||
.description("View help")
|
||||
.detailedDescription("View detailed help for /" + base.getLabels().get(0) + " commands.")
|
||||
.withArgument("query", "The command or query to view help for.", true)
|
||||
.executableCommand(helpCommandExecutable)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
179
src/main/java/fr/xephi/authme/command/CommandMapper.java
Normal file
179
src/main/java/fr/xephi/authme/command/CommandMapper.java
Normal file
@ -0,0 +1,179 @@
|
||||
package fr.xephi.authme.command;
|
||||
|
||||
import fr.xephi.authme.command.executable.HelpCommand;
|
||||
import fr.xephi.authme.permission.PermissionsManager;
|
||||
import fr.xephi.authme.util.CollectionUtils;
|
||||
import fr.xephi.authme.util.StringUtils;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static fr.xephi.authme.command.FoundResultStatus.INCORRECT_ARGUMENTS;
|
||||
import static fr.xephi.authme.command.FoundResultStatus.MISSING_BASE_COMMAND;
|
||||
import static fr.xephi.authme.command.FoundResultStatus.UNKNOWN_LABEL;
|
||||
|
||||
/**
|
||||
* The AuthMe command handler, responsible for mapping incoming
|
||||
* command parts to the correct {@link CommandDescription}.
|
||||
*/
|
||||
public class CommandMapper {
|
||||
|
||||
/**
|
||||
* The class of the help command, to which the base label should also be passed in the arguments.
|
||||
*/
|
||||
private static final Class<? extends ExecutableCommand> HELP_COMMAND_CLASS = HelpCommand.class;
|
||||
|
||||
private final Set<CommandDescription> baseCommands;
|
||||
private final PermissionsManager permissionsManager;
|
||||
|
||||
public CommandMapper(Set<CommandDescription> baseCommands, PermissionsManager permissionsManager) {
|
||||
this.baseCommands = baseCommands;
|
||||
this.permissionsManager = permissionsManager;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Map incoming command parts to a command. This processes all parts and distinguishes the labels from arguments.
|
||||
*
|
||||
* @param sender The command sender (null if none applicable)
|
||||
* @param parts The parts to map to commands and arguments
|
||||
* @return The generated {@link FoundCommandResult}
|
||||
*/
|
||||
public FoundCommandResult mapPartsToCommand(CommandSender sender, final List<String> parts) {
|
||||
if (CollectionUtils.isEmpty(parts)) {
|
||||
return new FoundCommandResult(null, parts, null, 0.0, MISSING_BASE_COMMAND);
|
||||
}
|
||||
|
||||
CommandDescription base = getBaseCommand(parts.get(0));
|
||||
if (base == null) {
|
||||
return new FoundCommandResult(null, parts, null, 0.0, MISSING_BASE_COMMAND);
|
||||
}
|
||||
|
||||
// Prefer labels: /register help goes to "Help command", not "Register command" with argument 'help'
|
||||
List<String> remainingParts = parts.subList(1, parts.size());
|
||||
CommandDescription childCommand = getSuitableChild(base, remainingParts);
|
||||
if (childCommand != null) {
|
||||
FoundResultStatus status = getPermissionAwareStatus(sender, childCommand);
|
||||
FoundCommandResult result = new FoundCommandResult(
|
||||
childCommand, parts.subList(0, 2), parts.subList(2, parts.size()), 0.0, status);
|
||||
return transformResultForHelp(result);
|
||||
} else if (hasSuitableArgumentCount(base, remainingParts.size())) {
|
||||
FoundResultStatus status = getPermissionAwareStatus(sender, base);
|
||||
return new FoundCommandResult(base, parts.subList(0, 1), parts.subList(1, parts.size()), 0.0, status);
|
||||
}
|
||||
|
||||
return getCommandWithSmallestDifference(base, parts);
|
||||
}
|
||||
|
||||
private FoundCommandResult getCommandWithSmallestDifference(CommandDescription base, List<String> parts) {
|
||||
// Return the base command with incorrect arg count error if we only have one part
|
||||
if (parts.size() <= 1) {
|
||||
return new FoundCommandResult(base, parts, new ArrayList<String>(), 0.0, INCORRECT_ARGUMENTS);
|
||||
}
|
||||
|
||||
final String childLabel = parts.get(1);
|
||||
double minDifference = Double.POSITIVE_INFINITY;
|
||||
CommandDescription closestCommand = null;
|
||||
|
||||
for (CommandDescription child : base.getChildren()) {
|
||||
double difference = getLabelDifference(child, childLabel);
|
||||
if (difference < minDifference) {
|
||||
minDifference = difference;
|
||||
closestCommand = child;
|
||||
}
|
||||
}
|
||||
|
||||
// base command may have no children, in which case we return the base command with incorrect arguments error
|
||||
if (closestCommand == null) {
|
||||
return new FoundCommandResult(
|
||||
base, parts.subList(0, 1), parts.subList(1, parts.size()), 0.0, INCORRECT_ARGUMENTS);
|
||||
}
|
||||
|
||||
FoundResultStatus status = (minDifference == 0.0) ? INCORRECT_ARGUMENTS : UNKNOWN_LABEL;
|
||||
final int partsSize = parts.size();
|
||||
List<String> labels = parts.subList(0, Math.min(closestCommand.getLabelCount(), partsSize));
|
||||
List<String> arguments = (labels.size() == partsSize)
|
||||
? new ArrayList<String>()
|
||||
: parts.subList(labels.size(), partsSize);
|
||||
|
||||
return new FoundCommandResult(closestCommand, labels, arguments, minDifference, status);
|
||||
}
|
||||
|
||||
private CommandDescription getBaseCommand(String label) {
|
||||
String baseLabel = label.toLowerCase();
|
||||
for (CommandDescription command : baseCommands) {
|
||||
if (command.hasLabel(baseLabel)) {
|
||||
return command;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a child from a base command if the label and the argument count match.
|
||||
*
|
||||
* @param baseCommand The base command whose children should be checked
|
||||
* @param parts The command parts received from the invocation; the first item is the potential label and any
|
||||
* other items are command arguments. The first initial part that led to the base command should not
|
||||
* be present.
|
||||
*
|
||||
* @return A command if there was a complete match (including proper argument count), null otherwise
|
||||
*/
|
||||
private CommandDescription getSuitableChild(CommandDescription baseCommand, List<String> parts) {
|
||||
if (CollectionUtils.isEmpty(parts)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final String label = parts.get(0).toLowerCase();
|
||||
final int argumentCount = parts.size() - 1;
|
||||
|
||||
for (CommandDescription child : baseCommand.getChildren()) {
|
||||
if (child.hasLabel(label) && hasSuitableArgumentCount(child, argumentCount)) {
|
||||
return child;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static FoundCommandResult transformResultForHelp(FoundCommandResult result) {
|
||||
if (result.getCommandDescription() != null
|
||||
&& HELP_COMMAND_CLASS.isAssignableFrom(result.getCommandDescription().getExecutableCommand().getClass())) {
|
||||
// For "/authme help register" we have labels = [authme, help] and arguments = [register]
|
||||
// But for the help command we want labels = [authme, help] and arguments = [authme, register],
|
||||
// so we can use the arguments as the labels to the command to show help for
|
||||
List<String> arguments = new ArrayList<>(result.getArguments());
|
||||
arguments.add(0, result.getLabels().get(0));
|
||||
return new FoundCommandResult(result.getCommandDescription(), result.getLabels(),
|
||||
arguments, result.getDifference(), result.getResultStatus());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private FoundResultStatus getPermissionAwareStatus(CommandSender sender, CommandDescription command) {
|
||||
if (sender != null && !permissionsManager.hasPermission(sender, command)) {
|
||||
return FoundResultStatus.NO_PERMISSION;
|
||||
}
|
||||
return FoundResultStatus.SUCCESS;
|
||||
}
|
||||
|
||||
private static boolean hasSuitableArgumentCount(CommandDescription command, int argumentCount) {
|
||||
int minArgs = CommandUtils.getMinNumberOfArguments(command);
|
||||
int maxArgs = CommandUtils.getMaxNumberOfArguments(command);
|
||||
|
||||
return argumentCount >= minArgs && argumentCount <= maxArgs;
|
||||
}
|
||||
|
||||
private static double getLabelDifference(CommandDescription command, String givenLabel) {
|
||||
double minDifference = Double.POSITIVE_INFINITY;
|
||||
for (String commandLabel : command.getLabels()) {
|
||||
double difference = StringUtils.getDifference(commandLabel, givenLabel);
|
||||
if (difference < minDifference) {
|
||||
minDifference = difference;
|
||||
}
|
||||
}
|
||||
return minDifference;
|
||||
}
|
||||
|
||||
}
|
@ -1,78 +0,0 @@
|
||||
package fr.xephi.authme.command;
|
||||
|
||||
import fr.xephi.authme.util.StringUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class CommandParts {
|
||||
|
||||
/**
|
||||
* The list of parts for this command.
|
||||
*/
|
||||
private final List<String> parts = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param part The part to add.
|
||||
*/
|
||||
public CommandParts(String part) {
|
||||
this.parts.add(part);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param parts The list of parts.
|
||||
*/
|
||||
public CommandParts(List<String> parts) {
|
||||
this.parts.addAll(parts);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the command parts.
|
||||
*
|
||||
* @return Command parts.
|
||||
*/
|
||||
public List<String> getList() {
|
||||
return this.parts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of parts.
|
||||
*
|
||||
* @return Part count.
|
||||
*/
|
||||
public int getCount() {
|
||||
return this.parts.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a part by its index.
|
||||
*
|
||||
* @param i Part index.
|
||||
*
|
||||
* @return The part.
|
||||
*/
|
||||
public String get(int i) {
|
||||
// Make sure the index is in-bound
|
||||
if (i < 0 || i >= getCount())
|
||||
return null;
|
||||
|
||||
// Get and return the argument
|
||||
return this.parts.get(i);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the parts to a string.
|
||||
*
|
||||
* @return The part as a string.
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return StringUtils.join(" ", this.parts);
|
||||
}
|
||||
}
|
@ -1,11 +1,7 @@
|
||||
package fr.xephi.authme.command;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.permission.DefaultPermission;
|
||||
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.List;
|
||||
|
||||
@ -42,38 +38,6 @@ public class CommandPermissions {
|
||||
return this.permissionNodes;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
public boolean hasPermission(CommandSender sender) {
|
||||
// Make sure any permission node is set
|
||||
if (permissionNodes.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
PermissionsManager permissionsManager = AuthMe.getInstance().getPermissionsManager();
|
||||
final boolean defaultPermission = getDefaultPermissionCommandSender(sender);
|
||||
|
||||
// Make sure the command sender is a player, if not use the default
|
||||
if (!(sender instanceof Player)) {
|
||||
return defaultPermission;
|
||||
}
|
||||
|
||||
// Get the player instance
|
||||
Player player = (Player) sender;
|
||||
|
||||
// Get the permissions manager, and make sure it's instance is valid
|
||||
|
||||
if (permissionsManager == null)
|
||||
return false;
|
||||
|
||||
// Check whether the player has permission, return the result
|
||||
return permissionsManager.hasPermission(player, this.permissionNodes, defaultPermission);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default permission if the permission nodes couldn't be used.
|
||||
@ -85,24 +49,4 @@ public class CommandPermissions {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the default permission for a specified command sender.
|
||||
*
|
||||
* @param sender The command sender to get the default permission for.
|
||||
*
|
||||
* @return True if the command sender has permission by default, false otherwise.
|
||||
*/
|
||||
public boolean getDefaultPermissionCommandSender(CommandSender sender) {
|
||||
switch (getDefaultPermission()) {
|
||||
case ALLOWED:
|
||||
return true;
|
||||
|
||||
case OP_ONLY:
|
||||
return sender.isOp();
|
||||
|
||||
case NOT_ALLOWED:
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
195
src/main/java/fr/xephi/authme/command/CommandService.java
Normal file
195
src/main/java/fr/xephi/authme/command/CommandService.java
Normal file
@ -0,0 +1,195 @@
|
||||
package fr.xephi.authme.command;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.command.help.HelpProvider;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
import fr.xephi.authme.output.MessageKey;
|
||||
import fr.xephi.authme.output.Messages;
|
||||
import fr.xephi.authme.permission.PermissionsManager;
|
||||
import fr.xephi.authme.process.Management;
|
||||
import fr.xephi.authme.security.PasswordSecurity;
|
||||
import fr.xephi.authme.settings.NewSetting;
|
||||
import fr.xephi.authme.settings.domain.Property;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Service for implementations of {@link ExecutableCommand} to execute some common tasks.
|
||||
* This service basically wraps calls, forwarding them to other classes.
|
||||
*/
|
||||
public class CommandService {
|
||||
|
||||
private final AuthMe authMe;
|
||||
private final Messages messages;
|
||||
private final HelpProvider helpProvider;
|
||||
private final CommandMapper commandMapper;
|
||||
private final PasswordSecurity passwordSecurity;
|
||||
private final PermissionsManager permissionsManager;
|
||||
private final NewSetting settings;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param authMe The plugin instance
|
||||
* @param commandMapper Command mapper
|
||||
* @param helpProvider Help provider
|
||||
* @param messages Messages instance
|
||||
* @param passwordSecurity The Password Security instance
|
||||
* @param permissionsManager The permissions manager
|
||||
* @param settings The settings manager
|
||||
*/
|
||||
public CommandService(AuthMe authMe, CommandMapper commandMapper, HelpProvider helpProvider, Messages messages,
|
||||
PasswordSecurity passwordSecurity, PermissionsManager permissionsManager,
|
||||
NewSetting settings) {
|
||||
this.authMe = authMe;
|
||||
this.messages = messages;
|
||||
this.helpProvider = helpProvider;
|
||||
this.commandMapper = commandMapper;
|
||||
this.passwordSecurity = passwordSecurity;
|
||||
this.permissionsManager = permissionsManager;
|
||||
this.settings = settings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a message to a player.
|
||||
*
|
||||
* @param sender The command sender to send the message to
|
||||
* @param messageKey The message key to send
|
||||
*/
|
||||
public void send(CommandSender sender, MessageKey messageKey) {
|
||||
messages.send(sender, messageKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a message to a player.
|
||||
*
|
||||
* @param sender The command sender to send the message to
|
||||
* @param messageKey The message key to send
|
||||
* @param replacements The replacement arguments for the message key's tags
|
||||
*/
|
||||
public void send(CommandSender sender, MessageKey messageKey, String... replacements) {
|
||||
messages.send(sender, messageKey, replacements);
|
||||
}
|
||||
|
||||
/**
|
||||
* Map command parts to a command description.
|
||||
*
|
||||
* @param sender The command sender issuing the request (for permission check), or null to skip permissions
|
||||
* @param commandParts The received command parts to map to a command
|
||||
* @return The computed mapping result
|
||||
*/
|
||||
public FoundCommandResult mapPartsToCommand(CommandSender sender, List<String> commandParts) {
|
||||
return commandMapper.mapPartsToCommand(sender, commandParts);
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the given task asynchronously with the Bukkit scheduler.
|
||||
*
|
||||
* @param task The task to run
|
||||
*/
|
||||
public void runTaskAsynchronously(Runnable task) {
|
||||
authMe.getServer().getScheduler().runTaskAsynchronously(authMe, task);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the AuthMe data source.
|
||||
*
|
||||
* @return The used data source
|
||||
*/
|
||||
public DataSource getDataSource() {
|
||||
return authMe.getDataSource();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the AuthMe instance for further manipulation. Use only if other methods from
|
||||
* the command service cannot be used.
|
||||
*
|
||||
* @return The AuthMe instance
|
||||
*/
|
||||
public AuthMe getAuthMe() {
|
||||
return authMe;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the PasswordSecurity instance.
|
||||
*
|
||||
* @return The password security instance
|
||||
*/
|
||||
public PasswordSecurity getPasswordSecurity() {
|
||||
return passwordSecurity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Output the help for a given command.
|
||||
*
|
||||
* @param sender The sender to output the help to
|
||||
* @param result The result to output information about
|
||||
* @param options Output options, see {@link HelpProvider}
|
||||
*/
|
||||
public void outputHelp(CommandSender sender, FoundCommandResult result, int options) {
|
||||
List<String> lines = helpProvider.printHelp(sender, result, options);
|
||||
for (String line : lines) {
|
||||
sender.sendMessage(line);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the management instance of the plugin.
|
||||
*
|
||||
* @return The Management instance linked to the AuthMe instance
|
||||
*/
|
||||
public Management getManagement() {
|
||||
return authMe.getManagement();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the permissions manager.
|
||||
*
|
||||
* @return the permissions manager
|
||||
*/
|
||||
public PermissionsManager getPermissionsManager() {
|
||||
return permissionsManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a message by its message key.
|
||||
*
|
||||
* @param key The message to retrieve
|
||||
* @return The message
|
||||
*/
|
||||
public String[] retrieveMessage(MessageKey key) {
|
||||
return messages.retrieve(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the messages instance to retrieve messages from the given file.
|
||||
*
|
||||
* @param file The new file to read messages from
|
||||
*/
|
||||
public void reloadMessages(File file) {
|
||||
messages.reload(file);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the given property's value.
|
||||
*
|
||||
* @param property The property to retrieve
|
||||
* @param <T> The type of the property
|
||||
* @return The property's value
|
||||
*/
|
||||
public <T> T getProperty(Property<T> property) {
|
||||
return settings.getProperty(property);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the settings manager.
|
||||
*
|
||||
* @return The settings manager
|
||||
*/
|
||||
public NewSetting getSettings() {
|
||||
return settings;
|
||||
}
|
||||
|
||||
}
|
@ -1,10 +1,11 @@
|
||||
package fr.xephi.authme.command;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import fr.xephi.authme.util.CollectionUtils;
|
||||
import com.google.common.collect.Lists;
|
||||
import fr.xephi.authme.util.StringUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public final class CommandUtils {
|
||||
|
||||
public static int getMinNumberOfArguments(CommandDescription command) {
|
||||
@ -23,35 +24,33 @@ public final class CommandUtils {
|
||||
|
||||
/**
|
||||
* Provide a textual representation of a list of labels to show it as a command. For example, a list containing
|
||||
* the items ["authme", "register", "player"] it will return "authme register player".
|
||||
* the items ["authme", "register", "player"] will return "authme register player".
|
||||
*
|
||||
* @param labels The labels to format
|
||||
*
|
||||
* @return The space-separated labels
|
||||
*/
|
||||
public static String labelsToString(Iterable<String> labels) {
|
||||
return StringUtils.join(" ", labels);
|
||||
}
|
||||
|
||||
public static double getDifference(List<String> labels1, List<String> labels2, boolean fullCompare) {
|
||||
// Make sure the other reference is correct
|
||||
if (labels1 == null || labels2 == null) {
|
||||
return -1;
|
||||
public static String constructCommandPath(CommandDescription command) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
String prefix = "/";
|
||||
for (CommandDescription ancestor : constructParentList(command)) {
|
||||
sb.append(prefix).append(ancestor.getLabels().get(0));
|
||||
prefix = " ";
|
||||
}
|
||||
|
||||
// Get the range to use
|
||||
int range = Math.min(labels1.size(), labels2.size());
|
||||
|
||||
// Get and the difference
|
||||
if (fullCompare) {
|
||||
return StringUtils.getDifference(CommandUtils.labelsToString(labels1), CommandUtils.labelsToString(labels2));
|
||||
}
|
||||
return StringUtils.getDifference(
|
||||
labelsToString(CollectionUtils.getRange(labels1, range - 1, 1)),
|
||||
labelsToString(CollectionUtils.getRange(labels2, range - 1, 1)));
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public static List<CommandDescription> constructParentList(CommandDescription command) {
|
||||
List<CommandDescription> commands = new ArrayList<>();
|
||||
CommandDescription currentCommand = command;
|
||||
while (currentCommand != null) {
|
||||
commands.add(currentCommand);
|
||||
currentCommand = currentCommand.getParent();
|
||||
}
|
||||
return Lists.reverse(commands);
|
||||
}
|
||||
}
|
||||
|
@ -2,19 +2,20 @@ package fr.xephi.authme.command;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Base class for AuthMe commands that can be executed.
|
||||
*/
|
||||
public abstract class ExecutableCommand {
|
||||
public interface ExecutableCommand {
|
||||
|
||||
/**
|
||||
* Execute the command.
|
||||
* Execute the command with the given arguments.
|
||||
*
|
||||
* @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.
|
||||
* @param sender The command sender.
|
||||
* @param arguments The arguments.
|
||||
* @param commandService The command service.
|
||||
*/
|
||||
public abstract boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments);
|
||||
void executeCommand(CommandSender sender, List<String> arguments, CommandService commandService);
|
||||
|
||||
}
|
||||
|
@ -1,149 +1,79 @@
|
||||
package fr.xephi.authme.command;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Result of a command mapping by {@link CommandHandler}. An object of this class represents a successful mapping
|
||||
* as well as erroneous ones, as communicated with {@link FoundResultStatus}.
|
||||
* <p>
|
||||
* Fields other than {@link FoundResultStatus} are available depending, among other factors, on the status:
|
||||
* <ul>
|
||||
* <li>{@link FoundResultStatus#SUCCESS} entails that mapping the input to a command was successful. Therefore,
|
||||
* the command description, labels and arguments are set. The difference is 0.0.</li>
|
||||
* <li>{@link FoundResultStatus#INCORRECT_ARGUMENTS}: The received parts could be mapped to a command but the argument
|
||||
* count doesn't match. Guarantees that the command description field is not null; difference is 0.0</li>
|
||||
* <li>{@link FoundResultStatus#UNKNOWN_LABEL}: The labels could not be mapped to a command. The command description
|
||||
* may be set to the most similar command, or it may be null. Difference is above 0.0.</li>
|
||||
* <li>{@link FoundResultStatus#NO_PERMISSION}: The command could be matched properly but the sender does not have
|
||||
* permission to execute it.</li>
|
||||
* <li>{@link FoundResultStatus#MISSING_BASE_COMMAND} should never occur. All other fields may be null and any further
|
||||
* processing of the object should be aborted.</li>
|
||||
* </ul>
|
||||
*/
|
||||
public class FoundCommandResult {
|
||||
|
||||
/**
|
||||
* The command description instance.
|
||||
*/
|
||||
private CommandDescription commandDescription;
|
||||
private final CommandDescription commandDescription;
|
||||
/**
|
||||
* The command reference.
|
||||
* The labels used to invoke the command. This may be different for the same {@link ExecutableCommand} instance
|
||||
* if multiple labels have been defined, e.g. "/authme register" and "/authme reg".
|
||||
*/
|
||||
private final CommandParts commandReference;
|
||||
/**
|
||||
* The command arguments.
|
||||
*/
|
||||
private final CommandParts commandArguments;
|
||||
/**
|
||||
* The original search query reference.
|
||||
*/
|
||||
private final CommandParts queryReference;
|
||||
private final List<String> labels;
|
||||
/** The command arguments. */
|
||||
private final List<String> arguments;
|
||||
/** The difference between the matched command and the supplied labels. */
|
||||
private final double difference;
|
||||
/** The status of the result (see class description). */
|
||||
private final FoundResultStatus resultStatus;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param commandDescription The command description.
|
||||
* @param commandReference The command reference.
|
||||
* @param commandArguments The command arguments.
|
||||
* @param queryReference The original query reference.
|
||||
* @param labels The labels used to access the command.
|
||||
* @param arguments The command arguments.
|
||||
* @param difference The difference between the supplied labels and the matched command.
|
||||
* @param resultStatus The status of the result.
|
||||
*/
|
||||
public FoundCommandResult(CommandDescription commandDescription, CommandParts commandReference, CommandParts commandArguments, CommandParts queryReference) {
|
||||
public FoundCommandResult(CommandDescription commandDescription, List<String> labels, List<String> arguments,
|
||||
double difference, FoundResultStatus resultStatus) {
|
||||
this.commandDescription = commandDescription;
|
||||
this.commandReference = commandReference;
|
||||
this.commandArguments = commandArguments;
|
||||
this.queryReference = queryReference;
|
||||
this.labels = labels;
|
||||
this.arguments = arguments;
|
||||
this.difference = difference;
|
||||
this.resultStatus = resultStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether the command was suitable.
|
||||
*
|
||||
* @return True if the command was suitable, false otherwise.
|
||||
*/
|
||||
public boolean hasProperArguments() {
|
||||
// Make sure the command description is set
|
||||
if (this.commandDescription == null)
|
||||
return false;
|
||||
|
||||
// Get and return the result
|
||||
return getCommandDescription().getSuitableArgumentsDifference(this.queryReference) == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the command description.
|
||||
*
|
||||
* @return Command description.
|
||||
*/
|
||||
public CommandDescription getCommandDescription() {
|
||||
return this.commandDescription;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether the command is executable.
|
||||
*
|
||||
* @return True if the command is executable, false otherwise.
|
||||
*/
|
||||
public boolean isExecutable() {
|
||||
return commandDescription != null;
|
||||
public List<String> getArguments() {
|
||||
return this.arguments;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the command.
|
||||
*
|
||||
* @param sender The command sender that executed the command.
|
||||
*
|
||||
* @return True on success, false on failure.
|
||||
*/
|
||||
public boolean executeCommand(CommandSender sender) {
|
||||
// Make sure the command description is valid
|
||||
if (this.commandDescription == null)
|
||||
return false;
|
||||
|
||||
// Execute the command
|
||||
return this.commandDescription.execute(sender, this.commandReference, this.commandArguments);
|
||||
public List<String> getLabels() {
|
||||
return this.labels;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether a command sender has permission to execute the command.
|
||||
*
|
||||
* @param sender The command sender.
|
||||
*
|
||||
* @return True if the command sender has permission, false otherwise.
|
||||
*/
|
||||
public boolean hasPermission(CommandSender sender) {
|
||||
if (commandDescription == null) {
|
||||
return false;
|
||||
} else if (commandDescription.getCommandPermissions() == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// TODO: Move permissions check to the permission package; command package should not define permission-checking
|
||||
// API
|
||||
return commandDescription.getCommandPermissions().hasPermission(sender);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the command reference.
|
||||
*
|
||||
* @return The command reference.
|
||||
*/
|
||||
public CommandParts getCommandReference() {
|
||||
return this.commandReference;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the command arguments.
|
||||
*
|
||||
* @return The command arguments.
|
||||
*/
|
||||
public CommandParts getCommandArguments() {
|
||||
return this.commandArguments;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the original query reference.
|
||||
*
|
||||
* @return Original query reference.
|
||||
*/
|
||||
public CommandParts getQueryReference() {
|
||||
return this.queryReference;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the difference value between the original query and the result reference.
|
||||
*
|
||||
* @return The difference value.
|
||||
*/
|
||||
public double getDifference() {
|
||||
// Get the difference through the command found
|
||||
if (this.commandDescription != null) {
|
||||
return this.commandDescription.getCommandDifference(this.queryReference);
|
||||
}
|
||||
|
||||
// Get the difference from the query reference
|
||||
return CommandUtils.getDifference(queryReference.getList(), commandReference.getList(), true);
|
||||
return difference;
|
||||
}
|
||||
|
||||
public FoundResultStatus getResultStatus() {
|
||||
return resultStatus;
|
||||
}
|
||||
|
||||
}
|
||||
|
18
src/main/java/fr/xephi/authme/command/FoundResultStatus.java
Normal file
18
src/main/java/fr/xephi/authme/command/FoundResultStatus.java
Normal file
@ -0,0 +1,18 @@
|
||||
package fr.xephi.authme.command;
|
||||
|
||||
/**
|
||||
* Result status for mapping command parts. See {@link FoundCommandResult} for a detailed description of the states.
|
||||
*/
|
||||
public enum FoundResultStatus {
|
||||
|
||||
SUCCESS,
|
||||
|
||||
INCORRECT_ARGUMENTS,
|
||||
|
||||
UNKNOWN_LABEL,
|
||||
|
||||
NO_PERMISSION,
|
||||
|
||||
MISSING_BASE_COMMAND
|
||||
|
||||
}
|
46
src/main/java/fr/xephi/authme/command/PlayerCommand.java
Normal file
46
src/main/java/fr/xephi/authme/command/PlayerCommand.java
Normal file
@ -0,0 +1,46 @@
|
||||
package fr.xephi.authme.command;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* Common base type for player-only commands, handling the verification that the command sender is indeed a player.
|
||||
*/
|
||||
public abstract class PlayerCommand implements ExecutableCommand {
|
||||
|
||||
@Override
|
||||
public void executeCommand(CommandSender sender, List<String> arguments, CommandService commandService) {
|
||||
if (sender instanceof Player) {
|
||||
runCommand((Player) sender, arguments, commandService);
|
||||
} else {
|
||||
String alternative = getAlternativeCommand();
|
||||
if (alternative != null) {
|
||||
sender.sendMessage("Player only! Please use " + alternative + " instead.");
|
||||
} else {
|
||||
sender.sendMessage("This command is only for players.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the command with the given player and arguments.
|
||||
*
|
||||
* @param player The player who initiated the command
|
||||
* @param arguments The arguments supplied with the command
|
||||
* @param commandService The command service
|
||||
*/
|
||||
protected abstract void runCommand(Player player, List<String> arguments, CommandService commandService);
|
||||
|
||||
/**
|
||||
* Return an alternative command (textual representation) that is not restricted to players only.
|
||||
* Example: {@code "authme register <playerName> <password>"}
|
||||
*
|
||||
* @return Alternative command not only for players, or null if not applicable
|
||||
*/
|
||||
protected String getAlternativeCommand() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -1,27 +1,47 @@
|
||||
package fr.xephi.authme.command.executable;
|
||||
|
||||
import fr.xephi.authme.command.CommandParts;
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.command.CommandUtils;
|
||||
import fr.xephi.authme.command.ExecutableCommand;
|
||||
import fr.xephi.authme.command.FoundCommandResult;
|
||||
import fr.xephi.authme.command.FoundResultStatus;
|
||||
import fr.xephi.authme.command.help.HelpProvider;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class HelpCommand extends ExecutableCommand {
|
||||
import java.util.List;
|
||||
|
||||
import static fr.xephi.authme.command.FoundResultStatus.MISSING_BASE_COMMAND;
|
||||
import static fr.xephi.authme.command.FoundResultStatus.UNKNOWN_LABEL;
|
||||
|
||||
public class HelpCommand implements ExecutableCommand {
|
||||
|
||||
// Convention: arguments is not the actual invoked arguments but the command that was invoked,
|
||||
// e.g. "/authme help register" would typically be arguments = [register], but here we pass [authme, register]
|
||||
@Override
|
||||
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
||||
// Check whether quick help should be shown
|
||||
boolean quickHelp = commandArguments.getCount() == 0;
|
||||
public void executeCommand(CommandSender sender, List<String> arguments, CommandService commandService) {
|
||||
FoundCommandResult result = commandService.mapPartsToCommand(sender, arguments);
|
||||
|
||||
// Set the proper command arguments for the quick help and show it
|
||||
if (quickHelp) {
|
||||
commandArguments = new CommandParts(commandReference.get(0));
|
||||
HelpProvider.showHelp(sender, commandReference, commandArguments, false, false, false, false, false, true);
|
||||
} else {
|
||||
HelpProvider.showHelp(sender, commandReference, commandArguments);
|
||||
FoundResultStatus resultStatus = result.getResultStatus();
|
||||
if (MISSING_BASE_COMMAND.equals(resultStatus)) {
|
||||
sender.sendMessage(ChatColor.DARK_RED + "Could not get base command");
|
||||
return;
|
||||
} else if (UNKNOWN_LABEL.equals(resultStatus)) {
|
||||
if (result.getCommandDescription() == null) {
|
||||
sender.sendMessage(ChatColor.DARK_RED + "Unknown command");
|
||||
return;
|
||||
} else {
|
||||
sender.sendMessage(ChatColor.GOLD + "Assuming " + ChatColor.WHITE
|
||||
+ CommandUtils.constructCommandPath(result.getCommandDescription()));
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
int mappedCommandLevel = result.getCommandDescription().getLabelCount();
|
||||
if (mappedCommandLevel == 1) {
|
||||
commandService.outputHelp(sender, result, HelpProvider.SHOW_CHILDREN);
|
||||
} else {
|
||||
commandService.outputHelp(sender, result, HelpProvider.ALL_OPTIONS);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,115 +1,65 @@
|
||||
package fr.xephi.authme.command.executable.authme;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||
import fr.xephi.authme.command.CommandParts;
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.command.ExecutableCommand;
|
||||
import fr.xephi.authme.output.MessageKey;
|
||||
import fr.xephi.authme.output.Messages;
|
||||
import org.bukkit.Bukkit;
|
||||
import fr.xephi.authme.util.StringUtils;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Shows all accounts registered by the same IP address for the given player name or IP address.
|
||||
*/
|
||||
public class AccountsCommand extends ExecutableCommand {
|
||||
public class AccountsCommand implements ExecutableCommand {
|
||||
|
||||
@Override
|
||||
public boolean executeCommand(final CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
||||
// AuthMe plugin instance
|
||||
final AuthMe plugin = AuthMe.getInstance();
|
||||
|
||||
// Messages instance
|
||||
final Messages m = plugin.getMessages();
|
||||
|
||||
// Get the player query
|
||||
String playerQuery = sender.getName();
|
||||
if (commandArguments.getCount() >= 1)
|
||||
playerQuery = commandArguments.get(0);
|
||||
final String playerQueryFinal = playerQuery;
|
||||
|
||||
// Command logic
|
||||
if (!playerQuery.contains(".")) {
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
|
||||
public void executeCommand(final CommandSender sender, List<String> arguments,
|
||||
final CommandService commandService) {
|
||||
final String playerName = arguments.isEmpty() ? sender.getName() : arguments.get(0);
|
||||
|
||||
// Assumption: a player name cannot contain '.'
|
||||
if (!playerName.contains(".")) {
|
||||
commandService.runTaskAsynchronously(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
PlayerAuth auth;
|
||||
StringBuilder message = new StringBuilder("[AuthMe] ");
|
||||
try {
|
||||
auth = plugin.database.getAuth(playerQueryFinal.toLowerCase());
|
||||
} catch (NullPointerException npe) {
|
||||
m.send(sender, MessageKey.UNKNOWN_USER);
|
||||
return;
|
||||
}
|
||||
PlayerAuth auth = commandService.getDataSource().getAuth(playerName.toLowerCase());
|
||||
if (auth == null) {
|
||||
m.send(sender, MessageKey.UNKNOWN_USER);
|
||||
return;
|
||||
}
|
||||
List<String> accountList = plugin.database.getAllAuthsByName(auth);
|
||||
if (accountList == null || accountList.isEmpty()) {
|
||||
m.send(sender, MessageKey.USER_NOT_REGISTERED);
|
||||
return;
|
||||
}
|
||||
if (accountList.size() == 1) {
|
||||
sender.sendMessage("[AuthMe] " + playerQueryFinal + " is a single account player");
|
||||
return;
|
||||
}
|
||||
int i = 0;
|
||||
for (String account : accountList) {
|
||||
i++;
|
||||
message.append(account);
|
||||
if (i != accountList.size()) {
|
||||
message.append(", ");
|
||||
} else {
|
||||
message.append('.');
|
||||
}
|
||||
}
|
||||
sender.sendMessage("[AuthMe] " + playerQueryFinal + " has " + String.valueOf(accountList.size()) + " accounts");
|
||||
sender.sendMessage(message.toString());
|
||||
}
|
||||
});
|
||||
return true;
|
||||
} else {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
List<String> accountList;
|
||||
try {
|
||||
accountList = plugin.database.getAllAuthsByIp(playerQueryFinal);
|
||||
} catch (Exception e) {
|
||||
ConsoleLogger.showError(e.getMessage());
|
||||
ConsoleLogger.writeStackTrace(e);
|
||||
m.send(sender, MessageKey.ERROR);
|
||||
commandService.send(sender, MessageKey.UNKNOWN_USER);
|
||||
return;
|
||||
}
|
||||
|
||||
StringBuilder message = new StringBuilder("[AuthMe] ");
|
||||
if (accountList == null || accountList.isEmpty()) {
|
||||
sender.sendMessage("[AuthMe] This IP does not exist in the database");
|
||||
return;
|
||||
List<String> accountList = commandService.getDataSource().getAllAuthsByIp(auth.getIp());
|
||||
if (accountList.isEmpty()) {
|
||||
commandService.send(sender, MessageKey.USER_NOT_REGISTERED);
|
||||
} else if (accountList.size() == 1) {
|
||||
sender.sendMessage("[AuthMe] " + playerName + " is a single account player");
|
||||
} else {
|
||||
outputAccountsList(sender, playerName, accountList);
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
commandService.runTaskAsynchronously(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
List<String> accountList = commandService.getDataSource().getAllAuthsByIp(playerName);
|
||||
if (accountList.isEmpty()) {
|
||||
sender.sendMessage("[AuthMe] This IP does not exist in the database.");
|
||||
} else if (accountList.size() == 1) {
|
||||
sender.sendMessage("[AuthMe] " + playerName + " is a single account player");
|
||||
} else {
|
||||
outputAccountsList(sender, playerName, accountList);
|
||||
}
|
||||
if (accountList.size() == 1) {
|
||||
sender.sendMessage("[AuthMe] " + playerQueryFinal + " is a single account player");
|
||||
return;
|
||||
}
|
||||
int i = 0;
|
||||
for (String account : accountList) {
|
||||
i++;
|
||||
message.append(account);
|
||||
if (i != accountList.size()) {
|
||||
message.append(", ");
|
||||
} else {
|
||||
message.append('.');
|
||||
}
|
||||
}
|
||||
sender.sendMessage("[AuthMe] " + playerQueryFinal + " has " + String.valueOf(accountList.size()) + " accounts");
|
||||
sender.sendMessage(message.toString());
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private static void outputAccountsList(CommandSender sender, String playerName, List<String> accountList) {
|
||||
sender.sendMessage("[AuthMe] " + playerName + " has " + accountList.size() + " accounts.");
|
||||
String message = "[AuthMe] " + StringUtils.join(", ", accountList) + ".";
|
||||
sender.sendMessage(message);
|
||||
}
|
||||
}
|
||||
|
@ -1,21 +1,25 @@
|
||||
package fr.xephi.authme.command.executable.authme;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.command.CommandParts;
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.command.ExecutableCommand;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* AuthMe base command; shows the version and some command pointers.
|
||||
*/
|
||||
public class AuthMeCommand extends ExecutableCommand {
|
||||
public class AuthMeCommand implements ExecutableCommand {
|
||||
|
||||
@Override
|
||||
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
||||
// Show some version info
|
||||
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) + " about" + ChatColor.YELLOW + " to view about.");
|
||||
return true;
|
||||
public void executeCommand(CommandSender sender, List<String> arguments, CommandService commandService) {
|
||||
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 + "/authme help" + ChatColor.YELLOW
|
||||
+ " to view help.");
|
||||
sender.sendMessage(ChatColor.YELLOW + "Use the command " + ChatColor.GOLD + "/authme about" + ChatColor.YELLOW
|
||||
+ " to view about.");
|
||||
}
|
||||
}
|
||||
|
@ -1,95 +1,80 @@
|
||||
package fr.xephi.authme.command.executable.authme;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||
import fr.xephi.authme.cache.auth.PlayerCache;
|
||||
import fr.xephi.authme.command.CommandParts;
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.command.ExecutableCommand;
|
||||
import fr.xephi.authme.security.PasswordSecurity;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
import fr.xephi.authme.output.MessageKey;
|
||||
import fr.xephi.authme.output.Messages;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import org.bukkit.Bukkit;
|
||||
import fr.xephi.authme.security.crypts.HashedPassword;
|
||||
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
||||
import fr.xephi.authme.settings.properties.SecuritySettings;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Admin command for changing a player's password.
|
||||
*/
|
||||
public class ChangePasswordAdminCommand extends ExecutableCommand {
|
||||
public class ChangePasswordAdminCommand implements ExecutableCommand {
|
||||
|
||||
@Override
|
||||
public boolean executeCommand(final CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
||||
final AuthMe plugin = AuthMe.getInstance();
|
||||
// Messages instance
|
||||
final Messages m = plugin.getMessages();
|
||||
|
||||
public void executeCommand(final CommandSender sender, List<String> arguments,
|
||||
final CommandService commandService) {
|
||||
// Get the player and password
|
||||
String playerName = commandArguments.get(0);
|
||||
final String playerPass = commandArguments.get(1);
|
||||
String playerName = arguments.get(0);
|
||||
final String playerPass = arguments.get(1);
|
||||
|
||||
// Validate the password
|
||||
String playerPassLowerCase = playerPass.toLowerCase();
|
||||
if (playerPassLowerCase.contains("delete") || playerPassLowerCase.contains("where")
|
||||
|| playerPassLowerCase.contains("insert") || playerPassLowerCase.contains("modify")
|
||||
|| playerPassLowerCase.contains("from") || playerPassLowerCase.contains("select")
|
||||
|| playerPassLowerCase.contains(";") || playerPassLowerCase.contains("null")
|
||||
|| !playerPassLowerCase.matches(Settings.getPassRegex)) {
|
||||
m.send(sender, MessageKey.PASSWORD_MATCH_ERROR);
|
||||
return true;
|
||||
if (!playerPassLowerCase.matches(commandService.getProperty(RestrictionSettings.ALLOWED_PASSWORD_REGEX))) {
|
||||
commandService.send(sender, MessageKey.PASSWORD_MATCH_ERROR);
|
||||
return;
|
||||
}
|
||||
if (playerPassLowerCase.equalsIgnoreCase(playerName)) {
|
||||
m.send(sender, MessageKey.PASSWORD_IS_USERNAME_ERROR);
|
||||
return true;
|
||||
commandService.send(sender, MessageKey.PASSWORD_IS_USERNAME_ERROR);
|
||||
return;
|
||||
}
|
||||
if (playerPassLowerCase.length() < Settings.getPasswordMinLen
|
||||
|| playerPassLowerCase.length() > Settings.passwordMaxLength) {
|
||||
m.send(sender, MessageKey.INVALID_PASSWORD_LENGTH);
|
||||
return true;
|
||||
if (playerPassLowerCase.length() < commandService.getProperty(SecuritySettings.MIN_PASSWORD_LENGTH)
|
||||
|| playerPassLowerCase.length() > commandService.getProperty(SecuritySettings.MAX_PASSWORD_LENGTH)) {
|
||||
commandService.send(sender, MessageKey.INVALID_PASSWORD_LENGTH);
|
||||
return;
|
||||
}
|
||||
if (!Settings.unsafePasswords.isEmpty() && Settings.unsafePasswords.contains(playerPassLowerCase)) {
|
||||
m.send(sender, MessageKey.PASSWORD_UNSAFE_ERROR);
|
||||
return true;
|
||||
if (commandService.getProperty(SecuritySettings.UNSAFE_PASSWORDS).contains(playerPassLowerCase)) {
|
||||
commandService.send(sender, MessageKey.PASSWORD_UNSAFE_ERROR);
|
||||
return;
|
||||
}
|
||||
// Set the password
|
||||
final String playerNameLowerCase = playerName.toLowerCase();
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {
|
||||
commandService.runTaskAsynchronously(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
String hash;
|
||||
try {
|
||||
hash = PasswordSecurity.getHash(Settings.getPasswordHash, playerPass, playerNameLowerCase);
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
m.send(sender, MessageKey.ERROR);
|
||||
return;
|
||||
}
|
||||
DataSource dataSource = commandService.getDataSource();
|
||||
PlayerAuth auth = null;
|
||||
if (PlayerCache.getInstance().isAuthenticated(playerNameLowerCase)) {
|
||||
auth = PlayerCache.getInstance().getAuth(playerNameLowerCase);
|
||||
} else if (plugin.database.isAuthAvailable(playerNameLowerCase)) {
|
||||
auth = plugin.database.getAuth(playerNameLowerCase);
|
||||
} else if (dataSource.isAuthAvailable(playerNameLowerCase)) {
|
||||
auth = dataSource.getAuth(playerNameLowerCase);
|
||||
}
|
||||
if (auth == null) {
|
||||
m.send(sender, MessageKey.UNKNOWN_USER);
|
||||
commandService.send(sender, MessageKey.UNKNOWN_USER);
|
||||
return;
|
||||
}
|
||||
auth.setHash(hash);
|
||||
if (PasswordSecurity.userSalt.containsKey(playerNameLowerCase)) {
|
||||
auth.setSalt(PasswordSecurity.userSalt.get(playerNameLowerCase));
|
||||
plugin.database.updateSalt(auth);
|
||||
|
||||
HashedPassword hashedPassword = commandService.getPasswordSecurity()
|
||||
.computeHash(playerPass, playerNameLowerCase);
|
||||
auth.setPassword(hashedPassword);
|
||||
|
||||
if (!dataSource.updatePassword(auth)) {
|
||||
commandService.send(sender, MessageKey.ERROR);
|
||||
} else {
|
||||
commandService.send(sender, MessageKey.PASSWORD_CHANGED_SUCCESS);
|
||||
ConsoleLogger.info(playerNameLowerCase + "'s password changed");
|
||||
}
|
||||
if (!plugin.database.updatePassword(auth)) {
|
||||
m.send(sender, MessageKey.ERROR);
|
||||
return;
|
||||
}
|
||||
sender.sendMessage("pwd_changed");
|
||||
ConsoleLogger.info(playerNameLowerCase + "'s password changed");
|
||||
}
|
||||
|
||||
});
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,94 @@
|
||||
package fr.xephi.authme.command.executable.authme;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.command.ExecutableCommand;
|
||||
import fr.xephi.authme.converter.Converter;
|
||||
import fr.xephi.authme.converter.CrazyLoginConverter;
|
||||
import fr.xephi.authme.converter.RakamakConverter;
|
||||
import fr.xephi.authme.converter.RoyalAuthConverter;
|
||||
import fr.xephi.authme.converter.SqliteToSql;
|
||||
import fr.xephi.authme.converter.vAuthConverter;
|
||||
import fr.xephi.authme.converter.xAuthConverter;
|
||||
import fr.xephi.authme.output.MessageKey;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ConverterCommand implements ExecutableCommand {
|
||||
|
||||
@Override
|
||||
public void executeCommand(CommandSender sender, List<String> arguments, CommandService commandService) {
|
||||
// AuthMe plugin instance
|
||||
final AuthMe plugin = AuthMe.getInstance();
|
||||
|
||||
// Get the conversion job
|
||||
String job = arguments.get(0);
|
||||
|
||||
// Determine the job type
|
||||
ConvertType jobType = ConvertType.fromName(job);
|
||||
if (jobType == null) {
|
||||
commandService.send(sender, MessageKey.ERROR);
|
||||
return;
|
||||
}
|
||||
|
||||
// Get the proper converter instance
|
||||
Converter converter = null;
|
||||
switch (jobType) {
|
||||
case XAUTH:
|
||||
converter = new xAuthConverter(plugin, sender);
|
||||
break;
|
||||
case CRAZYLOGIN:
|
||||
converter = new CrazyLoginConverter(plugin, sender);
|
||||
break;
|
||||
case RAKAMAK:
|
||||
converter = new RakamakConverter(plugin, sender);
|
||||
break;
|
||||
case ROYALAUTH:
|
||||
converter = new RoyalAuthConverter(plugin);
|
||||
break;
|
||||
case VAUTH:
|
||||
converter = new vAuthConverter(plugin, sender);
|
||||
break;
|
||||
case SQLITETOSQL:
|
||||
converter = new SqliteToSql(plugin, sender, commandService.getSettings());
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
// Run the convert job
|
||||
commandService.runTaskAsynchronously(converter);
|
||||
|
||||
// Show a status message
|
||||
sender.sendMessage("[AuthMe] Successfully converted from " + jobType.getName());
|
||||
}
|
||||
|
||||
public enum ConvertType {
|
||||
XAUTH("xauth"),
|
||||
CRAZYLOGIN("crazylogin"),
|
||||
RAKAMAK("rakamak"),
|
||||
ROYALAUTH("royalauth"),
|
||||
VAUTH("vauth"),
|
||||
SQLITETOSQL("sqlitetosql");
|
||||
|
||||
final String name;
|
||||
|
||||
ConvertType(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public static ConvertType fromName(String name) {
|
||||
for (ConvertType type : ConvertType.values()) {
|
||||
if (type.getName().equalsIgnoreCase(name)) {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
String getName() {
|
||||
return this.name;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,31 +1,27 @@
|
||||
package fr.xephi.authme.command.executable.authme;
|
||||
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.command.CommandParts;
|
||||
import fr.xephi.authme.command.ExecutableCommand;
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.command.PlayerCommand;
|
||||
import fr.xephi.authme.settings.Spawn;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class FirstSpawnCommand extends ExecutableCommand {
|
||||
import java.util.List;
|
||||
|
||||
public class FirstSpawnCommand extends PlayerCommand {
|
||||
|
||||
@Override
|
||||
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
||||
public void runCommand(Player player, List<String> arguments, CommandService commandService) {
|
||||
// Make sure the command executor is a player
|
||||
try {
|
||||
if (sender instanceof Player) {
|
||||
if (Spawn.getInstance().getFirstSpawn() != null)
|
||||
((Player) sender).teleport(Spawn.getInstance().getFirstSpawn());
|
||||
else sender.sendMessage("[AuthMe] First spawn has failed, please try to define the first spawn");
|
||||
if (Spawn.getInstance().getFirstSpawn() != null) {
|
||||
player.teleport(Spawn.getInstance().getFirstSpawn());
|
||||
} else {
|
||||
sender.sendMessage("[AuthMe] Please use that command in game");
|
||||
player.sendMessage("[AuthMe] First spawn has failed, please try to define the first spawn");
|
||||
}
|
||||
} catch (NullPointerException ex) {
|
||||
// TODO ljacqu 20151119: Catching NullPointerException is never a good idea. Find what can cause one instead
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -1,45 +1,33 @@
|
||||
package fr.xephi.authme.command.executable.authme;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.command.CommandParts;
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.command.ExecutableCommand;
|
||||
import fr.xephi.authme.permission.PlayerPermission;
|
||||
import org.bukkit.Bukkit;
|
||||
import fr.xephi.authme.util.Utils;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Forces the login of a player, i.e. logs the player in without the need of a (correct) password.
|
||||
*/
|
||||
public class ForceLoginCommand extends ExecutableCommand {
|
||||
public class ForceLoginCommand implements ExecutableCommand {
|
||||
|
||||
@Override
|
||||
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
||||
// AuthMe plugin instance
|
||||
final AuthMe plugin = AuthMe.getInstance();
|
||||
|
||||
public void executeCommand(CommandSender sender, List<String> arguments, CommandService commandService) {
|
||||
// Get the player query
|
||||
String playerName = sender.getName();
|
||||
if (commandArguments.getCount() >= 1)
|
||||
playerName = commandArguments.get(0);
|
||||
String playerName = arguments.isEmpty() ? sender.getName() : arguments.get(0);
|
||||
|
||||
// Command logic
|
||||
try {
|
||||
@SuppressWarnings("deprecation")
|
||||
Player player = Bukkit.getPlayer(playerName);
|
||||
if (player == null || !player.isOnline()) {
|
||||
sender.sendMessage("Player needs to be online!");
|
||||
return true;
|
||||
}
|
||||
if (!plugin.getPermissionsManager().hasPermission(player, PlayerPermission.CAN_LOGIN_BE_FORCED)) {
|
||||
sender.sendMessage("You cannot force login for the player " + playerName + "!");
|
||||
return true;
|
||||
}
|
||||
plugin.getManagement().performLogin(player, "dontneed", true);
|
||||
Player player = Utils.getPlayer(playerName);
|
||||
if (player == null || !player.isOnline()) {
|
||||
sender.sendMessage("Player needs to be online!");
|
||||
} else if (!commandService.getPermissionsManager()
|
||||
.hasPermission(player, PlayerPermission.CAN_LOGIN_BE_FORCED)) {
|
||||
sender.sendMessage("You cannot force login for the player " + playerName + "!");
|
||||
} else {
|
||||
commandService.getManagement().performLogin(player, "dontneed", true);
|
||||
sender.sendMessage("Force Login for " + playerName + " performed!");
|
||||
} catch (Exception e) {
|
||||
sender.sendMessage("An error occurred while trying to get that player!");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -1,44 +1,24 @@
|
||||
package fr.xephi.authme.command.executable.authme;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||
import fr.xephi.authme.command.CommandParts;
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.command.ExecutableCommand;
|
||||
import fr.xephi.authme.output.MessageKey;
|
||||
import fr.xephi.authme.output.Messages;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class GetEmailCommand extends ExecutableCommand {
|
||||
import java.util.List;
|
||||
|
||||
public class GetEmailCommand implements ExecutableCommand {
|
||||
|
||||
/**
|
||||
* Execute the command.
|
||||
*
|
||||
* @param sender The command sender.
|
||||
* @param commandReference The command reference.
|
||||
* @param commandArguments The command arguments.
|
||||
*
|
||||
* @return True if the command was executed successfully, false otherwise.
|
||||
*/
|
||||
@Override
|
||||
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
||||
// Get the player name
|
||||
String playerName = sender.getName();
|
||||
if (commandArguments.getCount() >= 1)
|
||||
playerName = commandArguments.get(0);
|
||||
public void executeCommand(CommandSender sender, List<String> arguments, CommandService commandService) {
|
||||
String playerName = arguments.isEmpty() ? sender.getName() : arguments.get(0);
|
||||
|
||||
// Get the authenticated user
|
||||
AuthMe plugin = AuthMe.getInstance();
|
||||
Messages m = plugin.getMessages();
|
||||
PlayerAuth auth = plugin.database.getAuth(playerName.toLowerCase());
|
||||
PlayerAuth auth = commandService.getDataSource().getAuth(playerName.toLowerCase());
|
||||
if (auth == null) {
|
||||
m.send(sender, MessageKey.UNKNOWN_USER);
|
||||
return true;
|
||||
commandService.send(sender, MessageKey.UNKNOWN_USER);
|
||||
} else {
|
||||
sender.sendMessage("[AuthMe] " + playerName + "'s email: " + auth.getEmail());
|
||||
}
|
||||
|
||||
// Show the email address
|
||||
sender.sendMessage("[AuthMe] " + playerName + "'s email: " + auth.getEmail());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -1,34 +1,33 @@
|
||||
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 org.bukkit.Bukkit;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class GetIpCommand extends ExecutableCommand {
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.command.ExecutableCommand;
|
||||
import fr.xephi.authme.util.Utils;
|
||||
|
||||
public class GetIpCommand implements ExecutableCommand {
|
||||
|
||||
@Override
|
||||
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
||||
// AuthMe plugin instance
|
||||
public void executeCommand(CommandSender sender, List<String> arguments, CommandService commandService) {
|
||||
final AuthMe plugin = AuthMe.getInstance();
|
||||
|
||||
// Get the player query
|
||||
String playerName = sender.getName();
|
||||
if (commandArguments.getCount() >= 1)
|
||||
playerName = commandArguments.get(0);
|
||||
String playerName = (arguments.size() >= 1) ? arguments.get(0) : sender.getName();
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
Player player = Bukkit.getPlayer(playerName);
|
||||
Player player = Utils.getPlayer(playerName);
|
||||
if (player == null) {
|
||||
sender.sendMessage("This player is not actually online");
|
||||
return true;
|
||||
sender.sendMessage("The player is not online");
|
||||
return;
|
||||
}
|
||||
sender.sendMessage(player.getName() + "'s actual IP is : " + player.getAddress().getAddress().getHostAddress() + ":" + player.getAddress().getPort());
|
||||
|
||||
// TODO ljacqu 20151212: Revise the messages (actual IP vs. real IP...?)
|
||||
sender.sendMessage(player.getName() + "'s actual IP is : " + player.getAddress().getAddress().getHostAddress()
|
||||
+ ":" + player.getAddress().getPort());
|
||||
sender.sendMessage(player.getName() + "'s real IP is : " + plugin.getIP(player));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -1,59 +1,40 @@
|
||||
package fr.xephi.authme.command.executable.authme;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||
import fr.xephi.authme.command.CommandParts;
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.command.ExecutableCommand;
|
||||
import fr.xephi.authme.output.MessageKey;
|
||||
import fr.xephi.authme.output.Messages;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class LastLoginCommand extends ExecutableCommand {
|
||||
public class LastLoginCommand implements ExecutableCommand {
|
||||
|
||||
@Override
|
||||
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
||||
public void executeCommand(CommandSender sender, List<String> arguments, CommandService commandService) {
|
||||
// Get the player
|
||||
String playerName = sender.getName();
|
||||
if (commandArguments.getCount() >= 1)
|
||||
playerName = commandArguments.get(0);
|
||||
String playerName = (arguments.size() >= 1) ? arguments.get(0) : sender.getName();
|
||||
|
||||
// Validate the player
|
||||
AuthMe plugin = AuthMe.getInstance();
|
||||
Messages m = plugin.getMessages();
|
||||
|
||||
PlayerAuth auth;
|
||||
try {
|
||||
auth = plugin.database.getAuth(playerName.toLowerCase());
|
||||
} catch (NullPointerException e) {
|
||||
m.send(sender, MessageKey.UNKNOWN_USER);
|
||||
return true;
|
||||
}
|
||||
PlayerAuth auth = commandService.getDataSource().getAuth(playerName.toLowerCase());
|
||||
if (auth == null) {
|
||||
m.send(sender, MessageKey.USER_NOT_REGISTERED);
|
||||
return true;
|
||||
commandService.send(sender, MessageKey.USER_NOT_REGISTERED);
|
||||
return;
|
||||
}
|
||||
|
||||
// Get the last login date
|
||||
long lastLogin = auth.getLastLogin();
|
||||
final long diff = System.currentTimeMillis() - lastLogin;
|
||||
final String lastLoginMessage = (int) (diff / 86400000) + " days " + (int) (diff / 3600000 % 24) + " hours "
|
||||
+ (int) (diff / 60000 % 60) + " mins " + (int) (diff / 1000 % 60) + " secs";
|
||||
Date date = new Date(lastLogin);
|
||||
|
||||
// Get the difference
|
||||
final long diff = System.currentTimeMillis() - lastLogin;
|
||||
|
||||
// Build the message
|
||||
final String msg = (int) (diff / 86400000) + " days " + (int) (diff / 3600000 % 24) + " hours " + (int) (diff / 60000 % 60) + " mins " + (int) (diff / 1000 % 60) + " secs.";
|
||||
|
||||
// Get the player's last IP
|
||||
String lastIP = auth.getIp();
|
||||
|
||||
// Show the player status
|
||||
sender.sendMessage("[AuthMe] " + playerName + " last login : " + date.toString());
|
||||
sender.sendMessage("[AuthMe] The player " + auth.getNickname() + " is unlogged since " + msg);
|
||||
sender.sendMessage("[AuthMe] Last Player's IP: " + lastIP);
|
||||
return true;
|
||||
sender.sendMessage("[AuthMe] " + playerName + " last login: " + date.toString());
|
||||
sender.sendMessage("[AuthMe] The player " + auth.getNickname() + " last logged in "
|
||||
+ lastLoginMessage + " ago.");
|
||||
sender.sendMessage("[AuthMe] Last Player's IP: " + auth.getIp());
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
package fr.xephi.authme.command.executable.authme;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.command.CommandParts;
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.command.ExecutableCommand;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
@ -10,21 +10,10 @@ import org.bukkit.command.CommandSender;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class PurgeBannedPlayersCommand extends ExecutableCommand {
|
||||
public class PurgeBannedPlayersCommand implements ExecutableCommand {
|
||||
|
||||
/**
|
||||
* Execute the command.
|
||||
*
|
||||
* @param sender The command sender.
|
||||
* @param commandReference The command reference.
|
||||
* @param commandArguments The command arguments.
|
||||
*
|
||||
* @return True if the command was executed successfully, false otherwise.
|
||||
*/
|
||||
@Override
|
||||
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
||||
public void executeCommand(CommandSender sender, List<String> arguments, CommandService commandService) {
|
||||
// AuthMe plugin instance
|
||||
final AuthMe plugin = AuthMe.getInstance();
|
||||
|
||||
@ -35,7 +24,7 @@ public class PurgeBannedPlayersCommand extends ExecutableCommand {
|
||||
}
|
||||
|
||||
// Purge the banned players
|
||||
plugin.database.purgeBanned(bannedPlayers);
|
||||
plugin.getDataSource().purgeBanned(bannedPlayers);
|
||||
if (Settings.purgeEssentialsFile && plugin.ess != null)
|
||||
plugin.dataManager.purgeEssentials(bannedPlayers);
|
||||
if (Settings.purgePlayerDat)
|
||||
@ -47,6 +36,5 @@ public class PurgeBannedPlayersCommand extends ExecutableCommand {
|
||||
|
||||
// Show a status message
|
||||
sender.sendMessage("[AuthMe] Database has been purged correctly");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
package fr.xephi.authme.command.executable.authme;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.command.CommandParts;
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.command.ExecutableCommand;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import org.bukkit.ChatColor;
|
||||
@ -10,40 +10,29 @@ import org.bukkit.command.CommandSender;
|
||||
import java.util.Calendar;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class PurgeCommand extends ExecutableCommand {
|
||||
public class PurgeCommand implements ExecutableCommand {
|
||||
|
||||
/**
|
||||
* Execute the command.
|
||||
*
|
||||
* @param sender The command sender.
|
||||
* @param commandReference The command reference.
|
||||
* @param commandArguments The command arguments.
|
||||
*
|
||||
* @return True if the command was executed successfully, false otherwise.
|
||||
*/
|
||||
@Override
|
||||
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
||||
public void executeCommand(CommandSender sender, List<String> arguments, CommandService commandService) {
|
||||
// AuthMe plugin instance
|
||||
AuthMe plugin = AuthMe.getInstance();
|
||||
|
||||
// Get the days parameter
|
||||
String daysStr = commandArguments.get(0);
|
||||
String daysStr = arguments.get(0);
|
||||
|
||||
// Convert the days string to an integer value, and make sure it's valid
|
||||
int days;
|
||||
try {
|
||||
days = Integer.valueOf(daysStr);
|
||||
} catch (Exception ex) {
|
||||
days = Integer.parseInt(daysStr);
|
||||
} catch (NumberFormatException ex) {
|
||||
sender.sendMessage(ChatColor.RED + "The value you've entered is invalid!");
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
|
||||
// Validate the value
|
||||
if (days < 30) {
|
||||
sender.sendMessage(ChatColor.RED + "You can only purge data older than 30 days");
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
|
||||
// Create a calender instance to determine the date
|
||||
@ -52,7 +41,7 @@ public class PurgeCommand extends ExecutableCommand {
|
||||
long until = calendar.getTimeInMillis();
|
||||
|
||||
// Purge the data, get the purged values
|
||||
List<String> purged = plugin.database.autoPurgeDatabase(until);
|
||||
List<String> purged = commandService.getDataSource().autoPurgeDatabase(until);
|
||||
|
||||
// Show a status message
|
||||
sender.sendMessage(ChatColor.GOLD + "Deleted " + purged.size() + " user accounts");
|
||||
@ -69,6 +58,5 @@ public class PurgeCommand extends ExecutableCommand {
|
||||
|
||||
// Show a status message
|
||||
sender.sendMessage(ChatColor.GREEN + "[AuthMe] Database has been purged correctly");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -1,49 +1,40 @@
|
||||
package fr.xephi.authme.command.executable.authme;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||
import fr.xephi.authme.command.CommandParts;
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.command.ExecutableCommand;
|
||||
import fr.xephi.authme.output.MessageKey;
|
||||
import fr.xephi.authme.output.Messages;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class PurgeLastPositionCommand extends ExecutableCommand {
|
||||
import java.util.List;
|
||||
|
||||
public class PurgeLastPositionCommand implements ExecutableCommand {
|
||||
|
||||
/**
|
||||
* Execute the command.
|
||||
*
|
||||
* @param sender The command sender.
|
||||
* @param commandReference The command reference.
|
||||
* @param commandArguments The command arguments.
|
||||
*
|
||||
* @return True if the command was executed successfully, false otherwise.
|
||||
*/
|
||||
@Override
|
||||
public boolean executeCommand(final CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
||||
// AuthMe plugin instance
|
||||
final AuthMe plugin = AuthMe.getInstance();
|
||||
|
||||
// Messages instance
|
||||
final Messages m = plugin.getMessages();
|
||||
|
||||
// Get the player
|
||||
String playerName = sender.getName();
|
||||
if (commandArguments.getCount() >= 1)
|
||||
playerName = commandArguments.get(0);
|
||||
public void executeCommand(final CommandSender sender, List<String> arguments, CommandService commandService) {
|
||||
String playerName = arguments.isEmpty() ? sender.getName() : arguments.get(0);
|
||||
String playerNameLowerCase = playerName.toLowerCase();
|
||||
|
||||
// Purge the last position of the player
|
||||
try {
|
||||
if (playerNameLowerCase.equalsIgnoreCase("*"))
|
||||
{
|
||||
for (PlayerAuth auth : commandService.getDataSource().getAllAuths())
|
||||
{
|
||||
// Set the last position
|
||||
auth.setQuitLocX(0D);
|
||||
auth.setQuitLocY(0D);
|
||||
auth.setQuitLocZ(0D);
|
||||
auth.setWorld("world");
|
||||
commandService.getDataSource().updateQuitLoc(auth);
|
||||
}
|
||||
sender.sendMessage("All players last position locations are now reset");
|
||||
}
|
||||
else
|
||||
{
|
||||
// Get the user auth and make sure the user exists
|
||||
PlayerAuth auth = plugin.database.getAuth(playerNameLowerCase);
|
||||
PlayerAuth auth = commandService.getDataSource().getAuth(playerNameLowerCase);
|
||||
if (auth == null) {
|
||||
m.send(sender, MessageKey.UNKNOWN_USER);
|
||||
return true;
|
||||
commandService.send(sender, MessageKey.UNKNOWN_USER);
|
||||
return;
|
||||
}
|
||||
|
||||
// Set the last position
|
||||
@ -51,17 +42,11 @@ public class PurgeLastPositionCommand extends ExecutableCommand {
|
||||
auth.setQuitLocY(0D);
|
||||
auth.setQuitLocZ(0D);
|
||||
auth.setWorld("world");
|
||||
plugin.database.updateQuitLoc(auth);
|
||||
commandService.getDataSource().updateQuitLoc(auth);
|
||||
|
||||
// Show a status message
|
||||
sender.sendMessage(playerNameLowerCase + "'s last position location is now reset");
|
||||
|
||||
} catch (Exception e) {
|
||||
ConsoleLogger.showError("An error occurred while trying to reset location or player do not exist, please see below: ");
|
||||
ConsoleLogger.showError(e.getMessage());
|
||||
if (sender instanceof Player)
|
||||
sender.sendMessage("An error occurred while trying to reset location or player do not exist, please see logs");
|
||||
}
|
||||
return true;
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,100 +1,78 @@
|
||||
package fr.xephi.authme.command.executable.authme;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||
import fr.xephi.authme.command.CommandParts;
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.command.ExecutableCommand;
|
||||
import fr.xephi.authme.security.PasswordSecurity;
|
||||
import fr.xephi.authme.output.MessageKey;
|
||||
import fr.xephi.authme.output.Messages;
|
||||
import fr.xephi.authme.security.crypts.HashedPassword;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.settings.properties.SecuritySettings;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Admin command to register a user.
|
||||
*/
|
||||
public class RegisterAdminCommand extends ExecutableCommand {
|
||||
public class RegisterAdminCommand implements ExecutableCommand {
|
||||
|
||||
/**
|
||||
* Execute the command.
|
||||
*
|
||||
* @param sender The command sender.
|
||||
* @param commandReference The command reference.
|
||||
* @param commandArguments The command arguments.
|
||||
*
|
||||
* @return True if the command was executed successfully, false otherwise.
|
||||
*/
|
||||
@Override
|
||||
public boolean executeCommand(final CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
||||
// AuthMe plugin instance
|
||||
final AuthMe plugin = AuthMe.getInstance();
|
||||
|
||||
// Messages instance
|
||||
final Messages m = plugin.getMessages();
|
||||
|
||||
public void executeCommand(final CommandSender sender, List<String> arguments,
|
||||
final CommandService commandService) {
|
||||
// Get the player name and password
|
||||
final String playerName = commandArguments.get(0);
|
||||
final String playerPass = commandArguments.get(1);
|
||||
final String playerName = arguments.get(0).toLowerCase();
|
||||
final String playerPass = arguments.get(1).toLowerCase();
|
||||
final String playerNameLowerCase = playerName.toLowerCase();
|
||||
final String playerPassLowerCase = playerPass.toLowerCase();
|
||||
|
||||
// Command logic
|
||||
if (playerPassLowerCase.contains("delete") || playerPassLowerCase.contains("where")
|
||||
|| playerPassLowerCase.contains("insert") || playerPassLowerCase.contains("modify")
|
||||
|| playerPassLowerCase.contains("from") || playerPassLowerCase.contains("select")
|
||||
|| playerPassLowerCase.contains(";") || playerPassLowerCase.contains("null")
|
||||
|| !playerPassLowerCase.matches(Settings.getPassRegex)) {
|
||||
m.send(sender, MessageKey.PASSWORD_MATCH_ERROR);
|
||||
return true;
|
||||
if (!playerPassLowerCase.matches(Settings.getPassRegex)) {
|
||||
commandService.send(sender, MessageKey.PASSWORD_MATCH_ERROR);
|
||||
return;
|
||||
}
|
||||
if (playerPassLowerCase.equalsIgnoreCase(playerName)) {
|
||||
m.send(sender, MessageKey.PASSWORD_IS_USERNAME_ERROR);
|
||||
return true;
|
||||
commandService.send(sender, MessageKey.PASSWORD_IS_USERNAME_ERROR);
|
||||
return;
|
||||
}
|
||||
if (playerPassLowerCase.length() < Settings.getPasswordMinLen || playerPassLowerCase.length() > Settings.passwordMaxLength) {
|
||||
m.send(sender, MessageKey.INVALID_PASSWORD_LENGTH);
|
||||
return true;
|
||||
if (playerPassLowerCase.length() < commandService.getProperty(SecuritySettings.MIN_PASSWORD_LENGTH)
|
||||
|| playerPassLowerCase.length() > commandService.getProperty(SecuritySettings.MAX_PASSWORD_LENGTH)) {
|
||||
commandService.send(sender, MessageKey.INVALID_PASSWORD_LENGTH);
|
||||
return;
|
||||
}
|
||||
if (!Settings.unsafePasswords.isEmpty()) {
|
||||
if (Settings.unsafePasswords.contains(playerPassLowerCase)) {
|
||||
m.send(sender, MessageKey.PASSWORD_UNSAFE_ERROR);
|
||||
return true;
|
||||
}
|
||||
if (!Settings.unsafePasswords.isEmpty() && Settings.unsafePasswords.contains(playerPassLowerCase)) {
|
||||
commandService.send(sender, MessageKey.PASSWORD_UNSAFE_ERROR);
|
||||
return;
|
||||
}
|
||||
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable() {
|
||||
@SuppressWarnings("deprecation")
|
||||
commandService.runTaskAsynchronously(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
if (plugin.database.isAuthAvailable(playerNameLowerCase)) {
|
||||
m.send(sender, MessageKey.NAME_ALREADY_REGISTERED);
|
||||
return;
|
||||
}
|
||||
String hash = PasswordSecurity.getHash(Settings.getPasswordHash, playerPass, playerNameLowerCase);
|
||||
PlayerAuth auth = new PlayerAuth(playerNameLowerCase, hash, "192.168.0.1", 0L, "your@email.com", playerName);
|
||||
if (PasswordSecurity.userSalt.containsKey(playerNameLowerCase) && PasswordSecurity.userSalt.get(playerNameLowerCase) != null)
|
||||
auth.setSalt(PasswordSecurity.userSalt.get(playerNameLowerCase));
|
||||
else auth.setSalt("");
|
||||
if (!plugin.database.saveAuth(auth)) {
|
||||
m.send(sender, MessageKey.ERROR);
|
||||
return;
|
||||
}
|
||||
plugin.database.setUnlogged(playerNameLowerCase);
|
||||
if (Bukkit.getPlayerExact(playerName) != null)
|
||||
Bukkit.getPlayerExact(playerName).kickPlayer("An admin just registered you, please log again");
|
||||
m.send(sender, MessageKey.REGISTER_SUCCESS);
|
||||
ConsoleLogger.info(playerNameLowerCase + " registered");
|
||||
} catch (NoSuchAlgorithmException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
m.send(sender, MessageKey.ERROR);
|
||||
if (commandService.getDataSource().isAuthAvailable(playerNameLowerCase)) {
|
||||
commandService.send(sender, MessageKey.NAME_ALREADY_REGISTERED);
|
||||
return;
|
||||
}
|
||||
HashedPassword hashedPassword = commandService.getPasswordSecurity()
|
||||
.computeHash(playerPass, playerNameLowerCase);
|
||||
PlayerAuth auth = PlayerAuth.builder()
|
||||
.name(playerNameLowerCase)
|
||||
.realName(playerName)
|
||||
.password(hashedPassword)
|
||||
.build();
|
||||
|
||||
if (!commandService.getDataSource().saveAuth(auth)) {
|
||||
commandService.send(sender, MessageKey.ERROR);
|
||||
return;
|
||||
}
|
||||
commandService.getDataSource().setUnlogged(playerNameLowerCase);
|
||||
if (Bukkit.getPlayerExact(playerName) != null) {
|
||||
Bukkit.getPlayerExact(playerName).kickPlayer("An admin just registered you, please log again");
|
||||
} else {
|
||||
commandService.send(sender, MessageKey.REGISTER_SUCCESS);
|
||||
ConsoleLogger.info(playerName + " registered");
|
||||
}
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -1,62 +1,34 @@
|
||||
package fr.xephi.authme.command.executable.authme;
|
||||
|
||||
//import org.bukkit.ChatColor;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.command.CommandParts;
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.command.ExecutableCommand;
|
||||
import fr.xephi.authme.output.MessageKey;
|
||||
import fr.xephi.authme.output.Messages;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.util.Profiler;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The reload command.
|
||||
*/
|
||||
public class ReloadCommand extends ExecutableCommand {
|
||||
public class ReloadCommand implements ExecutableCommand {
|
||||
|
||||
/**
|
||||
* Execute the command.
|
||||
*
|
||||
* @param sender The command sender.
|
||||
* @param commandReference The command reference.
|
||||
* @param commandArguments The command arguments.
|
||||
*
|
||||
* @return True if the command was executed successfully, false otherwise.
|
||||
*/
|
||||
@Override
|
||||
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
||||
// Profile the reload process
|
||||
Profiler p = new Profiler(true);
|
||||
|
||||
// AuthMe plugin instance
|
||||
AuthMe plugin = AuthMe.getInstance();
|
||||
|
||||
// Messages instance
|
||||
Messages m = plugin.getMessages();
|
||||
|
||||
// Show a status message
|
||||
// sender.sendMessage(ChatColor.YELLOW + "Reloading AuthMeReloaded...");
|
||||
|
||||
public void executeCommand(CommandSender sender, List<String> arguments, CommandService commandService) {
|
||||
AuthMe plugin = commandService.getAuthMe();
|
||||
try {
|
||||
Settings.reload();
|
||||
Messages.getInstance().reloadManager();
|
||||
plugin.getModuleManager().reloadModules();
|
||||
plugin.setupDatabase();
|
||||
commandService.getSettings().reload();
|
||||
commandService.reloadMessages(commandService.getSettings().getMessagesFile());
|
||||
// TODO #432: We should not reload only certain plugin entities but actually reinitialize all elements,
|
||||
// i.e. here in the future we might not have setupDatabase() but Authme.onEnable(), maybe after
|
||||
// a call to some destructor method
|
||||
plugin.setupDatabase(commandService.getSettings());
|
||||
commandService.send(sender, MessageKey.CONFIG_RELOAD_SUCCESS);
|
||||
} catch (Exception e) {
|
||||
ConsoleLogger.showError("Fatal error occurred! AuthMe instance ABORTED!");
|
||||
ConsoleLogger.writeStackTrace(e);
|
||||
sender.sendMessage("Error occurred during reload of AuthMe: aborting");
|
||||
ConsoleLogger.logException("Aborting! Encountered exception during reload of AuthMe:", e);
|
||||
plugin.stopOrUnload();
|
||||
return false;
|
||||
}
|
||||
|
||||
// Show a status message
|
||||
// TODO: add the profiler result
|
||||
m.send(sender, MessageKey.CONFIG_RELOAD_SUCCESS);
|
||||
|
||||
// AuthMeReloaded reloaded, show a status message
|
||||
// sender.sendMessage(ChatColor.GREEN + "AuthMeReloaded has been reloaded successfully, took " + p.getTimeFormatted() + "!");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -1,44 +0,0 @@
|
||||
package fr.xephi.authme.command.executable.authme;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||
import fr.xephi.authme.command.CommandParts;
|
||||
import fr.xephi.authme.command.ExecutableCommand;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class ResetNameCommand extends ExecutableCommand {
|
||||
|
||||
/**
|
||||
* Execute the command.
|
||||
*
|
||||
* @param sender The command sender.
|
||||
* @param commandReference The command reference.
|
||||
* @param commandArguments The command arguments.
|
||||
*
|
||||
* @return True if the command was executed successfully, false otherwise.
|
||||
*/
|
||||
@Override
|
||||
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
||||
// AuthMe plugin instance
|
||||
final AuthMe plugin = AuthMe.getInstance();
|
||||
|
||||
// Command logic
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
List<PlayerAuth> authentications = plugin.database.getAllAuths();
|
||||
for (PlayerAuth auth : authentications) {
|
||||
auth.setRealName("Player");
|
||||
plugin.database.updateSession(auth);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -1,66 +1,59 @@
|
||||
package fr.xephi.authme.command.executable.authme;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||
import fr.xephi.authme.cache.auth.PlayerCache;
|
||||
import fr.xephi.authme.command.CommandParts;
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.command.ExecutableCommand;
|
||||
import fr.xephi.authme.output.MessageKey;
|
||||
import fr.xephi.authme.output.Messages;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.util.Utils;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class SetEmailCommand extends ExecutableCommand {
|
||||
import java.util.List;
|
||||
|
||||
public class SetEmailCommand implements ExecutableCommand {
|
||||
|
||||
/**
|
||||
* Execute the command.
|
||||
*
|
||||
* @param sender The command sender.
|
||||
* @param commandReference The command reference.
|
||||
* @param commandArguments The command arguments.
|
||||
*
|
||||
* @return True if the command was executed successfully, false otherwise.
|
||||
*/
|
||||
@Override
|
||||
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
||||
// AuthMe plugin instance
|
||||
AuthMe plugin = AuthMe.getInstance();
|
||||
|
||||
// Messages instance
|
||||
Messages m = plugin.getMessages();
|
||||
|
||||
public void executeCommand(final CommandSender sender, List<String> arguments,
|
||||
final CommandService commandService) {
|
||||
// Get the player name and email address
|
||||
String playerName = commandArguments.get(0);
|
||||
String playerEmail = commandArguments.get(1);
|
||||
final String playerName = arguments.get(0);
|
||||
final String playerEmail = arguments.get(1);
|
||||
|
||||
// Validate the email address
|
||||
if (!Settings.isEmailCorrect(playerEmail)) {
|
||||
m.send(sender, MessageKey.INVALID_EMAIL);
|
||||
return true;
|
||||
if (!Utils.isEmailCorrect(playerEmail, commandService.getSettings())) {
|
||||
commandService.send(sender, MessageKey.INVALID_EMAIL);
|
||||
return;
|
||||
}
|
||||
|
||||
// Validate the user
|
||||
PlayerAuth auth = plugin.database.getAuth(playerName.toLowerCase());
|
||||
if (auth == null) {
|
||||
m.send(sender, MessageKey.UNKNOWN_USER);
|
||||
return true;
|
||||
}
|
||||
commandService.runTaskAsynchronously(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
// Validate the user
|
||||
PlayerAuth auth = commandService.getDataSource().getAuth(playerName);
|
||||
if (auth == null) {
|
||||
commandService.send(sender, MessageKey.UNKNOWN_USER);
|
||||
return;
|
||||
} else if (commandService.getDataSource().isEmailStored(playerEmail)) {
|
||||
commandService.send(sender, MessageKey.EMAIL_ALREADY_USED_ERROR);
|
||||
return;
|
||||
}
|
||||
|
||||
// Set the email address
|
||||
auth.setEmail(playerEmail);
|
||||
if (!plugin.database.updateEmail(auth)) {
|
||||
m.send(sender, MessageKey.ERROR);
|
||||
return true;
|
||||
}
|
||||
// Set the email address
|
||||
auth.setEmail(playerEmail);
|
||||
if (!commandService.getDataSource().updateEmail(auth)) {
|
||||
commandService.send(sender, MessageKey.ERROR);
|
||||
return;
|
||||
}
|
||||
|
||||
// Update the player cache
|
||||
if (PlayerCache.getInstance().getAuth(playerName.toLowerCase()) != null)
|
||||
PlayerCache.getInstance().updatePlayer(auth);
|
||||
// Update the player cache
|
||||
if (PlayerCache.getInstance().getAuth(playerName) != null) {
|
||||
PlayerCache.getInstance().updatePlayer(auth);
|
||||
}
|
||||
|
||||
// Show a status message
|
||||
m.send(sender, MessageKey.EMAIL_CHANGED_SUCCESS);
|
||||
return true;
|
||||
// Show a status message
|
||||
commandService.send(sender, MessageKey.EMAIL_CHANGED_SUCCESS);
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -1,38 +1,25 @@
|
||||
package fr.xephi.authme.command.executable.authme;
|
||||
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.command.CommandParts;
|
||||
import fr.xephi.authme.command.ExecutableCommand;
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.command.PlayerCommand;
|
||||
import fr.xephi.authme.settings.Spawn;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class SetFirstSpawnCommand extends ExecutableCommand {
|
||||
import java.util.List;
|
||||
|
||||
public class SetFirstSpawnCommand extends PlayerCommand {
|
||||
|
||||
/**
|
||||
* Execute the command.
|
||||
*
|
||||
* @param sender The command sender.
|
||||
* @param commandReference The command reference.
|
||||
* @param commandArguments The command arguments.
|
||||
*
|
||||
* @return True if the command was executed successfully, false otherwise.
|
||||
*/
|
||||
@Override
|
||||
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
||||
public void runCommand(Player player, List<String> arguments, CommandService commandService) {
|
||||
try {
|
||||
if (sender instanceof Player) {
|
||||
if (Spawn.getInstance().setFirstSpawn(((Player) sender).getLocation()))
|
||||
sender.sendMessage("[AuthMe] Correctly defined new first spawn point");
|
||||
else sender.sendMessage("[AuthMe] SetFirstSpawn has failed, please retry");
|
||||
if (Spawn.getInstance().setFirstSpawn(player.getLocation())) {
|
||||
player.sendMessage("[AuthMe] Correctly defined new first spawn point");
|
||||
} else {
|
||||
sender.sendMessage("[AuthMe] Please use that command in game");
|
||||
player.sendMessage("[AuthMe] SetFirstSpawn has failed, please retry");
|
||||
}
|
||||
} catch (NullPointerException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -1,41 +1,25 @@
|
||||
package fr.xephi.authme.command.executable.authme;
|
||||
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.command.CommandParts;
|
||||
import fr.xephi.authme.command.ExecutableCommand;
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.command.PlayerCommand;
|
||||
import fr.xephi.authme.settings.Spawn;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class SetSpawnCommand extends ExecutableCommand {
|
||||
import java.util.List;
|
||||
|
||||
public class SetSpawnCommand extends PlayerCommand {
|
||||
|
||||
/**
|
||||
* Execute the command.
|
||||
*
|
||||
* @param sender The command sender.
|
||||
* @param commandReference The command reference.
|
||||
* @param commandArguments The command arguments.
|
||||
*
|
||||
* @return True if the command was executed successfully, false otherwise.
|
||||
*/
|
||||
@Override
|
||||
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
||||
// Make sure the command executor is a player
|
||||
public void runCommand(Player player, List<String> arguments, CommandService commandService) {
|
||||
try {
|
||||
if (sender instanceof Player) {
|
||||
if (Spawn.getInstance().setSpawn(((Player) sender).getLocation())) {
|
||||
sender.sendMessage("[AuthMe] Correctly defined new spawn point");
|
||||
} else {
|
||||
sender.sendMessage("[AuthMe] SetSpawn has failed, please retry");
|
||||
}
|
||||
if (Spawn.getInstance().setSpawn(player.getLocation())) {
|
||||
player.sendMessage("[AuthMe] Correctly defined new spawn point");
|
||||
} else {
|
||||
sender.sendMessage("[AuthMe] Please use that command in game");
|
||||
player.sendMessage("[AuthMe] SetSpawn has failed, please retry");
|
||||
}
|
||||
} catch (NullPointerException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -1,39 +1,25 @@
|
||||
package fr.xephi.authme.command.executable.authme;
|
||||
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.command.CommandParts;
|
||||
import fr.xephi.authme.command.ExecutableCommand;
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.command.PlayerCommand;
|
||||
import fr.xephi.authme.settings.Spawn;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class SpawnCommand extends ExecutableCommand {
|
||||
import java.util.List;
|
||||
|
||||
public class SpawnCommand extends PlayerCommand {
|
||||
|
||||
/**
|
||||
* Execute the command.
|
||||
*
|
||||
* @param sender The command sender.
|
||||
* @param commandReference The command reference.
|
||||
* @param commandArguments The command arguments.
|
||||
*
|
||||
* @return True if the command was executed successfully, false otherwise.
|
||||
*/
|
||||
@Override
|
||||
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
||||
// Make sure the command executor is a player
|
||||
public void runCommand(Player player, List<String> arguments, CommandService commandService) {
|
||||
try {
|
||||
if (sender instanceof Player) {
|
||||
if (Spawn.getInstance().getSpawn() != null)
|
||||
((Player) sender).teleport(Spawn.getInstance().getSpawn());
|
||||
else sender.sendMessage("[AuthMe] Spawn has failed, please try to define the spawn");
|
||||
if (Spawn.getInstance().getSpawn() != null) {
|
||||
player.teleport(Spawn.getInstance().getSpawn());
|
||||
} else {
|
||||
sender.sendMessage("[AuthMe] Please use that command in game");
|
||||
player.sendMessage("[AuthMe] Spawn has failed, please try to define the spawn");
|
||||
}
|
||||
} catch (NullPointerException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -1,64 +1,42 @@
|
||||
package fr.xephi.authme.command.executable.authme;
|
||||
|
||||
import fr.xephi.authme.AntiBot;
|
||||
import fr.xephi.authme.command.CommandParts;
|
||||
import fr.xephi.authme.command.CommandUtils;
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.command.ExecutableCommand;
|
||||
import fr.xephi.authme.command.FoundCommandResult;
|
||||
import fr.xephi.authme.command.help.HelpProvider;
|
||||
import fr.xephi.authme.util.CollectionUtils;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Display or change the status of the antibot mod.
|
||||
*/
|
||||
public class SwitchAntiBotCommand extends ExecutableCommand {
|
||||
public class SwitchAntiBotCommand implements ExecutableCommand {
|
||||
|
||||
/**
|
||||
* Execute the command.
|
||||
*
|
||||
* @param sender The command sender.
|
||||
* @param commandReference The command reference.
|
||||
* @param commandArguments The command arguments.
|
||||
*
|
||||
* @return True if the command was executed successfully, false otherwise.
|
||||
*/
|
||||
@Override
|
||||
public boolean executeCommand(final CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
||||
// Get the new state
|
||||
String newState = null;
|
||||
if (commandArguments.getCount() == 1) {
|
||||
newState = commandArguments.get(0);
|
||||
} else if(commandArguments.getCount() == 0) {
|
||||
public void executeCommand(final CommandSender sender, List<String> arguments, CommandService commandService) {
|
||||
if (arguments.isEmpty()) {
|
||||
sender.sendMessage("[AuthMe] AntiBot status: " + AntiBot.getAntiBotStatus().name());
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
|
||||
// Enable the mod
|
||||
String newState = arguments.get(0);
|
||||
|
||||
// Enable or disable the mod
|
||||
if ("ON".equalsIgnoreCase(newState)) {
|
||||
AntiBot.overrideAntiBotStatus(true);
|
||||
sender.sendMessage("[AuthMe] AntiBot Manual Override: enabled!");
|
||||
return true;
|
||||
}
|
||||
|
||||
// Disable the mod
|
||||
if ("OFF".equalsIgnoreCase(newState)) {
|
||||
} else if ("OFF".equalsIgnoreCase(newState)) {
|
||||
AntiBot.overrideAntiBotStatus(false);
|
||||
sender.sendMessage("[AuthMe] AntiBotMod Manual Override: disabled!");
|
||||
return true;
|
||||
sender.sendMessage("[AuthMe] AntiBot Manual Override: disabled!");
|
||||
} else {
|
||||
sender.sendMessage(ChatColor.DARK_RED + "Invalid AntiBot mode!");
|
||||
FoundCommandResult result = commandService.mapPartsToCommand(sender, Arrays.asList("authme", "antibot"));
|
||||
commandService.outputHelp(sender, result, HelpProvider.SHOW_ARGUMENTS);
|
||||
sender.sendMessage(ChatColor.GOLD + "Detailed help: " + ChatColor.WHITE + "/authme help antibot");
|
||||
}
|
||||
|
||||
// Show the invalid arguments warning
|
||||
sender.sendMessage(ChatColor.DARK_RED + "Invalid AntiBot mode!");
|
||||
|
||||
// Show the command argument help
|
||||
HelpProvider.showHelp(sender, commandReference, commandReference, true, false, true, false, false, false);
|
||||
|
||||
// Show the command to use for detailed help
|
||||
List<String> helpCommandReference = CollectionUtils.getRange(commandReference.getList(), 1);
|
||||
sender.sendMessage(ChatColor.GOLD + "Detailed help: " + ChatColor.WHITE + "/"
|
||||
+ commandReference.get(0) + " help " + CommandUtils.labelsToString(helpCommandReference));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -1,18 +1,7 @@
|
||||
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.output.MessageKey;
|
||||
import fr.xephi.authme.output.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 java.util.List;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
@ -20,46 +9,47 @@ import org.bukkit.potion.PotionEffectType;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
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.CommandService;
|
||||
import fr.xephi.authme.command.ExecutableCommand;
|
||||
import fr.xephi.authme.output.MessageKey;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.task.MessageTask;
|
||||
import fr.xephi.authme.task.TimeoutTask;
|
||||
import fr.xephi.authme.util.Utils;
|
||||
|
||||
/**
|
||||
* Admin command to unregister a player.
|
||||
*/
|
||||
public class UnregisterAdminCommand extends ExecutableCommand {
|
||||
public class UnregisterAdminCommand implements ExecutableCommand {
|
||||
|
||||
|
||||
/**
|
||||
* Execute the command.
|
||||
*
|
||||
* @param sender The command sender.
|
||||
* @param commandReference The command reference.
|
||||
* @param commandArguments The command arguments.
|
||||
*
|
||||
* @return True if the command was executed successfully, false otherwise.
|
||||
*/
|
||||
@Override
|
||||
public boolean executeCommand(final CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
||||
public void executeCommand(final CommandSender sender, List<String> arguments, CommandService commandService) {
|
||||
// AuthMe plugin instance
|
||||
final AuthMe plugin = AuthMe.getInstance();
|
||||
|
||||
// Messages instance
|
||||
final Messages m = plugin.getMessages();
|
||||
|
||||
// Get the player name
|
||||
String playerName = commandArguments.get(0);
|
||||
String playerName = arguments.get(0);
|
||||
String playerNameLowerCase = playerName.toLowerCase();
|
||||
|
||||
// Make sure the user is valid
|
||||
if (!plugin.database.isAuthAvailable(playerNameLowerCase)) {
|
||||
m.send(sender, MessageKey.UNKNOWN_USER);
|
||||
return true;
|
||||
if (!commandService.getDataSource().isAuthAvailable(playerNameLowerCase)) {
|
||||
commandService.send(sender, MessageKey.UNKNOWN_USER);
|
||||
return;
|
||||
}
|
||||
|
||||
// Remove the player
|
||||
if (!plugin.database.removeAuth(playerNameLowerCase)) {
|
||||
m.send(sender, MessageKey.ERROR);
|
||||
return true;
|
||||
if (!commandService.getDataSource().removeAuth(playerNameLowerCase)) {
|
||||
commandService.send(sender, MessageKey.ERROR);
|
||||
return;
|
||||
}
|
||||
|
||||
// Unregister the player
|
||||
Player target = Bukkit.getPlayer(playerNameLowerCase);
|
||||
Player target = Utils.getPlayer(playerNameLowerCase);
|
||||
PlayerCache.getInstance().removePlayer(playerNameLowerCase);
|
||||
Utils.setGroup(target, Utils.GroupType.UNREGISTERED);
|
||||
if (target != null && target.isOnline()) {
|
||||
@ -74,20 +64,16 @@ public class UnregisterAdminCommand extends ExecutableCommand {
|
||||
}
|
||||
LimboCache.getInstance().getLimboPlayer(playerNameLowerCase).setMessageTaskId(
|
||||
scheduler.runTaskAsynchronously(plugin,
|
||||
new MessageTask(plugin, playerNameLowerCase, m.retrieve(MessageKey.REGISTER_MESSAGE), interval)));
|
||||
if (Settings.applyBlindEffect)
|
||||
target.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, Settings.getRegistrationTimeout * 20, 2));
|
||||
if (!Settings.isMovementAllowed && Settings.isRemoveSpeedEnabled) {
|
||||
target.setWalkSpeed(0.0f);
|
||||
target.setFlySpeed(0.0f);
|
||||
new MessageTask(plugin, playerNameLowerCase, commandService.retrieveMessage(MessageKey.REGISTER_MESSAGE), interval)));
|
||||
if (Settings.applyBlindEffect) {
|
||||
target.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS,
|
||||
Settings.getRegistrationTimeout * 20, 2));
|
||||
}
|
||||
m.send(target, MessageKey.UNREGISTERED_SUCCESS);
|
||||
|
||||
commandService.send(target, MessageKey.UNREGISTERED_SUCCESS);
|
||||
}
|
||||
|
||||
// Show a status message
|
||||
m.send(sender, MessageKey.UNREGISTERED_SUCCESS);
|
||||
commandService.send(sender, MessageKey.UNREGISTERED_SUCCESS);
|
||||
ConsoleLogger.info(playerName + " unregistered");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -1,43 +1,38 @@
|
||||
package fr.xephi.authme.command.executable.authme;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.command.CommandParts;
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.command.ExecutableCommand;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class VersionCommand extends ExecutableCommand {
|
||||
import java.util.List;
|
||||
|
||||
import static fr.xephi.authme.settings.properties.PluginSettings.HELP_HEADER;
|
||||
|
||||
public class VersionCommand implements ExecutableCommand {
|
||||
|
||||
/**
|
||||
* Execute the command.
|
||||
*
|
||||
* @param sender The command sender.
|
||||
* @param commandReference The command reference.
|
||||
* @param commandArguments The command arguments.
|
||||
*
|
||||
* @return True if the command was executed successfully, false otherwise.
|
||||
*/
|
||||
@Override
|
||||
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
||||
public void executeCommand(CommandSender sender, List<String> arguments, CommandService commandService) {
|
||||
// Show some version info
|
||||
sender.sendMessage(ChatColor.GOLD + "==========[ " + Settings.helpHeader.toUpperCase() + " ABOUT ]==========");
|
||||
sender.sendMessage(ChatColor.GOLD + "Version: " + ChatColor.WHITE + AuthMe.getPluginName() + " v" + AuthMe.getPluginVersion() + ChatColor.GRAY + " (build: " + AuthMe.getPluginBuildNumber() + ")");
|
||||
sender.sendMessage(ChatColor.GOLD + "==========[ " + commandService.getProperty(HELP_HEADER)
|
||||
+ " ABOUT ]==========");
|
||||
sender.sendMessage(ChatColor.GOLD + "Version: " + ChatColor.WHITE + AuthMe.getPluginName()
|
||||
+ " v" + AuthMe.getPluginVersion() + ChatColor.GRAY + " (build: " + AuthMe.getPluginBuildNumber() + ")");
|
||||
sender.sendMessage(ChatColor.GOLD + "Developers:");
|
||||
printDeveloper(sender, "Xephi", "xephi59", "Lead Developer");
|
||||
printDeveloper(sender, "DNx5", "DNx5", "Developer");
|
||||
printDeveloper(sender, "games647", "games647", "Developer");
|
||||
printDeveloper(sender, "Tim Visee", "timvisee", "Developer");
|
||||
printDeveloper(sender, "Sgdc3", "sgdc3", "Project manager, Contributor");
|
||||
sender.sendMessage(ChatColor.GOLD + "Website: " + ChatColor.WHITE + "http://dev.bukkit.org/bukkit-plugins/authme-reloaded/");
|
||||
sender.sendMessage(ChatColor.GOLD + "License: " + ChatColor.WHITE + "GNU GPL v3.0" + ChatColor.GRAY + ChatColor.ITALIC + " (See LICENSE file)");
|
||||
sender.sendMessage(ChatColor.GOLD + "Copyright: " + ChatColor.WHITE + "Copyright (c) Xephi 2015. All rights reserved.");
|
||||
return true;
|
||||
sender.sendMessage(ChatColor.GOLD + "Website: " + ChatColor.WHITE +
|
||||
"http://dev.bukkit.org/bukkit-plugins/authme-reloaded/");
|
||||
sender.sendMessage(ChatColor.GOLD + "License: " + ChatColor.WHITE + "GNU GPL v3.0"
|
||||
+ ChatColor.GRAY + ChatColor.ITALIC + " (See LICENSE file)");
|
||||
sender.sendMessage(ChatColor.GOLD + "Copyright: " + ChatColor.WHITE
|
||||
+ "Copyright (c) Xephi 2015. All rights reserved.");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -48,22 +43,21 @@ public class VersionCommand extends ExecutableCommand {
|
||||
* @param minecraftName The Minecraft username of the developer, if available.
|
||||
* @param function The function of the developer.
|
||||
*/
|
||||
@SuppressWarnings("StringConcatenationInsideStringBufferAppend")
|
||||
private void printDeveloper(CommandSender sender, String name, String minecraftName, String function) {
|
||||
private static void printDeveloper(CommandSender sender, String name, String minecraftName, String function) {
|
||||
// Print the name
|
||||
StringBuilder msg = new StringBuilder();
|
||||
msg.append(" " + ChatColor.WHITE);
|
||||
msg.append(name);
|
||||
msg.append(" ")
|
||||
.append(ChatColor.WHITE)
|
||||
.append(name);
|
||||
|
||||
// Append the Minecraft name, if available
|
||||
if (minecraftName.length() != 0)
|
||||
msg.append(ChatColor.GRAY + " // " + ChatColor.WHITE + minecraftName);
|
||||
msg.append(ChatColor.GRAY + "" + ChatColor.ITALIC + " (" + function + ")");
|
||||
// Append the Minecraft name
|
||||
msg.append(ChatColor.GRAY).append(" // ").append(ChatColor.WHITE).append(minecraftName);
|
||||
msg.append(ChatColor.GRAY).append(ChatColor.ITALIC).append(" (").append(function).append(")");
|
||||
|
||||
// Show the online status
|
||||
if (minecraftName.length() != 0)
|
||||
if (isPlayerOnline(minecraftName))
|
||||
msg.append(ChatColor.GREEN + "" + ChatColor.ITALIC + " (In-Game)");
|
||||
if (isPlayerOnline(minecraftName)) {
|
||||
msg.append(ChatColor.GREEN).append(ChatColor.ITALIC).append(" (In-Game)");
|
||||
}
|
||||
|
||||
// Print the message
|
||||
sender.sendMessage(msg.toString());
|
||||
@ -76,7 +70,7 @@ public class VersionCommand extends ExecutableCommand {
|
||||
*
|
||||
* @return True if the player is online, false otherwise.
|
||||
*/
|
||||
private boolean isPlayerOnline(String minecraftName) {
|
||||
private static boolean isPlayerOnline(String minecraftName) {
|
||||
// Note ljacqu 20151121: Generally you should use Utils#getOnlinePlayers to retrieve the list of online players.
|
||||
// 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()) {
|
||||
|
@ -2,74 +2,56 @@ package fr.xephi.authme.command.executable.captcha;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.cache.auth.PlayerCache;
|
||||
import fr.xephi.authme.command.CommandParts;
|
||||
import fr.xephi.authme.command.ExecutableCommand;
|
||||
import fr.xephi.authme.security.RandomString;
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.command.PlayerCommand;
|
||||
import fr.xephi.authme.output.MessageKey;
|
||||
import fr.xephi.authme.output.Messages;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.security.RandomString;
|
||||
import fr.xephi.authme.settings.properties.SecuritySettings;
|
||||
import fr.xephi.authme.util.Wrapper;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class CaptchaCommand extends ExecutableCommand {
|
||||
import java.util.List;
|
||||
|
||||
public class CaptchaCommand extends PlayerCommand {
|
||||
|
||||
@Override
|
||||
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
||||
// Make sure the current command executor is a player
|
||||
if (!(sender instanceof Player)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Get the player instance and name
|
||||
final Player player = (Player) sender;
|
||||
public void runCommand(Player player, List<String> arguments, CommandService commandService) {
|
||||
final String playerNameLowerCase = player.getName().toLowerCase();
|
||||
|
||||
// Get the parameter values
|
||||
String captcha = commandArguments.get(0);
|
||||
|
||||
// AuthMe plugin instance
|
||||
final Wrapper wrapper = Wrapper.getInstance();
|
||||
final String captcha = arguments.get(0);
|
||||
Wrapper wrapper = Wrapper.getInstance();
|
||||
final AuthMe plugin = wrapper.getAuthMe();
|
||||
|
||||
// Messages instance
|
||||
final Messages m = wrapper.getMessages();
|
||||
PlayerCache playerCache = wrapper.getPlayerCache();
|
||||
|
||||
// Command logic
|
||||
if (PlayerCache.getInstance().isAuthenticated(playerNameLowerCase)) {
|
||||
m.send(player, MessageKey.ALREADY_LOGGED_IN_ERROR);
|
||||
return true;
|
||||
if (playerCache.isAuthenticated(playerNameLowerCase)) {
|
||||
commandService.send(player, MessageKey.ALREADY_LOGGED_IN_ERROR);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Settings.useCaptcha) {
|
||||
m.send(player, MessageKey.USAGE_LOGIN);
|
||||
return true;
|
||||
if (!commandService.getProperty(SecuritySettings.USE_CAPTCHA)) {
|
||||
commandService.send(player, MessageKey.USAGE_LOGIN);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (!plugin.cap.containsKey(playerNameLowerCase)) {
|
||||
m.send(player, MessageKey.USAGE_LOGIN);
|
||||
return true;
|
||||
commandService.send(player, MessageKey.USAGE_LOGIN);
|
||||
return;
|
||||
}
|
||||
|
||||
if (Settings.useCaptcha && !captcha.equals(plugin.cap.get(playerNameLowerCase))) {
|
||||
if (!captcha.equals(plugin.cap.get(playerNameLowerCase))) {
|
||||
plugin.cap.remove(playerNameLowerCase);
|
||||
String randStr = new RandomString(Settings.captchaLength).nextString();
|
||||
int captchaLength = commandService.getProperty(SecuritySettings.CAPTCHA_LENGTH);
|
||||
String randStr = RandomString.generate(captchaLength);
|
||||
plugin.cap.put(playerNameLowerCase, randStr);
|
||||
for (String s : m.retrieve(MessageKey.CAPTCHA_WRONG_ERROR)) {
|
||||
player.sendMessage(s.replace("THE_CAPTCHA", plugin.cap.get(playerNameLowerCase)));
|
||||
}
|
||||
return true;
|
||||
commandService.send(player, MessageKey.CAPTCHA_WRONG_ERROR, plugin.cap.get(playerNameLowerCase));
|
||||
return;
|
||||
}
|
||||
|
||||
plugin.captcha.remove(playerNameLowerCase);
|
||||
plugin.cap.remove(playerNameLowerCase);
|
||||
|
||||
// Show a status message
|
||||
m.send(player, MessageKey.CAPTCHA_SUCCESS);
|
||||
m.send(player, MessageKey.LOGIN_MESSAGE);
|
||||
return true;
|
||||
commandService.send(player, MessageKey.CAPTCHA_SUCCESS);
|
||||
commandService.send(player, MessageKey.LOGIN_MESSAGE);
|
||||
}
|
||||
}
|
||||
|
@ -2,72 +2,57 @@ package fr.xephi.authme.command.executable.changepassword;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.cache.auth.PlayerCache;
|
||||
import fr.xephi.authme.command.CommandParts;
|
||||
import fr.xephi.authme.command.ExecutableCommand;
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.command.PlayerCommand;
|
||||
import fr.xephi.authme.output.MessageKey;
|
||||
import fr.xephi.authme.output.Messages;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
||||
import fr.xephi.authme.settings.properties.SecuritySettings;
|
||||
import fr.xephi.authme.task.ChangePasswordTask;
|
||||
import fr.xephi.authme.util.Wrapper;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The command for a player to change his password with.
|
||||
*/
|
||||
public class ChangePasswordCommand extends ExecutableCommand {
|
||||
public class ChangePasswordCommand extends PlayerCommand {
|
||||
|
||||
@Override
|
||||
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
||||
// Make sure the current command executor is a player
|
||||
if (!(sender instanceof Player)) {
|
||||
return true;
|
||||
}
|
||||
public void runCommand(Player player, List<String> arguments, CommandService commandService) {
|
||||
String oldPassword = arguments.get(0);
|
||||
String newPassword = arguments.get(1);
|
||||
|
||||
final Wrapper wrapper = Wrapper.getInstance();
|
||||
final Messages m = wrapper.getMessages();
|
||||
|
||||
// Get the passwords
|
||||
String oldPassword = commandArguments.get(0);
|
||||
String newPassword = commandArguments.get(1);
|
||||
|
||||
// Get the player instance and make sure he's authenticated
|
||||
Player player = (Player) sender;
|
||||
String name = player.getName().toLowerCase();
|
||||
Wrapper wrapper = Wrapper.getInstance();
|
||||
final PlayerCache playerCache = wrapper.getPlayerCache();
|
||||
if (!playerCache.isAuthenticated(name)) {
|
||||
m.send(player, MessageKey.NOT_LOGGED_IN);
|
||||
return true;
|
||||
commandService.send(player, MessageKey.NOT_LOGGED_IN);
|
||||
return;
|
||||
}
|
||||
|
||||
// Make sure the password is allowed
|
||||
String playerPassLowerCase = newPassword.toLowerCase();
|
||||
if (playerPassLowerCase.contains("delete") || playerPassLowerCase.contains("where")
|
||||
|| playerPassLowerCase.contains("insert") || playerPassLowerCase.contains("modify")
|
||||
|| playerPassLowerCase.contains("from") || playerPassLowerCase.contains("select")
|
||||
|| playerPassLowerCase.contains(";") || playerPassLowerCase.contains("null")
|
||||
|| !playerPassLowerCase.matches(Settings.getPassRegex)) {
|
||||
m.send(player, MessageKey.PASSWORD_MATCH_ERROR);
|
||||
return true;
|
||||
if (!playerPassLowerCase.matches(commandService.getProperty(RestrictionSettings.ALLOWED_PASSWORD_REGEX))) {
|
||||
commandService.send(player, MessageKey.PASSWORD_MATCH_ERROR);
|
||||
return;
|
||||
}
|
||||
if (playerPassLowerCase.equalsIgnoreCase(name)) {
|
||||
m.send(player, MessageKey.PASSWORD_IS_USERNAME_ERROR);
|
||||
return true;
|
||||
commandService.send(player, MessageKey.PASSWORD_IS_USERNAME_ERROR);
|
||||
return;
|
||||
}
|
||||
if (playerPassLowerCase.length() < Settings.getPasswordMinLen
|
||||
|| playerPassLowerCase.length() > Settings.passwordMaxLength) {
|
||||
m.send(player, MessageKey.INVALID_PASSWORD_LENGTH);
|
||||
return true;
|
||||
if (playerPassLowerCase.length() < commandService.getProperty(SecuritySettings.MIN_PASSWORD_LENGTH)
|
||||
|| playerPassLowerCase.length() > commandService.getProperty(SecuritySettings.MAX_PASSWORD_LENGTH)) {
|
||||
commandService.send(player, MessageKey.INVALID_PASSWORD_LENGTH);
|
||||
return;
|
||||
}
|
||||
if (!Settings.unsafePasswords.isEmpty() && Settings.unsafePasswords.contains(playerPassLowerCase)) {
|
||||
m.send(player, MessageKey.PASSWORD_UNSAFE_ERROR);
|
||||
return true;
|
||||
if (commandService.getProperty(SecuritySettings.UNSAFE_PASSWORDS).contains(playerPassLowerCase)) {
|
||||
commandService.send(player, MessageKey.PASSWORD_UNSAFE_ERROR);
|
||||
return;
|
||||
}
|
||||
|
||||
// Set the password
|
||||
final AuthMe plugin = wrapper.getAuthMe();
|
||||
wrapper.getScheduler().runTaskAsynchronously(plugin,
|
||||
new ChangePasswordTask(plugin, player, oldPassword, newPassword));
|
||||
return true;
|
||||
AuthMe plugin = AuthMe.getInstance();
|
||||
// TODO ljacqu 20160117: Call async task via Management
|
||||
commandService.runTaskAsynchronously(new ChangePasswordTask(plugin, player, oldPassword, newPassword));
|
||||
}
|
||||
}
|
||||
|
@ -1,129 +0,0 @@
|
||||
package fr.xephi.authme.command.executable.converter;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.command.CommandParts;
|
||||
import fr.xephi.authme.command.ExecutableCommand;
|
||||
import fr.xephi.authme.converter.*;
|
||||
import fr.xephi.authme.output.MessageKey;
|
||||
import fr.xephi.authme.output.Messages;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class ConverterCommand extends ExecutableCommand {
|
||||
|
||||
/**
|
||||
* Execute the command.
|
||||
*
|
||||
* @param sender The command sender.
|
||||
* @param commandReference The command reference.
|
||||
* @param commandArguments The command arguments.
|
||||
*
|
||||
* @return True if the command was executed successfully, false otherwise.
|
||||
*/
|
||||
@Override
|
||||
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
||||
// AuthMe plugin instance
|
||||
final AuthMe plugin = AuthMe.getInstance();
|
||||
|
||||
// Messages instance
|
||||
final Messages m = plugin.getMessages();
|
||||
|
||||
// Get the conversion job
|
||||
String job = commandArguments.get(0);
|
||||
|
||||
// Determine the job type
|
||||
ConvertType jobType = ConvertType.fromName(job);
|
||||
if (jobType == null) {
|
||||
m.send(sender, MessageKey.ERROR);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Get the proper converter instance
|
||||
Converter converter = null;
|
||||
switch (jobType) {
|
||||
case ftsql:
|
||||
converter = new FlatToSql();
|
||||
break;
|
||||
case ftsqlite:
|
||||
converter = new FlatToSqlite(sender);
|
||||
break;
|
||||
case xauth:
|
||||
converter = new xAuthConverter(plugin, sender);
|
||||
break;
|
||||
case crazylogin:
|
||||
converter = new CrazyLoginConverter(plugin, sender);
|
||||
break;
|
||||
case rakamak:
|
||||
converter = new RakamakConverter(plugin, sender);
|
||||
break;
|
||||
case royalauth:
|
||||
converter = new RoyalAuthConverter(plugin);
|
||||
break;
|
||||
case vauth:
|
||||
converter = new vAuthConverter(plugin, sender);
|
||||
break;
|
||||
case sqltoflat:
|
||||
converter = new SqlToFlat(plugin, sender);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
// Run the convert job
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, converter);
|
||||
|
||||
// Show a status message
|
||||
sender.sendMessage("[AuthMe] Successfully converted from " + jobType.getName());
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public enum ConvertType {
|
||||
ftsql("flattosql"),
|
||||
ftsqlite("flattosqlite"),
|
||||
xauth("xauth"),
|
||||
crazylogin("crazylogin"),
|
||||
rakamak("rakamak"),
|
||||
royalauth("royalauth"),
|
||||
vauth("vauth"),
|
||||
sqltoflat("sqltoflat");
|
||||
|
||||
final String name;
|
||||
|
||||
/**
|
||||
* Constructor for ConvertType.
|
||||
*
|
||||
* @param name String
|
||||
*/
|
||||
ConvertType(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method fromName.
|
||||
*
|
||||
* @param name String
|
||||
*
|
||||
* @return ConvertType
|
||||
*/
|
||||
public static ConvertType fromName(String name) {
|
||||
for (ConvertType type : ConvertType.values()) {
|
||||
if (type.getName().equalsIgnoreCase(name))
|
||||
return type;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method getName.
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
String getName() {
|
||||
return this.name;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,31 +1,26 @@
|
||||
package fr.xephi.authme.command.executable.email;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.command.CommandParts;
|
||||
import fr.xephi.authme.command.ExecutableCommand;
|
||||
import fr.xephi.authme.util.Wrapper;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.command.PlayerCommand;
|
||||
import fr.xephi.authme.output.MessageKey;
|
||||
import fr.xephi.authme.util.Utils;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class AddEmailCommand extends ExecutableCommand {
|
||||
import java.util.List;
|
||||
|
||||
public class AddEmailCommand extends PlayerCommand {
|
||||
|
||||
@Override
|
||||
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
||||
// Make sure the current command executor is a player
|
||||
if (!(sender instanceof Player)) {
|
||||
return true;
|
||||
public void runCommand(Player player, List<String> arguments, CommandService commandService) {
|
||||
String email = arguments.get(0);
|
||||
String emailConfirmation = arguments.get(1);
|
||||
|
||||
if (!Utils.isEmailCorrect(email, commandService.getSettings())) {
|
||||
commandService.send(player, MessageKey.INVALID_EMAIL);
|
||||
} else if (email.equals(emailConfirmation)) {
|
||||
commandService.getManagement().performAddEmail(player, email);
|
||||
} else {
|
||||
commandService.send(player, MessageKey.CONFIRM_EMAIL_MESSAGE);
|
||||
}
|
||||
|
||||
// Get the parameter values
|
||||
String playerMail = commandArguments.get(0);
|
||||
String playerMailVerify = commandArguments.get(1);
|
||||
|
||||
// Get the player and perform email addition
|
||||
final AuthMe plugin = Wrapper.getInstance().getAuthMe();
|
||||
final Player player = (Player) sender;
|
||||
plugin.getManagement().performAddEmail(player, playerMail, playerMailVerify);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -1,31 +1,21 @@
|
||||
package fr.xephi.authme.command.executable.email;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.command.CommandParts;
|
||||
import fr.xephi.authme.command.ExecutableCommand;
|
||||
import fr.xephi.authme.util.Wrapper;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.command.PlayerCommand;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Change email command.
|
||||
*/
|
||||
public class ChangeEmailCommand extends ExecutableCommand {
|
||||
public class ChangeEmailCommand extends PlayerCommand {
|
||||
|
||||
@Override
|
||||
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
||||
// Make sure the current command executor is a player
|
||||
if (!(sender instanceof Player)) {
|
||||
return true;
|
||||
}
|
||||
public void runCommand(Player player, List<String> arguments, CommandService commandService) {
|
||||
String playerMailOld = arguments.get(0);
|
||||
String playerMailNew = arguments.get(1);
|
||||
|
||||
// Get the parameter values
|
||||
String playerMailOld = commandArguments.get(0);
|
||||
String playerMailNew = commandArguments.get(1);
|
||||
|
||||
// Get the player instance and execute action
|
||||
final AuthMe plugin = Wrapper.getInstance().getAuthMe();
|
||||
final Player player = (Player) sender;
|
||||
plugin.getManagement().performChangeEmail(player, playerMailOld, playerMailNew);
|
||||
return true;
|
||||
commandService.getManagement().performChangeEmail(player, playerMailOld, playerMailNew);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,22 @@
|
||||
package fr.xephi.authme.command.executable.email;
|
||||
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.command.ExecutableCommand;
|
||||
import fr.xephi.authme.command.FoundCommandResult;
|
||||
import fr.xephi.authme.command.help.HelpProvider;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Base command for /email, showing information about the child commands.
|
||||
*/
|
||||
public class EmailBaseCommand implements ExecutableCommand {
|
||||
|
||||
@Override
|
||||
public void executeCommand(CommandSender sender, List<String> arguments, CommandService commandService) {
|
||||
FoundCommandResult result = commandService.mapPartsToCommand(sender, Collections.singletonList("email"));
|
||||
commandService.outputHelp(sender, result, HelpProvider.SHOW_CHILDREN);
|
||||
}
|
||||
}
|
@ -1,89 +1,68 @@
|
||||
package fr.xephi.authme.command.executable.email;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||
import fr.xephi.authme.cache.auth.PlayerCache;
|
||||
import fr.xephi.authme.command.CommandParts;
|
||||
import fr.xephi.authme.command.ExecutableCommand;
|
||||
import fr.xephi.authme.security.PasswordSecurity;
|
||||
import fr.xephi.authme.security.RandomString;
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.command.PlayerCommand;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
import fr.xephi.authme.output.MessageKey;
|
||||
import fr.xephi.authme.output.Messages;
|
||||
import fr.xephi.authme.security.RandomString;
|
||||
import fr.xephi.authme.security.crypts.HashedPassword;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.util.Wrapper;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import fr.xephi.authme.util.StringUtils;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class RecoverEmailCommand extends ExecutableCommand {
|
||||
public class RecoverEmailCommand extends PlayerCommand {
|
||||
|
||||
@Override
|
||||
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
||||
// Make sure the current command executor is a player
|
||||
if (!(sender instanceof Player)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Get the parameter values
|
||||
String playerMail = commandArguments.get(0);
|
||||
|
||||
// Get the player instance and name
|
||||
final Player player = (Player) sender;
|
||||
public void runCommand(Player player, List<String> arguments, CommandService commandService) {
|
||||
String playerMail = arguments.get(0);
|
||||
final String playerName = player.getName();
|
||||
|
||||
// Command logic
|
||||
final Wrapper wrapper = Wrapper.getInstance();
|
||||
final AuthMe plugin = wrapper.getAuthMe();
|
||||
final Messages m = wrapper.getMessages();
|
||||
final AuthMe plugin = AuthMe.getInstance();
|
||||
|
||||
if (plugin.mail == null) {
|
||||
m.send(player, MessageKey.ERROR);
|
||||
return true;
|
||||
commandService.send(player, MessageKey.ERROR);
|
||||
return;
|
||||
}
|
||||
if (plugin.database.isAuthAvailable(playerName)) {
|
||||
DataSource dataSource = commandService.getDataSource();
|
||||
if (dataSource.isAuthAvailable(playerName)) {
|
||||
if (PlayerCache.getInstance().isAuthenticated(playerName)) {
|
||||
m.send(player, MessageKey.ALREADY_LOGGED_IN_ERROR);
|
||||
return true;
|
||||
commandService.send(player, MessageKey.ALREADY_LOGGED_IN_ERROR);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
RandomString rand = new RandomString(Settings.getRecoveryPassLength);
|
||||
String thePass = rand.nextString();
|
||||
String hashNew = PasswordSecurity.getHash(Settings.getPasswordHash, thePass, playerName);
|
||||
PlayerAuth auth;
|
||||
if (PlayerCache.getInstance().isAuthenticated(playerName)) {
|
||||
auth = PlayerCache.getInstance().getAuth(playerName);
|
||||
} else if (plugin.database.isAuthAvailable(playerName)) {
|
||||
auth = plugin.database.getAuth(playerName);
|
||||
} else {
|
||||
m.send(player, MessageKey.UNKNOWN_USER);
|
||||
return true;
|
||||
}
|
||||
if (Settings.getmailAccount.equals("") || Settings.getmailAccount.isEmpty()) {
|
||||
m.send(player, MessageKey.ERROR);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!playerMail.equalsIgnoreCase(auth.getEmail()) || playerMail.equalsIgnoreCase("your@email.com") || auth.getEmail().equalsIgnoreCase("your@email.com")) {
|
||||
m.send(player, MessageKey.INVALID_EMAIL);
|
||||
return true;
|
||||
}
|
||||
auth.setHash(hashNew);
|
||||
plugin.database.updatePassword(auth);
|
||||
plugin.mail.main(auth, thePass);
|
||||
m.send(player, MessageKey.RECOVERY_EMAIL_SENT_MESSAGE);
|
||||
} catch (NoSuchAlgorithmException | NoClassDefFoundError ex) {
|
||||
ex.printStackTrace();
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
m.send(sender, MessageKey.ERROR);
|
||||
String thePass = RandomString.generate(Settings.getRecoveryPassLength);
|
||||
HashedPassword hashNew = commandService.getPasswordSecurity().computeHash(thePass, playerName);
|
||||
PlayerAuth auth;
|
||||
if (PlayerCache.getInstance().isAuthenticated(playerName)) {
|
||||
auth = PlayerCache.getInstance().getAuth(playerName);
|
||||
} else if (dataSource.isAuthAvailable(playerName)) {
|
||||
auth = dataSource.getAuth(playerName);
|
||||
} else {
|
||||
commandService.send(player, MessageKey.UNKNOWN_USER);
|
||||
return;
|
||||
}
|
||||
if (StringUtils.isEmpty(Settings.getmailAccount)) {
|
||||
commandService.send(player, MessageKey.ERROR);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!playerMail.equalsIgnoreCase(auth.getEmail()) || playerMail.equalsIgnoreCase("your@email.com")
|
||||
|| auth.getEmail().equalsIgnoreCase("your@email.com")) {
|
||||
commandService.send(player, MessageKey.INVALID_EMAIL);
|
||||
return;
|
||||
}
|
||||
auth.setPassword(hashNew);
|
||||
dataSource.updatePassword(auth);
|
||||
plugin.mail.main(auth, thePass);
|
||||
commandService.send(player, MessageKey.RECOVERY_EMAIL_SENT_MESSAGE);
|
||||
} else {
|
||||
m.send(player, MessageKey.REGISTER_EMAIL_MESSAGE);
|
||||
commandService.send(player, MessageKey.REGISTER_EMAIL_MESSAGE);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -1,30 +1,19 @@
|
||||
package fr.xephi.authme.command.executable.login;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.command.CommandParts;
|
||||
import fr.xephi.authme.command.ExecutableCommand;
|
||||
import fr.xephi.authme.util.Wrapper;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.command.PlayerCommand;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Login command.
|
||||
*/
|
||||
public class LoginCommand extends ExecutableCommand {
|
||||
public class LoginCommand extends PlayerCommand {
|
||||
|
||||
@Override
|
||||
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
||||
// Make sure the current command executor is a player
|
||||
if (!(sender instanceof Player)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Get the necessary objects
|
||||
final AuthMe plugin = Wrapper.getInstance().getAuthMe();
|
||||
final Player player = (Player) sender;
|
||||
final String password = commandArguments.get(0);
|
||||
|
||||
// Log the player in
|
||||
plugin.getManagement().performLogin(player, password, false);
|
||||
return true;
|
||||
public void runCommand(Player player, List<String> arguments, CommandService commandService) {
|
||||
final String password = arguments.get(0);
|
||||
commandService.getManagement().performLogin(player, password, false);
|
||||
}
|
||||
}
|
||||
|
@ -1,29 +1,18 @@
|
||||
package fr.xephi.authme.command.executable.logout;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.command.CommandParts;
|
||||
import fr.xephi.authme.command.ExecutableCommand;
|
||||
import fr.xephi.authme.util.Wrapper;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.command.PlayerCommand;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Logout command.
|
||||
*/
|
||||
public class LogoutCommand extends ExecutableCommand {
|
||||
public class LogoutCommand extends PlayerCommand {
|
||||
|
||||
@Override
|
||||
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
||||
// Make sure the current command executor is a player
|
||||
if (!(sender instanceof Player)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Get the player instance
|
||||
final AuthMe plugin = Wrapper.getInstance().getAuthMe();
|
||||
final Player player = (Player) sender;
|
||||
|
||||
// Logout the player
|
||||
plugin.getManagement().performLogout(player);
|
||||
return true;
|
||||
public void runCommand(Player player, List<String> arguments, CommandService commandService) {
|
||||
commandService.getManagement().performLogout(player);
|
||||
}
|
||||
}
|
||||
|
@ -1,65 +1,61 @@
|
||||
package fr.xephi.authme.command.executable.register;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.command.CommandParts;
|
||||
import fr.xephi.authme.command.ExecutableCommand;
|
||||
import fr.xephi.authme.process.Management;
|
||||
import fr.xephi.authme.security.RandomString;
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.command.PlayerCommand;
|
||||
import fr.xephi.authme.output.MessageKey;
|
||||
import fr.xephi.authme.output.Messages;
|
||||
import fr.xephi.authme.process.Management;
|
||||
import fr.xephi.authme.security.HashAlgorithm;
|
||||
import fr.xephi.authme.security.RandomString;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.util.Wrapper;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import fr.xephi.authme.util.Utils;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class RegisterCommand extends ExecutableCommand {
|
||||
import java.util.List;
|
||||
|
||||
public class RegisterCommand extends PlayerCommand {
|
||||
|
||||
@Override
|
||||
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
||||
|
||||
// Make sure the sender is a player
|
||||
if (!(sender instanceof Player)) {
|
||||
sender.sendMessage("Player Only! Use 'authme register <playername> <password>' instead");
|
||||
return true;
|
||||
public void runCommand(Player player, List<String> arguments, CommandService commandService) {
|
||||
if (Settings.getPasswordHash == HashAlgorithm.TWO_FACTOR) {
|
||||
//for two factor auth we don't need to check the usage
|
||||
commandService.getManagement().performRegister(player, "", "");
|
||||
return;
|
||||
}
|
||||
|
||||
final Wrapper wrapper = Wrapper.getInstance();
|
||||
final AuthMe plugin = wrapper.getAuthMe();
|
||||
final Messages m = wrapper.getMessages();
|
||||
|
||||
// Make sure the command arguments are valid
|
||||
final Player player = (Player) sender;
|
||||
if (commandArguments.getCount() == 0 || (Settings.getEnablePasswordVerifier && commandArguments.getCount() < 2)) {
|
||||
m.send(player, MessageKey.USAGE_REGISTER);
|
||||
return true;
|
||||
if (arguments.isEmpty() || Settings.enablePasswordConfirmation && arguments.size() < 2) {
|
||||
commandService.send(player, MessageKey.USAGE_REGISTER);
|
||||
return;
|
||||
}
|
||||
|
||||
final Management management = plugin.getManagement();
|
||||
final Management management = commandService.getManagement();
|
||||
if (Settings.emailRegistration && !Settings.getmailAccount.isEmpty()) {
|
||||
if (Settings.doubleEmailCheck) {
|
||||
if (commandArguments.getCount() < 2 || !commandArguments.get(0).equals(commandArguments.get(1))) {
|
||||
m.send(player, MessageKey.USAGE_REGISTER);
|
||||
return true;
|
||||
}
|
||||
if (Settings.doubleEmailCheck && arguments.size() < 2 || !arguments.get(0).equals(arguments.get(1))) {
|
||||
commandService.send(player, MessageKey.USAGE_REGISTER);
|
||||
return;
|
||||
}
|
||||
final String email = commandArguments.get(0);
|
||||
if (!Settings.isEmailCorrect(email)) {
|
||||
m.send(player, MessageKey.INVALID_EMAIL);
|
||||
return true;
|
||||
|
||||
final String email = arguments.get(0);
|
||||
if (!Utils.isEmailCorrect(email, commandService.getSettings())) {
|
||||
commandService.send(player, MessageKey.INVALID_EMAIL);
|
||||
return;
|
||||
}
|
||||
final String thePass = new RandomString(Settings.getRecoveryPassLength).nextString();
|
||||
|
||||
final String thePass = RandomString.generate(Settings.getRecoveryPassLength);
|
||||
management.performRegister(player, thePass, email);
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
if (commandArguments.getCount() > 1 && Settings.getEnablePasswordVerifier) {
|
||||
if (!commandArguments.get(0).equals(commandArguments.get(1))) {
|
||||
m.send(player, MessageKey.PASSWORD_MATCH_ERROR);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (arguments.size() > 1 && Settings.enablePasswordConfirmation && !arguments.get(0).equals(arguments.get(1))) {
|
||||
commandService.send(player, MessageKey.PASSWORD_MATCH_ERROR);
|
||||
return;
|
||||
}
|
||||
management.performRegister(player, commandArguments.get(0), "");
|
||||
return true;
|
||||
|
||||
management.performRegister(player, arguments.get(0), "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAlternativeCommand() {
|
||||
return "/authme register <playername> <password>";
|
||||
}
|
||||
}
|
||||
|
@ -1,55 +1,27 @@
|
||||
package fr.xephi.authme.command.executable.unregister;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.cache.auth.PlayerCache;
|
||||
import fr.xephi.authme.command.CommandParts;
|
||||
import fr.xephi.authme.command.ExecutableCommand;
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.command.PlayerCommand;
|
||||
import fr.xephi.authme.output.MessageKey;
|
||||
import fr.xephi.authme.output.Messages;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class UnregisterCommand extends ExecutableCommand {
|
||||
import java.util.List;
|
||||
|
||||
public class UnregisterCommand extends PlayerCommand {
|
||||
|
||||
/**
|
||||
* Execute the command.
|
||||
*
|
||||
* @param sender The command sender.
|
||||
* @param commandReference The command reference.
|
||||
* @param commandArguments The command arguments.
|
||||
*
|
||||
* @return True if the command was executed successfully, false otherwise.
|
||||
*/
|
||||
@Override
|
||||
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
||||
// AuthMe plugin instance
|
||||
final AuthMe plugin = AuthMe.getInstance();
|
||||
|
||||
// Messages instance
|
||||
final Messages m = plugin.getMessages();
|
||||
|
||||
// Make sure the current command executor is a player
|
||||
if (!(sender instanceof Player)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Get the password
|
||||
String playerPass = commandArguments.get(0);
|
||||
|
||||
// Get the player instance and name
|
||||
final Player player = (Player) sender;
|
||||
public void runCommand(Player player, List<String> arguments, CommandService commandService) {
|
||||
String playerPass = arguments.get(0);
|
||||
final String playerNameLowerCase = player.getName().toLowerCase();
|
||||
|
||||
// Make sure the player is authenticated
|
||||
if (!PlayerCache.getInstance().isAuthenticated(playerNameLowerCase)) {
|
||||
m.send(player, MessageKey.NOT_LOGGED_IN);
|
||||
return true;
|
||||
commandService.send(player, MessageKey.NOT_LOGGED_IN);
|
||||
return;
|
||||
}
|
||||
|
||||
// Unregister the player
|
||||
plugin.getManagement().performUnregister(player, playerPass, false);
|
||||
return true;
|
||||
commandService.getManagement().performUnregister(player, playerPass, false);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,36 @@
|
||||
package fr.xephi.authme.command.help;
|
||||
|
||||
import fr.xephi.authme.command.CommandArgumentDescription;
|
||||
import fr.xephi.authme.command.CommandDescription;
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Helper class for displaying the syntax of a command properly to a user.
|
||||
*/
|
||||
class CommandSyntaxHelper {
|
||||
|
||||
private CommandSyntaxHelper() {
|
||||
}
|
||||
|
||||
public static String getSyntax(CommandDescription command, List<String> correctLabels) {
|
||||
String commandSyntax = ChatColor.WHITE + "/" + correctLabels.get(0) + ChatColor.YELLOW;
|
||||
for (int i = 1; i < correctLabels.size(); ++i) {
|
||||
commandSyntax += " " + correctLabels.get(i);
|
||||
}
|
||||
for (CommandArgumentDescription argument : command.getArguments()) {
|
||||
commandSyntax += " " + formatArgument(argument);
|
||||
}
|
||||
return commandSyntax;
|
||||
}
|
||||
|
||||
/** Format a command argument with the proper type of brackets. */
|
||||
private static String formatArgument(CommandArgumentDescription argument) {
|
||||
if (argument.isOptional()) {
|
||||
return "[" + argument.getName() + "]";
|
||||
}
|
||||
return "<" + argument.getName() + ">";
|
||||
}
|
||||
|
||||
}
|
@ -1,194 +0,0 @@
|
||||
package fr.xephi.authme.command.help;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.command.CommandArgumentDescription;
|
||||
import fr.xephi.authme.command.CommandDescription;
|
||||
import fr.xephi.authme.command.CommandParts;
|
||||
import fr.xephi.authme.command.CommandPermissions;
|
||||
import fr.xephi.authme.permission.PermissionNode;
|
||||
import fr.xephi.authme.util.CollectionUtils;
|
||||
import fr.xephi.authme.util.StringUtils;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class HelpPrinter {
|
||||
|
||||
/**
|
||||
* Print the command help information.
|
||||
*
|
||||
* @param sender The command sender to print the help to.
|
||||
* @param command The command to print.
|
||||
* @param commandReference The command reference used.
|
||||
*/
|
||||
public static void printCommand(CommandSender sender, CommandDescription command, CommandParts commandReference) {
|
||||
// Print the proper command syntax
|
||||
sender.sendMessage(ChatColor.GOLD + "Command: " + HelpSyntaxHelper.getCommandSyntax(command, commandReference, null, true));
|
||||
}
|
||||
|
||||
/**
|
||||
* Print the command help description information. This will print both the short, as the detailed description if available.
|
||||
*
|
||||
* @param sender The command sender to print the help to.
|
||||
* @param command The command to print the description help for.
|
||||
*/
|
||||
public static void printCommandDescription(CommandSender sender, CommandDescription command) {
|
||||
sender.sendMessage(ChatColor.GOLD + "Short Description: " + ChatColor.WHITE + command.getDescription());
|
||||
|
||||
// Print the detailed description, if available
|
||||
if (!StringUtils.isEmpty(command.getDetailedDescription())) {
|
||||
sender.sendMessage(ChatColor.GOLD + "Detailed Description:");
|
||||
sender.sendMessage(ChatColor.WHITE + " " + command.getDetailedDescription());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Print the command help arguments information if available.
|
||||
*
|
||||
* @param sender The command sender to print the help to.
|
||||
* @param command The command to print the argument help for.
|
||||
*/
|
||||
@SuppressWarnings("StringConcatenationInsideStringBufferAppend")
|
||||
public static void printArguments(CommandSender sender, CommandDescription command) {
|
||||
// Make sure there are any commands to print
|
||||
if (!command.hasArguments())
|
||||
return;
|
||||
|
||||
// Print the header
|
||||
sender.sendMessage(ChatColor.GOLD + "Arguments:");
|
||||
|
||||
// Print each argument
|
||||
for (CommandArgumentDescription arg : command.getArguments()) {
|
||||
// Create a string builder to build the syntax in
|
||||
StringBuilder argString = new StringBuilder();
|
||||
argString.append(" " + ChatColor.YELLOW + ChatColor.ITALIC + arg.getLabel() + " : " + ChatColor.WHITE + arg.getDescription());
|
||||
|
||||
// Suffix a note if the command is optional
|
||||
if (arg.isOptional())
|
||||
argString.append(ChatColor.GRAY + "" + ChatColor.ITALIC + " (Optional)");
|
||||
|
||||
// Print the syntax
|
||||
sender.sendMessage(argString.toString());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Print the command help permissions information if available.
|
||||
*
|
||||
* @param sender The command sender to print the help to.
|
||||
* @param command The command to print the permissions help for.
|
||||
*/
|
||||
public static void printPermissions(CommandSender sender, CommandDescription command) {
|
||||
// Get the permissions and make sure they aren't missing
|
||||
CommandPermissions permissions = command.getCommandPermissions();
|
||||
if (permissions == null || CollectionUtils.isEmpty(permissions.getPermissionNodes())) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Print the header
|
||||
sender.sendMessage(ChatColor.GOLD + "Permissions:");
|
||||
|
||||
// Print each node
|
||||
for (PermissionNode node : permissions.getPermissionNodes()) {
|
||||
boolean nodePermission = true;
|
||||
if (sender instanceof Player)
|
||||
nodePermission = AuthMe.getInstance().getPermissionsManager().hasPermission((Player) sender, node);
|
||||
final String nodePermsString = ChatColor.GRAY + (nodePermission ? ChatColor.ITALIC + " (Permission!)" : ChatColor.ITALIC + " (No Permission!)");
|
||||
sender.sendMessage(" " + ChatColor.YELLOW + ChatColor.ITALIC + node + nodePermsString);
|
||||
}
|
||||
|
||||
// Print the default permission
|
||||
// TODO ljacqu 20151205: This is duplicating the logic in PermissionsManager#evaluateDefaultPermission
|
||||
// Either use the command manager here, or if that's too heavy, look into moving certain permissions logic
|
||||
// into a Utils class
|
||||
switch (permissions.getDefaultPermission()) {
|
||||
case ALLOWED:
|
||||
sender.sendMessage(ChatColor.GOLD + " Default: " + ChatColor.GRAY + ChatColor.ITALIC + "Permission!");
|
||||
break;
|
||||
|
||||
case OP_ONLY:
|
||||
final String defaultPermsString = ChatColor.GRAY + (sender.isOp() ? ChatColor.ITALIC + " (Permission!)" : ChatColor.ITALIC + " (No Permission!)");
|
||||
sender.sendMessage(ChatColor.GOLD + " Default: " + ChatColor.YELLOW + ChatColor.ITALIC + "OP's Only!" + defaultPermsString);
|
||||
break;
|
||||
|
||||
case NOT_ALLOWED:
|
||||
default:
|
||||
sender.sendMessage(ChatColor.GOLD + " Default: " + ChatColor.GRAY + ChatColor.ITALIC + "No Permission!");
|
||||
break;
|
||||
}
|
||||
|
||||
// Print the permission result
|
||||
if (permissions.hasPermission(sender))
|
||||
sender.sendMessage(ChatColor.GOLD + " Result: " + ChatColor.GREEN + ChatColor.ITALIC + "Permission!");
|
||||
else
|
||||
sender.sendMessage(ChatColor.GOLD + " Result: " + ChatColor.DARK_RED + ChatColor.ITALIC + "No Permission!");
|
||||
}
|
||||
|
||||
/**
|
||||
* Print the command help alternatives information if available.
|
||||
*
|
||||
* @param sender The command sender to print the help to.
|
||||
* @param command The command used.
|
||||
* @param commandReference The original command reference used for this command.
|
||||
*/
|
||||
public static void printAlternatives(CommandSender sender, CommandDescription command, CommandParts commandReference) {
|
||||
// Make sure there are any alternatives
|
||||
if (command.getLabels().size() <= 1)
|
||||
return;
|
||||
|
||||
// Print the header
|
||||
sender.sendMessage(ChatColor.GOLD + "Alternatives:");
|
||||
|
||||
// Get the label used
|
||||
final String usedLabel = commandReference.get(command.getParentCount());
|
||||
|
||||
// Create a list of alternatives
|
||||
List<String> alternatives = new ArrayList<>();
|
||||
for (String entry : command.getLabels()) {
|
||||
// Exclude the proper argument
|
||||
if (entry.equalsIgnoreCase(usedLabel))
|
||||
continue;
|
||||
alternatives.add(entry);
|
||||
}
|
||||
|
||||
// Sort the alternatives
|
||||
Collections.sort(alternatives, new Comparator<String>() {
|
||||
@Override
|
||||
public int compare(String o1, String o2) {
|
||||
return Double.compare(StringUtils.getDifference(usedLabel, o1), StringUtils.getDifference(usedLabel, o2));
|
||||
}
|
||||
});
|
||||
|
||||
// Print each alternative with proper syntax
|
||||
for (String alternative : alternatives)
|
||||
sender.sendMessage(" " + HelpSyntaxHelper.getCommandSyntax(command, commandReference, alternative, true));
|
||||
}
|
||||
|
||||
/**
|
||||
* Print the command help child's information if available.
|
||||
*
|
||||
* @param sender The command sender to print the help to.
|
||||
* @param command The command to print the help for.
|
||||
* @param commandReference The original command reference used for this command.
|
||||
*/
|
||||
public static void printChildren(CommandSender sender, CommandDescription command, CommandParts commandReference) {
|
||||
// Make sure there are child's
|
||||
if (command.getChildren().size() <= 0)
|
||||
return;
|
||||
|
||||
// Print the header
|
||||
sender.sendMessage(ChatColor.GOLD + "Commands:");
|
||||
|
||||
// Loop through each child
|
||||
for (CommandDescription child : command.getChildren())
|
||||
sender.sendMessage(" " + HelpSyntaxHelper.getCommandSyntax(child, commandReference, null, false) + ChatColor.GRAY + ChatColor.ITALIC + " : " + child.getDescription());
|
||||
}
|
||||
}
|
@ -1,12 +1,15 @@
|
||||
package fr.xephi.authme.command.help;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import fr.xephi.authme.command.CommandArgumentDescription;
|
||||
import fr.xephi.authme.command.CommandDescription;
|
||||
import fr.xephi.authme.command.CommandParts;
|
||||
import fr.xephi.authme.command.CommandPermissions;
|
||||
import fr.xephi.authme.command.CommandUtils;
|
||||
import fr.xephi.authme.command.FoundCommandResult;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
|
||||
import fr.xephi.authme.permission.DefaultPermission;
|
||||
import fr.xephi.authme.permission.PermissionNode;
|
||||
import fr.xephi.authme.permission.PermissionsManager;
|
||||
import fr.xephi.authme.util.CollectionUtils;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@ -14,120 +17,183 @@ import org.bukkit.command.CommandSender;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
import static java.util.Collections.singletonList;
|
||||
|
||||
/**
|
||||
* Help syntax generator for AuthMe commands.
|
||||
*/
|
||||
public class HelpProvider {
|
||||
|
||||
/**
|
||||
* Show help for a specific command.
|
||||
*
|
||||
* @param sender The command sender the help needs to be shown to.
|
||||
* @param reference The command reference to the help command.
|
||||
* @param helpQuery The query to show help for.
|
||||
*/
|
||||
public static void showHelp(CommandSender sender, CommandParts reference, CommandParts helpQuery) {
|
||||
showHelp(sender, reference, helpQuery, true, true, true, true, true, true);
|
||||
// --- Bit flags ---
|
||||
/** Set to <i>not</i> show the command. */
|
||||
public static final int HIDE_COMMAND = 0x001;
|
||||
/** Set to show the detailed description of a command. */
|
||||
public static final int SHOW_LONG_DESCRIPTION = 0x002;
|
||||
/** Set to include the arguments the command takes. */
|
||||
public static final int SHOW_ARGUMENTS = 0x004;
|
||||
/** Set to show the permissions required to execute the command. */
|
||||
public static final int SHOW_PERMISSIONS = 0x008;
|
||||
/** Set to show alternative labels for the command. */
|
||||
public static final int SHOW_ALTERNATIVES = 0x010;
|
||||
/** Set to show the child commands of the command. */
|
||||
public static final int SHOW_CHILDREN = 0x020;
|
||||
|
||||
/** Shortcut for setting all options apart from {@link HelpProvider#HIDE_COMMAND}. */
|
||||
public static final int ALL_OPTIONS = ~HIDE_COMMAND;
|
||||
|
||||
private final PermissionsManager permissionsManager;
|
||||
private final String helpHeader;
|
||||
|
||||
public HelpProvider(PermissionsManager permissionsManager, String helpHeader) {
|
||||
this.permissionsManager = permissionsManager;
|
||||
this.helpHeader = helpHeader;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show help for a specific command.
|
||||
*
|
||||
* @param sender The command sender the help needs to be shown to.
|
||||
* @param reference The command reference to the help command.
|
||||
* @param helpQuery The query to show help for.
|
||||
* @param showCommand True to show the command.
|
||||
* @param showDescription True to show the command description, both the short and detailed description.
|
||||
* @param showArguments True to show the command argument help.
|
||||
* @param showPermissions True to show the command permission help.
|
||||
* @param showAlternatives True to show the command alternatives.
|
||||
* @param showCommands True to show the child commands.
|
||||
*/
|
||||
public static void showHelp(CommandSender sender, CommandParts reference, CommandParts helpQuery, boolean showCommand, boolean showDescription, boolean showArguments, boolean showPermissions, boolean showAlternatives, boolean showCommands) {
|
||||
// Find the command for this help query, one with and one without a prefixed base command
|
||||
FoundCommandResult result = AuthMe.getInstance().getCommandHandler().findCommand(new CommandParts(helpQuery.getList()));
|
||||
|
||||
// TODO ljacqu 20151204 Fix me to nicer code
|
||||
List<String> parts = new ArrayList<>(helpQuery.getList());
|
||||
parts.add(0, reference.get(0));
|
||||
CommandParts commandReferenceOther = new CommandParts(parts);
|
||||
|
||||
FoundCommandResult resultOther = AuthMe.getInstance().getCommandHandler().findCommand(commandReferenceOther);
|
||||
if (resultOther != null) {
|
||||
if (result == null)
|
||||
result = resultOther;
|
||||
|
||||
else if (result.getDifference() > resultOther.getDifference())
|
||||
result = resultOther;
|
||||
public List<String> printHelp(CommandSender sender, FoundCommandResult result, int options) {
|
||||
if (result.getCommandDescription() == null) {
|
||||
return singletonList(ChatColor.DARK_RED + "Failed to retrieve any help information!");
|
||||
}
|
||||
|
||||
// Make sure a result was found
|
||||
if (result == null) {
|
||||
// Show a warning message
|
||||
sender.sendMessage(ChatColor.DARK_RED + "" + ChatColor.ITALIC + helpQuery);
|
||||
sender.sendMessage(ChatColor.DARK_RED + "Couldn't show any help information for this help query.");
|
||||
return;
|
||||
}
|
||||
List<String> lines = new ArrayList<>();
|
||||
lines.add(ChatColor.GOLD + "==========[ " + helpHeader + " HELP ]==========");
|
||||
|
||||
// Get the command description, and make sure it's valid
|
||||
CommandDescription command = result.getCommandDescription();
|
||||
if (command == null) {
|
||||
// Show a warning message
|
||||
sender.sendMessage(ChatColor.DARK_RED + "Failed to retrieve any help information!");
|
||||
return;
|
||||
List<String> labels = ImmutableList.copyOf(result.getLabels());
|
||||
List<String> correctLabels = ImmutableList.copyOf(filterCorrectLabels(command, labels));
|
||||
|
||||
if (!hasFlag(HIDE_COMMAND, options)) {
|
||||
lines.add(ChatColor.GOLD + "Command: " + CommandSyntaxHelper.getSyntax(command, correctLabels));
|
||||
}
|
||||
if (hasFlag(SHOW_LONG_DESCRIPTION, options)) {
|
||||
printDetailedDescription(command, lines);
|
||||
}
|
||||
if (hasFlag(SHOW_ARGUMENTS, options)) {
|
||||
printArguments(command, lines);
|
||||
}
|
||||
if (hasFlag(SHOW_PERMISSIONS, options) && sender != null) {
|
||||
printPermissions(command, sender, permissionsManager, lines);
|
||||
}
|
||||
if (hasFlag(SHOW_ALTERNATIVES, options)) {
|
||||
printAlternatives(command, correctLabels, lines);
|
||||
}
|
||||
if (hasFlag(SHOW_CHILDREN, options)) {
|
||||
printChildren(command, labels, lines);
|
||||
}
|
||||
|
||||
// Get the proper command reference to use for the help page
|
||||
CommandParts commandReference = command.getCommandReference(result.getQueryReference());
|
||||
|
||||
// Get the base command
|
||||
String baseCommand = commandReference.get(0);
|
||||
|
||||
// Make sure the difference between the command reference and the actual command isn't too big
|
||||
final double commandDifference = result.getDifference();
|
||||
if (commandDifference > 0.20) {
|
||||
// Show the unknown command warning
|
||||
sender.sendMessage(ChatColor.DARK_RED + "No help found for '" + helpQuery + "'!");
|
||||
|
||||
// Show a command suggestion if available and the difference isn't too big
|
||||
if (commandDifference < 0.75 && result.getCommandDescription() != null) {
|
||||
// Get the suggested command
|
||||
List<String> suggestedCommandParts = CollectionUtils.getRange(
|
||||
result.getCommandDescription().getCommandReference(commandReference).getList(), 1);
|
||||
sender.sendMessage(ChatColor.YELLOW + "Did you mean " + ChatColor.GOLD + "/" + baseCommand
|
||||
+ " help " + CommandUtils.labelsToString(suggestedCommandParts) + ChatColor.YELLOW + "?");
|
||||
}
|
||||
|
||||
// Show the help command
|
||||
sender.sendMessage(ChatColor.YELLOW + "Use the command " + ChatColor.GOLD + "/" + baseCommand + " help" + ChatColor.YELLOW + " to view help.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Show a message when the command handler is assuming a command
|
||||
if (commandDifference > 0) {
|
||||
// Get the suggested command
|
||||
List<String> suggestedCommandParts = CollectionUtils.getRange(
|
||||
result.getCommandDescription().getCommandReference(commandReference).getList(), 1);
|
||||
|
||||
// Show the suggested command
|
||||
sender.sendMessage(ChatColor.DARK_RED + "No help found, assuming '" + ChatColor.GOLD
|
||||
+ CommandUtils.labelsToString(suggestedCommandParts) + ChatColor.DARK_RED + "'!");
|
||||
}
|
||||
|
||||
// Print the help header
|
||||
sender.sendMessage(ChatColor.GOLD + "==========[ " + Settings.helpHeader.toUpperCase() + " HELP ]==========");
|
||||
|
||||
// Print the command help information
|
||||
if (showCommand)
|
||||
HelpPrinter.printCommand(sender, command, commandReference);
|
||||
if (showDescription)
|
||||
HelpPrinter.printCommandDescription(sender, command);
|
||||
if (showArguments)
|
||||
HelpPrinter.printArguments(sender, command);
|
||||
if (showPermissions)
|
||||
HelpPrinter.printPermissions(sender, command);
|
||||
if (showAlternatives)
|
||||
HelpPrinter.printAlternatives(sender, command, commandReference);
|
||||
if (showCommands)
|
||||
HelpPrinter.printChildren(sender, command, commandReference);
|
||||
return lines;
|
||||
}
|
||||
|
||||
private static void printDetailedDescription(CommandDescription command, List<String> lines) {
|
||||
lines.add(ChatColor.GOLD + "Short description: " + ChatColor.WHITE + command.getDescription());
|
||||
lines.add(ChatColor.GOLD + "Detailed description:");
|
||||
lines.add(ChatColor.WHITE + " " + command.getDetailedDescription());
|
||||
}
|
||||
|
||||
private static void printArguments(CommandDescription command, List<String> lines) {
|
||||
if (command.getArguments().isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
lines.add(ChatColor.GOLD + "Arguments:");
|
||||
StringBuilder argString = new StringBuilder();
|
||||
for (CommandArgumentDescription argument : command.getArguments()) {
|
||||
argString.setLength(0);
|
||||
argString.append(" ").append(ChatColor.YELLOW).append(ChatColor.ITALIC).append(argument.getName())
|
||||
.append(": ").append(ChatColor.WHITE).append(argument.getDescription());
|
||||
|
||||
if (argument.isOptional()) {
|
||||
argString.append(ChatColor.GRAY).append(ChatColor.ITALIC).append(" (Optional)");
|
||||
}
|
||||
lines.add(argString.toString());
|
||||
}
|
||||
}
|
||||
|
||||
private static void printAlternatives(CommandDescription command, List<String> correctLabels, List<String> lines) {
|
||||
// TODO ljacqu 20151219: Need to show alternatives for base labels too? E.g. /r for /register
|
||||
if (command.getLabels().size() <= 1 || correctLabels.size() <= 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
lines.add(ChatColor.GOLD + "Alternatives:");
|
||||
// Get the label used
|
||||
final String parentLabel = correctLabels.get(0);
|
||||
final String childLabel = correctLabels.get(1);
|
||||
|
||||
// Create a list of alternatives
|
||||
for (String entry : command.getLabels()) {
|
||||
if (!entry.equalsIgnoreCase(childLabel)) {
|
||||
lines.add(" " + CommandSyntaxHelper.getSyntax(command, asList(parentLabel, entry)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void printPermissions(CommandDescription command, CommandSender sender,
|
||||
PermissionsManager permissionsManager, List<String> lines) {
|
||||
CommandPermissions permissions = command.getCommandPermissions();
|
||||
// TODO ljacqu 20151224: Isn't it possible to have a default permission but no permission nodes?
|
||||
if (permissions == null || CollectionUtils.isEmpty(permissions.getPermissionNodes())) {
|
||||
return;
|
||||
}
|
||||
lines.add(ChatColor.GOLD + "Permissions:");
|
||||
|
||||
for (PermissionNode node : permissions.getPermissionNodes()) {
|
||||
boolean hasPermission = permissionsManager.hasPermission(sender, node);
|
||||
final String nodePermsString = "" + ChatColor.GRAY + ChatColor.ITALIC
|
||||
+ (hasPermission ? " (You have permission)" : " (No permission)");
|
||||
lines.add(" " + ChatColor.YELLOW + ChatColor.ITALIC + node.getNode() + nodePermsString);
|
||||
}
|
||||
|
||||
// Addendum to the line to specify whether the sender has permission or not when default is OP_ONLY
|
||||
final DefaultPermission defaultPermission = permissions.getDefaultPermission();
|
||||
String addendum = "";
|
||||
if (DefaultPermission.OP_ONLY.equals(defaultPermission)) {
|
||||
addendum = PermissionsManager.evaluateDefaultPermission(defaultPermission, sender)
|
||||
? " (You have permission)"
|
||||
: " (No permission)";
|
||||
}
|
||||
lines.add(ChatColor.GOLD + "Default: " + ChatColor.GRAY + ChatColor.ITALIC
|
||||
+ defaultPermission.getTitle() + addendum);
|
||||
|
||||
// Evaluate if the sender has permission to the command
|
||||
if (permissionsManager.hasPermission(sender, command)) {
|
||||
lines.add(ChatColor.GOLD + " Result: " + ChatColor.GREEN + ChatColor.ITALIC + "You have permission");
|
||||
} else {
|
||||
lines.add(ChatColor.GOLD + " Result: " + ChatColor.DARK_RED + ChatColor.ITALIC + "No permission");
|
||||
}
|
||||
}
|
||||
|
||||
private static void printChildren(CommandDescription command, List<String> parentLabels, List<String> lines) {
|
||||
if (command.getChildren().isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
lines.add(ChatColor.GOLD + "Commands:");
|
||||
String parentCommandPath = CommandUtils.labelsToString(parentLabels);
|
||||
for (CommandDescription child : command.getChildren()) {
|
||||
lines.add(" /" + parentCommandPath + " " + child.getLabels().get(0)
|
||||
+ ChatColor.GRAY + ChatColor.ITALIC + ": " + child.getDescription());
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean hasFlag(int flag, int options) {
|
||||
return (flag & options) != 0;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
protected static List<String> filterCorrectLabels(CommandDescription command, List<String> labels) {
|
||||
List<CommandDescription> commands = CommandUtils.constructParentList(command);
|
||||
List<String> correctLabels = new ArrayList<>();
|
||||
boolean foundIncorrectLabel = false;
|
||||
for (int i = 0; i < commands.size(); ++i) {
|
||||
if (!foundIncorrectLabel && i < labels.size() && commands.get(i).hasLabel(labels.get(i))) {
|
||||
correctLabels.add(labels.get(i));
|
||||
} else {
|
||||
foundIncorrectLabel = true;
|
||||
correctLabels.add(commands.get(i).getLabels().get(0));
|
||||
}
|
||||
}
|
||||
return correctLabels;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,76 +0,0 @@
|
||||
package fr.xephi.authme.command.help;
|
||||
|
||||
import fr.xephi.authme.command.CommandArgumentDescription;
|
||||
import fr.xephi.authme.command.CommandDescription;
|
||||
import fr.xephi.authme.command.CommandParts;
|
||||
import fr.xephi.authme.command.CommandUtils;
|
||||
import fr.xephi.authme.util.CollectionUtils;
|
||||
import fr.xephi.authme.util.StringUtils;
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
/**
|
||||
* 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 formatted syntax for a command.
|
||||
*
|
||||
* @param commandDescription The command to build the syntax for.
|
||||
* @param commandReference The reference of the command.
|
||||
* @param alternativeLabel The alternative label to use for this command syntax.
|
||||
* @param highlight True to highlight the important parts of this command.
|
||||
*
|
||||
* @return The command with proper syntax.
|
||||
*/
|
||||
public static String getCommandSyntax(CommandDescription commandDescription, CommandParts commandReference,
|
||||
String alternativeLabel, boolean highlight) {
|
||||
// Create a string builder with white color and prefixed slash
|
||||
StringBuilder sb = new StringBuilder()
|
||||
.append(ChatColor.WHITE)
|
||||
.append("/");
|
||||
|
||||
// Get the help command reference, and the command label
|
||||
CommandParts helpCommandReference = commandDescription.getCommandReference(commandReference);
|
||||
final String parentCommand = CommandUtils.labelsToString(
|
||||
CollectionUtils.getRange(helpCommandReference.getList(), 0, helpCommandReference.getCount() - 1));
|
||||
|
||||
// Check whether the alternative label should be used
|
||||
String commandLabel;
|
||||
if (StringUtils.isEmpty(alternativeLabel)) {
|
||||
commandLabel = helpCommandReference.get(helpCommandReference.getCount() - 1);
|
||||
} else {
|
||||
commandLabel = alternativeLabel;
|
||||
}
|
||||
|
||||
// Show the important bit of the command, highlight this part if required
|
||||
sb.append(parentCommand)
|
||||
.append(" ")
|
||||
.append(highlight ? ChatColor.YELLOW.toString() + ChatColor.BOLD : "")
|
||||
.append(commandLabel);
|
||||
|
||||
if (highlight) {
|
||||
sb.append(ChatColor.YELLOW);
|
||||
}
|
||||
|
||||
// Add each command argument
|
||||
for (CommandArgumentDescription arg : commandDescription.getArguments()) {
|
||||
sb.append(ChatColor.ITALIC).append(formatArgument(arg));
|
||||
}
|
||||
|
||||
// Return the build command syntax
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private static String formatArgument(CommandArgumentDescription argument) {
|
||||
if (argument.isOptional()) {
|
||||
return " [" + argument.getLabel() + "]";
|
||||
}
|
||||
return " <" + argument.getLabel() + ">";
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
package fr.xephi.authme.converter;
|
||||
|
||||
/**
|
||||
* Common supertype for AuthMe converters.
|
||||
*/
|
||||
public interface Converter extends Runnable {
|
||||
}
|
||||
|
@ -14,13 +14,11 @@ import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author Xephi59
|
||||
* @version $Revision: 1.0 $
|
||||
*/
|
||||
public class CrazyLoginConverter implements Converter {
|
||||
|
||||
public final AuthMe instance;
|
||||
public final DataSource database;
|
||||
public final CommandSender sender;
|
||||
private final DataSource database;
|
||||
private final CommandSender sender;
|
||||
|
||||
/**
|
||||
* Constructor for CrazyLoginConverter.
|
||||
@ -29,8 +27,7 @@ public class CrazyLoginConverter implements Converter {
|
||||
* @param sender CommandSender
|
||||
*/
|
||||
public CrazyLoginConverter(AuthMe instance, CommandSender sender) {
|
||||
this.instance = instance;
|
||||
this.database = instance.database;
|
||||
this.database = instance.getDataSource();
|
||||
this.sender = sender;
|
||||
}
|
||||
|
||||
|
@ -1,84 +0,0 @@
|
||||
package fr.xephi.authme.converter;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
/**
|
||||
* @author Xephi59
|
||||
* @version $Revision: 1.0 $
|
||||
*/
|
||||
public class FlatToSql implements Converter {
|
||||
|
||||
private static String tableName;
|
||||
private static String columnName;
|
||||
private static String columnPassword;
|
||||
private static String columnIp;
|
||||
private static String columnLastLogin;
|
||||
private static String lastlocX;
|
||||
private static String lastlocY;
|
||||
private static String lastlocZ;
|
||||
private static String lastlocWorld;
|
||||
private static String columnEmail;
|
||||
private static String columnLogged;
|
||||
private static String columnID;
|
||||
|
||||
public FlatToSql() {
|
||||
tableName = Settings.getMySQLTablename;
|
||||
columnName = Settings.getMySQLColumnName;
|
||||
columnPassword = Settings.getMySQLColumnPassword;
|
||||
columnIp = Settings.getMySQLColumnIp;
|
||||
columnLastLogin = Settings.getMySQLColumnLastLogin;
|
||||
lastlocX = Settings.getMySQLlastlocX;
|
||||
lastlocY = Settings.getMySQLlastlocY;
|
||||
lastlocZ = Settings.getMySQLlastlocZ;
|
||||
lastlocWorld = Settings.getMySQLlastlocWorld;
|
||||
columnEmail = Settings.getMySQLColumnEmail;
|
||||
columnLogged = Settings.getMySQLColumnLogged;
|
||||
columnID = Settings.getMySQLColumnId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method run.
|
||||
*
|
||||
* @see java.lang.Runnable#run()
|
||||
*/
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
File source = new File(AuthMe.getInstance().getDataFolder() + File.separator + "auths.db");
|
||||
source.createNewFile();
|
||||
File output = new File(AuthMe.getInstance().getDataFolder() + File.separator + "authme.sql");
|
||||
output.createNewFile();
|
||||
BufferedReader br = new BufferedReader(new FileReader(source));
|
||||
BufferedWriter sql = new BufferedWriter(new FileWriter(output));
|
||||
String createDB = "CREATE TABLE IF NOT EXISTS " + tableName + " (" + columnID + " INTEGER AUTO_INCREMENT," + columnName + " VARCHAR(255) NOT NULL UNIQUE," + columnPassword + " VARCHAR(255) NOT NULL," + columnIp + " VARCHAR(40) NOT NULL DEFAULT '127.0.0.1'," + columnLastLogin + " BIGINT NOT NULL DEFAULT '" + System.currentTimeMillis() + "'," + lastlocX + " DOUBLE NOT NULL DEFAULT '0.0'," + lastlocY + " DOUBLE NOT NULL DEFAULT '0.0'," + lastlocZ + " DOUBLE NOT NULL DEFAULT '0.0'," + lastlocWorld + " VARCHAR(255) DEFAULT 'world'," + columnEmail + " VARCHAR(255) DEFAULT 'your@email.com'," + columnLogged + " SMALLINT NOT NULL DEFAULT '0'," + "CONSTRAINT table_const_prim PRIMARY KEY (" + columnID + "));";
|
||||
sql.write(createDB);
|
||||
String line;
|
||||
String newline;
|
||||
while ((line = br.readLine()) != null) {
|
||||
sql.newLine();
|
||||
String[] args = line.split(":");
|
||||
if (args.length == 4)
|
||||
newline = "INSERT INTO " + tableName + "(" + columnName + "," + columnPassword + "," + columnIp + "," + columnLastLogin + "," + lastlocX + "," + lastlocY + "," + lastlocZ + "," + lastlocWorld + "," + columnEmail + "," + columnLogged + ") VALUES ('" + args[0] + "', '" + args[1] + "', '" + args[2] + "', " + args[3] + ", 0.0, 0.0, 0.0, 'world', 'your@email.com', 0);";
|
||||
else if (args.length == 7)
|
||||
newline = "INSERT INTO " + tableName + "(" + columnName + "," + columnPassword + "," + columnIp + "," + columnLastLogin + "," + lastlocX + "," + lastlocY + "," + lastlocZ + "," + lastlocWorld + "," + columnEmail + "," + columnLogged + ") VALUES ('" + args[0] + "', '" + args[1] + "', '" + args[2] + "', " + args[3] + ", " + args[4] + ", " + args[5] + ", " + args[6] + ", 'world', 'your@email.com', 0);";
|
||||
else if (args.length == 8)
|
||||
newline = "INSERT INTO " + tableName + "(" + columnName + "," + columnPassword + "," + columnIp + "," + columnLastLogin + "," + lastlocX + "," + lastlocY + "," + lastlocZ + "," + lastlocWorld + "," + columnEmail + "," + columnLogged + ") VALUES ('" + args[0] + "', '" + args[1] + "', '" + args[2] + "', " + args[3] + ", " + args[4] + ", " + args[5] + ", " + args[6] + ", '" + args[7] + "', 'your@email.com', 0);";
|
||||
else if (args.length == 9)
|
||||
newline = "INSERT INTO " + tableName + "(" + columnName + "," + columnPassword + "," + columnIp + "," + columnLastLogin + "," + lastlocX + "," + lastlocY + "," + lastlocZ + "," + lastlocWorld + "," + columnEmail + "," + columnLogged + ") VALUES ('" + args[0] + "', '" + args[1] + "', '" + args[2] + "', " + args[3] + ", " + args[4] + ", " + args[5] + ", " + args[6] + ", '" + args[7] + "', '" + args[8] + "', 0);";
|
||||
else newline = "";
|
||||
if (!newline.equals(""))
|
||||
sql.write(newline);
|
||||
}
|
||||
sql.close();
|
||||
br.close();
|
||||
ConsoleLogger.info("The FlatFile has been converted to authme.sql file");
|
||||
} catch (IOException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
ConsoleLogger.showError("Can't open the flat database file! Does it exist?");
|
||||
}
|
||||
}
|
||||
}
|
@ -1,198 +0,0 @@
|
||||
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.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.sql.*;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class FlatToSqlite implements Converter {
|
||||
|
||||
public final CommandSender sender;
|
||||
private String tableName;
|
||||
private String columnName;
|
||||
private String columnPassword;
|
||||
private String columnIp;
|
||||
private String columnLastLogin;
|
||||
private String lastlocX;
|
||||
private String lastlocY;
|
||||
private String lastlocZ;
|
||||
private String lastlocWorld;
|
||||
private String columnEmail;
|
||||
private String database;
|
||||
private String columnID;
|
||||
private Connection con;
|
||||
|
||||
/**
|
||||
* Constructor for FlatToSqlite.
|
||||
*
|
||||
* @param sender CommandSender
|
||||
*/
|
||||
public FlatToSqlite(CommandSender sender) {
|
||||
this.sender = sender;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method close.
|
||||
*
|
||||
* @param o AutoCloseable
|
||||
*/
|
||||
private static void close(AutoCloseable o) {
|
||||
if (o != null) {
|
||||
try {
|
||||
o.close();
|
||||
} catch (Exception ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method run.
|
||||
*
|
||||
* @see java.lang.Runnable#run()
|
||||
*/
|
||||
@Override
|
||||
public void run() {
|
||||
database = Settings.getMySQLDatabase;
|
||||
tableName = Settings.getMySQLTablename;
|
||||
columnName = Settings.getMySQLColumnName;
|
||||
columnPassword = Settings.getMySQLColumnPassword;
|
||||
columnIp = Settings.getMySQLColumnIp;
|
||||
columnLastLogin = Settings.getMySQLColumnLastLogin;
|
||||
lastlocX = Settings.getMySQLlastlocX;
|
||||
lastlocY = Settings.getMySQLlastlocY;
|
||||
lastlocZ = Settings.getMySQLlastlocZ;
|
||||
lastlocWorld = Settings.getMySQLlastlocWorld;
|
||||
columnEmail = Settings.getMySQLColumnEmail;
|
||||
columnID = Settings.getMySQLColumnId;
|
||||
|
||||
File source = new File(Settings.PLUGIN_FOLDER, "auths.db");
|
||||
if (!source.exists()) {
|
||||
sender.sendMessage("Source file for FlatFile database not found... Aborting");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
connect();
|
||||
setup();
|
||||
} catch (Exception e) {
|
||||
sender.sendMessage("Some error appeared while trying to setup and connect to sqlite database... Aborting");
|
||||
return;
|
||||
}
|
||||
|
||||
try (BufferedReader reader = new BufferedReader(new FileReader(source))) {
|
||||
String line;
|
||||
int i = 1;
|
||||
String newline;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
String[] args = line.split(":");
|
||||
if (args.length == 4)
|
||||
newline = "INSERT INTO " + tableName + " VALUES (" + i + ", '" + args[0] + "', '" + args[1] + "', '" + args[2] + "', " + args[3] + ", 0, 0, 0, 'world', 'your@email.com');";
|
||||
else if (args.length == 7)
|
||||
newline = "INSERT INTO " + tableName + " VALUES (" + i + ", '" + args[0] + "', '" + args[1] + "', '" + args[2] + "', " + args[3] + ", " + args[4] + ", " + args[5] + ", " + args[6] + ", 'world', 'your@email.com');";
|
||||
else if (args.length == 8)
|
||||
newline = "INSERT INTO " + tableName + " VALUES (" + i + ", '" + args[0] + "', '" + args[1] + "', '" + args[2] + "', " + args[3] + ", " + args[4] + ", " + args[5] + ", " + args[6] + ", '" + args[7] + "', 'your@email.com');";
|
||||
else if (args.length == 9)
|
||||
newline = "INSERT INTO " + tableName + " VALUES (" + i + ", '" + args[0] + "', '" + args[1] + "', '" + args[2] + "', " + args[3] + ", " + args[4] + ", " + args[5] + ", " + args[6] + ", '" + args[7] + "', '" + args[8] + "');";
|
||||
else newline = "";
|
||||
if (!newline.equals(""))
|
||||
saveAuth(newline);
|
||||
i = i + 1;
|
||||
}
|
||||
String resp = "The FlatFile has been converted to " + database + ".db file";
|
||||
ConsoleLogger.info(resp);
|
||||
sender.sendMessage(resp);
|
||||
} catch (IOException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
sender.sendMessage("Can't open the flat database file!");
|
||||
} finally {
|
||||
close(con);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method connect.
|
||||
*
|
||||
* @throws ClassNotFoundException * @throws SQLException
|
||||
*/
|
||||
private synchronized void connect() throws ClassNotFoundException, SQLException {
|
||||
Class.forName("org.sqlite.JDBC");
|
||||
con = DriverManager.getConnection("jdbc:sqlite:plugins/AuthMe/" + database + ".db");
|
||||
}
|
||||
|
||||
/**
|
||||
* Method setup.
|
||||
*
|
||||
* @throws SQLException
|
||||
*/
|
||||
private synchronized void setup() throws SQLException {
|
||||
Statement st = null;
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
st = con.createStatement();
|
||||
st.executeUpdate("CREATE TABLE IF NOT EXISTS " + tableName + " (" + columnID + " INTEGER AUTO_INCREMENT," + columnName + " VARCHAR(255) NOT NULL UNIQUE," + columnPassword + " VARCHAR(255) NOT NULL," + columnIp + " VARCHAR(40) NOT NULL," + columnLastLogin + " BIGINT," + lastlocX + " DOUBLE NOT NULL DEFAULT '0.0'," + lastlocY + " DOUBLE NOT NULL DEFAULT '0.0'," + lastlocZ + " DOUBLE NOT NULL DEFAULT '0.0'," + lastlocWorld + " VARCHAR(255) NOT NULL DEFAULT '" + Settings.defaultWorld + "'," + columnEmail + " VARCHAR(255) DEFAULT 'your@email.com'," + "CONSTRAINT table_const_prim PRIMARY KEY (" + columnID + "));");
|
||||
rs = con.getMetaData().getColumns(null, null, tableName, columnPassword);
|
||||
if (!rs.next()) {
|
||||
st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + columnPassword + " VARCHAR(255) NOT NULL;");
|
||||
}
|
||||
rs.close();
|
||||
rs = con.getMetaData().getColumns(null, null, tableName, columnIp);
|
||||
if (!rs.next()) {
|
||||
st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + columnIp + " VARCHAR(40) NOT NULL;");
|
||||
}
|
||||
rs.close();
|
||||
rs = con.getMetaData().getColumns(null, null, tableName, columnLastLogin);
|
||||
if (!rs.next()) {
|
||||
st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + columnLastLogin + " BIGINT;");
|
||||
}
|
||||
rs.close();
|
||||
rs = con.getMetaData().getColumns(null, null, tableName, lastlocX);
|
||||
if (!rs.next()) {
|
||||
st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + lastlocX + " DOUBLE NOT NULL DEFAULT '0.0';");
|
||||
st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + lastlocY + " DOUBLE NOT NULL DEFAULT '0.0';");
|
||||
st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + lastlocZ + " DOUBLE NOT NULL DEFAULT '0.0';");
|
||||
}
|
||||
rs.close();
|
||||
rs = con.getMetaData().getColumns(null, null, tableName, lastlocWorld);
|
||||
if (!rs.next()) {
|
||||
st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + lastlocWorld + " VARCHAR(255) NOT NULL DEFAULT 'world';");
|
||||
}
|
||||
rs.close();
|
||||
rs = con.getMetaData().getColumns(null, null, tableName, columnEmail);
|
||||
if (!rs.next()) {
|
||||
st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + columnEmail + " VARCHAR(255) DEFAULT 'your@email.com';");
|
||||
}
|
||||
} finally {
|
||||
close(rs);
|
||||
close(st);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method saveAuth.
|
||||
*
|
||||
* @param s String
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
private synchronized boolean saveAuth(String s) {
|
||||
PreparedStatement pst = null;
|
||||
try {
|
||||
pst = con.prepareStatement(s);
|
||||
pst.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
ConsoleLogger.showError(e.getMessage());
|
||||
return false;
|
||||
} finally {
|
||||
close(pst);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
@ -1,49 +1,41 @@
|
||||
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.datasource.DataSourceType;
|
||||
import fr.xephi.authme.datasource.SQLite;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.settings.NewSetting;
|
||||
import fr.xephi.authme.settings.properties.DatabaseSettings;
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
* Mandatory migration from the deprecated flat file datasource to SQLite.
|
||||
*/
|
||||
public class ForceFlatToSqlite implements Converter {
|
||||
public class ForceFlatToSqlite {
|
||||
|
||||
private final DataSource data;
|
||||
private final DataSource database;
|
||||
private final NewSetting settings;
|
||||
|
||||
/**
|
||||
* Constructor for ForceFlatToSqlite.
|
||||
*
|
||||
* @param data DataSource
|
||||
* @param plugin AuthMe
|
||||
*/
|
||||
public ForceFlatToSqlite(DataSource data, AuthMe plugin) {
|
||||
this.data = data;
|
||||
public ForceFlatToSqlite(DataSource database, NewSetting settings) {
|
||||
this.database = database;
|
||||
this.settings = settings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method run.
|
||||
*
|
||||
* @see java.lang.Runnable#run()
|
||||
*/
|
||||
@Override
|
||||
public void run() {
|
||||
DataSource sqlite = null;
|
||||
public DataSource run() {
|
||||
try {
|
||||
sqlite = new SQLite();
|
||||
for (PlayerAuth auth : data.getAllAuths()) {
|
||||
DataSource sqlite = new SQLite(settings);
|
||||
for (PlayerAuth auth : database.getAllAuths()) {
|
||||
auth.setRealName("Player");
|
||||
sqlite.saveAuth(auth);
|
||||
}
|
||||
Settings.setValue("DataSource.backend", "sqlite");
|
||||
ConsoleLogger.info("Database successfully converted to sqlite !");
|
||||
} catch (Exception e) {
|
||||
ConsoleLogger.showError("An error appeared while trying to convert flatfile to sqlite ...");
|
||||
} finally {
|
||||
if (sqlite != null)
|
||||
sqlite.close();
|
||||
settings.setProperty(DatabaseSettings.BACKEND, DataSourceType.SQLITE);
|
||||
settings.save();
|
||||
ConsoleLogger.info("Database successfully converted to sqlite!");
|
||||
return sqlite;
|
||||
} catch (SQLException | ClassNotFoundException e) {
|
||||
ConsoleLogger.logException("Could not convert from Flatfile to SQLite:", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ 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.security.crypts.HashedPassword;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
@ -13,13 +14,11 @@ import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
/**
|
||||
* @author Xephi59
|
||||
* @version $Revision: 1.0 $
|
||||
*/
|
||||
public class RakamakConverter implements Converter {
|
||||
|
||||
@ -27,33 +26,14 @@ public class RakamakConverter implements Converter {
|
||||
public final DataSource database;
|
||||
public final CommandSender sender;
|
||||
|
||||
/**
|
||||
* Constructor for RakamakConverter.
|
||||
*
|
||||
* @param instance AuthMe
|
||||
* @param sender CommandSender
|
||||
*/
|
||||
public RakamakConverter(AuthMe instance, CommandSender sender) {
|
||||
this.instance = instance;
|
||||
this.database = instance.database;
|
||||
this.database = instance.getDataSource();
|
||||
this.sender = sender;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method getInstance.
|
||||
*
|
||||
* @return RakamakConverter
|
||||
*/
|
||||
public RakamakConverter getInstance() {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method run.
|
||||
*
|
||||
* @see java.lang.Runnable#run()
|
||||
*/
|
||||
@Override
|
||||
// TODO ljacqu 20151229: Restructure this into smaller portions
|
||||
public void run() {
|
||||
HashAlgorithm hash = Settings.getPasswordHash;
|
||||
boolean useIP = Settings.rakamakUseIp;
|
||||
@ -62,7 +42,7 @@ public class RakamakConverter implements Converter {
|
||||
File source = new File(Settings.PLUGIN_FOLDER, fileName);
|
||||
File ipfiles = new File(Settings.PLUGIN_FOLDER, ipFileName);
|
||||
HashMap<String, String> playerIP = new HashMap<>();
|
||||
HashMap<String, String> playerPSW = new HashMap<>();
|
||||
HashMap<String, HashedPassword> playerPSW = new HashMap<>();
|
||||
try {
|
||||
BufferedReader users;
|
||||
BufferedReader ipFile;
|
||||
@ -78,30 +58,29 @@ public class RakamakConverter implements Converter {
|
||||
}
|
||||
}
|
||||
ipFile.close();
|
||||
|
||||
users = new BufferedReader(new FileReader(source));
|
||||
PasswordSecurity passwordSecurity = instance.getPasswordSecurity();
|
||||
while ((line = users.readLine()) != null) {
|
||||
if (line.contains("=")) {
|
||||
String[] arguments = line.split("=");
|
||||
try {
|
||||
playerPSW.put(arguments[0], PasswordSecurity.getHash(hash, arguments[1], arguments[0]));
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
ConsoleLogger.showError(e.getMessage());
|
||||
}
|
||||
HashedPassword hashedPassword = passwordSecurity.computeHash(hash, arguments[1], arguments[0]);
|
||||
playerPSW.put(arguments[0], hashedPassword);
|
||||
|
||||
}
|
||||
}
|
||||
users.close();
|
||||
for (Entry<String, String> m : playerPSW.entrySet()) {
|
||||
for (Entry<String, HashedPassword> m : playerPSW.entrySet()) {
|
||||
String playerName = m.getKey();
|
||||
String psw = playerPSW.get(playerName);
|
||||
String ip;
|
||||
if (useIP) {
|
||||
ip = playerIP.get(playerName);
|
||||
} else {
|
||||
ip = "127.0.0.1";
|
||||
}
|
||||
PlayerAuth auth = new PlayerAuth(playerName, psw, ip, System.currentTimeMillis(), playerName);
|
||||
if (PasswordSecurity.userSalt.containsKey(playerName))
|
||||
auth.setSalt(PasswordSecurity.userSalt.get(playerName));
|
||||
HashedPassword psw = playerPSW.get(playerName);
|
||||
String ip = useIP ? playerIP.get(playerName) : "127.0.0.1";
|
||||
PlayerAuth auth = PlayerAuth.builder()
|
||||
.name(playerName)
|
||||
.realName(playerName)
|
||||
.ip(ip)
|
||||
.password(psw)
|
||||
.lastLogin(System.currentTimeMillis())
|
||||
.build();
|
||||
database.saveAuth(auth);
|
||||
}
|
||||
ConsoleLogger.info("Rakamak database has been imported correctly");
|
||||
|
@ -8,28 +8,16 @@ import org.bukkit.OfflinePlayer;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class RoyalAuthConverter implements Converter {
|
||||
|
||||
public final AuthMe plugin;
|
||||
private final AuthMe plugin;
|
||||
private final DataSource data;
|
||||
|
||||
/**
|
||||
* Constructor for RoyalAuthConverter.
|
||||
*
|
||||
* @param plugin AuthMe
|
||||
*/
|
||||
public RoyalAuthConverter(AuthMe plugin) {
|
||||
this.plugin = plugin;
|
||||
this.data = plugin.database;
|
||||
this.data = plugin.getDataSource();
|
||||
}
|
||||
|
||||
/**
|
||||
* Method run.
|
||||
*
|
||||
* @see java.lang.Runnable#run()
|
||||
*/
|
||||
@Override
|
||||
public void run() {
|
||||
for (OfflinePlayer o : plugin.getServer().getOfflinePlayers()) {
|
||||
@ -45,8 +33,7 @@ public class RoyalAuthConverter implements Converter {
|
||||
PlayerAuth auth = new PlayerAuth(name, ra.getHash(), "127.0.0.1", ra.getLastLogin(), "your@email.com", o.getName());
|
||||
data.saveAuth(auth);
|
||||
} catch (Exception e) {
|
||||
ConsoleLogger.writeStackTrace(e);
|
||||
ConsoleLogger.showError("Error while trying to import " + o.getName() + " RoyalAuth datas");
|
||||
ConsoleLogger.logException("Error while trying to import " + o.getName() + " RoyalAuth data", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,35 +4,18 @@ import fr.xephi.authme.settings.CustomConfiguration;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class RoyalAuthYamlReader extends CustomConfiguration {
|
||||
class RoyalAuthYamlReader extends CustomConfiguration {
|
||||
|
||||
/**
|
||||
* Constructor for RoyalAuthYamlReader.
|
||||
*
|
||||
* @param file File
|
||||
*/
|
||||
public RoyalAuthYamlReader(File file) {
|
||||
super(file);
|
||||
load();
|
||||
save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Method getLastLogin.
|
||||
*
|
||||
* @return long
|
||||
*/
|
||||
public long getLastLogin() {
|
||||
return getLong("timestamps.quit");
|
||||
}
|
||||
|
||||
/**
|
||||
* Method getHash.
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
public String getHash() {
|
||||
return getString("login.password");
|
||||
}
|
||||
|
@ -1,59 +0,0 @@
|
||||
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.datasource.FlatFile;
|
||||
import fr.xephi.authme.output.MessageKey;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class SqlToFlat implements Converter {
|
||||
|
||||
public final AuthMe plugin;
|
||||
public final DataSource database;
|
||||
public final CommandSender sender;
|
||||
|
||||
/**
|
||||
* Constructor for SqlToFlat.
|
||||
*
|
||||
* @param plugin AuthMe
|
||||
* @param sender CommandSender
|
||||
*/
|
||||
public SqlToFlat(AuthMe plugin, CommandSender sender) {
|
||||
this.plugin = plugin;
|
||||
this.database = plugin.database;
|
||||
this.sender = sender;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method run.
|
||||
*
|
||||
* @see java.lang.Runnable#run()
|
||||
*/
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
FlatFile flat = new FlatFile();
|
||||
List<PlayerAuth> auths = database.getAllAuths();
|
||||
int i = 0;
|
||||
final int size = auths.size();
|
||||
for (PlayerAuth auth : auths) {
|
||||
flat.saveAuth(auth);
|
||||
i++;
|
||||
if ((i % 100) == 0) {
|
||||
sender.sendMessage("Conversion Status : " + i + " / " + size);
|
||||
}
|
||||
}
|
||||
sender.sendMessage("Successfully convert from SQL table to file auths.db");
|
||||
} catch (Exception ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
plugin.getMessages().send(sender, MessageKey.ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
42
src/main/java/fr/xephi/authme/converter/SqliteToSql.java
Normal file
42
src/main/java/fr/xephi/authme/converter/SqliteToSql.java
Normal file
@ -0,0 +1,42 @@
|
||||
package fr.xephi.authme.converter;
|
||||
|
||||
import fr.xephi.authme.settings.NewSetting;
|
||||
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.DataSourceType;
|
||||
import fr.xephi.authme.datasource.SQLite;
|
||||
import fr.xephi.authme.output.MessageKey;
|
||||
|
||||
public class SqliteToSql implements Converter {
|
||||
|
||||
private final AuthMe plugin;
|
||||
private final CommandSender sender;
|
||||
private final NewSetting settings;
|
||||
|
||||
public SqliteToSql(AuthMe plugin, CommandSender sender, NewSetting settings) {
|
||||
this.plugin = plugin;
|
||||
this.sender = sender;
|
||||
this.settings = settings;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (plugin.getDataSource().getType() != DataSourceType.MYSQL) {
|
||||
sender.sendMessage("Please configure your mySQL connection and re-run this command");
|
||||
return;
|
||||
}
|
||||
try {
|
||||
SQLite data = new SQLite(settings);
|
||||
for (PlayerAuth auth : data.getAllAuths()) {
|
||||
plugin.getDataSource().saveAuth(auth);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
plugin.getMessages().send(sender, MessageKey.ERROR);
|
||||
ConsoleLogger.logException("Problem during SQLite to SQL conversion:", e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -2,38 +2,22 @@ package fr.xephi.authme.converter;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class vAuthConverter implements Converter {
|
||||
|
||||
public final AuthMe plugin;
|
||||
public final DataSource database;
|
||||
public final CommandSender sender;
|
||||
private final AuthMe plugin;
|
||||
private final CommandSender sender;
|
||||
|
||||
/**
|
||||
* Constructor for vAuthConverter.
|
||||
*
|
||||
* @param plugin AuthMe
|
||||
* @param sender CommandSender
|
||||
*/
|
||||
public vAuthConverter(AuthMe plugin, CommandSender sender) {
|
||||
this.plugin = plugin;
|
||||
this.database = plugin.database;
|
||||
this.sender = sender;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method run.
|
||||
*
|
||||
* @see java.lang.Runnable#run()
|
||||
*/
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
new vAuthFileReader(plugin, sender).convert();
|
||||
new vAuthFileReader(plugin).convert();
|
||||
} catch (Exception e) {
|
||||
sender.sendMessage(e.getMessage());
|
||||
ConsoleLogger.showError(e.getMessage());
|
||||
|
@ -6,34 +6,29 @@ import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Scanner;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class vAuthFileReader {
|
||||
class vAuthFileReader {
|
||||
|
||||
public final AuthMe plugin;
|
||||
public final DataSource database;
|
||||
public final CommandSender sender;
|
||||
private final AuthMe plugin;
|
||||
private final DataSource database;
|
||||
|
||||
/**
|
||||
* Constructor for vAuthFileReader.
|
||||
*
|
||||
* @param plugin AuthMe
|
||||
* @param sender CommandSender
|
||||
*/
|
||||
public vAuthFileReader(AuthMe plugin, CommandSender sender) {
|
||||
public vAuthFileReader(AuthMe plugin) {
|
||||
this.plugin = plugin;
|
||||
this.database = plugin.database;
|
||||
this.sender = sender;
|
||||
this.database = plugin.getDataSource();
|
||||
}
|
||||
|
||||
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;
|
||||
try {
|
||||
scanner = new Scanner(file);
|
||||
@ -58,8 +53,8 @@ public class vAuthFileReader {
|
||||
database.saveAuth(auth);
|
||||
}
|
||||
scanner.close();
|
||||
} catch (Exception e) {
|
||||
ConsoleLogger.writeStackTrace(e);
|
||||
} catch (IOException e) {
|
||||
ConsoleLogger.logException("Error while trying to import some vAuth data", e);
|
||||
}
|
||||
|
||||
}
|
||||
@ -68,20 +63,11 @@ public class vAuthFileReader {
|
||||
return s.length() > 8 && s.charAt(8) == '-';
|
||||
}
|
||||
|
||||
/**
|
||||
* Method getName.
|
||||
*
|
||||
* @param uuid UUID
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
private String getName(UUID uuid) {
|
||||
try {
|
||||
for (OfflinePlayer op : Bukkit.getOfflinePlayers()) {
|
||||
if (op.getUniqueId().compareTo(uuid) == 0)
|
||||
return op.getName();
|
||||
for (OfflinePlayer op : Bukkit.getOfflinePlayers()) {
|
||||
if (op.getUniqueId().compareTo(uuid) == 0) {
|
||||
return op.getName();
|
||||
}
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -3,29 +3,16 @@ package fr.xephi.authme.converter;
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class xAuthConverter implements Converter {
|
||||
|
||||
public final AuthMe plugin;
|
||||
public final CommandSender sender;
|
||||
private final AuthMe plugin;
|
||||
private final CommandSender sender;
|
||||
|
||||
/**
|
||||
* Constructor for xAuthConverter.
|
||||
*
|
||||
* @param plugin AuthMe
|
||||
* @param sender CommandSender
|
||||
*/
|
||||
public xAuthConverter(AuthMe plugin, CommandSender sender) {
|
||||
this.plugin = plugin;
|
||||
this.sender = sender;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method run.
|
||||
*
|
||||
* @see java.lang.Runnable#run()
|
||||
*/
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
|
@ -4,8 +4,10 @@ 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.ConsoleLogger;
|
||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
import fr.xephi.authme.util.CollectionUtils;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.io.File;
|
||||
@ -16,42 +18,30 @@ import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class xAuthToFlat {
|
||||
class xAuthToFlat {
|
||||
|
||||
public final AuthMe instance;
|
||||
public final DataSource database;
|
||||
public final CommandSender sender;
|
||||
private final AuthMe instance;
|
||||
private final DataSource database;
|
||||
private final CommandSender sender;
|
||||
|
||||
/**
|
||||
* Constructor for xAuthToFlat.
|
||||
*
|
||||
* @param instance AuthMe
|
||||
* @param sender CommandSender
|
||||
*/
|
||||
public xAuthToFlat(AuthMe instance, CommandSender sender) {
|
||||
this.instance = instance;
|
||||
this.database = instance.database;
|
||||
this.database = instance.getDataSource();
|
||||
this.sender = sender;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method convert.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public boolean convert() {
|
||||
if (instance.getServer().getPluginManager().getPlugin("xAuth") == null) {
|
||||
sender.sendMessage("[AuthMe] xAuth plugin not found");
|
||||
return false;
|
||||
}
|
||||
if (!(new File(instance.getDataFolder().getParent() + File.separator + "xAuth" + File.separator + "xAuth.h2.db").exists())) {
|
||||
File xAuthDb = new File(instance.getDataFolder().getParent(), "xAuth" + File.separator + "xAuth.h2.db");
|
||||
if (!xAuthDb.exists()) {
|
||||
sender.sendMessage("[AuthMe] xAuth H2 database not found, checking for MySQL or SQLite data...");
|
||||
}
|
||||
List<Integer> players = getXAuthPlayers();
|
||||
if (players == null || players.isEmpty()) {
|
||||
sender.sendMessage("[AuthMe] Error while import xAuthPlayers");
|
||||
if (CollectionUtils.isEmpty(players)) {
|
||||
sender.sendMessage("[AuthMe] Error while importing xAuthPlayers: did not find any players");
|
||||
return false;
|
||||
}
|
||||
sender.sendMessage("[AuthMe] Starting import...");
|
||||
@ -64,21 +54,16 @@ public class xAuthToFlat {
|
||||
database.saveAuth(auth);
|
||||
}
|
||||
}
|
||||
sender.sendMessage("[AuthMe] Successfully convert from xAuth database");
|
||||
sender.sendMessage("[AuthMe] Successfully converted from xAuth database");
|
||||
} 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 occurred while importing the xAuth database."
|
||||
+ " The import may have succeeded partially.");
|
||||
ConsoleLogger.logException("Error during xAuth database import", e);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method getIdPlayer.
|
||||
*
|
||||
* @param id int
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
public String getIdPlayer(int id) {
|
||||
private String getIdPlayer(int id) {
|
||||
String realPass = "";
|
||||
Connection conn = xAuth.getPlugin().getDatabaseController().getConnection();
|
||||
PreparedStatement ps = null;
|
||||
@ -100,12 +85,7 @@ public class xAuthToFlat {
|
||||
return realPass;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method getXAuthPlayers.
|
||||
*
|
||||
* @return List<Integer>
|
||||
*/
|
||||
public List<Integer> getXAuthPlayers() {
|
||||
private List<Integer> getXAuthPlayers() {
|
||||
List<Integer> xP = new ArrayList<>();
|
||||
Connection conn = xAuth.getPlugin().getDatabaseController().getConnection();
|
||||
PreparedStatement ps = null;
|
||||
@ -126,14 +106,7 @@ public class xAuthToFlat {
|
||||
return xP;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method getPassword.
|
||||
*
|
||||
* @param accountId int
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
public String getPassword(int accountId) {
|
||||
private String getPassword(int accountId) {
|
||||
String realPass = "";
|
||||
Connection conn = xAuth.getPlugin().getDatabaseController().getConnection();
|
||||
PreparedStatement ps = null;
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user