Deleted Command usage related code

This commit is contained in:
Rsl1122 2019-09-21 12:51:56 +03:00
parent 826faa1b1a
commit dd6f2a1e30
22 changed files with 9 additions and 603 deletions

View File

@ -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())));
}
});
}

View File

@ -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
);

View File

@ -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 <https://www.gnu.org/licenses/>.
*/
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;
}
}

View File

@ -58,6 +58,7 @@ public class ServerKeys {
public static final Key<List<TPS>> TPS = new Key<>(new Type<List<TPS>>() {}, "tps");
public static final Key<DateObj<Integer>> ALL_TIME_PEAK_PLAYERS = new Key<>(new Type<DateObj<Integer>>() {}, "all_time_peak_players");
public static final Key<DateObj<Integer>> RECENT_PEAK_PLAYERS = new Key<>(new Type<DateObj<Integer>>() {}, "recent_peak_players");
@Deprecated
public static final Key<Map<String, Integer>> COMMAND_USAGE = new Key<>(new Type<Map<String, Integer>>() {}, "command_usage");
public static final Key<List<ExtensionData>> EXTENSION_DATA = new Key<>(new Type<List<ExtensionData>>() {}, "extension_data");
}

View File

@ -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 <https://www.gnu.org/licenses/>.
*/
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.
* <p>
* Can be used to easily get different values about the map.
*
* @author Rsl1122
*/
public class CommandUseMutator {
private Map<String, Integer> commandUsage;
public CommandUseMutator(Map<String, Integer> 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;
}
}

View File

@ -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<String, Integer> commandUsages;
private List<TPS> tpsData;
private ServerImportData(Map<String, Integer> commandUsages, List<TPS> tpsData) {
this.commandUsages = commandUsages;
private ServerImportData(List<TPS> tpsData) {
this.tpsData = tpsData;
}
@ -38,14 +39,6 @@ public class ServerImportData {
return new ServerImportDataBuilder();
}
public Map<String, Integer> getCommandUsages() {
return commandUsages;
}
public void setCommandUsages(Map<String, Integer> commandUsages) {
this.commandUsages = commandUsages;
}
public List<TPS> getTpsData() {
return tpsData;
}
@ -55,23 +48,12 @@ public class ServerImportData {
}
public static final class ServerImportDataBuilder {
private final Map<String, Integer> commandUsages = new HashMap<>();
private final List<TPS> 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<String, Integer> 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);
}
}
}

View File

@ -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.
*

View File

@ -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<Map<UUID, Map<String, Integer>>> 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<Map<UUID, Map<String, Integer>>>(sql, 10000) {
@Override
public Map<UUID, Map<String, Integer>> processResults(ResultSet set) throws SQLException {
Map<UUID, Map<String, Integer>> map = new HashMap<>();
while (set.next()) {
UUID serverUUID = UUID.fromString(set.getString("s_uuid"));
Map<String, Integer> 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.
*

View File

@ -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<UUID, Map<String, Integer>> 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<UUID, Map<String, Integer>> serverEntry : ofServers.entrySet()) {
UUID serverUUID = serverEntry.getKey();
// Every Command
for (Map.Entry<String, Integer> 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.
*

View File

@ -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<Map<String, Integer>> 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<Map<String, Integer>>(sql, 5000) {
@Override
public void prepare(PreparedStatement statement) throws SQLException {
statement.setString(1, serverUUID.toString());
}
@Override
public Map<String, Integer> processResults(ResultSet set) throws SQLException {
Map<String, Integer> 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;
}
};
}
}

View File

@ -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<ServerContainer> {
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

View File

@ -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();
}
}

View File

@ -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());
}

View File

@ -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);

View File

@ -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 <https://www.gnu.org/licenses/>.
*/
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));
}
}

View File

@ -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));

View File

@ -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";

View File

@ -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());
}

View File

@ -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);

View File

@ -146,56 +146,6 @@ public interface DatabaseTest {
db().init();
}
@Test
default void testSaveCommandUse() {
Map<String, Integer> 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<String, Integer> commandUse = db().query(ServerAggregateQueries.commandUsageCounts(serverUUID()));
assertEquals(expected, commandUse);
}
@Test
default void commandUsageSavingDoesNotCreateNewEntriesForOldCommands() {
Map<String, Integer> 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<String, Integer> 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<TPS> 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());

View File

@ -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,

View File

@ -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 <https://www.gnu.org/licenses/>.
*/
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<? extends CommandMapping> 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));
}
}