diff --git a/src/main/java/cc/baka9/catseedlogin/bukkit/database/MySQL.java b/src/main/java/cc/baka9/catseedlogin/bukkit/database/MySQL.java index 88f6c79..6140707 100644 --- a/src/main/java/cc/baka9/catseedlogin/bukkit/database/MySQL.java +++ b/src/main/java/cc/baka9/catseedlogin/bukkit/database/MySQL.java @@ -16,7 +16,7 @@ public MySQL(JavaPlugin javaPlugin) { } @Override - public Connection getConnection() throws SQLException { + public synchronized Connection getConnection() throws SQLException { if (isConnectionValid()) { return this.connection; } diff --git a/src/main/java/cc/baka9/catseedlogin/bukkit/database/SQLite.java b/src/main/java/cc/baka9/catseedlogin/bukkit/database/SQLite.java index f225651..9a61c3e 100644 --- a/src/main/java/cc/baka9/catseedlogin/bukkit/database/SQLite.java +++ b/src/main/java/cc/baka9/catseedlogin/bukkit/database/SQLite.java @@ -14,24 +14,35 @@ public SQLite(JavaPlugin javaPlugin) { } @Override - public Connection getConnection() { - try { - if (connection == null || connection.isClosed()) { - connection = createConnection(); - } - return connection; - } catch (SQLException e) { - return null; + public synchronized Connection getConnection() throws SQLException { + if (connection == null || connection.isClosed()) { + connection = createConnection(); } + return connection; } private Connection createConnection() throws SQLException { try { - if (!plugin.getDataFolder().exists()) plugin.getDataFolder().mkdir(); + ensureDataFolderExists(); Class.forName("org.sqlite.JDBC"); return DriverManager.getConnection("jdbc:sqlite:" + plugin.getDataFolder().getAbsolutePath() + "/accounts.db"); } catch (ClassNotFoundException e) { throw new SQLException(e); } } + + private void ensureDataFolderExists() { + if (!plugin.getDataFolder().exists()) { + plugin.getDataFolder().mkdir(); + } + } + + public void closeConnection() { + try { + if (connection != null && !connection.isClosed()) { + connection.close(); + } + } catch (SQLException e) { + } + } } diff --git a/src/main/java/cc/baka9/catseedlogin/bukkit/object/LoginPlayerHelper.java b/src/main/java/cc/baka9/catseedlogin/bukkit/object/LoginPlayerHelper.java index 6f3421c..ff2ac76 100644 --- a/src/main/java/cc/baka9/catseedlogin/bukkit/object/LoginPlayerHelper.java +++ b/src/main/java/cc/baka9/catseedlogin/bukkit/object/LoginPlayerHelper.java @@ -1,5 +1,7 @@ package cc.baka9.catseedlogin.bukkit.object; +import java.net.InetAddress; +import java.net.UnknownHostException; import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; @@ -102,7 +104,12 @@ public static boolean recordCurrentIP(Player player) { List storedIPs = getStoredIPs(storedPlayer); Long exitTime = playerExitTimes.get(playerName); - if (currentIP.equals("127.0.0.1")) { + try { + InetAddress localHost = InetAddress.getByName("localhost"); + if (InetAddress.getByName(currentIP).equals(localHost)) { + return false; + } + } catch (UnknownHostException e) { return false; }