Fix potential concurrentmodificationexception, fix foreign key constraint being linked before the table exists

This commit is contained in:
Esophose 2018-11-01 20:25:48 -06:00
parent 323a316668
commit b302f36998
2 changed files with 5 additions and 3 deletions

View file

@ -209,9 +209,9 @@ public class PlayerParticles extends JavaPlugin {
// Try to create the tables just in case they don't exist // Try to create the tables just in case they don't exist
try (Statement createStatement = connection.createStatement()) { try (Statement createStatement = connection.createStatement()) {
createStatement.addBatch("CREATE TABLE IF NOT EXISTS pp_particle (uuid VARCHAR(36), group_uuid VARCHAR(36), id SMALLINT, effect VARCHAR(100), style VARCHAR(100), item_material VARCHAR(100), block_material VARCHAR(100), note SMALLINT, r SMALLINT, g SMALLINT, b SMALLINT, PRIMARY KEY(uuid))");
createStatement.addBatch("CREATE TABLE IF NOT EXISTS pp_group (uuid VARCHAR(36), owner_uuid VARCHAR(36), name VARCHAR(100), PRIMARY KEY(uuid))"); createStatement.addBatch("CREATE TABLE IF NOT EXISTS pp_group (uuid VARCHAR(36), owner_uuid VARCHAR(36), name VARCHAR(100), PRIMARY KEY(uuid))");
createStatement.addBatch("CREATE TABLE IF NOT EXISTS pp_fixed (owner_uuid VARCHAR(36), id SMALLINT, particle_uuid VARCHAR(36), world VARCHAR(100), xPos DOUBLE, yPos DOUBLE, zPos DOUBLE, PRIMARY KEY(owner_uuid, id), FOREIGN KEY(particle_uuid) REFERENCES pp_particle(uuid))"); createStatement.addBatch("CREATE TABLE IF NOT EXISTS pp_fixed (owner_uuid VARCHAR(36), id SMALLINT, particle_uuid VARCHAR(36), world VARCHAR(100), xPos DOUBLE, yPos DOUBLE, zPos DOUBLE, PRIMARY KEY(owner_uuid, id), FOREIGN KEY(particle_uuid) REFERENCES pp_particle(uuid))");
createStatement.addBatch("CREATE TABLE IF NOT EXISTS pp_particle (uuid VARCHAR(36), group_uuid VARCHAR(36), id SMALLINT, effect VARCHAR(100), style VARCHAR(100), item_material VARCHAR(100), block_material VARCHAR(100), note SMALLINT, r SMALLINT, g SMALLINT, b SMALLINT, PRIMARY KEY(uuid))");
int[] results = createStatement.executeBatch(); int[] results = createStatement.executeBatch();
if (results[0] + results[1] + results[2] > 0) { if (results[0] + results[1] + results[2] > 0) {
getLogger().warning("Updated " + (useMySql ? "MySQL" : "SQLite") + " database schema."); getLogger().warning("Updated " + (useMySql ? "MySQL" : "SQLite") + " database schema.");
@ -238,7 +238,7 @@ public class PlayerParticles extends JavaPlugin {
new BukkitRunnable() { new BukkitRunnable() {
public void run() { public void run() {
long ticks = PSetting.TICKS_PER_PARTICLE.getLong(); long ticks = PSetting.TICKS_PER_PARTICLE.getLong();
particleTask = new ParticleManager().runTaskTimer(playerParticles, 0, ticks); particleTask = new ParticleManager().runTaskTimer(playerParticles, 5, ticks);
} }
}.runTaskLater(playerParticles, 1); }.runTaskLater(playerParticles, 1);
} }

View file

@ -173,7 +173,9 @@ public class DataManager {
ResultSet result = statement.executeQuery(); ResultSet result = statement.executeQuery();
while (result.next()) { while (result.next()) {
UUID playerUUID = UUID.fromString(result.getString("owner_uuid")); UUID playerUUID = UUID.fromString(result.getString("owner_uuid"));
getPPlayer(playerUUID, (pplayer) -> { }); sync(() -> {
getPPlayer(playerUUID, (pplayer) -> { });
});
} }
} }
}); });