Skip to content

Commit

Permalink
Update emote parsing, update placeholder api, tweak mixin to make 1.1…
Browse files Browse the repository at this point in the history
…9.3 version compatible with 1.19.4
  • Loading branch information
Patbox committed Mar 7, 2023
1 parent fca2f54 commit 3973054
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 57 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ dependencies {
modCompileOnly fabricApi.module("fabric-message-api-v1", project.fabric_version)

modImplementation include("eu.pb4:predicate-api:0.1.0+1.19.3")
modImplementation include("eu.pb4:placeholder-api:2.0.0-pre.2+1.19.3")
modImplementation include("eu.pb4:placeholder-api:2.0.0-rc.1+1.19.3")
modImplementation include("me.lucko:fabric-permissions-api:0.2-SNAPSHOT")
modImplementation include("eu.pb4:player-data-api:0.2.2+1.19.3")

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ fabric_version=0.68.1+1.19.3

# Mod Properties

mod_version = 2.1.2+1.19.3
mod_version = 2.1.3+1.19.3
maven_group = eu.pb4
archives_base_name = styled-chat

Expand Down
27 changes: 13 additions & 14 deletions src/main/java/eu/pb4/styledchat/StyledChatUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@
import eu.pb4.placeholders.api.node.EmptyNode;
import eu.pb4.placeholders.api.node.LiteralNode;
import eu.pb4.placeholders.api.node.TextNode;
import eu.pb4.placeholders.api.parsers.LegacyFormattingParser;
import eu.pb4.placeholders.api.parsers.MarkdownLiteParserV1;
import eu.pb4.placeholders.api.parsers.NodeParser;
import eu.pb4.placeholders.api.parsers.TextParserV1;
import eu.pb4.placeholders.api.parsers.*;
import eu.pb4.playerdata.api.PlayerDataApi;
import eu.pb4.playerdata.api.storage.JsonDataStorage;
import eu.pb4.styledchat.config.ChatStyle;
Expand Down Expand Up @@ -63,7 +60,7 @@ public final class StyledChatUtils {

public static final String FORMAT_PERMISSION_BASE = "styledchat.format.";
public static final String FORMAT_PERMISSION_UNSAFE = "styledchat.unsafe_format.";
public static final Pattern EMOTE_PATTERN = Pattern.compile("[:](?<id>[^:]+)[:]");
public static final Pattern EMOTE_PATTERN = Pattern.compile("(?<!((?<!(\\\\))\\\\))[:](?<id>[^:]+)[:]");;
public static final Text EMPTY_TEXT = Text.empty();
private static final Set<RegistryKey<MessageType>> DECORABLE = Set.of(MessageType.CHAT, MessageType.EMOTE_COMMAND, MessageType.MSG_COMMAND_INCOMING, MessageType.MSG_COMMAND_OUTGOING, MessageType.SAY_COMMAND, MessageType.TEAM_MSG_COMMAND_INCOMING, MessageType.TEAM_MSG_COMMAND_OUTGOING);

Expand Down Expand Up @@ -113,6 +110,10 @@ public static NodeParser createParser(PlaceholderContext context) {
form.add(MarkdownLiteParserV1.MarkdownFormat.SPOILER);
}

if (base.getTagParser("link") != null) {
form.add(MarkdownLiteParserV1.MarkdownFormat.URL);
}

if (!form.isEmpty()) {
list.add(new MarkdownLiteParserV1(SpoilerNode::new, MarkdownLiteParserV1::defaultQuoteFormatting, form.toArray(new MarkdownLiteParserV1.MarkdownFormat[0])));
}
Expand All @@ -133,6 +134,12 @@ public static NodeParser createParser(PlaceholderContext context) {
}
}

var emotes = getEmotes(context);

if (!emotes.isEmpty()) {
list.add(new PatternPlaceholderParser(EMOTE_PATTERN, emotes::get));
}

return NodeParser.merge(list);
}

Expand Down Expand Up @@ -173,21 +180,13 @@ public static Text formatFor(PlaceholderContext context, String input) {
input = StyledChatEvents.PRE_MESSAGE_CONTENT.invoker().onPreMessage(input, context);
}

var emotes = getEmotes(context);

var value = TextNode.asSingle(parser.parseNodes(new LiteralNode(input)));

if (StyledChatMod.USE_FABRIC_API) {
value = StyledChatEvents.MESSAGE_CONTENT.invoker().onMessage(value, context);
}


var text = Placeholders.parseText(
value,
context,
EMOTE_PATTERN,
(id) -> emotes.containsKey(id) ? ((ctx, arg) -> PlaceholderResult.value(Placeholders.parseText(emotes.get(id), ctx))) : null
);
var text = value.toText(context);

if (config.configData.formatting.allowModdedDecorators) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

@Mixin(MinecraftServer.class)
public class MinecraftServerMixin {
@Inject(method = "runServer", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/MinecraftServer;setFavicon(Lnet/minecraft/server/ServerMetadata;)V"))
@Inject(method = "runServer", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/Util;getMeasuringTimeMs()J", ordinal = 0))
private void styledChat_registerStarting(CallbackInfo ci) {
StyledChatMod.serverStarting((MinecraftServer) (Object) this);
}
Expand Down
40 changes: 0 additions & 40 deletions src/main/java/eu/pb4/styledchat/other/ServerTranslationUtils.java

This file was deleted.

0 comments on commit 3973054

Please sign in to comment.