From d353a4c46ac5a78337389d07d5847777d55fcecf Mon Sep 17 00:00:00 2001
From: Jason Penilla <11360596+jpenilla@users.noreply.github.com>
Date: Thu, 22 Jun 2023 18:09:44 -0700
Subject: [PATCH] 1.20.1
---
build.gradle.kts | 7 ++-
settings.gradle.kts | 3 ++
.../paper/console/HexFormattingConverter.java | 9 ++--
.../BetterFabricConsole.java | 23 +-------
.../LoggingComponentSerializerHolder.java | 31 -----------
.../configuration/Config.java | 7 ---
.../console/MinecraftCommandCompleter.java | 20 +++----
.../mixin/DedicatedServerMixin.java | 22 ++------
.../FabricComponentLoggerProviderMixin.java | 53 -------------------
.../better-fabric-console.mixins.json | 1 -
src/main/resources/fabric.mod.json | 2 +-
11 files changed, 27 insertions(+), 151 deletions(-)
delete mode 100644 src/main/java/xyz/jpenilla/betterfabricconsole/adventure/LoggingComponentSerializerHolder.java
delete mode 100644 src/main/java/xyz/jpenilla/betterfabricconsole/mixin/FabricComponentLoggerProviderMixin.java
diff --git a/build.gradle.kts b/build.gradle.kts
index 6b7065c..053039c 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -11,13 +11,13 @@ version = "1.1.5-SNAPSHOT"
group = "xyz.jpenilla"
description = "Server-side Fabric mod enhancing the console with tab completions, colored log output, command syntax highlighting, command history, and more."
-val minecraftVersion = "1.19.4"
+val minecraftVersion = "1.20.1"
dependencies {
minecraft("com.mojang", "minecraft", minecraftVersion)
mappings(loom.officialMojangMappings())
modImplementation("net.fabricmc", "fabric-loader", "0.14.21")
- modImplementation("net.fabricmc.fabric-api", "fabric-api", "0.83.0+1.19.4")
+ modImplementation("net.fabricmc.fabric-api", "fabric-api", "0.83.0+1.20.1")
annotationProcessor("org.apache.logging.log4j", "log4j-core", "2.17.1")
@@ -27,8 +27,7 @@ dependencies {
implementation(include("org.fusesource.jansi", "jansi", "2.4.0"))
- modImplementation(include("net.kyori", "adventure-platform-fabric", "5.8.0"))
- implementation(include("net.kyori", "adventure-text-serializer-legacy", "4.13.1"))
+ modImplementation(include("net.kyori", "adventure-platform-fabric", "5.10.0-SNAPSHOT"))
implementation(include("com.typesafe:config:1.4.2")!!)
implementation(include("io.leangen.geantyref:geantyref:1.3.13")!!)
diff --git a/settings.gradle.kts b/settings.gradle.kts
index 8ca0224..8711040 100644
--- a/settings.gradle.kts
+++ b/settings.gradle.kts
@@ -8,6 +8,9 @@ dependencyResolutionManagement {
maven("https://oss.sonatype.org/content/repositories/snapshots/") {
mavenContent { snapshotsOnly() }
}
+ maven("https://repo.jpenilla.xyz/snapshots/") {
+ mavenContent { snapshotsOnly() }
+ }
}
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
}
diff --git a/src/main/java/io/papermc/paper/console/HexFormattingConverter.java b/src/main/java/io/papermc/paper/console/HexFormattingConverter.java
index 6da7860..a24c656 100644
--- a/src/main/java/io/papermc/paper/console/HexFormattingConverter.java
+++ b/src/main/java/io/papermc/paper/console/HexFormattingConverter.java
@@ -4,6 +4,7 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import net.kyori.adventure.text.format.NamedTextColor;
+import net.kyori.ansi.ColorLevel;
import org.apache.logging.log4j.core.LogEvent;
import org.apache.logging.log4j.core.config.Configuration;
import org.apache.logging.log4j.core.config.plugins.Plugin;
@@ -15,10 +16,11 @@
import org.apache.logging.log4j.core.pattern.PatternParser;
import org.apache.logging.log4j.util.PerformanceSensitive;
import org.apache.logging.log4j.util.PropertiesUtil;
-import xyz.jpenilla.betterfabricconsole.BetterFabricConsolePreLaunch;
/**
* Modified version of Paper's HexFormattingConverter to work with Kyori 'ยง#rrggbb' format
+ *
+ *
"Deprecated", but kept around for some mods and datapacks that still log legacy codes.
*/
@Plugin(name = "paperMinecraftFormatting", category = PatternConverter.CATEGORY)
@ConverterKeys({"paperMinecraftFormatting"})
@@ -115,7 +117,7 @@ public void format(LogEvent event, StringBuilder toAppendTo) {
return;
}
- boolean useAnsi = ansi;/* && TerminalConsoleAppender.isAnsiSupported();*/
+ boolean useAnsi = ansi && ColorLevel.compute() != ColorLevel.NONE;
String content = toAppendTo.substring(start);
content = useAnsi ? convertRGBColors(content) : stripRGBColors(content);
format(content, toAppendTo, start, useAnsi);
@@ -170,8 +172,7 @@ static void format(String content, StringBuilder result, int start, boolean ansi
}
private static String[] ansiCodes() {
- final boolean rgb = BetterFabricConsolePreLaunch.instanceOrNull() == null
- || BetterFabricConsolePreLaunch.instance().config().useRgbForNamedTextColors();
+ final boolean rgb = ColorLevel.compute() == ColorLevel.TRUE_COLOR;
return rgb ? RGB_ANSI_CODES : ANSI_ANSI_CODES;
}
diff --git a/src/main/java/xyz/jpenilla/betterfabricconsole/BetterFabricConsole.java b/src/main/java/xyz/jpenilla/betterfabricconsole/BetterFabricConsole.java
index b4fbeb0..3c01b07 100644
--- a/src/main/java/xyz/jpenilla/betterfabricconsole/BetterFabricConsole.java
+++ b/src/main/java/xyz/jpenilla/betterfabricconsole/BetterFabricConsole.java
@@ -27,11 +27,9 @@
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.logging.LogUtils;
-import java.util.function.Function;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
-import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.TextColor;
import net.minecraft.DefaultUncaughtExceptionHandler;
import net.minecraft.commands.CommandBuildContext;
@@ -40,10 +38,8 @@
import net.minecraft.server.dedicated.DedicatedServer;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
import org.checkerframework.checker.nullness.qual.NonNull;
-import org.checkerframework.checker.nullness.qual.Nullable;
import org.checkerframework.framework.qual.DefaultQualifier;
import org.slf4j.Logger;
-import xyz.jpenilla.betterfabricconsole.adventure.LoggingComponentSerializerHolder;
import xyz.jpenilla.betterfabricconsole.configuration.Config;
import xyz.jpenilla.betterfabricconsole.console.ConsoleState;
import xyz.jpenilla.betterfabricconsole.console.ConsoleThread;
@@ -63,17 +59,11 @@ public final class BetterFabricConsole implements ModInitializer {
private static final TextColor PINK = color(0xFF79C6);
private static @MonotonicNonNull BetterFabricConsole INSTANCE;
- private volatile @Nullable DedicatedServer server;
-
@Override
public void onInitialize() {
INSTANCE = this;
CommandRegistrationCallback.EVENT.register(this::registerCommands);
- ServerLifecycleEvents.SERVER_STARTING.register(server -> {
- this.server = (DedicatedServer) server;
- this.initConsoleThread((DedicatedServer) server);
- });
- ServerLifecycleEvents.SERVER_STOPPED.register(server -> this.server = null);
+ ServerLifecycleEvents.SERVER_STARTING.register(server -> this.initConsoleThread((DedicatedServer) server));
}
private void initConsoleThread(final DedicatedServer server) {
@@ -109,17 +99,6 @@ public Config config() {
return BetterFabricConsolePreLaunch.INSTANCE.config;
}
- public @Nullable Function loggingComponentSerializer() {
- if (this.server == null) {
- return null;
- }
- return ((LoggingComponentSerializerHolder) this.server).loggingComponentSerializer();
- }
-
- public static @Nullable BetterFabricConsole instanceOrNull() {
- return INSTANCE;
- }
-
public static BetterFabricConsole instance() {
if (INSTANCE == null) {
throw new IllegalStateException("Better Fabric Console has not yet been initialized!");
diff --git a/src/main/java/xyz/jpenilla/betterfabricconsole/adventure/LoggingComponentSerializerHolder.java b/src/main/java/xyz/jpenilla/betterfabricconsole/adventure/LoggingComponentSerializerHolder.java
deleted file mode 100644
index 13c6d06..0000000
--- a/src/main/java/xyz/jpenilla/betterfabricconsole/adventure/LoggingComponentSerializerHolder.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * This file is part of Better Fabric Console, licensed under the MIT License.
- *
- * Copyright (c) 2021-2022 Jason Penilla
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-package xyz.jpenilla.betterfabricconsole.adventure;
-
-import java.util.function.Function;
-import net.kyori.adventure.text.Component;
-
-public interface LoggingComponentSerializerHolder {
- Function loggingComponentSerializer();
-}
diff --git a/src/main/java/xyz/jpenilla/betterfabricconsole/configuration/Config.java b/src/main/java/xyz/jpenilla/betterfabricconsole/configuration/Config.java
index 2b7877d..867c46f 100644
--- a/src/main/java/xyz/jpenilla/betterfabricconsole/configuration/Config.java
+++ b/src/main/java/xyz/jpenilla/betterfabricconsole/configuration/Config.java
@@ -70,19 +70,12 @@ public StyleColor[] highlightColors() {
return this.highlightColors;
}
- @Comment("If true, the RGB color code for NamedTextColors will be used in console. If false, NamedTextColors will use the ANSI color code counterpart, allowing for the console color scheme to effect them.")
- private boolean useRgbForNamedTextColors = true;
-
@Comment("Whether to log commands executed by players to console.")
private boolean logPlayerExecutedCommands = true;
@Comment("Controls whether logger names and stacktraces should be left in intermediary mappings (NONE), remapped to Mojang mappings (MOJANG), or to Yarn mappings (YARN).")
private RemapMode remapMode = RemapMode.MOJANG;
- public boolean useRgbForNamedTextColors() {
- return this.useRgbForNamedTextColors;
- }
-
public boolean logPlayerExecutedCommands() {
return this.logPlayerExecutedCommands;
}
diff --git a/src/main/java/xyz/jpenilla/betterfabricconsole/console/MinecraftCommandCompleter.java b/src/main/java/xyz/jpenilla/betterfabricconsole/console/MinecraftCommandCompleter.java
index fc28e72..939de95 100644
--- a/src/main/java/xyz/jpenilla/betterfabricconsole/console/MinecraftCommandCompleter.java
+++ b/src/main/java/xyz/jpenilla/betterfabricconsole/console/MinecraftCommandCompleter.java
@@ -23,14 +23,17 @@
*/
package xyz.jpenilla.betterfabricconsole.console;
-import com.mojang.brigadier.Message;
import com.mojang.brigadier.ParseResults;
import com.mojang.brigadier.StringReader;
import com.mojang.brigadier.suggestion.Suggestion;
import com.mojang.brigadier.suggestion.Suggestions;
import java.util.List;
+import java.util.Optional;
import java.util.concurrent.CompletableFuture;
+import net.kyori.adventure.text.serializer.ansi.ANSIComponentSerializer;
import net.minecraft.commands.CommandSourceStack;
+import net.minecraft.network.chat.Component;
+import net.minecraft.network.chat.ComponentUtils;
import net.minecraft.server.MinecraftServer;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
@@ -56,14 +59,13 @@ public void complete(final LineReader reader, final ParsedLine line, final List<
continue;
}
- final Message suggestionTooltip = suggestion.getTooltip();
- final @Nullable String description;
- if (suggestionTooltip == null) {
- description = null;
- } else {
- final String tooltipString = suggestionTooltip.getString();
- description = tooltipString.isEmpty() ? null : tooltipString;
- }
+ final @Nullable String description = Optional.ofNullable(suggestion.getTooltip())
+ .map(tooltip -> {
+ final Component tooltipComponent = ComponentUtils.fromMessage(tooltip);
+ return tooltipComponent.equals(Component.empty()) ? null : tooltipComponent.asComponent();
+ })
+ .map(adventure -> ANSIComponentSerializer.ansi().serialize(adventure))
+ .orElse(null);
candidates.add(new Candidate(
suggestionText,
diff --git a/src/main/java/xyz/jpenilla/betterfabricconsole/mixin/DedicatedServerMixin.java b/src/main/java/xyz/jpenilla/betterfabricconsole/mixin/DedicatedServerMixin.java
index eeb8194..c2b685b 100644
--- a/src/main/java/xyz/jpenilla/betterfabricconsole/mixin/DedicatedServerMixin.java
+++ b/src/main/java/xyz/jpenilla/betterfabricconsole/mixin/DedicatedServerMixin.java
@@ -25,9 +25,7 @@
import com.mojang.datafixers.DataFixer;
import java.net.Proxy;
-import java.util.function.Function;
-import net.kyori.adventure.platform.fabric.FabricServerAudiences;
-import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
+import net.kyori.adventure.text.serializer.ansi.ANSIComponentSerializer;
import net.minecraft.network.chat.Component;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.Services;
@@ -41,31 +39,17 @@
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
-import xyz.jpenilla.betterfabricconsole.adventure.LoggingComponentSerializerHolder;
@Mixin(DedicatedServer.class)
-abstract class DedicatedServerMixin extends MinecraftServer implements LoggingComponentSerializerHolder {
+abstract class DedicatedServerMixin extends MinecraftServer {
@Final @Shadow static Logger LOGGER;
- private final FabricServerAudiences audiences = FabricServerAudiences.of(this);
- private final LegacyComponentSerializer legacySerializer = LegacyComponentSerializer.builder()
- .flattener(this.audiences.flattener())
- .hexColors()
- .character(LegacyComponentSerializer.SECTION_CHAR)
- .hexCharacter(LegacyComponentSerializer.HEX_CHAR)
- .build();
-
DedicatedServerMixin(final Thread thread, final LevelStorageSource.LevelStorageAccess levelStorageAccess, final PackRepository packRepository, final WorldStem worldStem, final Proxy proxy, final DataFixer dataFixer, final Services services, final ChunkProgressListenerFactory chunkProgressListenerFactory) {
super(thread, levelStorageAccess, packRepository, worldStem, proxy, dataFixer, services, chunkProgressListenerFactory);
}
- @Override
- public Function loggingComponentSerializer() {
- return this.legacySerializer::serialize;
- }
-
@Override
public void sendSystemMessage(final @NonNull Component component) {
- LOGGER.info(this.legacySerializer.serialize(component.asComponent()));
+ LOGGER.info(ANSIComponentSerializer.ansi().serialize(component.asComponent()));
}
}
diff --git a/src/main/java/xyz/jpenilla/betterfabricconsole/mixin/FabricComponentLoggerProviderMixin.java b/src/main/java/xyz/jpenilla/betterfabricconsole/mixin/FabricComponentLoggerProviderMixin.java
deleted file mode 100644
index 64c33ed..0000000
--- a/src/main/java/xyz/jpenilla/betterfabricconsole/mixin/FabricComponentLoggerProviderMixin.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * This file is part of Better Fabric Console, licensed under the MIT License.
- *
- * Copyright (c) 2021-2022 Jason Penilla
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-package xyz.jpenilla.betterfabricconsole.mixin;
-
-import java.util.Locale;
-import java.util.function.Function;
-import net.kyori.adventure.platform.fabric.impl.service.FabricComponentLoggerProvider;
-import net.kyori.adventure.text.Component;
-import net.kyori.adventure.translation.GlobalTranslator;
-import org.checkerframework.checker.nullness.qual.Nullable;
-import org.spongepowered.asm.mixin.Mixin;
-import org.spongepowered.asm.mixin.injection.At;
-import org.spongepowered.asm.mixin.injection.Inject;
-import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
-import xyz.jpenilla.betterfabricconsole.BetterFabricConsole;
-
-@Mixin(value = FabricComponentLoggerProvider.class, remap = false)
-abstract class FabricComponentLoggerProviderMixin {
- @Inject(method = "serialize", at = @At(value = "HEAD"), cancellable = true)
- private void formattedLogString(final Component message, final CallbackInfoReturnable cir) {
- final @Nullable BetterFabricConsole betterFabricConsole = BetterFabricConsole.instanceOrNull();
- if (betterFabricConsole == null) {
- return;
- }
- final @Nullable Function serializer = betterFabricConsole.loggingComponentSerializer();
- if (serializer == null) {
- return;
- }
- final Component rendered = GlobalTranslator.render(message, Locale.getDefault());
- cir.setReturnValue(serializer.apply(rendered));
- }
-}
diff --git a/src/main/resources/better-fabric-console.mixins.json b/src/main/resources/better-fabric-console.mixins.json
index 369bbc7..2ac423e 100644
--- a/src/main/resources/better-fabric-console.mixins.json
+++ b/src/main/resources/better-fabric-console.mixins.json
@@ -10,7 +10,6 @@
"server": [
"DedicatedServerConsoleThreadMixin",
"DedicatedServerMixin",
- "FabricComponentLoggerProviderMixin",
"FabricServerAudiencesImplMixin",
"ServerGamePacketListenerImplMixin"
],
diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json
index 330ab17..884a706 100644
--- a/src/main/resources/fabric.mod.json
+++ b/src/main/resources/fabric.mod.json
@@ -29,7 +29,7 @@
"depends": {
"fabricloader": ">=0.14.6",
"fabric": "*",
- "minecraft": "1.19.x",
+ "minecraft": "1.20.x",
"adventure-platform-fabric": "*"
}
}