Compare commits

..

No commits in common. "dev" and "v1.0.0" have entirely different histories.
dev ... v1.0.0

22 changed files with 92 additions and 200 deletions

2
.gitattributes vendored
View File

@ -4,7 +4,7 @@
# Linux start script should use lf # Linux start script should use lf
/gradlew text eol=lf /gradlew text eol=lf
* text=auto eol=lf * test=auto eol=lf
# These are Windows script files and should use crlf # These are Windows script files and should use crlf
*.bat text eol=crlf *.bat text eol=crlf

View File

@ -11,13 +11,13 @@ jobs:
runs-on: ubuntu-24.04 runs-on: ubuntu-24.04
steps: steps:
- name: checkout repository - name: checkout repository
uses: actions/checkout@v6 uses: actions/checkout@v4
- name: validate gradle wrapper - name: validate gradle wrapper
uses: gradle/actions/wrapper-validation@v6 uses: gradle/actions/wrapper-validation@v4
- name: setup jdk - name: setup jdk
uses: actions/setup-java@v5 uses: actions/setup-java@v4
with: with:
java-version: '25' java-version: '21'
distribution: 'microsoft' distribution: 'microsoft'
- name: make gradle wrapper executable - name: make gradle wrapper executable
run: chmod +x ./gradlew run: chmod +x ./gradlew

View File

@ -1,6 +1,6 @@
# Chat Plus # Chat Plus
![Static Badge](https://img.shields.io/badge/Minecraft_version-1.19%2B_%7C_1.20%2B_%7C_1.21%2B_%7C_26.1%2B-red?style=flat) ![Static Badge](https://img.shields.io/badge/Minecraft_version-1.19%2B_%7C_1.20%2B_%7C_1.21%2B-red?style=flat)
<a href="https://modrinth.com/mod/chatplus"> <a href="https://modrinth.com/mod/chatplus">
<img src="https://img.shields.io/badge/Modrinth-Chat_Plus-%234e910e?style=flat" /> <img src="https://img.shields.io/badge/Modrinth-Chat_Plus-%234e910e?style=flat" />
</a> </a>
@ -42,8 +42,7 @@ _* Other mods may work without explicit support. Report compatibility requests v
| 1.19.3 | 1.19.3 - 1.19.4 | | 1.19.3 | 1.19.3 - 1.19.4 |
| 1.20 | 1.20 - 1.20.2 | | 1.20 | 1.20 - 1.20.2 |
| 1.20.3 | 1.20.3 - 1.20.6 | | 1.20.3 | 1.20.3 - 1.20.6 |
| 1.21 | 1.21 - 1.21.11 | | 1.21 | 1.21 - 1.21.5 |
| 26.1 | 26.1 - 26.1.2 |
@ -51,7 +50,7 @@ _* Other mods may work without explicit support. Report compatibility requests v
#### Environment #### Environment
- Java 25 or higher - Java 21 or higher
- (Optional) Java IDE with Manifold support (e.g., IntelliJ IDEA)<br> - (Optional) Java IDE with Manifold support (e.g., IntelliJ IDEA)<br>
_* If using IntelliJ IDEA, the Manifold plugin should be installed_ _* If using IntelliJ IDEA, the Manifold plugin should be installed_

View File

@ -2,8 +2,7 @@ import org.gradle.nativeplatform.platform.internal.DefaultNativePlatform
import java.nio.file.Paths import java.nio.file.Paths
plugins { plugins {
id "net.fabricmc.fabric-loom-remap" version "1.16-SNAPSHOT" apply false id "fabric-loom" version "1.10-SNAPSHOT"
id "net.fabricmc.fabric-loom" version "1.16-SNAPSHOT" apply false
id "maven-publish" id "maven-publish"
// Manifold preprocessor // Manifold preprocessor
@ -13,13 +12,6 @@ plugins {
// Transfer gradle extra properties to root project extra properties // Transfer gradle extra properties to root project extra properties
gradle.ext.properties.each { prop -> project.ext.set(prop.key, prop.value) } gradle.ext.properties.each { prop -> project.ext.set(prop.key, prop.value) }
def loomRemapStr = project.findProperty("fabric_loom_remap")?.toString()
assert loomRemapStr in ["true", "false"] :
"${loomRemapStr == null ? "Missing" : "Invalid"} property in ${Paths.get(version_properties_path, "${project.targetVersion}.properties")} : " +
"fabric_loom_remap${loomRemapStr == null ? "" : "=$loomRemapStr"}"
def loomRemap = loomRemapStr.toBoolean()
apply plugin: loomRemap ? "net.fabricmc.fabric-loom-remap" : "net.fabricmc.fabric-loom"
generateBuildProperties(project.minecraftVersions, project.targetVersion) generateBuildProperties(project.minecraftVersions, project.targetVersion)
version = "${project.mod_version}-mc${project.targetVersion}" version = "${project.mod_version}-mc${project.targetVersion}"
@ -72,40 +64,24 @@ loom {
// } // }
} }
configurations {
remappableImplementation
remappableCompileOnly
remappableLocalRuntime
}
if (loomRemap) {
configurations.modImplementation.extendsFrom(configurations.remappableImplementation)
configurations.modCompileOnly.extendsFrom(configurations.remappableCompileOnly)
configurations.modLocalRuntime.extendsFrom(configurations.remappableLocalRuntime)
} else {
configurations.implementation.extendsFrom(configurations.remappableImplementation)
configurations.compileOnly.extendsFrom(configurations.remappableCompileOnly)
configurations.localRuntime.extendsFrom(configurations.remappableLocalRuntime)
}
dependencies { dependencies {
// To change the versions see the gradle.properties file or the ./properties/${minecraftVersion}.properties file // To change the versions see the gradle.properties file or the ./properties/${minecraftVersion}.properties file
minecraft "com.mojang:minecraft:${project.minecraft_version}" minecraft "com.mojang:minecraft:${project.minecraft_version}"
if (loomRemap) mappings loom.officialMojangMappings() mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
remappableImplementation "net.fabricmc:fabric-loader:${project.fabric_loader_version}" modImplementation "net.fabricmc:fabric-loader:${project.fabric_loader_version}"
remappableImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_api_version}+${project.targetVersion}" modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_api_version}+${project.targetVersion}"
// Override Fabric API version for local testing (runClient/runServer) // Override Fabric API version for local testing (runClient/runServer)
if (project.hasProperty("test_fabric_api_version")) if (project.hasProperty("test_fabric_api_version"))
remappableLocalRuntime "net.fabricmc.fabric-api:fabric-api:${project.test_fabric_api_version}" modLocalRuntime "net.fabricmc.fabric-api:fabric-api:${project.test_fabric_api_version}"
// Mod Compatibility // Mod Compatibility
if (project.hasProperty("mod_dynmap_version") && !project.mod_dynmap_version.allWhitespace) if (project.hasProperty("mod_dynmap_version"))
remappableCompileOnly "maven.modrinth:dynmap:${project.mod_dynmap_version}" modCompileOnly "maven.modrinth:dynmap:${project.mod_dynmap_version}"
if (project.hasProperty("mod_styled_chat_version") && !project.mod_styled_chat_version.allWhitespace) if (project.hasProperty("mod_styled_chat_version"))
remappableCompileOnly "maven.modrinth:styled-chat:${project.mod_styled_chat_version}" modCompileOnly "maven.modrinth:styled-chat:${project.mod_styled_chat_version}"
if (project.hasProperty("mod_styled_chat_placeholder_api_version") && !project.mod_styled_chat_placeholder_api_version.allWhitespace) if (project.hasProperty("mod_styled_chat_placeholder_api_version"))
remappableCompileOnly "eu.pb4:placeholder-api:${project.mod_styled_chat_placeholder_api_version}" modCompileOnly "eu.pb4:placeholder-api:${project.mod_styled_chat_placeholder_api_version}"
// Manifold // Manifold
annotationProcessor "systems.manifold:manifold-preprocessor:${project.manifold_version}" annotationProcessor "systems.manifold:manifold-preprocessor:${project.manifold_version}"
@ -143,8 +119,6 @@ tasks.register("buildAll") {
logger.lifecycle("Using Java ${javaToolchain.metadata.javaRuntimeVersion} (path=\"${projectJavaHome}\")") logger.lifecycle("Using Java ${javaToolchain.metadata.javaRuntimeVersion} (path=\"${projectJavaHome}\")")
def failedVersions = new ArrayList<String>()
project.minecraftVersions.each { version -> project.minecraftVersions.each { version ->
logger.lifecycle("================ Building for Minecraft ${version} ================") logger.lifecycle("================ Building for Minecraft ${version} ================")
// TODO: Refactor this (is there a better approach?) // TODO: Refactor this (is there a better approach?)
@ -157,14 +131,11 @@ tasks.register("buildAll") {
def result = execOutput.result.get() def result = execOutput.result.get()
def output = execOutput.standardOutput.asText.get() def output = execOutput.standardOutput.asText.get()
def error = execOutput.standardError.asText.get() def error = execOutput.standardError.asText.get()
logger.lifecycle("[Minecraft ${version}] BUILD ${result.exitValue == 0 ? "SUCCESSFUL" : "FAILED"}. Process exited with code: ${result.exitValue}") logger.lifecycle("[Minecraft ${version}] BUILD ${result.exitValue == 0 ? "SUCCESS" : "FAILED"}. Process exited with code: ${result.exitValue}")
if (result.exitValue != 0) { if (result.exitValue != 0) {
failedVersions.addLast(version as String)
logger.lifecycle("[Minecraft ${version}] Error: ${error}") logger.lifecycle("[Minecraft ${version}] Error: ${error}")
} }
} }
if (!failedVersions.isEmpty()) throw new GradleException("Build failed for Minecraft versions: ${failedVersions.join(", ")}")
} }
} }

View File

@ -6,12 +6,12 @@ org.gradle.parallel=true
version_properties_path=./properties version_properties_path=./properties
# Mod Properties # Mod Properties
mod_version=1.1.0 mod_version=1.0.0
maven_group=cn.revaria.chatplus maven_group=cn.revaria.chatplus
archives_base_name=chat-plus archives_base_name=chat-plus
# Minecraft # Minecraft
minecraft_version=26.1 minecraft_version=1.21
# Override Fabric API version for local testing (runClient/runServer) # Override Fabric API version for local testing (runClient/runServer)
#test_fabric_api_version= #test_fabric_api_version=

Binary file not shown.

View File

@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-9.4.1-bin.zip distributionUrl=https\://services.gradle.org/distributions/gradle-8.12.1-bin.zip
networkTimeout=10000 networkTimeout=10000
validateDistributionUrl=true validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME

11
gradlew vendored
View File

@ -1,7 +1,7 @@
#!/bin/sh #!/bin/sh
# #
# Copyright © 2015 the original authors. # Copyright © 2015-2021 the original authors.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
@ -57,7 +57,7 @@
# Darwin, MinGW, and NonStop. # Darwin, MinGW, and NonStop.
# #
# (3) This script is generated from the Groovy template # (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/2d6327017519d23b96af35865dc997fcb544fb40/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt # https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project. # within the Gradle project.
# #
# You can find Gradle at https://github.com/gradle/gradle/. # You can find Gradle at https://github.com/gradle/gradle/.
@ -114,6 +114,7 @@ case "$( uname )" in #(
NONSTOP* ) nonstop=true ;; NONSTOP* ) nonstop=true ;;
esac esac
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM. # Determine the Java command to use to start the JVM.
@ -171,6 +172,7 @@ fi
# For Cygwin or MSYS, switch paths to Windows format before running java # For Cygwin or MSYS, switch paths to Windows format before running java
if "$cygwin" || "$msys" ; then if "$cygwin" || "$msys" ; then
APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
JAVACMD=$( cygpath --unix "$JAVACMD" ) JAVACMD=$( cygpath --unix "$JAVACMD" )
@ -203,14 +205,15 @@ fi
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Collect all arguments for the java command: # Collect all arguments for the java command:
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, # * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
# and any embedded shellness will be escaped. # and any embedded shellness will be escaped.
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be # * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
# treated as '${Hostname}' itself on the command line. # treated as '${Hostname}' itself on the command line.
set -- \ set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \ "-Dorg.gradle.appname=$APP_BASE_NAME" \
-jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \ -classpath "$CLASSPATH" \
org.gradle.wrapper.GradleWrapperMain \
"$@" "$@"
# Stop when "xargs" is not available. # Stop when "xargs" is not available.

3
gradlew.bat vendored
View File

@ -70,10 +70,11 @@ goto fail
:execute :execute
@rem Setup the command line @rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle @rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %* "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
:end :end
@rem End local scope for the variables with windows NT shell @rem End local scope for the variables with windows NT shell

View File

@ -1,12 +1,8 @@
java_version=17 java_version=17
# Fabric Loom
# - For Minecraft versions <26.1: enable remap
# - For Minecraft versions >=26.1: disable remap
fabric_loom_remap=true
# Fabric Properties # Fabric Properties
# check these on https://fabricmc.net/develop # check these on https://fabricmc.net/develop
yarn_mappings=1.19.1+build.6
fabric_loader_version=0.16.10 fabric_loader_version=0.16.10
min_fabric_loader_version= min_fabric_loader_version=
fabric_api_version=0.58.4 fabric_api_version=0.58.4

View File

@ -1,12 +1,8 @@
java_version=17 java_version=17
# Fabric Loom
# - For Minecraft versions <26.1: enable remap
# - For Minecraft versions >=26.1: disable remap
fabric_loom_remap=true
# Fabric Properties # Fabric Properties
# check these on https://fabricmc.net/develop # check these on https://fabricmc.net/develop
yarn_mappings=1.19.3+build.5
fabric_loader_version=0.16.10 fabric_loader_version=0.16.10
min_fabric_loader_version= min_fabric_loader_version=
fabric_api_version=0.68.1 fabric_api_version=0.68.1

View File

@ -1,12 +1,8 @@
java_version=17 java_version=17
# Fabric Loom
# - For Minecraft versions <26.1: enable remap
# - For Minecraft versions >=26.1: disable remap
fabric_loom_remap=true
# Fabric Properties # Fabric Properties
# check these on https://fabricmc.net/develop # check these on https://fabricmc.net/develop
yarn_mappings=1.19+build.4
fabric_loader_version=0.16.10 fabric_loader_version=0.16.10
min_fabric_loader_version= min_fabric_loader_version=
fabric_api_version=0.55.1 fabric_api_version=0.55.1

View File

@ -1,12 +1,8 @@
java_version=17 java_version=17
# Fabric Loom
# - For Minecraft versions <26.1: enable remap
# - For Minecraft versions >=26.1: disable remap
fabric_loom_remap=true
# Fabric Properties # Fabric Properties
# check these on https://fabricmc.net/develop # check these on https://fabricmc.net/develop
yarn_mappings=1.20.3+build.1
fabric_loader_version=0.16.10 fabric_loader_version=0.16.10
min_fabric_loader_version= min_fabric_loader_version=
fabric_api_version=0.91.1 fabric_api_version=0.91.1

View File

@ -1,12 +1,8 @@
java_version=17 java_version=17
# Fabric Loom
# - For Minecraft versions <26.1: enable remap
# - For Minecraft versions >=26.1: disable remap
fabric_loom_remap=true
# Fabric Properties # Fabric Properties
# check these on https://fabricmc.net/develop # check these on https://fabricmc.net/develop
yarn_mappings=1.20+build.1
fabric_loader_version=0.16.10 fabric_loader_version=0.16.10
min_fabric_loader_version= min_fabric_loader_version=
fabric_api_version=0.83.0 fabric_api_version=0.83.0

View File

@ -1,12 +1,8 @@
java_version=21 java_version=21
# Fabric Loom
# - For Minecraft versions <26.1: enable remap
# - For Minecraft versions >=26.1: disable remap
fabric_loom_remap=true
# Fabric Properties # Fabric Properties
# check these on https://fabricmc.net/develop # check these on https://fabricmc.net/develop
yarn_mappings=1.21+build.9
fabric_loader_version=0.16.10 fabric_loader_version=0.16.10
min_fabric_loader_version= min_fabric_loader_version=
fabric_api_version=0.100.1 fabric_api_version=0.100.1

View File

@ -1,24 +0,0 @@
java_version=25
# Fabric Loom
# - For Minecraft versions <26.1: enable remap
# - For Minecraft versions >=26.1: disable remap
fabric_loom_remap=false
# Fabric Properties
# check these on https://fabricmc.net/develop
fabric_loader_version=0.19.1
min_fabric_loader_version=
fabric_api_version=0.144.0
# Fabric API mod ID conventions:
# - For Minecraft versions <1.19.2: use "fabric"
# - For Minecraft versions >=1.19.2: use "fabric-api"
# Ref: https://wiki.fabricmc.net/tutorial:setup
fabric_api_mod_id=fabric-api
# Mod Compatibility
! Dynmap 3.8
mod_dynmap_version=4UHHD4t6
! Styled Chat 2.12.0-pre.1+26.1
mod_styled_chat_version=2.12.0-pre.1+26.1
mod_styled_chat_placeholder_api_version=3.0.0-beta.2+26.1

View File

@ -24,7 +24,7 @@ def loadProperties() {
// Prefer the version defined by the command line argument -Pmc=x.x.x // Prefer the version defined by the command line argument -Pmc=x.x.x
def inputVersion = hasProperty("mc") ? def inputVersion = hasProperty("mc") ?
validateMinecraftVersionFormat(mc as String, "Invalid Minecraft version provided via -Pmc=${mc}") : validateMinecraftVersionFormat(mc as String, "Invalid Minecraft version provided via -Pmc=${minecraft_version}") :
validateMinecraftVersionFormat(minecraft_version, "Invalid Minecraft version in gradle.properties: minecraft_version=${minecraft_version}") validateMinecraftVersionFormat(minecraft_version, "Invalid Minecraft version in gradle.properties: minecraft_version=${minecraft_version}")
gradle.ext.minecraft_version = inputVersion gradle.ext.minecraft_version = inputVersion

View File

@ -1,16 +1,16 @@
package cn.revaria.chatplus.mixin; package cn.revaria.chatplus.mixin;
#if MC_VER <= MC_1_19 #if MC_VER <= MC_1_19
import net.minecraft.resources.ResourceKey; import net.minecraft.server.filter.FilteredMessage;
import net.minecraft.server.network.FilteredText; import net.minecraft.util.registry.RegistryKey;
#endif #endif
import cn.revaria.chatplus.plugin.annotation.DisableIfModsLoaded; import cn.revaria.chatplus.plugin.annotation.DisableIfModsLoaded;
import net.minecraft.network.chat.ChatType; import net.minecraft.network.message.MessageType;
import net.minecraft.network.chat.PlayerChatMessage; import net.minecraft.network.message.SignedMessage;
import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.PlayerManager;
import net.minecraft.server.network.ServerGamePacketListenerImpl; import net.minecraft.server.network.ServerPlayNetworkHandler;
import net.minecraft.server.players.PlayerList; import net.minecraft.server.network.ServerPlayerEntity;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.Redirect;
@ -18,31 +18,26 @@ import org.spongepowered.asm.mixin.injection.Redirect;
import static cn.revaria.chatplus.util.TextStyleFormatter.applyStyle; import static cn.revaria.chatplus.util.TextStyleFormatter.applyStyle;
@DisableIfModsLoaded("styledchat") @DisableIfModsLoaded("styledchat")
@Mixin(ServerGamePacketListenerImpl.class) @Mixin(ServerPlayNetworkHandler.class)
public abstract class ChatMixin { public abstract class ChatMixin {
@Redirect(method = "broadcastChatMessage", at = @At(value = "INVOKE", target = @Redirect(method = "handleDecoratedMessage", at = @At(value = "INVOKE", target =
#if MC_VER <= MC_1_19 #if MC_VER <= MC_1_19
"Lnet/minecraft/server/players/PlayerList;broadcastChatMessage(Lnet/minecraft/server/network/FilteredText;Lnet/minecraft/server/level/ServerPlayer;Lnet/minecraft/resources/ResourceKey;)V" "Lnet/minecraft/server/PlayerManager;broadcast(Lnet/minecraft/server/filter/FilteredMessage;Lnet/minecraft/server/network/ServerPlayerEntity;Lnet/minecraft/util/registry/RegistryKey;)V"
#else #else
"Lnet/minecraft/server/players/PlayerList;broadcastChatMessage(Lnet/minecraft/network/chat/PlayerChatMessage;Lnet/minecraft/server/level/ServerPlayer;Lnet/minecraft/network/chat/ChatType$Bound;)V" "Lnet/minecraft/server/PlayerManager;broadcast(Lnet/minecraft/network/message/SignedMessage;Lnet/minecraft/server/network/ServerPlayerEntity;Lnet/minecraft/network/message/MessageType$Parameters;)V"
#endif #endif
)) ))
#if MC_VER <= MC_1_19 #if MC_VER <= MC_1_19
private void replaceText(PlayerList instance, FilteredText<PlayerChatMessage> message, ServerPlayer sender, ResourceKey<ChatType> typeKey) { private void replaceText(PlayerManager instance, FilteredMessage<SignedMessage> message, ServerPlayerEntity sender, RegistryKey<MessageType> typeKey) {
var newMessage = new FilteredText<>( var newMessage = new FilteredMessage<>(
message.raw().withUnsignedContent(applyStyle(message.raw().serverContent(), sender)), message.raw().withUnsigned(applyStyle(message.raw().getContent(), sender)),
message.filtered() != null ? message.filtered().withUnsignedContent(applyStyle(message.filtered().serverContent(), sender)) : null message.filtered() != null ? message.filtered().withUnsigned(applyStyle(message.filtered().getContent(), sender)) : null
); );
instance.broadcastChatMessage(newMessage, sender, typeKey); instance.broadcast(newMessage, sender, typeKey);
} }
#else #else
private void replaceText(PlayerList instance, PlayerChatMessage message, ServerPlayer sender, ChatType.Bound params) { private void replaceText(PlayerManager instance, SignedMessage message, ServerPlayerEntity sender, MessageType.Parameters params) {
instance.broadcastChatMessage( instance.broadcast(message.withUnsignedContent(applyStyle(message.getContent(), sender)), sender, params);
message.withUnsignedContent(
applyStyle(message.#if MC_VER <= MC_1_19_1 serverContent() #else decoratedContent() #endif, sender)
),
sender, params
);
} }
#endif #endif
} }

View File

@ -2,8 +2,8 @@ package cn.revaria.chatplus.mixin.compat;
import com.llamalad7.mixinextras.sugar.Local; import com.llamalad7.mixinextras.sugar.Local;
import com.llamalad7.mixinextras.sugar.ref.LocalRef; import com.llamalad7.mixinextras.sugar.ref.LocalRef;
import net.minecraft.network.chat.Component; import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.level.ServerPlayer; import net.minecraft.text.Text;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Pseudo; import org.spongepowered.asm.mixin.Pseudo;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;
@ -29,20 +29,13 @@ import static cn.revaria.chatplus.util.TextStyleFormatter.applyStyle;
"org.dynmap.fabric_1_21.DynmapPlugin$ChatHandler", "org.dynmap.fabric_1_21.DynmapPlugin$ChatHandler",
"org.dynmap.fabric_1_21_1.DynmapPlugin$ChatHandler", "org.dynmap.fabric_1_21_1.DynmapPlugin$ChatHandler",
"org.dynmap.fabric_1_21_3.DynmapPlugin$ChatHandler", "org.dynmap.fabric_1_21_3.DynmapPlugin$ChatHandler",
"org.dynmap.fabric_1_21_5.DynmapPlugin$ChatHandler", "org.dynmap.fabric_1_21_5.DynmapPlugin$ChatHandler"
"org.dynmap.fabric_1_21_7.DynmapPlugin$ChatHandler",
"org.dynmap.fabric_1_21_9_10.DynmapPlugin$ChatHandler",
"org.dynmap.fabric_1_21_11.DynmapPlugin$ChatHandler",
} }
#elif MC_VER <= MC_26_1
// TODO: Since Dynmap has not yet been updated to be compatible with Minecraft 26.1,
// the compatibility Mixins for Dynmap are currently not enabled for this version.
{}
#endif #endif
) )
public abstract class DynmapMixin { public abstract class DynmapMixin {
@Inject(method = "handleChat", at = @At("HEAD"), remap = false) @Inject(method = "handleChat", at = @At("HEAD"), remap = false)
private void modifyMessage(ServerPlayer player, String message, CallbackInfo ci, @Local(argsOnly = true) LocalRef<String> messageRef) { private void modifyMessage(ServerPlayerEntity player, String message, CallbackInfo ci, @Local(argsOnly = true) LocalRef<String> messageRef) {
messageRef.set(applyStyle(Component.nullToEmpty(message), player).getString()); messageRef.set(applyStyle(Text.of(message), player).getString());
} }
} }

View File

@ -1,13 +1,8 @@
package cn.revaria.chatplus.mixin.compat; package cn.revaria.chatplus.mixin.compat;
#if MC_VER <= MC_1_21
import eu.pb4.placeholders.api.PlaceholderContext; import eu.pb4.placeholders.api.PlaceholderContext;
#else
import eu.pb4.placeholders.api.ServerPlaceholderContext;
#endif
import eu.pb4.styledchat.StyledChatUtils; import eu.pb4.styledchat.StyledChatUtils;
import net.minecraft.network.chat.Component; import net.minecraft.text.Text;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Pseudo; import org.spongepowered.asm.mixin.Pseudo;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;
@ -19,19 +14,8 @@ import static cn.revaria.chatplus.util.TextStyleFormatter.applyStyle;
@Pseudo @Pseudo
@Mixin(StyledChatUtils.class) @Mixin(StyledChatUtils.class)
public abstract class StyledChatMixin { public abstract class StyledChatMixin {
@Inject(method = @Inject(method = "formatFor(Leu/pb4/placeholders/api/PlaceholderContext;Ljava/lang/String;)Lnet/minecraft/text/Text;", at = @At("RETURN"), cancellable = true)
#if MC_VER <= MC_1_21 private static void modifyText(PlaceholderContext context, String input, CallbackInfoReturnable<Text> cir) {
"formatFor(Leu/pb4/placeholders/api/PlaceholderContext;Ljava/lang/String;)Lnet/minecraft/network/chat/Component;" cir.setReturnValue(applyStyle(cir.getReturnValue(), context.player()));
#else
"formatFor(Leu/pb4/placeholders/api/ServerPlaceholderContext;Ljava/lang/String;)Lnet/minecraft/network/chat/Component;"
#endif,
at = @At("RETURN"),
cancellable = true
)
private static void modifyText(
#if MC_VER <= MC_1_21 PlaceholderContext #else ServerPlaceholderContext #endif context,
String input, CallbackInfoReturnable<Component> cir
) {
cir.setReturnValue(applyStyle(cir.getReturnValue(), context.#if MC_VER <= MC_1_21 player() #else serverPlayer() #endif));
} }
} }

View File

@ -2,14 +2,11 @@ package cn.revaria.chatplus.plugin;
import cn.revaria.chatplus.plugin.annotation.DisableIfModsLoaded; import cn.revaria.chatplus.plugin.annotation.DisableIfModsLoaded;
import net.fabricmc.loader.api.FabricLoader; import net.fabricmc.loader.api.FabricLoader;
import org.objectweb.asm.tree.AnnotationNode;
import org.objectweb.asm.tree.ClassNode; import org.objectweb.asm.tree.ClassNode;
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin; import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
import org.spongepowered.asm.mixin.extensibility.IMixinInfo; import org.spongepowered.asm.mixin.extensibility.IMixinInfo;
import org.spongepowered.asm.service.MixinService;
import org.spongepowered.asm.util.Annotations;
import java.io.IOException; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
@ -26,17 +23,14 @@ public class MixinConfigPlugin implements IMixinConfigPlugin {
@Override @Override
public boolean shouldApplyMixin(String targetClassName, String mixinClassName) { public boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
try { try {
ClassNode classNode = MixinService.getService().getBytecodeProvider().getClassNode(mixinClassName); Class<?> mixinClass = Class.forName(mixinClassName);
AnnotationNode annotationNode = Annotations.getVisible(classNode, DisableIfModsLoaded.class); DisableIfModsLoaded annotation = mixinClass.getAnnotation(DisableIfModsLoaded.class);
if (annotation != null) {
if (annotationNode == null) { return Arrays.stream(annotation.value()).noneMatch(modId -> FabricLoader.getInstance().isModLoaded(modId));
return true;
} }
return true;
List<String> modIds = Annotations.getValue(annotationNode); } catch (Exception e) {
return modIds.stream().noneMatch(modId -> FabricLoader.getInstance().isModLoaded(modId)); return true;
} catch (IOException | ClassNotFoundException e) {
return false;
} }
} }

View File

@ -1,15 +1,15 @@
package cn.revaria.chatplus.util; package cn.revaria.chatplus.util;
#if MC_VER <= MC_1_20 #if MC_VER <= MC_1_20
import net.minecraft.network.chat.contents.LiteralContents; import net.minecraft.text.LiteralTextContent;
#else #else
import net.minecraft.network.chat.contents.PlainTextContents; import net.minecraft.text.PlainTextContent.Literal;
#endif #endif
import net.minecraft.network.chat.Component; import net.minecraft.item.ItemStack;
import net.minecraft.network.chat.MutableComponent; import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.level.ServerPlayer; import net.minecraft.text.MutableText;
import net.minecraft.world.item.ItemStack; import net.minecraft.text.Text;
import java.util.ArrayDeque; import java.util.ArrayDeque;
import java.util.Deque; import java.util.Deque;
@ -32,13 +32,13 @@ public class TextStyleFormatter {
* @param sourcePlayer Player used for item stack references * @param sourcePlayer Player used for item stack references
* @return Processed text with styling and item hover elements * @return Processed text with styling and item hover elements
*/ */
public static MutableComponent applyStyle(Component sourceText, ServerPlayer sourcePlayer) { public static MutableText applyStyle(Text sourceText, ServerPlayerEntity sourcePlayer) {
MutableComponent sourceMutableText = sourceText.copy(); MutableText sourceMutableText = sourceText.copy();
MutableComponent finalText = Component.empty().setStyle(sourceMutableText.getStyle()); MutableText finalText = Text.empty().setStyle(sourceMutableText.getStyle());
if (sourceText.getContents() instanceof #if MC_VER <= MC_1_20 LiteralContents #else PlainTextContents #endif plainTextContent) { if (sourceText.getContent() instanceof #if MC_VER <= MC_1_20 LiteralTextContent #else Literal #endif plainTextContent) {
String changedMessage = plainTextContent.text() String changedMessage = plainTextContent.string()
.replace('&', '§') .replace('&', '§')
.replace("§§", "&"); .replace("§§", "&");
String regex = "\\[item(?:=([1-9]))?\\]"; String regex = "\\[item(?:=([1-9]))?\\]";
@ -56,22 +56,22 @@ public class TextStyleFormatter {
} }
for (String message : messages) { for (String message : messages) {
finalText.append(Component.literal(message)); finalText.append(Text.literal(message));
if (!itemDeque.isEmpty()) { if (!itemDeque.isEmpty()) {
ItemStack itemStack; ItemStack itemStack;
if (itemDeque.getFirst() == MAIN_HAND) { if (itemDeque.getFirst() == MAIN_HAND) {
itemStack = sourcePlayer.getMainHandItem(); itemStack = sourcePlayer.getMainHandStack();
} else { } else {
itemStack = sourcePlayer.getInventory().getItem(itemDeque.getFirst() - 1); itemStack = sourcePlayer.getInventory().getStack(itemDeque.getFirst() - 1);
} }
finalText.append(itemStack.getDisplayName()); finalText.append(itemStack.toHoverableText());
itemDeque.removeFirst(); itemDeque.removeFirst();
} }
} }
} }
List<Component> sourceTexts = sourceMutableText.getSiblings(); List<Text> sourceTexts = sourceMutableText.getSiblings();
for (Component text : sourceTexts) { for (Text text : sourceTexts) {
finalText.append(applyStyle(text, sourcePlayer)); finalText.append(applyStyle(text, sourcePlayer));
} }