-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Added MiniPlaceholders support in plugin messages
- Loading branch information
Showing
2 changed files
with
64 additions
and
46 deletions.
There are no files selected for viewing
38 changes: 35 additions & 3 deletions
38
src/main/kotlin/io/github/_4drian3d/clientcatcher/Extensions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,47 @@ | ||
package io.github._4drian3d.clientcatcher | ||
|
||
import io.github.miniplaceholders.api.MiniPlaceholders | ||
import net.kyori.adventure.audience.Audience | ||
import net.kyori.adventure.text.minimessage.MiniMessage | ||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver | ||
|
||
fun String.asMiniMessage() = MiniMessage.miniMessage().deserialize(this) | ||
fun String.asMiniMessage(vararg resolvers: TagResolver) = MiniMessage.miniMessage().deserialize(this, *resolvers) | ||
fun String.asMiniMessage(resolver: TagResolver) = MiniMessage.miniMessage().deserialize(this, resolver) | ||
val hasMiniPlaceholders by lazy { | ||
try { | ||
Class.forName("io.github.miniplaceholders.api.MiniPlaceholders") | ||
true | ||
} catch (e: ClassNotFoundException) { | ||
false | ||
} | ||
} | ||
|
||
private fun String.asMiniMessage(resolvers: Array<out TagResolver>) = MiniMessage.miniMessage().deserialize(this, *resolvers) | ||
private fun String.asMiniMessage(resolver: TagResolver) = MiniMessage.miniMessage().deserialize(this, resolver) | ||
|
||
fun Audience.sendMini(message: String, resolver: TagResolver) { | ||
if (message.isNotBlank()) { | ||
val builder = TagResolver.builder().resolver(resolver) | ||
if (hasMiniPlaceholders) { | ||
builder.resolver(MiniPlaceholders.getAudienceGlobalPlaceholders(this)) | ||
} | ||
this.sendMessage(message.asMiniMessage(resolver)) | ||
} | ||
} | ||
|
||
fun Audience.sendMini(message: String, vararg resolver: TagResolver) { | ||
if (message.isNotBlank()) { | ||
val builder = TagResolver.builder().resolvers(*resolver) | ||
if (hasMiniPlaceholders) { | ||
builder.resolver(MiniPlaceholders.getAudienceGlobalPlaceholders(this)) | ||
} | ||
this.sendMessage(message.asMiniMessage(resolver)) | ||
} | ||
} | ||
|
||
fun Audience.sendMini(message: String) { | ||
if (message.isNotBlank()) { | ||
val resolver = | ||
if (hasMiniPlaceholders) MiniPlaceholders.getAudienceGlobalPlaceholders(this) | ||
else TagResolver.empty() | ||
this.sendMessage(message.asMiniMessage(resolver)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters