Skip to content

Commit

Permalink
*: (MiniPlaceholders Integration) deprecate 'unemoji', add 'creativel…
Browse files Browse the repository at this point in the history
…glyphs'
  • Loading branch information
yusshu committed Feb 3, 2024
1 parent 2cbe660 commit 4a76b47
Showing 1 changed file with 32 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,26 @@

import io.github.miniplaceholders.api.Expansion;
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 org.bukkit.plugin.Plugin;
import org.jetbrains.annotations.NotNull;
import team.unnamed.creativeglyphs.Glyph;
import team.unnamed.creativeglyphs.plugin.CreativeGlyphsPlugin;
import team.unnamed.creativeglyphs.plugin.integration.PluginIntegration;
import team.unnamed.creativeglyphs.plugin.PluginGlyphMap;

import java.util.function.BiFunction;

import static java.util.Objects.requireNonNull;

public final class MiniPlaceholdersIntegration implements PluginIntegration {
private final PluginGlyphMap registry;
private final CreativeGlyphsPlugin plugin;
private boolean warnAboutDeprecation = true;

public MiniPlaceholdersIntegration(final PluginGlyphMap registry) {
this.registry = registry;
public MiniPlaceholdersIntegration(final @NotNull CreativeGlyphsPlugin plugin) {
this.plugin = requireNonNull(plugin, "plugin");
}

@Override
Expand All @@ -22,16 +30,30 @@ public MiniPlaceholdersIntegration(final PluginGlyphMap registry) {
}

@Override
public void enable(final @NotNull Plugin hook) {
public void enable(final @NotNull Plugin miniPlaceholders) {
final var placeholder = (BiFunction<ArgumentQueue, Context, Tag>) (queue, ctx) -> {
final var argument = queue.popOr("You need to provide an argument");
final var glyph = plugin.registry().getByName(argument.value());
if (glyph == null) {
return null;
} else {
return Tag.selfClosingInserting(Component.text(glyph.replacement()));
}
};

Expansion.builder("creativeglyphs")
.globalPlaceholder("glyph", placeholder)
.build()
.register();

Expansion.builder("unemoji")
.globalPlaceholder("emoji", (queue, ctx) -> {
final Tag.Argument argument = queue.popOr("You need to provide an argument");
Glyph glyph = registry.getByName(argument.value());
if (glyph == null) {
return null;
} else {
return Tag.selfClosingInserting(Component.text(glyph.replacement()));
if (warnAboutDeprecation) {
plugin.getLogger().warning("(MiniPlaceholders Integration) Detected usage of deprecated" +
" placeholder format: '<unemoji_emoji:NAME>', please use '<creativeglyphs_glyph:NAME>' instead.");
warnAboutDeprecation = false;
}
return placeholder.apply(queue, ctx);
})
.build()
.register();
Expand Down

0 comments on commit 4a76b47

Please sign in to comment.