Search in sources :

Example 1 with SimpleDefinitionProvider

use of com.denizenscript.denizencore.utilities.SimpleDefinitionProvider in project Denizen-For-Bukkit by DenizenScript.

the class FormatScriptContainer method getFormattedText.

public String getFormattedText(String textToReplace, NPCTag npc, PlayerTag player) {
    String name = npc != null ? npc.getName() : (player != null ? player.getName() : "");
    String text = getFormat();
    if (text.contains("<text") || text.contains("<name")) {
        Deprecations.pseudoTagBases.warn(this);
        text = text.replace("<text", "<element[" + EscapeTagBase.escape(textToReplace) + "].unescaped").replace("<name", "<element[" + EscapeTagBase.escape(name) + "].unescaped");
    }
    BukkitTagContext context = new BukkitTagContext(player, npc, new ScriptTag(this));
    context.definitionProvider = new SimpleDefinitionProvider();
    context.definitionProvider.addDefinition("text", new ElementTag(textToReplace));
    context.definitionProvider.addDefinition("name", new ElementTag(name));
    return TagManager.tag(text, context);
}
Also used : BukkitTagContext(com.denizenscript.denizen.tags.BukkitTagContext) ScriptTag(com.denizenscript.denizencore.objects.core.ScriptTag) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) SimpleDefinitionProvider(com.denizenscript.denizencore.utilities.SimpleDefinitionProvider)

Aggregations

BukkitTagContext (com.denizenscript.denizen.tags.BukkitTagContext)1 ElementTag (com.denizenscript.denizencore.objects.core.ElementTag)1 ScriptTag (com.denizenscript.denizencore.objects.core.ScriptTag)1 SimpleDefinitionProvider (com.denizenscript.denizencore.utilities.SimpleDefinitionProvider)1