diff --git a/pom.xml b/pom.xml index 2ca8916..1d77b2c 100644 --- a/pom.xml +++ b/pom.xml @@ -26,31 +26,31 @@ com.cryptomorin.xseries - net.tylermurphy.hideAndSeek.util.xseries + net.tylermurphy.xseries - - com.github.cryptomorin:XSeries - org.xerial:sqlite-jdbc - + + org.spigotmc:spigot-api + com.comphenix.protocol:ProtocolLib + org.jetbrains:annotations + net.bytebuddy:byte-buddy + *:* META-INF/*.MF - com/cryptomorin/xseries/XBiome* - com/cryptomorin/xseries/NMSExtras* - com/cryptomorin/xseries/NoteBlockMusic* - com/cryptomorin/xseries/SkullCacheListener* - com/cryptomorin/xseries/XBlock* - com/cryptomorin/xseries/XEntity* - com/cryptomorin/xseries/particles/* - com/cryptomorin/xseries/messages/ActionBar* + sqlite-jdbc.properties + + + META-INF/services/java.sql.Driver + + @@ -89,9 +89,7 @@ org.xerial sqlite-jdbc - 3.36.0.3 - jar - provided + 3.7.2 org.jetbrains diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Localization.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Localization.java index 07402d1..b93329f 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Localization.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Localization.java @@ -36,7 +36,7 @@ public class Localization { public static void loadLocalization() { - ConfigManager manager = new ConfigManager("localization.yml", "lang"+File.separator+"localization_"+Config.locale +".yml"); + ConfigManager manager = new ConfigManager("localization.yml", "lang/localization_"+Config.locale +".yml"); int PLUGIN_VERSION = manager.getDefaultInt("version"); int VERSION = manager.getInt("version"); diff --git a/src/main/java/net/tylermurphy/hideAndSeek/database/Database.java b/src/main/java/net/tylermurphy/hideAndSeek/database/Database.java index 9a0837b..8001368 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/database/Database.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/database/Database.java @@ -21,6 +21,8 @@ package net.tylermurphy.hideAndSeek.database; import com.google.common.io.ByteStreams; import net.tylermurphy.hideAndSeek.Main; +import org.sqlite.SQLiteConfig; +import sun.font.ScriptRun; import java.io.ByteArrayInputStream; import java.io.File; @@ -30,6 +32,8 @@ import java.nio.ByteBuffer; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; + +import java.sql.Statement; import java.util.UUID; public class Database { @@ -37,14 +41,15 @@ public class Database { private static final File databaseFile = new File(Main.data, "database.db"); public static PlayerInfoTable playerInfo; + private static SQLiteConfig config; protected static Connection connect() { Connection conn = null; try { String url = "jdbc:sqlite:"+databaseFile; - conn = DriverManager.getConnection(url); + conn = DriverManager.getConnection(url, config.toProperties()); } catch (SQLException e) { - System.out.println(e.getMessage()); + Main.plugin.getLogger().severe(e.getMessage()); } return conn; } @@ -71,10 +76,15 @@ public class Database { try { Class.forName("org.sqlite.JDBC"); } catch (ClassNotFoundException e) { - Main.plugin.getLogger().severe("Unable to load SQLite driver!"); - System.exit(-1); - return; + Main.plugin.getLogger().severe(e.getMessage()); + throw new RuntimeException(e.getMessage()); } + + config = new SQLiteConfig(); + config.setSynchronous(SQLiteConfig.SynchronousMode.NORMAL); + config.setTempStore(SQLiteConfig.TempStore.MEMORY); + playerInfo = new PlayerInfoTable(); } + } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/database/PlayerInfoTable.java b/src/main/java/net/tylermurphy/hideAndSeek/database/PlayerInfoTable.java index e859687..7b9b476 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/database/PlayerInfoTable.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/database/PlayerInfoTable.java @@ -20,8 +20,10 @@ package net.tylermurphy.hideAndSeek.database; import net.tylermurphy.hideAndSeek.Main; +import net.tylermurphy.hideAndSeek.configuration.Config; import net.tylermurphy.hideAndSeek.util.WinType; +import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.sql.*; @@ -42,7 +44,7 @@ public class PlayerInfoTable { + ");"; try(Connection connection = Database.connect(); Statement statement = connection.createStatement()){ - statement.execute(sql); + statement.executeUpdate(sql); } catch (SQLException e){ Main.plugin.getLogger().severe("SQL Error: " + e.getMessage()); } @@ -59,6 +61,8 @@ public class PlayerInfoTable { statement.setBytes(1, bytes); ResultSet rs = statement.executeQuery(); if(rs.next()){ + rs.close(); + connection.close(); return new PlayerInfo( uuid, rs.getInt("wins"), @@ -67,6 +71,7 @@ public class PlayerInfoTable { rs.getInt("games_played") ); } + rs.close(); } catch (SQLException e){ Main.plugin.getLogger().severe("SQL Error: " + e.getMessage()); } catch (IOException e) { @@ -84,7 +89,7 @@ public class PlayerInfoTable { List infoList = new ArrayList<>(); while(rs.next()){ PlayerInfo info = new PlayerInfo( - Database.convertBinaryStream(rs.getBinaryStream("uuid")), + Database.convertBinaryStream(new ByteArrayInputStream(rs.getBytes("uuid"))), rs.getInt("wins"), rs.getInt("seeker_wins"), rs.getInt("hider_wins"), @@ -92,6 +97,8 @@ public class PlayerInfoTable { ); infoList.add(info); } + rs.close(); + connection.close(); return infoList; } catch (SQLException e){ Main.plugin.getLogger().severe("SQL Error: " + e.getMessage()); diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/EventListener.java b/src/main/java/net/tylermurphy/hideAndSeek/game/EventListener.java index 698d650..aab55d4 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/EventListener.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/EventListener.java @@ -271,9 +271,13 @@ public class EventListener implements Listener { } } } + String[] temp = array[0].split(":"); for(String handle : blockedCommands){ - System.out.println(handle); - if(array[0].substring(1).equalsIgnoreCase(handle) && Board.isPlayer(player) && Game.status != Status.STANDBY){ + if( + array[0].substring(1).equalsIgnoreCase(handle) && Board.isPlayer(player) && + temp[temp.length-1].substring(1).equalsIgnoreCase(handle) && Board.isPlayer(player) && + Game.status != Status.STANDBY + ) { player.sendMessage(errorPrefix + message("BLOCKED_COMMAND")); event.setCancelled(true); break;