-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Used for placeholders that contains legacy format / MM tags
- Loading branch information
Showing
3 changed files
with
57 additions
and
6 deletions.
There are no files selected for viewing
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
43 changes: 43 additions & 0 deletions
43
plugin/src/main/kotlin/me/gabytm/minecraft/arcanevouchers/util/PapiMiniMessageTag.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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package me.gabytm.minecraft.arcanevouchers.util | ||
|
||
import me.gabytm.minecraft.arcanevouchers.functions.papi | ||
import net.kyori.adventure.text.Component | ||
import net.kyori.adventure.text.minimessage.Context | ||
import net.kyori.adventure.text.minimessage.tag.Tag | ||
import net.kyori.adventure.text.minimessage.tag.resolver.ArgumentQueue | ||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver | ||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer | ||
import org.bukkit.entity.Player | ||
|
||
class PapiMiniMessageTag(private val player: Player) : TagResolver { | ||
|
||
override fun resolve(name: String, arguments: ArgumentQueue, ctx: Context): Tag? { | ||
val placeholder = arguments.popOr("Placeholder argument not found").value() | ||
val parsed = "%$placeholder%".papi(player) | ||
|
||
// If the placeholder returns itself it means it is invalid | ||
if (parsed == "%$placeholder%") { | ||
return null | ||
} | ||
|
||
if (parsed.isEmpty()) { | ||
return Tag.inserting(Component.empty()) | ||
} | ||
|
||
if (LEGACY_REGEX.containsMatchIn(parsed)) { | ||
return Tag.inserting(LegacyComponentSerializer.legacyAmpersand().deserialize(parsed.replace('§', '&'))) | ||
} | ||
|
||
return Tag.inserting(ctx.deserialize(parsed)); | ||
} | ||
|
||
override fun has(name: String): Boolean = name == NAME | ||
|
||
companion object { | ||
|
||
private const val NAME: String = "papi" | ||
private val LEGACY_REGEX: Regex = Regex("[&|§][0-9A-FK-OR]", RegexOption.IGNORE_CASE) | ||
|
||
} | ||
|
||
} |
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