Search in sources :

Example 16 with ScriptTag

use of com.denizenscript.denizencore.objects.core.ScriptTag in project Denizen-For-Bukkit by DenizenScript.

the class BookScriptContainer method writeBookTo.

public ItemTag writeBookTo(ItemTag book, TagContext context) {
    if (context == null) {
        context = new BukkitTagContext(null, null, new ScriptTag(this));
    }
    // Get current ItemMeta from the book
    BookMeta bookInfo = (BookMeta) book.getItemMeta();
    if (contains("title", String.class)) {
        String title = getString("title");
        title = TagManager.tag(title, context);
        bookInfo.setTitle(title);
    }
    if (contains("signed", String.class)) {
        if (getString("signed").equalsIgnoreCase("false")) {
            book.getItemStack().setType(Material.WRITABLE_BOOK);
        }
    }
    if (contains("author", String.class)) {
        String author = getString("author");
        author = TagManager.tag(author, context);
        bookInfo.setAuthor(author);
    }
    if (contains("text", List.class)) {
        List<String> pages = getStringList("text");
        for (String page : pages) {
            page = TagManager.tag(page, context);
            bookInfo.spigot().addPage(FormattedTextHelper.parse(page, ChatColor.BLACK));
        }
    }
    book.setItemMeta(bookInfo);
    return book;
}
Also used : BukkitTagContext(com.denizenscript.denizen.tags.BukkitTagContext) ScriptTag(com.denizenscript.denizencore.objects.core.ScriptTag) BookMeta(org.bukkit.inventory.meta.BookMeta)

Example 17 with ScriptTag

use of com.denizenscript.denizencore.objects.core.ScriptTag in project Denizen-For-Bukkit by DenizenScript.

the class CommandScriptContainer method runTabCompleteProcedure.

public List<String> runTabCompleteProcedure(PlayerTag player, NPCTag npc, Map<String, ObjectTag> context, String[] originalArguments) {
    BukkitTagContext tagContext = new BukkitTagContext(player, npc, new ScriptTag(this));
    ContextSource contextSrc = null;
    if (context != null) {
        ContextSource.SimpleMap src = new ContextSource.SimpleMap();
        src.contexts = context;
        tagContext.contextSource = src;
        contextSrc = src;
    }
    List<String> list = new ArrayList<>();
    if (tabCompletionTaggables != null) {
        int argCount = Math.max(originalArguments.length, 1);
        String taggable = tabCompletionTaggables.get(argCount);
        if (taggable == null) {
            taggable = tabCompletionTaggables.get(-1);
        }
        if (taggable != null) {
            String argLow = originalArguments.length == 0 ? "" : CoreUtilities.toLowerCase(originalArguments[originalArguments.length - 1]);
            for (String value : ListTag.getListFor(TagManager.tagObject(taggable, tagContext), tagContext)) {
                if (CoreUtilities.toLowerCase(value).startsWith(argLow)) {
                    list.add(value);
                }
            }
        }
    }
    if (hasProcStyleTabComplete) {
        List<ScriptEntry> entries = getEntries(new BukkitScriptEntryData(player, npc), "tab complete");
        ScriptQueue queue = new InstantQueue(getName());
        queue.addEntries(entries);
        if (contextSrc != null) {
            queue.setContextSource(contextSrc);
        }
        queue.start();
        if (queue.determinations != null && queue.determinations.size() > 0) {
            list.addAll(ListTag.getListFor(queue.determinations.getObject(0), tagContext));
        }
    }
    return list;
}
Also used : ArrayList(java.util.ArrayList) ScriptEntry(com.denizenscript.denizencore.scripts.ScriptEntry) BukkitTagContext(com.denizenscript.denizen.tags.BukkitTagContext) BukkitScriptEntryData(com.denizenscript.denizen.utilities.implementation.BukkitScriptEntryData) ScriptTag(com.denizenscript.denizencore.objects.core.ScriptTag) ContextSource(com.denizenscript.denizencore.scripts.queues.ContextSource) InstantQueue(com.denizenscript.denizencore.scripts.queues.core.InstantQueue) ScriptQueue(com.denizenscript.denizencore.scripts.queues.ScriptQueue)

Example 18 with ScriptTag

use of com.denizenscript.denizencore.objects.core.ScriptTag in project Denizen-For-Bukkit by DenizenScript.

the class EnchantmentScriptContainer method autoTag.

public String autoTag(String value, ContextSource src) {
    if (value == null) {
        return null;
    }
    validateThread();
    TagContext context = new BukkitTagContext(null, new ScriptTag(this));
    context.contextSource = src;
    return TagManager.tag(value, context);
}
Also used : BukkitTagContext(com.denizenscript.denizen.tags.BukkitTagContext) TagContext(com.denizenscript.denizencore.tags.TagContext) BukkitTagContext(com.denizenscript.denizen.tags.BukkitTagContext) ScriptTag(com.denizenscript.denizencore.objects.core.ScriptTag)

Example 19 with ScriptTag

use of com.denizenscript.denizencore.objects.core.ScriptTag in project Denizen-For-Bukkit by DenizenScript.

the class EntityScriptHelper method setEntityScript.

/**
 * Marks the entity as having been created by a specified script.
 */
public static void setEntityScript(Entity ent, String script) {
    if (ent == null || ent.getUniqueId() == null || script == null) {
        return;
    }
    ScriptTag scriptObj = ScriptTag.valueOf(script, CoreUtilities.basicContext);
    if (scriptObj == null) {
        Debug.echoError("Can't set entity script to '" + script + "': not a valid script!");
    }
    DataPersistenceHelper.setDenizenKey(ent, "entity_script", scriptObj);
    return;
}
Also used : ScriptTag(com.denizenscript.denizencore.objects.core.ScriptTag)

Example 20 with ScriptTag

use of com.denizenscript.denizencore.objects.core.ScriptTag in project Denizen-For-Bukkit by DenizenScript.

the class FormatScriptContainer method getFormatText.

public String getFormatText(NPCTag npc, PlayerTag player) {
    String text = getFormat();
    if (text.contains("<text") || text.contains("<name")) {
        Deprecations.pseudoTagBases.warn(this);
        text = text.replace("<text>", String.valueOf((char) 0x00)).replace("<name>", String.valueOf((char) 0x04));
    }
    text = text.replace("<[text]>", String.valueOf((char) 0x00)).replace("<[name]>", String.valueOf((char) 0x04));
    return TagManager.tag(text, new BukkitTagContext(player, npc, new ScriptTag(this))).replace("%", "%%").replace(String.valueOf((char) 0x00), "%2$s").replace(String.valueOf((char) 0x04), "%1$s");
}
Also used : BukkitTagContext(com.denizenscript.denizen.tags.BukkitTagContext) ScriptTag(com.denizenscript.denizencore.objects.core.ScriptTag)

Aggregations

ScriptTag (com.denizenscript.denizencore.objects.core.ScriptTag)38 ElementTag (com.denizenscript.denizencore.objects.core.ElementTag)17 BukkitTagContext (com.denizenscript.denizen.tags.BukkitTagContext)16 PlayerTag (com.denizenscript.denizen.objects.PlayerTag)8 ListTag (com.denizenscript.denizencore.objects.core.ListTag)8 List (java.util.List)7 ItemTag (com.denizenscript.denizen.objects.ItemTag)5 InvalidArgumentsException (com.denizenscript.denizencore.exceptions.InvalidArgumentsException)5 ObjectTag (com.denizenscript.denizencore.objects.ObjectTag)5 DurationTag (com.denizenscript.denizencore.objects.core.DurationTag)5 EntityTag (com.denizenscript.denizen.objects.EntityTag)4 LocationTag (com.denizenscript.denizen.objects.LocationTag)4 FormatScriptContainer (com.denizenscript.denizen.scripts.containers.core.FormatScriptContainer)4 ScriptEntry (com.denizenscript.denizencore.scripts.ScriptEntry)4 Player (org.bukkit.entity.Player)4 ImprovedOfflinePlayer (com.denizenscript.denizen.nms.abstracts.ImprovedOfflinePlayer)3 NPCTag (com.denizenscript.denizen.objects.NPCTag)3 AssignmentScriptContainer (com.denizenscript.denizen.scripts.containers.core.AssignmentScriptContainer)3 InteractScriptContainer (com.denizenscript.denizen.scripts.containers.core.InteractScriptContainer)3 ScriptQueue (com.denizenscript.denizencore.scripts.queues.ScriptQueue)3