mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2024-11-27 20:57:35 +01:00
Merge master into 306-commands-service
Conflicts: - AuthMe - CommandInitializer - ConverterCommand
This commit is contained in:
commit
103ebb44f0
@ -1,7 +1,34 @@
|
||||
package fr.xephi.authme;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.util.Calendar;
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
import org.mcstats.Metrics;
|
||||
import org.mcstats.Metrics.Graph;
|
||||
|
||||
import com.earth2me.essentials.Essentials;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
|
||||
import fr.xephi.authme.api.API;
|
||||
import fr.xephi.authme.api.NewAPI;
|
||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||
@ -577,15 +604,16 @@ public class AuthMe extends JavaPlugin {
|
||||
});
|
||||
}
|
||||
|
||||
if (Settings.isCachingEnabled) {
|
||||
database = new CacheDataSource(database);
|
||||
if (Settings.getDataSource == DataSource.DataSourceType.FILE) {
|
||||
ConsoleLogger.showError("FlatFile backend has been detected and is now deprecated, it will be changed to SQLite... Connection will be impossible until conversion is done!");
|
||||
ForceFlatToSqlite converter = new ForceFlatToSqlite(database, this);
|
||||
DataSource source = converter.run();
|
||||
if (source != null)
|
||||
database = source;
|
||||
}
|
||||
|
||||
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");
|
||||
if (Settings.isCachingEnabled) {
|
||||
database = new CacheDataSource(database);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,14 @@
|
||||
package fr.xephi.authme.command;
|
||||
|
||||
import static fr.xephi.authme.permission.DefaultPermission.ALLOWED;
|
||||
import static fr.xephi.authme.permission.DefaultPermission.OP_ONLY;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
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;
|
||||
@ -36,14 +44,6 @@ import fr.xephi.authme.command.executable.unregister.UnregisterCommand;
|
||||
import fr.xephi.authme.permission.AdminPermission;
|
||||
import fr.xephi.authme.permission.PlayerPermission;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* Initializes all available AuthMe commands.
|
||||
*/
|
||||
@ -387,8 +387,8 @@ public final class CommandInitializer {
|
||||
.labels("converter", "convert", "conv")
|
||||
.description("Converter Command")
|
||||
.detailedDescription("Converter command for AuthMeReloaded.")
|
||||
.withArgument("job", "Conversion job: flattosql / flattosqlite /| xauth / crazylogin / rakamak / " +
|
||||
"royalauth / vauth / sqltoflat / sqlitetosql", false)
|
||||
.withArgument("job", "Conversion job: xauth / crazylogin / rakamak / " +
|
||||
"royalauth / vauth / sqlitetosql", false)
|
||||
.permissions(OP_ONLY, AdminPermission.CONVERTER)
|
||||
.executableCommand(new ConverterCommand())
|
||||
.build();
|
||||
|
@ -1,15 +1,17 @@
|
||||
package fr.xephi.authme.command.executable.converter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
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.FlatToSql;
|
||||
import fr.xephi.authme.converter.FlatToSqlite;
|
||||
import fr.xephi.authme.converter.RakamakConverter;
|
||||
import fr.xephi.authme.converter.RoyalAuthConverter;
|
||||
import fr.xephi.authme.converter.SqlToFlat;
|
||||
import fr.xephi.authme.converter.SqliteToSql;
|
||||
import fr.xephi.authme.converter.vAuthConverter;
|
||||
import fr.xephi.authme.converter.xAuthConverter;
|
||||
@ -38,12 +40,6 @@ public class ConverterCommand implements ExecutableCommand {
|
||||
// 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;
|
||||
@ -59,9 +55,6 @@ public class ConverterCommand implements ExecutableCommand {
|
||||
case VAUTH:
|
||||
converter = new vAuthConverter(plugin, sender);
|
||||
break;
|
||||
case SQLTOFLAT:
|
||||
converter = new SqlToFlat(plugin, sender);
|
||||
break;
|
||||
case SQLITETOSQL:
|
||||
converter = new SqliteToSql(plugin, sender);
|
||||
break;
|
||||
@ -77,14 +70,11 @@ public class ConverterCommand implements ExecutableCommand {
|
||||
}
|
||||
|
||||
public enum ConvertType {
|
||||
FTSQL("flattosql"),
|
||||
FTSQLITE("flattosqlite"),
|
||||
XAUTH("xauth"),
|
||||
CRAZYLOGIN("crazylogin"),
|
||||
RAKAMAK("rakamak"),
|
||||
ROYALAUTH("royalauth"),
|
||||
VAUTH("vauth"),
|
||||
SQLTOFLAT("sqltoflat"),
|
||||
SQLITETOSQL("sqlitetosql");
|
||||
|
||||
final String name;
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
@ -9,7 +9,7 @@ import fr.xephi.authme.settings.Settings;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class ForceFlatToSqlite implements Converter {
|
||||
public class ForceFlatToSqlite {
|
||||
|
||||
private final DataSource data;
|
||||
|
||||
@ -28,8 +28,7 @@ public class ForceFlatToSqlite implements Converter {
|
||||
*
|
||||
* @see java.lang.Runnable#run()
|
||||
*/
|
||||
@Override
|
||||
public void run() {
|
||||
public DataSource run() {
|
||||
DataSource sqlite = null;
|
||||
try {
|
||||
sqlite = new SQLite();
|
||||
@ -40,10 +39,9 @@ public class ForceFlatToSqlite implements Converter {
|
||||
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();
|
||||
ConsoleLogger.showError("An error occured while trying to convert flatfile to sqlite ...");
|
||||
return null;
|
||||
}
|
||||
return sqlite;
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,11 +1,5 @@
|
||||
package fr.xephi.authme.datasource;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||
import fr.xephi.authme.cache.auth.PlayerCache;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
@ -16,8 +10,15 @@ import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||
import fr.xephi.authme.cache.auth.PlayerCache;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
|
||||
/**
|
||||
*/
|
||||
@Deprecated
|
||||
public class FlatFile implements DataSource {
|
||||
|
||||
/*
|
||||
|
@ -250,8 +250,7 @@ public class PermissionsManager implements PermissionsService {
|
||||
// Check if any known permissions system is enabling
|
||||
if (pluginName.equals("PermissionsEx") || pluginName.equals("PermissionsBukkit") ||
|
||||
pluginName.equals("bPermissions") || pluginName.equals("GroupManager") ||
|
||||
pluginName.equals("zPermissions") || pluginName.equals("Vault") ||
|
||||
pluginName.equals("Permissions")) {
|
||||
pluginName.equals("zPermissions") || pluginName.equals("Vault")) {
|
||||
this.log.info(pluginName + " plugin enabled, dynamically updating permissions hooks!");
|
||||
setup();
|
||||
}
|
||||
@ -270,8 +269,7 @@ public class PermissionsManager implements PermissionsService {
|
||||
// Is the WorldGuard plugin disabled
|
||||
if (pluginName.equals("PermissionsEx") || pluginName.equals("PermissionsBukkit") ||
|
||||
pluginName.equals("bPermissions") || pluginName.equals("GroupManager") ||
|
||||
pluginName.equals("zPermissions") || pluginName.equals("Vault") ||
|
||||
pluginName.equals("Permissions")) {
|
||||
pluginName.equals("zPermissions") || pluginName.equals("Vault")) {
|
||||
this.log.info(pluginName + " plugin disabled, updating hooks!");
|
||||
setup();
|
||||
}
|
||||
|
@ -1,7 +1,14 @@
|
||||
package fr.xephi.authme.process.login;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
|
||||
import com.google.common.io.ByteArrayDataOutput;
|
||||
import com.google.common.io.ByteStreams;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||
import fr.xephi.authme.cache.backup.JsonCache;
|
||||
@ -16,11 +23,6 @@ import fr.xephi.authme.listener.AuthMePlayerListener;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.util.Utils;
|
||||
import fr.xephi.authme.util.Utils.GroupType;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
|
||||
/**
|
||||
*/
|
||||
@ -197,6 +199,16 @@ public class ProcessSyncronousPlayerLogin implements Runnable {
|
||||
|
||||
// Login is now finish , we can force all commands
|
||||
forceCommands();
|
||||
|
||||
sendTo();
|
||||
}
|
||||
|
||||
private void sendTo() {
|
||||
if (Settings.sendPlayerTo.isEmpty())
|
||||
return;
|
||||
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
||||
out.writeUTF("Connect");
|
||||
out.writeUTF(Settings.sendPlayerTo);
|
||||
player.sendPluginMessage(plugin, "BungeeCord", out.toByteArray());
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,14 @@
|
||||
package fr.xephi.authme.process.register;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import com.google.common.io.ByteArrayDataOutput;
|
||||
import com.google.common.io.ByteStreams;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.cache.limbo.LimboCache;
|
||||
@ -14,11 +21,6 @@ import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.task.MessageTask;
|
||||
import fr.xephi.authme.task.TimeoutTask;
|
||||
import fr.xephi.authme.util.Utils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
/**
|
||||
*/
|
||||
@ -161,5 +163,16 @@ public class ProcessSyncPasswordRegister implements Runnable {
|
||||
|
||||
// Register is now finish , we can force all commands
|
||||
forceCommands();
|
||||
|
||||
sendTo();
|
||||
}
|
||||
|
||||
private void sendTo() {
|
||||
if (Settings.sendPlayerTo.isEmpty())
|
||||
return;
|
||||
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
||||
out.writeUTF("Connect");
|
||||
out.writeUTF(Settings.sendPlayerTo);
|
||||
player.sendPluginMessage(plugin, "BungeeCord", out.toByteArray());
|
||||
}
|
||||
}
|
||||
|
@ -1,15 +1,5 @@
|
||||
package fr.xephi.authme.settings;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
import com.google.common.io.Files;
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
import fr.xephi.authme.datasource.DataSource.DataSourceType;
|
||||
import fr.xephi.authme.security.HashAlgorithm;
|
||||
import fr.xephi.authme.util.Wrapper;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
@ -25,6 +15,18 @@ import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
import com.google.common.io.Files;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
import fr.xephi.authme.datasource.DataSource.DataSourceType;
|
||||
import fr.xephi.authme.security.HashAlgorithm;
|
||||
import fr.xephi.authme.util.Wrapper;
|
||||
|
||||
/**
|
||||
*/
|
||||
public final class Settings {
|
||||
@ -93,7 +95,7 @@ public final class Settings {
|
||||
getMailSubject, getMailText, getMySQLlastlocWorld, defaultWorld,
|
||||
getPhpbbPrefix, getWordPressPrefix, getMySQLColumnLogged,
|
||||
spawnPriority, crazyloginFileName, getPassRegex,
|
||||
getMySQLColumnRealName, emailOauth2Token;
|
||||
getMySQLColumnRealName, emailOauth2Token, sendPlayerTo;
|
||||
public static int getWarnMessageInterval, getSessionTimeout,
|
||||
getRegistrationTimeout, getMaxNickLength, getMinNickLength,
|
||||
getPasswordMinLen, getMovementRadius, getmaxRegPerIp,
|
||||
@ -301,6 +303,7 @@ public final class Settings {
|
||||
preventOtherCase = configFile.getBoolean("settings.preventOtherCase", false);
|
||||
kickPlayersBeforeStopping = configFile.getBoolean("Security.stop.kickPlayersBeforeStopping", true);
|
||||
emailOauth2Token = configFile.getString("Email.emailOauth2Token", "");
|
||||
sendPlayerTo = configFile.getString("Hooks.sendPlayerTo", "");
|
||||
|
||||
// Load the welcome message
|
||||
getWelcomeMessage();
|
||||
@ -743,6 +746,12 @@ public final class Settings {
|
||||
|
||||
if (!contains("Email.emailOauth2Token"))
|
||||
set("Email.emailOauth2Token", "");
|
||||
|
||||
if (!contains("Hook.sendPlayerTo"))
|
||||
{
|
||||
set("Hooks.sendPlayerTo", "");
|
||||
changes = true;
|
||||
}
|
||||
|
||||
if (changes) {
|
||||
plugin.getLogger().warning("Merged new Config Options - I'm not an error, please don't report me");
|
||||
|
@ -4,8 +4,6 @@ import net.ricecode.similarity.LevenshteinDistanceStrategy;
|
||||
import net.ricecode.similarity.StringSimilarityService;
|
||||
import net.ricecode.similarity.StringSimilarityServiceImpl;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
@ -108,25 +106,6 @@ public final class StringUtils {
|
||||
return join(delimiter, Arrays.asList(elements));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a full stack trace of an exception as a string.
|
||||
*
|
||||
* @param exception The exception.
|
||||
*
|
||||
* @return Stack trace as a string.
|
||||
*/
|
||||
public static String getStackTrace(Exception exception) {
|
||||
// Create a string and print writer to print the stack trace into
|
||||
StringWriter stringWriter = new StringWriter();
|
||||
PrintWriter printWriter = new PrintWriter(stringWriter);
|
||||
|
||||
// Print the stack trace into the print writer
|
||||
exception.printStackTrace(printWriter);
|
||||
|
||||
// Return the result as a string
|
||||
return stringWriter.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Format the information from a Throwable as string, retaining the type and its message.
|
||||
*
|
||||
|
@ -359,8 +359,10 @@ Email:
|
||||
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?
|
||||
# Do we need to hook with BungeeCord ?
|
||||
bungeecord: false
|
||||
# Send player to this BungeeCord server after register/login
|
||||
sendPlayerTo: ''
|
||||
# Do we need to disable Essentials SocialSpy on join?
|
||||
disableSocialSpy: true
|
||||
# Do we need to force /motd Essentials command on join?
|
||||
|
@ -6,9 +6,8 @@ import java.net.MalformedURLException;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static org.hamcrest.Matchers.greaterThan;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.stringContainsInOrder;
|
||||
import static org.hamcrest.Matchers.greaterThan;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
@ -121,18 +120,6 @@ public class StringUtilsTest {
|
||||
assertThat(result, equalTo("[MalformedURLException]: Unrecognized URL format"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldPrintStackTrace() {
|
||||
// given
|
||||
MalformedURLException ex = new MalformedURLException("Unrecognized URL format");
|
||||
|
||||
// when
|
||||
String result = StringUtils.getStackTrace(ex);
|
||||
|
||||
// then
|
||||
assertThat(result, stringContainsInOrder(getClass().getName()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldGetDifferenceWithNullString() {
|
||||
// given/when/then
|
||||
|
@ -12,12 +12,15 @@ import utils.TagReplacer;
|
||||
import utils.ToolTask;
|
||||
import utils.ToolsConstants;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.Scanner;
|
||||
import java.util.Set;
|
||||
|
||||
public class CommandPageCreater implements ToolTask {
|
||||
|
||||
private static final String OUTPUT_FILE = ToolsConstants.DOCS_FOLDER + "commands.md";
|
||||
|
||||
@Override
|
||||
public String getTaskName() {
|
||||
return "createCommandPage";
|
||||
@ -30,20 +33,30 @@ public class CommandPageCreater implements ToolTask {
|
||||
+ "commands/command_entry.tpl.md");
|
||||
|
||||
StringBuilder commandsResult = new StringBuilder();
|
||||
for (CommandDescription command : baseCommands) {
|
||||
addCommandsInfo(commandsResult, baseCommands, template);
|
||||
|
||||
FileUtils.generateFileFromTemplate(
|
||||
ToolsConstants.TOOLS_SOURCE_ROOT + "commands/commands.tpl.md",
|
||||
OUTPUT_FILE,
|
||||
ANewMap.with("commands", commandsResult.toString()).build());
|
||||
System.out.println("Wrote to '" + OUTPUT_FILE + "' with " + baseCommands.size() + " base commands.");
|
||||
}
|
||||
|
||||
private static void addCommandsInfo(StringBuilder sb, Collection<CommandDescription> commands,
|
||||
final String template) {
|
||||
for (CommandDescription command : commands) {
|
||||
Map<String, String> tags = ANewMap
|
||||
.with("command", CommandUtils.constructCommandPath(command))
|
||||
.and("description", command.getDetailedDescription())
|
||||
.and("arguments", formatArguments(command.getArguments()))
|
||||
.and("permissions", formatPermissions(command.getCommandPermissions()))
|
||||
.build();
|
||||
commandsResult.append(TagReplacer.applyReplacements(template, tags));
|
||||
}
|
||||
sb.append(TagReplacer.applyReplacements(template, tags));
|
||||
|
||||
FileUtils.generateFileFromTemplate(
|
||||
ToolsConstants.TOOLS_SOURCE_ROOT + "commands/commands.tpl.md",
|
||||
ToolsConstants.DOCS_FOLDER + "commands.md",
|
||||
ANewMap.with("commands", commandsResult.toString()).build());
|
||||
if (!command.getChildren().isEmpty()) {
|
||||
addCommandsInfo(sb, command.getChildren(), template);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static String formatPermissions(CommandPermissions permissions) {
|
||||
@ -54,16 +67,16 @@ public class CommandPageCreater implements ToolTask {
|
||||
for (PermissionNode node : permissions.getPermissionNodes()) {
|
||||
result += node.getNode() + " ";
|
||||
}
|
||||
return result;
|
||||
return result.trim();
|
||||
}
|
||||
|
||||
private static String formatArguments(Iterable<CommandArgumentDescription> arguments) {
|
||||
StringBuilder result = new StringBuilder();
|
||||
for (CommandArgumentDescription argument : arguments) {
|
||||
String argumentName = argument.isOptional()
|
||||
? "[" + argument.getDescription() + "]"
|
||||
: "<" + argument.getDescription() + ">";
|
||||
result.append(argumentName).append(" ");
|
||||
? "[" + argument.getName() + "]"
|
||||
: "<" + argument.getName() + ">";
|
||||
result.append(" ").append(argumentName);
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
|
@ -1,2 +1,2 @@
|
||||
{command}: {description} _{arguments}_
|
||||
[permissions]Permission: {permissions}[/permissions]
|
||||
- **{command}**{arguments}: {description}[permissions]
|
||||
<br />Requires `{permissions}`[/permissions]
|
||||
|
@ -1,4 +1,8 @@
|
||||
## AuthMe commands
|
||||
You can use the following commands to use the functions of AuthMe:
|
||||
<!-- {gen_warning} -->
|
||||
<!-- File auto-generated on {gen_date}. 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 (`[ ]`).
|
||||
|
||||
{commands}
|
||||
|
76
src/tools/docs/commands.md
Normal file
76
src/tools/docs/commands.md
Normal file
@ -0,0 +1,76 @@
|
||||
<!-- AUTO-GENERATED FILE! Do not edit this directly -->
|
||||
<!-- File auto-generated on Sat Dec 26 14:05:00 CET 2015. 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 help** [query]: View detailed help pages about AuthMeReloaded 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 getemail** [player]: Display the email address of the specified player if set.
|
||||
<br />Requires `authme.admin.getemail`
|
||||
- **/authme chgemail** <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.
|
||||
<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.
|
||||
- **/login** <password>: Command to log in using AuthMeReloaded.
|
||||
<br />Requires `authme.player.login`
|
||||
- **/login help** [query]: View detailed help pages about AuthMeReloaded login commands.
|
||||
- **/logout**: Command to logout using AuthMeReloaded.
|
||||
<br />Requires `authme.player.logout`
|
||||
- **/logout help** [query]: View detailed help pages about AuthMeReloaded logout commands.
|
||||
- **/register** <password> [verifyPassword]: Command to register using AuthMeReloaded.
|
||||
<br />Requires `authme.player.register`
|
||||
- **/register help** [query]: View detailed help pages about AuthMeReloaded register commands.
|
||||
- **/unreg** <password>: Command to unregister using AuthMeReloaded.
|
||||
<br />Requires `authme.player.unregister`
|
||||
- **/unreg help** [query]: View detailed help pages about AuthMeReloaded unregister commands.
|
||||
- **/changepassword** <oldPassword> <newPassword>: Command to change your password using AuthMeReloaded.
|
||||
<br />Requires `authme.player.changepassword`
|
||||
- **/changepassword help** [query]: View detailed help pages about AuthMeReloaded changepassword commands.
|
||||
- **/email**: The AuthMeReloaded Email command base.
|
||||
- **/email help** [query]: View detailed help pages about AuthMeReloaded email commands.
|
||||
- **/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`
|
||||
- **/captcha** <captcha>: Captcha command for AuthMeReloaded.
|
||||
<br />Requires `authme.player.captcha`
|
||||
- **/captcha help** [query]: View detailed help pages about AuthMeReloaded captcha commands.
|
||||
- **/converter** <job>: Converter command for AuthMeReloaded.
|
||||
<br />Requires `authme.admin.converter`
|
||||
- **/converter help** [query]: View detailed help pages about AuthMeReloaded converter commands.
|
||||
|
@ -4,6 +4,8 @@ import fr.xephi.authme.util.StringUtils;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* Class responsible for replacing template tags to actual content.
|
||||
@ -15,6 +17,9 @@ import java.util.Map;
|
||||
*/
|
||||
public class TagReplacer {
|
||||
|
||||
private TagReplacer() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace a template with default tags and custom ones supplied by a map.
|
||||
*
|
||||
@ -29,11 +34,9 @@ public class TagReplacer {
|
||||
final String name = tagRule.getKey();
|
||||
final String value = tagRule.getValue();
|
||||
|
||||
String replacement = StringUtils.isEmpty(value) ? "" : "\\1";
|
||||
result = result.replaceAll("\\[" + name + "\\](.*?)\\[/" + name + "\\]", replacement);
|
||||
result = result.replace("{" + tagRule.getKey() + "}", tagRule.getValue());
|
||||
result = replaceOptionalTag(result, name, value)
|
||||
.replace("{" + name + "}", value);
|
||||
}
|
||||
|
||||
return applyReplacements(result);
|
||||
}
|
||||
|
||||
@ -49,5 +52,21 @@ public class TagReplacer {
|
||||
.replace("{gen_warning}", "AUTO-GENERATED FILE! Do not edit this directly");
|
||||
}
|
||||
|
||||
private static String replaceOptionalTag(String text, String tagName, String tagValue) {
|
||||
Pattern regex = Pattern.compile("\\[" + tagName + "\\](.*?)\\[/" + tagName + "\\]", Pattern.DOTALL);
|
||||
Matcher matcher = regex.matcher(text);
|
||||
|
||||
if (!matcher.find()) {
|
||||
// Couldn't find results, so just return text as it is
|
||||
return text;
|
||||
} else if (StringUtils.isEmpty(tagValue)) {
|
||||
// Tag is empty, replace [tagName]some_text[/tagName] to nothing
|
||||
return matcher.replaceAll("");
|
||||
} else {
|
||||
// Tag is not empty, so replace [tagName]some_text[/tagName] to some_text
|
||||
return matcher.replaceAll(matcher.group(1));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user