From 180bf7f6428b51ff090b9ef9893fae8ccc05e44e Mon Sep 17 00:00:00 2001 From: ceze88 <70201650+ceze88@users.noreply.github.com> Date: Tue, 9 Aug 2022 15:26:16 +0200 Subject: [PATCH 1/4] Updated deprecated methods, added MySQL support --- pom.xml | 2 +- .../com/songoda/epichoppers/EpicHoppers.java | 23 +- .../epichoppers/commands/CommandReload.java | 2 +- .../epichoppers/database/DataManager.java | 448 ++++++++++-------- .../epichoppers/settings/Settings.java | 10 + 5 files changed, 275 insertions(+), 210 deletions(-) diff --git a/pom.xml b/pom.xml index ad8a6d1..8f92b2e 100644 --- a/pom.xml +++ b/pom.xml @@ -133,7 +133,7 @@ com.songoda SongodaCore - 2.6.13 + 2.6.14-DEV compile diff --git a/src/main/java/com/songoda/epichoppers/EpicHoppers.java b/src/main/java/com/songoda/epichoppers/EpicHoppers.java index 0f98e6e..dae3cdb 100644 --- a/src/main/java/com/songoda/epichoppers/EpicHoppers.java +++ b/src/main/java/com/songoda/epichoppers/EpicHoppers.java @@ -7,6 +7,7 @@ import com.songoda.core.compatibility.CompatibleMaterial; import com.songoda.core.configuration.Config; import com.songoda.core.database.DataMigrationManager; import com.songoda.core.database.DatabaseConnector; +import com.songoda.core.database.MySQLConnector; import com.songoda.core.database.SQLiteConnector; import com.songoda.core.gui.GuiManager; import com.songoda.core.hooks.EconomyManager; @@ -122,8 +123,26 @@ public class EpicHoppers extends SongodaPlugin { this.boostManager = new BoostManager(); // Database stuff, go! - this.databaseConnector = new SQLiteConnector(this); - this.getLogger().info("Data handler connected using SQLite."); + try { + if (Settings.MYSQL_ENABLED.getBoolean()) { + String hostname = Settings.MYSQL_HOSTNAME.getString(); + int port = Settings.MYSQL_PORT.getInt(); + String database = Settings.MYSQL_DATABASE.getString(); + String username = Settings.MYSQL_USERNAME.getString(); + String password = Settings.MYSQL_PASSWORD.getString(); + boolean useSSL = Settings.MYSQL_USE_SSL.getBoolean(); + int poolSize = Settings.MYSQL_POOL_SIZE.getInt(); + + this.databaseConnector = new MySQLConnector(this, hostname, port, database, username, password, useSSL, poolSize); + this.getLogger().info("Data handler connected using MySQL."); + } else { + this.databaseConnector = new SQLiteConnector(this); + this.getLogger().info("Data handler connected using SQLite."); + } + } catch (Exception ex) { + this.getLogger().severe("Fatal error trying to connect to database. Please make sure all your connection settings are correct and try again. Plugin has been disabled."); + this.emergencyStop(); + } this.dataManager = new DataManager(this.databaseConnector, this); DataMigrationManager dataMigrationManager = new DataMigrationManager(this.databaseConnector, this.dataManager, diff --git a/src/main/java/com/songoda/epichoppers/commands/CommandReload.java b/src/main/java/com/songoda/epichoppers/commands/CommandReload.java index e3888e8..2a30d9d 100644 --- a/src/main/java/com/songoda/epichoppers/commands/CommandReload.java +++ b/src/main/java/com/songoda/epichoppers/commands/CommandReload.java @@ -11,7 +11,7 @@ public class CommandReload extends AbstractCommand { private final EpicHoppers plugin; public CommandReload(EpicHoppers plugin) { - super(false, "reload"); + super(CommandType.CONSOLE_OK, "reload"); this.plugin = plugin; } diff --git a/src/main/java/com/songoda/epichoppers/database/DataManager.java b/src/main/java/com/songoda/epichoppers/database/DataManager.java index ad1af16..921e81f 100644 --- a/src/main/java/com/songoda/epichoppers/database/DataManager.java +++ b/src/main/java/com/songoda/epichoppers/database/DataManager.java @@ -21,6 +21,7 @@ import org.bukkit.util.io.BukkitObjectOutputStream; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; +import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.Statement; @@ -39,21 +40,25 @@ public class DataManager extends DataManagerAbstract { } public void createBoost(BoostData boostData) { - this.async(() -> this.databaseConnector.connect(connection -> { - String createBoostedPlayer = "INSERT INTO " + this.getTablePrefix() + "boosted_players (player, multiplier, end_time) VALUES (?, ?, ?)"; - try (PreparedStatement statement = connection.prepareStatement(createBoostedPlayer)) { + this.runAsync(() -> { + try (Connection connection = this.databaseConnector.getConnection()){ + String createBoostedPlayer = "INSERT INTO " + this.getTablePrefix() + "boosted_players (player, multiplier, end_time) VALUES (?, ?, ?)"; + PreparedStatement statement = connection.prepareStatement(createBoostedPlayer); statement.setString(1, boostData.getPlayer().toString()); statement.setInt(2, boostData.getMultiplier()); statement.setLong(3, boostData.getEndTime()); statement.executeUpdate(); + } catch (Exception ex) { + ex.printStackTrace(); } - })); + }); } public void getBoosts(Consumer> callback) { List boosts = new ArrayList<>(); - this.async(() -> this.databaseConnector.connect(connection -> { - try (Statement statement = connection.createStatement()) { + this.runAsync(() -> { + try (Connection connection = this.databaseConnector.getConnection()){ + Statement statement = connection.createStatement(); String selectBoostedPlayers = "SELECT * FROM " + this.getTablePrefix() + "boosted_players"; ResultSet result = statement.executeQuery(selectBoostedPlayers); while (result.next()) { @@ -62,26 +67,32 @@ public class DataManager extends DataManagerAbstract { long endTime = result.getLong("end_time"); boosts.add(new BoostData(multiplier, endTime, player)); } - } - this.sync(() -> callback.accept(boosts)); - })); + this.sync(() -> callback.accept(boosts)); + } catch (Exception ex) { + ex.printStackTrace(); + } + }); } public void deleteBoost(BoostData boostData) { - this.async(() -> this.databaseConnector.connect(connection -> { - String deleteBoost = "DELETE FROM " + this.getTablePrefix() + "boosted_players WHERE end_time = ?"; - try (PreparedStatement statement = connection.prepareStatement(deleteBoost)) { + this.runAsync(() -> { + try (Connection connection = this.databaseConnector.getConnection()){ + String deleteBoost = "DELETE FROM " + this.getTablePrefix() + "boosted_players WHERE end_time = ?"; + PreparedStatement statement = connection.prepareStatement(deleteBoost); statement.setLong(1, boostData.getEndTime()); statement.executeUpdate(); + } catch (Exception ex) { + ex.printStackTrace(); } - })); + }); } public void createLink(Hopper hopper, Location location, LinkType type) { - this.async(() -> this.databaseConnector.connect(connection -> { - String createLink = "INSERT INTO " + this.getTablePrefix() + "links (hopper_id, link_type, world, x, y, z) VALUES (?, ?, ?, ?, ?, ?)"; - try (PreparedStatement statement = connection.prepareStatement(createLink)) { + this.runAsync(() -> { + try (Connection connection = this.databaseConnector.getConnection()){ + String createLink = "INSERT INTO " + this.getTablePrefix() + "links (hopper_id, link_type, world, x, y, z) VALUES (?, ?, ?, ?, ?, ?)"; + PreparedStatement statement = connection.prepareStatement(createLink); statement.setInt(1, hopper.getId()); statement.setString(2, type.name()); @@ -91,62 +102,73 @@ public class DataManager extends DataManagerAbstract { statement.setInt(5, location.getBlockY()); statement.setInt(6, location.getBlockZ()); statement.executeUpdate(); + } catch (Exception ex) { + ex.printStackTrace(); } - })); + }); } public void updateItems(Hopper hopper, ItemType type, List items) { - this.async(() -> this.databaseConnector.connect(connection -> { - - String clearItems = "DELETE FROM " + this.getTablePrefix() + "items WHERE hopper_id = ? AND item_type = ?"; - try (PreparedStatement statement = connection.prepareStatement(clearItems)) { - statement.setInt(1, hopper.getId()); - statement.setString(2, type.name()); - statement.executeUpdate(); - } - - String createItem = "INSERT INTO " + this.getTablePrefix() + "items (hopper_id, item_type, item) VALUES (?, ?, ?)"; - try (PreparedStatement statement = connection.prepareStatement(createItem)) { - for (ItemStack item : items) { + this.runAsync(() -> { + try (Connection connection = this.databaseConnector.getConnection()){ + String clearItems = "DELETE FROM " + this.getTablePrefix() + "items WHERE hopper_id = ? AND item_type = ?"; + try (PreparedStatement statement = connection.prepareStatement(clearItems)) { statement.setInt(1, hopper.getId()); statement.setString(2, type.name()); - - try (ByteArrayOutputStream stream = new ByteArrayOutputStream(); BukkitObjectOutputStream bukkitStream = new BukkitObjectOutputStream(stream)) { - bukkitStream.writeObject(item); - statement.setString(3, Base64.getEncoder().encodeToString(stream.toByteArray())); - } catch (IOException e) { - e.printStackTrace(); - continue; - } - statement.addBatch(); + statement.executeUpdate(); } - statement.executeBatch(); + + String createItem = "INSERT INTO " + this.getTablePrefix() + "items (hopper_id, item_type, item) VALUES (?, ?, ?)"; + try (PreparedStatement statement = connection.prepareStatement(createItem)) { + for (ItemStack item : items) { + statement.setInt(1, hopper.getId()); + statement.setString(2, type.name()); + + try (ByteArrayOutputStream stream = new ByteArrayOutputStream(); BukkitObjectOutputStream bukkitStream = new BukkitObjectOutputStream(stream)) { + bukkitStream.writeObject(item); + statement.setString(3, Base64.getEncoder().encodeToString(stream.toByteArray())); + } catch (IOException e) { + e.printStackTrace(); + continue; + } + statement.addBatch(); + } + statement.executeBatch(); + } + } catch (Exception ex) { + ex.printStackTrace(); } - })); + }); } public void deleteLink(Hopper hopper, Location location) { - this.async(() -> this.databaseConnector.connect(connection -> { - String deleteLink = "DELETE FROM " + this.getTablePrefix() + "links WHERE hopper_id = ? AND world = ? AND x = ? AND y = ? AND z = ?"; - try (PreparedStatement statement = connection.prepareStatement(deleteLink)) { + this.runAsync(() -> { + try (Connection connection = this.databaseConnector.getConnection()){ + String deleteLink = "DELETE FROM " + this.getTablePrefix() + "links WHERE hopper_id = ? AND world = ? AND x = ? AND y = ? AND z = ?"; + PreparedStatement statement = connection.prepareStatement(deleteLink); statement.setInt(1, hopper.getId()); statement.setString(2, location.getWorld().getName()); statement.setInt(3, location.getBlockX()); statement.setInt(4, location.getBlockY()); statement.setInt(5, location.getBlockZ()); statement.executeUpdate(); + } catch (Exception ex) { + ex.printStackTrace(); } - })); + }); } public void deleteLinks(Hopper hopper) { - this.async(() -> this.databaseConnector.connect(connection -> { - String deleteHopperLinks = "DELETE FROM " + this.getTablePrefix() + "links WHERE hopper_id = ?"; - try (PreparedStatement statement = connection.prepareStatement(deleteHopperLinks)) { + this.runAsync(() -> { + try (Connection connection = this.databaseConnector.getConnection()){ + String deleteHopperLinks = "DELETE FROM " + this.getTablePrefix() + "links WHERE hopper_id = ?"; + PreparedStatement statement = connection.prepareStatement(deleteHopperLinks); statement.setInt(1, hopper.getId()); statement.executeUpdate(); + } catch (Exception ex) { + ex.printStackTrace(); } - })); + }); } public void createHoppers(List hoppers) { @@ -155,217 +177,231 @@ public class DataManager extends DataManagerAbstract { } public void createHopper(Hopper hopper) { - this.queueAsync(() -> this.databaseConnector.connect(connection -> { - String createHopper = "INSERT INTO " + this.getTablePrefix() + "placed_hoppers (level, placed_by, last_opened_by, teleport_trigger, world, x, y, z) VALUES (?, ?, ?, ?, ?, ?, ?, ?)"; - try (PreparedStatement statement = connection.prepareStatement(createHopper)) { - statement.setInt(1, hopper.getLevel().getLevel()); + this.runAsync(() -> { + try (Connection connection = this.databaseConnector.getConnection()){ + String createHopper = "INSERT INTO " + this.getTablePrefix() + "placed_hoppers (level, placed_by, last_opened_by, teleport_trigger, world, x, y, z) VALUES (?, ?, ?, ?, ?, ?, ?, ?)"; + try (PreparedStatement statement = connection.prepareStatement(createHopper)) { + statement.setInt(1, hopper.getLevel().getLevel()); - statement.setString(2, - hopper.getPlacedBy() == null ? null : hopper.getPlacedBy().toString()); + statement.setString(2, + hopper.getPlacedBy() == null ? null : hopper.getPlacedBy().toString()); - statement.setString(3, - hopper.getLastPlayerOpened() == null ? null : hopper.getLastPlayerOpened().toString()); + statement.setString(3, + hopper.getLastPlayerOpened() == null ? null : hopper.getLastPlayerOpened().toString()); - statement.setString(4, hopper.getTeleportTrigger().name()); + statement.setString(4, hopper.getTeleportTrigger().name()); - statement.setString(5, hopper.getWorld().getName()); - statement.setInt(6, hopper.getX()); - statement.setInt(7, hopper.getY()); - statement.setInt(8, hopper.getZ()); - statement.executeUpdate(); - } + statement.setString(5, hopper.getWorld().getName()); + statement.setInt(6, hopper.getX()); + statement.setInt(7, hopper.getY()); + statement.setInt(8, hopper.getZ()); + statement.executeUpdate(); + } - int hopperId = this.lastInsertedId(connection, "placed_hoppers"); - hopper.setId(hopperId); + int hopperId = this.lastInsertedId(connection, "placed_hoppers"); + hopper.setId(hopperId); - Map items = new HashMap<>(); - Filter filter = hopper.getFilter(); + Map items = new HashMap<>(); + Filter filter = hopper.getFilter(); - for (ItemStack item : filter.getWhiteList()) - items.put(item, ItemType.WHITELIST); + for (ItemStack item : filter.getWhiteList()) + items.put(item, ItemType.WHITELIST); - for (ItemStack item : filter.getBlackList()) - items.put(item, ItemType.BLACKLIST); + for (ItemStack item : filter.getBlackList()) + items.put(item, ItemType.BLACKLIST); - for (ItemStack item : filter.getVoidList()) - items.put(item, ItemType.VOID); + for (ItemStack item : filter.getVoidList()) + items.put(item, ItemType.VOID); - for (ItemStack item : filter.getAutoSellWhiteList()) - items.put(item, ItemType.AUTO_SELL_WHITELIST); + for (ItemStack item : filter.getAutoSellWhiteList()) + items.put(item, ItemType.AUTO_SELL_WHITELIST); - for (ItemStack item : filter.getAutoSellBlackList()) - items.put(item, ItemType.AUTO_SELL_BLACKLIST); + for (ItemStack item : filter.getAutoSellBlackList()) + items.put(item, ItemType.AUTO_SELL_BLACKLIST); - String createItem = "INSERT INTO " + this.getTablePrefix() + "items (hopper_id, item_type, item) VALUES (?, ?, ?)"; - try (PreparedStatement statement = connection.prepareStatement(createItem)) { - for (Map.Entry entry : items.entrySet()) { - statement.setInt(1, hopper.getId()); - statement.setString(2, entry.getValue().name()); + String createItem = "INSERT INTO " + this.getTablePrefix() + "items (hopper_id, item_type, item) VALUES (?, ?, ?)"; + try (PreparedStatement statement = connection.prepareStatement(createItem)) { + for (Map.Entry entry : items.entrySet()) { + statement.setInt(1, hopper.getId()); + statement.setString(2, entry.getValue().name()); - try (ByteArrayOutputStream stream = new ByteArrayOutputStream(); BukkitObjectOutputStream bukkitStream = new BukkitObjectOutputStream(stream)) { - bukkitStream.writeObject(entry.getKey()); - statement.setString(3, Base64.getEncoder().encodeToString(stream.toByteArray())); - } catch (IOException e) { - e.printStackTrace(); - continue; + try (ByteArrayOutputStream stream = new ByteArrayOutputStream(); BukkitObjectOutputStream bukkitStream = new BukkitObjectOutputStream(stream)) { + bukkitStream.writeObject(entry.getKey()); + statement.setString(3, Base64.getEncoder().encodeToString(stream.toByteArray())); + } catch (IOException e) { + e.printStackTrace(); + continue; + } + statement.addBatch(); } - statement.addBatch(); + statement.executeBatch(); } - statement.executeBatch(); - } - Map links = new HashMap<>(); + Map links = new HashMap<>(); - for (Location location : hopper.getLinkedBlocks()) - links.put(location, LinkType.REGULAR); + for (Location location : hopper.getLinkedBlocks()) + links.put(location, LinkType.REGULAR); - if (filter.getEndPoint() != null) - links.put(filter.getEndPoint(), LinkType.REJECT); + if (filter.getEndPoint() != null) + links.put(filter.getEndPoint(), LinkType.REJECT); - String createLink = "INSERT INTO " + this.getTablePrefix() + "links (hopper_id, link_type, world, x, y, z) VALUES (?, ?, ?, ?, ?, ?)"; - try (PreparedStatement statement = connection.prepareStatement(createLink)) { - for (Map.Entry entry : links.entrySet()) { - statement.setInt(1, hopper.getId()); + String createLink = "INSERT INTO " + this.getTablePrefix() + "links (hopper_id, link_type, world, x, y, z) VALUES (?, ?, ?, ?, ?, ?)"; + try (PreparedStatement statement = connection.prepareStatement(createLink)) { + for (Map.Entry entry : links.entrySet()) { + statement.setInt(1, hopper.getId()); - statement.setString(2, entry.getValue().name()); + statement.setString(2, entry.getValue().name()); - Location location = entry.getKey(); - statement.setString(3, location.getWorld().getName()); - statement.setInt(4, location.getBlockX()); - statement.setInt(5, location.getBlockY()); - statement.setInt(6, location.getBlockZ()); - statement.addBatch(); + Location location = entry.getKey(); + statement.setString(3, location.getWorld().getName()); + statement.setInt(4, location.getBlockX()); + statement.setInt(5, location.getBlockY()); + statement.setInt(6, location.getBlockZ()); + statement.addBatch(); + } + statement.executeBatch(); } - statement.executeBatch(); + } catch (Exception ex) { + ex.printStackTrace(); } - }), "create"); + }); } public void updateHopper(Hopper hopper) { - this.async(() -> this.databaseConnector.connect(connection -> { - String updateHopper = "UPDATE " + this.getTablePrefix() + "placed_hoppers SET level = ?, placed_by = ?, last_opened_by = ?, teleport_trigger = ? WHERE id = ?"; - try (PreparedStatement statement = connection.prepareStatement(updateHopper)) { + this.runAsync(() -> { + try (Connection connection = this.databaseConnector.getConnection()){ + String updateHopper = "UPDATE " + this.getTablePrefix() + "placed_hoppers SET level = ?, placed_by = ?, last_opened_by = ?, teleport_trigger = ? WHERE id = ?"; + PreparedStatement statement = connection.prepareStatement(updateHopper); statement.setInt(1, hopper.getLevel().getLevel()); statement.setString(2, hopper.getPlacedBy().toString()); statement.setString(3, hopper.getLastPlayerOpened().toString()); statement.setString(4, hopper.getTeleportTrigger().name()); statement.setInt(5, hopper.getId()); statement.executeUpdate(); + } catch (Exception ex) { + ex.printStackTrace(); } - })); + }); } public void deleteHopper(Hopper hopper) { - this.async(() -> this.databaseConnector.connect(connection -> { - String deleteHopper = "DELETE FROM " + this.getTablePrefix() + "placed_hoppers WHERE id = ?"; - try (PreparedStatement statement = connection.prepareStatement(deleteHopper)) { - statement.setInt(1, hopper.getId()); - statement.executeUpdate(); - } + this.runAsync(() -> { + try (Connection connection = this.databaseConnector.getConnection()){ + String deleteHopper = "DELETE FROM " + this.getTablePrefix() + "placed_hoppers WHERE id = ?"; + try (PreparedStatement statement = connection.prepareStatement(deleteHopper)) { + statement.setInt(1, hopper.getId()); + statement.executeUpdate(); + } - String deleteHopperLinks = "DELETE FROM " + this.getTablePrefix() + "links WHERE hopper_id = ?"; - try (PreparedStatement statement = connection.prepareStatement(deleteHopperLinks)) { - statement.setInt(1, hopper.getId()); - statement.executeUpdate(); - } + String deleteHopperLinks = "DELETE FROM " + this.getTablePrefix() + "links WHERE hopper_id = ?"; + try (PreparedStatement statement = connection.prepareStatement(deleteHopperLinks)) { + statement.setInt(1, hopper.getId()); + statement.executeUpdate(); + } - String deleteItems = "DELETE FROM " + this.getTablePrefix() + "items WHERE hopper_id = ?"; - try (PreparedStatement statement = connection.prepareStatement(deleteItems)) { - statement.setInt(1, hopper.getId()); - statement.executeUpdate(); + String deleteItems = "DELETE FROM " + this.getTablePrefix() + "items WHERE hopper_id = ?"; + try (PreparedStatement statement = connection.prepareStatement(deleteItems)) { + statement.setInt(1, hopper.getId()); + statement.executeUpdate(); + } + } catch (Exception ex) { + ex.printStackTrace(); } - })); + }); } public void getHoppers(Consumer> callback) { - this.async(() -> this.databaseConnector.connect(connection -> { + this.runAsync(() -> { + try (Connection connection = this.databaseConnector.getConnection()){ + Map hoppers = new HashMap<>(); - Map hoppers = new HashMap<>(); + try (Statement statement = connection.createStatement()) { + String selectHoppers = "SELECT * FROM " + this.getTablePrefix() + "placed_hoppers"; + ResultSet result = statement.executeQuery(selectHoppers); + while (result.next()) { + World world = Bukkit.getWorld(result.getString("world")); - try (Statement statement = connection.createStatement()) { - String selectHoppers = "SELECT * FROM " + this.getTablePrefix() + "placed_hoppers"; - ResultSet result = statement.executeQuery(selectHoppers); - while (result.next()) { - World world = Bukkit.getWorld(result.getString("world")); + if (world == null) + continue; - if (world == null) - continue; + int id = result.getInt("id"); + int level = result.getInt("level"); - int id = result.getInt("id"); - int level = result.getInt("level"); + String placedByStr = result.getString("placed_by"); + UUID placedBy = placedByStr == null ? null : UUID.fromString(result.getString("placed_by")); - String placedByStr = result.getString("placed_by"); - UUID placedBy = placedByStr == null ? null : UUID.fromString(result.getString("placed_by")); + String lastOpenedByStr = result.getString("last_opened_by"); + UUID lastOpenedBy = lastOpenedByStr == null ? null : UUID.fromString(result.getString("last_opened_by")); - String lastOpenedByStr = result.getString("last_opened_by"); - UUID lastOpenedBy = lastOpenedByStr == null ? null : UUID.fromString(result.getString("last_opened_by")); + TeleportTrigger teleportTrigger = TeleportTrigger.valueOf(result.getString("teleport_trigger")); - TeleportTrigger teleportTrigger = TeleportTrigger.valueOf(result.getString("teleport_trigger")); + int x = result.getInt("x"); + int y = result.getInt("y"); + int z = result.getInt("z"); + Location location = new Location(world, x, y, z); - int x = result.getInt("x"); - int y = result.getInt("y"); - int z = result.getInt("z"); - Location location = new Location(world, x, y, z); + Hopper hopper = new HopperBuilder(location) + .setId(id) + .setLevel(EpicHoppers.getInstance().getLevelManager().getLevel(level)) + .setPlacedBy(placedBy) + .setLastPlayerOpened(lastOpenedBy) + .setTeleportTrigger(teleportTrigger) + .build(); - Hopper hopper = new HopperBuilder(location) - .setId(id) - .setLevel(EpicHoppers.getInstance().getLevelManager().getLevel(level)) - .setPlacedBy(placedBy) - .setLastPlayerOpened(lastOpenedBy) - .setTeleportTrigger(teleportTrigger) - .build(); - - hoppers.put(id, hopper); - } - } - - try (Statement statement = connection.createStatement()) { - String selectLinks = "SELECT * FROM " + this.getTablePrefix() + "links"; - ResultSet result = statement.executeQuery(selectLinks); - while (result.next()) { - World world = Bukkit.getWorld(result.getString("world")); - - if (world == null) - continue; - - int id = result.getInt("hopper_id"); - LinkType type = LinkType.valueOf(result.getString("link_type")); - - int x = result.getInt("x"); - int y = result.getInt("y"); - int z = result.getInt("z"); - Location location = new Location(world, x, y, z); - - Hopper hopper = hoppers.get(id); - if (hopper == null) break; - - hopper.addLinkedBlock(location, type); - } - } - - try (Statement statement = connection.createStatement()) { - String selectItems = "SELECT * FROM " + this.getTablePrefix() + "items"; - ResultSet result = statement.executeQuery(selectItems); - while (result.next()) { - int id = result.getInt("hopper_id"); - ItemType type = ItemType.valueOf(result.getString("item_type")); - - ItemStack item = null; - try (BukkitObjectInputStream stream = new BukkitObjectInputStream( - new ByteArrayInputStream(Base64.getDecoder().decode(result.getString("item"))))) { - item = (ItemStack) stream.readObject(); - } catch (IOException | ClassNotFoundException e) { - e.printStackTrace(); + hoppers.put(id, hopper); } - - Hopper hopper = hoppers.get(id); - if (hopper == null) break; - - if (item != null) - hopper.getFilter().addItem(item, type); } + + try (Statement statement = connection.createStatement()) { + String selectLinks = "SELECT * FROM " + this.getTablePrefix() + "links"; + ResultSet result = statement.executeQuery(selectLinks); + while (result.next()) { + World world = Bukkit.getWorld(result.getString("world")); + + if (world == null) + continue; + + int id = result.getInt("hopper_id"); + LinkType type = LinkType.valueOf(result.getString("link_type")); + + int x = result.getInt("x"); + int y = result.getInt("y"); + int z = result.getInt("z"); + Location location = new Location(world, x, y, z); + + Hopper hopper = hoppers.get(id); + if (hopper == null) break; + + hopper.addLinkedBlock(location, type); + } + } + + try (Statement statement = connection.createStatement()) { + String selectItems = "SELECT * FROM " + this.getTablePrefix() + "items"; + ResultSet result = statement.executeQuery(selectItems); + while (result.next()) { + int id = result.getInt("hopper_id"); + ItemType type = ItemType.valueOf(result.getString("item_type")); + + ItemStack item = null; + try (BukkitObjectInputStream stream = new BukkitObjectInputStream( + new ByteArrayInputStream(Base64.getDecoder().decode(result.getString("item"))))) { + item = (ItemStack) stream.readObject(); + } catch (IOException | ClassNotFoundException e) { + e.printStackTrace(); + } + + Hopper hopper = hoppers.get(id); + if (hopper == null) break; + + if (item != null) + hopper.getFilter().addItem(item, type); + } + } + this.sync(() -> callback.accept(hoppers)); + } catch (Exception ex) { + ex.printStackTrace(); } - this.sync(() -> callback.accept(hoppers)); - })); + }); } } diff --git a/src/main/java/com/songoda/epichoppers/settings/Settings.java b/src/main/java/com/songoda/epichoppers/settings/Settings.java index d301d19..007b058 100644 --- a/src/main/java/com/songoda/epichoppers/settings/Settings.java +++ b/src/main/java/com/songoda/epichoppers/settings/Settings.java @@ -109,6 +109,16 @@ public class Settings { "The enabled language file.", "More language files (if available) can be found in the plugins data folder."); + public static final ConfigSetting MYSQL_ENABLED = new ConfigSetting(config, "MySQL.Enabled", false, "Set to 'true' to use MySQL instead of SQLite for data storage."); + public static final ConfigSetting MYSQL_HOSTNAME = new ConfigSetting(config, "MySQL.Hostname", "localhost"); + public static final ConfigSetting MYSQL_PORT = new ConfigSetting(config, "MySQL.Port", 3306); + public static final ConfigSetting MYSQL_DATABASE = new ConfigSetting(config, "MySQL.Database", "your-database"); + public static final ConfigSetting MYSQL_USERNAME = new ConfigSetting(config, "MySQL.Username", "user"); + public static final ConfigSetting MYSQL_PASSWORD = new ConfigSetting(config, "MySQL.Password", "pass"); + public static final ConfigSetting MYSQL_USE_SSL = new ConfigSetting(config, "MySQL.Use SSL", false); + public static final ConfigSetting MYSQL_POOL_SIZE = new ConfigSetting(config, "MySQL.Pool Size", 3, "Determines the number of connections the pool is using. Increase this value if you are getting timeout errors when more players online."); + + /** * In order to set dynamic economy comment correctly, this needs to be * called after EconomyManager load From 6af6cbf1c34e017f7ba6edbba08f8e44ec39bf5b Mon Sep 17 00:00:00 2001 From: "songoda-projects-overview[bot]" <111250264+songoda-projects-overview[bot]@users.noreply.github.com> Date: Mon, 15 Aug 2022 00:47:43 +0200 Subject: [PATCH 2/4] Bump SongodaCore version to `2.6.15-DEV` --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 8f92b2e..7063a82 100644 --- a/pom.xml +++ b/pom.xml @@ -133,7 +133,7 @@ com.songoda SongodaCore - 2.6.14-DEV + 2.6.15-DEV compile From ef8359e238a1f1baede9aa7ed37be151a0a89736 Mon Sep 17 00:00:00 2001 From: "songoda-projects-overview[bot]" <111250264+songoda-projects-overview[bot]@users.noreply.github.com> Date: Mon, 5 Sep 2022 22:21:21 +0200 Subject: [PATCH 3/4] Bump SongodaCore version to `2.6.16` --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 7063a82..b3ebe9a 100644 --- a/pom.xml +++ b/pom.xml @@ -133,7 +133,7 @@ com.songoda SongodaCore - 2.6.15-DEV + 2.6.16 compile From 38698eec1a859a53bd8acfe303cad4be3d07ec05 Mon Sep 17 00:00:00 2001 From: Christian Koop Date: Mon, 5 Sep 2022 22:48:22 +0200 Subject: [PATCH 4/4] Release v4.7.6 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index b3ebe9a..ea6d4ef 100644 --- a/pom.xml +++ b/pom.xml @@ -2,7 +2,7 @@ com.songoda EpicHoppers 4.0.0 - 4.7.5 + 4.7.6 clean install EpicHoppers-${project.version}