From 66117b6cb0b5ddebd8d0a062cc5964df12ec38c8 Mon Sep 17 00:00:00 2001 From: 502647092 Date: Wed, 28 Oct 2015 20:18:11 +0800 Subject: [PATCH] clean up UUID and fix Message Error... Signed-off-by: 502647092 --- .classpath | 47 +-- pom.xml | 147 +-------- src/main/java/fr/xephi/authme/AuthMe.java | 2 +- src/main/java/fr/xephi/authme/Utils.java | 2 +- .../xephi/authme/cache/backup/JsonCache.java | 37 ++- .../fr/xephi/authme/datasource/FlatFile.java | 262 +++++++-------- .../fr/xephi/authme/datasource/MySQL.java | 301 +++++++++--------- .../fr/xephi/authme/datasource/SQLite.java | 2 +- .../authme/datasource/SQLite_HIKARI.java | 212 ++++++------ .../authme/process/join/AsyncronousJoin.java | 95 +++--- .../process/login/AsyncronousLogin.java | 79 +++-- .../process/register/AsyncronousRegister.java | 8 +- .../fr/xephi/authme/settings/Messages.java | 41 +-- .../xephi/authme/settings/OtherAccounts.java | 40 +-- .../fr/xephi/authme/settings/Settings.java | 212 ++++++------ src/main/resources/messages_zhcn.yml | Bin 4288 -> 3481 bytes 16 files changed, 677 insertions(+), 810 deletions(-) diff --git a/.classpath b/.classpath index 96f45ce..2c705bb 100644 --- a/.classpath +++ b/.classpath @@ -1,31 +1,16 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + diff --git a/pom.xml b/pom.xml index 22b94ea..5764790 100644 --- a/pom.xml +++ b/pom.xml @@ -48,6 +48,8 @@ 1.7 + http://ci.citycraft.cn:8080 + 测试版本发布... 1.8.8-R0.1-SNAPSHOT @@ -98,10 +100,12 @@ cn.citycraft:PluginHelper - - cn.citycraft.PluginHelper - ${project.groupId}.${project.artifactId} - + + + cn.citycraft.PluginHelper + ${project.groupId}.${project.artifactId} + + @@ -116,43 +120,15 @@ - spigot-repo http://hub.spigotmc.org/nexus/content/groups/public - - - - - - - - - - - - - - - - - - - - - - - + + citycraft-repo + ${jenkins.url}/plugin/repository/everything/ + @@ -211,104 +187,5 @@ system ${project.basedir}/lib/ProtocolLib-3.6.5-SNAPSHOT.jar - - - - - diff --git a/src/main/java/fr/xephi/authme/AuthMe.java b/src/main/java/fr/xephi/authme/AuthMe.java index f46751c..104fa7f 100644 --- a/src/main/java/fr/xephi/authme/AuthMe.java +++ b/src/main/java/fr/xephi/authme/AuthMe.java @@ -163,7 +163,7 @@ public class AuthMe extends JavaPlugin { final RegisteredServiceProvider permissionProvider = server.getServicesManager().getRegistration(net.milkbowl.vault.permission.Permission.class); if (permissionProvider != null) { permission = permissionProvider.getProvider(); - ConsoleLogger.info("发现 Vault 使用经济系统: " + permission.getName()); + ConsoleLogger.info("发现 Vault 使用权限系统: " + permission.getName()); } else { ConsoleLogger.showError("发现 Vault, 但是 Vault 未找到权限系统..."); } diff --git a/src/main/java/fr/xephi/authme/Utils.java b/src/main/java/fr/xephi/authme/Utils.java index 4c270c6..4caee45 100644 --- a/src/main/java/fr/xephi/authme/Utils.java +++ b/src/main/java/fr/xephi/authme/Utils.java @@ -89,7 +89,7 @@ public class Utils { if (lookupService != null) { return true; } - ConsoleLogger.info("[LICENSE] IP数据来自 CityCraft 的 Yum 源 原始数据来自 http://www.maxmind.com"); + ConsoleLogger.info("从 CityCraft 的 Yum 源 下载IP缓存库..."); final File file = new File(Settings.APLUGIN_FOLDER, "GeoIP.dat"); try { if (file.exists()) { diff --git a/src/main/java/fr/xephi/authme/cache/backup/JsonCache.java b/src/main/java/fr/xephi/authme/cache/backup/JsonCache.java index be49155..eb1a0fb 100644 --- a/src/main/java/fr/xephi/authme/cache/backup/JsonCache.java +++ b/src/main/java/fr/xephi/authme/cache/backup/JsonCache.java @@ -30,7 +30,7 @@ public class JsonCache { public JsonCache() { cacheDir = Settings.CACHE_FOLDER; if (!cacheDir.exists() && !cacheDir.isDirectory() && !cacheDir.mkdir()) { - ConsoleLogger.showError("Failed to create cache directory."); + ConsoleLogger.showError("创建缓存目录失败."); } gson = new GsonBuilder() .registerTypeAdapter(DataFileCache.class, new PlayerDataSerializer()) @@ -39,7 +39,7 @@ public class JsonCache { .create(); } - public void createCache(Player player, DataFileCache playerData) { + public void createCache(final Player player, final DataFileCache playerData) { if (player == null) { return; } @@ -51,7 +51,7 @@ public class JsonCache { path = player.getName().toLowerCase(); } - File file = new File(cacheDir, path + File.separator + "cache.json"); + final File file = new File(cacheDir, path + File.separator + "cache.json"); if (file.exists()) { return; } @@ -60,26 +60,26 @@ public class JsonCache { } try { - String data = gson.toJson(playerData); + final String data = gson.toJson(playerData); Files.touch(file); Files.write(data, file, Charsets.UTF_8); - } catch (IOException e) { + } catch (final IOException e) { e.printStackTrace(); } } - public boolean doesCacheExist(Player player) { + public boolean doesCacheExist(final Player player) { String path; try { path = player.getUniqueId().toString(); } catch (Exception | Error e) { path = player.getName().toLowerCase(); } - File file = new File(cacheDir, path + File.separator + "cache.json"); + final File file = new File(cacheDir, path + File.separator + "cache.json"); return file.exists(); } - public DataFileCache readCache(Player player) { + public DataFileCache readCache(final Player player) { String path; try { path = player.getUniqueId().toString(); @@ -87,40 +87,40 @@ public class JsonCache { path = player.getName().toLowerCase(); } - File file = new File(cacheDir, path + File.separator + "cache.json"); + final File file = new File(cacheDir, path + File.separator + "cache.json"); if (!file.exists()) { return null; } try { - String str = Files.toString(file, Charsets.UTF_8); + final String str = Files.toString(file, Charsets.UTF_8); return gson.fromJson(str, DataFileCache.class); - } catch (Exception e) { + } catch (final Exception e) { e.printStackTrace(); return null; } } - public void removeCache(Player player) { + public void removeCache(final Player player) { String path; try { path = player.getUniqueId().toString(); } catch (Exception | Error e) { path = player.getName().toLowerCase(); } - File file = new File(cacheDir, path); + final File file = new File(cacheDir, path); if (file.exists()) { Utils.purgeDirectory(file); if (!file.delete()) { - ConsoleLogger.showError("Failed to remove" + player.getName() + "cache."); + ConsoleLogger.showError("移除玩家 " + player.getName() + " 缓存数据失败."); } } } private static class PlayerDataDeserializer implements JsonDeserializer { @Override - public DataFileCache deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException { - JsonObject jsonObject = jsonElement.getAsJsonObject(); + public DataFileCache deserialize(final JsonElement jsonElement, final Type type, final JsonDeserializationContext jsonDeserializationContext) throws JsonParseException { + final JsonObject jsonObject = jsonElement.getAsJsonObject(); if (jsonObject == null) { return null; } @@ -145,12 +145,11 @@ public class JsonCache { private class PlayerDataSerializer implements JsonSerializer { @Override - public JsonElement serialize(DataFileCache dataFileCache, Type type, JsonSerializationContext jsonSerializationContext) { - JsonObject jsonObject = new JsonObject(); + public JsonElement serialize(final DataFileCache dataFileCache, final Type type, final JsonSerializationContext jsonSerializationContext) { + final JsonObject jsonObject = new JsonObject(); jsonObject.addProperty("group", dataFileCache.getGroup()); jsonObject.addProperty("operator", dataFileCache.getOperator()); jsonObject.addProperty("flying", dataFileCache.isFlying()); - return jsonObject; } } diff --git a/src/main/java/fr/xephi/authme/datasource/FlatFile.java b/src/main/java/fr/xephi/authme/datasource/FlatFile.java index 4945d9a..8662d4f 100644 --- a/src/main/java/fr/xephi/authme/datasource/FlatFile.java +++ b/src/main/java/fr/xephi/authme/datasource/FlatFile.java @@ -29,16 +29,16 @@ public class FlatFile implements DataSource { * :LASTPOSZ:LASTPOSWORLD PLAYERNAME:HASHSUM:IP:LOGININMILLIESECONDS * PLAYERNAME:HASHSUM:IP PLAYERNAME:HASHSUM */ - private File source; + private final File source; public FlatFile() { source = Settings.AUTH_FILE; try { source.createNewFile(); - } catch (IOException e) { + } catch (final IOException e) { ConsoleLogger.showError(e.getMessage()); if (Settings.isStopEnabled) { - ConsoleLogger.showError("Can't use FLAT FILE... SHUTDOWN..."); + ConsoleLogger.showError("无法读取用户数据文件... 关闭服务器..."); AuthMe.getInstance().getServer().shutdown(); } if (!Settings.isStopEnabled) { @@ -49,16 +49,16 @@ public class FlatFile implements DataSource { } @Override - public List autoPurgeDatabase(long until) { + public List autoPurgeDatabase(final long until) { BufferedReader br = null; BufferedWriter bw = null; - ArrayList lines = new ArrayList<>(); - List cleared = new ArrayList<>(); + final ArrayList lines = new ArrayList<>(); + final List cleared = new ArrayList<>(); try { br = new BufferedReader(new FileReader(source)); String line; while ((line = br.readLine()) != null) { - String[] args = line.split(":"); + final String[] args = line.split(":"); if (args.length >= 4) { if (Long.parseLong(args[3]) >= until) { lines.add(line); @@ -68,26 +68,26 @@ public class FlatFile implements DataSource { cleared.add(args[0]); } bw = new BufferedWriter(new FileWriter(source)); - for (String l : lines) { + for (final String l : lines) { bw.write(l + "\n"); } - } catch (FileNotFoundException ex) { + } catch (final FileNotFoundException ex) { ConsoleLogger.showError(ex.getMessage()); return cleared; - } catch (IOException ex) { + } catch (final IOException ex) { ConsoleLogger.showError(ex.getMessage()); return cleared; } finally { if (br != null) { try { br.close(); - } catch (IOException ex) { + } catch (final IOException ex) { } } if (bw != null) { try { bw.close(); - } catch (IOException ex) { + } catch (final IOException ex) { } } } @@ -107,14 +107,14 @@ public class FlatFile implements DataSource { while ((br.readLine()) != null) { result++; } - } catch (Exception ex) { + } catch (final Exception ex) { ConsoleLogger.showError(ex.getMessage()); return result; } finally { if (br != null) { try { br.close(); - } catch (IOException ex) { + } catch (final IOException ex) { } } } @@ -124,12 +124,12 @@ public class FlatFile implements DataSource { @Override public List getAllAuths() { BufferedReader br = null; - List auths = new ArrayList<>(); + final List auths = new ArrayList<>(); try { br = new BufferedReader(new FileReader(source)); String line; while ((line = br.readLine()) != null) { - String[] args = line.split(":"); + final String[] args = line.split(":"); switch (args.length) { case 2: auths.add(new PlayerAuth(args[0], args[1], "192.168.0.1", 0, "your@email.com", args[0])); @@ -141,30 +141,30 @@ public class FlatFile implements DataSource { auths.add(new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3]), "your@email.com", args[0])); break; case 7: - auths.add(new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]), - "unavailableworld", "your@email.com", args[0])); + auths.add(new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double + .parseDouble(args[6]), "unavailableworld", "your@email.com", args[0])); break; case 8: - auths.add(new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]), args[7], - "your@email.com", args[0])); + auths.add(new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double + .parseDouble(args[6]), args[7], "your@email.com", args[0])); break; case 9: - auths.add(new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]), args[7], - args[8], args[0])); + auths.add(new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double + .parseDouble(args[6]), args[7], args[8], args[0])); break; } } - } catch (FileNotFoundException ex) { + } catch (final FileNotFoundException ex) { ConsoleLogger.showError(ex.getMessage()); return auths; - } catch (IOException ex) { + } catch (final IOException ex) { ConsoleLogger.showError(ex.getMessage()); return auths; } finally { if (br != null) { try { br.close(); - } catch (IOException ex) { + } catch (final IOException ex) { } } } @@ -172,103 +172,103 @@ public class FlatFile implements DataSource { } @Override - public List getAllAuthsByEmail(String email) { + public List getAllAuthsByEmail(final String email) { BufferedReader br = null; - List countEmail = new ArrayList<>(); + final List countEmail = new ArrayList<>(); try { br = new BufferedReader(new FileReader(source)); String line; while ((line = br.readLine()) != null) { - String[] args = line.split(":"); + final String[] args = line.split(":"); if (args.length > 8 && args[8].equals(email)) { countEmail.add(args[0]); } } return countEmail; - } catch (FileNotFoundException ex) { + } catch (final FileNotFoundException ex) { ConsoleLogger.showError(ex.getMessage()); return new ArrayList<>(); - } catch (IOException ex) { + } catch (final IOException ex) { ConsoleLogger.showError(ex.getMessage()); return new ArrayList<>(); } finally { if (br != null) { try { br.close(); - } catch (IOException ex) { + } catch (final IOException ex) { } } } } @Override - public List getAllAuthsByIp(String ip) { + public List getAllAuthsByIp(final String ip) { BufferedReader br = null; - List countIp = new ArrayList<>(); + final List countIp = new ArrayList<>(); try { br = new BufferedReader(new FileReader(source)); String line; while ((line = br.readLine()) != null) { - String[] args = line.split(":"); + final String[] args = line.split(":"); if (args.length > 3 && args[2].equals(ip)) { countIp.add(args[0]); } } return countIp; - } catch (FileNotFoundException ex) { + } catch (final FileNotFoundException ex) { ConsoleLogger.showError(ex.getMessage()); return new ArrayList<>(); - } catch (IOException ex) { + } catch (final IOException ex) { ConsoleLogger.showError(ex.getMessage()); return new ArrayList<>(); } finally { if (br != null) { try { br.close(); - } catch (IOException ex) { + } catch (final IOException ex) { } } } } @Override - public List getAllAuthsByName(PlayerAuth auth) { + public List getAllAuthsByName(final PlayerAuth auth) { BufferedReader br = null; - List countIp = new ArrayList<>(); + final List countIp = new ArrayList<>(); try { br = new BufferedReader(new FileReader(source)); String line; while ((line = br.readLine()) != null) { - String[] args = line.split(":"); + final String[] args = line.split(":"); if (args.length > 3 && args[2].equals(auth.getIp())) { countIp.add(args[0]); } } return countIp; - } catch (FileNotFoundException ex) { + } catch (final FileNotFoundException ex) { ConsoleLogger.showError(ex.getMessage()); return new ArrayList<>(); - } catch (IOException ex) { + } catch (final IOException ex) { ConsoleLogger.showError(ex.getMessage()); return new ArrayList<>(); } finally { if (br != null) { try { br.close(); - } catch (IOException ex) { + } catch (final IOException ex) { } } } } @Override - public synchronized PlayerAuth getAuth(String user) { + public synchronized PlayerAuth getAuth(final String user) { BufferedReader br = null; try { br = new BufferedReader(new FileReader(source)); String line; while ((line = br.readLine()) != null) { - String[] args = line.split(":"); + final String[] args = line.split(":"); if (args[0].equalsIgnoreCase(user)) { switch (args.length) { case 2: @@ -278,28 +278,28 @@ public class FlatFile implements DataSource { case 4: return new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3]), "your@email.com", args[0]); case 7: - return new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]), - "unavailableworld", "your@email.com", args[0]); + return new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double + .parseDouble(args[6]), "unavailableworld", "your@email.com", args[0]); case 8: - return new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]), args[7], - "your@email.com", args[0]); + return new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double + .parseDouble(args[6]), args[7], "your@email.com", args[0]); case 9: - return new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]), args[7], - args[8], args[0]); + return new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double + .parseDouble(args[6]), args[7], args[8], args[0]); } } } - } catch (FileNotFoundException ex) { + } catch (final FileNotFoundException ex) { ConsoleLogger.showError(ex.getMessage()); return null; - } catch (IOException ex) { + } catch (final IOException ex) { ConsoleLogger.showError(ex.getMessage()); return null; } finally { if (br != null) { try { br.close(); - } catch (IOException ex) { + } catch (final IOException ex) { } } } @@ -307,30 +307,30 @@ public class FlatFile implements DataSource { } @Override - public int getIps(String ip) { + public int getIps(final String ip) { BufferedReader br = null; int countIp = 0; try { br = new BufferedReader(new FileReader(source)); String line; while ((line = br.readLine()) != null) { - String[] args = line.split(":"); + final String[] args = line.split(":"); if (args.length > 3 && args[2].equals(ip)) { countIp++; } } return countIp; - } catch (FileNotFoundException ex) { + } catch (final FileNotFoundException ex) { ConsoleLogger.showError(ex.getMessage()); return 0; - } catch (IOException ex) { + } catch (final IOException ex) { ConsoleLogger.showError(ex.getMessage()); return 0; } finally { if (br != null) { try { br.close(); - } catch (IOException ex) { + } catch (final IOException ex) { } } } @@ -347,28 +347,28 @@ public class FlatFile implements DataSource { } @Override - public synchronized boolean isAuthAvailable(String user) { + public synchronized boolean isAuthAvailable(final String user) { BufferedReader br = null; try { br = new BufferedReader(new FileReader(source)); String line; while ((line = br.readLine()) != null) { - String[] args = line.split(":"); + final String[] args = line.split(":"); if (args.length > 1 && args[0].equalsIgnoreCase(user)) { return true; } } - } catch (FileNotFoundException ex) { + } catch (final FileNotFoundException ex) { ConsoleLogger.showError(ex.getMessage()); return false; - } catch (IOException ex) { + } catch (final IOException ex) { ConsoleLogger.showError(ex.getMessage()); return false; } finally { if (br != null) { try { br.close(); - } catch (IOException ex) { + } catch (final IOException ex) { } } } @@ -376,20 +376,20 @@ public class FlatFile implements DataSource { } @Override - public boolean isLogged(String user) { + public boolean isLogged(final String user) { return PlayerCache.getInstance().isAuthenticated(user); } @Override - public void purgeBanned(List banned) { + public void purgeBanned(final List banned) { BufferedReader br = null; BufferedWriter bw = null; - ArrayList lines = new ArrayList<>(); + final ArrayList lines = new ArrayList<>(); try { br = new BufferedReader(new FileReader(source)); String line; while ((line = br.readLine()) != null) { - String[] args = line.split(":"); + final String[] args = line.split(":"); try { if (banned.contains(args[0])) { lines.add(line); @@ -398,26 +398,26 @@ public class FlatFile implements DataSource { } } bw = new BufferedWriter(new FileWriter(source)); - for (String l : lines) { + for (final String l : lines) { bw.write(l + "\n"); } - } catch (FileNotFoundException ex) { + } catch (final FileNotFoundException ex) { ConsoleLogger.showError(ex.getMessage()); return; - } catch (IOException ex) { + } catch (final IOException ex) { ConsoleLogger.showError(ex.getMessage()); return; } finally { if (br != null) { try { br.close(); - } catch (IOException ex) { + } catch (final IOException ex) { } } if (bw != null) { try { bw.close(); - } catch (IOException ex) { + } catch (final IOException ex) { } } } @@ -425,16 +425,16 @@ public class FlatFile implements DataSource { } @Override - public int purgeDatabase(long until) { + public int purgeDatabase(final long until) { BufferedReader br = null; BufferedWriter bw = null; - ArrayList lines = new ArrayList<>(); + final ArrayList lines = new ArrayList<>(); int cleared = 0; try { br = new BufferedReader(new FileReader(source)); String line; while ((line = br.readLine()) != null) { - String[] args = line.split(":"); + final String[] args = line.split(":"); if (args.length >= 4) { if (Long.parseLong(args[3]) >= until) { lines.add(line); @@ -444,26 +444,26 @@ public class FlatFile implements DataSource { cleared++; } bw = new BufferedWriter(new FileWriter(source)); - for (String l : lines) { + for (final String l : lines) { bw.write(l + "\n"); } - } catch (FileNotFoundException ex) { + } catch (final FileNotFoundException ex) { ConsoleLogger.showError(ex.getMessage()); return cleared; - } catch (IOException ex) { + } catch (final IOException ex) { ConsoleLogger.showError(ex.getMessage()); return cleared; } finally { if (br != null) { try { br.close(); - } catch (IOException ex) { + } catch (final IOException ex) { } } if (bw != null) { try { bw.close(); - } catch (IOException ex) { + } catch (final IOException ex) { } } } @@ -479,43 +479,43 @@ public class FlatFile implements DataSource { } @Override - public synchronized boolean removeAuth(String user) { + public synchronized boolean removeAuth(final String user) { if (!isAuthAvailable(user)) { return false; } BufferedReader br = null; BufferedWriter bw = null; - ArrayList lines = new ArrayList<>(); + final ArrayList lines = new ArrayList<>(); try { br = new BufferedReader(new FileReader(source)); String line; while ((line = br.readLine()) != null) { - String[] args = line.split(":"); + final String[] args = line.split(":"); if (args.length > 1 && !args[0].equals(user)) { lines.add(line); } } bw = new BufferedWriter(new FileWriter(source)); - for (String l : lines) { + for (final String l : lines) { bw.write(l + "\n"); } - } catch (FileNotFoundException ex) { + } catch (final FileNotFoundException ex) { ConsoleLogger.showError(ex.getMessage()); return false; - } catch (IOException ex) { + } catch (final IOException ex) { ConsoleLogger.showError(ex.getMessage()); return false; } finally { if (br != null) { try { br.close(); - } catch (IOException ex) { + } catch (final IOException ex) { } } if (bw != null) { try { bw.close(); - } catch (IOException ex) { + } catch (final IOException ex) { } } } @@ -523,7 +523,7 @@ public class FlatFile implements DataSource { } @Override - public synchronized boolean saveAuth(PlayerAuth auth) { + public synchronized boolean saveAuth(final PlayerAuth auth) { if (isAuthAvailable(auth.getNickname())) { return false; } @@ -532,14 +532,14 @@ public class FlatFile implements DataSource { bw = new BufferedWriter(new FileWriter(source, true)); bw.write(auth.getNickname() + ":" + auth.getHash() + ":" + auth.getIp() + ":" + auth.getLastLogin() + ":" + auth.getQuitLocX() + ":" + auth.getQuitLocY() + ":" + auth.getQuitLocZ() + ":" + auth.getWorld() + ":" + auth.getEmail() + "\n"); - } catch (IOException ex) { + } catch (final IOException ex) { ConsoleLogger.showError(ex.getMessage()); return false; } finally { if (bw != null) { try { bw.close(); - } catch (IOException ex) { + } catch (final IOException ex) { } } } @@ -547,15 +547,15 @@ public class FlatFile implements DataSource { } @Override - public void setLogged(String user) { + public void setLogged(final String user) { } @Override - public void setUnlogged(String user) { + public void setUnlogged(final String user) { } @Override - public boolean updateEmail(PlayerAuth auth) { + public boolean updateEmail(final PlayerAuth auth) { if (!isAuthAvailable(auth.getNickname())) { return false; } @@ -565,24 +565,24 @@ public class FlatFile implements DataSource { br = new BufferedReader(new FileReader(source)); String line = ""; while ((line = br.readLine()) != null) { - String[] args = line.split(":"); + final String[] args = line.split(":"); if (args[0].equals(auth.getNickname())) { - newAuth = new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]), args[7], - auth.getEmail(), args[0]); + newAuth = new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]), args[7], auth + .getEmail(), args[0]); break; } } - } catch (FileNotFoundException ex) { + } catch (final FileNotFoundException ex) { ConsoleLogger.showError(ex.getMessage()); return false; - } catch (IOException ex) { + } catch (final IOException ex) { ConsoleLogger.showError(ex.getMessage()); return false; } finally { if (br != null) { try { br.close(); - } catch (IOException ex) { + } catch (final IOException ex) { } } } @@ -594,15 +594,15 @@ public class FlatFile implements DataSource { } @Override - public void updateName(String oldone, String newone) { - PlayerAuth auth = this.getAuth(oldone); + public void updateName(final String oldone, final String newone) { + final PlayerAuth auth = this.getAuth(oldone); auth.setName(newone); this.saveAuth(auth); this.removeAuth(oldone); } @Override - public synchronized boolean updatePassword(PlayerAuth auth) { + public synchronized boolean updatePassword(final PlayerAuth auth) { if (!isAuthAvailable(auth.getNickname())) { return false; } @@ -612,7 +612,7 @@ public class FlatFile implements DataSource { br = new BufferedReader(new FileReader(source)); String line; while ((line = br.readLine()) != null) { - String[] args = line.split(":"); + final String[] args = line.split(":"); if (args[0].equals(auth.getNickname())) { switch (args.length) { case 4: { @@ -620,18 +620,18 @@ public class FlatFile implements DataSource { break; } case 7: { - newAuth = new PlayerAuth(args[0], auth.getHash(), args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]), - "world", "your@email.com", args[0]); + newAuth = new PlayerAuth(args[0], auth.getHash(), args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double + .parseDouble(args[6]), "world", "your@email.com", args[0]); break; } case 8: { - newAuth = new PlayerAuth(args[0], auth.getHash(), args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]), - args[7], "your@email.com", args[0]); + newAuth = new PlayerAuth(args[0], auth.getHash(), args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double + .parseDouble(args[6]), args[7], "your@email.com", args[0]); break; } case 9: { - newAuth = new PlayerAuth(args[0], auth.getHash(), args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]), - args[7], args[8], args[0]); + newAuth = new PlayerAuth(args[0], auth.getHash(), args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double + .parseDouble(args[6]), args[7], args[8], args[0]); break; } default: { @@ -642,17 +642,17 @@ public class FlatFile implements DataSource { break; } } - } catch (FileNotFoundException ex) { + } catch (final FileNotFoundException ex) { ConsoleLogger.showError(ex.getMessage()); return false; - } catch (IOException ex) { + } catch (final IOException ex) { ConsoleLogger.showError(ex.getMessage()); return false; } finally { if (br != null) { try { br.close(); - } catch (IOException ex) { + } catch (final IOException ex) { } } } @@ -664,7 +664,7 @@ public class FlatFile implements DataSource { } @Override - public boolean updateQuitLoc(PlayerAuth auth) { + public boolean updateQuitLoc(final PlayerAuth auth) { if (!isAuthAvailable(auth.getNickname())) { return false; } @@ -674,23 +674,23 @@ public class FlatFile implements DataSource { br = new BufferedReader(new FileReader(source)); String line; while ((line = br.readLine()) != null) { - String[] args = line.split(":"); + final String[] args = line.split(":"); if (args[0].equalsIgnoreCase(auth.getNickname())) { newAuth = new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3]), auth.getQuitLocX(), auth.getQuitLocY(), auth.getQuitLocZ(), auth.getWorld(), auth.getEmail(), args[0]); break; } } - } catch (FileNotFoundException ex) { + } catch (final FileNotFoundException ex) { ConsoleLogger.showError(ex.getMessage()); return false; - } catch (IOException ex) { + } catch (final IOException ex) { ConsoleLogger.showError(ex.getMessage()); return false; } finally { if (br != null) { try { br.close(); - } catch (IOException ex) { + } catch (final IOException ex) { } } } @@ -702,12 +702,12 @@ public class FlatFile implements DataSource { } @Override - public boolean updateSalt(PlayerAuth auth) { + public boolean updateSalt(final PlayerAuth auth) { return false; } @Override - public boolean updateSession(PlayerAuth auth) { + public boolean updateSession(final PlayerAuth auth) { if (!isAuthAvailable(auth.getNickname())) { return false; } @@ -717,7 +717,7 @@ public class FlatFile implements DataSource { br = new BufferedReader(new FileReader(source)); String line; while ((line = br.readLine()) != null) { - String[] args = line.split(":"); + final String[] args = line.split(":"); if (args[0].equalsIgnoreCase(auth.getNickname())) { switch (args.length) { case 4: { @@ -725,18 +725,18 @@ public class FlatFile implements DataSource { break; } case 7: { - newAuth = new PlayerAuth(args[0], args[1], auth.getIp(), auth.getLastLogin(), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]), "world", - "your@email.com", args[0]); + newAuth = new PlayerAuth(args[0], args[1], auth.getIp(), auth.getLastLogin(), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double + .parseDouble(args[6]), "world", "your@email.com", args[0]); break; } case 8: { - newAuth = new PlayerAuth(args[0], args[1], auth.getIp(), auth.getLastLogin(), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]), args[7], - "your@email.com", args[0]); + newAuth = new PlayerAuth(args[0], args[1], auth.getIp(), auth.getLastLogin(), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double + .parseDouble(args[6]), args[7], "your@email.com", args[0]); break; } case 9: { - newAuth = new PlayerAuth(args[0], args[1], auth.getIp(), auth.getLastLogin(), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]), args[7], - args[8], args[0]); + newAuth = new PlayerAuth(args[0], args[1], auth.getIp(), auth.getLastLogin(), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double + .parseDouble(args[6]), args[7], args[8], args[0]); break; } default: { @@ -747,17 +747,17 @@ public class FlatFile implements DataSource { break; } } - } catch (FileNotFoundException ex) { + } catch (final FileNotFoundException ex) { ConsoleLogger.showError(ex.getMessage()); return false; - } catch (IOException ex) { + } catch (final IOException ex) { ConsoleLogger.showError(ex.getMessage()); return false; } finally { if (br != null) { try { br.close(); - } catch (IOException ex) { + } catch (final IOException ex) { } } } diff --git a/src/main/java/fr/xephi/authme/datasource/MySQL.java b/src/main/java/fr/xephi/authme/datasource/MySQL.java index e5b3c51..f8b2b12 100644 --- a/src/main/java/fr/xephi/authme/datasource/MySQL.java +++ b/src/main/java/fr/xephi/authme/datasource/MySQL.java @@ -21,29 +21,29 @@ import fr.xephi.authme.settings.Settings; public class MySQL implements DataSource { - private String columnEmail; - private String columnGroup; - private String columnID; - private String columnIp; - private String columnLastLogin; - private String columnLogged; - private String columnName; - private List columnOthers; - private String columnPassword; - private String columnRealName; - private String columnSalt; - private String database; + 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 List columnOthers; + private final String columnPassword; + private final String columnRealName; + private final String columnSalt; + private final String database; private HikariDataSource ds; - private String host; - private String lastlocWorld; - private String lastlocX; - private String lastlocY; - private String lastlocZ; - private int maxConnections; - private String password; - private String port; - private String tableName; - private String username; + private final String host; + private final String lastlocWorld; + private final String lastlocX; + private final String lastlocY; + private final String lastlocZ; + private final int maxConnections; + private final String password; + private final String port; + private final String tableName; + private final String username; public MySQL() throws ClassNotFoundException, SQLException, PoolInitializationException { this.host = Settings.getMySQLHost; @@ -72,38 +72,34 @@ public class MySQL implements DataSource { // Set the connection arguments (and check if connection is ok) try { this.setConnectionArguments(); - } catch (RuntimeException e) { + } catch (final RuntimeException e) { if (e instanceof IllegalArgumentException) { - ConsoleLogger.showError("Invalid database arguments! Please check your configuration!"); - ConsoleLogger.showError("If this error persists, please report it to the developer! SHUTDOWN..."); - throw new IllegalArgumentException(e); + ConsoleLogger.showError("错误的数据库信息! 请检查您的配置是否正确!"); } if (e instanceof PoolInitializationException) { - ConsoleLogger.showError("Can't initialize database connection! Please check your configuration!"); - ConsoleLogger.showError("If this error persists, please report it to the developer! SHUTDOWN..."); - throw new PoolInitializationException(e); + ConsoleLogger.showError("无法初始化数据库连接池! 请检查您的配置是否正确!"); } - ConsoleLogger.showError("Can't use the Hikari Connection Pool! Please, report this error to the developer! SHUTDOWN..."); + ConsoleLogger.showError("MySQL数据库加载失败! 如果你认为配置文件没问题 请报告此错误给开发者! 关闭服务器..."); throw e; } // Initialize the database try { this.setupConnection(); - } catch (SQLException e) { + } catch (final SQLException e) { this.close(); - ConsoleLogger.showError("Can't initialize the MySQL database... Please check your database settings in the config.yml file! SHUTDOWN..."); - ConsoleLogger.showError("If this error persists, please report it to the developer! SHUTDOWN..."); + ConsoleLogger.showError("无法初始化 MySQL 数据库连接池... 请检查您的配置是否正确! 关闭服务器..."); + ConsoleLogger.showError("如果你认为配置文件没问题 请报告此错误给开发者! 关闭服务器..."); throw e; } } @Override - public synchronized List autoPurgeDatabase(long until) { + public synchronized List autoPurgeDatabase(final long until) { Connection con = null; PreparedStatement pst = null; ResultSet rs = null; - List list = new ArrayList<>(); + final List list = new ArrayList<>(); try { con = getConnection(); pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnLastLogin + "(); } finally { @@ -129,8 +125,9 @@ public class MySQL implements DataSource { @Override public synchronized void close() { - if (ds != null) + if (ds != null) { ds.close(); + } } @Override @@ -146,7 +143,7 @@ public class MySQL implements DataSource { if (rs != null && rs.next()) { result = rs.getInt(1); } - } catch (Exception ex) { + } catch (final Exception ex) { ConsoleLogger.showError(ex.getMessage()); return result; } finally { @@ -158,7 +155,7 @@ public class MySQL implements DataSource { @Override public List getAllAuths() { - List auths = new ArrayList<>(); + final List auths = new ArrayList<>(); Connection con = null; PreparedStatement pst = null; ResultSet rs = null; @@ -168,22 +165,23 @@ public class MySQL implements DataSource { rs = pst.executeQuery(); while (rs.next()) { PlayerAuth pAuth; - int id = rs.getInt(columnID); + final int id = rs.getInt(columnID); if (rs.getString(columnIp).isEmpty() && rs.getString(columnIp) != null) { - pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), "192.168.0.1", rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), - rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName)); + pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), "192.168.0.1", rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs + .getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName)); } else { if (!columnSalt.isEmpty()) { - if (!columnGroup.isEmpty()) - pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnSalt), rs.getInt(columnGroup), rs.getString(columnIp), - rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), - rs.getString(columnRealName)); - else - pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnSalt), rs.getString(columnIp), rs.getLong(columnLastLogin), - rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName)); + if (!columnGroup.isEmpty()) { + pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnSalt), rs.getInt(columnGroup), rs.getString(columnIp), rs + .getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs + .getString(columnRealName)); + } else { + pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnSalt), rs.getString(columnIp), rs.getLong(columnLastLogin), rs + .getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName)); + } } else { - pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnIp), rs.getLong(columnLastLogin), rs.getDouble(lastlocX), - rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName)); + pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnIp), rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs + .getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName)); } } if (Settings.getPasswordHash == HashAlgorithm.XENFORO) { @@ -192,15 +190,15 @@ public class MySQL implements DataSource { pst.setInt(1, id); rsid = pst.executeQuery(); if (rsid.next()) { - Blob blob = rsid.getBlob("data"); - byte[] bytes = blob.getBytes(1, (int) blob.length()); + final Blob blob = rsid.getBlob("data"); + final byte[] bytes = blob.getBytes(1, (int) blob.length()); pAuth.setHash(new String(bytes)); } rsid.close(); } auths.add(pAuth); } - } catch (Exception ex) { + } catch (final Exception ex) { ConsoleLogger.showError(ex.getMessage()); return auths; } finally { @@ -212,11 +210,11 @@ public class MySQL implements DataSource { } @Override - public synchronized List getAllAuthsByEmail(String email) { + public synchronized List getAllAuthsByEmail(final String email) { Connection con = null; PreparedStatement pst = null; ResultSet rs = null; - List countEmail = new ArrayList<>(); + final List countEmail = new ArrayList<>(); try { con = getConnection(); pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnEmail + "=?;"); @@ -226,7 +224,7 @@ public class MySQL implements DataSource { countEmail.add(rs.getString(columnName)); } return countEmail; - } catch (Exception ex) { + } catch (final Exception ex) { ConsoleLogger.showError(ex.getMessage()); return new ArrayList<>(); } finally { @@ -237,11 +235,11 @@ public class MySQL implements DataSource { } @Override - public synchronized List getAllAuthsByIp(String ip) { + public synchronized List getAllAuthsByIp(final String ip) { Connection con = null; PreparedStatement pst = null; ResultSet rs = null; - List countIp = new ArrayList<>(); + final List countIp = new ArrayList<>(); try { con = getConnection(); pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnIp + "=?;"); @@ -251,7 +249,7 @@ public class MySQL implements DataSource { countIp.add(rs.getString(columnName)); } return countIp; - } catch (Exception ex) { + } catch (final Exception ex) { ConsoleLogger.showError(ex.getMessage()); return new ArrayList<>(); } finally { @@ -262,11 +260,11 @@ public class MySQL implements DataSource { } @Override - public synchronized List getAllAuthsByName(PlayerAuth auth) { + public synchronized List getAllAuthsByName(final PlayerAuth auth) { Connection con = null; PreparedStatement pst = null; ResultSet rs = null; - List countIp = new ArrayList<>(); + final List countIp = new ArrayList<>(); try { con = getConnection(); pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnIp + "=?;"); @@ -276,7 +274,7 @@ public class MySQL implements DataSource { countIp.add(rs.getString(columnName)); } return countIp; - } catch (Exception ex) { + } catch (final Exception ex) { ConsoleLogger.showError(ex.getMessage()); return new ArrayList<>(); } finally { @@ -287,7 +285,7 @@ public class MySQL implements DataSource { } @Override - public synchronized PlayerAuth getAuth(String user) { + public synchronized PlayerAuth getAuth(final String user) { Connection con = null; PreparedStatement pst = null; ResultSet rs = null; @@ -301,20 +299,22 @@ public class MySQL implements DataSource { if (rs.next()) { id = rs.getInt(columnID); if (rs.getString(columnIp).isEmpty() && rs.getString(columnIp) != null) { - pAuth = new PlayerAuth(rs.getString(columnName).toLowerCase(), rs.getString(columnPassword), "192.168.0.1", rs.getLong(columnLastLogin), rs.getDouble(lastlocX), - rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName)); + pAuth = new PlayerAuth(rs.getString(columnName).toLowerCase(), rs.getString(columnPassword), "192.168.0.1", rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs + .getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName)); } else { if (!columnSalt.isEmpty()) { - if (!columnGroup.isEmpty()) - pAuth = new PlayerAuth(rs.getString(columnName).toLowerCase(), rs.getString(columnPassword), rs.getString(columnSalt), rs.getInt(columnGroup), rs.getString(columnIp), - rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), - rs.getString(columnRealName)); - else - pAuth = new PlayerAuth(rs.getString(columnName).toLowerCase(), rs.getString(columnPassword), rs.getString(columnSalt), rs.getString(columnIp), rs.getLong(columnLastLogin), - rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName)); + if (!columnGroup.isEmpty()) { + pAuth = new PlayerAuth(rs.getString(columnName).toLowerCase(), rs.getString(columnPassword), rs.getString(columnSalt), rs.getInt(columnGroup), rs.getString(columnIp), rs + .getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs + .getString(columnRealName)); + } else { + pAuth = new PlayerAuth(rs.getString(columnName).toLowerCase(), rs.getString(columnPassword), rs.getString(columnSalt), rs.getString(columnIp), rs + .getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs + .getString(columnRealName)); + } } else { - pAuth = new PlayerAuth(rs.getString(columnName).toLowerCase(), rs.getString(columnPassword), rs.getString(columnIp), rs.getLong(columnLastLogin), rs.getDouble(lastlocX), - rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName)); + pAuth = new PlayerAuth(rs.getString(columnName).toLowerCase(), rs.getString(columnPassword), rs.getString(columnIp), rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs + .getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName)); } } if (Settings.getPasswordHash == HashAlgorithm.XENFORO) { @@ -324,15 +324,15 @@ public class MySQL implements DataSource { pst.setInt(1, id); rs = pst.executeQuery(); if (rs.next()) { - Blob blob = rs.getBlob("data"); - byte[] bytes = blob.getBytes(1, (int) blob.length()); + final Blob blob = rs.getBlob("data"); + final byte[] bytes = blob.getBytes(1, (int) blob.length()); pAuth.setHash(new String(bytes)); } } } else { return null; } - } catch (Exception ex) { + } catch (final Exception ex) { ConsoleLogger.showError(ex.getMessage()); return null; } finally { @@ -344,7 +344,7 @@ public class MySQL implements DataSource { } @Override - public synchronized int getIps(String ip) { + public synchronized int getIps(final String ip) { Connection con = null; PreparedStatement pst = null; ResultSet rs = null; @@ -358,7 +358,7 @@ public class MySQL implements DataSource { countIp++; } return countIp; - } catch (Exception ex) { + } catch (final Exception ex) { ConsoleLogger.showError(ex.getMessage()); return 0; } finally { @@ -370,7 +370,7 @@ public class MySQL implements DataSource { @Override public List getLoggedPlayers() { - List auths = new ArrayList<>(); + final List auths = new ArrayList<>(); Connection con = null; PreparedStatement pst = null; ResultSet rs = null; @@ -380,22 +380,23 @@ public class MySQL implements DataSource { rs = pst.executeQuery(); while (rs.next()) { PlayerAuth pAuth; - int id = rs.getInt(columnID); + final int id = rs.getInt(columnID); if (rs.getString(columnIp).isEmpty() && rs.getString(columnIp) != null) { - pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), "192.168.0.1", rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), - rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName)); + pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), "192.168.0.1", rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs + .getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName)); } else { if (!columnSalt.isEmpty()) { - if (!columnGroup.isEmpty()) - pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnSalt), rs.getInt(columnGroup), rs.getString(columnIp), - rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), - rs.getString(columnRealName)); - else - pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnSalt), rs.getString(columnIp), rs.getLong(columnLastLogin), - rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName)); + if (!columnGroup.isEmpty()) { + pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnSalt), rs.getInt(columnGroup), rs.getString(columnIp), rs + .getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs + .getString(columnRealName)); + } else { + pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnSalt), rs.getString(columnIp), rs.getLong(columnLastLogin), rs + .getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName)); + } } else { - pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnIp), rs.getLong(columnLastLogin), rs.getDouble(lastlocX), - rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName)); + pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnIp), rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs + .getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName)); } } if (Settings.getPasswordHash == HashAlgorithm.XENFORO) { @@ -404,15 +405,15 @@ public class MySQL implements DataSource { pst.setInt(1, id); rsid = pst.executeQuery(); if (rsid.next()) { - Blob blob = rsid.getBlob("data"); - byte[] bytes = blob.getBytes(1, (int) blob.length()); + final Blob blob = rsid.getBlob("data"); + final byte[] bytes = blob.getBytes(1, (int) blob.length()); pAuth.setHash(new String(bytes)); } rsid.close(); } auths.add(pAuth); } - } catch (Exception ex) { + } catch (final Exception ex) { ConsoleLogger.showError(ex.getMessage()); return auths; } finally { @@ -429,7 +430,7 @@ public class MySQL implements DataSource { } @Override - public synchronized boolean isAuthAvailable(String user) { + public synchronized boolean isAuthAvailable(final String user) { Connection con = null; PreparedStatement pst = null; ResultSet rs = null; @@ -439,7 +440,7 @@ public class MySQL implements DataSource { pst.setString(1, user); rs = pst.executeQuery(); return rs.next(); - } catch (Exception ex) { + } catch (final Exception ex) { ConsoleLogger.showError(ex.getMessage()); return false; } finally { @@ -450,7 +451,7 @@ public class MySQL implements DataSource { } @Override - public boolean isLogged(String user) { + public boolean isLogged(final String user) { Connection con = null; PreparedStatement pst = null; ResultSet rs = null; @@ -459,9 +460,10 @@ public class MySQL implements DataSource { 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 (Exception ex) { + } + } catch (final Exception ex) { ConsoleLogger.showError(ex.getMessage()); return false; } finally { @@ -473,17 +475,17 @@ public class MySQL implements DataSource { } @Override - public synchronized void purgeBanned(List banned) { + public synchronized void purgeBanned(final List banned) { Connection con = null; PreparedStatement pst = null; try { - for (String name : banned) { + for (final String name : banned) { con = getConnection(); pst = con.prepareStatement("DELETE FROM " + tableName + " WHERE LOWER(" + columnName + ")=?;"); pst.setString(1, name); pst.executeUpdate(); } - } catch (Exception ex) { + } catch (final Exception ex) { ConsoleLogger.showError(ex.getMessage()); } finally { close(pst); @@ -492,7 +494,7 @@ public class MySQL implements DataSource { } @Override - public synchronized int purgeDatabase(long until) { + public synchronized int purgeDatabase(final long until) { Connection con = null; PreparedStatement pst = null; try { @@ -500,7 +502,7 @@ public class MySQL implements DataSource { pst = con.prepareStatement("DELETE FROM " + tableName + " WHERE " + columnLastLogin + " autoPurgeDatabase(long until) { + public List autoPurgeDatabase(final long until) { Connection con = null; PreparedStatement pst = null; ResultSet rs = null; - List list = new ArrayList<>(); + final List list = new ArrayList<>(); try { con = getConnection(); pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnLastLogin + "(); } finally { @@ -100,8 +100,9 @@ public class SQLite_HIKARI implements DataSource { @Override public synchronized void close() { - if (ds != null) + if (ds != null) { ds.close(); + } } @Override @@ -117,7 +118,7 @@ public class SQLite_HIKARI 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 { @@ -132,7 +133,7 @@ public class SQLite_HIKARI implements DataSource { Connection con = null; PreparedStatement pst = null; ResultSet rs; - List auths = new ArrayList<>(); + final List auths = new ArrayList<>(); try { con = getConnection(); pst = con.prepareStatement("SELECT * FROM " + tableName + ";"); @@ -140,21 +141,21 @@ public class SQLite_HIKARI implements DataSource { while (rs.next()) { PlayerAuth pAuth; if (rs.getString(columnIp).isEmpty()) { - pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), "127.0.0.1", rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), - rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName)); + pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), "127.0.0.1", rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs + .getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName)); } else { if (!columnSalt.isEmpty()) { - pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnSalt), rs.getInt(columnGroup), rs.getString(columnIp), - rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), - rs.getString(columnRealName)); + pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnSalt), rs.getInt(columnGroup), rs.getString(columnIp), rs + .getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs + .getString(columnRealName)); } else { - pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnIp), rs.getLong(columnLastLogin), rs.getDouble(lastlocX), - rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName)); + pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnIp), rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs + .getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName)); } } auths.add(pAuth); } - } catch (SQLException ex) { + } catch (final SQLException ex) { ConsoleLogger.showError(ex.getMessage()); return auths; } finally { @@ -165,11 +166,11 @@ public class SQLite_HIKARI implements DataSource { } @Override - public List getAllAuthsByEmail(String email) { + public List getAllAuthsByEmail(final String email) { Connection con = null; PreparedStatement pst = null; ResultSet rs = null; - List countEmail = new ArrayList<>(); + final List countEmail = new ArrayList<>(); try { con = getConnection(); pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnEmail + "=?;"); @@ -179,10 +180,10 @@ public class SQLite_HIKARI 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); @@ -192,11 +193,11 @@ public class SQLite_HIKARI implements DataSource { } @Override - public List getAllAuthsByIp(String ip) { + public List getAllAuthsByIp(final String ip) { Connection con = null; PreparedStatement pst = null; ResultSet rs = null; - List countIp = new ArrayList<>(); + final List countIp = new ArrayList<>(); try { con = getConnection(); pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnIp + "=?;"); @@ -206,10 +207,10 @@ public class SQLite_HIKARI 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); @@ -219,11 +220,11 @@ public class SQLite_HIKARI implements DataSource { } @Override - public List getAllAuthsByName(PlayerAuth auth) { + public List getAllAuthsByName(final PlayerAuth auth) { Connection con = null; PreparedStatement pst = null; ResultSet rs = null; - List countIp = new ArrayList<>(); + final List countIp = new ArrayList<>(); try { con = getConnection(); pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnIp + "=?;"); @@ -233,10 +234,10 @@ public class SQLite_HIKARI 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); @@ -246,7 +247,7 @@ public class SQLite_HIKARI implements DataSource { } @Override - public synchronized PlayerAuth getAuth(String user) { + public synchronized PlayerAuth getAuth(final String user) { Connection con = null; PreparedStatement pst = null; ResultSet rs = null; @@ -257,22 +258,22 @@ public class SQLite_HIKARI implements DataSource { rs = pst.executeQuery(); if (rs.next()) { if (rs.getString(columnIp).isEmpty()) { - return new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), "192.168.0.1", rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), - rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName)); + return new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), "192.168.0.1", rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs + .getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName)); } else { if (!columnSalt.isEmpty()) { - return new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnSalt), rs.getInt(columnGroup), rs.getString(columnIp), - rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), - rs.getString(columnRealName)); + return new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnSalt), rs.getInt(columnGroup), rs.getString(columnIp), rs + .getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs + .getString(columnRealName)); } else { - return new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnIp), rs.getLong(columnLastLogin), rs.getDouble(lastlocX), - rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName)); + return new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnIp), rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs + .getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName)); } } } else { return null; } - } catch (SQLException ex) { + } catch (final SQLException ex) { ConsoleLogger.showError(ex.getMessage()); return null; } finally { @@ -283,7 +284,7 @@ public class SQLite_HIKARI implements DataSource { } @Override - public int getIps(String ip) { + public int getIps(final String ip) { Connection con = null; PreparedStatement pst = null; ResultSet rs = null; @@ -297,7 +298,7 @@ public class SQLite_HIKARI implements DataSource { countIp++; } return countIp; - } catch (SQLException ex) { + } catch (final SQLException ex) { ConsoleLogger.showError(ex.getMessage()); return 0; } finally { @@ -312,7 +313,7 @@ public class SQLite_HIKARI implements DataSource { Connection con = null; PreparedStatement pst = null; ResultSet rs; - List auths = new ArrayList<>(); + final List auths = new ArrayList<>(); try { con = getConnection(); pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnLogged + "=1;"); @@ -320,21 +321,21 @@ public class SQLite_HIKARI implements DataSource { while (rs.next()) { PlayerAuth pAuth; if (rs.getString(columnIp).isEmpty()) { - pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), "127.0.0.1", rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), - rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName)); + pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), "127.0.0.1", rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs + .getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName)); } else { if (!columnSalt.isEmpty()) { - pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnSalt), rs.getInt(columnGroup), rs.getString(columnIp), - rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), - rs.getString(columnRealName)); + pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnSalt), rs.getInt(columnGroup), rs.getString(columnIp), rs + .getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs + .getString(columnRealName)); } else { - pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnIp), rs.getLong(columnLastLogin), rs.getDouble(lastlocX), - rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName)); + pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnIp), rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs + .getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName)); } } auths.add(pAuth); } - } catch (SQLException ex) { + } catch (final SQLException ex) { ConsoleLogger.showError(ex.getMessage()); } finally { close(pst); @@ -349,7 +350,7 @@ public class SQLite_HIKARI implements DataSource { } @Override - public synchronized boolean isAuthAvailable(String user) { + public synchronized boolean isAuthAvailable(final String user) { Connection con = null; PreparedStatement pst = null; ResultSet rs = null; @@ -359,7 +360,7 @@ public class SQLite_HIKARI 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 { @@ -370,7 +371,7 @@ public class SQLite_HIKARI implements DataSource { } @Override - public boolean isLogged(String user) { + public boolean isLogged(final String user) { Connection con = null; PreparedStatement pst = null; ResultSet rs = null; @@ -379,9 +380,10 @@ public class SQLite_HIKARI implements DataSource { 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 { @@ -393,17 +395,17 @@ public class SQLite_HIKARI implements DataSource { } @Override - public void purgeBanned(List banned) { + public void purgeBanned(final List banned) { Connection con = null; PreparedStatement pst = null; try { con = getConnection(); - 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); @@ -412,7 +414,7 @@ public class SQLite_HIKARI implements DataSource { } @Override - public int purgeDatabase(long until) { + public int purgeDatabase(final long until) { Connection con = null; PreparedStatement pst = null; try { @@ -420,7 +422,7 @@ public class SQLite_HIKARI implements DataSource { pst = con.prepareStatement("DELETE FROM " + tableName + " WHERE " + columnLastLogin + " auths = this.database.getAllAuthsByName(auth); + final List auths = this.database.getAllAuthsByName(auth); // List uuidlist = - // plugin.otherAccounts.getAllPlayersByUUID(player.getUniqueId()); + // plugin.otherAccounts.getAllPlayersByUUID(player); if (auths.isEmpty()) { return; } if (auths.size() == 1) { return; } - StringBuilder message = new StringBuilder("[AuthMe] "); + final StringBuilder message = new StringBuilder("[AuthMe] "); // String uuidaccounts = // "[AuthMe] PlayerNames has %size% links to this UUID : "; int i = 0; - for (String account : auths) { + for (final String account : auths) { i++; message.append(account); if (i != auths.size()) { @@ -79,9 +79,9 @@ public class AsyncronousLogin { * uuidaccounts = uuidaccounts + ", "; } else { uuidaccounts = * uuidaccounts + "."; } } */ - for (Player player : Utils.getOnlinePlayers()) { + for (final Player player : Utils.getOnlinePlayers()) { if (plugin.authmePermissible(player, "authme.seeOtherAccounts")) { - player.sendMessage("[AuthMe] The player " + auth.getNickname() + " has " + auths.size() + " accounts"); + player.sendMessage("[AuthMe] 当前玩家 " + auth.getNickname() + " 拥有 " + auths.size() + " 个账户!"); player.sendMessage(message.toString()); // player.sendMessage(uuidaccounts.replace("%size%", // ""+uuidlist.size())); @@ -90,23 +90,25 @@ public class AsyncronousLogin { } public void process() { - PlayerAuth pAuth = preAuth(); - if (pAuth == null || needsCaptcha()) + final PlayerAuth pAuth = preAuth(); + if (pAuth == null || needsCaptcha()) { return; + } - String hash = pAuth.getHash(); - String email = pAuth.getEmail(); + final String hash = pAuth.getHash(); + final String email = pAuth.getEmail(); boolean passwordVerified = true; - if (!forceLogin) + if (!forceLogin) { try { passwordVerified = PasswordSecurity.comparePasswordWithHash(password, hash, realName); - } catch (Exception ex) { + } catch (final Exception ex) { ConsoleLogger.showError(ex.getMessage()); m.send(player, "error"); return; } + } if (passwordVerified && player.isOnline()) { - PlayerAuth auth = new PlayerAuth(name, hash, getIP(), new Date().getTime(), email, realName); + final PlayerAuth auth = new PlayerAuth(name, hash, getIP(), new Date().getTime(), email, realName); database.updateSession(auth); if (Settings.useCaptcha) { @@ -119,39 +121,45 @@ public class AsyncronousLogin { } player.setNoDamageTicks(0); - if (!forceLogin) + if (!forceLogin) { m.send(player, "login"); + } displayOtherAccounts(auth, player); if (Settings.recallEmail) { - if (email == null || email.isEmpty() || email.equalsIgnoreCase("your@email.com")) + if (email == null || email.isEmpty() || email.equalsIgnoreCase("your@email.com")) { m.send(player, "add_email"); + } } - if (!Settings.noConsoleSpam) - ConsoleLogger.info(realName + " logged in!"); + if (!Settings.noConsoleSpam) { + ConsoleLogger.info(realName + " 登陆成功!"); + } // makes player isLoggedin via API PlayerCache.getInstance().addPlayer(auth); database.setLogged(name); - plugin.otherAccounts.addPlayer(player.getUniqueId()); + plugin.otherAccounts.addPlayer(player.getName()); // As the scheduling executes the Task most likely after the current // task, we schedule it in the end // so that we can be sure, and have not to care if it might be // processed in other order. - ProcessSyncronousPlayerLogin syncronousPlayerLogin = new ProcessSyncronousPlayerLogin(player, plugin, database); + final ProcessSyncronousPlayerLogin syncronousPlayerLogin = new ProcessSyncronousPlayerLogin(player, plugin, database); if (syncronousPlayerLogin.getLimbo() != null) { - if (syncronousPlayerLogin.getLimbo().getTimeoutTaskId() != null) + if (syncronousPlayerLogin.getLimbo().getTimeoutTaskId() != null) { syncronousPlayerLogin.getLimbo().getTimeoutTaskId().cancel(); - if (syncronousPlayerLogin.getLimbo().getMessageTaskId() != null) + } + if (syncronousPlayerLogin.getLimbo().getMessageTaskId() != null) { syncronousPlayerLogin.getLimbo().getMessageTaskId().cancel(); + } } Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, syncronousPlayerLogin); } else if (player.isOnline()) { - if (!Settings.noConsoleSpam) - ConsoleLogger.info(realName + " used the wrong password"); + if (!Settings.noConsoleSpam) { + ConsoleLogger.info(realName + " 输入了错误的密码"); + } if (Settings.isKickOnWrongPasswordEnabled) { Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { @@ -167,7 +175,7 @@ public class AsyncronousLogin { m.send(player, "wrong_pwd"); } } else { - ConsoleLogger.showError("Player " + name + " wasn't online during login process, aborted... "); + ConsoleLogger.showError("玩家 " + name + " 在进行登陆流程时下线了, 已中断... "); } } @@ -180,13 +188,13 @@ public class AsyncronousLogin { if (!plugin.captcha.containsKey(name)) { plugin.captcha.putIfAbsent(name, 1); } else { - int i = plugin.captcha.get(name) + 1; + final int i = plugin.captcha.get(name) + 1; plugin.captcha.remove(name); plugin.captcha.putIfAbsent(name, i); } if (plugin.captcha.containsKey(name) && plugin.captcha.get(name) >= Settings.maxLoginTry) { plugin.cap.put(name, rdm.nextString()); - for (String s : m.send("usage_captcha")) { + for (final String s : m.send("usage_captcha")) { player.sendMessage(s.replace("THE_CAPTCHA", plugin.cap.get(name)).replace("", plugin.cap.get(name))); } return true; @@ -217,7 +225,7 @@ public class AsyncronousLogin { } else { msg = m.send("reg_msg"); } - BukkitTask msgT = Bukkit.getScheduler().runTaskAsynchronously(plugin, new MessageTask(plugin, name, msg, Settings.getWarnMessageInterval)); + final BukkitTask msgT = Bukkit.getScheduler().runTaskAsynchronously(plugin, new MessageTask(plugin, name, msg, Settings.getWarnMessageInterval)); LimboCache.getInstance().getLimboPlayer(name).setMessageTaskId(msgT); } return null; @@ -228,7 +236,7 @@ public class AsyncronousLogin { return null; } } - PlayerAuth pAuth = database.getAuth(name); + final PlayerAuth pAuth = database.getAuth(name); if (pAuth == null) { m.send(player, "user_unknown"); return null; @@ -237,10 +245,11 @@ public class AsyncronousLogin { m.send(player, "vb_nonActiv"); return null; } - AuthMeAsyncPreLoginEvent event = new AuthMeAsyncPreLoginEvent(player); + final AuthMeAsyncPreLoginEvent event = new AuthMeAsyncPreLoginEvent(player); Bukkit.getServer().getPluginManager().callEvent(event); - if (!event.canLogin()) + if (!event.canLogin()) { return null; + } return pAuth; } } diff --git a/src/main/java/fr/xephi/authme/process/register/AsyncronousRegister.java b/src/main/java/fr/xephi/authme/process/register/AsyncronousRegister.java index 1bba40d..05df2a4 100644 --- a/src/main/java/fr/xephi/authme/process/register/AsyncronousRegister.java +++ b/src/main/java/fr/xephi/authme/process/register/AsyncronousRegister.java @@ -63,8 +63,10 @@ public class AsyncronousRegister { PlayerAuth auth; try { final String hashnew = PasswordSecurity.getHash(Settings.getPasswordHash, password, name); - auth = new PlayerAuth(name, hashnew, getIp(), 0, (int) player.getLocation().getX(), (int) player.getLocation().getY(), (int) player.getLocation().getZ(), - player.getLocation().getWorld().getName(), email, player.getName()); + auth = new PlayerAuth(name, hashnew, getIp(), 0, (int) player.getLocation().getX(), (int) player.getLocation().getY(), (int) player.getLocation().getZ(), player + .getLocation() + .getWorld() + .getName(), email, player.getName()); } catch (final NoSuchAlgorithmException e) { ConsoleLogger.showError(e.getMessage()); m.send(player, "error"); @@ -107,7 +109,7 @@ public class AsyncronousRegister { PlayerCache.getInstance().addPlayer(auth); database.setLogged(name); } - plugin.otherAccounts.addPlayer(player.getUniqueId()); + plugin.otherAccounts.addPlayer(player.getName()); final ProcessSyncronousPasswordRegister syncronous = new ProcessSyncronousPasswordRegister(player, plugin); plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, syncronous); } diff --git a/src/main/java/fr/xephi/authme/settings/Messages.java b/src/main/java/fr/xephi/authme/settings/Messages.java index 0e95874..4e54a56 100644 --- a/src/main/java/fr/xephi/authme/settings/Messages.java +++ b/src/main/java/fr/xephi/authme/settings/Messages.java @@ -1,70 +1,57 @@ package fr.xephi.authme.settings; -import java.io.File; - import org.bukkit.command.CommandSender; import cn.citycraft.PluginHelper.config.FileConfig; +import fr.xephi.authme.AuthMe; import fr.xephi.authme.ConsoleLogger; public class Messages { private static Messages singleton = null; - private final FileConfig config; - private String lang = "zhcn"; + private final FileConfig msgcfg; - public Messages(final File file, final String lang) { - config = new FileConfig(file); + public Messages() { + msgcfg = new FileConfig(AuthMe.getInstance(), "messages_zhcn.yml"); singleton = this; - this.lang = lang; } public static Messages getInstance() { if (singleton == null) { - singleton = new Messages(Settings.messageFile, Settings.messagesLanguage); + singleton = new Messages(); } return singleton; } public String getString(final String string) { - return config.getMessage(string); + return msgcfg.getMessage(string); } public void reloadMessages() { - config.reload(); + msgcfg.reload(); } public void send(final CommandSender sender, final String msg) { - if (!Settings.messagesLanguage.equalsIgnoreCase(singleton.lang)) { - singleton.reloadMessages(); - } - String loc = config.getMessage(msg); - if (loc == null) { + String loc = msgcfg.getMessage(msg); + if (loc == null || loc.isEmpty()) { loc = "错误的语言文件 " + msg + " ; 请联系管理员升级语言文件"; - ConsoleLogger.showError("错误的语言文件 " + msg + " 请检查您的配置文件" + config.getName() + " !"); + ConsoleLogger.showError("错误的语言文件 " + msg + " 请检查您的配置文件" + msgcfg.getName() + " !"); } for (final String l : loc.split("&n")) { - sender.sendMessage(l.replace("&", "§")); + sender.sendMessage(l); } } public String[] send(final String msg) { - if (!Settings.messagesLanguage.equalsIgnoreCase(singleton.lang)) { - singleton.reloadMessages(); - } - final String s = config.getMessage(msg); - if (s == null) { - ConsoleLogger.showError("错误的语言文件 " + msg + " 请检查您的配置文件" + config.getName() + " !"); + final String s = msgcfg.getMessage(msg); + if (s == null || s.isEmpty()) { + ConsoleLogger.showError("错误的语言文件 " + msg + " 请检查您的配置文件" + msgcfg.getName() + " !"); final String[] loc = new String[1]; loc[0] = "错误的语言文件 " + msg + " ; 请联系管理员升级语言文件"; return (loc); } final int i = s.split("&n").length; final String[] loc = new String[i]; - int a; - for (a = 0; a < i; a++) { - loc[a] = config.getMessage(msg).split("&n")[a].replace("&", "§"); - } if (loc.length == 0) { loc[0] = "错误的语言文件 " + msg + " ; 请联系管理员升级语言文件"; } diff --git a/src/main/java/fr/xephi/authme/settings/OtherAccounts.java b/src/main/java/fr/xephi/authme/settings/OtherAccounts.java index 7f0d749..90dea81 100644 --- a/src/main/java/fr/xephi/authme/settings/OtherAccounts.java +++ b/src/main/java/fr/xephi/authme/settings/OtherAccounts.java @@ -1,6 +1,5 @@ package fr.xephi.authme.settings; -import java.io.File; import java.util.ArrayList; import java.util.List; import java.util.UUID; @@ -8,19 +7,20 @@ import java.util.UUID; import org.bukkit.Bukkit; import org.bukkit.entity.Player; +import cn.citycraft.PluginHelper.config.FileConfig; +import fr.xephi.authme.AuthMe; + /** * * @author Xephi59 */ -public class OtherAccounts extends CustomConfiguration { +public class OtherAccounts extends FileConfig { private static OtherAccounts others = null; public OtherAccounts() { - super(new File("." + File.separator + "plugins" + File.separator + "AuthMe" + File.separator + "otheraccounts.yml")); + super(AuthMe.getInstance(), "otheraccounts.yml"); others = this; - load(); - save(); } public static OtherAccounts getInstance() { @@ -30,40 +30,40 @@ public class OtherAccounts extends CustomConfiguration { return others; } - public void addPlayer(UUID uuid) { + public void addPlayer(final String pname) { try { - Player player = Bukkit.getPlayer(uuid); - if (player == null) + final Player player = Bukkit.getPlayer(pname); + if (player == null) { return; - if (!this.getStringList(uuid.toString()).contains(player.getName())) { - this.getStringList(uuid.toString()).add(player.getName()); + } + if (!this.getStringList(pname).contains(player.getName())) { + this.getStringList(pname).add(player.getName()); save(); } } catch (NoSuchMethodError | Exception e) { - // ignore } } - public void clear(UUID uuid) { - set(uuid.toString(), new ArrayList()); + public void clear(final String pname) { + set(pname, new ArrayList()); save(); } - public List getAllPlayersByUUID(UUID uuid) { + public List getAllPlayersByUUID(final UUID uuid) { return this.getStringList(uuid.toString()); } - public void removePlayer(UUID uuid) { + public void removePlayer(final String pname) { try { - Player player = Bukkit.getPlayer(uuid); - if (player == null) + final Player player = Bukkit.getPlayer(pname); + if (player == null) { return; - if (this.getStringList(uuid.toString()).contains(player.getName())) { - this.getStringList(uuid.toString()).remove(player.getName()); + } + if (this.getStringList(pname).contains(player.getName())) { + this.getStringList(pname).remove(player.getName()); save(); } } catch (NoSuchMethodError | Exception e) { - // ignore } } } diff --git a/src/main/java/fr/xephi/authme/settings/Settings.java b/src/main/java/fr/xephi/authme/settings/Settings.java index bf322ac..b31f069 100644 --- a/src/main/java/fr/xephi/authme/settings/Settings.java +++ b/src/main/java/fr/xephi/authme/settings/Settings.java @@ -17,7 +17,7 @@ import fr.xephi.authme.datasource.DataSource; import fr.xephi.authme.datasource.DataSource.DataSourceType; import fr.xephi.authme.security.HashAlgorithm; -public final class Settings extends FileConfig { +public final class Settings { public static List allowCommands; // This is not an option! @@ -42,9 +42,8 @@ public final class Settings extends FileConfig { public static List getMySQLOtherUsernameColumn; public static String getNickRegex, getUnloggedinGroup, getMySQLHost, getMySQLPort, getMySQLUsername, getMySQLPassword, getMySQLDatabase, getMySQLTablename, getMySQLColumnName, getMySQLColumnPassword, getMySQLColumnIp, getMySQLColumnLastLogin, getMySQLColumnSalt, getMySQLColumnGroup, getMySQLColumnEmail, unRegisteredGroup, backupWindowsPath, getRegisteredGroup, - messagesLanguage, getMySQLlastlocX, getMySQLlastlocY, getMySQLlastlocZ, rakamakUsers, rakamakUsersIp, getmailAccount, getmailPassword, getmailSMTP, getMySQLColumnId, getmailSenderName, - getMailSubject, getMailText, getMySQLlastlocWorld, defaultWorld, getPhpbbPrefix, getWordPressPrefix, getMySQLColumnLogged, spawnPriority, crazyloginFileName, getPassRegex, - getMySQLColumnRealName; + getMySQLlastlocX, getMySQLlastlocY, getMySQLlastlocZ, rakamakUsers, rakamakUsersIp, getmailAccount, getmailPassword, getmailSMTP, getMySQLColumnId, getmailSenderName, getMailSubject, + getMailText, getMySQLlastlocWorld, defaultWorld, getPhpbbPrefix, getWordPressPrefix, getMySQLColumnLogged, spawnPriority, crazyloginFileName, getPassRegex, getMySQLColumnRealName; public static HashAlgorithm getPasswordHash; public static List getRestrictedIp; public static List getUnrestrictedName; @@ -59,7 +58,6 @@ public final class Settings extends FileConfig { enableProtection, enableAntiBot, recallEmail, useWelcomeMessage, broadcastWelcomeMessage, forceRegKick, forceRegLogin, checkVeryGames, delayJoinMessage, noTeleport, applyBlindEffect, customAttributes, generateImage, isRemoveSpeedEnabled; public static final File LOG_FILE = new File(APLUGIN_FOLDER, "authme.log"); - public static File messageFile; public static int purgeDelay = 60; public static final File SETTINGS_FILE = new File(APLUGIN_FOLDER, "config.yml"); public static List unsafePasswords; @@ -67,14 +65,11 @@ public final class Settings extends FileConfig { public static List welcomeMsg; - private static Settings instance; - private static AuthMe plugin; protected static FileConfig configFile; public Settings(final AuthMe pl) { - instance = this; plugin = pl; configFile = (FileConfig) plugin.getConfig(); } @@ -296,19 +291,18 @@ public final class Settings extends FileConfig { forceRegisterCommandsAsConsole = configFile.getStringList("settings.forceRegisterCommandsAsConsole"); customAttributes = configFile.getBoolean("Hooks.customAttributes"); generateImage = configFile.getBoolean("Email.generateImage", true); - messageFile = new File(APLUGIN_FOLDER, "messages_zhcn.yml"); // Load the welcome message getWelcomeMessage(); } public static boolean reloadcfg() { - return instance.save(); + return configFile.reload(); } public static void setValue(final String key, final Object value) { - instance.set(key, value); - instance.save(); + configFile.set(key, value); + configFile.save(); } public static void switchAntiBotMod(final boolean mode) { @@ -374,193 +368,193 @@ public final class Settings extends FileConfig { public void mergeConfig() { boolean changes = false; - if (contains("Xenoforo.predefinedSalt")) { - set("Xenoforo.predefinedSalt", null); + if (configFile.contains("Xenoforo.predefinedSalt")) { + configFile.set("Xenoforo.predefinedSalt", null); changes = true; } if (configFile.getString("settings.security.passwordHash", "SHA256").toUpperCase().equals("XFSHA1") || configFile.getString("settings.security.passwordHash", "SHA256").toUpperCase().equals("XFSHA256")) { - set("settings.security.passwordHash", "XENFORO"); + configFile.set("settings.security.passwordHash", "XENFORO"); changes = true; } - if (!contains("Protection.enableProtection")) { - set("Protection.enableProtection", false); + if (!configFile.contains("Protection.enableProtection")) { + configFile.set("Protection.enableProtection", false); changes = true; } - if (!contains("settings.restrictions.removeSpeed")) { - set("settings.restrictions.removeSpeed", true); + if (!configFile.contains("settings.restrictions.removeSpeed")) { + configFile.set("settings.restrictions.removeSpeed", true); changes = true; } - if (!contains("DataSource.mySQLMaxConections")) { - set("DataSource.mySQLMaxConections", 25); + if (!configFile.contains("DataSource.mySQLMaxConections")) { + configFile.set("DataSource.mySQLMaxConections", 25); changes = true; } - if (!contains("Protection.countries")) { + if (!configFile.contains("Protection.countries")) { countries = new ArrayList<>(); countries.add("US"); countries.add("GB"); - set("Protection.countries", countries); + configFile.set("Protection.countries", countries); changes = true; } - if (!contains("Protection.enableAntiBot")) { - set("Protection.enableAntiBot", false); + if (!configFile.contains("Protection.enableAntiBot")) { + configFile.set("Protection.enableAntiBot", false); changes = true; } - if (!contains("Protection.antiBotSensibility")) { - set("Protection.antiBotSensibility", 5); + if (!configFile.contains("Protection.antiBotSensibility")) { + configFile.set("Protection.antiBotSensibility", 5); changes = true; } - if (!contains("Protection.antiBotDuration")) { - set("Protection.antiBotDuration", 10); + if (!configFile.contains("Protection.antiBotDuration")) { + configFile.set("Protection.antiBotDuration", 10); changes = true; } - if (!contains("settings.forceCommands")) { - set("settings.forceCommands", new ArrayList()); + if (!configFile.contains("settings.forceCommands")) { + configFile.set("settings.forceCommands", new ArrayList()); changes = true; } - if (!contains("settings.forceCommandsAsConsole")) { - set("settings.forceCommandsAsConsole", new ArrayList()); + if (!configFile.contains("settings.forceCommandsAsConsole")) { + configFile.set("settings.forceCommandsAsConsole", new ArrayList()); changes = true; } - if (!contains("Email.recallPlayers")) { - set("Email.recallPlayers", false); + if (!configFile.contains("Email.recallPlayers")) { + configFile.set("Email.recallPlayers", false); changes = true; } - if (!contains("Email.delayRecall")) { - set("Email.delayRecall", 5); + if (!configFile.contains("Email.delayRecall")) { + configFile.set("Email.delayRecall", 5); changes = true; } - if (!contains("settings.useWelcomeMessage")) { - set("settings.useWelcomeMessage", true); + if (!configFile.contains("settings.useWelcomeMessage")) { + configFile.set("settings.useWelcomeMessage", true); changes = true; } - if (!contains("settings.security.unsafePasswords")) { + if (!configFile.contains("settings.security.unsafePasswords")) { final List str = new ArrayList<>(); str.add("123456"); str.add("password"); - set("settings.security.unsafePasswords", str); + configFile.set("settings.security.unsafePasswords", str); changes = true; } - if (!contains("Protection.countriesBlacklist")) { + if (!configFile.contains("Protection.countriesBlacklist")) { countriesBlacklist = new ArrayList<>(); countriesBlacklist.add("A1"); - set("Protection.countriesBlacklist", countriesBlacklist); + configFile.set("Protection.countriesBlacklist", countriesBlacklist); changes = true; } - if (!contains("settings.broadcastWelcomeMessage")) { - set("settings.broadcastWelcomeMessage", false); + if (!configFile.contains("settings.broadcastWelcomeMessage")) { + configFile.set("settings.broadcastWelcomeMessage", false); changes = true; } - if (!contains("settings.registration.forceKickAfterRegister")) { - set("settings.registration.forceKickAfterRegister", false); + if (!configFile.contains("settings.registration.forceKickAfterRegister")) { + configFile.set("settings.registration.forceKickAfterRegister", false); changes = true; } - if (!contains("settings.registration.forceLoginAfterRegister")) { - set("settings.registration.forceLoginAfterRegister", false); + if (!configFile.contains("settings.registration.forceLoginAfterRegister")) { + configFile.set("settings.registration.forceLoginAfterRegister", false); changes = true; } - if (!contains("DataSource.mySQLColumnLogged")) { - set("DataSource.mySQLColumnLogged", "isLogged"); + if (!configFile.contains("DataSource.mySQLColumnLogged")) { + configFile.set("DataSource.mySQLColumnLogged", "isLogged"); changes = true; } - if (!contains("settings.restrictions.spawnPriority")) { - set("settings.restrictions.spawnPriority", "authme,essentials,multiverse,default"); + if (!configFile.contains("settings.restrictions.spawnPriority")) { + configFile.set("settings.restrictions.spawnPriority", "authme,essentials,multiverse,default"); changes = true; } - if (!contains("settings.restrictions.maxLoginPerIp")) { - set("settings.restrictions.maxLoginPerIp", 0); + if (!configFile.contains("settings.restrictions.maxLoginPerIp")) { + configFile.set("settings.restrictions.maxLoginPerIp", 0); changes = true; } - if (!contains("settings.restrictions.maxJoinPerIp")) { - set("settings.restrictions.maxJoinPerIp", 0); + if (!configFile.contains("settings.restrictions.maxJoinPerIp")) { + configFile.set("settings.restrictions.maxJoinPerIp", 0); changes = true; } - if (getString("settings.restrictions.allowedNicknameCharacters").equals("[a-zA-Z0-9_?]*")) { - set("settings.restrictions.allowedNicknameCharacters", "[a-zA-Z0-9_]*"); + if (configFile.getString("settings.restrictions.allowedNicknameCharacters").equals("[a-zA-Z0-9_?]*")) { + configFile.set("settings.restrictions.allowedNicknameCharacters", "[a-zA-Z0-9_]*"); changes = true; } - if (!contains("settings.delayJoinMessage")) { - set("settings.delayJoinMessage", false); + if (!configFile.contains("settings.delayJoinMessage")) { + configFile.set("settings.delayJoinMessage", false); changes = true; } - if (!contains("settings.restrictions.noTeleport")) { - set("settings.restrictions.noTeleport", false); + if (!configFile.contains("settings.restrictions.noTeleport")) { + configFile.set("settings.restrictions.noTeleport", false); changes = true; } - if (contains("Converter.Rakamak.newPasswordHash")) { - set("Converter.Rakamak.newPasswordHash", null); + if (configFile.contains("Converter.Rakamak.newPasswordHash")) { + configFile.set("Converter.Rakamak.newPasswordHash", null); changes = true; } - if (!contains("Converter.CrazyLogin.fileName")) { - set("Converter.CrazyLogin.fileName", "accounts.db"); + if (!configFile.contains("Converter.CrazyLogin.fileName")) { + configFile.set("Converter.CrazyLogin.fileName", "accounts.db"); changes = true; } - if (!contains("settings.restrictions.allowedPasswordCharacters")) { - set("settings.restrictions.allowedPasswordCharacters", "[\\x21-\\x7E]*"); + if (!configFile.contains("settings.restrictions.allowedPasswordCharacters")) { + configFile.set("settings.restrictions.allowedPasswordCharacters", "[\\x21-\\x7E]*"); changes = true; } - if (!contains("settings.applyBlindEffect")) { - set("settings.applyBlindEffect", false); + if (!configFile.contains("settings.applyBlindEffect")) { + configFile.set("settings.applyBlindEffect", false); changes = true; } - if (!contains("Email.emailBlacklisted")) { - set("Email.emailBlacklisted", new ArrayList()); + if (!configFile.contains("Email.emailBlacklisted")) { + configFile.set("Email.emailBlacklisted", new ArrayList()); changes = true; } - if (contains("Performances.useMultiThreading")) { - set("Performances.useMultiThreading", null); + if (configFile.contains("Performances.useMultiThreading")) { + configFile.set("Performances.useMultiThreading", null); changes = true; } - if (contains("Performances")) { - set("Performances", null); + if (configFile.contains("Performances")) { + configFile.set("Performances", null); changes = true; } - if (contains("Passpartu.enablePasspartu")) { - set("Passpartu.enablePasspartu", null); + if (configFile.contains("Passpartu.enablePasspartu")) { + configFile.set("Passpartu.enablePasspartu", null); changes = true; } - if (contains("Passpartu")) { - set("Passpartu", null); + if (configFile.contains("Passpartu")) { + configFile.set("Passpartu", null); changes = true; } - if (!contains("Email.emailWhitelisted")) { - set("Email.emailWhitelisted", new ArrayList()); + if (!configFile.contains("Email.emailWhitelisted")) { + configFile.set("Email.emailWhitelisted", new ArrayList()); changes = true; } - if (!contains("settings.forceRegisterCommands")) { - set("settings.forceRegisterCommands", new ArrayList()); + if (!configFile.contains("settings.forceRegisterCommands")) { + configFile.set("settings.forceRegisterCommands", new ArrayList()); changes = true; } - if (!contains("settings.forceRegisterCommandsAsConsole")) { - set("settings.forceRegisterCommandsAsConsole", new ArrayList()); + if (!configFile.contains("settings.forceRegisterCommandsAsConsole")) { + configFile.set("settings.forceRegisterCommandsAsConsole", new ArrayList()); changes = true; } - if (!contains("Hooks.customAttributes")) { - set("Hooks.customAttributes", false); + if (!configFile.contains("Hooks.customAttributes")) { + configFile.set("Hooks.customAttributes", false); changes = true; } - if (!contains("Purge.removePermissions")) { - set("Purge.removePermissions", false); + if (!configFile.contains("Purge.removePermissions")) { + configFile.set("Purge.removePermissions", false); changes = true; } - if (contains("Hooks.notifications")) { - set("Hooks.notifications", null); + if (configFile.contains("Hooks.notifications")) { + configFile.set("Hooks.notifications", null); changes = true; } - if (contains("Hooks.chestshop")) { - set("Hooks.chestshop", null); + if (configFile.contains("Hooks.chestshop")) { + configFile.set("Hooks.chestshop", null); changes = true; } - if (contains("Hooks.legacyChestshop")) { - set("Hooks.legacyChestshop", null); + if (configFile.contains("Hooks.legacyChestshop")) { + configFile.set("Hooks.legacyChestshop", null); changes = true; } - if (!contains("Email.generateImage")) { - set("Email.generateImage", true); + if (!configFile.contains("Email.generateImage")) { + configFile.set("Email.generateImage", true); changes = true; } - if (!contains("DataSource.mySQLRealName")) { - set("DataSource.mySQLRealName", "realname"); + if (!configFile.contains("DataSource.mySQLRealName")) { + configFile.set("DataSource.mySQLRealName", "realname"); changes = true; } @@ -569,20 +563,4 @@ public final class Settings extends FileConfig { plugin.getLogger().warning("请检查新的 config.yml 文件 并修改相关配置!"); } } - - /** - * Saves current configuration (plus defaults) to disk. - *

- * If defaults and configuration are empty, saves blank file. - * - * @return True if saved successfully - */ - public final boolean saveDefaults() { - options().copyDefaults(true); - options().copyHeader(true); - final boolean success = instance.save(); - options().copyDefaults(false); - options().copyHeader(false); - return success; - } } diff --git a/src/main/resources/messages_zhcn.yml b/src/main/resources/messages_zhcn.yml index a513105b3df2ba87a11cd6cedd5467cada755836..375a5dd19278e2768f0f412ad69749495d0ef202 100644 GIT binary patch literal 3481 zcmbVPOK%!i6yEbIrjc59_1>}~Wf4_bREoN&Dpl2Jj0a~Fm_a=3WCuvATgCTFGa z4^g^xLdzx@Y`TRKUB9yWWwLfcyKTGHp=%f6P)1KFQB_VQlx3Y?utxiCHcJWv+A5Rc z0cmvT_PM?D(i)ZRk;(3x>twZaeOaR2KS`@&U4nfMZlPbR|JL3rfjxMzYkT&}*KkNT z(sImLTvQiijR%Q&l(;dU<<4cOSmw%g)s%Sv|7) zS^Dt+ZrBGVF?T$JZ`oadBc&{=ELj#l0u_P@gX#=&APsnJ~8nsYO--ScB?qdH=yDeH(Xc2Bh1+p4fw3r-EAwoa_ zc7=2=&@{*dG!5wAF#-B7q+5j_t>O9od#t17gqn43J@86lfx$Q1(8-4|}7 z8V>OSd3L1o+TJ+9?m*_9T+Kck+U9{>&6C%4$d2pkZf2~X@AMsOUp_prs5|BS?;#*2 ziLWKzz`WEc^Wdhtg`W6OfN>y4o+!GnU*u1;i#0ZB?dy%wGdQ=sD8AIIWv^fOWaILl zq@N>e_1iGckVL^Xux~f}q*@AxH2qH7M*%vwk@uFvN2!Px58L=f0HeguCU zcymTX@#iaSCWg5jQ^o2MAfxV`t1Fn04ov0K6`oa6jTs6bTTyqFZ%vrSm7<3>pI>gF zOy8c6;=VH)5wk>lTOj|m7FWG$qxP`DW(rq0#DlT#Zhyx75guQiC^BCbTo6-aI%y@* z?e{21iDkhT6<4j!@SLnvU`g7?_Fk8+y>+sy@ZH@S1B6^1>N8Fd&cGY{(kiKbaChIq z@+94D+5>5n#3?Ls)DZ)dpUz6ZJp4(1_**!nEWl)BLyEf<1B!Jt|5*Y9X%54QK{a)| z!|1vXg)!k3i@^)@VhG^lV#CeEDv20NYVvs?HW}BUNW6$JU0?2rguEvK=H%bLl^BN= zUlkE0kp>=kQMV|X@y?_<_ZXI9jy+hyA$(W_uZhQnF!M$!f7f{VO!39Dz$p-P=ON;U zr1c&f<6CRM2^aEHSWI%%NG@p!%(}Jy>!Zim?F>G6N)7U?V}=Jzqy7^_qAMNe@PpGo zggyleaR3@emzh`$_B()$Zi}b1yAG8IL-Yyeh#YP#V4ayqnTF1`W~HDQgbb$aD{0aV zw!$<|cp}X~cL;ybAO81AH$LCf9QkKJCx6iZm%6&_EnaUN^LxTO-QEY>pr4oSNVLE+5+L1F*H{{&_iG2o34Z8opyx|f>wlJ^CKFI=a0M4B)i z&v7fTtBRi1=HcIjl1Uq~s{0S+-ydYsPkvVaklgww+8V%r7HcrDJFm!~V%JWs!3Jr+ zcMBE57o9VHM>md~Y>8BRAf;PQ1JCb&_Zsj=!2QW<=C#$4zK=^}E$_bBBh?L(Yr$(h F{0|~jpY#9# literal 4288 zcmbVQZD>)c-kYVC#JIIL(o})W2%SpM zDT`#%ws$%5XoRHF?100o`+>6V330!!%uISc`CFwH{pr~6dRhM?eZ;rE@`Bb{)i+3y zCHq5k9}x``t^-dZh_UC7-!B#{SQL5Su}fcpm$bPyddjc)2WENhoM;UY zKJYe5C^@C>Ssi|k(MRzG&0X{S&VWuNFIpuajKGnwYK+R0JZYn&>I=}UrwwU#r^Zs7sfdnqUs~ntn-Q!T4IbN zH{Ww@!V?l60*%Y1+I;g&NJ(eDYx5+tzFbXZ2-Pu))Ttlwx%HjCuZl-~?K)!G!#bI$ zZFq>xpkoi|JW_NiGBQdT8L@MOZbz++*fWq<`NsQ1;2y0cA(5SEQ zbcF7h^gKh^)@=Qn%?7F+;Iy=Dl}`kIakjL5Ri@r%mb{g`V32?PR2^xGGeZa@o*YBv&c>~GW-&XTioD*74DT8LID&gWPec-GZou-+33WGsj^G5f^dpvjWe&z!$Ba2y)_)8jEAZ&*%$#xB|6%D! z_(lpD!R$a>&iLc(){bz>7G2!{p5I~T7)O+`4xeegS{tiq(kAWDOZK-xH5wp zELgY)89&>_-ldH1V*6}<0j66kg@dmC+1XNx-+80?d%IQ2Ml z+K;^eQ(W{7>f9pjBQ${;`*4$LP1MIm>KyPp-?>zufQzcj>0SLchbcHrb;9!|BbHOX zm7b|*pz+Ab?~B+Q;k~-oIZsM$e81yTU=HcKQ$p3veN}nMc~)u%DqMGKd{tsM?d7~@ zQq^9L&_<7Kz@lsL41W)Z(RQV=E{6RAjC9&>_zqED|7I2}zOnJSrE1Aj52k58AWuA7 zQrm^-9;!7i2`yY&?I)S1NVRr^bev&>#?@jKw%EKzEY7Y~t*G6&oGtY%@^HtHHs_xF zy_B`u+FQ_>>=kweH_4Iz6WffF&>F3k1jW>p_%|Ig^=m(P!UJQe1pSv5|<$TZeK-09)0ROSu