diff options
author | Keuin <[email protected]> | 2023-10-21 20:22:30 +0800 |
---|---|---|
committer | Keuin <[email protected]> | 2023-10-21 20:22:30 +0800 |
commit | 2b176ff0fb9b992d2fc6225e6476fa85c9fd7581 (patch) | |
tree | 43aac2ac1f3f236de0a2a09fdd7c77dfeeb24d8b /src/main/java/com/keuin | |
parent | 8f9112896de4acd84def9b030500875aa6480c57 (diff) |
remove stat command
Diffstat (limited to 'src/main/java/com/keuin')
-rw-r--r-- | src/main/java/com/keuin/blame/Blame.java | 5 | ||||
-rw-r--r-- | src/main/java/com/keuin/blame/command/BlameStatCommand.java | 105 |
2 files changed, 0 insertions, 110 deletions
diff --git a/src/main/java/com/keuin/blame/Blame.java b/src/main/java/com/keuin/blame/Blame.java index 23a1830..4031e65 100644 --- a/src/main/java/com/keuin/blame/Blame.java +++ b/src/main/java/com/keuin/blame/Blame.java @@ -6,7 +6,6 @@ import com.keuin.blame.adapter.handler.EndGatewayTeleportHandler; import com.keuin.blame.adapter.handler.PlaceBlockHandler; import com.keuin.blame.command.BlameBlockCommand; import com.keuin.blame.command.BlameLimitCommand; -import com.keuin.blame.command.BlameStatCommand; import com.keuin.blame.config.BlameConfig; import com.keuin.blame.lookup.QueryExecutor; import com.keuin.blame.util.PrintUtil; @@ -127,10 +126,6 @@ public class Blame implements ModInitializer { .then(CommandManager.argument("limit", IntegerArgumentType.integer(1, 255)) .executes(BlameLimitCommand::setLimit))) ); - commandDispatcher.register( - CommandManager.literal("blame").then(CommandManager.literal("stat") - .executes(BlameStatCommand::showStat)) - ); }); } } diff --git a/src/main/java/com/keuin/blame/command/BlameStatCommand.java b/src/main/java/com/keuin/blame/command/BlameStatCommand.java deleted file mode 100644 index 34c3faf..0000000 --- a/src/main/java/com/keuin/blame/command/BlameStatCommand.java +++ /dev/null @@ -1,105 +0,0 @@ -package com.keuin.blame.command; - -import com.google.common.base.Strings; -import com.keuin.blame.data.entry.LogEntry; -import com.keuin.blame.util.DatabaseUtil; -import com.keuin.blame.util.PrintUtil; -import com.mojang.brigadier.context.CommandContext; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.util.Formatting; -import org.jetbrains.annotations.Nullable; - -import java.util.*; -import java.util.logging.Logger; - -public class BlameStatCommand { - - private static final Logger logger = Logger.getLogger(BlameStatCommand.class.getName()); - - public static int showStat(CommandContext<ServerCommandSource> context) { - PrintUtil.message(context, Formatting.ITALIC, "Collecting statistics. This may take a few seconds..."); - showStat(stat -> { - PrintUtil.Printer sb = PrintUtil.newPrinter(); - if (stat != null) { - sb.append("Logs grouped by subjects:").newline(); - boolean isFirst = true; - for (Map.Entry<String, Long> entry : stat.getCountMap().entrySet()) { - if (!isFirst) - sb.newline(); - isFirst = false; - final String subjectId = entry.getKey(); - final long count = entry.getValue(); - sb.append(Formatting.YELLOW, Optional.ofNullable(Strings.emptyToNull(subjectId)).orElse("null")) - .append(": ").append(count); - } - } else { - sb.append(Formatting.RED, "Failed to get statistics. Please refer to server log for more information."); - } - sb.sendTo(context); - }); - return Commands.SUCCESS; - } - - public static void showStat(ShowStatCallback callback) { - Objects.requireNonNull(callback); - new Thread(new Runnable() { - @Override - public void run() { - logger.info("Collecting statistics..."); -// try (final MongoClient mongoClient = MongoClients.create(DatabaseUtil.CLIENT_SETTINGS)) { -// final MongoDatabase db = mongoClient.getDatabase( -// DatabaseUtil.DB_CONFIG.getDatabaseName() -// ); -// final MongoCollection<LogEntry> collection = db.getCollection( -// DatabaseUtil.DB_CONFIG.getTableName(), LogEntry.class -// ); -// Collection<String> ids = VersionedLogEntryHelper.getLoggedSubjectsId(collection); -// -// // count by distinct subjects -// Map<String, Long> countMap = new HashMap<>(); -// for (String subjectId : ids) { -// long count = VersionedLogEntryHelper.countBySubjectId(collection, subjectId); -// countMap.put(subjectId, count); -// } -// -// // invoke callback -// callback.showStat(new BlameStat(countMap)); -// } catch (MongoClientException exception) { -// logger.severe("Failed when querying the database: " + exception + -// ". Failed to get statistics."); -// callback.showStat(null); -// } - } - }, "BlameStatCommandThread").start(); - } - - public static class BlameStat { - private final Map<String, Long> countMap; - - public BlameStat(Map<String, Long> countMap) { - this.countMap = countMap; - } - - public Map<String, Long> getCountMap() { - return Collections.unmodifiableMap(countMap); - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - BlameStat blameStat = (BlameStat) o; - return Objects.equals(countMap, blameStat.countMap); - } - - @Override - public int hashCode() { - return Objects.hash(countMap); - } - } - - public interface ShowStatCallback { - void showStat(@Nullable BlameStat stat); - } - -} |