diff --git a/pom.xml b/pom.xml
index 2170651..5341d67 100644
--- a/pom.xml
+++ b/pom.xml
@@ -2,7 +2,7 @@
com.songoda
UltimateModeration
4.0.0
- 2.0.11
+ 2.0.12
clean install
@@ -48,7 +48,7 @@
org.apache.maven.plugins
maven-shade-plugin
- 3.3.0-SNAPSHOT
+ 3.3.0
shaded
@@ -91,13 +91,6 @@
-
-
- apache.snapshots
- https://repository.apache.org/snapshots/
-
-
-
songoda-public
@@ -119,7 +112,7 @@
com.songoda
SongodaCore
- 2.6.13
+ 2.6.16
compile
diff --git a/src/main/java/com/songoda/ultimatemoderation/UltimateModeration.java b/src/main/java/com/songoda/ultimatemoderation/UltimateModeration.java
index cbefe40..8066683 100644
--- a/src/main/java/com/songoda/ultimatemoderation/UltimateModeration.java
+++ b/src/main/java/com/songoda/ultimatemoderation/UltimateModeration.java
@@ -106,8 +106,9 @@ public class UltimateModeration 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);
@@ -150,7 +151,7 @@ public class UltimateModeration extends SongodaPlugin {
@Override
public void onDataLoad() {
- getDataManager().queueAsync(() -> {
+ getDataManager().runAsync(() -> {
// Load data from DB
this.dataManager.getTemplates((templates) -> {
for (Template template : templates) {
@@ -169,7 +170,7 @@ public class UltimateModeration extends SongodaPlugin {
for (Ticket ticket : tickets.values())
this.ticketManager.addTicket(ticket);
});
- }, "create");
+ });
}
@Override
diff --git a/src/main/java/com/songoda/ultimatemoderation/database/DataManager.java b/src/main/java/com/songoda/ultimatemoderation/database/DataManager.java
index 7985009..709a646 100644
--- a/src/main/java/com/songoda/ultimatemoderation/database/DataManager.java
+++ b/src/main/java/com/songoda/ultimatemoderation/database/DataManager.java
@@ -13,6 +13,7 @@ import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.plugin.Plugin;
+import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
@@ -30,36 +31,43 @@ public class DataManager extends DataManagerAbstract {
}
public void createTemplate(Template template) {
- this.queueAsync(() -> this.databaseConnector.connect(connection -> {
- String createTemplate = "INSERT INTO " + this.getTablePrefix() + "templates (punishment_type, duration, reason, name, creator) VALUES (?, ?, ?, ?, ?)";
- try (PreparedStatement statement = connection.prepareStatement(createTemplate)) {
+ this.runAsync(() -> {
+ try (Connection connection = this.databaseConnector.getConnection()) {
+ String createTemplate = "INSERT INTO " + this.getTablePrefix() + "templates (punishment_type, duration, reason, name, creator) VALUES (?, ?, ?, ?, ?)";
+ PreparedStatement statement = connection.prepareStatement(createTemplate);
statement.setString(1, template.getPunishmentType().name());
statement.setLong(2, template.getDuration());
statement.setString(3, template.getReason());
statement.setString(4, template.getName());
statement.setString(5, template.getCreator().toString());
statement.executeUpdate();
- }
- int templateId = this.lastInsertedId(connection, "templates");
- template.setId(templateId);
- }), "create");
+ int templateId = this.lastInsertedId(connection, "templates");
+ template.setId(templateId);
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ });
}
public void deleteTemplate(Template template) {
- this.async(() -> this.databaseConnector.connect(connection -> {
- String deleteTemplate = "DELETE FROM " + this.getTablePrefix() + "templates WHERE id = ?";
- try (PreparedStatement statement = connection.prepareStatement(deleteTemplate)) {
+ this.runAsync(() -> {
+ try (Connection connection = this.databaseConnector.getConnection()) {
+ String deleteTemplate = "DELETE FROM " + this.getTablePrefix() + "templates WHERE id = ?";
+ PreparedStatement statement = connection.prepareStatement(deleteTemplate);
statement.setLong(1, template.getId());
statement.executeUpdate();
+ } catch (Exception ex) {
+ ex.printStackTrace();
}
- }));
+ });
}
public void getTemplates(Consumer> callback) {
List templates = 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 selectTemplates = "SELECT * FROM " + this.getTablePrefix() + "templates";
ResultSet result = statement.executeQuery(selectTemplates);
while (result.next()) {
@@ -73,16 +81,19 @@ public class DataManager extends DataManagerAbstract {
template.setId(id);
templates.add(template);
}
- }
- this.sync(() -> callback.accept(templates));
- }));
+ this.sync(() -> callback.accept(templates));
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ });
}
public void createAppliedPunishment(AppliedPunishment punishment) {
- this.queueAsync(() -> this.databaseConnector.connect(connection -> {
- String createPunishment = "INSERT INTO " + this.getTablePrefix() + "punishments (type, duration, reason, victim, punisher, expiration) VALUES (?, ?, ?, ?, ?, ?)";
- try (PreparedStatement statement = connection.prepareStatement(createPunishment)) {
+ this.runAsync(() -> {
+ try (Connection connection = this.databaseConnector.getConnection()) {
+ String createPunishment = "INSERT INTO " + this.getTablePrefix() + "punishments (type, duration, reason, victim, punisher, expiration) VALUES (?, ?, ?, ?, ?, ?)";
+ PreparedStatement statement = connection.prepareStatement(createPunishment);
statement.setString(1, punishment.getPunishmentType().name());
statement.setLong(2, punishment.getDuration());
statement.setString(3, punishment.getReason());
@@ -90,27 +101,33 @@ public class DataManager extends DataManagerAbstract {
statement.setString(5, punishment.getPunisher().toString());
statement.setLong(6, punishment.getExpiration());
statement.executeUpdate();
- }
- int punishmentId = this.lastInsertedId(connection, "punishments");
- punishment.setId(punishmentId);
- }), "create");
+ int punishmentId = this.lastInsertedId(connection, "punishments");
+ punishment.setId(punishmentId);
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ });
}
public void deleteAppliedPunishment(AppliedPunishment punishment) {
- this.async(() -> this.databaseConnector.connect(connection -> {
- String deletePunishment = "DELETE FROM " + this.getTablePrefix() + "punishments WHERE id = ?";
- try (PreparedStatement statement = connection.prepareStatement(deletePunishment)) {
+ this.runAsync(() -> {
+ try (Connection connection = this.databaseConnector.getConnection()) {
+ String deletePunishment = "DELETE FROM " + this.getTablePrefix() + "punishments WHERE id = ?";
+ PreparedStatement statement = connection.prepareStatement(deletePunishment);
statement.setLong(1, punishment.getId());
statement.executeUpdate();
+ } catch (Exception ex) {
+ ex.printStackTrace();
}
- }));
+ });
}
public void updateAppliedPunishment(AppliedPunishment punishment) {
- this.async(() -> this.databaseConnector.connect(connection -> {
- String updatePunishment = "UPDATE " + this.getTablePrefix() + "punishments set type = ?, duration = ?, reason = ?, victim = ?, punisher = ?, expiration = ? WHERE id = ?";
- try (PreparedStatement statement = connection.prepareStatement(updatePunishment)) {
+ this.runAsync(() -> {
+ try (Connection connection = this.databaseConnector.getConnection()) {
+ String updatePunishment = "UPDATE " + this.getTablePrefix() + "punishments set type = ?, duration = ?, reason = ?, victim = ?, punisher = ?, expiration = ? WHERE id = ?";
+ PreparedStatement statement = connection.prepareStatement(updatePunishment);
statement.setString(1, punishment.getPunishmentType().name());
statement.setLong(2, punishment.getDuration());
statement.setString(3, punishment.getReason());
@@ -119,14 +136,17 @@ public class DataManager extends DataManagerAbstract {
statement.setLong(6, punishment.getExpiration());
statement.setLong(7, punishment.getId());
statement.executeUpdate();
+ } catch (Exception ex) {
+ ex.printStackTrace();
}
- }));
+ });
}
public void getAppliedPunishments(Consumer> callback) {
List appliedPunishments = 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 selectPunishments = "SELECT * FROM " + this.getTablePrefix() + "punishments";
ResultSet result = statement.executeQuery(selectPunishments);
while (result.next()) {
@@ -139,42 +159,51 @@ public class DataManager extends DataManagerAbstract {
long expiration = result.getLong("expiration");
appliedPunishments.add(new AppliedPunishment(punishmentType, duration, reason, victim, punisher, expiration, id));
}
- }
- this.sync(() -> callback.accept(appliedPunishments));
- }));
+ this.sync(() -> callback.accept(appliedPunishments));
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ });
}
public void createNote(PunishmentNote note) {
- this.queueAsync(() -> this.databaseConnector.connect(connection -> {
- String createNote = "INSERT INTO " + this.getTablePrefix() + "notes (note, author, subject, creation) VALUES (?, ?, ?, ?)";
- try (PreparedStatement statement = connection.prepareStatement(createNote)) {
+ this.runAsync(() -> {
+ try (Connection connection = this.databaseConnector.getConnection()) {
+ String createNote = "INSERT INTO " + this.getTablePrefix() + "notes (note, author, subject, creation) VALUES (?, ?, ?, ?)";
+ PreparedStatement statement = connection.prepareStatement(createNote);
statement.setString(1, note.getNote());
statement.setString(2, note.getAuthor().toString());
statement.setString(3, note.getSubject().toString());
statement.setLong(4, note.getCreationDate());
statement.executeUpdate();
- }
- int noteId = this.lastInsertedId(connection, "notes");
- note.setId(noteId);
- }), "create");
+ int noteId = this.lastInsertedId(connection, "notes");
+ note.setId(noteId);
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ });
}
public void deleteNote(PunishmentNote note) {
- this.async(() -> this.databaseConnector.connect(connection -> {
- String deleteNote = "DELETE FROM " + this.getTablePrefix() + "notes WHERE id = ?";
- try (PreparedStatement statement = connection.prepareStatement(deleteNote)) {
+ this.runAsync(() -> {
+ try (Connection connection = this.databaseConnector.getConnection()) {
+ String deleteNote = "DELETE FROM " + this.getTablePrefix() + "notes WHERE id = ?";
+ PreparedStatement statement = connection.prepareStatement(deleteNote);
statement.setLong(1, note.getId());
statement.executeUpdate();
+ } catch (Exception ex) {
+ ex.printStackTrace();
}
- }));
+ });
}
public void getNotes(Consumer> callback) {
List notes = 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 getNotes = "SELECT * FROM " + this.getTablePrefix() + "notes";
ResultSet result = statement.executeQuery(getNotes);
while (result.next()) {
@@ -185,16 +214,19 @@ public class DataManager extends DataManagerAbstract {
long creation = result.getLong("creation");
notes.add(new PunishmentNote(id, note, author, subject, creation));
}
- }
- this.sync(() -> callback.accept(notes));
- }));
+ this.sync(() -> callback.accept(notes));
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ });
}
public void createTicket(Ticket ticket) {
- this.queueAsync(() -> this.databaseConnector.connect(connection -> {
- String createTicket = "INSERT INTO " + this.getTablePrefix() + "tickets (victim, subject, type, status, world, x, y, z, pitch, yaw) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
- try (PreparedStatement statement = connection.prepareStatement(createTicket)) {
+ this.runAsync(() -> {
+ try (Connection connection = this.databaseConnector.getConnection()) {
+ String createTicket = "INSERT INTO " + this.getTablePrefix() + "tickets (victim, subject, type, status, world, x, y, z, pitch, yaw) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
+ PreparedStatement statement = connection.prepareStatement(createTicket);
statement.setString(1, ticket.getVictim().toString());
statement.setString(2, ticket.getSubject());
statement.setString(3, ticket.getType());
@@ -209,36 +241,44 @@ public class DataManager extends DataManagerAbstract {
statement.setFloat(9, location.getPitch());
statement.setFloat(10, location.getYaw());
statement.executeUpdate();
+
+ for (TicketResponse response : ticket.getResponses()) {
+ createTicketResponse(response);
+ }
+
+ int ticketId = this.lastInsertedId(connection, "tickets");
+ ticket.setId(ticketId);
+ } catch (Exception ex) {
+ ex.printStackTrace();
}
-
- for (TicketResponse response : ticket.getResponses())
- createTicketResponse(response);
-
- int ticketId = this.lastInsertedId(connection, "tickets");
- ticket.setId(ticketId);
- }), "create");
+ });
}
public void deleteTicket(Ticket ticket) {
- this.async(() -> this.databaseConnector.connect(connection -> {
- String deleteTicket = "DELETE FROM " + this.getTablePrefix() + "tickets WHERE id = ?";
- try (PreparedStatement statement = connection.prepareStatement(deleteTicket)) {
- statement.setLong(1, ticket.getId());
- statement.executeUpdate();
- }
+ this.runAsync(() -> {
+ try (Connection connection = this.databaseConnector.getConnection()) {
+ String deleteTicket = "DELETE FROM " + this.getTablePrefix() + "tickets WHERE id = ?";
+ try (PreparedStatement statement = connection.prepareStatement(deleteTicket)) {
+ statement.setLong(1, ticket.getId());
+ statement.executeUpdate();
+ }
- String deleteTicketResponses = "DELETE FROM " + this.getTablePrefix() + "ticket_responses WHERE ticket_id = ?";
- try (PreparedStatement statement = connection.prepareStatement(deleteTicketResponses)) {
- statement.setLong(1, ticket.getId());
- statement.executeUpdate();
+ String deleteTicketResponses = "DELETE FROM " + this.getTablePrefix() + "ticket_responses WHERE ticket_id = ?";
+ try (PreparedStatement statement = connection.prepareStatement(deleteTicketResponses)) {
+ statement.setLong(1, ticket.getId());
+ statement.executeUpdate();
+ }
+ } catch (Exception ex) {
+ ex.printStackTrace();
}
- }));
+ });
}
public void updateTicket(Ticket ticket) {
- this.async(() -> this.databaseConnector.connect(connection -> {
- String updateTicket = "UPDATE " + this.getTablePrefix() + "tickets SET victim = ?, subject = ?, type = ?, status = ?, world = ?, x = ?, y = ?, z = ?, pitch = ?, yaw = ? WHERE id = ?";
- try (PreparedStatement statement = connection.prepareStatement(updateTicket)) {
+ this.runAsync(() -> {
+ try (Connection connection = this.databaseConnector.getConnection()) {
+ String updateTicket = "UPDATE " + this.getTablePrefix() + "tickets SET victim = ?, subject = ?, type = ?, status = ?, world = ?, x = ?, y = ?, z = ?, pitch = ?, yaw = ? WHERE id = ?";
+ PreparedStatement statement = connection.prepareStatement(updateTicket);
statement.setString(1, ticket.getVictim().toString());
statement.setString(2, ticket.getSubject());
statement.setString(3, ticket.getType());
@@ -254,73 +294,82 @@ public class DataManager extends DataManagerAbstract {
statement.setFloat(10, location.getYaw());
statement.setInt(11, ticket.getId());
statement.executeUpdate();
+ } catch (Exception ex) {
+ ex.printStackTrace();
}
- }));
+ });
}
public void getTickets(Consumer