Search in sources :

Example 1 with ContextSource

use of com.denizenscript.denizencore.scripts.queues.ContextSource 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)

Aggregations

BukkitTagContext (com.denizenscript.denizen.tags.BukkitTagContext)1 BukkitScriptEntryData (com.denizenscript.denizen.utilities.implementation.BukkitScriptEntryData)1 ScriptTag (com.denizenscript.denizencore.objects.core.ScriptTag)1 ScriptEntry (com.denizenscript.denizencore.scripts.ScriptEntry)1 ContextSource (com.denizenscript.denizencore.scripts.queues.ContextSource)1 ScriptQueue (com.denizenscript.denizencore.scripts.queues.ScriptQueue)1 InstantQueue (com.denizenscript.denizencore.scripts.queues.core.InstantQueue)1 ArrayList (java.util.ArrayList)1