mirror of
https://github.com/songoda/EpicHoppers.git
synced 2024-11-22 18:25:59 +01:00
Merge branch 'development'
This commit is contained in:
commit
86c4e03586
4
pom.xml
4
pom.xml
@ -2,7 +2,7 @@
|
||||
<groupId>com.songoda</groupId>
|
||||
<artifactId>EpicHoppers</artifactId>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<version>4.7.5</version>
|
||||
<version>4.7.6</version>
|
||||
<build>
|
||||
<defaultGoal>clean install</defaultGoal>
|
||||
<finalName>EpicHoppers-${project.version}</finalName>
|
||||
@ -133,7 +133,7 @@
|
||||
<dependency>
|
||||
<groupId>com.songoda</groupId>
|
||||
<artifactId>SongodaCore</artifactId>
|
||||
<version>2.6.13</version>
|
||||
<version>2.6.16</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
|
@ -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,
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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<List<BoostData>> callback) {
|
||||
List<BoostData> 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<ItemStack> 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<Hopper> 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<ItemStack, ItemType> items = new HashMap<>();
|
||||
Filter filter = hopper.getFilter();
|
||||
Map<ItemStack, ItemType> 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<ItemStack, ItemType> 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<ItemStack, ItemType> 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<Location, LinkType> links = new HashMap<>();
|
||||
Map<Location, LinkType> 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<Location, LinkType> 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<Location, LinkType> 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<Map<Integer, Hopper>> callback) {
|
||||
this.async(() -> this.databaseConnector.connect(connection -> {
|
||||
this.runAsync(() -> {
|
||||
try (Connection connection = this.databaseConnector.getConnection()){
|
||||
Map<Integer, Hopper> hoppers = new HashMap<>();
|
||||
|
||||
Map<Integer, Hopper> 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));
|
||||
}));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user