From e8e792f7ff29b93efab2595fd094415226c8f3d4 Mon Sep 17 00:00:00 2001 From: Patbox <39821509+Patbox@users.noreply.github.com> Date: Tue, 7 Jun 2022 22:40:00 +0200 Subject: [PATCH] Fix server logs and allow to disable sending full formatting --- .github/workflows/release.yml | 45 +++++++++++++++++ build.gradle | 49 +++++++++++++++++++ gradle.properties | 9 ++-- .../eu/pb4/styledchat/StyledChatUtils.java | 4 +- .../styledchat/config/data/ConfigData.java | 1 + .../styledchat/mixin/MessageFormatMixin.java | 3 +- .../styledchat/mixin/PlayerManagerMixin.java | 20 ++++++++ .../mixin/ServerPlayNetworkManagerMixin.java | 2 +- .../eu/pb4/styledchat/parser/SpoilerNode.java | 13 +++-- 9 files changed, 134 insertions(+), 12 deletions(-) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..ae05f9d --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,45 @@ +name: Release + +on: + release: + types: + - published + workflow_dispatch: + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/cache@v2 + with: + path: | + ~/.gradle/loom-cache + ~/.gradle/caches + ~/.gradle/wrapper + key: gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} + restore-keys: | + gradle- + - uses: actions/checkout@v2 + - name: Set up JDK + uses: actions/setup-java@v1 + with: + java-version: 17 + + - name: Grant execute permission for gradlew + run: chmod +x gradlew + + - name: Build and publish with Gradle + run: ./gradlew build publish + env: + MAVEN_URL: ${{ secrets.MAVEN_URL }} + MAVEN_USERNAME: ${{ secrets.MAVEN_USERNAME }} + MAVEN_PASSWORD: ${{ secrets.MAVEN_PASSWORD }} + CURSEFORGE: ${{ secrets.CURSEFORGE }} + MODRINTH: ${{ secrets.MODRINTH }} + CHANGELOG: ${{ github.event.release.body }} + - name: Upload GitHub release + uses: AButler/upload-release-assets@v2.0 + with: + files: 'build/libs/*.jar;!build/libs/*-sources.jar;!build/libs/*-dev.jar' + repo-token: ${{ secrets.GITHUB_TOKEN }} diff --git a/build.gradle b/build.gradle index fb56c55..124973a 100644 --- a/build.gradle +++ b/build.gradle @@ -1,8 +1,12 @@ plugins { id 'fabric-loom' version '0.12-SNAPSHOT' id 'maven-publish' + id "com.modrinth.minotaur" version "2.+" + id 'com.matthewprenger.cursegradle' version '1.4.0' } +var isStable = project.is_stable == "true" + sourceCompatibility = JavaVersion.VERSION_17 targetCompatibility = JavaVersion.VERSION_17 @@ -95,3 +99,48 @@ publishing { // retrieving dependencies. } } + +curseforge { + if (isStable && System.getenv("CURSEFORGE")) { + apiKey = System.getenv("CURSEFORGE") + + project { + id = "493348" + releaseType = "release" + changelog = System.getenv("CHANGELOG") + changelogType = "markdown" + addGameVersion ((String) project.minecraft_version) + addGameVersion "Fabric" + addGameVersion "Quilt" + mainArtifact(remapJar) + + afterEvaluate { + uploadTask.dependsOn("remapJar") + } + } + } + + options { + forgeGradleIntegration = false + } + remapJar { + finalizedBy project.tasks.curseforge + } +} + +if (System.getenv("MODRINTH")) { + modrinth { + token = System.getenv("MODRINTH") + projectId = 'doqSKB0e'// The ID of your modrinth project, slugs will not work. + versionNumber = "" + version // The version of the mod to upload. + versionType = isStable ? "release" : "beta" + uploadFile = remapJar // This links to a task that builds your mod jar and sets "uploadFile" to the mod jar. + gameVersions = [((String) project.minecraft_version)] + changelog = System.getenv("CHANGELOG") + loaders = ["fabric", "quilt"] + } + + remapJar { + finalizedBy project.tasks.modrinth + } +} diff --git a/gradle.properties b/gradle.properties index d75ad20..830f2b2 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,16 +3,17 @@ org.gradle.jvmargs=-Xmx1G # Fabric Properties # check these on https://fabricmc.net/use -minecraft_version=1.19-rc2 -yarn_mappings=1.19-rc2+build.1 +minecraft_version=1.19 +yarn_mappings=1.19+build.1 loader_version=0.14.6 #Fabric api -fabric_version=0.55.0+1.19 +fabric_version=0.55.1+1.19 # Mod Properties - mod_version = 1.3.0+1.19 + mod_version = 1.3.1+1.19 maven_group = eu.pb4 archives_base_name = styled-chat # Dependencies +is_stable = true diff --git a/src/main/java/eu/pb4/styledchat/StyledChatUtils.java b/src/main/java/eu/pb4/styledchat/StyledChatUtils.java index 6975bda..7b32cd3 100644 --- a/src/main/java/eu/pb4/styledchat/StyledChatUtils.java +++ b/src/main/java/eu/pb4/styledchat/StyledChatUtils.java @@ -127,7 +127,7 @@ public static String legacyFormatMessage(String input, Set handlers) { if (config.configData.legacyChatFormatting) { for (var formatting : Formatting.values()) { if (handlers.contains(formatting.getName())) { - input = input.replace(String.copyValueOf(new char[]{'&', formatting.getCode()}), "<" + formatting.getName() + ">"); + input = input.replace("&" + formatting.getCode(), "<" + formatting.getName() + ">"); } } } @@ -302,8 +302,6 @@ public static Text formatMessage(SignedMessage message, ServerCommandSource sour Config config = ConfigManager.getConfig(); var ext = (ExtSignedMessage) (Object) message; - System.out.println(ext.styledChat_getOriginal()); - var baseInput = ext.styledChat_getArg("base_input"); var input = baseInput != null && baseInput.getContent() != TextContent.EMPTY ? baseInput : formatFor(source, ext.styledChat_getOriginal()); diff --git a/src/main/java/eu/pb4/styledchat/config/data/ConfigData.java b/src/main/java/eu/pb4/styledchat/config/data/ConfigData.java index 2adfc5a..dc1c208 100644 --- a/src/main/java/eu/pb4/styledchat/config/data/ConfigData.java +++ b/src/main/java/eu/pb4/styledchat/config/data/ConfigData.java @@ -22,6 +22,7 @@ public class ConfigData { public boolean parseLinksInChat = true; public boolean enableMarkdown = true; public boolean allowModdedDecorators = true; + public boolean sendFullMessageInChatPreview = true; public String linkStyle = "${link}"; public String spoilerStyle = "${spoiler}"; public String spoilerSymbol = "▌"; diff --git a/src/main/java/eu/pb4/styledchat/mixin/MessageFormatMixin.java b/src/main/java/eu/pb4/styledchat/mixin/MessageFormatMixin.java index 23c5858..30ccbf5 100644 --- a/src/main/java/eu/pb4/styledchat/mixin/MessageFormatMixin.java +++ b/src/main/java/eu/pb4/styledchat/mixin/MessageFormatMixin.java @@ -1,5 +1,6 @@ package eu.pb4.styledchat.mixin; +import eu.pb4.styledchat.config.ConfigManager; import eu.pb4.styledchat.ducks.ExtMessageFormat; import eu.pb4.styledchat.StyledChatUtils; import net.minecraft.command.argument.MessageArgumentType; @@ -23,7 +24,7 @@ public class MessageFormatMixin implements ExtMessageFormat { @Redirect(method = "decorate", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/MinecraftServer;getMessageDecorator()Lnet/minecraft/network/message/MessageDecorator;")) private MessageDecorator styledChat_replaceDecorator2(MinecraftServer instance) { - if (styledChat_context != null) { + if (this.styledChat_context != null && ConfigManager.getConfig().configData.sendFullMessageInChatPreview) { return StyledChatUtils.getCommandDecorator(this.styledChat_context, this.styledChat_source, this.styledChat_args); } return StyledChatUtils.getRawDecorator(); diff --git a/src/main/java/eu/pb4/styledchat/mixin/PlayerManagerMixin.java b/src/main/java/eu/pb4/styledchat/mixin/PlayerManagerMixin.java index 2411353..08ecf9e 100644 --- a/src/main/java/eu/pb4/styledchat/mixin/PlayerManagerMixin.java +++ b/src/main/java/eu/pb4/styledchat/mixin/PlayerManagerMixin.java @@ -2,19 +2,26 @@ import eu.pb4.styledchat.StyledChatUtils; import eu.pb4.styledchat.config.ConfigManager; +import eu.pb4.styledchat.ducks.ExtSignedMessage; import net.minecraft.network.ClientConnection; +import net.minecraft.network.message.MessageSender; import net.minecraft.network.message.MessageType; +import net.minecraft.network.message.SignedMessage; +import net.minecraft.server.MinecraftServer; import net.minecraft.server.PlayerManager; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.stat.Stats; import net.minecraft.text.Text; import net.minecraft.text.TranslatableTextContent; import net.minecraft.util.registry.RegistryKey; +import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.ModifyArg; +import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import java.util.UUID; @@ -24,6 +31,7 @@ @Mixin(PlayerManager.class) public class PlayerManagerMixin { + @Shadow @Final private MinecraftServer server; @Unique private ServerPlayerEntity temporaryPlayer = null; @Inject(method = "onPlayerConnect", at = @At(value = "HEAD")) @@ -63,4 +71,16 @@ private void styledChat_excludeSendingOfHiddenMessages2(Text message, Function