mirror of
https://github.com/songoda/UltimateKits.git
synced 2024-11-08 11:41:28 +01:00
Remove deprecated methods, fix MySQL
This commit is contained in:
parent
02625326d8
commit
2af5251a85
@ -166,8 +166,9 @@ public class UltimateKits extends SongodaPlugin {
|
||||
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);
|
||||
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);
|
||||
|
@ -11,6 +11,7 @@ import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.Statement;
|
||||
@ -25,38 +26,40 @@ public class DataManager extends DataManagerAbstract {
|
||||
}
|
||||
|
||||
public void bulkUpdateBlockData(Map<Location, KitBlockData> blockData) {
|
||||
this.databaseConnector.connect(connection -> {
|
||||
try (Connection connection = this.databaseConnector.getConnection()) {
|
||||
String updateData = "UPDATE " + this.getTablePrefix() + "blockdata SET type = ?, kit = ?, holograms = ?, " +
|
||||
"displayItems = ?, particles = ?, itemOverride = ? " +
|
||||
"WHERE world = ? AND x = ? AND y = ? AND z = ?";
|
||||
try (PreparedStatement statement = connection.prepareStatement(updateData)) {
|
||||
for (KitBlockData data : blockData.values()) {
|
||||
if (data == null || data.getWorld() == null) continue;
|
||||
statement.setString(1, data.getType().toString());
|
||||
statement.setString(2, data.getKit().getKey());
|
||||
statement.setBoolean(3, data.showHologram());
|
||||
statement.setBoolean(4, data.isDisplayingItems());
|
||||
statement.setBoolean(5, data.hasParticles());
|
||||
statement.setBoolean(6, data.isItemOverride());
|
||||
statement.setString(7, data.getWorld().getName());
|
||||
statement.setInt(8, data.getX());
|
||||
statement.setInt(9, data.getY());
|
||||
statement.setInt(10, data.getZ());
|
||||
statement.addBatch();
|
||||
}
|
||||
|
||||
statement.executeBatch();
|
||||
PreparedStatement statement = connection.prepareStatement(updateData);
|
||||
for (KitBlockData data : blockData.values()) {
|
||||
if (data == null || data.getWorld() == null) continue;
|
||||
statement.setString(1, data.getType().toString());
|
||||
statement.setString(2, data.getKit().getKey());
|
||||
statement.setBoolean(3, data.showHologram());
|
||||
statement.setBoolean(4, data.isDisplayingItems());
|
||||
statement.setBoolean(5, data.hasParticles());
|
||||
statement.setBoolean(6, data.isItemOverride());
|
||||
statement.setString(7, data.getWorld().getName());
|
||||
statement.setInt(8, data.getX());
|
||||
statement.setInt(9, data.getY());
|
||||
statement.setInt(10, data.getZ());
|
||||
statement.addBatch();
|
||||
}
|
||||
});
|
||||
|
||||
statement.executeBatch();
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void updateBlockData(KitBlockData blockData) {
|
||||
if (blockData.getWorld() == null) return;
|
||||
this.async(() -> this.databaseConnector.connect(connection -> {
|
||||
String updateData = "UPDATE " + this.getTablePrefix() + "blockdata SET type = ?, kit = ?, holograms = ?, " +
|
||||
"displayItems = ?, particles = ?, itemOverride = ? " +
|
||||
"WHERE world = ? AND x = ? AND y = ? AND z = ?";
|
||||
try (PreparedStatement statement = connection.prepareStatement(updateData)) {
|
||||
this.runAsync(() -> {
|
||||
try (Connection connection = this.databaseConnector.getConnection()) {
|
||||
String updateData = "UPDATE " + this.getTablePrefix() + "blockdata SET type = ?, kit = ?, holograms = ?, " +
|
||||
"displayItems = ?, particles = ?, itemOverride = ? " +
|
||||
"WHERE world = ? AND x = ? AND y = ? AND z = ?";
|
||||
PreparedStatement statement = connection.prepareStatement(updateData);
|
||||
statement.setString(1, blockData.getType().toString());
|
||||
statement.setString(2, blockData.getKit().getKey());
|
||||
statement.setBoolean(3, blockData.showHologram());
|
||||
@ -68,17 +71,20 @@ public class DataManager extends DataManagerAbstract {
|
||||
statement.setInt(9, blockData.getY());
|
||||
statement.setInt(10, blockData.getZ());
|
||||
statement.executeUpdate();
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
public void createBlockData(KitBlockData blockData) {
|
||||
if (blockData.getWorld() == null) return;
|
||||
this.async(() -> this.databaseConnector.connect(connection -> {
|
||||
String createData = "INSERT INTO " + this.getTablePrefix() + "blockdata (" +
|
||||
"type, kit, holograms, displayItems, particles, itemOverride, world, x, y, z)" +
|
||||
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
|
||||
try (PreparedStatement statement = connection.prepareStatement(createData)) {
|
||||
this.runAsync(() -> {
|
||||
try (Connection connection = this.databaseConnector.getConnection()) {
|
||||
String createData = "INSERT INTO " + this.getTablePrefix() + "blockdata (" +
|
||||
"type, kit, holograms, displayItems, particles, itemOverride, world, x, y, z)" +
|
||||
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
|
||||
PreparedStatement statement = connection.prepareStatement(createData);
|
||||
statement.setString(1, blockData.getType().toString());
|
||||
statement.setString(2, blockData.getKit().getKey());
|
||||
statement.setBoolean(3, blockData.showHologram());
|
||||
@ -90,29 +96,35 @@ public class DataManager extends DataManagerAbstract {
|
||||
statement.setInt(9, blockData.getY());
|
||||
statement.setInt(10, blockData.getZ());
|
||||
statement.executeUpdate();
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
public void deleteBlockData(KitBlockData blockData) {
|
||||
this.async(() -> this.databaseConnector.connect(connection -> {
|
||||
String deleteData = "DELETE FROM " + this.getTablePrefix() + "blockdata WHERE world = ? " +
|
||||
"AND x = ? AND y = ? AND z = ?";
|
||||
try (PreparedStatement statement = connection.prepareStatement(deleteData)) {
|
||||
this.runAsync(() -> {
|
||||
try (Connection connection = this.databaseConnector.getConnection()) {
|
||||
String deleteData = "DELETE FROM " + this.getTablePrefix() + "blockdata WHERE world = ? " +
|
||||
"AND x = ? AND y = ? AND z = ?";
|
||||
PreparedStatement statement = connection.prepareStatement(deleteData);
|
||||
statement.setString(1, blockData.getWorld().getName());
|
||||
statement.setInt(2, blockData.getX());
|
||||
statement.setInt(3, blockData.getY());
|
||||
statement.setInt(4, blockData.getZ());
|
||||
statement.executeUpdate();
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
public void getBlockData(Consumer<Map<Location, KitBlockData>> callback) {
|
||||
this.async(() -> this.databaseConnector.connect(connection -> {
|
||||
String selectData = "SELECT * FROM " + this.getTablePrefix() + "blockdata";
|
||||
Map<Location, KitBlockData> blockData = new HashMap<>();
|
||||
try (Statement statement = connection.createStatement()) {
|
||||
this.runAsync(() -> {
|
||||
try (Connection connection = this.databaseConnector.getConnection()) {
|
||||
String selectData = "SELECT * FROM " + this.getTablePrefix() + "blockdata";
|
||||
Map<Location, KitBlockData> blockData = new HashMap<>();
|
||||
Statement statement = connection.createStatement();
|
||||
ResultSet result = statement.executeQuery(selectData);
|
||||
while (result.next()) {
|
||||
|
||||
@ -134,10 +146,11 @@ public class DataManager extends DataManagerAbstract {
|
||||
|
||||
blockData.put(location, new KitBlockData(kit, location, type, holograms, particles, displayItems, itemOverride));
|
||||
}
|
||||
result.close();
|
||||
}
|
||||
|
||||
this.sync(() -> callback.accept(blockData));
|
||||
}));
|
||||
this.sync(() -> callback.accept(blockData));
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -51,6 +51,7 @@ public class Settings {
|
||||
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.");
|
||||
|
||||
public static final ConfigSetting PARTICLE_AMOUNT = new ConfigSetting(config, "data.particlesettings.amount", 25);
|
||||
public static final ConfigSetting PARTICLE_TYPE = new ConfigSetting(config, "data.particlesettings.type", "SPELL_WITCH");
|
||||
|
Loading…
Reference in New Issue
Block a user