Search in sources :

Example 1 with InstantQueue

use of com.denizenscript.denizencore.scripts.queues.core.InstantQueue in project Denizen-For-Bukkit by DenizenScript.

the class ActionHandler method doAction.

public ListTag doAction(String actionName, NPCTag npc, PlayerTag player, AssignmentScriptContainer assignment, Map<String, ObjectTag> context) {
    if (context == null) {
        context = new HashMap<>();
    }
    if (assignment == null) {
        return null;
    }
    if (!assignment.containsScriptSection("actions.on " + actionName)) {
        return null;
    }
    Debug.report(assignment, "Action", ArgumentHelper.debugObj("Type", "On " + actionName), npc, assignment.getAsScriptArg(), player);
    // Fetch script from Actions
    List<ScriptEntry> script = assignment.getEntries(new BukkitScriptEntryData(player, npc), "actions.on " + actionName);
    if (script.isEmpty()) {
        return null;
    }
    Debug.echoDebug(assignment, DebugElement.Header, "Building action 'On " + actionName.toUpperCase() + "' for " + npc.toString());
    // Add entries and context to the queue
    ScriptQueue queue = new InstantQueue(assignment.getName());
    queue.addEntries(script);
    ContextSource.SimpleMap src = new ContextSource.SimpleMap();
    src.contexts = context;
    src.contexts.put("event_header", new ElementTag(actionName));
    queue.setContextSource(src);
    // Start the queue!
    queue.start();
    return queue.determinations;
}
Also used : BukkitScriptEntryData(com.denizenscript.denizen.utilities.implementation.BukkitScriptEntryData) ContextSource(com.denizenscript.denizencore.scripts.queues.ContextSource) ScriptEntry(com.denizenscript.denizencore.scripts.ScriptEntry) InstantQueue(com.denizenscript.denizencore.scripts.queues.core.InstantQueue) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) ScriptQueue(com.denizenscript.denizencore.scripts.queues.ScriptQueue)

Example 2 with InstantQueue

use of com.denizenscript.denizencore.scripts.queues.core.InstantQueue in project Denizen-For-Bukkit by DenizenScript.

the class AbstractTrigger method parse.

public boolean parse(NPCTag npc, PlayerTag player, InteractScriptContainer script, String id, Map<String, ObjectTag> context) {
    if (npc == null || player == null || script == null) {
        return false;
    }
    List<ScriptEntry> entries = script.getEntriesFor(this.getClass(), player, npc, id, true);
    if (entries.isEmpty()) {
        return false;
    }
    Debug.echoDebug(script, DebugElement.Header, "Parsing " + name + " trigger: n@" + npc.getName() + "/p@" + player.getName());
    // Create Queue
    long speedTicks;
    if (script.contains("SPEED", String.class)) {
        speedTicks = DurationTag.valueOf(script.getString("SPEED", "0"), new BukkitTagContext(script)).getTicks();
    } else {
        speedTicks = DurationTag.valueOf(Settings.interactQueueSpeed(), new BukkitTagContext(script)).getTicks();
    }
    ScriptQueue queue;
    if (speedTicks > 0) {
        queue = new TimedQueue(script.getName()).setSpeed(speedTicks);
    } else {
        queue = new InstantQueue(script.getName());
    }
    // Add all entries to set it up
    queue.addEntries(entries);
    // Add context
    if (context != null) {
        ContextSource.SimpleMap src = new ContextSource.SimpleMap();
        src.contexts = context;
        queue.setContextSource(src);
    }
    if (!npc.getTriggerTrait().properly_set.get(name)) {
        if (missetWarning.testShouldWarn()) {
            Debug.echoError(missetWarning.message.replace("{NAME}", name).replace("{NPC}", npc.getId() + "/" + npc.getName()));
        }
    }
    // Start it
    queue.start();
    return true;
}
Also used : BukkitTagContext(com.denizenscript.denizen.tags.BukkitTagContext) ContextSource(com.denizenscript.denizencore.scripts.queues.ContextSource) ScriptEntry(com.denizenscript.denizencore.scripts.ScriptEntry) TimedQueue(com.denizenscript.denizencore.scripts.queues.core.TimedQueue) InstantQueue(com.denizenscript.denizencore.scripts.queues.core.InstantQueue) ScriptQueue(com.denizenscript.denizencore.scripts.queues.ScriptQueue)

Example 3 with InstantQueue

use of com.denizenscript.denizencore.scripts.queues.core.InstantQueue in project Denizen-For-Bukkit by DenizenScript.

the class CommandScriptContainer method runAllowedHelpProcedure.

public boolean runAllowedHelpProcedure(PlayerTag player, NPCTag npc, Map<String, ObjectTag> context) {
    List<ScriptEntry> entries = getEntries(new BukkitScriptEntryData(player, npc), "allowed help");
    ScriptQueue queue = new InstantQueue(getName());
    queue.addEntries(entries);
    if (context != null) {
        ContextSource.SimpleMap src = new ContextSource.SimpleMap();
        src.contexts = context;
        queue.setContextSource(src);
    }
    queue.start();
    return queue.determinations != null && queue.determinations.size() > 0 && queue.determinations.get(0).equalsIgnoreCase("true");
}
Also used : BukkitScriptEntryData(com.denizenscript.denizen.utilities.implementation.BukkitScriptEntryData) ContextSource(com.denizenscript.denizencore.scripts.queues.ContextSource) ScriptEntry(com.denizenscript.denizencore.scripts.ScriptEntry) InstantQueue(com.denizenscript.denizencore.scripts.queues.core.InstantQueue) ScriptQueue(com.denizenscript.denizencore.scripts.queues.ScriptQueue)

Example 4 with InstantQueue

use of com.denizenscript.denizencore.scripts.queues.core.InstantQueue 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 5 with InstantQueue

use of com.denizenscript.denizencore.scripts.queues.core.InstantQueue in project Denizen-For-Bukkit by DenizenScript.

the class ExCommandHandler method onCommand.

@Override
public boolean onCommand(CommandSender sender, Command cmd, String alias, String[] args) {
    if (cmd.getName().equalsIgnoreCase("ex")) {
        List<Object> entries = new ArrayList<>();
        String entry = String.join(" ", args);
        boolean quiet = !Settings.showExDebug();
        if (entry.length() > 3 && entry.startsWith("-q ")) {
            quiet = !quiet;
            entry = entry.substring("-q ".length());
        }
        if (entry.length() < 2) {
            sender.sendMessage("/ex (-q) <denizen script command> (arguments)");
            return true;
        }
        if (Settings.showExHelp()) {
            if (Debug.showDebug) {
                if (quiet) {
                    sender.sendMessage(ChatColor.YELLOW + "Executing Denizen script command... check the console for full debug output!");
                } else {
                // sender.sendMessage(ChatColor.YELLOW + "Executing Denizen script command...");
                }
            } else {
                sender.sendMessage(ChatColor.YELLOW + "Executing Denizen script command... to see debug, use /denizen debug");
            }
        }
        entries.add(entry);
        InstantQueue queue = new InstantQueue("EXCOMMAND");
        NPCTag npc = null;
        if (Depends.citizens != null && Depends.citizens.getNPCSelector().getSelected(sender) != null) {
            npc = new NPCTag(Depends.citizens.getNPCSelector().getSelected(sender));
        }
        List<ScriptEntry> scriptEntries = ScriptBuilder.buildScriptEntries(entries, null, new BukkitScriptEntryData(sender instanceof Player ? new PlayerTag((Player) sender) : null, npc));
        queue.addEntries(scriptEntries);
        if (!quiet && sender instanceof Player) {
            final Player player = (Player) sender;
            queue.debugOutput = (s) -> {
                player.spigot().sendMessage(FormattedTextHelper.parse(s, net.md_5.bungee.api.ChatColor.WHITE));
            };
        }
        queue.start();
        return true;
    }
    return false;
}
Also used : Player(org.bukkit.entity.Player) BukkitScriptEntryData(com.denizenscript.denizen.utilities.implementation.BukkitScriptEntryData) PlayerTag(com.denizenscript.denizen.objects.PlayerTag) ArrayList(java.util.ArrayList) NPCTag(com.denizenscript.denizen.objects.NPCTag) InstantQueue(com.denizenscript.denizencore.scripts.queues.core.InstantQueue) ScriptEntry(com.denizenscript.denizencore.scripts.ScriptEntry)

Aggregations

InstantQueue (com.denizenscript.denizencore.scripts.queues.core.InstantQueue)8 ScriptEntry (com.denizenscript.denizencore.scripts.ScriptEntry)7 BukkitScriptEntryData (com.denizenscript.denizen.utilities.implementation.BukkitScriptEntryData)6 ContextSource (com.denizenscript.denizencore.scripts.queues.ContextSource)6 ScriptQueue (com.denizenscript.denizencore.scripts.queues.ScriptQueue)5 BukkitTagContext (com.denizenscript.denizen.tags.BukkitTagContext)2 ElementTag (com.denizenscript.denizencore.objects.core.ElementTag)2 ScriptTag (com.denizenscript.denizencore.objects.core.ScriptTag)2 ArrayList (java.util.ArrayList)2 EntityTag (com.denizenscript.denizen.objects.EntityTag)1 InventoryTag (com.denizenscript.denizen.objects.InventoryTag)1 ItemTag (com.denizenscript.denizen.objects.ItemTag)1 NPCTag (com.denizenscript.denizen.objects.NPCTag)1 PlayerTag (com.denizenscript.denizen.objects.PlayerTag)1 ListTag (com.denizenscript.denizencore.objects.core.ListTag)1 TimedQueue (com.denizenscript.denizencore.scripts.queues.core.TimedQueue)1 YamlConfiguration (com.denizenscript.denizencore.utilities.YamlConfiguration)1 StringHolder (com.denizenscript.denizencore.utilities.text.StringHolder)1 List (java.util.List)1 Player (org.bukkit.entity.Player)1