Skip to content

Commit

Permalink
Fix emoticons not working
Browse files Browse the repository at this point in the history
  • Loading branch information
Patbox committed Nov 30, 2021
1 parent 26e75ab commit 2601d04
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 13 deletions.
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ org.gradle.jvmargs=-Xmx1G

# Fabric Properties
# check these on https://fabricmc.net/use
minecraft_version=1.18-rc1
yarn_mappings=1.18-rc1+build.1
loader_version=0.12.5
minecraft_version=1.18
yarn_mappings=1.18+build.1
loader_version=0.12.6

#Fabric api
fabric_version=0.43.1+1.18

# Mod Properties
mod_version = 1.2.1+1.18
mod_version = 1.2.2+1.18
maven_group = eu.pb4
archives_base_name = styled-chat

Expand Down
13 changes: 12 additions & 1 deletion src/main/java/eu/pb4/styledchat/StyledChatUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ public static Map<String, TextParser.TextFormatterHandler> getHandlers(ServerPla
}
}

if (config.defaultFormattingCodes.getBoolean(SPOILER_TAG)
|| Permissions.check(source, FORMAT_PERMISSION_BASE + SPOILER_TAG, 2)) {
handlers.put(SPOILER_TAG, SPOILER_TAG_HANDLER);
}

if (handlers.containsKey("light_purple")) {
handlers.put("pink", handlers.get("light_purple"));
}
Expand Down Expand Up @@ -170,7 +175,13 @@ public Text get(Object key) {
}

text = this.texts.get(key);
return text != null ? this.cache.put((String) key, this.getParsed(text)) : null;

if (text != null) {
var out = this.getParsed(text);
this.cache.put((String) key, out);
return out;
}
return null;
}

@NotNull
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/eu/pb4/styledchat/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,10 @@ public Config(ConfigData data) {
for (var entry : data.permissionEmoticons) {
var emotes = PermissionEmotes.of(entry.permission, entry.opLevel);

for (var emote : entry.emotes.entrySet()) {
for (var emote : entry.emoticons.entrySet()) {
emotes.emotes().put(emote.getKey(), TextParser.parse(emote.getValue()));
}
this.permissionEmotes.add(emotes);
}


Expand Down
11 changes: 10 additions & 1 deletion src/main/java/eu/pb4/styledchat/config/data/ConfigData.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,13 @@ public static ConfigData transform(ConfigData configData) {
}


for (var entry : configData.permissionEmoticons) {
if (entry.emotes != null) {
entry.emoticons = entry.emotes;
entry.emotes = null;
}
}

return configData;
}

Expand All @@ -108,6 +115,8 @@ public static PermissionPriorityStyle of(String permission, ChatStyleData style)
public static class PermissionEmotes {
public String permission = "";
public int opLevel = 3;
public Map<String, String> emotes = Collections.EMPTY_MAP;
public Map<String, String> emoticons = Collections.EMPTY_MAP;
@Deprecated
public Map<String, String> emotes = null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,10 @@ private void styledChat_replaceChatMessage(PlayerManager playerManager, Text ser
rawMessage = StyledChatEvents.PRE_MESSAGE_CONTENT_SEND.invoker().onPreMessage(message.getRaw(), player, false);

rawMessage = StyledChatUtils.formatMessage(rawMessage, handlers);

Text rawText = config.getChat(this.player,
StyledChatEvents.MESSAGE_CONTENT_SEND.invoker().onMessage(handlers.size() > 0
? PlaceholderAPI.parsePredefinedText(TextParser.parse(rawMessage, handlers), StyledChatUtils.EMOTE_PATTERN, emotes)
: new LiteralText(message.getRaw()),
: PlaceholderAPI.parsePredefinedText(new LiteralText(message.getRaw()), StyledChatUtils.EMOTE_PATTERN, emotes),
player, false)
);

Expand All @@ -72,14 +71,14 @@ private void styledChat_replaceChatMessage(PlayerManager playerManager, Text ser

Text rawText = config.getChat(this.player,
StyledChatEvents.MESSAGE_CONTENT_SEND.invoker().onMessage(handlers.size() > 0
? TextParser.parse(rawMessage, handlers)
: new LiteralText(message.getRaw()),
? PlaceholderAPI.parsePredefinedText(TextParser.parse(rawMessage, handlers), StyledChatUtils.EMOTE_PATTERN, emotes)
: PlaceholderAPI.parsePredefinedText(new LiteralText(message.getRaw()), StyledChatUtils.EMOTE_PATTERN, emotes),
player, false)
);
Text filteredText = config.getChat(this.player,
StyledChatEvents.MESSAGE_CONTENT_SEND.invoker().onMessage(handlers.size() > 0
? TextParser.parse(filteredMessage, handlers)
: new LiteralText(message.getFiltered()),
? PlaceholderAPI.parsePredefinedText(TextParser.parse(filteredMessage, handlers), StyledChatUtils.EMOTE_PATTERN, emotes)
: PlaceholderAPI.parsePredefinedText(new LiteralText(message.getFiltered()), StyledChatUtils.EMOTE_PATTERN, emotes),
player, true)
);

Expand Down

0 comments on commit 2601d04

Please sign in to comment.