Search in sources :

Example 1 with TimedQueue

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

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

the class ExSustainedCommandHandler method getOrMakeQueue.

public TimedQueue getOrMakeQueue(final Player player, boolean quiet) {
    UUID id;
    if (player == null) {
        id = new UUID(0, 0);
    } else {
        id = player.getUniqueId();
    }
    TimedQueue queue = playerQueues.get(id);
    if (queue != null && !queue.isStopped) {
        return queue;
    }
    queue = new TimedQueue("EX_SUSTAINED_COMMAND", 0);
    queue.waitWhenEmpty = true;
    playerQueues.put(id, queue);
    return queue;
}
Also used : TimedQueue(com.denizenscript.denizencore.scripts.queues.core.TimedQueue) UUID(java.util.UUID)

Example 3 with TimedQueue

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

the class ExSustainedCommandHandler method onCommand.

@Override
public boolean onCommand(CommandSender sender, Command cmd, String alias, String[] args) {
    if (cmd.getName().equalsIgnoreCase("exs")) {
        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("/exs (-q) <denizen script command> (arguments)");
            return true;
        }
        TimedQueue queue = getOrMakeQueue(sender instanceof Player ? (Player) sender : null, quiet);
        if (!quiet && sender instanceof Player) {
            Player player = (Player) sender;
            queue.debugOutput = (s) -> {
                player.spigot().sendMessage(FormattedTextHelper.parse(s, net.md_5.bungee.api.ChatColor.WHITE));
            };
        } else {
            queue.debugOutput = null;
        }
        if (queue.isPaused() || queue.isDelayed()) {
            sender.sendMessage(ChatColor.YELLOW + "Sustained queue is currently paused or waiting, adding command to queue for later execution.");
        } else 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);
        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 (!queue.is_started) {
            queue.start();
        } else {
            queue.onStart();
        }
        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) TimedQueue(com.denizenscript.denizencore.scripts.queues.core.TimedQueue) ScriptEntry(com.denizenscript.denizencore.scripts.ScriptEntry)

Aggregations

TimedQueue (com.denizenscript.denizencore.scripts.queues.core.TimedQueue)3 ScriptEntry (com.denizenscript.denizencore.scripts.ScriptEntry)2 NPCTag (com.denizenscript.denizen.objects.NPCTag)1 PlayerTag (com.denizenscript.denizen.objects.PlayerTag)1 BukkitTagContext (com.denizenscript.denizen.tags.BukkitTagContext)1 BukkitScriptEntryData (com.denizenscript.denizen.utilities.implementation.BukkitScriptEntryData)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 UUID (java.util.UUID)1 Player (org.bukkit.entity.Player)1