diff options
author | Keuin <[email protected]> | 2020-12-26 12:48:28 +0800 |
---|---|---|
committer | Keuin <[email protected]> | 2020-12-26 12:48:28 +0800 |
commit | 55715b8b3fc8705e6eecbf835c8d441d3503fa7d (patch) | |
tree | 5ce4fe5e32219e8289bb61e18bc416d594cc0e79 | |
parent | 5adc0672b731970f75603b6bc386b731dcabe921 (diff) |
fix mongo spamming
-rw-r--r-- | build.gradle | 3 | ||||
-rw-r--r-- | gradle.properties | 2 | ||||
-rw-r--r-- | src/main/java/com/keuin/blame/Blame.java | 20 | ||||
-rw-r--r-- | src/main/java/com/keuin/blame/data/transformer/TransformerManager.java | 4 |
4 files changed, 24 insertions, 5 deletions
diff --git a/build.gradle b/build.gradle index 0a43752..0b12a78 100644 --- a/build.gradle +++ b/build.gradle @@ -14,7 +14,10 @@ dependencies { implementation 'junit:junit:4.12' implementation 'org.mongodb:mongo-java-driver:3.12.7' + implementation 'ch.qos.logback:logback-classic:1.2.3' include 'org.mongodb:mongo-java-driver:3.12.7' + include 'ch.qos.logback:logback-classic:1.2.3' + // To change the versions see the gradle.properties file minecraft "com.mojang:minecraft:${project.minecraft_version}" diff --git a/gradle.properties b/gradle.properties index 0026514..f57ba94 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,7 +6,7 @@ minecraft_version=1.16.4 yarn_mappings=1.16.4+build.6 loader_version=0.10.6+build.214 # Mod Properties -mod_version=1.2.1-alpha +mod_version=1.2.2-alpha maven_group=com.keuin.blame archives_base_name=blame-fabric # Dependencies diff --git a/src/main/java/com/keuin/blame/Blame.java b/src/main/java/com/keuin/blame/Blame.java index f620f73..744d920 100644 --- a/src/main/java/com/keuin/blame/Blame.java +++ b/src/main/java/com/keuin/blame/Blame.java @@ -18,6 +18,8 @@ import net.fabricmc.fabric.api.event.player.*; import net.minecraft.server.MinecraftServer; import net.minecraft.server.command.CommandManager; import net.minecraft.server.command.ServerCommandSource; +import org.apache.logging.log4j.core.LoggerContext; +import org.slf4j.LoggerFactory; import java.io.File; import java.io.IOException; @@ -55,7 +57,9 @@ public class Blame implements ModInitializer { private static void disableMongoSpamming() { Logger mongoLogger = Logger.getLogger("org.mongodb.driver"); - mongoLogger.setLevel(Level.WARNING); + mongoLogger.setLevel(Level.SEVERE); + ((LoggerContext) LoggerFactory.getILoggerFactory()).getLogger("org.mongodb.driver") + .setLevel(org.apache.logging.log4j.Level.ERROR); } private static void upgradeOldLogEntries() { @@ -66,11 +70,19 @@ public class Blame implements ModInitializer { // 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)); -// List<LogEntry> +// collection.find(Filters.ne(LogEntryNames.VERSION, TransformerManager.LATEST_VERSION)) +// .showRecordId(true); // for (LogEntry logEntry : iterable) { -// iterable.batchSize(100). +// 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()) // } // // } 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 e4db239..645c990 100644 --- a/src/main/java/com/keuin/blame/data/transformer/TransformerManager.java +++ b/src/main/java/com/keuin/blame/data/transformer/TransformerManager.java @@ -4,6 +4,7 @@ import com.keuin.blame.data.entry.LogEntry; import java.util.HashMap; import java.util.Map; +import java.util.Objects; public class TransformerManager { @@ -20,6 +21,9 @@ public class TransformerManager { } public static Object transformTo(int targetVersion, LogEntry baseEntry) { + Objects.requireNonNull(baseEntry); + if (baseEntry.version > targetVersion) + throw new RuntimeException("Downgrade is not supported."); LogEntry entry = baseEntry; for (int currentVersion = baseEntry.version; currentVersion != targetVersion; ++currentVersion) entry = transformerMap.get(currentVersion + 1).transform(entry); |