Skip to content

Commit 41b74e9

Browse files
committed
Reapply "Reapply "underlined links""
This reverts commit 1770f36.
1 parent 01a3d0c commit 41b74e9

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package org.polyfrost.chatting.mixin;
2+
3+
import net.minecraft.event.ClickEvent;
4+
import net.minecraft.util.ChatStyle;
5+
import net.minecraft.util.EnumChatFormatting;
6+
import org.polyfrost.chatting.config.ChattingConfig;
7+
import org.spongepowered.asm.mixin.Mixin;
8+
import org.spongepowered.asm.mixin.Shadow;
9+
import org.spongepowered.asm.mixin.Unique;
10+
import org.spongepowered.asm.mixin.injection.At;
11+
import org.spongepowered.asm.mixin.injection.Inject;
12+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
13+
14+
@Mixin(ChatStyle.class)
15+
public class ChatStyleMixin {
16+
@Shadow
17+
private ClickEvent chatClickEvent;
18+
19+
@Unique
20+
private boolean chatting$hasURL() {
21+
return ChattingConfig.INSTANCE.getUnderlinedLinks()
22+
&& chatClickEvent != null
23+
&& chatClickEvent.getAction() == ClickEvent.Action.OPEN_URL;
24+
}
25+
26+
@Inject(method = "getUnderlined", at = @At("HEAD"), cancellable = true)
27+
private void linkUnderline(CallbackInfoReturnable<Boolean> cir) {
28+
if (chatting$hasURL()) {
29+
cir.setReturnValue(true);
30+
}
31+
}
32+
33+
@Inject(method = "getColor", at = @At("HEAD"), cancellable = true)
34+
private void linkColor(CallbackInfoReturnable<EnumChatFormatting> cir) {
35+
if (chatting$hasURL()) {
36+
cir.setReturnValue(EnumChatFormatting.BLUE);
37+
}
38+
}
39+
}

src/main/kotlin/org/polyfrost/chatting/config/ChattingConfig.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,13 @@ object ChattingConfig : Config(
8282
)
8383
var peekMode = false
8484

85+
@Switch(
86+
name = "Underlined Links", category = "General",
87+
description = "Makes clickable links in chat blue and underlined.",
88+
size = 1
89+
)
90+
var underlinedLinks = true
91+
8592
@Switch(
8693
name = "Smooth Chat Messages",
8794
category = "Animations", subcategory = "Messages",

src/main/resources/mixins.chatting.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,8 @@
2525
"GuiUtilsMixin",
2626
"HUDUtilsMixin",
2727
"InventoryPlayerMixin"
28+
],
29+
"mixins": [
30+
"ChatStyleMixin"
2831
]
2932
}

0 commit comments

Comments
 (0)