summaryrefslogtreecommitdiff
path: root/src/main/java/com/keuin/blame
diff options
context:
space:
mode:
authorKeuin <[email protected]>2021-04-21 10:48:16 +0800
committerKeuin <[email protected]>2021-04-21 10:48:16 +0800
commit06a9dfb9690e2013c7222d53412e8acf8170d028 (patch)
treeef3c51920bab4aa16cffe2ad04b7d6445a46adfd /src/main/java/com/keuin/blame
parent6d869d86077f4c8371fb52bb833333f1ca9a6f95 (diff)
Code cleanup
Diffstat (limited to 'src/main/java/com/keuin/blame')
-rw-r--r--src/main/java/com/keuin/blame/Blame.java33
-rw-r--r--src/main/java/com/keuin/blame/EventHandler.java16
-rw-r--r--src/main/java/com/keuin/blame/command/BlameBlockCommand.java2
-rw-r--r--src/main/java/com/keuin/blame/data/entry/LogEntry.java28
-rw-r--r--src/main/java/com/keuin/blame/data/transformer/TransformerManager.java3
-rw-r--r--src/main/java/com/keuin/blame/util/DatabaseUtil.java5
6 files changed, 23 insertions, 64 deletions
diff --git a/src/main/java/com/keuin/blame/Blame.java b/src/main/java/com/keuin/blame/Blame.java
index a4c806d..b14102f 100644
--- a/src/main/java/com/keuin/blame/Blame.java
+++ b/src/main/java/com/keuin/blame/Blame.java
@@ -26,10 +26,11 @@ import java.io.IOException;
import java.io.Reader;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
+import java.util.logging.Logger;
public class Blame implements ModInitializer {
- private static final java.util.logging.Logger logger = java.util.logging.Logger.getLogger(Blame.class.getName());
+ private static final Logger logger = Logger.getLogger(Blame.class.getName());
public static BlameConfig config;
@@ -53,34 +54,6 @@ public class Blame implements ModInitializer {
return true;
}
-
-
- private static void upgradeOldLogEntries() {
-// try (final MongoClient mongoClient = MongoClients.create(DatabaseUtil.CLIENT_SETTINGS)) {
-// final MongoDatabase db = mongoClient.getDatabase(
-// DatabaseUtil.MONGO_CONFIG.getDatabaseName()
-// );
-// final MongoCollection<LogEntry> collection = db.getCollection(
-// DatabaseUtil.MONGO_CONFIG.getLogCollectionName(), LogEntry.class
-// );
-// collection.updateMany()
-// FindIterable<LogEntry> iterable =
-// collection.find(Filters.ne(LogEntryNames.VERSION, TransformerManager.LATEST_VERSION))
-// .showRecordId(true);
-// for (LogEntry logEntry : iterable) {
-// if (logEntry.version > TransformerManager.LATEST_VERSION) {
-// logger.warning("Detected a newer entry in the database! " +
-// "Downgrading of Blame is not supported and may cause " +
-// "unexpected behaviour.");
-// continue;
-// }
-//
-// collection.updateOne(iterable.showRecordId())
-// }
-//
-// }
- }
-
@Override
public void onInitialize() {
// This code runs as soon as Minecraft is in a mod-load-ready state.
@@ -134,7 +107,7 @@ public class Blame implements ModInitializer {
);
commandDispatcher.register(
CommandManager.literal("blame").then(CommandManager.literal("stat")
- .executes(BlameStatCommand::showStat))
+ .executes(BlameStatCommand::showStat))
);
}
});
diff --git a/src/main/java/com/keuin/blame/EventHandler.java b/src/main/java/com/keuin/blame/EventHandler.java
index 4a28a84..fb2df2f 100644
--- a/src/main/java/com/keuin/blame/EventHandler.java
+++ b/src/main/java/com/keuin/blame/EventHandler.java
@@ -64,9 +64,7 @@ public class EventHandler implements AttackEntityHandler, PlaceBlockHandler, Bre
}
lastUseBlockEntry = entry;
SubmitWorker.INSTANCE.submit(entry);
-// PrintUtil.broadcast("use_block; block_id=" + blockId + "; world=" + worldString);
// TODO: 增加判断,事件触发的时候用户不一定真正使用了方块(也可能是无效的动作)。放置方块的时候也会触发这个事件
-// PrintUtil.broadcast(String.format("player %s use block %s", playerEntity.getName().getString(), world.getBlockState(blockHitResult.getBlockPos())));
}
@Override
@@ -82,8 +80,6 @@ public class EventHandler implements AttackEntityHandler, PlaceBlockHandler, Bre
ActionType.BLOCK_PLACE
);
SubmitWorker.INSTANCE.submit(entry);
-// PrintUtil.broadcast(String.format("place_block; world=%s, player_entity=%s, block_pos=%s, block_state=%s, block_entity=%s",
-// world, playerEntity, blockPos, blockState, blockEntity));
}
@Override
@@ -99,8 +95,6 @@ public class EventHandler implements AttackEntityHandler, PlaceBlockHandler, Bre
ActionType.BLOCK_BREAK
);
SubmitWorker.INSTANCE.submit(entry);
-// PrintUtil.broadcast("break_block; block_id=" + blockId + "; world=" + worldString);
-// PrintUtil.broadcast(String.format("player %s break block %s", playerEntity.getName().getString(), blockState));
}
@Override
@@ -116,8 +110,6 @@ public class EventHandler implements AttackEntityHandler, PlaceBlockHandler, Bre
ActionType.ENTITY_ATTACK
);
SubmitWorker.INSTANCE.submit(entry);
-// PrintUtil.broadcast("attack_entity; entity_id=" + entityId);
-// PrintUtil.broadcast(String.format("player %s attack entity %s", playerEntity.getName().getString(), entity));
}
@Override
@@ -155,10 +147,8 @@ public class EventHandler implements AttackEntityHandler, PlaceBlockHandler, Bre
}
lastUseEntityEntry = entry;
SubmitWorker.INSTANCE.submit(entry);
-// PrintUtil.broadcast("use_entity; entity_id=" + entityId);
// TODO: 增加判断,无效的时候也会触发这个事件
- // TODO: 增加cooldown,过滤掉两个相邻重复事件(时间间隔大概为20ms+)
-// PrintUtil.broadcast(String.format("player %s use entity %s", playerEntity.getName().getString(), entity));
+ // TODO: 增加cool down,过滤掉两个相邻重复事件(时间间隔大概为20ms+)
}
@Override
@@ -171,9 +161,7 @@ public class EventHandler implements AttackEntityHandler, PlaceBlockHandler, Bre
ActionType.ITEM_USE
);
SubmitWorker.INSTANCE.submit(entry);
-// PrintUtil.broadcast("use_item; item_id=" + itemId);
- // TODO: 增加cooldown,过滤掉两个相邻重复事件(时间间隔大概为20ms+)
-// PrintUtil.broadcast(String.format("player %s use item %s", playerEntity.getName().getString(), playerEntity.getStackInHand(hand)));
+ // TODO: 增加cool down,过滤掉两个相邻重复事件(时间间隔大概为20ms+)
}
}
diff --git a/src/main/java/com/keuin/blame/command/BlameBlockCommand.java b/src/main/java/com/keuin/blame/command/BlameBlockCommand.java
index 4fdd350..c1702b9 100644
--- a/src/main/java/com/keuin/blame/command/BlameBlockCommand.java
+++ b/src/main/java/com/keuin/blame/command/BlameBlockCommand.java
@@ -14,6 +14,7 @@ import net.minecraft.server.network.ServerPlayerEntity;
import static com.keuin.blame.command.Commands.FAILED;
import static com.keuin.blame.command.Commands.SUCCESS;
+@SuppressWarnings("SameReturnValue")
public class BlameBlockCommand {
public static int blameGivenBlockPos(CommandContext<ServerCommandSource> context) {
@@ -38,6 +39,7 @@ public class BlameBlockCommand {
return SUCCESS;
}
+ // TODO
public static int blameGivenBlockRange(CommandContext<ServerCommandSource> context) {
return SUCCESS;
}
diff --git a/src/main/java/com/keuin/blame/data/entry/LogEntry.java b/src/main/java/com/keuin/blame/data/entry/LogEntry.java
index 77098c5..d12718d 100644
--- a/src/main/java/com/keuin/blame/data/entry/LogEntry.java
+++ b/src/main/java/com/keuin/blame/data/entry/LogEntry.java
@@ -146,20 +146,18 @@ public class LogEntry {
@Override
public String toString() {
- StringBuilder builder = new StringBuilder();
- builder.append("Time: ").append(PrettyUtil.timestampToString(timeMillis)).append("\n");
- builder.append("Subject: ").append(subjectId).append("{").append(subjectUUID).append("}@")
- .append(subjectPos.toString())
- .append("\n");
- builder.append("Action: ").append(actionType.toString()).append("\n");
- builder.append("Object: ").append(objectType.toString()).append("[").append(objectId).append("]@")
- .append(objectPos.toString())
- .append("\n");
- builder.append("(entryVersion: ")
- .append(version)
- .append(", gameVersion:")
- .append(gameVersion)
- .append(")");
- return builder.toString();
+ return "Time: " + PrettyUtil.timestampToString(timeMillis) + "\n" +
+ "Subject: " + subjectId + "{" + subjectUUID + "}@" +
+ subjectPos.toString() +
+ "\n" +
+ "Action: " + actionType.toString() + "\n" +
+ "Object: " + objectType.toString() + "[" + objectId + "]@" +
+ objectPos.toString() +
+ "\n" +
+ "(entryVersion: " +
+ version +
+ ", gameVersion:" +
+ gameVersion +
+ ")";
}
}
diff --git a/src/main/java/com/keuin/blame/data/transformer/TransformerManager.java b/src/main/java/com/keuin/blame/data/transformer/TransformerManager.java
index 645c990..6e8ae11 100644
--- a/src/main/java/com/keuin/blame/data/transformer/TransformerManager.java
+++ b/src/main/java/com/keuin/blame/data/transformer/TransformerManager.java
@@ -8,10 +8,11 @@ import java.util.Objects;
public class TransformerManager {
- public static int LATEST_VERSION = 2;
+ public static final int LATEST_VERSION = 2;
private static final Map<Integer, AbstractLogEntryTransformer> transformerMap = new HashMap<>();
+ @SuppressWarnings("SameParameterValue")
static void setTransformer(int baseVersion, AbstractLogEntryTransformer transformer) {
transformerMap.put(baseVersion, transformer);
}
diff --git a/src/main/java/com/keuin/blame/util/DatabaseUtil.java b/src/main/java/com/keuin/blame/util/DatabaseUtil.java
index d68bc4d..5ffbedf 100644
--- a/src/main/java/com/keuin/blame/util/DatabaseUtil.java
+++ b/src/main/java/com/keuin/blame/util/DatabaseUtil.java
@@ -1,8 +1,5 @@
package com.keuin.blame.util;
-//import ch.qos.logback.classic.Level;
-//import ch.qos.logback.classic.LoggerContext;
-
import com.keuin.blame.Blame;
import com.keuin.blame.config.MongoConfig;
import com.keuin.blame.data.enums.codec.ActionTypeCodec;
@@ -43,7 +40,7 @@ public class DatabaseUtil {
public static void disableMongoSpamming() {
// ((LoggerContext) LoggerFactory.getILoggerFactory()).getLogger("org.mongodb.driver").setLevel(Level.ERROR);
- String[] mongoDrivers = new String[] {"org.mongodb", "org.mongodb.driver", "org.mongodb.driver.cluster", "org.mongodb.driver.connection"};
+ String[] mongoDrivers = new String[]{"org.mongodb", "org.mongodb.driver", "org.mongodb.driver.cluster", "org.mongodb.driver.connection"};
for (String driverName : mongoDrivers) {
Logger mongoLogger = Logger.getLogger(driverName);
mongoLogger.setLevel(Level.OFF); // Plz be silent, my boy.