diff --git a/Plan/bukkit/src/main/java/com/djrapitops/plan/system/listeners/bukkit/CommandListener.java b/Plan/bukkit/src/main/java/com/djrapitops/plan/system/listeners/bukkit/CommandListener.java index 020568544..a8342dc1a 100644 --- a/Plan/bukkit/src/main/java/com/djrapitops/plan/system/listeners/bukkit/CommandListener.java +++ b/Plan/bukkit/src/main/java/com/djrapitops/plan/system/listeners/bukkit/CommandListener.java @@ -17,8 +17,9 @@ package com.djrapitops.plan.system.listeners.bukkit; import com.djrapitops.plan.Plan; -import com.djrapitops.plan.system.processing.Processing; -import com.djrapitops.plan.system.processing.processors.Processors; +import com.djrapitops.plan.db.access.transactions.events.CommandStoreTransaction; +import com.djrapitops.plan.system.database.DBSystem; +import com.djrapitops.plan.system.info.server.ServerInfo; import com.djrapitops.plan.system.settings.Permissions; import com.djrapitops.plan.system.settings.config.PlanConfig; import com.djrapitops.plan.system.settings.paths.DataGatheringSettings; @@ -41,22 +42,22 @@ public class CommandListener implements Listener { private final Plan plugin; private final PlanConfig config; - private final Processors processors; - private final Processing processing; + private final ServerInfo serverInfo; + private final DBSystem dbSystem; private final ErrorHandler errorHandler; @Inject public CommandListener( Plan plugin, PlanConfig config, - Processors processors, - Processing processing, + ServerInfo serverInfo, + DBSystem dbSystem, ErrorHandler errorHandler ) { this.plugin = plugin; this.config = config; - this.processors = processors; - this.processing = processing; + this.serverInfo = serverInfo; + this.dbSystem = dbSystem; this.errorHandler = errorHandler; } @@ -90,7 +91,7 @@ public class CommandListener implements Listener { commandName = command.getName(); } } - processing.submit(processors.commandProcessor(commandName)); + dbSystem.getDatabase().executeTransaction(new CommandStoreTransaction(serverInfo.getServerUUID(), commandName)); } private Command getBukkitCommand(String commandName) { diff --git a/Plan/common/src/main/java/com/djrapitops/plan/db/SQLDB.java b/Plan/common/src/main/java/com/djrapitops/plan/db/SQLDB.java index 29972ac23..0942ac65a 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/db/SQLDB.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/db/SQLDB.java @@ -76,7 +76,6 @@ public abstract class SQLDB extends AbstractDatabase { private final NicknamesTable nicknamesTable; private final SessionsTable sessionsTable; private final GeoInfoTable geoInfoTable; - private final CommandUseTable commandUseTable; private final TPSTable tpsTable; private final SecurityTable securityTable; private final WorldTable worldTable; @@ -114,7 +113,6 @@ public abstract class SQLDB extends AbstractDatabase { serverTable = new ServerTable(this); securityTable = new SecurityTable(this); - commandUseTable = new CommandUseTable(this); tpsTable = new TPSTable(this); usersTable = new UsersTable(this); @@ -377,11 +375,6 @@ public abstract class SQLDB extends AbstractDatabase { return nicknamesTable; } - @Deprecated - public CommandUseTable getCommandUseTable() { - return commandUseTable; - } - @Deprecated public TPSTable getTpsTable() { return tpsTable; diff --git a/Plan/common/src/main/java/com/djrapitops/plan/db/access/transactions/events/CommandStoreTransaction.java b/Plan/common/src/main/java/com/djrapitops/plan/db/access/transactions/events/CommandStoreTransaction.java new file mode 100644 index 000000000..caa8a1c13 --- /dev/null +++ b/Plan/common/src/main/java/com/djrapitops/plan/db/access/transactions/events/CommandStoreTransaction.java @@ -0,0 +1,67 @@ +package com.djrapitops.plan.db.access.transactions.events; + +import com.djrapitops.plan.db.access.ExecStatement; +import com.djrapitops.plan.db.access.transactions.Transaction; +import com.djrapitops.plan.db.sql.tables.CommandUseTable; +import com.djrapitops.plan.db.sql.tables.ServerTable; + +import java.sql.PreparedStatement; +import java.sql.SQLException; +import java.util.UUID; + +/** + * Transaction to update command usage information in the database. + * + * @author Rsl1122 + */ +public class CommandStoreTransaction extends Transaction { + + private final UUID serverUUID; + private final String commandName; + + public CommandStoreTransaction( + UUID serverUUID, + String commandName + ) { + this.serverUUID = serverUUID; + this.commandName = commandName; + } + + @Override + protected boolean shouldBeExecuted() { + return commandName.length() <= 20; + } + + @Override + protected void performOperations() { + if (!updateCommandUse()) { + insertCommand(); + } + } + + private boolean updateCommandUse() { + String sql = "UPDATE " + CommandUseTable.TABLE_NAME + " SET " + + CommandUseTable.TIMES_USED + "=" + CommandUseTable.TIMES_USED + "+ 1" + + " WHERE " + CommandUseTable.SERVER_ID + "=" + ServerTable.STATEMENT_SELECT_SERVER_ID + + " AND " + CommandUseTable.COMMAND + "=?"; + + return execute(new ExecStatement(sql) { + @Override + public void prepare(PreparedStatement statement) throws SQLException { + statement.setString(1, serverUUID.toString()); + statement.setString(2, commandName); + } + }); + } + + private void insertCommand() { + execute(new ExecStatement(CommandUseTable.INSERT_STATEMENT) { + @Override + public void prepare(PreparedStatement statement) throws SQLException { + statement.setString(1, commandName); + statement.setInt(2, 1); + statement.setString(3, serverUUID.toString()); + } + }); + } +} \ No newline at end of file diff --git a/Plan/common/src/main/java/com/djrapitops/plan/db/sql/tables/CommandUseTable.java b/Plan/common/src/main/java/com/djrapitops/plan/db/sql/tables/CommandUseTable.java index 62a64150c..9453d70d1 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/db/sql/tables/CommandUseTable.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/db/sql/tables/CommandUseTable.java @@ -17,26 +17,22 @@ package com.djrapitops.plan.db.sql.tables; import com.djrapitops.plan.db.DBType; -import com.djrapitops.plan.db.SQLDB; -import com.djrapitops.plan.db.access.ExecStatement; import com.djrapitops.plan.db.sql.parsing.CreateTableParser; import com.djrapitops.plan.db.sql.parsing.Sql; -import java.sql.PreparedStatement; -import java.sql.SQLException; - /** - * Table that is in charge of storing command data. - *
- * Table Name: plan_commandusages
+ * Table information about 'plan_commandusages'.
+ *
+ * Patches affecting this table:
+ * {@link com.djrapitops.plan.db.patches.Version10Patch}
*
* @author Rsl1122
*/
-public class CommandUseTable extends Table {
+public class CommandUseTable {
public static final String TABLE_NAME = "plan_commandusages";
- public static final String COMMAND_ID = "id";
+ public static final String ID = "id";
public static final String SERVER_ID = "server_id";
public static final String COMMAND = "command";
public static final String TIMES_USED = "times_used";
@@ -47,50 +43,17 @@ public class CommandUseTable extends Table {
+ SERVER_ID
+ ") VALUES (?, ?, " + ServerTable.STATEMENT_SELECT_SERVER_ID + ")";
- public CommandUseTable(SQLDB db) {
- super(TABLE_NAME, db);
+ private CommandUseTable() {
+ /* Static information class */
}
public static String createTableSQL(DBType dbType) {
return CreateTableParser.create(TABLE_NAME, dbType)
- .column(COMMAND_ID, Sql.INT).primaryKey()
+ .column(ID, Sql.INT).primaryKey()
.column(COMMAND, Sql.varchar(20)).notNull()
.column(TIMES_USED, Sql.INT).notNull()
.column(SERVER_ID, Sql.INT).notNull()
.foreignKey(SERVER_ID, ServerTable.TABLE_NAME, ServerTable.SERVER_ID)
.toString();
}
-
- public void commandUsed(String command) {
- if (command.length() > 20) {
- return;
- }
-
- String sql = "UPDATE " + TABLE_NAME + " SET "
- + TIMES_USED + "=" + TIMES_USED + "+ 1" +
- " WHERE " + SERVER_ID + "=" + ServerTable.STATEMENT_SELECT_SERVER_ID +
- " AND " + COMMAND + "=?";
-
- boolean updated = execute(new ExecStatement(sql) {
- @Override
- public void prepare(PreparedStatement statement) throws SQLException {
- statement.setString(1, getServerUUID().toString());
- statement.setString(2, command);
- }
- });
- if (!updated) {
- insertCommand(command);
- }
- }
-
- private void insertCommand(String command) {
- execute(new ExecStatement(INSERT_STATEMENT) {
- @Override
- public void prepare(PreparedStatement statement) throws SQLException {
- statement.setString(1, command);
- statement.setInt(2, 1);
- statement.setString(3, getServerUUID().toString());
- }
- });
- }
}
diff --git a/Plan/common/src/main/java/com/djrapitops/plan/system/database/databases/operation/SaveOperations.java b/Plan/common/src/main/java/com/djrapitops/plan/system/database/databases/operation/SaveOperations.java
index 755b7cdb3..16a051f4d 100644
--- a/Plan/common/src/main/java/com/djrapitops/plan/system/database/databases/operation/SaveOperations.java
+++ b/Plan/common/src/main/java/com/djrapitops/plan/system/database/databases/operation/SaveOperations.java
@@ -88,9 +88,6 @@ public interface SaveOperations {
@Deprecated
void registerNewUserOnThisServer(UUID uuid, long registered);
- @Deprecated
- void commandUsed(String commandName);
-
@Deprecated
void insertTPSforThisServer(TPS tps);
diff --git a/Plan/common/src/main/java/com/djrapitops/plan/system/database/databases/sql/operation/SQLOps.java b/Plan/common/src/main/java/com/djrapitops/plan/system/database/databases/sql/operation/SQLOps.java
index 8e4c9a1a9..f1b8d537d 100644
--- a/Plan/common/src/main/java/com/djrapitops/plan/system/database/databases/sql/operation/SQLOps.java
+++ b/Plan/common/src/main/java/com/djrapitops/plan/system/database/databases/sql/operation/SQLOps.java
@@ -19,6 +19,7 @@ package com.djrapitops.plan.system.database.databases.sql.operation;
import com.djrapitops.plan.db.SQLDB;
import com.djrapitops.plan.db.sql.tables.*;
+@Deprecated
public class SQLOps {
protected final SQLDB db;
@@ -29,7 +30,6 @@ public class SQLOps {
protected final NicknamesTable nicknamesTable;
protected final SessionsTable sessionsTable;
protected final GeoInfoTable geoInfoTable;
- protected final CommandUseTable commandUseTable;
protected final TPSTable tpsTable;
protected final SecurityTable securityTable;
protected final WorldTable worldTable;
@@ -47,7 +47,6 @@ public class SQLOps {
nicknamesTable = db.getNicknamesTable();
sessionsTable = db.getSessionsTable();
geoInfoTable = db.getGeoInfoTable();
- commandUseTable = db.getCommandUseTable();
tpsTable = db.getTpsTable();
securityTable = db.getSecurityTable();
worldTable = db.getWorldTable();
diff --git a/Plan/common/src/main/java/com/djrapitops/plan/system/database/databases/sql/operation/SQLSaveOps.java b/Plan/common/src/main/java/com/djrapitops/plan/system/database/databases/sql/operation/SQLSaveOps.java
index 4b5f5234b..f95a1a75d 100644
--- a/Plan/common/src/main/java/com/djrapitops/plan/system/database/databases/sql/operation/SQLSaveOps.java
+++ b/Plan/common/src/main/java/com/djrapitops/plan/system/database/databases/sql/operation/SQLSaveOps.java
@@ -166,11 +166,6 @@ public class SQLSaveOps extends SQLOps implements SaveOperations {
userInfoTable.registerUserInfo(uuid, registered);
}
- @Override
- public void commandUsed(String commandName) {
- commandUseTable.commandUsed(commandName);
- }
-
@Override
public void insertTPSforThisServer(TPS tps) {
tpsTable.insertTPS(tps);
diff --git a/Plan/common/src/main/java/com/djrapitops/plan/system/processing/processors/CommandProcessor.java b/Plan/common/src/main/java/com/djrapitops/plan/system/processing/processors/CommandProcessor.java
deleted file mode 100644
index bc26e7940..000000000
--- a/Plan/common/src/main/java/com/djrapitops/plan/system/processing/processors/CommandProcessor.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * This file is part of Player Analytics (Plan).
- *
- * Plan is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License v3 as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Plan is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with Plan. If not, see