Search in sources :

Example 11 with ScriptEntry

use of com.denizenscript.denizencore.scripts.ScriptEntry 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 12 with ScriptEntry

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

Example 13 with ScriptEntry

use of com.denizenscript.denizencore.scripts.ScriptEntry in project Denizen-For-Bukkit by DenizenScript.

the class DenizenCoreImplementation method setSpecialDef.

@Override
public boolean setSpecialDef(String def, ScriptQueue queue, ObjectTag value) {
    if (def.equals("__player")) {
        BukkitScriptEntryData baseData = getScriptEntryData(queue);
        if (baseData == null) {
            return true;
        }
        PlayerTag player = value == null ? null : value.asType(PlayerTag.class, baseData.getTagContext());
        if (queue.getLastEntryExecuted() != null) {
            ((BukkitScriptEntryData) queue.getLastEntryExecuted().entryData).setPlayer(player);
        }
        for (ScriptEntry entry : queue.getEntries()) {
            ((BukkitScriptEntryData) entry.entryData).setPlayer(player);
        }
        return true;
    } else if (def.equals("__npc")) {
        BukkitScriptEntryData baseData = getScriptEntryData(queue);
        if (baseData == null) {
            return true;
        }
        NPCTag npc = value == null ? null : value.asType(NPCTag.class, baseData.getTagContext());
        if (queue.getLastEntryExecuted() != null) {
            ((BukkitScriptEntryData) queue.getLastEntryExecuted().entryData).setNPC(npc);
        }
        for (ScriptEntry entry : queue.getEntries()) {
            ((BukkitScriptEntryData) entry.entryData).setNPC(npc);
        }
        return true;
    }
    return false;
}
Also used : ScriptEntry(com.denizenscript.denizencore.scripts.ScriptEntry)

Example 14 with ScriptEntry

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

Example 15 with ScriptEntry

use of com.denizenscript.denizencore.scripts.ScriptEntry in project Denizen-For-Bukkit by DenizenScript.

the class BukkitQueueProperties method adjust.

@Override
public void adjust(Mechanism mechanism) {
    // -->
    if (mechanism.matches("linked_player") && mechanism.requireObject(PlayerTag.class)) {
        PlayerTag player = mechanism.valueAsType(PlayerTag.class);
        for (ScriptEntry entry : queue.getEntries()) {
            BukkitScriptEntryData data = (BukkitScriptEntryData) entry.entryData;
            data.setPlayer(player);
        }
    }
    // -->
    if (mechanism.matches("linked_npc") && mechanism.requireObject(NPCTag.class)) {
        NPCTag npc = mechanism.valueAsType(NPCTag.class);
        for (ScriptEntry entry : queue.getEntries()) {
            BukkitScriptEntryData data = (BukkitScriptEntryData) entry.entryData;
            data.setNPC(npc);
        }
    }
}
Also used : PlayerTag(com.denizenscript.denizen.objects.PlayerTag) BukkitScriptEntryData(com.denizenscript.denizen.utilities.implementation.BukkitScriptEntryData) NPCTag(com.denizenscript.denizen.objects.NPCTag) ScriptEntry(com.denizenscript.denizencore.scripts.ScriptEntry)

Aggregations

ScriptEntry (com.denizenscript.denizencore.scripts.ScriptEntry)23 ElementTag (com.denizenscript.denizencore.objects.core.ElementTag)11 EntityTag (com.denizenscript.denizen.objects.EntityTag)10 InvalidArgumentsException (com.denizenscript.denizencore.exceptions.InvalidArgumentsException)9 NPCTag (com.denizenscript.denizen.objects.NPCTag)8 PlayerTag (com.denizenscript.denizen.objects.PlayerTag)8 ListTag (com.denizenscript.denizencore.objects.core.ListTag)8 AbstractCommand (com.denizenscript.denizencore.scripts.commands.AbstractCommand)8 List (java.util.List)8 Debug (com.denizenscript.denizen.utilities.debugging.Debug)7 BukkitScriptEntryData (com.denizenscript.denizen.utilities.implementation.BukkitScriptEntryData)7 ScriptQueue (com.denizenscript.denizencore.scripts.queues.ScriptQueue)7 InstantQueue (com.denizenscript.denizencore.scripts.queues.core.InstantQueue)7 NMSHandler (com.denizenscript.denizen.nms.NMSHandler)6 Utilities (com.denizenscript.denizen.utilities.Utilities)6 Argument (com.denizenscript.denizencore.objects.Argument)6 ContextSource (com.denizenscript.denizencore.scripts.queues.ContextSource)5 Player (org.bukkit.entity.Player)5 Denizen (com.denizenscript.denizen.Denizen)4 LocationTag (com.denizenscript.denizen.objects.LocationTag)4