diff --git a/Plan/bukkit/src/main/java/com/djrapitops/plan/gathering/importing/importers/BukkitImporter.java b/Plan/bukkit/src/main/java/com/djrapitops/plan/gathering/importing/importers/BukkitImporter.java index 532fc941d..ffdbed27b 100644 --- a/Plan/bukkit/src/main/java/com/djrapitops/plan/gathering/importing/importers/BukkitImporter.java +++ b/Plan/bukkit/src/main/java/com/djrapitops/plan/gathering/importing/importers/BukkitImporter.java @@ -98,7 +98,6 @@ public abstract class BukkitImporter implements Importer { @Override protected void performOperations() { execute(LargeStoreQueries.storeAllTPSData(Collections.singletonMap(serverUUID.get(), serverImportData.getTpsData()))); - execute(LargeStoreQueries.storeAllCommandUsageData(Collections.singletonMap(serverUUID.get(), serverImportData.getCommandUsages()))); } }); } diff --git a/Plan/bukkit/src/main/java/com/djrapitops/plan/gathering/listeners/BukkitListenerSystem.java b/Plan/bukkit/src/main/java/com/djrapitops/plan/gathering/listeners/BukkitListenerSystem.java index c2fe7a98a..1d74aea70 100644 --- a/Plan/bukkit/src/main/java/com/djrapitops/plan/gathering/listeners/BukkitListenerSystem.java +++ b/Plan/bukkit/src/main/java/com/djrapitops/plan/gathering/listeners/BukkitListenerSystem.java @@ -35,7 +35,6 @@ public class BukkitListenerSystem extends ListenerSystem { private final ChatListener chatListener; private final GameModeChangeListener gamemodeChangeListener; private final WorldChangeListener worldChangeListener; - private final CommandListener commandListener; private final DeathEventListener deathEventListener; private final BukkitAFKListener afkListener; @@ -46,7 +45,6 @@ public class BukkitListenerSystem extends ListenerSystem { ChatListener chatListener, GameModeChangeListener gamemodeChangeListener, WorldChangeListener worldChangeListener, - CommandListener commandListener, DeathEventListener deathEventListener, BukkitAFKListener afkListener ) { @@ -57,7 +55,6 @@ public class BukkitListenerSystem extends ListenerSystem { this.chatListener = chatListener; this.gamemodeChangeListener = gamemodeChangeListener; this.worldChangeListener = worldChangeListener; - this.commandListener = commandListener; this.deathEventListener = deathEventListener; this.afkListener = afkListener; } @@ -69,7 +66,6 @@ public class BukkitListenerSystem extends ListenerSystem { chatListener, gamemodeChangeListener, worldChangeListener, - commandListener, deathEventListener, afkListener ); diff --git a/Plan/bukkit/src/main/java/com/djrapitops/plan/gathering/listeners/bukkit/CommandListener.java b/Plan/bukkit/src/main/java/com/djrapitops/plan/gathering/listeners/bukkit/CommandListener.java deleted file mode 100644 index 742723a75..000000000 --- a/Plan/bukkit/src/main/java/com/djrapitops/plan/gathering/listeners/bukkit/CommandListener.java +++ /dev/null @@ -1,108 +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 . - */ -package com.djrapitops.plan.gathering.listeners.bukkit; - -import com.djrapitops.plan.Plan; -import com.djrapitops.plan.identification.ServerInfo; -import com.djrapitops.plan.settings.Permissions; -import com.djrapitops.plan.settings.config.PlanConfig; -import com.djrapitops.plan.settings.config.paths.DataGatheringSettings; -import com.djrapitops.plan.storage.database.DBSystem; -import com.djrapitops.plan.storage.database.transactions.events.CommandStoreTransaction; -import com.djrapitops.plugin.logging.L; -import com.djrapitops.plugin.logging.error.ErrorHandler; -import org.bukkit.command.Command; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.Listener; -import org.bukkit.event.player.PlayerCommandPreprocessEvent; - -import javax.inject.Inject; - -/** - * Event Listener for PlayerCommandPreprocessEvents. - * - * @author Rsl1122 - */ -public class CommandListener implements Listener { - - private final Plan plugin; - private final PlanConfig config; - private final ServerInfo serverInfo; - private final DBSystem dbSystem; - private final ErrorHandler errorHandler; - - @Inject - public CommandListener( - Plan plugin, - PlanConfig config, - ServerInfo serverInfo, - DBSystem dbSystem, - ErrorHandler errorHandler - ) { - this.plugin = plugin; - this.config = config; - this.serverInfo = serverInfo; - this.dbSystem = dbSystem; - this.errorHandler = errorHandler; - } - - @EventHandler(priority = EventPriority.MONITOR) - public void onPlayerCommand(PlayerCommandPreprocessEvent event) { - boolean hasIgnorePermission = event.getPlayer().hasPermission(Permissions.IGNORE_COMMAND_USE.getPermission()); - if (event.isCancelled() || hasIgnorePermission) { - return; - } - - try { - actOnCommandEvent(event); - } catch (Exception e) { - errorHandler.log(L.ERROR, this.getClass(), e); - } - } - - private void actOnCommandEvent(PlayerCommandPreprocessEvent event) { - String commandName = event.getMessage().substring(1).split(" ")[0].toLowerCase(); - - boolean logUnknownCommands = config.isTrue(DataGatheringSettings.LOG_UNKNOWN_COMMANDS); - boolean combineCommandAliases = config.isTrue(DataGatheringSettings.COMBINE_COMMAND_ALIASES); - - if (!logUnknownCommands || combineCommandAliases) { - Command command = getBukkitCommand(commandName); - if (command == null) { - if (!logUnknownCommands) { - return; - } - } else if (combineCommandAliases) { - commandName = command.getName(); - } - } - dbSystem.getDatabase().executeTransaction(new CommandStoreTransaction(serverInfo.getServerUUID(), commandName)); - } - - private Command getBukkitCommand(String commandName) { - Command command = plugin.getServer().getPluginCommand(commandName); - if (command == null) { - try { - command = plugin.getServer().getCommandMap().getCommand(commandName); - } catch (NoSuchMethodError ignored) { - /* Ignored, Bukkit 1.8 has no such method. This method is from Paper */ - } - } - return command; - } -} diff --git a/Plan/common/src/main/java/com/djrapitops/plan/delivery/domain/keys/ServerKeys.java b/Plan/common/src/main/java/com/djrapitops/plan/delivery/domain/keys/ServerKeys.java index 6bb14ed6d..73c93ac2c 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/delivery/domain/keys/ServerKeys.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/delivery/domain/keys/ServerKeys.java @@ -58,6 +58,7 @@ public class ServerKeys { public static final Key> TPS = new Key<>(new Type>() {}, "tps"); public static final Key> ALL_TIME_PEAK_PLAYERS = new Key<>(new Type>() {}, "all_time_peak_players"); public static final Key> RECENT_PEAK_PLAYERS = new Key<>(new Type>() {}, "recent_peak_players"); + @Deprecated public static final Key> COMMAND_USAGE = new Key<>(new Type>() {}, "command_usage"); public static final Key> EXTENSION_DATA = new Key<>(new Type>() {}, "extension_data"); } \ No newline at end of file diff --git a/Plan/common/src/main/java/com/djrapitops/plan/delivery/domain/mutators/CommandUseMutator.java b/Plan/common/src/main/java/com/djrapitops/plan/delivery/domain/mutators/CommandUseMutator.java deleted file mode 100644 index 544869f29..000000000 --- a/Plan/common/src/main/java/com/djrapitops/plan/delivery/domain/mutators/CommandUseMutator.java +++ /dev/null @@ -1,51 +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 . - */ -package com.djrapitops.plan.delivery.domain.mutators; - -import com.djrapitops.plan.delivery.domain.container.DataContainer; -import com.djrapitops.plan.delivery.domain.keys.ServerKeys; - -import java.util.HashMap; -import java.util.Map; - -/** - * Mutator for Command Usage Map objects. - *

- * Can be used to easily get different values about the map. - * - * @author Rsl1122 - */ -public class CommandUseMutator { - - private Map commandUsage; - - public CommandUseMutator(Map commandUsage) { - this.commandUsage = commandUsage; - } - - public static CommandUseMutator forContainer(DataContainer container) { - return new CommandUseMutator(container.getValue(ServerKeys.COMMAND_USAGE).orElse(new HashMap<>())); - } - - public int commandUsageCount() { - int total = 0; - for (Integer value : commandUsage.values()) { - total += value; - } - return total; - } -} \ No newline at end of file diff --git a/Plan/common/src/main/java/com/djrapitops/plan/gathering/importing/data/ServerImportData.java b/Plan/common/src/main/java/com/djrapitops/plan/gathering/importing/data/ServerImportData.java index 11f2a3824..8b387e350 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/gathering/importing/data/ServerImportData.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/gathering/importing/data/ServerImportData.java @@ -19,18 +19,19 @@ package com.djrapitops.plan.gathering.importing.data; import com.djrapitops.plan.gathering.domain.TPS; import com.djrapitops.plan.gathering.domain.builders.TPSBuilder; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.List; /** * @author Fuzzlemann */ public class ServerImportData { - private Map commandUsages; private List tpsData; - private ServerImportData(Map commandUsages, List tpsData) { - this.commandUsages = commandUsages; + private ServerImportData(List tpsData) { this.tpsData = tpsData; } @@ -38,14 +39,6 @@ public class ServerImportData { return new ServerImportDataBuilder(); } - public Map getCommandUsages() { - return commandUsages; - } - - public void setCommandUsages(Map commandUsages) { - this.commandUsages = commandUsages; - } - public List getTpsData() { return tpsData; } @@ -55,23 +48,12 @@ public class ServerImportData { } public static final class ServerImportDataBuilder { - private final Map commandUsages = new HashMap<>(); private final List tpsData = new ArrayList<>(); private ServerImportDataBuilder() { /* Private Constructor */ } - public ServerImportDataBuilder commandUsage(String command, Integer usages) { - this.commandUsages.put(command, usages); - return this; - } - - public ServerImportDataBuilder commandUsages(Map commandUsages) { - this.commandUsages.putAll(commandUsages); - return this; - } - public ServerImportDataBuilder tpsData(long date, double ticksPerSecond, int players, double cpuUsage, long usedMemory, int entityCount, int chunksLoaded) { TPS tps = TPSBuilder.get() .date(date) @@ -97,7 +79,7 @@ public class ServerImportData { } public ServerImportData build() { - return new ServerImportData(commandUsages, tpsData); + return new ServerImportData(tpsData); } } } diff --git a/Plan/common/src/main/java/com/djrapitops/plan/storage/database/queries/DataStoreQueries.java b/Plan/common/src/main/java/com/djrapitops/plan/storage/database/queries/DataStoreQueries.java index 41e153dc7..ac2b2a44f 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/storage/database/queries/DataStoreQueries.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/storage/database/queries/DataStoreQueries.java @@ -42,43 +42,6 @@ public class DataStoreQueries { /* static method class */ } - /** - * Store the used command in the database. - * - * @param serverUUID UUID of the Plan server. - * @param commandName Name of the command that was used. - * @return Executable, use inside a {@link com.djrapitops.plan.storage.database.transactions.Transaction} - */ - public static Executable storeUsedCommandInformation(UUID serverUUID, String commandName) { - return connection -> { - if (!updateCommandUsage(serverUUID, commandName).execute(connection)) { - insertNewCommandUsage(serverUUID, commandName).execute(connection); - } - return false; - }; - } - - private static Executable updateCommandUsage(UUID serverUUID, String commandName) { - return new ExecStatement(CommandUseTable.UPDATE_STATEMENT) { - @Override - public void prepare(PreparedStatement statement) throws SQLException { - statement.setString(1, serverUUID.toString()); - statement.setString(2, commandName); - } - }; - } - - private static Executable insertNewCommandUsage(UUID serverUUID, String commandName) { - return 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()); - } - }; - } - /** * Store a finished session in the database. * diff --git a/Plan/common/src/main/java/com/djrapitops/plan/storage/database/queries/LargeFetchQueries.java b/Plan/common/src/main/java/com/djrapitops/plan/storage/database/queries/LargeFetchQueries.java index c776eeba4..4608d4485 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/storage/database/queries/LargeFetchQueries.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/storage/database/queries/LargeFetchQueries.java @@ -18,7 +18,6 @@ package com.djrapitops.plan.storage.database.queries; import com.djrapitops.plan.gathering.domain.TPS; import com.djrapitops.plan.gathering.domain.builders.TPSBuilder; -import com.djrapitops.plan.storage.database.sql.tables.CommandUseTable; import com.djrapitops.plan.storage.database.sql.tables.ServerTable; import com.djrapitops.plan.storage.database.sql.tables.TPSTable; import com.djrapitops.plan.storage.database.sql.tables.WorldTable; @@ -40,41 +39,6 @@ public class LargeFetchQueries { /* Static method class */ } - /** - * Query database for all command usage data. - * - * @return Multi map: Server UUID - (Command name - Usage count) - */ - public static Query>> fetchAllCommandUsageData() { - String serverIDColumn = ServerTable.TABLE_NAME + '.' + ServerTable.SERVER_ID; - String serverUUIDColumn = ServerTable.TABLE_NAME + '.' + ServerTable.SERVER_UUID + " as s_uuid"; - String sql = SELECT + - CommandUseTable.COMMAND + ',' + - CommandUseTable.TIMES_USED + ',' + - serverUUIDColumn + - FROM + CommandUseTable.TABLE_NAME + - INNER_JOIN + ServerTable.TABLE_NAME + " on " + serverIDColumn + "=" + CommandUseTable.SERVER_ID; - - return new QueryAllStatement>>(sql, 10000) { - @Override - public Map> processResults(ResultSet set) throws SQLException { - Map> map = new HashMap<>(); - while (set.next()) { - UUID serverUUID = UUID.fromString(set.getString("s_uuid")); - - Map serverMap = map.getOrDefault(serverUUID, new HashMap<>()); - - String command = set.getString(CommandUseTable.COMMAND); - int timesUsed = set.getInt(CommandUseTable.TIMES_USED); - - serverMap.put(command, timesUsed); - map.put(serverUUID, serverMap); - } - return map; - } - }; - } - /** * Query database for TPS data. * diff --git a/Plan/common/src/main/java/com/djrapitops/plan/storage/database/queries/LargeStoreQueries.java b/Plan/common/src/main/java/com/djrapitops/plan/storage/database/queries/LargeStoreQueries.java index 73ae78256..fe64d5c65 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/storage/database/queries/LargeStoreQueries.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/storage/database/queries/LargeStoreQueries.java @@ -44,38 +44,6 @@ public class LargeStoreQueries { /* Static method class */ } - /** - * Execute a big batch of command use insert statements. - * - * @param ofServers Multi map: Server UUID - (Command name - Usage count) - * @return Executable, use inside a {@link com.djrapitops.plan.storage.database.transactions.Transaction} - */ - public static Executable storeAllCommandUsageData(Map> ofServers) { - if (ofServers.isEmpty()) { - return Executable.empty(); - } - - return new ExecBatchStatement(CommandUseTable.INSERT_STATEMENT) { - @Override - public void prepare(PreparedStatement statement) throws SQLException { - // Every Server - for (Map.Entry> serverEntry : ofServers.entrySet()) { - UUID serverUUID = serverEntry.getKey(); - // Every Command - for (Map.Entry entry : serverEntry.getValue().entrySet()) { - String command = entry.getKey(); - int timesUsed = entry.getValue(); - - statement.setString(1, command); - statement.setInt(2, timesUsed); - statement.setString(3, serverUUID.toString()); - statement.addBatch(); - } - } - } - }; - } - /** * Execute a big batch of GeoInfo insert statements. * diff --git a/Plan/common/src/main/java/com/djrapitops/plan/storage/database/queries/ServerAggregateQueries.java b/Plan/common/src/main/java/com/djrapitops/plan/storage/database/queries/ServerAggregateQueries.java index de4ac6736..240bec5f5 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/storage/database/queries/ServerAggregateQueries.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/storage/database/queries/ServerAggregateQueries.java @@ -16,8 +16,6 @@ */ package com.djrapitops.plan.storage.database.queries; -import com.djrapitops.plan.storage.database.sql.tables.CommandUseTable; -import com.djrapitops.plan.storage.database.sql.tables.ServerTable; import com.djrapitops.plan.storage.database.sql.tables.UserInfoTable; import com.djrapitops.plan.storage.database.sql.tables.UsersTable; @@ -103,33 +101,4 @@ public class ServerAggregateQueries { }; } - /** - * Count how many times commands have been used on a server. - * - * @param serverUUID Server UUID of the Plan server. - * @return Map: Lowercase used command - Count of use times. - */ - public static Query> commandUsageCounts(UUID serverUUID) { - String sql = SELECT + CommandUseTable.COMMAND + ',' + CommandUseTable.TIMES_USED + FROM + CommandUseTable.TABLE_NAME + - WHERE + CommandUseTable.SERVER_ID + "=" + ServerTable.STATEMENT_SELECT_SERVER_ID; - - return new QueryStatement>(sql, 5000) { - @Override - public void prepare(PreparedStatement statement) throws SQLException { - statement.setString(1, serverUUID.toString()); - } - - @Override - public Map processResults(ResultSet set) throws SQLException { - Map commandUse = new HashMap<>(); - while (set.next()) { - String cmd = set.getString(CommandUseTable.COMMAND).toLowerCase(); - int amountUsed = set.getInt(CommandUseTable.TIMES_USED); - commandUse.put(cmd, amountUsed); - } - return commandUse; - } - }; - } - } diff --git a/Plan/common/src/main/java/com/djrapitops/plan/storage/database/queries/containers/ServerContainerQuery.java b/Plan/common/src/main/java/com/djrapitops/plan/storage/database/queries/containers/ServerContainerQuery.java index 80c87212a..54dd3373e 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/storage/database/queries/containers/ServerContainerQuery.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/storage/database/queries/containers/ServerContainerQuery.java @@ -26,7 +26,6 @@ import com.djrapitops.plan.gathering.domain.Session; import com.djrapitops.plan.identification.Server; import com.djrapitops.plan.storage.database.SQLDB; import com.djrapitops.plan.storage.database.queries.Query; -import com.djrapitops.plan.storage.database.queries.ServerAggregateQueries; import com.djrapitops.plan.storage.database.queries.objects.ServerQueries; import com.djrapitops.plan.storage.database.queries.objects.TPSQueries; import com.djrapitops.plan.storage.database.queries.objects.WorldTimesQueries; @@ -79,7 +78,6 @@ public class ServerContainerQuery implements Query { return db.query(TPSQueries.fetchPeakPlayerCount(serverUUID, twoDaysAgo)).orElse(null); }); - container.putCachingSupplier(ServerKeys.COMMAND_USAGE, () -> db.query(ServerAggregateQueries.commandUsageCounts(serverUUID))); container.putCachingSupplier(ServerKeys.WORLD_TIMES, () -> db.query(WorldTimesQueries.fetchServerTotalWorldTimes(serverUUID))); // Calculating getters diff --git a/Plan/common/src/main/java/com/djrapitops/plan/storage/database/sql/tables/CommandUseTable.java b/Plan/common/src/main/java/com/djrapitops/plan/storage/database/sql/tables/CommandUseTable.java index 2ba22aa5a..ea8ae6f22 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/storage/database/sql/tables/CommandUseTable.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/storage/database/sql/tables/CommandUseTable.java @@ -16,13 +16,6 @@ */ package com.djrapitops.plan.storage.database.sql.tables; -import com.djrapitops.plan.storage.database.DBType; -import com.djrapitops.plan.storage.database.sql.parsing.CreateTableParser; -import com.djrapitops.plan.storage.database.sql.parsing.Sql; - -import static com.djrapitops.plan.storage.database.sql.parsing.Sql.AND; -import static com.djrapitops.plan.storage.database.sql.parsing.Sql.WHERE; - /** * Table information about 'plan_commandusages'. * @@ -30,38 +23,15 @@ import static com.djrapitops.plan.storage.database.sql.parsing.Sql.WHERE; * {@link com.djrapitops.plan.storage.database.transactions.patches.Version10Patch} * * @author Rsl1122 + * @deprecated TODO DELETE AFTER DROPPING TABLE */ +@Deprecated public class CommandUseTable { public static final String TABLE_NAME = "plan_commandusages"; - 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"; - - public static final String INSERT_STATEMENT = "INSERT INTO " + TABLE_NAME + " (" - + COMMAND + ',' - + TIMES_USED + ',' - + SERVER_ID - + ") VALUES (?, ?, " + ServerTable.STATEMENT_SELECT_SERVER_ID + ')'; - - public static final String UPDATE_STATEMENT = "UPDATE " + CommandUseTable.TABLE_NAME + " SET " - + CommandUseTable.TIMES_USED + "=" + CommandUseTable.TIMES_USED + "+ 1" + - WHERE + CommandUseTable.SERVER_ID + "=" + ServerTable.STATEMENT_SELECT_SERVER_ID + - AND + CommandUseTable.COMMAND + "=?"; - private CommandUseTable() { /* Static information class */ } - public static String createTableSQL(DBType dbType) { - return CreateTableParser.create(TABLE_NAME, dbType) - .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(); - } } diff --git a/Plan/common/src/main/java/com/djrapitops/plan/storage/database/transactions/BackupCopyTransaction.java b/Plan/common/src/main/java/com/djrapitops/plan/storage/database/transactions/BackupCopyTransaction.java index cea68c8aa..319f641d9 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/storage/database/transactions/BackupCopyTransaction.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/storage/database/transactions/BackupCopyTransaction.java @@ -55,7 +55,6 @@ public class BackupCopyTransaction extends RemoveEverythingTransaction { copyWorldNames(); copyTPSData(); copyPlanWebUsers(); - copyCommandUsageData(); copyGeoInformation(); copyNicknameData(); copySessionsWithKillAndWorldData(); @@ -72,10 +71,6 @@ public class BackupCopyTransaction extends RemoveEverythingTransaction { copy(LargeStoreQueries::storeAllPingData, PingQueries.fetchAllPingData()); } - private void copyCommandUsageData() { - copy(LargeStoreQueries::storeAllCommandUsageData, LargeFetchQueries.fetchAllCommandUsageData()); - } - private void copyGeoInformation() { copy(LargeStoreQueries::storeAllGeoInformation, GeoInfoQueries.fetchAllGeoInformation()); } diff --git a/Plan/common/src/main/java/com/djrapitops/plan/storage/database/transactions/commands/RemoveEverythingTransaction.java b/Plan/common/src/main/java/com/djrapitops/plan/storage/database/transactions/commands/RemoveEverythingTransaction.java index 0747032ec..88a0fa00d 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/storage/database/transactions/commands/RemoveEverythingTransaction.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/storage/database/transactions/commands/RemoveEverythingTransaction.java @@ -42,7 +42,6 @@ public class RemoveEverythingTransaction extends Transaction { clearTable(PingTable.TABLE_NAME); clearTable(UserInfoTable.TABLE_NAME); clearTable(UsersTable.TABLE_NAME); - clearTable(CommandUseTable.TABLE_NAME); clearTable(TPSTable.TABLE_NAME); clearTable(SecurityTable.TABLE_NAME); clearTable(ServerTable.TABLE_NAME); diff --git a/Plan/common/src/main/java/com/djrapitops/plan/storage/database/transactions/events/CommandStoreTransaction.java b/Plan/common/src/main/java/com/djrapitops/plan/storage/database/transactions/events/CommandStoreTransaction.java deleted file mode 100644 index 8b008011a..000000000 --- a/Plan/common/src/main/java/com/djrapitops/plan/storage/database/transactions/events/CommandStoreTransaction.java +++ /dev/null @@ -1,51 +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 . - */ -package com.djrapitops.plan.storage.database.transactions.events; - -import com.djrapitops.plan.storage.database.queries.DataStoreQueries; -import com.djrapitops.plan.storage.database.transactions.Transaction; - -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() { - execute(DataStoreQueries.storeUsedCommandInformation(serverUUID, commandName)); - } -} \ No newline at end of file diff --git a/Plan/common/src/main/java/com/djrapitops/plan/storage/database/transactions/init/CreateTablesTransaction.java b/Plan/common/src/main/java/com/djrapitops/plan/storage/database/transactions/init/CreateTablesTransaction.java index bf258ab03..955a9a399 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/storage/database/transactions/init/CreateTablesTransaction.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/storage/database/transactions/init/CreateTablesTransaction.java @@ -39,7 +39,6 @@ public class CreateTablesTransaction extends OperationCriticalTransaction { execute(SessionsTable.createTableSQL(dbType)); execute(KillsTable.createTableSQL(dbType)); execute(PingTable.createTableSQL(dbType)); - execute(CommandUseTable.createTableSQL(dbType)); execute(TPSTable.createTableSQL(dbType)); execute(WorldTable.createTableSQL(dbType)); execute(WorldTimesTable.createTableSQL(dbType)); diff --git a/Plan/common/src/main/java/com/djrapitops/plan/storage/database/transactions/patches/Version10Patch.java b/Plan/common/src/main/java/com/djrapitops/plan/storage/database/transactions/patches/Version10Patch.java index 6190c4b5d..e39754673 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/storage/database/transactions/patches/Version10Patch.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/storage/database/transactions/patches/Version10Patch.java @@ -43,8 +43,6 @@ public class Version10Patch extends Patch { } public void alterTablesToV10() { - copyCommandUsage(); - copyTPS(); dropTable(UserInfoTable.TABLE_NAME); @@ -103,22 +101,6 @@ public class Version10Patch extends Patch { execute(statement); } - private void copyCommandUsage() { - String tempTableName = "temp_cmdusg"; - - renameTable("plan_commandusages", tempTableName); - - execute(CommandUseTable.createTableSQL(dbType)); - - String statement = "INSERT INTO plan_commandusages " + - "(command, times_used, server_id)" + - " SELECT command, times_used, '" + serverID + "'" + - FROM + tempTableName; - execute(statement); - - dropTable(tempTableName); - } - private void copyTPS() { String tempTableName = "temp_tps"; diff --git a/Plan/common/src/test/java/com/djrapitops/plan/gathering/importing/data/ImportBuilderTest.java b/Plan/common/src/test/java/com/djrapitops/plan/gathering/importing/data/ImportBuilderTest.java index fea5a6502..7dd3619fc 100644 --- a/Plan/common/src/test/java/com/djrapitops/plan/gathering/importing/data/ImportBuilderTest.java +++ b/Plan/common/src/test/java/com/djrapitops/plan/gathering/importing/data/ImportBuilderTest.java @@ -29,7 +29,6 @@ import utilities.TestConstants; import java.util.Arrays; import java.util.Collections; -import java.util.HashMap; import java.util.UUID; import static org.junit.jupiter.api.Assertions.*; @@ -49,7 +48,6 @@ class ImportBuilderTest { void emptyServerBuilderInitializesCollections() { ServerImportData data = ServerImportData.builder().build(); - assertNotNull(data.getCommandUsages()); assertNotNull(data.getTpsData()); } @@ -93,16 +91,9 @@ class ImportBuilderTest { .tpsData(randomInt, randomInt, randomInt, randomInt, randomInt, randomInt, randomInt) .tpsData(Collections.singletonList(tps)) .tpsData(Arrays.asList(tps, tps)) - .commandUsage(randomString, randomInt) - .commandUsage(randomString, randomInt) - .commandUsage(randomString, randomInt) - .commandUsage(randomString, randomInt) - .commandUsages(new HashMap<>()) - .commandUsages(ImmutableMap.of(randomString, randomInt)) .build(); assertEquals(10, data.getTpsData().size()); - assertEquals(1, data.getCommandUsages().size()); assertEquals(randomInt, data.getTpsData().get(0).getDate()); } diff --git a/Plan/common/src/test/java/com/djrapitops/plan/storage/database/DBPatchRegressionTest.java b/Plan/common/src/test/java/com/djrapitops/plan/storage/database/DBPatchRegressionTest.java index f394a33dd..9833c8ba2 100644 --- a/Plan/common/src/test/java/com/djrapitops/plan/storage/database/DBPatchRegressionTest.java +++ b/Plan/common/src/test/java/com/djrapitops/plan/storage/database/DBPatchRegressionTest.java @@ -43,7 +43,6 @@ abstract class DBPatchRegressionTest { underTest.executeTransaction(new Transaction() { @Override protected void performOperations() { - execute("DROP TABLE " + CommandUseTable.TABLE_NAME); execute("DROP TABLE " + GeoInfoTable.TABLE_NAME); execute("DROP TABLE " + KillsTable.TABLE_NAME); execute("DROP TABLE " + NicknamesTable.TABLE_NAME); diff --git a/Plan/common/src/test/java/com/djrapitops/plan/storage/database/DatabaseTest.java b/Plan/common/src/test/java/com/djrapitops/plan/storage/database/DatabaseTest.java index e35842865..b81963943 100644 --- a/Plan/common/src/test/java/com/djrapitops/plan/storage/database/DatabaseTest.java +++ b/Plan/common/src/test/java/com/djrapitops/plan/storage/database/DatabaseTest.java @@ -146,56 +146,6 @@ public interface DatabaseTest { db().init(); } - @Test - default void testSaveCommandUse() { - Map expected = new HashMap<>(); - - expected.put("plan", 1); - expected.put("tp", 4); - expected.put("pla", 7); - expected.put("help", 21); - - useCommand("plan"); - useCommand("tp", 4); - useCommand("pla", 7); - useCommand("help", 21); - useCommand("roiergbnougbierubieugbeigubeigubgierbgeugeg", 3); - - commitTest(); - - Map commandUse = db().query(ServerAggregateQueries.commandUsageCounts(serverUUID())); - assertEquals(expected, commandUse); - } - - @Test - default void commandUsageSavingDoesNotCreateNewEntriesForOldCommands() { - Map expected = new HashMap<>(); - - expected.put("plan", 1); - expected.put("test", 3); - expected.put("tp", 6); - expected.put("pla", 7); - expected.put("help", 21); - - testSaveCommandUse(); - - useCommand("test", 3); - useCommand("tp", 2); - - Map commandUse = db().query(ServerAggregateQueries.commandUsageCounts(serverUUID())); - assertEquals(expected, commandUse); - } - - default void useCommand(String commandName) { - db().executeTransaction(new CommandStoreTransaction(serverUUID(), commandName)); - } - - default void useCommand(String commandName, int times) { - for (int i = 0; i < times; i++) { - useCommand(commandName); - } - } - @Test default void testTPSSaving() { Random r = new Random(); @@ -494,7 +444,6 @@ public interface DatabaseTest { assertQueryIsEmpty(db(), NicknameQueries.fetchAllNicknameData()); assertQueryIsEmpty(db(), GeoInfoQueries.fetchAllGeoInformation()); assertTrue(db().query(SessionQueries.fetchAllSessions()).isEmpty()); - assertQueryIsEmpty(db(), LargeFetchQueries.fetchAllCommandUsageData()); assertQueryIsEmpty(db(), LargeFetchQueries.fetchAllWorldNames()); assertQueryIsEmpty(db(), LargeFetchQueries.fetchAllTPSData()); assertQueryIsEmpty(db(), ServerQueries.fetchPlanServerInformation()); @@ -525,13 +474,6 @@ public interface DatabaseTest { assertTrue(db().query(PlayerFetchQueries.isPlayerRegistered(playerUUID))); - useCommand("plan"); - useCommand("plan"); - useCommand("tp"); - useCommand("help"); - useCommand("help"); - useCommand("help"); - List expected = new ArrayList<>(); Random r = new Random(); OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean(); @@ -694,7 +636,6 @@ public interface DatabaseTest { assertQueryResultIsEqual(db(), backup, NicknameQueries.fetchAllNicknameData()); assertQueryResultIsEqual(db(), backup, GeoInfoQueries.fetchAllGeoInformation()); assertQueryResultIsEqual(db(), backup, SessionQueries.fetchAllSessions()); - assertQueryResultIsEqual(db(), backup, LargeFetchQueries.fetchAllCommandUsageData()); assertQueryResultIsEqual(db(), backup, LargeFetchQueries.fetchAllWorldNames()); assertQueryResultIsEqual(db(), backup, LargeFetchQueries.fetchAllTPSData()); assertQueryResultIsEqual(db(), backup, ServerQueries.fetchPlanServerInformation()); @@ -722,7 +663,6 @@ public interface DatabaseTest { assertQueryResultIsEqual(db(), backup, NicknameQueries.fetchAllNicknameData()); assertQueryResultIsEqual(db(), backup, GeoInfoQueries.fetchAllGeoInformation()); assertQueryResultIsEqual(db(), backup, SessionQueries.fetchAllSessions()); - assertQueryResultIsEqual(db(), backup, LargeFetchQueries.fetchAllCommandUsageData()); assertQueryResultIsEqual(db(), backup, LargeFetchQueries.fetchAllWorldNames()); assertQueryResultIsEqual(db(), backup, LargeFetchQueries.fetchAllTPSData()); assertQueryResultIsEqual(db(), backup, ServerQueries.fetchPlanServerInformation()); diff --git a/Plan/sponge/src/main/java/com/djrapitops/plan/gathering/listeners/SpongeListenerSystem.java b/Plan/sponge/src/main/java/com/djrapitops/plan/gathering/listeners/SpongeListenerSystem.java index bc70ddbb9..1bcd2a6b2 100644 --- a/Plan/sponge/src/main/java/com/djrapitops/plan/gathering/listeners/SpongeListenerSystem.java +++ b/Plan/sponge/src/main/java/com/djrapitops/plan/gathering/listeners/SpongeListenerSystem.java @@ -33,7 +33,6 @@ public class SpongeListenerSystem extends ListenerSystem { private final SpongeAFKListener afkListener; private final SpongeChatListener chatListener; - private final SpongeCommandListener commandListener; private final SpongeDeathListener deathListener; private final SpongeGMChangeListener gmChangeListener; private final PlayerOnlineListener playerListener; @@ -45,7 +44,6 @@ public class SpongeListenerSystem extends ListenerSystem { PlanSponge plugin, SpongeAFKListener afkListener, SpongeChatListener chatListener, - SpongeCommandListener commandListener, SpongeDeathListener deathListener, SpongeGMChangeListener gmChangeListener, PlayerOnlineListener playerListener, @@ -56,7 +54,6 @@ public class SpongeListenerSystem extends ListenerSystem { this.afkListener = afkListener; this.chatListener = chatListener; - this.commandListener = commandListener; this.deathListener = deathListener; this.gmChangeListener = gmChangeListener; this.playerListener = playerListener; @@ -69,7 +66,6 @@ public class SpongeListenerSystem extends ListenerSystem { plugin.registerListener( afkListener, chatListener, - commandListener, deathListener, playerListener, gmChangeListener, diff --git a/Plan/sponge/src/main/java/com/djrapitops/plan/gathering/listeners/sponge/SpongeCommandListener.java b/Plan/sponge/src/main/java/com/djrapitops/plan/gathering/listeners/sponge/SpongeCommandListener.java deleted file mode 100644 index fbb5cbd37..000000000 --- a/Plan/sponge/src/main/java/com/djrapitops/plan/gathering/listeners/sponge/SpongeCommandListener.java +++ /dev/null @@ -1,95 +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 . - */ -package com.djrapitops.plan.gathering.listeners.sponge; - -import com.djrapitops.plan.identification.ServerInfo; -import com.djrapitops.plan.settings.Permissions; -import com.djrapitops.plan.settings.config.PlanConfig; -import com.djrapitops.plan.settings.config.paths.DataGatheringSettings; -import com.djrapitops.plan.storage.database.DBSystem; -import com.djrapitops.plan.storage.database.transactions.events.CommandStoreTransaction; -import com.djrapitops.plugin.logging.L; -import com.djrapitops.plugin.logging.error.ErrorHandler; -import org.spongepowered.api.Sponge; -import org.spongepowered.api.command.CommandMapping; -import org.spongepowered.api.entity.living.player.Player; -import org.spongepowered.api.event.Listener; -import org.spongepowered.api.event.Order; -import org.spongepowered.api.event.command.SendCommandEvent; -import org.spongepowered.api.event.filter.cause.First; - -import javax.inject.Inject; -import java.util.Optional; - -/** - * Listener that keeps track of used commands. - * - * @author Rsl1122 - */ -public class SpongeCommandListener { - - private final PlanConfig config; - private final ServerInfo serverInfo; - private final DBSystem dbSystem; - private final ErrorHandler errorHandler; - - @Inject - public SpongeCommandListener( - PlanConfig config, - ServerInfo serverInfo, - DBSystem dbSystem, - ErrorHandler errorHandler - ) { - this.config = config; - this.serverInfo = serverInfo; - this.dbSystem = dbSystem; - this.errorHandler = errorHandler; - } - - @Listener(order = Order.POST) - public void onPlayerCommand(SendCommandEvent event, @First Player player) { - boolean hasIgnorePermission = player.hasPermission(Permissions.IGNORE_COMMAND_USE.getPermission()); - if (event.isCancelled() || hasIgnorePermission) { - return; - } - try { - actOnCommandEvent(event); - } catch (Exception e) { - errorHandler.log(L.ERROR, this.getClass(), e); - } - } - - private void actOnCommandEvent(SendCommandEvent event) { - String commandName = event.getCommand(); - - boolean logUnknownCommands = config.isTrue(DataGatheringSettings.LOG_UNKNOWN_COMMANDS); - boolean combineCommandAliases = config.isTrue(DataGatheringSettings.COMBINE_COMMAND_ALIASES); - - if (!logUnknownCommands || combineCommandAliases) { - Optional existingCommand = Sponge.getCommandManager().get(commandName); - if (!existingCommand.isPresent()) { - if (!logUnknownCommands) { - return; - } - } else if (combineCommandAliases) { - commandName = existingCommand.get().getPrimaryAlias(); - } - } - dbSystem.getDatabase().executeTransaction(new CommandStoreTransaction(serverInfo.getServerUUID(), commandName)); - } - -} \ No newline at end of file