diff options
Diffstat (limited to 'src/main/kotlin/features/chat')
-rw-r--r-- | src/main/kotlin/features/chat/ChatLinks.kt | 9 | ||||
-rw-r--r-- | src/main/kotlin/features/chat/CopyChat.kt | 31 |
2 files changed, 36 insertions, 4 deletions
diff --git a/src/main/kotlin/features/chat/ChatLinks.kt b/src/main/kotlin/features/chat/ChatLinks.kt index a084234..1fb12e1 100644 --- a/src/main/kotlin/features/chat/ChatLinks.kt +++ b/src/main/kotlin/features/chat/ChatLinks.kt @@ -51,7 +51,7 @@ object ChatLinks : FirmamentFeature { private fun isUrlAllowed(url: String) = isHostAllowed(url.removePrefix("https://").substringBefore("/")) override val config get() = TConfig - val urlRegex = "https://[^. ]+\\.[^ ]+(\\.?( |$))".toRegex() + val urlRegex = "https://[^. ]+\\.[^ ]+(\\.?(\\s|$))".toRegex() val nextTexId = AtomicInteger(0) data class Image( @@ -139,19 +139,20 @@ object ChatLinks : FirmamentFeature { var index = 0 while (index < text.length) { val nextMatch = urlRegex.find(text, index) - if (nextMatch == null) { + val url = nextMatch?.groupValues[0] + val uri = runCatching { url?.let(::URI) }.getOrNull() + if (nextMatch == null || url == null || uri == null) { s.append(Text.literal(text.substring(index, text.length))) break } val range = nextMatch.groups[0]!!.range - val url = nextMatch.groupValues[0] s.append(Text.literal(text.substring(index, range.first))) s.append( Text.literal(url).setStyle( Style.EMPTY.withUnderline(true).withColor( Formatting.AQUA ).withHoverEvent(HoverEvent.ShowText(Text.literal(url))) - .withClickEvent(ClickEvent.OpenUrl(URI(url))) + .withClickEvent(ClickEvent.OpenUrl(uri)) ) ) if (isImageUrl(url)) diff --git a/src/main/kotlin/features/chat/CopyChat.kt b/src/main/kotlin/features/chat/CopyChat.kt new file mode 100644 index 0000000..64f8734 --- /dev/null +++ b/src/main/kotlin/features/chat/CopyChat.kt @@ -0,0 +1,31 @@ +package moe.nea.firmament.features.chat + +import net.minecraft.text.OrderedText +import moe.nea.firmament.annotations.Subscribe +import moe.nea.firmament.events.ClientStartedEvent +import moe.nea.firmament.features.FirmamentFeature +import moe.nea.firmament.gui.config.ManagedConfig +import moe.nea.firmament.util.reconstitute + + +object CopyChat : FirmamentFeature { + override val identifier: String + get() = "copy-chat" + + object TConfig : ManagedConfig(identifier, Category.CHAT) { + val copyChat by toggle("copy-chat") { false } + } + + @Subscribe + fun onInit(event: ClientStartedEvent) { + } + + override val config: ManagedConfig? + get() = TConfig + + fun orderedTextToString(orderedText: OrderedText): String { + return orderedText.reconstitute().string + } + + +} |