mirror of
https://github.com/HibiscusMC/HibiscusCommons.git
synced 2025-12-19 15:09:26 +00:00
feat: add papi tag handler
This commit is contained in:
@@ -10,7 +10,7 @@ plugins {
|
|||||||
}
|
}
|
||||||
|
|
||||||
group = "me.lojosho"
|
group = "me.lojosho"
|
||||||
version = "0.2.8"
|
version = "0.2.8-DEV"
|
||||||
|
|
||||||
allprojects {
|
allprojects {
|
||||||
apply(plugin = "java")
|
apply(plugin = "java")
|
||||||
|
|||||||
@@ -1,8 +1,14 @@
|
|||||||
package me.lojosho.hibiscuscommons.util;
|
package me.lojosho.hibiscuscommons.util;
|
||||||
|
|
||||||
|
import me.lojosho.hibiscuscommons.hooks.Hooks;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||||
|
import net.kyori.adventure.text.minimessage.tag.Tag;
|
||||||
|
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||||
import net.kyori.adventure.text.minimessage.tag.standard.StandardTags;
|
import net.kyori.adventure.text.minimessage.tag.standard.StandardTags;
|
||||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class AdventureUtils {
|
public class AdventureUtils {
|
||||||
|
|
||||||
@@ -16,4 +22,27 @@ public class AdventureUtils {
|
|||||||
).
|
).
|
||||||
build();
|
build();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a tag resolver capable of resolving PlaceholderAPI tags for a given player.
|
||||||
|
* Credit to mbaxter, <a href="https://gist.github.com/kezz/ff1bcb8c8db4e113e0119c210026d5ad">...</a>
|
||||||
|
*
|
||||||
|
* @param player the player
|
||||||
|
* @return the tag resolver
|
||||||
|
*/
|
||||||
|
public @NotNull TagResolver papiTag(final @NotNull Player player) {
|
||||||
|
return TagResolver.resolver("papi", (argumentQueue, context) -> {
|
||||||
|
// Get the string placeholder that they want to use.
|
||||||
|
final String papiPlaceholder = argumentQueue.popOr("papi tag requires an argument").value();
|
||||||
|
|
||||||
|
// Then get PAPI to parse the placeholder for the given player.
|
||||||
|
final String parsedPlaceholder = Hooks.processPlaceholders(player, '%' + papiPlaceholder + '%');
|
||||||
|
|
||||||
|
// We need to turn this ugly legacy string into a nice component.
|
||||||
|
final Component componentPlaceholder = LegacyComponentSerializer.legacySection().deserialize(parsedPlaceholder);
|
||||||
|
|
||||||
|
// Finally, return the tag instance to insert the placeholder!
|
||||||
|
return Tag.selfClosingInserting(componentPlaceholder);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user