1
0
mirror of https://e.coding.net/circlecloud/AuthMe.git synced 2024-12-22 06:48:55 +00:00

clean up UUID and fix Message Error...

Signed-off-by: 502647092 <jtb1@163.com>
This commit is contained in:
502647092 2015-10-28 20:18:11 +08:00
parent f0b74ad048
commit 66117b6cb0
16 changed files with 677 additions and 810 deletions

View File

@ -1,27 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<classpath> <classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java"> <classpathentry kind="src" path="src/main/java"/>
<attributes> <classpathentry kind="src" path="src/main/resources"/>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
<attributes> <attributes>
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry excluding="**" including="**/*.java" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"> <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes> <attributes>
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>

147
pom.xml
View File

@ -48,6 +48,8 @@
<!-- Change Compiler Version (JDK) HERE! --> <!-- Change Compiler Version (JDK) HERE! -->
<javaVersion>1.7</javaVersion> <javaVersion>1.7</javaVersion>
<!-- Change MC Version HERE! --> <!-- Change MC Version HERE! -->
<jenkins.url>http://ci.citycraft.cn:8080</jenkins.url>
<update.description>测试版本发布...</update.description>
<bukkitVersion>1.8.8-R0.1-SNAPSHOT</bukkitVersion> <bukkitVersion>1.8.8-R0.1-SNAPSHOT</bukkitVersion>
</properties> </properties>
@ -98,10 +100,12 @@
<include>cn.citycraft:PluginHelper</include> <include>cn.citycraft:PluginHelper</include>
</includes> </includes>
</artifactSet> </artifactSet>
<relocation> <relocations>
<pattern>cn.citycraft.PluginHelper</pattern> <relocation>
<shadedPattern>${project.groupId}.${project.artifactId}</shadedPattern> <pattern>cn.citycraft.PluginHelper</pattern>
</relocation> <shadedPattern>${project.groupId}.${project.artifactId}</shadedPattern>
</relocation>
</relocations>
</configuration> </configuration>
<executions> <executions>
<execution> <execution>
@ -116,43 +120,15 @@
</build> </build>
<repositories> <repositories>
<!-- SpigotMC Repo (Bukkit and SpigotAPI) --> <!-- SpigotMC Repo (Bukkit and SpigotAPI) -->
<repository> <repository>
<id>spigot-repo</id> <id>spigot-repo</id>
<url>http://hub.spigotmc.org/nexus/content/groups/public</url> <url>http://hub.spigotmc.org/nexus/content/groups/public</url>
</repository> </repository>
<repository>
<!-- EssentialsX Repo --> <id>citycraft-repo</id>
<!-- <repository> <id>ess-repo</id> <url>http://ci.drtshock.net/plugin/repository/everything</url> <url>${jenkins.url}/plugin/repository/everything/</url>
</repository> --> </repository>
<!-- CombatTagPlus Repo -->
<!-- <repository> <id>minelink-thirdparty</id> <url>http://repo.minelink.net/content/repositories/public</url>
</repository> -->
<!-- Attribute Repo -->
<!-- <repository> <id>comphenix-snapshots</id> <url>http://repo.comphenix.net/content/repositories/public</url>
</repository> -->
<!-- Multiverse Repo -->
<!-- <repository> <id>onarandombox</id> <url>http://repo.onarandombox.com/content/groups/public</url>
</repository> -->
<!-- Vault Repo -->
<!-- <repository> <id>vault-repo</id> <url>http://nexus.theyeticave.net/content/repositories/pub_releases</url>
</repository> -->
<!-- XAuth Repo -->
<!-- <repository> <id>luricos-releases</id> <url>http://repo.luricos.de/content/repositories/releases</url>
</repository> -->
<!-- Xephi Repo <repository> <id>xephi-repo</id> <url>http://ci.xephi.fr/plugin/repository/everything/</url>
</repository> -->
<!-- Metrics Snapshots Repo -->
<!-- <repository> <id>mcstats-snapshots</id> <url>http://repo.mcstats.org/content/repositories/snapshots/</url>
</repository> -->
</repositories> </repositories>
<dependencies> <dependencies>
@ -211,104 +187,5 @@
<scope>system</scope> <scope>system</scope>
<systemPath>${project.basedir}/lib/ProtocolLib-3.6.5-SNAPSHOT.jar</systemPath> <systemPath>${project.basedir}/lib/ProtocolLib-3.6.5-SNAPSHOT.jar</systemPath>
</dependency> </dependency>
<!-- Maven Dependencies -->
<!-- Database Connection Pool -->
<!-- <dependency> <groupId>com.zaxxer</groupId> <artifactId>HikariCP</artifactId>
<version>2.4.1</version> <scope>compile</scope> <exclusions> <exclusion>
<artifactId>slf4j-api</artifactId> <groupId>org.slf4j</groupId> </exclusion>
</exclusions> <optional>true</optional> </dependency> <dependency> <groupId>org.slf4j</groupId>
<artifactId>slf4j-jdk14</artifactId> <version>1.7.12</version> <scope>compile</scope>
<optional>true</optional> </dependency> Log4J Logger (for the filter) <dependency>
<groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-core</artifactId>
<version>2.0-beta9</version> <scope>provided</scope> <optional>true</optional>
</dependency> SQLite Connector <dependency> <groupId>org.xerial</groupId>
<artifactId>sqlite-jdbc</artifactId> <version>3.8.11.2</version> <scope>compile</scope>
<optional>true</optional> </dependency> Java Email API and Implementation
<dependency> <groupId>javax.mail</groupId> <artifactId>javax.mail-api</artifactId>
<version>1.5.4</version> <scope>compile</scope> <optional>true</optional>
</dependency> <dependency> <groupId>com.sun.mail</groupId> <artifactId>javax.mail</artifactId>
<version>1.5.4</version> <scope>compile</scope> <exclusions> <exclusion>
<artifactId>activation</artifactId> <groupId>javax.activation</groupId> </exclusion>
</exclusions> <optional>true</optional> </dependency> GSON required for 1.7.X
compatibility <dependency> <groupId>com.google.code.gson</groupId> <artifactId>gson</artifactId>
<version>2.4</version> <scope>compile</scope> <optional>true</optional> </dependency>
Maxmind GeoIp API <dependency> <groupId>com.maxmind.geoip</groupId> <artifactId>geoip-api</artifactId>
<version>1.2.15</version> <scope>compile</scope> <optional>true</optional>
</dependency> Metrics API <dependency> <groupId>org.mcstats.bukkit</groupId>
<artifactId>metrics</artifactId> <version>R8-SNAPSHOT</version> <scope>compile</scope>
<exclusions> <exclusion> <groupId>org.bukkit</groupId> <artifactId>bukkit</artifactId>
</exclusion> </exclusions> <optional>true</optional> </dependency> Bukkit
API, http://www.spigotmc.org/ or http://bukkit.org/ <dependency> <groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId> <version>${bukkitVersion}</version> <scope>provided</scope>
<optional>true</optional> <exclusions> <exclusion> <artifactId>junit</artifactId>
<groupId>junit</groupId> </exclusion> <exclusion> <artifactId>json-simple</artifactId>
<groupId>com.googlecode.json-simple</groupId> </exclusion> <exclusion> <artifactId>persistence-api</artifactId>
<groupId>javax.persistence</groupId> </exclusion> </exclusions> </dependency>
Attribute <dependency> <groupId>com.comphenix.attribute</groupId> <artifactId>AttributeStorage</artifactId>
<version>0.0.2-SNAPSHOT</version> <scope>compile</scope> <exclusions> <exclusion>
<groupId>org.bukkit</groupId> <artifactId>bukkit</artifactId> </exclusion>
<exclusion> <groupId>org.bukkit</groupId> <artifactId>craftbukkit</artifactId>
</exclusion> </exclusions> <optional>true</optional> </dependency> ProtocolLib
http://dev.bukkit.org/bukkit-plugins/protocollib/ <dependency> <groupId>com.comphenix.protocol</groupId>
<artifactId>ProtocolLib</artifactId> <version>3.4.0</version> <scope>provided</scope>
<optional>true</optional> <exclusions> <exclusion> <artifactId>cglib-nodep</artifactId>
<groupId>cglib</groupId> </exclusion> <exclusion> <artifactId>BukkitExecutors</artifactId>
<groupId>com.comphenix.executors</groupId> </exclusion> </exclusions> </dependency>
Vault, http://dev.bukkit.org/bukkit-plugins/vault/ <dependency> <groupId>net.milkbowl.vault</groupId>
<artifactId>VaultAPI</artifactId> <version>1.5</version> <scope>provided</scope>
<exclusions> <exclusion> <groupId>org.bukkit</groupId> <artifactId>bukkit</artifactId>
</exclusion> <exclusion> <groupId>org.bukkit</groupId> <artifactId>craftbukkit</artifactId>
</exclusion> </exclusions> <optional>true</optional> </dependency> Multi
World plugin, http://www.spigotmc.org/resources/multiverse-core.390/ <dependency>
<groupId>com.onarandombox.multiversecore</groupId> <artifactId>Multiverse-Core</artifactId>
<version>2.5</version> <type>jar</type> <scope>provided</scope> <exclusions>
<exclusion> <groupId>org.bukkit</groupId> <artifactId>bukkit</artifactId>
</exclusion> <exclusion> <groupId>org.bukkit</groupId> <artifactId>craftbukkit</artifactId>
</exclusion> <exclusion> <artifactId>AllPay</artifactId> <groupId>com.fernferret.allpay</groupId>
</exclusion> <exclusion> <artifactId>Vault</artifactId> <groupId>net.milkbowl.vault</groupId>
</exclusion> <exclusion> <artifactId>CommandHandler</artifactId> <groupId>com.pneumaticraft.commandhandler</groupId>
</exclusion> <exclusion> <artifactId>SerializationConfig</artifactId> <groupId>me.main__.util</groupId>
</exclusion> <exclusion> <artifactId>Logging</artifactId> <groupId>com.dumptruckman.minecraft</groupId>
</exclusion> <exclusion> <artifactId>metrics</artifactId> <groupId>org.mcstats.bukkit</groupId>
</exclusion> <exclusion> <artifactId>buscript</artifactId> <groupId>com.dumptruckman.minecraft</groupId>
</exclusion> <exclusion> <artifactId>junit</artifactId> <groupId>junit</groupId>
</exclusion> </exclusions> <optional>true</optional> </dependency> Essentials
plugin <dependency> <groupId>net.ess3</groupId> <artifactId>EssentialsX</artifactId>
<version>2.0.1-SNAPSHOT</version> <scope>provided</scope> <exclusions> <exclusion>
<groupId>org.spigotmc</groupId> <artifactId>spigot-api</artifactId> </exclusion>
</exclusions> <optional>true</optional> </dependency> Anti PvPLogging plugin,
https://github.com/MinelinkNetwork/CombatTagPlus <dependency> <groupId>net.minelink</groupId>
<artifactId>CombatTagPlus</artifactId> <version>1.2.1-SNAPSHOT</version>
<scope>provided</scope> <exclusions> <exclusion> <groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId> </exclusion> <exclusion> <groupId>org.bukkit</groupId>
<artifactId>craftbukkit</artifactId> </exclusion> <exclusion> <artifactId>CombatTagPlusHook</artifactId>
<groupId>net.minelink</groupId> </exclusion> <exclusion> <artifactId>CombatTagPlusFactions-v1_6</artifactId>
<groupId>net.minelink</groupId> </exclusion> <exclusion> <artifactId>CombatTagPlusCompat-v1_7_R3</artifactId>
<groupId>net.minelink</groupId> </exclusion> <exclusion> <artifactId>CombatTagPlusFactions-v1_8</artifactId>
<groupId>net.minelink</groupId> </exclusion> <exclusion> <artifactId>CombatTagPlusCompat-v1_7_R4</artifactId>
<groupId>net.minelink</groupId> </exclusion> <exclusion> <artifactId>CombatTagPlusWG-v5</artifactId>
<groupId>net.minelink</groupId> </exclusion> <exclusion> <artifactId>CombatTagPlusWG-v6</artifactId>
<groupId>net.minelink</groupId> </exclusion> <exclusion> <artifactId>CombatTagPlusCompat-API</artifactId>
<groupId>net.minelink</groupId> </exclusion> <exclusion> <artifactId>CombatTagPlusFactions-v2_6</artifactId>
<groupId>net.minelink</groupId> </exclusion> <exclusion> <artifactId>CombatTagPlusCompat-v1_8_R3</artifactId>
<groupId>net.minelink</groupId> </exclusion> <exclusion> <artifactId>CombatTagPlusFactions-v2_7</artifactId>
<groupId>net.minelink</groupId> </exclusion> <exclusion> <artifactId>CombatTagPlusCompat-v1_8_R2</artifactId>
<groupId>net.minelink</groupId> </exclusion> <exclusion> <artifactId>CombatTagPlusCompat-v1_8_R1</artifactId>
<groupId>net.minelink</groupId> </exclusion> <exclusion> <artifactId>metrics-lite</artifactId>
<groupId>org.mcstats.bukkit</groupId> </exclusion> </exclusions> <optional>true</optional>
</dependency> XAuth, another authentication plugin, required by the database
converter <dependency> <groupId>de.luricos.bukkit</groupId> <artifactId>xAuth</artifactId>
<version>2.6</version> <scope>provided</scope> <exclusions> <exclusion> <groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId> </exclusion> <exclusion> <groupId>org.bukkit</groupId>
<artifactId>craftbukkit</artifactId> </exclusion> <exclusion> <artifactId>updater</artifactId>
<groupId>net.gravitydevelopment.updater</groupId> </exclusion> <exclusion>
<artifactId>lombok</artifactId> <groupId>org.projectlombok</groupId> </exclusion>
<exclusion> <artifactId>EssentialsGroupManager</artifactId> <groupId>net.ess3</groupId>
</exclusion> <exclusion> <artifactId>PermissionsEx</artifactId> <groupId>ru.tehkode</groupId>
</exclusion> <exclusion> <artifactId>AccountsClient</artifactId> <groupId>com.mojang</groupId>
</exclusion> <exclusion> <artifactId>log4j-core</artifactId> <groupId>org.apache.logging.log4j</groupId>
</exclusion> </exclusions> <optional>true</optional> </dependency> -->
</dependencies> </dependencies>
</project> </project>

View File

@ -163,7 +163,7 @@ public class AuthMe extends JavaPlugin {
final RegisteredServiceProvider<Permission> permissionProvider = server.getServicesManager().getRegistration(net.milkbowl.vault.permission.Permission.class); final RegisteredServiceProvider<Permission> permissionProvider = server.getServicesManager().getRegistration(net.milkbowl.vault.permission.Permission.class);
if (permissionProvider != null) { if (permissionProvider != null) {
permission = permissionProvider.getProvider(); permission = permissionProvider.getProvider();
ConsoleLogger.info("发现 Vault 使用经济系统: " + permission.getName()); ConsoleLogger.info("发现 Vault 使用权限系统: " + permission.getName());
} else { } else {
ConsoleLogger.showError("发现 Vault, 但是 Vault 未找到权限系统..."); ConsoleLogger.showError("发现 Vault, 但是 Vault 未找到权限系统...");
} }

View File

@ -89,7 +89,7 @@ public class Utils {
if (lookupService != null) { if (lookupService != null) {
return true; 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"); final File file = new File(Settings.APLUGIN_FOLDER, "GeoIP.dat");
try { try {
if (file.exists()) { if (file.exists()) {

View File

@ -30,7 +30,7 @@ public class JsonCache {
public JsonCache() { public JsonCache() {
cacheDir = Settings.CACHE_FOLDER; cacheDir = Settings.CACHE_FOLDER;
if (!cacheDir.exists() && !cacheDir.isDirectory() && !cacheDir.mkdir()) { if (!cacheDir.exists() && !cacheDir.isDirectory() && !cacheDir.mkdir()) {
ConsoleLogger.showError("Failed to create cache directory."); ConsoleLogger.showError("创建缓存目录失败.");
} }
gson = new GsonBuilder() gson = new GsonBuilder()
.registerTypeAdapter(DataFileCache.class, new PlayerDataSerializer()) .registerTypeAdapter(DataFileCache.class, new PlayerDataSerializer())
@ -39,7 +39,7 @@ public class JsonCache {
.create(); .create();
} }
public void createCache(Player player, DataFileCache playerData) { public void createCache(final Player player, final DataFileCache playerData) {
if (player == null) { if (player == null) {
return; return;
} }
@ -51,7 +51,7 @@ public class JsonCache {
path = player.getName().toLowerCase(); 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()) { if (file.exists()) {
return; return;
} }
@ -60,26 +60,26 @@ public class JsonCache {
} }
try { try {
String data = gson.toJson(playerData); final String data = gson.toJson(playerData);
Files.touch(file); Files.touch(file);
Files.write(data, file, Charsets.UTF_8); Files.write(data, file, Charsets.UTF_8);
} catch (IOException e) { } catch (final IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
public boolean doesCacheExist(Player player) { public boolean doesCacheExist(final Player player) {
String path; String path;
try { try {
path = player.getUniqueId().toString(); path = player.getUniqueId().toString();
} catch (Exception | Error e) { } catch (Exception | Error e) {
path = player.getName().toLowerCase(); 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(); return file.exists();
} }
public DataFileCache readCache(Player player) { public DataFileCache readCache(final Player player) {
String path; String path;
try { try {
path = player.getUniqueId().toString(); path = player.getUniqueId().toString();
@ -87,40 +87,40 @@ public class JsonCache {
path = player.getName().toLowerCase(); 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()) { if (!file.exists()) {
return null; return null;
} }
try { try {
String str = Files.toString(file, Charsets.UTF_8); final String str = Files.toString(file, Charsets.UTF_8);
return gson.fromJson(str, DataFileCache.class); return gson.fromJson(str, DataFileCache.class);
} catch (Exception e) { } catch (final Exception e) {
e.printStackTrace(); e.printStackTrace();
return null; return null;
} }
} }
public void removeCache(Player player) { public void removeCache(final Player player) {
String path; String path;
try { try {
path = player.getUniqueId().toString(); path = player.getUniqueId().toString();
} catch (Exception | Error e) { } catch (Exception | Error e) {
path = player.getName().toLowerCase(); path = player.getName().toLowerCase();
} }
File file = new File(cacheDir, path); final File file = new File(cacheDir, path);
if (file.exists()) { if (file.exists()) {
Utils.purgeDirectory(file); Utils.purgeDirectory(file);
if (!file.delete()) { if (!file.delete()) {
ConsoleLogger.showError("Failed to remove" + player.getName() + "cache."); ConsoleLogger.showError("移除玩家 " + player.getName() + " 缓存数据失败.");
} }
} }
} }
private static class PlayerDataDeserializer implements JsonDeserializer<DataFileCache> { private static class PlayerDataDeserializer implements JsonDeserializer<DataFileCache> {
@Override @Override
public DataFileCache deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException { public DataFileCache deserialize(final JsonElement jsonElement, final Type type, final JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
JsonObject jsonObject = jsonElement.getAsJsonObject(); final JsonObject jsonObject = jsonElement.getAsJsonObject();
if (jsonObject == null) { if (jsonObject == null) {
return null; return null;
} }
@ -145,12 +145,11 @@ public class JsonCache {
private class PlayerDataSerializer implements JsonSerializer<DataFileCache> { private class PlayerDataSerializer implements JsonSerializer<DataFileCache> {
@Override @Override
public JsonElement serialize(DataFileCache dataFileCache, Type type, JsonSerializationContext jsonSerializationContext) { public JsonElement serialize(final DataFileCache dataFileCache, final Type type, final JsonSerializationContext jsonSerializationContext) {
JsonObject jsonObject = new JsonObject(); final JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("group", dataFileCache.getGroup()); jsonObject.addProperty("group", dataFileCache.getGroup());
jsonObject.addProperty("operator", dataFileCache.getOperator()); jsonObject.addProperty("operator", dataFileCache.getOperator());
jsonObject.addProperty("flying", dataFileCache.isFlying()); jsonObject.addProperty("flying", dataFileCache.isFlying());
return jsonObject; return jsonObject;
} }
} }

View File

@ -29,16 +29,16 @@ public class FlatFile implements DataSource {
* :LASTPOSZ:LASTPOSWORLD PLAYERNAME:HASHSUM:IP:LOGININMILLIESECONDS * :LASTPOSZ:LASTPOSWORLD PLAYERNAME:HASHSUM:IP:LOGININMILLIESECONDS
* PLAYERNAME:HASHSUM:IP PLAYERNAME:HASHSUM * PLAYERNAME:HASHSUM:IP PLAYERNAME:HASHSUM
*/ */
private File source; private final File source;
public FlatFile() { public FlatFile() {
source = Settings.AUTH_FILE; source = Settings.AUTH_FILE;
try { try {
source.createNewFile(); source.createNewFile();
} catch (IOException e) { } catch (final IOException e) {
ConsoleLogger.showError(e.getMessage()); ConsoleLogger.showError(e.getMessage());
if (Settings.isStopEnabled) { if (Settings.isStopEnabled) {
ConsoleLogger.showError("Can't use FLAT FILE... SHUTDOWN..."); ConsoleLogger.showError("无法读取用户数据文件... 关闭服务器...");
AuthMe.getInstance().getServer().shutdown(); AuthMe.getInstance().getServer().shutdown();
} }
if (!Settings.isStopEnabled) { if (!Settings.isStopEnabled) {
@ -49,16 +49,16 @@ public class FlatFile implements DataSource {
} }
@Override @Override
public List<String> autoPurgeDatabase(long until) { public List<String> autoPurgeDatabase(final long until) {
BufferedReader br = null; BufferedReader br = null;
BufferedWriter bw = null; BufferedWriter bw = null;
ArrayList<String> lines = new ArrayList<>(); final ArrayList<String> lines = new ArrayList<>();
List<String> cleared = new ArrayList<>(); final List<String> cleared = new ArrayList<>();
try { try {
br = new BufferedReader(new FileReader(source)); br = new BufferedReader(new FileReader(source));
String line; String line;
while ((line = br.readLine()) != null) { while ((line = br.readLine()) != null) {
String[] args = line.split(":"); final String[] args = line.split(":");
if (args.length >= 4) { if (args.length >= 4) {
if (Long.parseLong(args[3]) >= until) { if (Long.parseLong(args[3]) >= until) {
lines.add(line); lines.add(line);
@ -68,26 +68,26 @@ public class FlatFile implements DataSource {
cleared.add(args[0]); cleared.add(args[0]);
} }
bw = new BufferedWriter(new FileWriter(source)); bw = new BufferedWriter(new FileWriter(source));
for (String l : lines) { for (final String l : lines) {
bw.write(l + "\n"); bw.write(l + "\n");
} }
} catch (FileNotFoundException ex) { } catch (final FileNotFoundException ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return cleared; return cleared;
} catch (IOException ex) { } catch (final IOException ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return cleared; return cleared;
} finally { } finally {
if (br != null) { if (br != null) {
try { try {
br.close(); br.close();
} catch (IOException ex) { } catch (final IOException ex) {
} }
} }
if (bw != null) { if (bw != null) {
try { try {
bw.close(); bw.close();
} catch (IOException ex) { } catch (final IOException ex) {
} }
} }
} }
@ -107,14 +107,14 @@ public class FlatFile implements DataSource {
while ((br.readLine()) != null) { while ((br.readLine()) != null) {
result++; result++;
} }
} catch (Exception ex) { } catch (final Exception ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return result; return result;
} finally { } finally {
if (br != null) { if (br != null) {
try { try {
br.close(); br.close();
} catch (IOException ex) { } catch (final IOException ex) {
} }
} }
} }
@ -124,12 +124,12 @@ public class FlatFile implements DataSource {
@Override @Override
public List<PlayerAuth> getAllAuths() { public List<PlayerAuth> getAllAuths() {
BufferedReader br = null; BufferedReader br = null;
List<PlayerAuth> auths = new ArrayList<>(); final List<PlayerAuth> auths = new ArrayList<>();
try { try {
br = new BufferedReader(new FileReader(source)); br = new BufferedReader(new FileReader(source));
String line; String line;
while ((line = br.readLine()) != null) { while ((line = br.readLine()) != null) {
String[] args = line.split(":"); final String[] args = line.split(":");
switch (args.length) { switch (args.length) {
case 2: case 2:
auths.add(new PlayerAuth(args[0], args[1], "192.168.0.1", 0, "your@email.com", args[0])); 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])); auths.add(new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3]), "your@email.com", args[0]));
break; break;
case 7: 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]), auths.add(new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double
"unavailableworld", "your@email.com", args[0])); .parseDouble(args[6]), "unavailableworld", "your@email.com", args[0]));
break; break;
case 8: 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], auths.add(new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double
"your@email.com", args[0])); .parseDouble(args[6]), args[7], "your@email.com", args[0]));
break; break;
case 9: 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], auths.add(new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double
args[8], args[0])); .parseDouble(args[6]), args[7], args[8], args[0]));
break; break;
} }
} }
} catch (FileNotFoundException ex) { } catch (final FileNotFoundException ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return auths; return auths;
} catch (IOException ex) { } catch (final IOException ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return auths; return auths;
} finally { } finally {
if (br != null) { if (br != null) {
try { try {
br.close(); br.close();
} catch (IOException ex) { } catch (final IOException ex) {
} }
} }
} }
@ -172,103 +172,103 @@ public class FlatFile implements DataSource {
} }
@Override @Override
public List<String> getAllAuthsByEmail(String email) { public List<String> getAllAuthsByEmail(final String email) {
BufferedReader br = null; BufferedReader br = null;
List<String> countEmail = new ArrayList<>(); final List<String> countEmail = new ArrayList<>();
try { try {
br = new BufferedReader(new FileReader(source)); br = new BufferedReader(new FileReader(source));
String line; String line;
while ((line = br.readLine()) != null) { while ((line = br.readLine()) != null) {
String[] args = line.split(":"); final String[] args = line.split(":");
if (args.length > 8 && args[8].equals(email)) { if (args.length > 8 && args[8].equals(email)) {
countEmail.add(args[0]); countEmail.add(args[0]);
} }
} }
return countEmail; return countEmail;
} catch (FileNotFoundException ex) { } catch (final FileNotFoundException ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return new ArrayList<>(); return new ArrayList<>();
} catch (IOException ex) { } catch (final IOException ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return new ArrayList<>(); return new ArrayList<>();
} finally { } finally {
if (br != null) { if (br != null) {
try { try {
br.close(); br.close();
} catch (IOException ex) { } catch (final IOException ex) {
} }
} }
} }
} }
@Override @Override
public List<String> getAllAuthsByIp(String ip) { public List<String> getAllAuthsByIp(final String ip) {
BufferedReader br = null; BufferedReader br = null;
List<String> countIp = new ArrayList<>(); final List<String> countIp = new ArrayList<>();
try { try {
br = new BufferedReader(new FileReader(source)); br = new BufferedReader(new FileReader(source));
String line; String line;
while ((line = br.readLine()) != null) { while ((line = br.readLine()) != null) {
String[] args = line.split(":"); final String[] args = line.split(":");
if (args.length > 3 && args[2].equals(ip)) { if (args.length > 3 && args[2].equals(ip)) {
countIp.add(args[0]); countIp.add(args[0]);
} }
} }
return countIp; return countIp;
} catch (FileNotFoundException ex) { } catch (final FileNotFoundException ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return new ArrayList<>(); return new ArrayList<>();
} catch (IOException ex) { } catch (final IOException ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return new ArrayList<>(); return new ArrayList<>();
} finally { } finally {
if (br != null) { if (br != null) {
try { try {
br.close(); br.close();
} catch (IOException ex) { } catch (final IOException ex) {
} }
} }
} }
} }
@Override @Override
public List<String> getAllAuthsByName(PlayerAuth auth) { public List<String> getAllAuthsByName(final PlayerAuth auth) {
BufferedReader br = null; BufferedReader br = null;
List<String> countIp = new ArrayList<>(); final List<String> countIp = new ArrayList<>();
try { try {
br = new BufferedReader(new FileReader(source)); br = new BufferedReader(new FileReader(source));
String line; String line;
while ((line = br.readLine()) != null) { while ((line = br.readLine()) != null) {
String[] args = line.split(":"); final String[] args = line.split(":");
if (args.length > 3 && args[2].equals(auth.getIp())) { if (args.length > 3 && args[2].equals(auth.getIp())) {
countIp.add(args[0]); countIp.add(args[0]);
} }
} }
return countIp; return countIp;
} catch (FileNotFoundException ex) { } catch (final FileNotFoundException ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return new ArrayList<>(); return new ArrayList<>();
} catch (IOException ex) { } catch (final IOException ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return new ArrayList<>(); return new ArrayList<>();
} finally { } finally {
if (br != null) { if (br != null) {
try { try {
br.close(); br.close();
} catch (IOException ex) { } catch (final IOException ex) {
} }
} }
} }
} }
@Override @Override
public synchronized PlayerAuth getAuth(String user) { public synchronized PlayerAuth getAuth(final String user) {
BufferedReader br = null; BufferedReader br = null;
try { try {
br = new BufferedReader(new FileReader(source)); br = new BufferedReader(new FileReader(source));
String line; String line;
while ((line = br.readLine()) != null) { while ((line = br.readLine()) != null) {
String[] args = line.split(":"); final String[] args = line.split(":");
if (args[0].equalsIgnoreCase(user)) { if (args[0].equalsIgnoreCase(user)) {
switch (args.length) { switch (args.length) {
case 2: case 2:
@ -278,28 +278,28 @@ public class FlatFile implements DataSource {
case 4: case 4:
return new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3]), "your@email.com", args[0]); return new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3]), "your@email.com", args[0]);
case 7: 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]), return new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double
"unavailableworld", "your@email.com", args[0]); .parseDouble(args[6]), "unavailableworld", "your@email.com", args[0]);
case 8: 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], return new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double
"your@email.com", args[0]); .parseDouble(args[6]), args[7], "your@email.com", args[0]);
case 9: 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], return new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double
args[8], args[0]); .parseDouble(args[6]), args[7], args[8], args[0]);
} }
} }
} }
} catch (FileNotFoundException ex) { } catch (final FileNotFoundException ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return null; return null;
} catch (IOException ex) { } catch (final IOException ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return null; return null;
} finally { } finally {
if (br != null) { if (br != null) {
try { try {
br.close(); br.close();
} catch (IOException ex) { } catch (final IOException ex) {
} }
} }
} }
@ -307,30 +307,30 @@ public class FlatFile implements DataSource {
} }
@Override @Override
public int getIps(String ip) { public int getIps(final String ip) {
BufferedReader br = null; BufferedReader br = null;
int countIp = 0; int countIp = 0;
try { try {
br = new BufferedReader(new FileReader(source)); br = new BufferedReader(new FileReader(source));
String line; String line;
while ((line = br.readLine()) != null) { while ((line = br.readLine()) != null) {
String[] args = line.split(":"); final String[] args = line.split(":");
if (args.length > 3 && args[2].equals(ip)) { if (args.length > 3 && args[2].equals(ip)) {
countIp++; countIp++;
} }
} }
return countIp; return countIp;
} catch (FileNotFoundException ex) { } catch (final FileNotFoundException ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return 0; return 0;
} catch (IOException ex) { } catch (final IOException ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return 0; return 0;
} finally { } finally {
if (br != null) { if (br != null) {
try { try {
br.close(); br.close();
} catch (IOException ex) { } catch (final IOException ex) {
} }
} }
} }
@ -347,28 +347,28 @@ public class FlatFile implements DataSource {
} }
@Override @Override
public synchronized boolean isAuthAvailable(String user) { public synchronized boolean isAuthAvailable(final String user) {
BufferedReader br = null; BufferedReader br = null;
try { try {
br = new BufferedReader(new FileReader(source)); br = new BufferedReader(new FileReader(source));
String line; String line;
while ((line = br.readLine()) != null) { while ((line = br.readLine()) != null) {
String[] args = line.split(":"); final String[] args = line.split(":");
if (args.length > 1 && args[0].equalsIgnoreCase(user)) { if (args.length > 1 && args[0].equalsIgnoreCase(user)) {
return true; return true;
} }
} }
} catch (FileNotFoundException ex) { } catch (final FileNotFoundException ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return false; return false;
} catch (IOException ex) { } catch (final IOException ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return false; return false;
} finally { } finally {
if (br != null) { if (br != null) {
try { try {
br.close(); br.close();
} catch (IOException ex) { } catch (final IOException ex) {
} }
} }
} }
@ -376,20 +376,20 @@ public class FlatFile implements DataSource {
} }
@Override @Override
public boolean isLogged(String user) { public boolean isLogged(final String user) {
return PlayerCache.getInstance().isAuthenticated(user); return PlayerCache.getInstance().isAuthenticated(user);
} }
@Override @Override
public void purgeBanned(List<String> banned) { public void purgeBanned(final List<String> banned) {
BufferedReader br = null; BufferedReader br = null;
BufferedWriter bw = null; BufferedWriter bw = null;
ArrayList<String> lines = new ArrayList<>(); final ArrayList<String> lines = new ArrayList<>();
try { try {
br = new BufferedReader(new FileReader(source)); br = new BufferedReader(new FileReader(source));
String line; String line;
while ((line = br.readLine()) != null) { while ((line = br.readLine()) != null) {
String[] args = line.split(":"); final String[] args = line.split(":");
try { try {
if (banned.contains(args[0])) { if (banned.contains(args[0])) {
lines.add(line); lines.add(line);
@ -398,26 +398,26 @@ public class FlatFile implements DataSource {
} }
} }
bw = new BufferedWriter(new FileWriter(source)); bw = new BufferedWriter(new FileWriter(source));
for (String l : lines) { for (final String l : lines) {
bw.write(l + "\n"); bw.write(l + "\n");
} }
} catch (FileNotFoundException ex) { } catch (final FileNotFoundException ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return; return;
} catch (IOException ex) { } catch (final IOException ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return; return;
} finally { } finally {
if (br != null) { if (br != null) {
try { try {
br.close(); br.close();
} catch (IOException ex) { } catch (final IOException ex) {
} }
} }
if (bw != null) { if (bw != null) {
try { try {
bw.close(); bw.close();
} catch (IOException ex) { } catch (final IOException ex) {
} }
} }
} }
@ -425,16 +425,16 @@ public class FlatFile implements DataSource {
} }
@Override @Override
public int purgeDatabase(long until) { public int purgeDatabase(final long until) {
BufferedReader br = null; BufferedReader br = null;
BufferedWriter bw = null; BufferedWriter bw = null;
ArrayList<String> lines = new ArrayList<>(); final ArrayList<String> lines = new ArrayList<>();
int cleared = 0; int cleared = 0;
try { try {
br = new BufferedReader(new FileReader(source)); br = new BufferedReader(new FileReader(source));
String line; String line;
while ((line = br.readLine()) != null) { while ((line = br.readLine()) != null) {
String[] args = line.split(":"); final String[] args = line.split(":");
if (args.length >= 4) { if (args.length >= 4) {
if (Long.parseLong(args[3]) >= until) { if (Long.parseLong(args[3]) >= until) {
lines.add(line); lines.add(line);
@ -444,26 +444,26 @@ public class FlatFile implements DataSource {
cleared++; cleared++;
} }
bw = new BufferedWriter(new FileWriter(source)); bw = new BufferedWriter(new FileWriter(source));
for (String l : lines) { for (final String l : lines) {
bw.write(l + "\n"); bw.write(l + "\n");
} }
} catch (FileNotFoundException ex) { } catch (final FileNotFoundException ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return cleared; return cleared;
} catch (IOException ex) { } catch (final IOException ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return cleared; return cleared;
} finally { } finally {
if (br != null) { if (br != null) {
try { try {
br.close(); br.close();
} catch (IOException ex) { } catch (final IOException ex) {
} }
} }
if (bw != null) { if (bw != null) {
try { try {
bw.close(); bw.close();
} catch (IOException ex) { } catch (final IOException ex) {
} }
} }
} }
@ -479,43 +479,43 @@ public class FlatFile implements DataSource {
} }
@Override @Override
public synchronized boolean removeAuth(String user) { public synchronized boolean removeAuth(final String user) {
if (!isAuthAvailable(user)) { if (!isAuthAvailable(user)) {
return false; return false;
} }
BufferedReader br = null; BufferedReader br = null;
BufferedWriter bw = null; BufferedWriter bw = null;
ArrayList<String> lines = new ArrayList<>(); final ArrayList<String> lines = new ArrayList<>();
try { try {
br = new BufferedReader(new FileReader(source)); br = new BufferedReader(new FileReader(source));
String line; String line;
while ((line = br.readLine()) != null) { while ((line = br.readLine()) != null) {
String[] args = line.split(":"); final String[] args = line.split(":");
if (args.length > 1 && !args[0].equals(user)) { if (args.length > 1 && !args[0].equals(user)) {
lines.add(line); lines.add(line);
} }
} }
bw = new BufferedWriter(new FileWriter(source)); bw = new BufferedWriter(new FileWriter(source));
for (String l : lines) { for (final String l : lines) {
bw.write(l + "\n"); bw.write(l + "\n");
} }
} catch (FileNotFoundException ex) { } catch (final FileNotFoundException ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return false; return false;
} catch (IOException ex) { } catch (final IOException ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return false; return false;
} finally { } finally {
if (br != null) { if (br != null) {
try { try {
br.close(); br.close();
} catch (IOException ex) { } catch (final IOException ex) {
} }
} }
if (bw != null) { if (bw != null) {
try { try {
bw.close(); bw.close();
} catch (IOException ex) { } catch (final IOException ex) {
} }
} }
} }
@ -523,7 +523,7 @@ public class FlatFile implements DataSource {
} }
@Override @Override
public synchronized boolean saveAuth(PlayerAuth auth) { public synchronized boolean saveAuth(final PlayerAuth auth) {
if (isAuthAvailable(auth.getNickname())) { if (isAuthAvailable(auth.getNickname())) {
return false; return false;
} }
@ -532,14 +532,14 @@ public class FlatFile implements DataSource {
bw = new BufferedWriter(new FileWriter(source, true)); bw = new BufferedWriter(new FileWriter(source, true));
bw.write(auth.getNickname() + ":" + auth.getHash() + ":" + auth.getIp() + ":" + auth.getLastLogin() + ":" + auth.getQuitLocX() + ":" + auth.getQuitLocY() + ":" + auth.getQuitLocZ() + ":" bw.write(auth.getNickname() + ":" + auth.getHash() + ":" + auth.getIp() + ":" + auth.getLastLogin() + ":" + auth.getQuitLocX() + ":" + auth.getQuitLocY() + ":" + auth.getQuitLocZ() + ":"
+ auth.getWorld() + ":" + auth.getEmail() + "\n"); + auth.getWorld() + ":" + auth.getEmail() + "\n");
} catch (IOException ex) { } catch (final IOException ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return false; return false;
} finally { } finally {
if (bw != null) { if (bw != null) {
try { try {
bw.close(); bw.close();
} catch (IOException ex) { } catch (final IOException ex) {
} }
} }
} }
@ -547,15 +547,15 @@ public class FlatFile implements DataSource {
} }
@Override @Override
public void setLogged(String user) { public void setLogged(final String user) {
} }
@Override @Override
public void setUnlogged(String user) { public void setUnlogged(final String user) {
} }
@Override @Override
public boolean updateEmail(PlayerAuth auth) { public boolean updateEmail(final PlayerAuth auth) {
if (!isAuthAvailable(auth.getNickname())) { if (!isAuthAvailable(auth.getNickname())) {
return false; return false;
} }
@ -565,24 +565,24 @@ public class FlatFile implements DataSource {
br = new BufferedReader(new FileReader(source)); br = new BufferedReader(new FileReader(source));
String line = ""; String line = "";
while ((line = br.readLine()) != null) { while ((line = br.readLine()) != null) {
String[] args = line.split(":"); final String[] args = line.split(":");
if (args[0].equals(auth.getNickname())) { 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], 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
auth.getEmail(), args[0]); .getEmail(), args[0]);
break; break;
} }
} }
} catch (FileNotFoundException ex) { } catch (final FileNotFoundException ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return false; return false;
} catch (IOException ex) { } catch (final IOException ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return false; return false;
} finally { } finally {
if (br != null) { if (br != null) {
try { try {
br.close(); br.close();
} catch (IOException ex) { } catch (final IOException ex) {
} }
} }
} }
@ -594,15 +594,15 @@ public class FlatFile implements DataSource {
} }
@Override @Override
public void updateName(String oldone, String newone) { public void updateName(final String oldone, final String newone) {
PlayerAuth auth = this.getAuth(oldone); final PlayerAuth auth = this.getAuth(oldone);
auth.setName(newone); auth.setName(newone);
this.saveAuth(auth); this.saveAuth(auth);
this.removeAuth(oldone); this.removeAuth(oldone);
} }
@Override @Override
public synchronized boolean updatePassword(PlayerAuth auth) { public synchronized boolean updatePassword(final PlayerAuth auth) {
if (!isAuthAvailable(auth.getNickname())) { if (!isAuthAvailable(auth.getNickname())) {
return false; return false;
} }
@ -612,7 +612,7 @@ public class FlatFile implements DataSource {
br = new BufferedReader(new FileReader(source)); br = new BufferedReader(new FileReader(source));
String line; String line;
while ((line = br.readLine()) != null) { while ((line = br.readLine()) != null) {
String[] args = line.split(":"); final String[] args = line.split(":");
if (args[0].equals(auth.getNickname())) { if (args[0].equals(auth.getNickname())) {
switch (args.length) { switch (args.length) {
case 4: { case 4: {
@ -620,18 +620,18 @@ public class FlatFile implements DataSource {
break; break;
} }
case 7: { 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]), newAuth = new PlayerAuth(args[0], auth.getHash(), args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double
"world", "your@email.com", args[0]); .parseDouble(args[6]), "world", "your@email.com", args[0]);
break; break;
} }
case 8: { 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]), newAuth = new PlayerAuth(args[0], auth.getHash(), args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double
args[7], "your@email.com", args[0]); .parseDouble(args[6]), args[7], "your@email.com", args[0]);
break; break;
} }
case 9: { 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]), newAuth = new PlayerAuth(args[0], auth.getHash(), args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double
args[7], args[8], args[0]); .parseDouble(args[6]), args[7], args[8], args[0]);
break; break;
} }
default: { default: {
@ -642,17 +642,17 @@ public class FlatFile implements DataSource {
break; break;
} }
} }
} catch (FileNotFoundException ex) { } catch (final FileNotFoundException ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return false; return false;
} catch (IOException ex) { } catch (final IOException ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return false; return false;
} finally { } finally {
if (br != null) { if (br != null) {
try { try {
br.close(); br.close();
} catch (IOException ex) { } catch (final IOException ex) {
} }
} }
} }
@ -664,7 +664,7 @@ public class FlatFile implements DataSource {
} }
@Override @Override
public boolean updateQuitLoc(PlayerAuth auth) { public boolean updateQuitLoc(final PlayerAuth auth) {
if (!isAuthAvailable(auth.getNickname())) { if (!isAuthAvailable(auth.getNickname())) {
return false; return false;
} }
@ -674,23 +674,23 @@ public class FlatFile implements DataSource {
br = new BufferedReader(new FileReader(source)); br = new BufferedReader(new FileReader(source));
String line; String line;
while ((line = br.readLine()) != null) { while ((line = br.readLine()) != null) {
String[] args = line.split(":"); final String[] args = line.split(":");
if (args[0].equalsIgnoreCase(auth.getNickname())) { 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]); 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; break;
} }
} }
} catch (FileNotFoundException ex) { } catch (final FileNotFoundException ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return false; return false;
} catch (IOException ex) { } catch (final IOException ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return false; return false;
} finally { } finally {
if (br != null) { if (br != null) {
try { try {
br.close(); br.close();
} catch (IOException ex) { } catch (final IOException ex) {
} }
} }
} }
@ -702,12 +702,12 @@ public class FlatFile implements DataSource {
} }
@Override @Override
public boolean updateSalt(PlayerAuth auth) { public boolean updateSalt(final PlayerAuth auth) {
return false; return false;
} }
@Override @Override
public boolean updateSession(PlayerAuth auth) { public boolean updateSession(final PlayerAuth auth) {
if (!isAuthAvailable(auth.getNickname())) { if (!isAuthAvailable(auth.getNickname())) {
return false; return false;
} }
@ -717,7 +717,7 @@ public class FlatFile implements DataSource {
br = new BufferedReader(new FileReader(source)); br = new BufferedReader(new FileReader(source));
String line; String line;
while ((line = br.readLine()) != null) { while ((line = br.readLine()) != null) {
String[] args = line.split(":"); final String[] args = line.split(":");
if (args[0].equalsIgnoreCase(auth.getNickname())) { if (args[0].equalsIgnoreCase(auth.getNickname())) {
switch (args.length) { switch (args.length) {
case 4: { case 4: {
@ -725,18 +725,18 @@ public class FlatFile implements DataSource {
break; break;
} }
case 7: { 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", newAuth = new PlayerAuth(args[0], args[1], auth.getIp(), auth.getLastLogin(), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double
"your@email.com", args[0]); .parseDouble(args[6]), "world", "your@email.com", args[0]);
break; break;
} }
case 8: { 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], newAuth = new PlayerAuth(args[0], args[1], auth.getIp(), auth.getLastLogin(), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double
"your@email.com", args[0]); .parseDouble(args[6]), args[7], "your@email.com", args[0]);
break; break;
} }
case 9: { 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], newAuth = new PlayerAuth(args[0], args[1], auth.getIp(), auth.getLastLogin(), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double
args[8], args[0]); .parseDouble(args[6]), args[7], args[8], args[0]);
break; break;
} }
default: { default: {
@ -747,17 +747,17 @@ public class FlatFile implements DataSource {
break; break;
} }
} }
} catch (FileNotFoundException ex) { } catch (final FileNotFoundException ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return false; return false;
} catch (IOException ex) { } catch (final IOException ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return false; return false;
} finally { } finally {
if (br != null) { if (br != null) {
try { try {
br.close(); br.close();
} catch (IOException ex) { } catch (final IOException ex) {
} }
} }
} }

View File

@ -21,29 +21,29 @@ import fr.xephi.authme.settings.Settings;
public class MySQL implements DataSource { public class MySQL implements DataSource {
private String columnEmail; private final String columnEmail;
private String columnGroup; private final String columnGroup;
private String columnID; private final String columnID;
private String columnIp; private final String columnIp;
private String columnLastLogin; private final String columnLastLogin;
private String columnLogged; private final String columnLogged;
private String columnName; private final String columnName;
private List<String> columnOthers; private final List<String> columnOthers;
private String columnPassword; private final String columnPassword;
private String columnRealName; private final String columnRealName;
private String columnSalt; private final String columnSalt;
private String database; private final String database;
private HikariDataSource ds; private HikariDataSource ds;
private String host; private final String host;
private String lastlocWorld; private final String lastlocWorld;
private String lastlocX; private final String lastlocX;
private String lastlocY; private final String lastlocY;
private String lastlocZ; private final String lastlocZ;
private int maxConnections; private final int maxConnections;
private String password; private final String password;
private String port; private final String port;
private String tableName; private final String tableName;
private String username; private final String username;
public MySQL() throws ClassNotFoundException, SQLException, PoolInitializationException { public MySQL() throws ClassNotFoundException, SQLException, PoolInitializationException {
this.host = Settings.getMySQLHost; this.host = Settings.getMySQLHost;
@ -72,38 +72,34 @@ public class MySQL implements DataSource {
// Set the connection arguments (and check if connection is ok) // Set the connection arguments (and check if connection is ok)
try { try {
this.setConnectionArguments(); this.setConnectionArguments();
} catch (RuntimeException e) { } catch (final RuntimeException e) {
if (e instanceof IllegalArgumentException) { if (e instanceof IllegalArgumentException) {
ConsoleLogger.showError("Invalid database arguments! Please check your configuration!"); ConsoleLogger.showError("错误的数据库信息! 请检查您的配置是否正确!");
ConsoleLogger.showError("If this error persists, please report it to the developer! SHUTDOWN...");
throw new IllegalArgumentException(e);
} }
if (e instanceof PoolInitializationException) { if (e instanceof PoolInitializationException) {
ConsoleLogger.showError("Can't initialize database connection! Please check your configuration!"); ConsoleLogger.showError("无法初始化数据库连接池! 请检查您的配置是否正确!");
ConsoleLogger.showError("If this error persists, please report it to the developer! SHUTDOWN...");
throw new PoolInitializationException(e);
} }
ConsoleLogger.showError("Can't use the Hikari Connection Pool! Please, report this error to the developer! SHUTDOWN..."); ConsoleLogger.showError("MySQL数据库加载失败! 如果你认为配置文件没问题 请报告此错误给开发者! 关闭服务器...");
throw e; throw e;
} }
// Initialize the database // Initialize the database
try { try {
this.setupConnection(); this.setupConnection();
} catch (SQLException e) { } catch (final SQLException e) {
this.close(); this.close();
ConsoleLogger.showError("Can't initialize the MySQL database... Please check your database settings in the config.yml file! SHUTDOWN..."); ConsoleLogger.showError("无法初始化 MySQL 数据库连接池... 请检查您的配置是否正确! 关闭服务器...");
ConsoleLogger.showError("If this error persists, please report it to the developer! SHUTDOWN..."); ConsoleLogger.showError("如果你认为配置文件没问题 请报告此错误给开发者! 关闭服务器...");
throw e; throw e;
} }
} }
@Override @Override
public synchronized List<String> autoPurgeDatabase(long until) { public synchronized List<String> autoPurgeDatabase(final long until) {
Connection con = null; Connection con = null;
PreparedStatement pst = null; PreparedStatement pst = null;
ResultSet rs = null; ResultSet rs = null;
List<String> list = new ArrayList<>(); final List<String> list = new ArrayList<>();
try { try {
con = getConnection(); con = getConnection();
pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnLastLogin + "<?;"); pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnLastLogin + "<?;");
@ -117,7 +113,7 @@ public class MySQL implements DataSource {
pst.setLong(1, until); pst.setLong(1, until);
pst.executeUpdate(); pst.executeUpdate();
return list; return list;
} catch (Exception ex) { } catch (final Exception ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return new ArrayList<>(); return new ArrayList<>();
} finally { } finally {
@ -129,8 +125,9 @@ public class MySQL implements DataSource {
@Override @Override
public synchronized void close() { public synchronized void close() {
if (ds != null) if (ds != null) {
ds.close(); ds.close();
}
} }
@Override @Override
@ -146,7 +143,7 @@ public class MySQL implements DataSource {
if (rs != null && rs.next()) { if (rs != null && rs.next()) {
result = rs.getInt(1); result = rs.getInt(1);
} }
} catch (Exception ex) { } catch (final Exception ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return result; return result;
} finally { } finally {
@ -158,7 +155,7 @@ public class MySQL implements DataSource {
@Override @Override
public List<PlayerAuth> getAllAuths() { public List<PlayerAuth> getAllAuths() {
List<PlayerAuth> auths = new ArrayList<>(); final List<PlayerAuth> auths = new ArrayList<>();
Connection con = null; Connection con = null;
PreparedStatement pst = null; PreparedStatement pst = null;
ResultSet rs = null; ResultSet rs = null;
@ -168,22 +165,23 @@ public class MySQL implements DataSource {
rs = pst.executeQuery(); rs = pst.executeQuery();
while (rs.next()) { while (rs.next()) {
PlayerAuth pAuth; PlayerAuth pAuth;
int id = rs.getInt(columnID); final int id = rs.getInt(columnID);
if (rs.getString(columnIp).isEmpty() && rs.getString(columnIp) != null) { 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), pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), "192.168.0.1", rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs
rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName)); .getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName));
} else { } else {
if (!columnSalt.isEmpty()) { if (!columnSalt.isEmpty()) {
if (!columnGroup.isEmpty()) if (!columnGroup.isEmpty()) {
pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnSalt), rs.getInt(columnGroup), rs.getString(columnIp), pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnSalt), rs.getInt(columnGroup), rs.getString(columnIp), rs
rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), .getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs
rs.getString(columnRealName)); .getString(columnRealName));
else } else {
pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnSalt), rs.getString(columnIp), rs.getLong(columnLastLogin), pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnSalt), rs.getString(columnIp), rs.getLong(columnLastLogin), rs
rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName)); .getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName));
}
} else { } else {
pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnIp), rs.getLong(columnLastLogin), rs.getDouble(lastlocX), pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnIp), rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs
rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName)); .getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName));
} }
} }
if (Settings.getPasswordHash == HashAlgorithm.XENFORO) { if (Settings.getPasswordHash == HashAlgorithm.XENFORO) {
@ -192,15 +190,15 @@ public class MySQL implements DataSource {
pst.setInt(1, id); pst.setInt(1, id);
rsid = pst.executeQuery(); rsid = pst.executeQuery();
if (rsid.next()) { if (rsid.next()) {
Blob blob = rsid.getBlob("data"); final Blob blob = rsid.getBlob("data");
byte[] bytes = blob.getBytes(1, (int) blob.length()); final byte[] bytes = blob.getBytes(1, (int) blob.length());
pAuth.setHash(new String(bytes)); pAuth.setHash(new String(bytes));
} }
rsid.close(); rsid.close();
} }
auths.add(pAuth); auths.add(pAuth);
} }
} catch (Exception ex) { } catch (final Exception ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return auths; return auths;
} finally { } finally {
@ -212,11 +210,11 @@ public class MySQL implements DataSource {
} }
@Override @Override
public synchronized List<String> getAllAuthsByEmail(String email) { public synchronized List<String> getAllAuthsByEmail(final String email) {
Connection con = null; Connection con = null;
PreparedStatement pst = null; PreparedStatement pst = null;
ResultSet rs = null; ResultSet rs = null;
List<String> countEmail = new ArrayList<>(); final List<String> countEmail = new ArrayList<>();
try { try {
con = getConnection(); con = getConnection();
pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnEmail + "=?;"); pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnEmail + "=?;");
@ -226,7 +224,7 @@ public class MySQL implements DataSource {
countEmail.add(rs.getString(columnName)); countEmail.add(rs.getString(columnName));
} }
return countEmail; return countEmail;
} catch (Exception ex) { } catch (final Exception ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return new ArrayList<>(); return new ArrayList<>();
} finally { } finally {
@ -237,11 +235,11 @@ public class MySQL implements DataSource {
} }
@Override @Override
public synchronized List<String> getAllAuthsByIp(String ip) { public synchronized List<String> getAllAuthsByIp(final String ip) {
Connection con = null; Connection con = null;
PreparedStatement pst = null; PreparedStatement pst = null;
ResultSet rs = null; ResultSet rs = null;
List<String> countIp = new ArrayList<>(); final List<String> countIp = new ArrayList<>();
try { try {
con = getConnection(); con = getConnection();
pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnIp + "=?;"); pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnIp + "=?;");
@ -251,7 +249,7 @@ public class MySQL implements DataSource {
countIp.add(rs.getString(columnName)); countIp.add(rs.getString(columnName));
} }
return countIp; return countIp;
} catch (Exception ex) { } catch (final Exception ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return new ArrayList<>(); return new ArrayList<>();
} finally { } finally {
@ -262,11 +260,11 @@ public class MySQL implements DataSource {
} }
@Override @Override
public synchronized List<String> getAllAuthsByName(PlayerAuth auth) { public synchronized List<String> getAllAuthsByName(final PlayerAuth auth) {
Connection con = null; Connection con = null;
PreparedStatement pst = null; PreparedStatement pst = null;
ResultSet rs = null; ResultSet rs = null;
List<String> countIp = new ArrayList<>(); final List<String> countIp = new ArrayList<>();
try { try {
con = getConnection(); con = getConnection();
pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnIp + "=?;"); pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnIp + "=?;");
@ -276,7 +274,7 @@ public class MySQL implements DataSource {
countIp.add(rs.getString(columnName)); countIp.add(rs.getString(columnName));
} }
return countIp; return countIp;
} catch (Exception ex) { } catch (final Exception ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return new ArrayList<>(); return new ArrayList<>();
} finally { } finally {
@ -287,7 +285,7 @@ public class MySQL implements DataSource {
} }
@Override @Override
public synchronized PlayerAuth getAuth(String user) { public synchronized PlayerAuth getAuth(final String user) {
Connection con = null; Connection con = null;
PreparedStatement pst = null; PreparedStatement pst = null;
ResultSet rs = null; ResultSet rs = null;
@ -301,20 +299,22 @@ public class MySQL implements DataSource {
if (rs.next()) { if (rs.next()) {
id = rs.getInt(columnID); id = rs.getInt(columnID);
if (rs.getString(columnIp).isEmpty() && rs.getString(columnIp) != null) { 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), pAuth = new PlayerAuth(rs.getString(columnName).toLowerCase(), rs.getString(columnPassword), "192.168.0.1", rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs
rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName)); .getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName));
} else { } else {
if (!columnSalt.isEmpty()) { if (!columnSalt.isEmpty()) {
if (!columnGroup.isEmpty()) if (!columnGroup.isEmpty()) {
pAuth = new PlayerAuth(rs.getString(columnName).toLowerCase(), rs.getString(columnPassword), rs.getString(columnSalt), rs.getInt(columnGroup), rs.getString(columnIp), pAuth = new PlayerAuth(rs.getString(columnName).toLowerCase(), rs.getString(columnPassword), rs.getString(columnSalt), rs.getInt(columnGroup), rs.getString(columnIp), rs
rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), .getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs
rs.getString(columnRealName)); .getString(columnRealName));
else } else {
pAuth = new PlayerAuth(rs.getString(columnName).toLowerCase(), rs.getString(columnPassword), rs.getString(columnSalt), rs.getString(columnIp), rs.getLong(columnLastLogin), pAuth = new PlayerAuth(rs.getString(columnName).toLowerCase(), rs.getString(columnPassword), rs.getString(columnSalt), rs.getString(columnIp), rs
rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName)); .getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs
.getString(columnRealName));
}
} else { } else {
pAuth = new PlayerAuth(rs.getString(columnName).toLowerCase(), rs.getString(columnPassword), rs.getString(columnIp), rs.getLong(columnLastLogin), rs.getDouble(lastlocX), pAuth = new PlayerAuth(rs.getString(columnName).toLowerCase(), rs.getString(columnPassword), rs.getString(columnIp), rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs
rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName)); .getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName));
} }
} }
if (Settings.getPasswordHash == HashAlgorithm.XENFORO) { if (Settings.getPasswordHash == HashAlgorithm.XENFORO) {
@ -324,15 +324,15 @@ public class MySQL implements DataSource {
pst.setInt(1, id); pst.setInt(1, id);
rs = pst.executeQuery(); rs = pst.executeQuery();
if (rs.next()) { if (rs.next()) {
Blob blob = rs.getBlob("data"); final Blob blob = rs.getBlob("data");
byte[] bytes = blob.getBytes(1, (int) blob.length()); final byte[] bytes = blob.getBytes(1, (int) blob.length());
pAuth.setHash(new String(bytes)); pAuth.setHash(new String(bytes));
} }
} }
} else { } else {
return null; return null;
} }
} catch (Exception ex) { } catch (final Exception ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return null; return null;
} finally { } finally {
@ -344,7 +344,7 @@ public class MySQL implements DataSource {
} }
@Override @Override
public synchronized int getIps(String ip) { public synchronized int getIps(final String ip) {
Connection con = null; Connection con = null;
PreparedStatement pst = null; PreparedStatement pst = null;
ResultSet rs = null; ResultSet rs = null;
@ -358,7 +358,7 @@ public class MySQL implements DataSource {
countIp++; countIp++;
} }
return countIp; return countIp;
} catch (Exception ex) { } catch (final Exception ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return 0; return 0;
} finally { } finally {
@ -370,7 +370,7 @@ public class MySQL implements DataSource {
@Override @Override
public List<PlayerAuth> getLoggedPlayers() { public List<PlayerAuth> getLoggedPlayers() {
List<PlayerAuth> auths = new ArrayList<>(); final List<PlayerAuth> auths = new ArrayList<>();
Connection con = null; Connection con = null;
PreparedStatement pst = null; PreparedStatement pst = null;
ResultSet rs = null; ResultSet rs = null;
@ -380,22 +380,23 @@ public class MySQL implements DataSource {
rs = pst.executeQuery(); rs = pst.executeQuery();
while (rs.next()) { while (rs.next()) {
PlayerAuth pAuth; PlayerAuth pAuth;
int id = rs.getInt(columnID); final int id = rs.getInt(columnID);
if (rs.getString(columnIp).isEmpty() && rs.getString(columnIp) != null) { 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), pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), "192.168.0.1", rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs
rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName)); .getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName));
} else { } else {
if (!columnSalt.isEmpty()) { if (!columnSalt.isEmpty()) {
if (!columnGroup.isEmpty()) if (!columnGroup.isEmpty()) {
pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnSalt), rs.getInt(columnGroup), rs.getString(columnIp), pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnSalt), rs.getInt(columnGroup), rs.getString(columnIp), rs
rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), .getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs
rs.getString(columnRealName)); .getString(columnRealName));
else } else {
pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnSalt), rs.getString(columnIp), rs.getLong(columnLastLogin), pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnSalt), rs.getString(columnIp), rs.getLong(columnLastLogin), rs
rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName)); .getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName));
}
} else { } else {
pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnIp), rs.getLong(columnLastLogin), rs.getDouble(lastlocX), pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnIp), rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs
rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName)); .getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName));
} }
} }
if (Settings.getPasswordHash == HashAlgorithm.XENFORO) { if (Settings.getPasswordHash == HashAlgorithm.XENFORO) {
@ -404,15 +405,15 @@ public class MySQL implements DataSource {
pst.setInt(1, id); pst.setInt(1, id);
rsid = pst.executeQuery(); rsid = pst.executeQuery();
if (rsid.next()) { if (rsid.next()) {
Blob blob = rsid.getBlob("data"); final Blob blob = rsid.getBlob("data");
byte[] bytes = blob.getBytes(1, (int) blob.length()); final byte[] bytes = blob.getBytes(1, (int) blob.length());
pAuth.setHash(new String(bytes)); pAuth.setHash(new String(bytes));
} }
rsid.close(); rsid.close();
} }
auths.add(pAuth); auths.add(pAuth);
} }
} catch (Exception ex) { } catch (final Exception ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return auths; return auths;
} finally { } finally {
@ -429,7 +430,7 @@ public class MySQL implements DataSource {
} }
@Override @Override
public synchronized boolean isAuthAvailable(String user) { public synchronized boolean isAuthAvailable(final String user) {
Connection con = null; Connection con = null;
PreparedStatement pst = null; PreparedStatement pst = null;
ResultSet rs = null; ResultSet rs = null;
@ -439,7 +440,7 @@ public class MySQL implements DataSource {
pst.setString(1, user); pst.setString(1, user);
rs = pst.executeQuery(); rs = pst.executeQuery();
return rs.next(); return rs.next();
} catch (Exception ex) { } catch (final Exception ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return false; return false;
} finally { } finally {
@ -450,7 +451,7 @@ public class MySQL implements DataSource {
} }
@Override @Override
public boolean isLogged(String user) { public boolean isLogged(final String user) {
Connection con = null; Connection con = null;
PreparedStatement pst = null; PreparedStatement pst = null;
ResultSet rs = null; ResultSet rs = null;
@ -459,9 +460,10 @@ public class MySQL implements DataSource {
pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE LOWER(" + columnName + ")=?;"); pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE LOWER(" + columnName + ")=?;");
pst.setString(1, user); pst.setString(1, user);
rs = pst.executeQuery(); rs = pst.executeQuery();
if (rs.next()) if (rs.next()) {
return (rs.getInt(columnLogged) == 1); return (rs.getInt(columnLogged) == 1);
} catch (Exception ex) { }
} catch (final Exception ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return false; return false;
} finally { } finally {
@ -473,17 +475,17 @@ public class MySQL implements DataSource {
} }
@Override @Override
public synchronized void purgeBanned(List<String> banned) { public synchronized void purgeBanned(final List<String> banned) {
Connection con = null; Connection con = null;
PreparedStatement pst = null; PreparedStatement pst = null;
try { try {
for (String name : banned) { for (final String name : banned) {
con = getConnection(); con = getConnection();
pst = con.prepareStatement("DELETE FROM " + tableName + " WHERE LOWER(" + columnName + ")=?;"); pst = con.prepareStatement("DELETE FROM " + tableName + " WHERE LOWER(" + columnName + ")=?;");
pst.setString(1, name); pst.setString(1, name);
pst.executeUpdate(); pst.executeUpdate();
} }
} catch (Exception ex) { } catch (final Exception ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
} finally { } finally {
close(pst); close(pst);
@ -492,7 +494,7 @@ public class MySQL implements DataSource {
} }
@Override @Override
public synchronized int purgeDatabase(long until) { public synchronized int purgeDatabase(final long until) {
Connection con = null; Connection con = null;
PreparedStatement pst = null; PreparedStatement pst = null;
try { try {
@ -500,7 +502,7 @@ public class MySQL implements DataSource {
pst = con.prepareStatement("DELETE FROM " + tableName + " WHERE " + columnLastLogin + "<?;"); pst = con.prepareStatement("DELETE FROM " + tableName + " WHERE " + columnLastLogin + "<?;");
pst.setLong(1, until); pst.setLong(1, until);
return pst.executeUpdate(); return pst.executeUpdate();
} catch (Exception ex) { } catch (final Exception ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return 0; return 0;
} finally { } finally {
@ -519,7 +521,7 @@ public class MySQL implements DataSource {
pst.setInt(1, 0); pst.setInt(1, 0);
pst.setInt(2, 1); pst.setInt(2, 1);
pst.executeUpdate(); pst.executeUpdate();
} catch (Exception ex) { } catch (final Exception ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
} finally { } finally {
close(pst); close(pst);
@ -531,19 +533,20 @@ public class MySQL implements DataSource {
public void reload() { public void reload() {
try { try {
reloadArguments(); reloadArguments();
} catch (Exception e) { } catch (final Exception e) {
ConsoleLogger.showError(e.getMessage()); ConsoleLogger.showError(e.getMessage());
ConsoleLogger.showError("Can't reconnect to MySQL database... Please check your MySQL informations ! SHUTDOWN..."); ConsoleLogger.showError("无法再次连接到 MySQL 数据库... 请检查您 MySQL 数据库服务器是否正常 ! 关闭服务器...");
if (Settings.isStopEnabled) { if (Settings.isStopEnabled) {
AuthMe.getInstance().getServer().shutdown(); AuthMe.getInstance().getServer().shutdown();
} }
if (!Settings.isStopEnabled) if (!Settings.isStopEnabled) {
AuthMe.getInstance().getServer().getPluginManager().disablePlugin(AuthMe.getInstance()); AuthMe.getInstance().getServer().getPluginManager().disablePlugin(AuthMe.getInstance());
}
} }
} }
@Override @Override
public synchronized boolean removeAuth(String user) { public synchronized boolean removeAuth(final String user) {
Connection con = null; Connection con = null;
PreparedStatement pst = null; PreparedStatement pst = null;
try { try {
@ -557,18 +560,19 @@ public class MySQL implements DataSource {
if (rs.next()) { if (rs.next()) {
id = rs.getInt(columnID); id = rs.getInt(columnID);
// Remove data // Remove data
PreparedStatement pst2 = con.prepareStatement("DELETE FROM xf_user_authenticate WHERE " + columnID + "=?;"); final PreparedStatement pst2 = con.prepareStatement("DELETE FROM xf_user_authenticate WHERE " + columnID + "=?;");
pst2.setInt(1, id); pst2.setInt(1, id);
pst2.executeUpdate(); pst2.executeUpdate();
pst2.close(); pst2.close();
} }
} }
if (pst != null && !pst.isClosed()) if (pst != null && !pst.isClosed()) {
pst.close(); pst.close();
}
pst = con.prepareStatement("DELETE FROM " + tableName + " WHERE LOWER(" + columnName + ")=?;"); pst = con.prepareStatement("DELETE FROM " + tableName + " WHERE LOWER(" + columnName + ")=?;");
pst.setString(1, user); pst.setString(1, user);
pst.executeUpdate(); pst.executeUpdate();
} catch (Exception ex) { } catch (final Exception ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return false; return false;
} finally { } finally {
@ -579,7 +583,7 @@ public class MySQL implements DataSource {
} }
@Override @Override
public synchronized boolean saveAuth(PlayerAuth auth) { public synchronized boolean saveAuth(final PlayerAuth auth) {
Connection con = null; Connection con = null;
PreparedStatement pst = null; PreparedStatement pst = null;
ResultSet rs = null; ResultSet rs = null;
@ -608,7 +612,7 @@ public class MySQL implements DataSource {
pst.close(); pst.close();
} }
if (!columnOthers.isEmpty()) { if (!columnOthers.isEmpty()) {
for (String column : columnOthers) { for (final String column : columnOthers) {
pst = con.prepareStatement("UPDATE " + tableName + " SET " + column + "=? WHERE " + columnName + "=?;"); pst = con.prepareStatement("UPDATE " + tableName + " SET " + column + "=? WHERE " + columnName + "=?;");
pst.setString(1, auth.getRealName()); pst.setString(1, auth.getRealName());
pst.setString(2, auth.getNickname()); pst.setString(2, auth.getNickname());
@ -617,11 +621,11 @@ public class MySQL implements DataSource {
} }
} }
if (Settings.getPasswordHash == HashAlgorithm.PHPBB) { if (Settings.getPasswordHash == HashAlgorithm.PHPBB) {
PreparedStatement pst2 = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnName + "=?;"); final PreparedStatement pst2 = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnName + "=?;");
pst2.setString(1, auth.getNickname()); pst2.setString(1, auth.getNickname());
rs = pst2.executeQuery(); rs = pst2.executeQuery();
if (rs.next()) { if (rs.next()) {
int id = rs.getInt(columnID); final int id = rs.getInt(columnID);
// Insert player in phpbb_user_group // Insert player in phpbb_user_group
pst = con.prepareStatement("INSERT INTO " + Settings.getPhpbbPrefix + "user_group (group_id, user_id, group_leader, user_pending) VALUES (?,?,?,?);"); pst = con.prepareStatement("INSERT INTO " + Settings.getPhpbbPrefix + "user_group (group_id, user_id, group_leader, user_pending) VALUES (?,?,?,?);");
pst.setInt(1, Settings.getPhpbbGroup); pst.setInt(1, Settings.getPhpbbGroup);
@ -643,7 +647,7 @@ public class MySQL implements DataSource {
pst.executeUpdate(); pst.executeUpdate();
pst.close(); pst.close();
// Get current time without ms // Get current time without ms
long time = System.currentTimeMillis() / 1000; final long time = System.currentTimeMillis() / 1000;
// Update user_regdate // Update user_regdate
pst = con.prepareStatement("UPDATE " + tableName + " SET " + tableName + ".user_regdate=? WHERE " + columnName + "=?;"); pst = con.prepareStatement("UPDATE " + tableName + " SET " + tableName + ".user_regdate=? WHERE " + columnName + "=?;");
pst.setLong(1, time); pst.setLong(1, time);
@ -669,7 +673,7 @@ public class MySQL implements DataSource {
pst.setString(1, auth.getNickname()); pst.setString(1, auth.getNickname());
rs = pst.executeQuery(); rs = pst.executeQuery();
if (rs.next()) { if (rs.next()) {
int id = rs.getInt(columnID); final int id = rs.getInt(columnID);
// First Name // First Name
pst = con.prepareStatement("INSERT INTO " + Settings.getWordPressPrefix + "usermeta (user_id, meta_key, meta_value) VALUES (?,?,?);"); pst = con.prepareStatement("INSERT INTO " + Settings.getWordPressPrefix + "usermeta (user_id, meta_key, meta_value) VALUES (?,?,?);");
pst.setInt(1, id); pst.setInt(1, id);
@ -762,20 +766,20 @@ public class MySQL implements DataSource {
pst.setString(1, auth.getNickname()); pst.setString(1, auth.getNickname());
rs = pst.executeQuery(); rs = pst.executeQuery();
if (rs.next()) { if (rs.next()) {
int id = rs.getInt(columnID); final int id = rs.getInt(columnID);
// Insert password in the correct table // Insert password in the correct table
pst = con.prepareStatement("INSERT INTO xf_user_authenticate (user_id, scheme_class, data) VALUES (?,?,?);"); pst = con.prepareStatement("INSERT INTO xf_user_authenticate (user_id, scheme_class, data) VALUES (?,?,?);");
pst.setInt(1, id); pst.setInt(1, id);
pst.setString(2, "XenForo_Authentication_Core12"); pst.setString(2, "XenForo_Authentication_Core12");
byte[] bytes = auth.getHash().getBytes(); final byte[] bytes = auth.getHash().getBytes();
Blob blob = con.createBlob(); final Blob blob = con.createBlob();
blob.setBytes(1, bytes); blob.setBytes(1, bytes);
pst.setBlob(3, blob); pst.setBlob(3, blob);
pst.executeUpdate(); pst.executeUpdate();
} }
rs.close(); rs.close();
} }
} catch (Exception ex) { } catch (final Exception ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return false; return false;
} finally { } finally {
@ -787,7 +791,7 @@ public class MySQL implements DataSource {
} }
@Override @Override
public void setLogged(String user) { public void setLogged(final String user) {
Connection con = null; Connection con = null;
PreparedStatement pst = null; PreparedStatement pst = null;
try { try {
@ -796,7 +800,7 @@ public class MySQL implements DataSource {
pst.setInt(1, 1); pst.setInt(1, 1);
pst.setString(2, user); pst.setString(2, user);
pst.executeUpdate(); pst.executeUpdate();
} catch (Exception ex) { } catch (final Exception ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
} finally { } finally {
close(pst); close(pst);
@ -805,26 +809,27 @@ public class MySQL implements DataSource {
} }
@Override @Override
public void setUnlogged(String user) { public void setUnlogged(final String user) {
Connection con = null; Connection con = null;
PreparedStatement pst = null; PreparedStatement pst = null;
if (user != null) if (user != null) {
try { try {
con = getConnection(); con = getConnection();
pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnLogged + "=? WHERE LOWER(" + columnName + ")=?;"); pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnLogged + "=? WHERE LOWER(" + columnName + ")=?;");
pst.setInt(1, 0); pst.setInt(1, 0);
pst.setString(2, user); pst.setString(2, user);
pst.executeUpdate(); pst.executeUpdate();
} catch (Exception ex) { } catch (final Exception ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
} finally { } finally {
close(pst); close(pst);
close(con); close(con);
} }
}
} }
@Override @Override
public synchronized boolean updateEmail(PlayerAuth auth) { public synchronized boolean updateEmail(final PlayerAuth auth) {
Connection con = null; Connection con = null;
PreparedStatement pst = null; PreparedStatement pst = null;
try { try {
@ -833,7 +838,7 @@ public class MySQL implements DataSource {
pst.setString(1, auth.getEmail()); pst.setString(1, auth.getEmail());
pst.setString(2, auth.getNickname()); pst.setString(2, auth.getNickname());
pst.executeUpdate(); pst.executeUpdate();
} catch (Exception ex) { } catch (final Exception ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return false; return false;
} finally { } finally {
@ -844,7 +849,7 @@ public class MySQL implements DataSource {
} }
@Override @Override
public void updateName(String oldone, String newone) { public void updateName(final String oldone, final String newone) {
Connection con = null; Connection con = null;
PreparedStatement pst = null; PreparedStatement pst = null;
try { try {
@ -853,7 +858,7 @@ public class MySQL implements DataSource {
pst.setString(1, newone); pst.setString(1, newone);
pst.setString(2, oldone); pst.setString(2, oldone);
pst.executeUpdate(); pst.executeUpdate();
} catch (Exception ex) { } catch (final Exception ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
} finally { } finally {
close(pst); close(pst);
@ -862,7 +867,7 @@ public class MySQL implements DataSource {
} }
@Override @Override
public synchronized boolean updatePassword(PlayerAuth auth) { public synchronized boolean updatePassword(final PlayerAuth auth) {
Connection con = null; Connection con = null;
PreparedStatement pst = null; PreparedStatement pst = null;
ResultSet rs = null; ResultSet rs = null;
@ -878,11 +883,11 @@ public class MySQL implements DataSource {
pst.setString(1, auth.getNickname()); pst.setString(1, auth.getNickname());
rs = pst.executeQuery(); rs = pst.executeQuery();
if (rs.next()) { if (rs.next()) {
int id = rs.getInt(columnID); final int id = rs.getInt(columnID);
// Insert password in the correct table // Insert password in the correct table
pst = con.prepareStatement("UPDATE xf_user_authenticate SET data=? WHERE " + columnID + "=?;"); pst = con.prepareStatement("UPDATE xf_user_authenticate SET data=? WHERE " + columnID + "=?;");
byte[] bytes = auth.getHash().getBytes(); final byte[] bytes = auth.getHash().getBytes();
Blob blob = con.createBlob(); final Blob blob = con.createBlob();
blob.setBytes(1, bytes); blob.setBytes(1, bytes);
pst.setBlob(1, blob); pst.setBlob(1, blob);
pst.setInt(2, id); pst.setInt(2, id);
@ -894,7 +899,7 @@ public class MySQL implements DataSource {
} }
rs.close(); rs.close();
} }
} catch (Exception ex) { } catch (final Exception ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return false; return false;
} finally { } finally {
@ -906,7 +911,7 @@ public class MySQL implements DataSource {
} }
@Override @Override
public synchronized boolean updateQuitLoc(PlayerAuth auth) { public synchronized boolean updateQuitLoc(final PlayerAuth auth) {
Connection con = null; Connection con = null;
PreparedStatement pst = null; PreparedStatement pst = null;
try { try {
@ -918,7 +923,7 @@ public class MySQL implements DataSource {
pst.setString(4, auth.getWorld()); pst.setString(4, auth.getWorld());
pst.setString(5, auth.getNickname()); pst.setString(5, auth.getNickname());
pst.executeUpdate(); pst.executeUpdate();
} catch (Exception ex) { } catch (final Exception ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return false; return false;
} finally { } finally {
@ -929,7 +934,7 @@ public class MySQL implements DataSource {
} }
@Override @Override
public synchronized boolean updateSalt(PlayerAuth auth) { public synchronized boolean updateSalt(final PlayerAuth auth) {
if (columnSalt.isEmpty()) { if (columnSalt.isEmpty()) {
return false; return false;
} }
@ -941,7 +946,7 @@ public class MySQL implements DataSource {
pst.setString(1, auth.getSalt()); pst.setString(1, auth.getSalt());
pst.setString(2, auth.getNickname()); pst.setString(2, auth.getNickname());
pst.executeUpdate(); pst.executeUpdate();
} catch (Exception ex) { } catch (final Exception ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return false; return false;
} finally { } finally {
@ -952,7 +957,7 @@ public class MySQL implements DataSource {
} }
@Override @Override
public synchronized boolean updateSession(PlayerAuth auth) { public synchronized boolean updateSession(final PlayerAuth auth) {
Connection con = null; Connection con = null;
PreparedStatement pst = null; PreparedStatement pst = null;
try { try {
@ -963,7 +968,7 @@ public class MySQL implements DataSource {
pst.setString(3, auth.getRealName()); pst.setString(3, auth.getRealName());
pst.setString(4, auth.getNickname()); pst.setString(4, auth.getNickname());
pst.executeUpdate(); pst.executeUpdate();
} catch (Exception ex) { } catch (final Exception ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return false; return false;
} finally { } finally {
@ -973,11 +978,11 @@ public class MySQL implements DataSource {
return true; return true;
} }
private void close(AutoCloseable o) { private void close(final AutoCloseable o) {
if (o != null) { if (o != null) {
try { try {
o.close(); o.close();
} catch (Exception ex) { } catch (final Exception ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
} }
} }
@ -998,7 +1003,7 @@ public class MySQL implements DataSource {
} }
private synchronized void setConnectionArguments() throws ClassNotFoundException, IllegalArgumentException { private synchronized void setConnectionArguments() throws ClassNotFoundException, IllegalArgumentException {
HikariConfig config = new HikariConfig(); final HikariConfig config = new HikariConfig();
config.setPoolName("AuthMeMYSQLPool"); config.setPoolName("AuthMeMYSQLPool");
config.setDriverClassName("com.mysql.jdbc.Driver"); config.setDriverClassName("com.mysql.jdbc.Driver");
config.setJdbcUrl("jdbc:mysql://" + this.host + ":" + this.port + "/" + this.database); config.setJdbcUrl("jdbc:mysql://" + this.host + ":" + this.port + "/" + this.database);
@ -1079,7 +1084,7 @@ public class MySQL implements DataSource {
close(st); close(st);
close(con); close(con);
} }
ConsoleLogger.info("MySQL Setup finished"); ConsoleLogger.info("MySQL 数据表已初始化并载入完毕...");
} }
} }

View File

@ -672,6 +672,6 @@ public class SQLite implements DataSource {
close(rs); close(rs);
close(st); close(st);
} }
ConsoleLogger.info("SQLite 数据已初始化并载入完毕..."); ConsoleLogger.info("SQLite 数据已初始化并载入完毕...");
} }
} }

View File

@ -18,23 +18,23 @@ import fr.xephi.authme.settings.Settings;
public class SQLite_HIKARI implements DataSource { public class SQLite_HIKARI implements DataSource {
private String columnEmail; private final String columnEmail;
private String columnGroup; private final String columnGroup;
private String columnID; private final String columnID;
private String columnIp; private final String columnIp;
private String columnLastLogin; private final String columnLastLogin;
private String columnLogged; private final String columnLogged;
private String columnName; private final String columnName;
private String columnPassword; private final String columnPassword;
private String columnRealName; private final String columnRealName;
private String columnSalt; private final String columnSalt;
private String database; private final String database;
private HikariDataSource ds; private HikariDataSource ds;
private String lastlocWorld; private final String lastlocWorld;
private String lastlocX; private final String lastlocX;
private String lastlocY; private final String lastlocY;
private String lastlocZ; private final String lastlocZ;
private String tableName; private final String tableName;
public SQLite_HIKARI() throws ClassNotFoundException, SQLException { public SQLite_HIKARI() throws ClassNotFoundException, SQLException {
this.database = Settings.getMySQLDatabase; this.database = Settings.getMySQLDatabase;
@ -57,28 +57,28 @@ public class SQLite_HIKARI implements DataSource {
// Set the connection arguments // Set the connection arguments
try { try {
this.setConnectionArguments(); this.setConnectionArguments();
} catch (RuntimeException rt) { } catch (final RuntimeException rt) {
ConsoleLogger.showError("Can't use the Hikari Connection Pool! Please, report this error to the developer!"); ConsoleLogger.showError("无法初始化数据库连接池! 请报告此错误给开发者!");
throw rt; throw rt;
} }
// Initialize the database // Initialize the database
try { try {
this.setupConnection(); this.setupConnection();
} catch (SQLException e) { } catch (final SQLException e) {
this.close(); this.close();
ConsoleLogger.showError("Can't initialize the SQLite database... Please check your database settings in the config.yml file! SHUTDOWN..."); ConsoleLogger.showError("无法初始化 Hikari SQLite 数据库连接池... 请检查您的配置是否正确! 关闭服务器...");
ConsoleLogger.showError("If this error persists, please report it to the developer! SHUTDOWN..."); ConsoleLogger.showError("如果你认为配置文件没问题 请报告此错误给开发者! 关闭服务器...");
throw e; throw e;
} }
} }
@Override @Override
public List<String> autoPurgeDatabase(long until) { public List<String> autoPurgeDatabase(final long until) {
Connection con = null; Connection con = null;
PreparedStatement pst = null; PreparedStatement pst = null;
ResultSet rs = null; ResultSet rs = null;
List<String> list = new ArrayList<>(); final List<String> list = new ArrayList<>();
try { try {
con = getConnection(); con = getConnection();
pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnLastLogin + "<?;"); pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnLastLogin + "<?;");
@ -88,7 +88,7 @@ public class SQLite_HIKARI implements DataSource {
list.add(rs.getString(columnName)); list.add(rs.getString(columnName));
} }
return list; return list;
} catch (SQLException ex) { } catch (final SQLException ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return new ArrayList<>(); return new ArrayList<>();
} finally { } finally {
@ -100,8 +100,9 @@ public class SQLite_HIKARI implements DataSource {
@Override @Override
public synchronized void close() { public synchronized void close() {
if (ds != null) if (ds != null) {
ds.close(); ds.close();
}
} }
@Override @Override
@ -117,7 +118,7 @@ public class SQLite_HIKARI implements DataSource {
if (rs != null && rs.next()) { if (rs != null && rs.next()) {
result = rs.getInt(1); result = rs.getInt(1);
} }
} catch (SQLException ex) { } catch (final SQLException ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return result; return result;
} finally { } finally {
@ -132,7 +133,7 @@ public class SQLite_HIKARI implements DataSource {
Connection con = null; Connection con = null;
PreparedStatement pst = null; PreparedStatement pst = null;
ResultSet rs; ResultSet rs;
List<PlayerAuth> auths = new ArrayList<>(); final List<PlayerAuth> auths = new ArrayList<>();
try { try {
con = getConnection(); con = getConnection();
pst = con.prepareStatement("SELECT * FROM " + tableName + ";"); pst = con.prepareStatement("SELECT * FROM " + tableName + ";");
@ -140,21 +141,21 @@ public class SQLite_HIKARI implements DataSource {
while (rs.next()) { while (rs.next()) {
PlayerAuth pAuth; PlayerAuth pAuth;
if (rs.getString(columnIp).isEmpty()) { 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), pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), "127.0.0.1", rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs
rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName)); .getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName));
} else { } else {
if (!columnSalt.isEmpty()) { if (!columnSalt.isEmpty()) {
pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnSalt), rs.getInt(columnGroup), rs.getString(columnIp), pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnSalt), rs.getInt(columnGroup), rs.getString(columnIp), rs
rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), .getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs
rs.getString(columnRealName)); .getString(columnRealName));
} else { } else {
pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnIp), rs.getLong(columnLastLogin), rs.getDouble(lastlocX), pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnIp), rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs
rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName)); .getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName));
} }
} }
auths.add(pAuth); auths.add(pAuth);
} }
} catch (SQLException ex) { } catch (final SQLException ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return auths; return auths;
} finally { } finally {
@ -165,11 +166,11 @@ public class SQLite_HIKARI implements DataSource {
} }
@Override @Override
public List<String> getAllAuthsByEmail(String email) { public List<String> getAllAuthsByEmail(final String email) {
Connection con = null; Connection con = null;
PreparedStatement pst = null; PreparedStatement pst = null;
ResultSet rs = null; ResultSet rs = null;
List<String> countEmail = new ArrayList<>(); final List<String> countEmail = new ArrayList<>();
try { try {
con = getConnection(); con = getConnection();
pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnEmail + "=?;"); pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnEmail + "=?;");
@ -179,10 +180,10 @@ public class SQLite_HIKARI implements DataSource {
countEmail.add(rs.getString(columnName)); countEmail.add(rs.getString(columnName));
} }
return countEmail; return countEmail;
} catch (SQLException ex) { } catch (final SQLException ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return new ArrayList<>(); return new ArrayList<>();
} catch (NullPointerException npe) { } catch (final NullPointerException npe) {
return new ArrayList<>(); return new ArrayList<>();
} finally { } finally {
close(rs); close(rs);
@ -192,11 +193,11 @@ public class SQLite_HIKARI implements DataSource {
} }
@Override @Override
public List<String> getAllAuthsByIp(String ip) { public List<String> getAllAuthsByIp(final String ip) {
Connection con = null; Connection con = null;
PreparedStatement pst = null; PreparedStatement pst = null;
ResultSet rs = null; ResultSet rs = null;
List<String> countIp = new ArrayList<>(); final List<String> countIp = new ArrayList<>();
try { try {
con = getConnection(); con = getConnection();
pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnIp + "=?;"); pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnIp + "=?;");
@ -206,10 +207,10 @@ public class SQLite_HIKARI implements DataSource {
countIp.add(rs.getString(columnName)); countIp.add(rs.getString(columnName));
} }
return countIp; return countIp;
} catch (SQLException ex) { } catch (final SQLException ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return new ArrayList<>(); return new ArrayList<>();
} catch (NullPointerException npe) { } catch (final NullPointerException npe) {
return new ArrayList<>(); return new ArrayList<>();
} finally { } finally {
close(rs); close(rs);
@ -219,11 +220,11 @@ public class SQLite_HIKARI implements DataSource {
} }
@Override @Override
public List<String> getAllAuthsByName(PlayerAuth auth) { public List<String> getAllAuthsByName(final PlayerAuth auth) {
Connection con = null; Connection con = null;
PreparedStatement pst = null; PreparedStatement pst = null;
ResultSet rs = null; ResultSet rs = null;
List<String> countIp = new ArrayList<>(); final List<String> countIp = new ArrayList<>();
try { try {
con = getConnection(); con = getConnection();
pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnIp + "=?;"); pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnIp + "=?;");
@ -233,10 +234,10 @@ public class SQLite_HIKARI implements DataSource {
countIp.add(rs.getString(columnName)); countIp.add(rs.getString(columnName));
} }
return countIp; return countIp;
} catch (SQLException ex) { } catch (final SQLException ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return new ArrayList<>(); return new ArrayList<>();
} catch (NullPointerException npe) { } catch (final NullPointerException npe) {
return new ArrayList<>(); return new ArrayList<>();
} finally { } finally {
close(rs); close(rs);
@ -246,7 +247,7 @@ public class SQLite_HIKARI implements DataSource {
} }
@Override @Override
public synchronized PlayerAuth getAuth(String user) { public synchronized PlayerAuth getAuth(final String user) {
Connection con = null; Connection con = null;
PreparedStatement pst = null; PreparedStatement pst = null;
ResultSet rs = null; ResultSet rs = null;
@ -257,22 +258,22 @@ public class SQLite_HIKARI implements DataSource {
rs = pst.executeQuery(); rs = pst.executeQuery();
if (rs.next()) { if (rs.next()) {
if (rs.getString(columnIp).isEmpty()) { 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), return new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), "192.168.0.1", rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs
rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName)); .getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName));
} else { } else {
if (!columnSalt.isEmpty()) { if (!columnSalt.isEmpty()) {
return new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnSalt), rs.getInt(columnGroup), rs.getString(columnIp), return new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnSalt), rs.getInt(columnGroup), rs.getString(columnIp), rs
rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), .getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs
rs.getString(columnRealName)); .getString(columnRealName));
} else { } else {
return new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnIp), rs.getLong(columnLastLogin), rs.getDouble(lastlocX), return new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnIp), rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs
rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName)); .getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName));
} }
} }
} else { } else {
return null; return null;
} }
} catch (SQLException ex) { } catch (final SQLException ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return null; return null;
} finally { } finally {
@ -283,7 +284,7 @@ public class SQLite_HIKARI implements DataSource {
} }
@Override @Override
public int getIps(String ip) { public int getIps(final String ip) {
Connection con = null; Connection con = null;
PreparedStatement pst = null; PreparedStatement pst = null;
ResultSet rs = null; ResultSet rs = null;
@ -297,7 +298,7 @@ public class SQLite_HIKARI implements DataSource {
countIp++; countIp++;
} }
return countIp; return countIp;
} catch (SQLException ex) { } catch (final SQLException ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return 0; return 0;
} finally { } finally {
@ -312,7 +313,7 @@ public class SQLite_HIKARI implements DataSource {
Connection con = null; Connection con = null;
PreparedStatement pst = null; PreparedStatement pst = null;
ResultSet rs; ResultSet rs;
List<PlayerAuth> auths = new ArrayList<>(); final List<PlayerAuth> auths = new ArrayList<>();
try { try {
con = getConnection(); con = getConnection();
pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnLogged + "=1;"); pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnLogged + "=1;");
@ -320,21 +321,21 @@ public class SQLite_HIKARI implements DataSource {
while (rs.next()) { while (rs.next()) {
PlayerAuth pAuth; PlayerAuth pAuth;
if (rs.getString(columnIp).isEmpty()) { 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), pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), "127.0.0.1", rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs
rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName)); .getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName));
} else { } else {
if (!columnSalt.isEmpty()) { if (!columnSalt.isEmpty()) {
pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnSalt), rs.getInt(columnGroup), rs.getString(columnIp), pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnSalt), rs.getInt(columnGroup), rs.getString(columnIp), rs
rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), .getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs
rs.getString(columnRealName)); .getString(columnRealName));
} else { } else {
pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnIp), rs.getLong(columnLastLogin), rs.getDouble(lastlocX), pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnIp), rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs
rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName)); .getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName));
} }
} }
auths.add(pAuth); auths.add(pAuth);
} }
} catch (SQLException ex) { } catch (final SQLException ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
} finally { } finally {
close(pst); close(pst);
@ -349,7 +350,7 @@ public class SQLite_HIKARI implements DataSource {
} }
@Override @Override
public synchronized boolean isAuthAvailable(String user) { public synchronized boolean isAuthAvailable(final String user) {
Connection con = null; Connection con = null;
PreparedStatement pst = null; PreparedStatement pst = null;
ResultSet rs = null; ResultSet rs = null;
@ -359,7 +360,7 @@ public class SQLite_HIKARI implements DataSource {
pst.setString(1, user); pst.setString(1, user);
rs = pst.executeQuery(); rs = pst.executeQuery();
return rs.next(); return rs.next();
} catch (SQLException ex) { } catch (final SQLException ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return false; return false;
} finally { } finally {
@ -370,7 +371,7 @@ public class SQLite_HIKARI implements DataSource {
} }
@Override @Override
public boolean isLogged(String user) { public boolean isLogged(final String user) {
Connection con = null; Connection con = null;
PreparedStatement pst = null; PreparedStatement pst = null;
ResultSet rs = null; ResultSet rs = null;
@ -379,9 +380,10 @@ public class SQLite_HIKARI implements DataSource {
pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE LOWER(" + columnName + ")=?;"); pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE LOWER(" + columnName + ")=?;");
pst.setString(1, user); pst.setString(1, user);
rs = pst.executeQuery(); rs = pst.executeQuery();
if (rs.next()) if (rs.next()) {
return (rs.getInt(columnLogged) == 1); return (rs.getInt(columnLogged) == 1);
} catch (SQLException ex) { }
} catch (final SQLException ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return false; return false;
} finally { } finally {
@ -393,17 +395,17 @@ public class SQLite_HIKARI implements DataSource {
} }
@Override @Override
public void purgeBanned(List<String> banned) { public void purgeBanned(final List<String> banned) {
Connection con = null; Connection con = null;
PreparedStatement pst = null; PreparedStatement pst = null;
try { try {
con = getConnection(); con = getConnection();
for (String name : banned) { for (final String name : banned) {
pst = con.prepareStatement("DELETE FROM " + tableName + " WHERE " + columnName + "=?;"); pst = con.prepareStatement("DELETE FROM " + tableName + " WHERE " + columnName + "=?;");
pst.setString(1, name); pst.setString(1, name);
pst.executeUpdate(); pst.executeUpdate();
} }
} catch (SQLException ex) { } catch (final SQLException ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
} finally { } finally {
close(pst); close(pst);
@ -412,7 +414,7 @@ public class SQLite_HIKARI implements DataSource {
} }
@Override @Override
public int purgeDatabase(long until) { public int purgeDatabase(final long until) {
Connection con = null; Connection con = null;
PreparedStatement pst = null; PreparedStatement pst = null;
try { try {
@ -420,7 +422,7 @@ public class SQLite_HIKARI implements DataSource {
pst = con.prepareStatement("DELETE FROM " + tableName + " WHERE " + columnLastLogin + "<?;"); pst = con.prepareStatement("DELETE FROM " + tableName + " WHERE " + columnLastLogin + "<?;");
pst.setLong(1, until); pst.setLong(1, until);
return pst.executeUpdate(); return pst.executeUpdate();
} catch (SQLException ex) { } catch (final SQLException ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return 0; return 0;
} finally { } finally {
@ -439,7 +441,7 @@ public class SQLite_HIKARI implements DataSource {
pst.setInt(1, 0); pst.setInt(1, 0);
pst.setInt(2, 1); pst.setInt(2, 1);
pst.executeUpdate(); pst.executeUpdate();
} catch (SQLException ex) { } catch (final SQLException ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
} finally { } finally {
close(pst); close(pst);
@ -451,19 +453,20 @@ public class SQLite_HIKARI implements DataSource {
public void reload() { public void reload() {
try { try {
reloadArguments(); reloadArguments();
} catch (Exception e) { } catch (final Exception e) {
ConsoleLogger.showError(e.getMessage()); ConsoleLogger.showError(e.getMessage());
ConsoleLogger.showError("Can't reconnect to SQLite database... Please check your SQLite informations ! SHUTDOWN..."); ConsoleLogger.showError("Can't reconnect to SQLite database... Please check your SQLite informations ! SHUTDOWN...");
if (Settings.isStopEnabled) { if (Settings.isStopEnabled) {
AuthMe.getInstance().getServer().shutdown(); AuthMe.getInstance().getServer().shutdown();
} }
if (!Settings.isStopEnabled) if (!Settings.isStopEnabled) {
AuthMe.getInstance().getServer().getPluginManager().disablePlugin(AuthMe.getInstance()); AuthMe.getInstance().getServer().getPluginManager().disablePlugin(AuthMe.getInstance());
}
} }
} }
@Override @Override
public synchronized boolean removeAuth(String user) { public synchronized boolean removeAuth(final String user) {
Connection con = null; Connection con = null;
PreparedStatement pst = null; PreparedStatement pst = null;
try { try {
@ -471,7 +474,7 @@ public class SQLite_HIKARI implements DataSource {
pst = con.prepareStatement("DELETE FROM " + tableName + " WHERE " + columnName + "=?;"); pst = con.prepareStatement("DELETE FROM " + tableName + " WHERE " + columnName + "=?;");
pst.setString(1, user); pst.setString(1, user);
pst.executeUpdate(); pst.executeUpdate();
} catch (SQLException ex) { } catch (final SQLException ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return false; return false;
} finally { } finally {
@ -482,7 +485,7 @@ public class SQLite_HIKARI implements DataSource {
} }
@Override @Override
public synchronized boolean saveAuth(PlayerAuth auth) { public synchronized boolean saveAuth(final PlayerAuth auth) {
Connection con = null; Connection con = null;
PreparedStatement pst = null; PreparedStatement pst = null;
try { try {
@ -507,7 +510,7 @@ public class SQLite_HIKARI implements DataSource {
pst.setString(6, auth.getRealName()); pst.setString(6, auth.getRealName());
pst.executeUpdate(); pst.executeUpdate();
} }
} catch (SQLException ex) { } catch (final SQLException ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return false; return false;
} finally { } finally {
@ -518,7 +521,7 @@ public class SQLite_HIKARI implements DataSource {
} }
@Override @Override
public void setLogged(String user) { public void setLogged(final String user) {
Connection con = null; Connection con = null;
PreparedStatement pst = null; PreparedStatement pst = null;
try { try {
@ -527,7 +530,7 @@ public class SQLite_HIKARI implements DataSource {
pst.setInt(1, 1); pst.setInt(1, 1);
pst.setString(2, user); pst.setString(2, user);
pst.executeUpdate(); pst.executeUpdate();
} catch (SQLException ex) { } catch (final SQLException ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
} finally { } finally {
close(pst); close(pst);
@ -536,26 +539,27 @@ public class SQLite_HIKARI implements DataSource {
} }
@Override @Override
public void setUnlogged(String user) { public void setUnlogged(final String user) {
Connection con = null; Connection con = null;
PreparedStatement pst = null; PreparedStatement pst = null;
if (user != null) if (user != null) {
try { try {
con = getConnection(); con = getConnection();
pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnLogged + "=? WHERE LOWER(" + columnName + ")=?;"); pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnLogged + "=? WHERE LOWER(" + columnName + ")=?;");
pst.setInt(1, 0); pst.setInt(1, 0);
pst.setString(2, user); pst.setString(2, user);
pst.executeUpdate(); pst.executeUpdate();
} catch (SQLException ex) { } catch (final SQLException ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
} finally { } finally {
close(pst); close(pst);
close(con); close(con);
} }
}
} }
@Override @Override
public boolean updateEmail(PlayerAuth auth) { public boolean updateEmail(final PlayerAuth auth) {
Connection con = null; Connection con = null;
PreparedStatement pst = null; PreparedStatement pst = null;
try { try {
@ -564,7 +568,7 @@ public class SQLite_HIKARI implements DataSource {
pst.setString(1, auth.getEmail()); pst.setString(1, auth.getEmail());
pst.setString(2, auth.getNickname()); pst.setString(2, auth.getNickname());
pst.executeUpdate(); pst.executeUpdate();
} catch (SQLException ex) { } catch (final SQLException ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return false; return false;
} finally { } finally {
@ -575,7 +579,7 @@ public class SQLite_HIKARI implements DataSource {
} }
@Override @Override
public void updateName(String oldone, String newone) { public void updateName(final String oldone, final String newone) {
Connection con = null; Connection con = null;
PreparedStatement pst = null; PreparedStatement pst = null;
try { try {
@ -584,7 +588,7 @@ public class SQLite_HIKARI implements DataSource {
pst.setString(1, newone); pst.setString(1, newone);
pst.setString(2, oldone); pst.setString(2, oldone);
pst.executeUpdate(); pst.executeUpdate();
} catch (SQLException ex) { } catch (final SQLException ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
} finally { } finally {
close(pst); close(pst);
@ -593,7 +597,7 @@ public class SQLite_HIKARI implements DataSource {
} }
@Override @Override
public synchronized boolean updatePassword(PlayerAuth auth) { public synchronized boolean updatePassword(final PlayerAuth auth) {
Connection con = null; Connection con = null;
PreparedStatement pst = null; PreparedStatement pst = null;
try { try {
@ -602,7 +606,7 @@ public class SQLite_HIKARI implements DataSource {
pst.setString(1, auth.getHash()); pst.setString(1, auth.getHash());
pst.setString(2, auth.getNickname()); pst.setString(2, auth.getNickname());
pst.executeUpdate(); pst.executeUpdate();
} catch (SQLException ex) { } catch (final SQLException ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return false; return false;
} finally { } finally {
@ -613,7 +617,7 @@ public class SQLite_HIKARI implements DataSource {
} }
@Override @Override
public boolean updateQuitLoc(PlayerAuth auth) { public boolean updateQuitLoc(final PlayerAuth auth) {
Connection con = null; Connection con = null;
PreparedStatement pst = null; PreparedStatement pst = null;
try { try {
@ -625,7 +629,7 @@ public class SQLite_HIKARI implements DataSource {
pst.setString(4, auth.getWorld()); pst.setString(4, auth.getWorld());
pst.setString(5, auth.getNickname()); pst.setString(5, auth.getNickname());
pst.executeUpdate(); pst.executeUpdate();
} catch (SQLException ex) { } catch (final SQLException ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return false; return false;
} finally { } finally {
@ -636,7 +640,7 @@ public class SQLite_HIKARI implements DataSource {
} }
@Override @Override
public boolean updateSalt(PlayerAuth auth) { public boolean updateSalt(final PlayerAuth auth) {
if (columnSalt.isEmpty()) { if (columnSalt.isEmpty()) {
return false; return false;
} }
@ -648,7 +652,7 @@ public class SQLite_HIKARI implements DataSource {
pst.setString(1, auth.getSalt()); pst.setString(1, auth.getSalt());
pst.setString(2, auth.getNickname()); pst.setString(2, auth.getNickname());
pst.executeUpdate(); pst.executeUpdate();
} catch (SQLException ex) { } catch (final SQLException ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return false; return false;
} finally { } finally {
@ -659,7 +663,7 @@ public class SQLite_HIKARI implements DataSource {
} }
@Override @Override
public boolean updateSession(PlayerAuth auth) { public boolean updateSession(final PlayerAuth auth) {
Connection con = null; Connection con = null;
PreparedStatement pst = null; PreparedStatement pst = null;
try { try {
@ -670,7 +674,7 @@ public class SQLite_HIKARI implements DataSource {
pst.setString(3, auth.getRealName()); pst.setString(3, auth.getRealName());
pst.setString(4, auth.getNickname()); pst.setString(4, auth.getNickname());
pst.executeUpdate(); pst.executeUpdate();
} catch (SQLException ex) { } catch (final SQLException ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return false; return false;
} finally { } finally {
@ -680,11 +684,11 @@ public class SQLite_HIKARI implements DataSource {
return true; return true;
} }
private void close(AutoCloseable o) { private void close(final AutoCloseable o) {
if (o != null) { if (o != null) {
try { try {
o.close(); o.close();
} catch (Exception ex) { } catch (final Exception ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
} }
} }
@ -703,7 +707,7 @@ public class SQLite_HIKARI implements DataSource {
} }
private synchronized void setConnectionArguments() throws RuntimeException { private synchronized void setConnectionArguments() throws RuntimeException {
HikariConfig config = new HikariConfig(); final HikariConfig config = new HikariConfig();
config.setPoolName("AuthMeSQLitePool"); config.setPoolName("AuthMeSQLitePool");
config.setDriverClassName("org.sqlite.JDBC"); // RuntimeException config.setDriverClassName("org.sqlite.JDBC"); // RuntimeException
config.setJdbcUrl("jdbc:sqlite:plugins/AuthMe/" + database + ".db"); config.setJdbcUrl("jdbc:sqlite:plugins/AuthMe/" + database + ".db");

View File

@ -31,13 +31,13 @@ import fr.xephi.authme.task.TimeoutTask;
public class AsyncronousJoin { public class AsyncronousJoin {
private Messages m = Messages.getInstance(); private final Messages m = Messages.getInstance();
protected DataSource database; protected DataSource database;
protected String name; protected String name;
protected Player player; protected Player player;
protected AuthMe plugin; protected AuthMe plugin;
public AsyncronousJoin(Player player, AuthMe plugin, DataSource database) { public AsyncronousJoin(final Player player, final AuthMe plugin, final DataSource database) {
this.player = player; this.player = player;
this.plugin = plugin; this.plugin = plugin;
this.database = database; this.database = database;
@ -45,10 +45,11 @@ public class AsyncronousJoin {
} }
public void process() { public void process() {
if (AuthMePlayerListener.gameMode.containsKey(name)) if (AuthMePlayerListener.gameMode.containsKey(name)) {
AuthMePlayerListener.gameMode.remove(name); AuthMePlayerListener.gameMode.remove(name);
}
AuthMePlayerListener.gameMode.putIfAbsent(name, player.getGameMode()); AuthMePlayerListener.gameMode.putIfAbsent(name, player.getGameMode());
BukkitScheduler sched = plugin.getServer().getScheduler(); final BukkitScheduler sched = plugin.getServer().getScheduler();
if (Utils.isNPC(player) || Utils.isUnrestricted(player)) { if (Utils.isNPC(player) || Utils.isUnrestricted(player)) {
return; return;
@ -68,8 +69,9 @@ public class AsyncronousJoin {
AuthMePlayerListener.causeByAuthMe.putIfAbsent(name, true); AuthMePlayerListener.causeByAuthMe.putIfAbsent(name, true);
player.setGameMode(gM); player.setGameMode(gM);
player.kickPlayer("You are not the Owner of this account, please try another name!"); player.kickPlayer("You are not the Owner of this account, please try another name!");
if (Settings.banUnsafeIp) if (Settings.banUnsafeIp) {
plugin.getServer().banIP(ip); plugin.getServer().banIP(ip);
}
} }
}); });
@ -81,7 +83,7 @@ public class AsyncronousJoin {
@Override @Override
public void run() { public void run() {
player.kickPlayer("A player with the same IP is already in game!"); player.kickPlayer("§c同一个IP只允许一个玩家进入!");
} }
}); });
@ -102,34 +104,37 @@ public class AsyncronousJoin {
}); });
} }
if (!Settings.noTeleport) if (!Settings.noTeleport) {
if (Settings.isTeleportToSpawnEnabled || (Settings.isForceSpawnLocOnJoinEnabled && Settings.getForcedWorlds.contains(player.getWorld().getName()))) { if (Settings.isTeleportToSpawnEnabled || (Settings.isForceSpawnLocOnJoinEnabled && Settings.getForcedWorlds.contains(player.getWorld().getName()))) {
sched.scheduleSyncDelayedTask(plugin, new Runnable() { sched.scheduleSyncDelayedTask(plugin, new Runnable() {
@Override @Override
public void run() { public void run() {
SpawnTeleportEvent tpEvent = new SpawnTeleportEvent(player, player.getLocation(), spawnLoc, PlayerCache.getInstance().isAuthenticated(name)); final SpawnTeleportEvent tpEvent = new SpawnTeleportEvent(player, player.getLocation(), spawnLoc, PlayerCache.getInstance().isAuthenticated(name));
plugin.getServer().getPluginManager().callEvent(tpEvent); plugin.getServer().getPluginManager().callEvent(tpEvent);
if (!tpEvent.isCancelled()) { if (!tpEvent.isCancelled()) {
if (player.isOnline() && tpEvent.getTo() != null) { if (player.isOnline() && tpEvent.getTo() != null) {
if (tpEvent.getTo().getWorld() != null) if (tpEvent.getTo().getWorld() != null) {
player.teleport(tpEvent.getTo()); player.teleport(tpEvent.getTo());
}
} }
} }
} }
}); });
} }
}
placePlayerSafely(player, spawnLoc); placePlayerSafely(player, spawnLoc);
LimboCache.getInstance().updateLimboPlayer(player); LimboCache.getInstance().updateLimboPlayer(player);
// protect inventory // protect inventory
if (Settings.protectInventoryBeforeLogInEnabled && plugin.inventoryProtector != null) { if (Settings.protectInventoryBeforeLogInEnabled && plugin.inventoryProtector != null) {
ProtectInventoryEvent ev = new ProtectInventoryEvent(player); final ProtectInventoryEvent ev = new ProtectInventoryEvent(player);
plugin.getServer().getPluginManager().callEvent(ev); plugin.getServer().getPluginManager().callEvent(ev);
if (ev.isCancelled()) { if (ev.isCancelled()) {
plugin.inventoryProtector.sendInventoryPacket(player); plugin.inventoryProtector.sendInventoryPacket(player);
if (!Settings.noConsoleSpam) if (!Settings.noConsoleSpam) {
ConsoleLogger.info("ProtectInventoryEvent has been cancelled for " + player.getName() + " ..."); ConsoleLogger.info("玩家 " + player.getName() + " 的背包保护事件已被取消...");
}
} }
} }
} else { } else {
@ -150,23 +155,25 @@ public class AsyncronousJoin {
if (!Settings.isForcedRegistrationEnabled) { if (!Settings.isForcedRegistrationEnabled) {
return; return;
} }
if (!Settings.noTeleport) if (!Settings.noTeleport) {
if (!needFirstspawn() && Settings.isTeleportToSpawnEnabled || (Settings.isForceSpawnLocOnJoinEnabled && Settings.getForcedWorlds.contains(player.getWorld().getName()))) { if (!needFirstspawn() && Settings.isTeleportToSpawnEnabled || (Settings.isForceSpawnLocOnJoinEnabled && Settings.getForcedWorlds.contains(player.getWorld().getName()))) {
sched.scheduleSyncDelayedTask(plugin, new Runnable() { sched.scheduleSyncDelayedTask(plugin, new Runnable() {
@Override @Override
public void run() { public void run() {
SpawnTeleportEvent tpEvent = new SpawnTeleportEvent(player, player.getLocation(), spawnLoc, PlayerCache.getInstance().isAuthenticated(name)); final SpawnTeleportEvent tpEvent = new SpawnTeleportEvent(player, player.getLocation(), spawnLoc, PlayerCache.getInstance().isAuthenticated(name));
plugin.getServer().getPluginManager().callEvent(tpEvent); plugin.getServer().getPluginManager().callEvent(tpEvent);
if (!tpEvent.isCancelled()) { if (!tpEvent.isCancelled()) {
if (player.isOnline() && tpEvent.getTo() != null) { if (player.isOnline() && tpEvent.getTo() != null) {
if (tpEvent.getTo().getWorld() != null) if (tpEvent.getTo().getWorld() != null) {
player.teleport(tpEvent.getTo()); player.teleport(tpEvent.getTo());
}
} }
} }
} }
}); });
} }
}
} }
String[] msg; String[] msg;
@ -175,16 +182,18 @@ public class AsyncronousJoin {
} else { } else {
msg = isAuthAvailable ? m.send("login_msg") : m.send("reg_msg"); msg = isAuthAvailable ? m.send("login_msg") : m.send("reg_msg");
} }
int time = Settings.getRegistrationTimeout * 20; final int time = Settings.getRegistrationTimeout * 20;
int msgInterval = Settings.getWarnMessageInterval; final int msgInterval = Settings.getWarnMessageInterval;
if (time != 0) { if (time != 0) {
BukkitTask id = sched.runTaskLaterAsynchronously(plugin, new TimeoutTask(plugin, name, player), time); final BukkitTask id = sched.runTaskLaterAsynchronously(plugin, new TimeoutTask(plugin, name, player), time);
if (!LimboCache.getInstance().hasLimboPlayer(name)) if (!LimboCache.getInstance().hasLimboPlayer(name)) {
LimboCache.getInstance().addLimboPlayer(player); LimboCache.getInstance().addLimboPlayer(player);
}
LimboCache.getInstance().getLimboPlayer(name).setTimeoutTaskId(id); LimboCache.getInstance().getLimboPlayer(name).setTimeoutTaskId(id);
} }
if (!LimboCache.getInstance().hasLimboPlayer(name)) if (!LimboCache.getInstance().hasLimboPlayer(name)) {
LimboCache.getInstance().addLimboPlayer(player); LimboCache.getInstance().addLimboPlayer(player);
}
if (isAuthAvailable) { if (isAuthAvailable) {
Utils.setGroup(player, GroupType.NOTLOGGEDIN); Utils.setGroup(player, GroupType.NOTLOGGEDIN);
} else { } else {
@ -194,17 +203,20 @@ public class AsyncronousJoin {
@Override @Override
public void run() { public void run() {
if (player.isOp()) if (player.isOp()) {
player.setOp(false); player.setOp(false);
}
if (player.getGameMode() != GameMode.CREATIVE && !Settings.isMovementAllowed) { if (player.getGameMode() != GameMode.CREATIVE && !Settings.isMovementAllowed) {
player.setAllowFlight(true); player.setAllowFlight(true);
player.setFlying(true); player.setFlying(true);
} }
player.setNoDamageTicks(Settings.getRegistrationTimeout * 20); player.setNoDamageTicks(Settings.getRegistrationTimeout * 20);
if (Settings.useEssentialsMotd) if (Settings.useEssentialsMotd) {
player.performCommand("motd"); player.performCommand("motd");
if (Settings.applyBlindEffect) }
if (Settings.applyBlindEffect) {
player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, Settings.getRegistrationTimeout * 20, 2)); player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, Settings.getRegistrationTimeout * 20, 2));
}
if (!Settings.isMovementAllowed && Settings.isRemoveSpeedEnabled) { if (!Settings.isMovementAllowed && Settings.isRemoveSpeedEnabled) {
player.setWalkSpeed(0.0f); player.setWalkSpeed(0.0f);
player.setFlySpeed(0.0f); player.setFlySpeed(0.0f);
@ -213,10 +225,11 @@ public class AsyncronousJoin {
}); });
if (Settings.isSessionsEnabled && isAuthAvailable && (PlayerCache.getInstance().isAuthenticated(name) || database.isLogged(name))) { if (Settings.isSessionsEnabled && isAuthAvailable && (PlayerCache.getInstance().isAuthenticated(name) || database.isLogged(name))) {
if (plugin.sessions.containsKey(name)) if (plugin.sessions.containsKey(name)) {
plugin.sessions.get(name).cancel(); plugin.sessions.get(name).cancel();
}
plugin.sessions.remove(name); plugin.sessions.remove(name);
PlayerAuth auth = database.getAuth(name); final PlayerAuth auth = database.getAuth(name);
if (auth != null && auth.getIp().equals(ip)) { if (auth != null && auth.getIp().equals(ip)) {
m.send(player, "valid_session"); m.send(player, "valid_session");
PlayerCache.getInstance().removePlayer(name); PlayerCache.getInstance().removePlayer(name);
@ -229,16 +242,18 @@ public class AsyncronousJoin {
} }
return; return;
} }
BukkitTask msgT = sched.runTaskAsynchronously(plugin, new MessageTask(plugin, name, msg, msgInterval)); final BukkitTask msgT = sched.runTaskAsynchronously(plugin, new MessageTask(plugin, name, msg, msgInterval));
LimboCache.getInstance().getLimboPlayer(name).setMessageTaskId(msgT); LimboCache.getInstance().getLimboPlayer(name).setMessageTaskId(msgT);
} }
private boolean needFirstspawn() { private boolean needFirstspawn() {
if (player.hasPlayedBefore()) if (player.hasPlayedBefore()) {
return false; return false;
if (Spawn.getInstance().getFirstSpawn() == null || Spawn.getInstance().getFirstSpawn().getWorld() == null) }
if (Spawn.getInstance().getFirstSpawn() == null || Spawn.getInstance().getFirstSpawn().getWorld() == null) {
return false; return false;
FirstSpawnTeleportEvent tpEvent = new FirstSpawnTeleportEvent(player, player.getLocation(), Spawn.getInstance().getFirstSpawn()); }
final FirstSpawnTeleportEvent tpEvent = new FirstSpawnTeleportEvent(player, player.getLocation(), Spawn.getInstance().getFirstSpawn());
plugin.getServer().getPluginManager().callEvent(tpEvent); plugin.getServer().getPluginManager().callEvent(tpEvent);
if (!tpEvent.isCancelled()) { if (!tpEvent.isCancelled()) {
if (player.isOnline() && tpEvent.getTo() != null && tpEvent.getTo().getWorld() != null) { if (player.isOnline() && tpEvent.getTo() != null && tpEvent.getTo().getWorld() != null) {
@ -259,25 +274,31 @@ public class AsyncronousJoin {
private void placePlayerSafely(final Player player, final Location spawnLoc) { private void placePlayerSafely(final Player player, final Location spawnLoc) {
Location loc = null; Location loc = null;
if (spawnLoc == null) if (spawnLoc == null) {
return; return;
if (!Settings.noTeleport) }
if (!Settings.noTeleport) {
return; return;
if (Settings.isTeleportToSpawnEnabled || (Settings.isForceSpawnLocOnJoinEnabled && Settings.getForcedWorlds.contains(player.getWorld().getName()))) }
if (Settings.isTeleportToSpawnEnabled || (Settings.isForceSpawnLocOnJoinEnabled && Settings.getForcedWorlds.contains(player.getWorld().getName()))) {
return; return;
if (!player.hasPlayedBefore()) }
if (!player.hasPlayedBefore()) {
return; return;
Block b = player.getLocation().getBlock(); }
final Block b = player.getLocation().getBlock();
if (b.getType() == Material.PORTAL || b.getType() == Material.ENDER_PORTAL) { if (b.getType() == Material.PORTAL || b.getType() == Material.ENDER_PORTAL) {
m.send(player, "unsafe_spawn"); m.send(player, "unsafe_spawn");
if (spawnLoc.getWorld() != null) if (spawnLoc.getWorld() != null) {
loc = spawnLoc; loc = spawnLoc;
}
} else { } else {
Block c = player.getLocation().add(0D, 1D, 0D).getBlock(); final Block c = player.getLocation().add(0D, 1D, 0D).getBlock();
if (c.getType() == Material.PORTAL || c.getType() == Material.ENDER_PORTAL) { if (c.getType() == Material.PORTAL || c.getType() == Material.ENDER_PORTAL) {
m.send(player, "unsafe_spawn"); m.send(player, "unsafe_spawn");
if (spawnLoc.getWorld() != null) if (spawnLoc.getWorld() != null) {
loc = spawnLoc; loc = spawnLoc;
}
} }
} }
if (loc != null) { if (loc != null) {

View File

@ -25,16 +25,16 @@ import fr.xephi.authme.task.MessageTask;
public class AsyncronousLogin { public class AsyncronousLogin {
private static RandomString rdm = new RandomString(Settings.captchaLength); private static RandomString rdm = new RandomString(Settings.captchaLength);
private DataSource database; private final DataSource database;
private Messages m = Messages.getInstance(); private final Messages m = Messages.getInstance();
private AuthMe plugin; private final AuthMe plugin;
protected boolean forceLogin; protected boolean forceLogin;
protected String name; protected String name;
protected String password; protected String password;
protected Player player; protected Player player;
protected String realName; protected String realName;
public AsyncronousLogin(Player player, String password, boolean forceLogin, AuthMe plugin, DataSource data) { public AsyncronousLogin(final Player player, final String password, final boolean forceLogin, final AuthMe plugin, final DataSource data) {
this.player = player; this.player = player;
this.password = password; this.password = password;
name = player.getName().toLowerCase(); name = player.getName().toLowerCase();
@ -44,27 +44,27 @@ public class AsyncronousLogin {
this.database = data; this.database = data;
} }
public void displayOtherAccounts(PlayerAuth auth, Player p) { public void displayOtherAccounts(final PlayerAuth auth, final Player p) {
if (!Settings.displayOtherAccounts) { if (!Settings.displayOtherAccounts) {
return; return;
} }
if (auth == null) { if (auth == null) {
return; return;
} }
List<String> auths = this.database.getAllAuthsByName(auth); final List<String> auths = this.database.getAllAuthsByName(auth);
// List<String> uuidlist = // List<String> uuidlist =
// plugin.otherAccounts.getAllPlayersByUUID(player.getUniqueId()); // plugin.otherAccounts.getAllPlayersByUUID(player);
if (auths.isEmpty()) { if (auths.isEmpty()) {
return; return;
} }
if (auths.size() == 1) { if (auths.size() == 1) {
return; return;
} }
StringBuilder message = new StringBuilder("[AuthMe] "); final StringBuilder message = new StringBuilder("[AuthMe] ");
// String uuidaccounts = // String uuidaccounts =
// "[AuthMe] PlayerNames has %size% links to this UUID : "; // "[AuthMe] PlayerNames has %size% links to this UUID : ";
int i = 0; int i = 0;
for (String account : auths) { for (final String account : auths) {
i++; i++;
message.append(account); message.append(account);
if (i != auths.size()) { if (i != auths.size()) {
@ -79,9 +79,9 @@ public class AsyncronousLogin {
* uuidaccounts = uuidaccounts + ", "; } else { uuidaccounts = * uuidaccounts = uuidaccounts + ", "; } else { uuidaccounts =
* uuidaccounts + "."; } } * uuidaccounts + "."; } }
*/ */
for (Player player : Utils.getOnlinePlayers()) { for (final Player player : Utils.getOnlinePlayers()) {
if (plugin.authmePermissible(player, "authme.seeOtherAccounts")) { 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(message.toString());
// player.sendMessage(uuidaccounts.replace("%size%", // player.sendMessage(uuidaccounts.replace("%size%",
// ""+uuidlist.size())); // ""+uuidlist.size()));
@ -90,23 +90,25 @@ public class AsyncronousLogin {
} }
public void process() { public void process() {
PlayerAuth pAuth = preAuth(); final PlayerAuth pAuth = preAuth();
if (pAuth == null || needsCaptcha()) if (pAuth == null || needsCaptcha()) {
return; return;
}
String hash = pAuth.getHash(); final String hash = pAuth.getHash();
String email = pAuth.getEmail(); final String email = pAuth.getEmail();
boolean passwordVerified = true; boolean passwordVerified = true;
if (!forceLogin) if (!forceLogin) {
try { try {
passwordVerified = PasswordSecurity.comparePasswordWithHash(password, hash, realName); passwordVerified = PasswordSecurity.comparePasswordWithHash(password, hash, realName);
} catch (Exception ex) { } catch (final Exception ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
m.send(player, "error"); m.send(player, "error");
return; return;
} }
}
if (passwordVerified && player.isOnline()) { 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); database.updateSession(auth);
if (Settings.useCaptcha) { if (Settings.useCaptcha) {
@ -119,39 +121,45 @@ public class AsyncronousLogin {
} }
player.setNoDamageTicks(0); player.setNoDamageTicks(0);
if (!forceLogin) if (!forceLogin) {
m.send(player, "login"); m.send(player, "login");
}
displayOtherAccounts(auth, player); displayOtherAccounts(auth, player);
if (Settings.recallEmail) { 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"); m.send(player, "add_email");
}
} }
if (!Settings.noConsoleSpam) if (!Settings.noConsoleSpam) {
ConsoleLogger.info(realName + " logged in!"); ConsoleLogger.info(realName + " 登陆成功!");
}
// makes player isLoggedin via API // makes player isLoggedin via API
PlayerCache.getInstance().addPlayer(auth); PlayerCache.getInstance().addPlayer(auth);
database.setLogged(name); database.setLogged(name);
plugin.otherAccounts.addPlayer(player.getUniqueId()); plugin.otherAccounts.addPlayer(player.getName());
// As the scheduling executes the Task most likely after the current // As the scheduling executes the Task most likely after the current
// task, we schedule it in the end // task, we schedule it in the end
// so that we can be sure, and have not to care if it might be // so that we can be sure, and have not to care if it might be
// processed in other order. // 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() != null) {
if (syncronousPlayerLogin.getLimbo().getTimeoutTaskId() != null) if (syncronousPlayerLogin.getLimbo().getTimeoutTaskId() != null) {
syncronousPlayerLogin.getLimbo().getTimeoutTaskId().cancel(); syncronousPlayerLogin.getLimbo().getTimeoutTaskId().cancel();
if (syncronousPlayerLogin.getLimbo().getMessageTaskId() != null) }
if (syncronousPlayerLogin.getLimbo().getMessageTaskId() != null) {
syncronousPlayerLogin.getLimbo().getMessageTaskId().cancel(); syncronousPlayerLogin.getLimbo().getMessageTaskId().cancel();
}
} }
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, syncronousPlayerLogin); Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, syncronousPlayerLogin);
} else if (player.isOnline()) { } else if (player.isOnline()) {
if (!Settings.noConsoleSpam) if (!Settings.noConsoleSpam) {
ConsoleLogger.info(realName + " used the wrong password"); ConsoleLogger.info(realName + " 输入了错误的密码");
}
if (Settings.isKickOnWrongPasswordEnabled) { if (Settings.isKickOnWrongPasswordEnabled) {
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
@ -167,7 +175,7 @@ public class AsyncronousLogin {
m.send(player, "wrong_pwd"); m.send(player, "wrong_pwd");
} }
} else { } 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)) { if (!plugin.captcha.containsKey(name)) {
plugin.captcha.putIfAbsent(name, 1); plugin.captcha.putIfAbsent(name, 1);
} else { } else {
int i = plugin.captcha.get(name) + 1; final int i = plugin.captcha.get(name) + 1;
plugin.captcha.remove(name); plugin.captcha.remove(name);
plugin.captcha.putIfAbsent(name, i); plugin.captcha.putIfAbsent(name, i);
} }
if (plugin.captcha.containsKey(name) && plugin.captcha.get(name) >= Settings.maxLoginTry) { if (plugin.captcha.containsKey(name) && plugin.captcha.get(name) >= Settings.maxLoginTry) {
plugin.cap.put(name, rdm.nextString()); 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("<theCaptcha>", plugin.cap.get(name))); player.sendMessage(s.replace("THE_CAPTCHA", plugin.cap.get(name)).replace("<theCaptcha>", plugin.cap.get(name)));
} }
return true; return true;
@ -217,7 +225,7 @@ public class AsyncronousLogin {
} else { } else {
msg = m.send("reg_msg"); 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); LimboCache.getInstance().getLimboPlayer(name).setMessageTaskId(msgT);
} }
return null; return null;
@ -228,7 +236,7 @@ public class AsyncronousLogin {
return null; return null;
} }
} }
PlayerAuth pAuth = database.getAuth(name); final PlayerAuth pAuth = database.getAuth(name);
if (pAuth == null) { if (pAuth == null) {
m.send(player, "user_unknown"); m.send(player, "user_unknown");
return null; return null;
@ -237,10 +245,11 @@ public class AsyncronousLogin {
m.send(player, "vb_nonActiv"); m.send(player, "vb_nonActiv");
return null; return null;
} }
AuthMeAsyncPreLoginEvent event = new AuthMeAsyncPreLoginEvent(player); final AuthMeAsyncPreLoginEvent event = new AuthMeAsyncPreLoginEvent(player);
Bukkit.getServer().getPluginManager().callEvent(event); Bukkit.getServer().getPluginManager().callEvent(event);
if (!event.canLogin()) if (!event.canLogin()) {
return null; return null;
}
return pAuth; return pAuth;
} }
} }

View File

@ -63,8 +63,10 @@ public class AsyncronousRegister {
PlayerAuth auth; PlayerAuth auth;
try { try {
final String hashnew = PasswordSecurity.getHash(Settings.getPasswordHash, password, name); 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(), auth = new PlayerAuth(name, hashnew, getIp(), 0, (int) player.getLocation().getX(), (int) player.getLocation().getY(), (int) player.getLocation().getZ(), player
player.getLocation().getWorld().getName(), email, player.getName()); .getLocation()
.getWorld()
.getName(), email, player.getName());
} catch (final NoSuchAlgorithmException e) { } catch (final NoSuchAlgorithmException e) {
ConsoleLogger.showError(e.getMessage()); ConsoleLogger.showError(e.getMessage());
m.send(player, "error"); m.send(player, "error");
@ -107,7 +109,7 @@ public class AsyncronousRegister {
PlayerCache.getInstance().addPlayer(auth); PlayerCache.getInstance().addPlayer(auth);
database.setLogged(name); database.setLogged(name);
} }
plugin.otherAccounts.addPlayer(player.getUniqueId()); plugin.otherAccounts.addPlayer(player.getName());
final ProcessSyncronousPasswordRegister syncronous = new ProcessSyncronousPasswordRegister(player, plugin); final ProcessSyncronousPasswordRegister syncronous = new ProcessSyncronousPasswordRegister(player, plugin);
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, syncronous); plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, syncronous);
} }

View File

@ -1,70 +1,57 @@
package fr.xephi.authme.settings; package fr.xephi.authme.settings;
import java.io.File;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import cn.citycraft.PluginHelper.config.FileConfig; import cn.citycraft.PluginHelper.config.FileConfig;
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.ConsoleLogger; import fr.xephi.authme.ConsoleLogger;
public class Messages { public class Messages {
private static Messages singleton = null; private static Messages singleton = null;
private final FileConfig config; private final FileConfig msgcfg;
private String lang = "zhcn";
public Messages(final File file, final String lang) { public Messages() {
config = new FileConfig(file); msgcfg = new FileConfig(AuthMe.getInstance(), "messages_zhcn.yml");
singleton = this; singleton = this;
this.lang = lang;
} }
public static Messages getInstance() { public static Messages getInstance() {
if (singleton == null) { if (singleton == null) {
singleton = new Messages(Settings.messageFile, Settings.messagesLanguage); singleton = new Messages();
} }
return singleton; return singleton;
} }
public String getString(final String string) { public String getString(final String string) {
return config.getMessage(string); return msgcfg.getMessage(string);
} }
public void reloadMessages() { public void reloadMessages() {
config.reload(); msgcfg.reload();
} }
public void send(final CommandSender sender, final String msg) { public void send(final CommandSender sender, final String msg) {
if (!Settings.messagesLanguage.equalsIgnoreCase(singleton.lang)) { String loc = msgcfg.getMessage(msg);
singleton.reloadMessages(); if (loc == null || loc.isEmpty()) {
}
String loc = config.getMessage(msg);
if (loc == null) {
loc = "错误的语言文件 " + msg + " ; 请联系管理员升级语言文件"; loc = "错误的语言文件 " + msg + " ; 请联系管理员升级语言文件";
ConsoleLogger.showError("错误的语言文件 " + msg + " 请检查您的配置文件" + config.getName() + " !"); ConsoleLogger.showError("错误的语言文件 " + msg + " 请检查您的配置文件" + msgcfg.getName() + " !");
} }
for (final String l : loc.split("&n")) { for (final String l : loc.split("&n")) {
sender.sendMessage(l.replace("&", "§")); sender.sendMessage(l);
} }
} }
public String[] send(final String msg) { public String[] send(final String msg) {
if (!Settings.messagesLanguage.equalsIgnoreCase(singleton.lang)) { final String s = msgcfg.getMessage(msg);
singleton.reloadMessages(); if (s == null || s.isEmpty()) {
} ConsoleLogger.showError("错误的语言文件 " + msg + " 请检查您的配置文件" + msgcfg.getName() + " !");
final String s = config.getMessage(msg);
if (s == null) {
ConsoleLogger.showError("错误的语言文件 " + msg + " 请检查您的配置文件" + config.getName() + " !");
final String[] loc = new String[1]; final String[] loc = new String[1];
loc[0] = "错误的语言文件 " + msg + " ; 请联系管理员升级语言文件"; loc[0] = "错误的语言文件 " + msg + " ; 请联系管理员升级语言文件";
return (loc); return (loc);
} }
final int i = s.split("&n").length; final int i = s.split("&n").length;
final String[] loc = new String[i]; 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) { if (loc.length == 0) {
loc[0] = "错误的语言文件 " + msg + " ; 请联系管理员升级语言文件"; loc[0] = "错误的语言文件 " + msg + " ; 请联系管理员升级语言文件";
} }

View File

@ -1,6 +1,5 @@
package fr.xephi.authme.settings; package fr.xephi.authme.settings;
import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
@ -8,19 +7,20 @@ import java.util.UUID;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import cn.citycraft.PluginHelper.config.FileConfig;
import fr.xephi.authme.AuthMe;
/** /**
* *
* @author Xephi59 * @author Xephi59
*/ */
public class OtherAccounts extends CustomConfiguration { public class OtherAccounts extends FileConfig {
private static OtherAccounts others = null; private static OtherAccounts others = null;
public OtherAccounts() { public OtherAccounts() {
super(new File("." + File.separator + "plugins" + File.separator + "AuthMe" + File.separator + "otheraccounts.yml")); super(AuthMe.getInstance(), "otheraccounts.yml");
others = this; others = this;
load();
save();
} }
public static OtherAccounts getInstance() { public static OtherAccounts getInstance() {
@ -30,40 +30,40 @@ public class OtherAccounts extends CustomConfiguration {
return others; return others;
} }
public void addPlayer(UUID uuid) { public void addPlayer(final String pname) {
try { try {
Player player = Bukkit.getPlayer(uuid); final Player player = Bukkit.getPlayer(pname);
if (player == null) if (player == null) {
return; 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(); save();
} }
} catch (NoSuchMethodError | Exception e) { } catch (NoSuchMethodError | Exception e) {
// ignore
} }
} }
public void clear(UUID uuid) { public void clear(final String pname) {
set(uuid.toString(), new ArrayList<String>()); set(pname, new ArrayList<String>());
save(); save();
} }
public List<String> getAllPlayersByUUID(UUID uuid) { public List<String> getAllPlayersByUUID(final UUID uuid) {
return this.getStringList(uuid.toString()); return this.getStringList(uuid.toString());
} }
public void removePlayer(UUID uuid) { public void removePlayer(final String pname) {
try { try {
Player player = Bukkit.getPlayer(uuid); final Player player = Bukkit.getPlayer(pname);
if (player == null) if (player == null) {
return; 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(); save();
} }
} catch (NoSuchMethodError | Exception e) { } catch (NoSuchMethodError | Exception e) {
// ignore
} }
} }
} }

View File

@ -17,7 +17,7 @@ import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.datasource.DataSource.DataSourceType; import fr.xephi.authme.datasource.DataSource.DataSourceType;
import fr.xephi.authme.security.HashAlgorithm; import fr.xephi.authme.security.HashAlgorithm;
public final class Settings extends FileConfig { public final class Settings {
public static List<String> allowCommands; public static List<String> allowCommands;
// This is not an option! // This is not an option!
@ -42,9 +42,8 @@ public final class Settings extends FileConfig {
public static List<String> getMySQLOtherUsernameColumn; public static List<String> getMySQLOtherUsernameColumn;
public static String getNickRegex, getUnloggedinGroup, getMySQLHost, getMySQLPort, getMySQLUsername, getMySQLPassword, getMySQLDatabase, getMySQLTablename, getMySQLColumnName, public static String getNickRegex, getUnloggedinGroup, getMySQLHost, getMySQLPort, getMySQLUsername, getMySQLPassword, getMySQLDatabase, getMySQLTablename, getMySQLColumnName,
getMySQLColumnPassword, getMySQLColumnIp, getMySQLColumnLastLogin, getMySQLColumnSalt, getMySQLColumnGroup, getMySQLColumnEmail, unRegisteredGroup, backupWindowsPath, getRegisteredGroup, getMySQLColumnPassword, getMySQLColumnIp, getMySQLColumnLastLogin, getMySQLColumnSalt, getMySQLColumnGroup, getMySQLColumnEmail, unRegisteredGroup, backupWindowsPath, getRegisteredGroup,
messagesLanguage, getMySQLlastlocX, getMySQLlastlocY, getMySQLlastlocZ, rakamakUsers, rakamakUsersIp, getmailAccount, getmailPassword, getmailSMTP, getMySQLColumnId, getmailSenderName, getMySQLlastlocX, getMySQLlastlocY, getMySQLlastlocZ, rakamakUsers, rakamakUsersIp, getmailAccount, getmailPassword, getmailSMTP, getMySQLColumnId, getmailSenderName, getMailSubject,
getMailSubject, getMailText, getMySQLlastlocWorld, defaultWorld, getPhpbbPrefix, getWordPressPrefix, getMySQLColumnLogged, spawnPriority, crazyloginFileName, getPassRegex, getMailText, getMySQLlastlocWorld, defaultWorld, getPhpbbPrefix, getWordPressPrefix, getMySQLColumnLogged, spawnPriority, crazyloginFileName, getPassRegex, getMySQLColumnRealName;
getMySQLColumnRealName;
public static HashAlgorithm getPasswordHash; public static HashAlgorithm getPasswordHash;
public static List<String> getRestrictedIp; public static List<String> getRestrictedIp;
public static List<String> getUnrestrictedName; public static List<String> getUnrestrictedName;
@ -59,7 +58,6 @@ public final class Settings extends FileConfig {
enableProtection, enableAntiBot, recallEmail, useWelcomeMessage, broadcastWelcomeMessage, forceRegKick, forceRegLogin, checkVeryGames, delayJoinMessage, noTeleport, applyBlindEffect, enableProtection, enableAntiBot, recallEmail, useWelcomeMessage, broadcastWelcomeMessage, forceRegKick, forceRegLogin, checkVeryGames, delayJoinMessage, noTeleport, applyBlindEffect,
customAttributes, generateImage, isRemoveSpeedEnabled; customAttributes, generateImage, isRemoveSpeedEnabled;
public static final File LOG_FILE = new File(APLUGIN_FOLDER, "authme.log"); public static final File LOG_FILE = new File(APLUGIN_FOLDER, "authme.log");
public static File messageFile;
public static int purgeDelay = 60; public static int purgeDelay = 60;
public static final File SETTINGS_FILE = new File(APLUGIN_FOLDER, "config.yml"); public static final File SETTINGS_FILE = new File(APLUGIN_FOLDER, "config.yml");
public static List<String> unsafePasswords; public static List<String> unsafePasswords;
@ -67,14 +65,11 @@ public final class Settings extends FileConfig {
public static List<String> welcomeMsg; public static List<String> welcomeMsg;
private static Settings instance;
private static AuthMe plugin; private static AuthMe plugin;
protected static FileConfig configFile; protected static FileConfig configFile;
public Settings(final AuthMe pl) { public Settings(final AuthMe pl) {
instance = this;
plugin = pl; plugin = pl;
configFile = (FileConfig) plugin.getConfig(); configFile = (FileConfig) plugin.getConfig();
} }
@ -296,19 +291,18 @@ public final class Settings extends FileConfig {
forceRegisterCommandsAsConsole = configFile.getStringList("settings.forceRegisterCommandsAsConsole"); forceRegisterCommandsAsConsole = configFile.getStringList("settings.forceRegisterCommandsAsConsole");
customAttributes = configFile.getBoolean("Hooks.customAttributes"); customAttributes = configFile.getBoolean("Hooks.customAttributes");
generateImage = configFile.getBoolean("Email.generateImage", true); generateImage = configFile.getBoolean("Email.generateImage", true);
messageFile = new File(APLUGIN_FOLDER, "messages_zhcn.yml");
// Load the welcome message // Load the welcome message
getWelcomeMessage(); getWelcomeMessage();
} }
public static boolean reloadcfg() { public static boolean reloadcfg() {
return instance.save(); return configFile.reload();
} }
public static void setValue(final String key, final Object value) { public static void setValue(final String key, final Object value) {
instance.set(key, value); configFile.set(key, value);
instance.save(); configFile.save();
} }
public static void switchAntiBotMod(final boolean mode) { public static void switchAntiBotMod(final boolean mode) {
@ -374,193 +368,193 @@ public final class Settings extends FileConfig {
public void mergeConfig() { public void mergeConfig() {
boolean changes = false; boolean changes = false;
if (contains("Xenoforo.predefinedSalt")) { if (configFile.contains("Xenoforo.predefinedSalt")) {
set("Xenoforo.predefinedSalt", null); configFile.set("Xenoforo.predefinedSalt", null);
changes = true; changes = true;
} }
if (configFile.getString("settings.security.passwordHash", "SHA256").toUpperCase().equals("XFSHA1") if (configFile.getString("settings.security.passwordHash", "SHA256").toUpperCase().equals("XFSHA1")
|| configFile.getString("settings.security.passwordHash", "SHA256").toUpperCase().equals("XFSHA256")) { || configFile.getString("settings.security.passwordHash", "SHA256").toUpperCase().equals("XFSHA256")) {
set("settings.security.passwordHash", "XENFORO"); configFile.set("settings.security.passwordHash", "XENFORO");
changes = true; changes = true;
} }
if (!contains("Protection.enableProtection")) { if (!configFile.contains("Protection.enableProtection")) {
set("Protection.enableProtection", false); configFile.set("Protection.enableProtection", false);
changes = true; changes = true;
} }
if (!contains("settings.restrictions.removeSpeed")) { if (!configFile.contains("settings.restrictions.removeSpeed")) {
set("settings.restrictions.removeSpeed", true); configFile.set("settings.restrictions.removeSpeed", true);
changes = true; changes = true;
} }
if (!contains("DataSource.mySQLMaxConections")) { if (!configFile.contains("DataSource.mySQLMaxConections")) {
set("DataSource.mySQLMaxConections", 25); configFile.set("DataSource.mySQLMaxConections", 25);
changes = true; changes = true;
} }
if (!contains("Protection.countries")) { if (!configFile.contains("Protection.countries")) {
countries = new ArrayList<>(); countries = new ArrayList<>();
countries.add("US"); countries.add("US");
countries.add("GB"); countries.add("GB");
set("Protection.countries", countries); configFile.set("Protection.countries", countries);
changes = true; changes = true;
} }
if (!contains("Protection.enableAntiBot")) { if (!configFile.contains("Protection.enableAntiBot")) {
set("Protection.enableAntiBot", false); configFile.set("Protection.enableAntiBot", false);
changes = true; changes = true;
} }
if (!contains("Protection.antiBotSensibility")) { if (!configFile.contains("Protection.antiBotSensibility")) {
set("Protection.antiBotSensibility", 5); configFile.set("Protection.antiBotSensibility", 5);
changes = true; changes = true;
} }
if (!contains("Protection.antiBotDuration")) { if (!configFile.contains("Protection.antiBotDuration")) {
set("Protection.antiBotDuration", 10); configFile.set("Protection.antiBotDuration", 10);
changes = true; changes = true;
} }
if (!contains("settings.forceCommands")) { if (!configFile.contains("settings.forceCommands")) {
set("settings.forceCommands", new ArrayList<String>()); configFile.set("settings.forceCommands", new ArrayList<String>());
changes = true; changes = true;
} }
if (!contains("settings.forceCommandsAsConsole")) { if (!configFile.contains("settings.forceCommandsAsConsole")) {
set("settings.forceCommandsAsConsole", new ArrayList<String>()); configFile.set("settings.forceCommandsAsConsole", new ArrayList<String>());
changes = true; changes = true;
} }
if (!contains("Email.recallPlayers")) { if (!configFile.contains("Email.recallPlayers")) {
set("Email.recallPlayers", false); configFile.set("Email.recallPlayers", false);
changes = true; changes = true;
} }
if (!contains("Email.delayRecall")) { if (!configFile.contains("Email.delayRecall")) {
set("Email.delayRecall", 5); configFile.set("Email.delayRecall", 5);
changes = true; changes = true;
} }
if (!contains("settings.useWelcomeMessage")) { if (!configFile.contains("settings.useWelcomeMessage")) {
set("settings.useWelcomeMessage", true); configFile.set("settings.useWelcomeMessage", true);
changes = true; changes = true;
} }
if (!contains("settings.security.unsafePasswords")) { if (!configFile.contains("settings.security.unsafePasswords")) {
final List<String> str = new ArrayList<>(); final List<String> str = new ArrayList<>();
str.add("123456"); str.add("123456");
str.add("password"); str.add("password");
set("settings.security.unsafePasswords", str); configFile.set("settings.security.unsafePasswords", str);
changes = true; changes = true;
} }
if (!contains("Protection.countriesBlacklist")) { if (!configFile.contains("Protection.countriesBlacklist")) {
countriesBlacklist = new ArrayList<>(); countriesBlacklist = new ArrayList<>();
countriesBlacklist.add("A1"); countriesBlacklist.add("A1");
set("Protection.countriesBlacklist", countriesBlacklist); configFile.set("Protection.countriesBlacklist", countriesBlacklist);
changes = true; changes = true;
} }
if (!contains("settings.broadcastWelcomeMessage")) { if (!configFile.contains("settings.broadcastWelcomeMessage")) {
set("settings.broadcastWelcomeMessage", false); configFile.set("settings.broadcastWelcomeMessage", false);
changes = true; changes = true;
} }
if (!contains("settings.registration.forceKickAfterRegister")) { if (!configFile.contains("settings.registration.forceKickAfterRegister")) {
set("settings.registration.forceKickAfterRegister", false); configFile.set("settings.registration.forceKickAfterRegister", false);
changes = true; changes = true;
} }
if (!contains("settings.registration.forceLoginAfterRegister")) { if (!configFile.contains("settings.registration.forceLoginAfterRegister")) {
set("settings.registration.forceLoginAfterRegister", false); configFile.set("settings.registration.forceLoginAfterRegister", false);
changes = true; changes = true;
} }
if (!contains("DataSource.mySQLColumnLogged")) { if (!configFile.contains("DataSource.mySQLColumnLogged")) {
set("DataSource.mySQLColumnLogged", "isLogged"); configFile.set("DataSource.mySQLColumnLogged", "isLogged");
changes = true; changes = true;
} }
if (!contains("settings.restrictions.spawnPriority")) { if (!configFile.contains("settings.restrictions.spawnPriority")) {
set("settings.restrictions.spawnPriority", "authme,essentials,multiverse,default"); configFile.set("settings.restrictions.spawnPriority", "authme,essentials,multiverse,default");
changes = true; changes = true;
} }
if (!contains("settings.restrictions.maxLoginPerIp")) { if (!configFile.contains("settings.restrictions.maxLoginPerIp")) {
set("settings.restrictions.maxLoginPerIp", 0); configFile.set("settings.restrictions.maxLoginPerIp", 0);
changes = true; changes = true;
} }
if (!contains("settings.restrictions.maxJoinPerIp")) { if (!configFile.contains("settings.restrictions.maxJoinPerIp")) {
set("settings.restrictions.maxJoinPerIp", 0); configFile.set("settings.restrictions.maxJoinPerIp", 0);
changes = true; changes = true;
} }
if (getString("settings.restrictions.allowedNicknameCharacters").equals("[a-zA-Z0-9_?]*")) { if (configFile.getString("settings.restrictions.allowedNicknameCharacters").equals("[a-zA-Z0-9_?]*")) {
set("settings.restrictions.allowedNicknameCharacters", "[a-zA-Z0-9_]*"); configFile.set("settings.restrictions.allowedNicknameCharacters", "[a-zA-Z0-9_]*");
changes = true; changes = true;
} }
if (!contains("settings.delayJoinMessage")) { if (!configFile.contains("settings.delayJoinMessage")) {
set("settings.delayJoinMessage", false); configFile.set("settings.delayJoinMessage", false);
changes = true; changes = true;
} }
if (!contains("settings.restrictions.noTeleport")) { if (!configFile.contains("settings.restrictions.noTeleport")) {
set("settings.restrictions.noTeleport", false); configFile.set("settings.restrictions.noTeleport", false);
changes = true; changes = true;
} }
if (contains("Converter.Rakamak.newPasswordHash")) { if (configFile.contains("Converter.Rakamak.newPasswordHash")) {
set("Converter.Rakamak.newPasswordHash", null); configFile.set("Converter.Rakamak.newPasswordHash", null);
changes = true; changes = true;
} }
if (!contains("Converter.CrazyLogin.fileName")) { if (!configFile.contains("Converter.CrazyLogin.fileName")) {
set("Converter.CrazyLogin.fileName", "accounts.db"); configFile.set("Converter.CrazyLogin.fileName", "accounts.db");
changes = true; changes = true;
} }
if (!contains("settings.restrictions.allowedPasswordCharacters")) { if (!configFile.contains("settings.restrictions.allowedPasswordCharacters")) {
set("settings.restrictions.allowedPasswordCharacters", "[\\x21-\\x7E]*"); configFile.set("settings.restrictions.allowedPasswordCharacters", "[\\x21-\\x7E]*");
changes = true; changes = true;
} }
if (!contains("settings.applyBlindEffect")) { if (!configFile.contains("settings.applyBlindEffect")) {
set("settings.applyBlindEffect", false); configFile.set("settings.applyBlindEffect", false);
changes = true; changes = true;
} }
if (!contains("Email.emailBlacklisted")) { if (!configFile.contains("Email.emailBlacklisted")) {
set("Email.emailBlacklisted", new ArrayList<String>()); configFile.set("Email.emailBlacklisted", new ArrayList<String>());
changes = true; changes = true;
} }
if (contains("Performances.useMultiThreading")) { if (configFile.contains("Performances.useMultiThreading")) {
set("Performances.useMultiThreading", null); configFile.set("Performances.useMultiThreading", null);
changes = true; changes = true;
} }
if (contains("Performances")) { if (configFile.contains("Performances")) {
set("Performances", null); configFile.set("Performances", null);
changes = true; changes = true;
} }
if (contains("Passpartu.enablePasspartu")) { if (configFile.contains("Passpartu.enablePasspartu")) {
set("Passpartu.enablePasspartu", null); configFile.set("Passpartu.enablePasspartu", null);
changes = true; changes = true;
} }
if (contains("Passpartu")) { if (configFile.contains("Passpartu")) {
set("Passpartu", null); configFile.set("Passpartu", null);
changes = true; changes = true;
} }
if (!contains("Email.emailWhitelisted")) { if (!configFile.contains("Email.emailWhitelisted")) {
set("Email.emailWhitelisted", new ArrayList<String>()); configFile.set("Email.emailWhitelisted", new ArrayList<String>());
changes = true; changes = true;
} }
if (!contains("settings.forceRegisterCommands")) { if (!configFile.contains("settings.forceRegisterCommands")) {
set("settings.forceRegisterCommands", new ArrayList<String>()); configFile.set("settings.forceRegisterCommands", new ArrayList<String>());
changes = true; changes = true;
} }
if (!contains("settings.forceRegisterCommandsAsConsole")) { if (!configFile.contains("settings.forceRegisterCommandsAsConsole")) {
set("settings.forceRegisterCommandsAsConsole", new ArrayList<String>()); configFile.set("settings.forceRegisterCommandsAsConsole", new ArrayList<String>());
changes = true; changes = true;
} }
if (!contains("Hooks.customAttributes")) { if (!configFile.contains("Hooks.customAttributes")) {
set("Hooks.customAttributes", false); configFile.set("Hooks.customAttributes", false);
changes = true; changes = true;
} }
if (!contains("Purge.removePermissions")) { if (!configFile.contains("Purge.removePermissions")) {
set("Purge.removePermissions", false); configFile.set("Purge.removePermissions", false);
changes = true; changes = true;
} }
if (contains("Hooks.notifications")) { if (configFile.contains("Hooks.notifications")) {
set("Hooks.notifications", null); configFile.set("Hooks.notifications", null);
changes = true; changes = true;
} }
if (contains("Hooks.chestshop")) { if (configFile.contains("Hooks.chestshop")) {
set("Hooks.chestshop", null); configFile.set("Hooks.chestshop", null);
changes = true; changes = true;
} }
if (contains("Hooks.legacyChestshop")) { if (configFile.contains("Hooks.legacyChestshop")) {
set("Hooks.legacyChestshop", null); configFile.set("Hooks.legacyChestshop", null);
changes = true; changes = true;
} }
if (!contains("Email.generateImage")) { if (!configFile.contains("Email.generateImage")) {
set("Email.generateImage", true); configFile.set("Email.generateImage", true);
changes = true; changes = true;
} }
if (!contains("DataSource.mySQLRealName")) { if (!configFile.contains("DataSource.mySQLRealName")) {
set("DataSource.mySQLRealName", "realname"); configFile.set("DataSource.mySQLRealName", "realname");
changes = true; changes = true;
} }
@ -569,20 +563,4 @@ public final class Settings extends FileConfig {
plugin.getLogger().warning("请检查新的 config.yml 文件 并修改相关配置!"); plugin.getLogger().warning("请检查新的 config.yml 文件 并修改相关配置!");
} }
} }
/**
* Saves current configuration (plus defaults) to disk.
* <p>
* 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;
}
} }

Binary file not shown.