Skip to content

Commit

Permalink
Fix server logs and allow to disable sending full formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Patbox committed Jun 7, 2022
1 parent f4bfc32 commit e8e792f
Show file tree
Hide file tree
Showing 9 changed files with 134 additions and 12 deletions.
45 changes: 45 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -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 }}
49 changes: 49 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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
}
}
9 changes: 5 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 1 addition & 3 deletions src/main/java/eu/pb4/styledchat/StyledChatUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public static String legacyFormatMessage(String input, Set<String> 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() + ">");
}
}
}
Expand Down Expand Up @@ -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());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "<underline><c:#7878ff>${link}";
public String spoilerStyle = "<gray>${spoiler}";
public String spoilerSymbol = "▌";
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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 <T> 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();
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/eu/pb4/styledchat/mixin/PlayerManagerMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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"))
Expand Down Expand Up @@ -63,4 +71,16 @@ private void styledChat_excludeSendingOfHiddenMessages2(Text message, Function<S
ci.cancel();
}
}

@Redirect(method = "broadcast(Lnet/minecraft/network/message/SignedMessage;Ljava/util/function/Function;Lnet/minecraft/network/message/MessageSender;Lnet/minecraft/util/registry/RegistryKey;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/MinecraftServer;logChatMessage(Lnet/minecraft/network/message/MessageSender;Lnet/minecraft/text/Text;)V"))
private void styledChat_fixServerLogs(MinecraftServer instance, MessageSender sender, Text ignore, SignedMessage message) {
var out = ((ExtSignedMessage) (Object) message).styledChat_getArg("override");
if (out != null) {
if (out != StyledChatUtils.IGNORED_TEXT) {
this.server.sendMessage(out);
}
} else {
this.server.logChatMessage(sender, message.getContent());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ private void styledChat_removeCachedIfNotPreviewed(ChatMessageC2SPacket packet,

@Redirect(method = "decorateChat", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/MinecraftServer;getMessageDecorator()Lnet/minecraft/network/message/MessageDecorator;"))
private MessageDecorator styledChat_replaceDecorator2(MinecraftServer instance) {
return StyledChatUtils.getChatDecorator();
return ConfigManager.getConfig().configData.sendFullMessageInChatPreview ? StyledChatUtils.getChatDecorator() : StyledChatUtils.getRawDecorator();
}

@Inject(method = "sendChatPreviewPacket", at = @At("HEAD"))
Expand Down
13 changes: 10 additions & 3 deletions src/main/java/eu/pb4/styledchat/parser/SpoilerNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
import eu.pb4.placeholders.api.Placeholders;
import eu.pb4.placeholders.api.node.TextNode;
import eu.pb4.placeholders.api.node.parent.ParentNode;
import eu.pb4.placeholders.api.node.parent.ParentTextNode;
import eu.pb4.styledchat.config.ConfigManager;
import net.minecraft.text.HoverEvent;
import net.minecraft.text.MutableText;
import net.minecraft.text.Style;
import net.minecraft.text.Text;

import java.util.Map;
Expand All @@ -20,9 +20,16 @@ public SpoilerNode(TextNode[] children) {
@Override
protected Text applyFormatting(MutableText out, ParserContext context) {
var config = ConfigManager.getConfig();
return ((MutableText) Placeholders.parseText(config.spoilerStyle,
var obj = ((MutableText) Placeholders.parseText(config.spoilerStyle,
Placeholders.PREDEFINED_PLACEHOLDER_PATTERN,
Map.of("spoiler", Text.literal(config.configData.spoilerSymbol.repeat(out.getString().length())))
)).setStyle(Style.EMPTY.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, out)));
));

return obj.setStyle(obj.getStyle().withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, out)));
}

@Override
public ParentTextNode copyWith(TextNode[] children) {
return new SpoilerNode(this.children);
}
}

0 comments on commit e8e792f

Please sign in to comment.