diff --git a/src/main/java/fr/xephi/authme/AuthMe.java b/src/main/java/fr/xephi/authme/AuthMe.java index 2488305..175f0a4 100644 --- a/src/main/java/fr/xephi/authme/AuthMe.java +++ b/src/main/java/fr/xephi/authme/AuthMe.java @@ -408,7 +408,7 @@ public class AuthMe extends JavaPlugin { if (Settings.isBackupActivated && Settings.isBackupOnStart) { // Do backup and check return value! if (new PerformBackup(this).doBackup()) { - ConsoleLogger.info("数据备份完成"); + ConsoleLogger.info("数据备份完成..."); } else { ConsoleLogger.showError("Error while performing the backup!"); } @@ -420,7 +420,7 @@ public class AuthMe extends JavaPlugin { } catch (final Exception e) { ConsoleLogger.writeStackTrace(e); ConsoleLogger.showError(e.getMessage()); - ConsoleLogger.showError("连接数据库期间发生错误! Authme 初始化 中断 关闭服务器!"); + ConsoleLogger.showError("连接数据库期间发生错误! Authme 初始化 中断!"); stopOrUnload(); return; } @@ -587,20 +587,17 @@ public class AuthMe extends JavaPlugin { isSQLite = true; break; } - if (isSQLite) { server.getScheduler().runTaskAsynchronously(this, new Runnable() { - @Override public void run() { final 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!!"); + ConsoleLogger.showError("您使用 SQLite 存储了超过 " + accounts + " 个账户, 为了获得更好的性能, 建议使用MySQL!!!"); } } }); } - if (Settings.isCachingEnabled) { database = new CacheDataSource(this, database); } else { @@ -610,16 +607,19 @@ public class AuthMe extends JavaPlugin { if (Settings.getDataSource == DataSource.DataSourceType.FILE) { final 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"); + ConsoleLogger.info("数据格式 FlatFile 已经过时并且被弃用..."); + ConsoleLogger.info("下一次启动服务器, 数据格式将被转换为 SQLite..."); + ConsoleLogger.info("转换过程将会在后台异步进行..."); + ConsoleLogger.info("这不会影响您的服务器性能..."); + ConsoleLogger.info("如果你想继续使用 FlatFile 格式 请修改配置文件..."); + ConsoleLogger.info("但是下次重启 插件仍然会进行此操作..."); } } // Stop/unload the server/plugin as defined in the configuration public void stopOrUnload() { if (Settings.isStopEnabled) { - ConsoleLogger.showError("根据您的配置 服务器即将关闭..."); + ConsoleLogger.showError("插件载入发生错误 根据您的配置 服务器即将关闭..."); server.shutdown(); } else { server.getPluginManager().disablePlugin(AuthMe.getInstance()); @@ -713,7 +713,7 @@ public class AuthMe extends JavaPlugin { if (database.isAuthAvailable(name)) { if (PlayerCache.getInstance().isAuthenticated(name)) { final String email = database.getAuth(name).getEmail(); - if (email == null || email.isEmpty() || email.equalsIgnoreCase("mc@mc.com")) { + if (email == null || email.isEmpty() || email.equalsIgnoreCase("your@email.com")) { m.send(player, "add_email"); } } diff --git a/src/main/java/fr/xephi/authme/converter/CrazyLoginConverter.java b/src/main/java/fr/xephi/authme/converter/CrazyLoginConverter.java index bd60315..51dbde7 100644 --- a/src/main/java/fr/xephi/authme/converter/CrazyLoginConverter.java +++ b/src/main/java/fr/xephi/authme/converter/CrazyLoginConverter.java @@ -22,7 +22,7 @@ public class CrazyLoginConverter implements Converter { public AuthMe instance; public CommandSender sender; - public CrazyLoginConverter(AuthMe instance, CommandSender sender) { + public CrazyLoginConverter(final AuthMe instance, final CommandSender sender) { this.instance = instance; this.database = instance.database; this.sender = sender; @@ -34,35 +34,37 @@ public class CrazyLoginConverter implements Converter { @Override public void run() { - String fileName = Settings.crazyloginFileName; + final String fileName = Settings.crazyloginFileName; try { - File source = new File(AuthMe.getInstance().getDataFolder() + File.separator + fileName); + final File source = new File(AuthMe.getInstance().getDataFolder() + File.separator + fileName); if (!source.exists()) { - sender.sendMessage("Error while trying to import datas, please put " + fileName + " in AuthMe folder!"); + sender.sendMessage("转换 CrazyLogin 数据时发生错误, 请把文件 " + fileName + " 放在 plugin/AuthMe 文件夹!"); return; } String line; - BufferedReader users = new BufferedReader(new FileReader(source)); + final BufferedReader users = new BufferedReader(new FileReader(source)); while ((line = users.readLine()) != null) { if (line.contains("|")) { - String[] args = line.split("\\|"); - if (args.length < 2) + final String[] args = line.split("\\|"); + if (args.length < 2) { continue; - if (args[0].equalsIgnoreCase("name")) + } + if (args[0].equalsIgnoreCase("name")) { continue; - String playerName = args[0].toLowerCase(); - String psw = args[1]; + } + final String playerName = args[0].toLowerCase(); + final String psw = args[1]; if (psw != null) { - PlayerAuth auth = new PlayerAuth(playerName, psw, "127.0.0.1", System.currentTimeMillis(), playerName); + final PlayerAuth auth = new PlayerAuth(playerName, psw, "127.0.0.1", System.currentTimeMillis(), playerName); database.saveAuth(auth); } } } users.close(); - ConsoleLogger.info("CrazyLogin database has been imported correctly"); - } catch (IOException ex) { + ConsoleLogger.info("CrazyLogin 数据导入完成..."); + } catch (final IOException ex) { ConsoleLogger.showError(ex.getMessage()); - ConsoleLogger.showError("Can't open the crazylogin database file! Does it exist?"); + ConsoleLogger.showError("转换 CrazyLogin 数据时发生错误, 请确认文件是否正确..."); } } diff --git a/src/main/java/fr/xephi/authme/converter/ForceFlatToSqlite.java b/src/main/java/fr/xephi/authme/converter/ForceFlatToSqlite.java index ee10cad..aab8532 100644 --- a/src/main/java/fr/xephi/authme/converter/ForceFlatToSqlite.java +++ b/src/main/java/fr/xephi/authme/converter/ForceFlatToSqlite.java @@ -9,9 +9,9 @@ import fr.xephi.authme.settings.Settings; public class ForceFlatToSqlite implements Converter { - private DataSource data; + private final DataSource data; - public ForceFlatToSqlite(DataSource data, AuthMe plugin) { + public ForceFlatToSqlite(final DataSource data, final AuthMe plugin) { this.data = data; } @@ -20,17 +20,18 @@ public class ForceFlatToSqlite implements Converter { DataSource sqlite = null; try { sqlite = new SQLite(); - for (PlayerAuth auth : data.getAllAuths()) { + for (final PlayerAuth auth : data.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 ..."); + ConsoleLogger.info("数据库已成功转换为 sqlite !"); + } catch (final Exception e) { + ConsoleLogger.showError("一个错误发生了 当尝试将数据从 flatfile 转换为时 sqlite ..."); } finally { - if (sqlite != null) + if (sqlite != null) { sqlite.close(); + } } } } diff --git a/src/main/java/fr/xephi/authme/datasource/SQLite.java b/src/main/java/fr/xephi/authme/datasource/SQLite.java index 817e654..bc95a9e 100644 --- a/src/main/java/fr/xephi/authme/datasource/SQLite.java +++ b/src/main/java/fr/xephi/authme/datasource/SQLite.java @@ -15,23 +15,23 @@ import fr.xephi.authme.settings.Settings; public class SQLite implements DataSource { - private String columnEmail; - private String columnGroup; - private String columnID; - private String columnIp; - private String columnLastLogin; - private String columnLogged; - private String columnName; - private String columnPassword; - private String columnRealName; - private String columnSalt; + private final String columnEmail; + private final String columnGroup; + private final String columnID; + private final String columnIp; + private final String columnLastLogin; + private final String columnLogged; + private final String columnName; + private final String columnPassword; + private final String columnRealName; + private final String columnSalt; private Connection con; - private String database; - private String lastlocWorld; - private String lastlocX; - private String lastlocY; - private String lastlocZ; - private String tableName; + private final String database; + private final String lastlocWorld; + private final String lastlocX; + private final String lastlocY; + private final String lastlocZ; + private final String tableName; public SQLite() throws ClassNotFoundException, SQLException { this.database = Settings.getMySQLDatabase; @@ -55,16 +55,16 @@ public class SQLite implements DataSource { this.connect(); this.setup(); } catch (ClassNotFoundException | SQLException cnf) { - ConsoleLogger.showError("Can't use SQLITE... !"); + ConsoleLogger.showError("无法使用 SQLite 保存用户数据... !"); throw cnf; } } @Override - public List autoPurgeDatabase(long until) { + public List autoPurgeDatabase(final long until) { PreparedStatement pst = null; ResultSet rs = null; - List list = new ArrayList<>(); + final List list = new ArrayList<>(); try { pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnLastLogin + "(); } finally { @@ -86,7 +86,7 @@ public class SQLite implements DataSource { public synchronized void close() { try { con.close(); - } catch (SQLException ex) { + } catch (final SQLException ex) { ConsoleLogger.showError(ex.getMessage()); } } @@ -102,7 +102,7 @@ public class SQLite implements DataSource { if (rs != null && rs.next()) { result = rs.getInt(1); } - } catch (SQLException ex) { + } catch (final SQLException ex) { ConsoleLogger.showError(ex.getMessage()); return result; } finally { @@ -113,7 +113,7 @@ public class SQLite implements DataSource { @Override public List getAllAuths() { - List auths = new ArrayList<>(); + final List auths = new ArrayList<>(); PreparedStatement pst = null; ResultSet rs; try { @@ -136,7 +136,7 @@ public class SQLite implements DataSource { } auths.add(pAuth); } - } catch (SQLException ex) { + } catch (final SQLException ex) { ConsoleLogger.showError(ex.getMessage()); return auths; } finally { @@ -146,10 +146,10 @@ public class SQLite implements DataSource { } @Override - public List getAllAuthsByEmail(String email) { + public List getAllAuthsByEmail(final String email) { PreparedStatement pst = null; ResultSet rs = null; - List countEmail = new ArrayList<>(); + final List countEmail = new ArrayList<>(); try { pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnEmail + "=?;"); pst.setString(1, email); @@ -158,10 +158,10 @@ public class SQLite implements DataSource { countEmail.add(rs.getString(columnName)); } return countEmail; - } catch (SQLException ex) { + } catch (final SQLException ex) { ConsoleLogger.showError(ex.getMessage()); return new ArrayList<>(); - } catch (NullPointerException npe) { + } catch (final NullPointerException npe) { return new ArrayList<>(); } finally { close(rs); @@ -170,10 +170,10 @@ public class SQLite implements DataSource { } @Override - public List getAllAuthsByIp(String ip) { + public List getAllAuthsByIp(final String ip) { PreparedStatement pst = null; ResultSet rs = null; - List countIp = new ArrayList<>(); + final List countIp = new ArrayList<>(); try { pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnIp + "=?;"); pst.setString(1, ip); @@ -182,10 +182,10 @@ public class SQLite implements DataSource { countIp.add(rs.getString(columnName)); } return countIp; - } catch (SQLException ex) { + } catch (final SQLException ex) { ConsoleLogger.showError(ex.getMessage()); return new ArrayList<>(); - } catch (NullPointerException npe) { + } catch (final NullPointerException npe) { return new ArrayList<>(); } finally { close(rs); @@ -194,10 +194,10 @@ public class SQLite implements DataSource { } @Override - public List getAllAuthsByName(PlayerAuth auth) { + public List getAllAuthsByName(final PlayerAuth auth) { PreparedStatement pst = null; ResultSet rs = null; - List countIp = new ArrayList<>(); + final List countIp = new ArrayList<>(); try { pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnIp + "=?;"); pst.setString(1, auth.getIp()); @@ -206,10 +206,10 @@ public class SQLite implements DataSource { countIp.add(rs.getString(columnName)); } return countIp; - } catch (SQLException ex) { + } catch (final SQLException ex) { ConsoleLogger.showError(ex.getMessage()); return new ArrayList<>(); - } catch (NullPointerException npe) { + } catch (final NullPointerException npe) { return new ArrayList<>(); } finally { close(rs); @@ -218,7 +218,7 @@ public class SQLite implements DataSource { } @Override - public synchronized PlayerAuth getAuth(String user) { + public synchronized PlayerAuth getAuth(final String user) { PreparedStatement pst = null; ResultSet rs = null; try { @@ -242,7 +242,7 @@ public class SQLite implements DataSource { } else { return null; } - } catch (SQLException ex) { + } catch (final SQLException ex) { ConsoleLogger.showError(ex.getMessage()); return null; } finally { @@ -252,7 +252,7 @@ public class SQLite implements DataSource { } @Override - public int getIps(String ip) { + public int getIps(final String ip) { PreparedStatement pst = null; ResultSet rs = null; int countIp = 0; @@ -264,7 +264,7 @@ public class SQLite implements DataSource { countIp++; } return countIp; - } catch (SQLException ex) { + } catch (final SQLException ex) { ConsoleLogger.showError(ex.getMessage()); return 0; } finally { @@ -275,7 +275,7 @@ public class SQLite implements DataSource { @Override public List getLoggedPlayers() { - List auths = new ArrayList<>(); + final List auths = new ArrayList<>(); PreparedStatement pst = null; ResultSet rs; try { @@ -298,7 +298,7 @@ public class SQLite implements DataSource { } auths.add(pAuth); } - } catch (SQLException ex) { + } catch (final SQLException ex) { ConsoleLogger.showError(ex.getMessage()); return auths; } finally { @@ -313,7 +313,7 @@ public class SQLite implements DataSource { } @Override - public synchronized boolean isAuthAvailable(String user) { + public synchronized boolean isAuthAvailable(final String user) { PreparedStatement pst = null; ResultSet rs = null; try { @@ -321,7 +321,7 @@ public class SQLite implements DataSource { pst.setString(1, user); rs = pst.executeQuery(); return rs.next(); - } catch (SQLException ex) { + } catch (final SQLException ex) { ConsoleLogger.showError(ex.getMessage()); return false; } finally { @@ -331,16 +331,17 @@ public class SQLite implements DataSource { } @Override - public boolean isLogged(String user) { + public boolean isLogged(final String user) { PreparedStatement pst = null; ResultSet rs = null; try { pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE LOWER(" + columnName + ")=?;"); pst.setString(1, user); rs = pst.executeQuery(); - if (rs.next()) + if (rs.next()) { return (rs.getInt(columnLogged) == 1); - } catch (SQLException ex) { + } + } catch (final SQLException ex) { ConsoleLogger.showError(ex.getMessage()); return false; } finally { @@ -351,15 +352,15 @@ public class SQLite implements DataSource { } @Override - public void purgeBanned(List banned) { + public void purgeBanned(final List banned) { PreparedStatement pst = null; try { - for (String name : banned) { + for (final String name : banned) { pst = con.prepareStatement("DELETE FROM " + tableName + " WHERE " + columnName + "=?;"); pst.setString(1, name); pst.executeUpdate(); } - } catch (SQLException ex) { + } catch (final SQLException ex) { ConsoleLogger.showError(ex.getMessage()); } finally { close(pst); @@ -367,14 +368,14 @@ public class SQLite implements DataSource { } @Override - public int purgeDatabase(long until) { + public int purgeDatabase(final long until) { PreparedStatement pst = null; try { pst = con.prepareStatement("DELETE FROM " + tableName + " WHERE " + columnLastLogin + " classe; - HashAlgorithm(Class classe) { + HashAlgorithm(final Class classe) { this.classe = classe; } diff --git a/src/main/java/fr/xephi/authme/settings/CustomConfiguration.java b/src/main/java/fr/xephi/authme/settings/CustomConfiguration.java index 815fdd3..7976cde 100644 --- a/src/main/java/fr/xephi/authme/settings/CustomConfiguration.java +++ b/src/main/java/fr/xephi/authme/settings/CustomConfiguration.java @@ -15,9 +15,9 @@ import fr.xephi.authme.ConsoleLogger; public class CustomConfiguration extends YamlConfiguration { - private File configFile; + private final File configFile; - public CustomConfiguration(File file) { + public CustomConfiguration(final File file) { this.configFile = file; load(); } @@ -29,32 +29,32 @@ public class CustomConfiguration extends YamlConfiguration { public void load() { try { super.load(configFile); - } catch (FileNotFoundException e) { - ConsoleLogger.showError("Could not find " + configFile.getName() + ", creating new one..."); + } catch (final FileNotFoundException e) { + ConsoleLogger.showError("未找到配置文件 " + configFile.getName() + ", 创建新文件..."); reLoad(); - } catch (IOException e) { - ConsoleLogger.showError("Could not load " + configFile.getName()); - } catch (InvalidConfigurationException e) { - ConsoleLogger.showError(configFile.getName() + " is no valid configuration file"); + } catch (final IOException e) { + ConsoleLogger.showError("无法载入配置文件 " + configFile.getName()); + } catch (final InvalidConfigurationException e) { + ConsoleLogger.showError(configFile.getName() + " 不是一个有效的配置文件"); } } - public boolean loadResource(File file) { + public boolean loadResource(final File file) { if (!file.exists()) { try { if (!file.getParentFile().exists() && !file.getParentFile().mkdirs()) { return false; } - int i = file.getPath().indexOf("AuthMe"); + final int i = file.getPath().indexOf("AuthMe"); if (i > -1) { - String path = file.getPath().substring(i + 6).replace('\\', '/'); - InputStream is = AuthMe.class.getResourceAsStream(path); + final String path = file.getPath().substring(i + 6).replace('\\', '/'); + final InputStream is = AuthMe.class.getResourceAsStream(path); Files.copy(is, file.toPath(), StandardCopyOption.REPLACE_EXISTING); return true; } - } catch (Exception e) { + } catch (final Exception e) { ConsoleLogger.writeStackTrace(e); - ConsoleLogger.showError("Failed to load config from JAR"); + ConsoleLogger.showError("从 JAR 载入配置文件失败..."); } } return false; @@ -65,16 +65,17 @@ public class CustomConfiguration extends YamlConfiguration { if (!configFile.exists()) { out = loadResource(configFile); } - if (out) + if (out) { load(); + } return out; } public void save() { try { super.save(configFile); - } catch (IOException ex) { - ConsoleLogger.showError("Could not save config to " + configFile.getName()); + } catch (final IOException ex) { + ConsoleLogger.showError("无法保存配置文件 " + configFile.getName()); } } } diff --git a/src/main/java/fr/xephi/authme/settings/Settings.java b/src/main/java/fr/xephi/authme/settings/Settings.java index 3359a82..48aaa75 100644 --- a/src/main/java/fr/xephi/authme/settings/Settings.java +++ b/src/main/java/fr/xephi/authme/settings/Settings.java @@ -122,7 +122,7 @@ public final class Settings extends YamlConfiguration { if (!email.contains("@")) { return false; } - if (email.equalsIgnoreCase("mc@mc.com")) { + if (email.equalsIgnoreCase("your@email.com")) { return false; } final String emailDomain = email.split("@")[1];