Search in sources :

Example 1 with BukkitScriptEntryData

use of com.denizenscript.denizen.utilities.implementation.BukkitScriptEntryData in project Denizen-For-Bukkit by DenizenScript.

the class BukkitScriptProperties method registerTags.

public static void registerTags() {
    // <--[tag]
    // @attribute <ScriptTag.cooled_down[<player>]>
    // @returns ElementTag(Boolean)
    // @description
    // Returns whether the script is currently cooled down for the player. Any global
    // cooldown present on the script will also be taken into account. Not specifying a player will result in
    // using the attached player available in the script entry. Not having a valid player will result in 'null'.
    // -->
    PropertyParser.<BukkitScriptProperties, ElementTag>registerTag(ElementTag.class, "cooled_down", (attribute, script) -> {
        PlayerTag player = (attribute.hasParam() ? attribute.paramAsType(PlayerTag.class) : ((BukkitScriptEntryData) attribute.getScriptEntry().entryData).getPlayer());
        if (player != null && player.isValid()) {
            return new ElementTag(CooldownCommand.checkCooldown(player, script.script.getContainer().getName()));
        } else {
            return null;
        }
    });
    // <--[tag]
    // @attribute <ScriptTag.cooldown[<player>]>
    // @returns DurationTag
    // @description
    // Returns the time left for the player to cooldown for the script.
    // -->
    PropertyParser.<BukkitScriptProperties, DurationTag>registerTag(DurationTag.class, "cooldown", (attribute, script) -> {
        PlayerTag player = (attribute.hasParam() ? attribute.paramAsType(PlayerTag.class) : ((BukkitScriptEntryData) attribute.getScriptEntry().entryData).getPlayer());
        return CooldownCommand.getCooldownDuration(player, script.script.getName());
    });
    // <--[tag]
    // @attribute <ScriptTag.step[(<player>)]>
    // @returns ElementTag
    // @description
    // Returns the name of a script step that the player is currently on.
    // Must be an INTERACT script.
    // -->
    PropertyParser.<BukkitScriptProperties, ElementTag>registerTag(ElementTag.class, "step", (attribute, script) -> {
        PlayerTag player = attribute.hasParam() ? attribute.paramAsType(PlayerTag.class) : ((BukkitScriptEntryData) attribute.getScriptEntry().entryData).getPlayer();
        if (player != null && player.isValid()) {
            return new ElementTag(InteractScriptHelper.getCurrentStep(player, script.script.getContainer().getName()));
        } else {
            return null;
        }
    });
    // <--[tag]
    // @attribute <ScriptTag.step_expiration[(<player>)]>
    // @returns TimeTag
    // @description
    // Returns the time that an interact script step expires at, if applied by <@link command zap> with a duration limit.
    // -->
    PropertyParser.<BukkitScriptProperties, TimeTag>registerTag(TimeTag.class, "step_expiration", (attribute, script) -> {
        PlayerTag player = attribute.hasParam() ? attribute.paramAsType(PlayerTag.class) : ((BukkitScriptEntryData) attribute.getScriptEntry().entryData).getPlayer();
        if (player != null && player.isValid()) {
            return InteractScriptHelper.getStepExpiration(player, script.script.getContainer().getName());
        } else {
            return null;
        }
    });
    // <--[tag]
    // @attribute <ScriptTag.default_step>
    // @returns ElementTag
    // @description
    // Returns the name of the default step of an interact script.
    // -->
    PropertyParser.<BukkitScriptProperties, ElementTag>registerStaticTag(ElementTag.class, "default_step", (attribute, script) -> {
        String step = ((InteractScriptContainer) script.script.getContainer()).getDefaultStepName();
        return new ElementTag(step);
    });
}
Also used : PlayerTag(com.denizenscript.denizen.objects.PlayerTag) BukkitScriptEntryData(com.denizenscript.denizen.utilities.implementation.BukkitScriptEntryData) TimeTag(com.denizenscript.denizencore.objects.core.TimeTag) InteractScriptContainer(com.denizenscript.denizen.scripts.containers.core.InteractScriptContainer) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) DurationTag(com.denizenscript.denizencore.objects.core.DurationTag)

Example 2 with BukkitScriptEntryData

use of com.denizenscript.denizen.utilities.implementation.BukkitScriptEntryData in project Denizen-For-Bukkit by DenizenScript.

the class ClickableCommand method runClickable.

public static void runClickable(UUID id, Player player) {
    Clickable clickable = clickables.get(id);
    if (clickable == null) {
        return;
    }
    if (clickable.until != 0 && System.currentTimeMillis() > clickable.until) {
        clickables.remove(id);
        return;
    }
    if (clickable.forPlayers != null && !clickable.forPlayers.contains(player.getUniqueId())) {
        return;
    }
    if (clickable.remainingUsages > 0) {
        clickable.remainingUsages--;
        if (clickable.remainingUsages <= 0) {
            clickables.remove(id);
        }
    }
    Consumer<ScriptQueue> configure = (queue) -> {
        if (clickable.defMap != null) {
            for (Map.Entry<StringHolder, ObjectTag> val : clickable.defMap.map.entrySet()) {
                queue.addDefinition(val.getKey().str, val.getValue());
            }
        }
    };
    ScriptUtilities.createAndStartQueue(clickable.script.getContainer(), clickable.path, new BukkitScriptEntryData(new PlayerTag(player), clickable.npc), null, configure, null, null, clickable.definitions, clickable.context);
}
Also used : Utilities(com.denizenscript.denizen.utilities.Utilities) InvalidArgumentsRuntimeException(com.denizenscript.denizencore.exceptions.InvalidArgumentsRuntimeException) java.util(java.util) ObjectTag(com.denizenscript.denizencore.objects.ObjectTag) com.denizenscript.denizencore.objects.core(com.denizenscript.denizencore.objects.core) BukkitScriptEntryData(com.denizenscript.denizen.utilities.implementation.BukkitScriptEntryData) Player(org.bukkit.entity.Player) PlayerTag(com.denizenscript.denizen.objects.PlayerTag) InvalidArgumentsException(com.denizenscript.denizencore.exceptions.InvalidArgumentsException) Argument(com.denizenscript.denizencore.objects.Argument) Consumer(java.util.function.Consumer) ScriptQueue(com.denizenscript.denizencore.scripts.queues.ScriptQueue) ScriptUtilities(com.denizenscript.denizencore.utilities.ScriptUtilities) NPCTag(com.denizenscript.denizen.objects.NPCTag) TagContext(com.denizenscript.denizencore.tags.TagContext) ScriptEntry(com.denizenscript.denizencore.scripts.ScriptEntry) Debug(com.denizenscript.denizen.utilities.debugging.Debug) AbstractCommand(com.denizenscript.denizencore.scripts.commands.AbstractCommand) TaskScriptContainer(com.denizenscript.denizencore.scripts.containers.core.TaskScriptContainer) StringHolder(com.denizenscript.denizencore.utilities.text.StringHolder) ScriptEntry(com.denizenscript.denizencore.scripts.ScriptEntry) BukkitScriptEntryData(com.denizenscript.denizen.utilities.implementation.BukkitScriptEntryData) PlayerTag(com.denizenscript.denizen.objects.PlayerTag) ScriptQueue(com.denizenscript.denizencore.scripts.queues.ScriptQueue)

Example 3 with BukkitScriptEntryData

use of com.denizenscript.denizen.utilities.implementation.BukkitScriptEntryData 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 4 with BukkitScriptEntryData

use of com.denizenscript.denizen.utilities.implementation.BukkitScriptEntryData 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 5 with BukkitScriptEntryData

use of com.denizenscript.denizen.utilities.implementation.BukkitScriptEntryData in project Denizen-For-Bukkit by DenizenScript.

the class Debug method echoError.

public static void echoError(ScriptEntry source, String addedContext, String message, boolean reformat) {
    message = cleanTextForDebugOutput(message);
    if (errorDuplicatePrevention) {
        if (!com.denizenscript.denizencore.utilities.debugging.Debug.verbose) {
            finalOutputDebugText("Error within error (??!!!! SOMETHING WENT SUPER WRONG!): " + message, source, reformat);
        }
        return;
    }
    errorDuplicatePrevention = true;
    ScriptQueue sourceQueue = CommandExecutor.currentQueue;
    if (source != null && source.queue != null) {
        sourceQueue = source.queue;
    }
    ScriptTag sourceScript = null;
    if (source != null) {
        sourceScript = source.getScript();
    }
    if (throwErrorEvent) {
        throwErrorEvent = false;
        boolean cancel = ScriptGeneratesErrorScriptEvent.instance.handle(message, sourceQueue, sourceScript, source == null ? -1 : source.internal.lineNumber);
        throwErrorEvent = true;
        if (cancel) {
            errorDuplicatePrevention = false;
            return;
        }
    }
    if (!showDebug) {
        errorDuplicatePrevention = false;
        return;
    }
    StringBuilder headerBuilder = new StringBuilder();
    headerBuilder.append(ERROR_HEADER_START);
    if (sourceScript != null) {
        headerBuilder.append(" in script '").append(ChatColor.AQUA).append(sourceScript.getName()).append(ChatColor.RED).append("'");
    }
    if (sourceQueue != null) {
        headerBuilder.append(" in queue '").append(sourceQueue.debugId).append(ChatColor.RED).append("'");
    }
    if (source != null) {
        headerBuilder.append(" while executing command '").append(ChatColor.AQUA).append(source.getCommandName()).append(ChatColor.RED).append("'");
        if (sourceScript != null) {
            headerBuilder.append(" in file '").append(ChatColor.AQUA).append(sourceScript.getContainer().getRelativeFileName()).append(ChatColor.RED).append("' on line '").append(ChatColor.AQUA).append(source.internal.lineNumber).append(ChatColor.RED).append("'");
        }
        BukkitScriptEntryData data = Utilities.getEntryData(source);
        if (data.hasPlayer()) {
            headerBuilder.append(" with player '").append(ChatColor.AQUA).append(data.getPlayer().getName()).append(ChatColor.RED).append("'");
        }
        if (data.hasNPC()) {
            headerBuilder.append(" with NPC '").append(ChatColor.AQUA).append(data.getNPC().debuggable()).append(ChatColor.RED).append("'");
        }
    }
    if (addedContext != null) {
        headerBuilder.append("\n<FORCE_ALIGN>").append(addedContext);
    }
    headerBuilder.append(ERROR_HEADER_END);
    String header = headerBuilder.toString();
    boolean showDebugSuffix = sourceScript != null && !sourceScript.getContainer().shouldDebug();
    String headerRef = header;
    if (header.equals(lastErrorHeader)) {
        header = ADDITIONAL_ERROR_HEADER;
        showDebugSuffix = false;
    }
    finalOutputDebugText(header + message + (showDebugSuffix ? ENABLE_DEBUG_MESSAGE : ""), sourceQueue, reformat);
    errorDuplicatePrevention = false;
    if (com.denizenscript.denizencore.utilities.debugging.Debug.verbose && depthCorrectError == 0) {
        depthCorrectError++;
        try {
            throw new RuntimeException("Verbose info for above error");
        } catch (Throwable e) {
            echoError(source, e);
        }
        depthCorrectError--;
    }
    lastErrorHeader = headerRef;
}
Also used : BukkitScriptEntryData(com.denizenscript.denizen.utilities.implementation.BukkitScriptEntryData) ScriptTag(com.denizenscript.denizencore.objects.core.ScriptTag) ScriptQueue(com.denizenscript.denizencore.scripts.queues.ScriptQueue)

Aggregations

BukkitScriptEntryData (com.denizenscript.denizen.utilities.implementation.BukkitScriptEntryData)15 ScriptEntry (com.denizenscript.denizencore.scripts.ScriptEntry)8 PlayerTag (com.denizenscript.denizen.objects.PlayerTag)7 NPCTag (com.denizenscript.denizen.objects.NPCTag)6 ScriptQueue (com.denizenscript.denizencore.scripts.queues.ScriptQueue)6 InstantQueue (com.denizenscript.denizencore.scripts.queues.core.InstantQueue)6 ContextSource (com.denizenscript.denizencore.scripts.queues.ContextSource)5 ElementTag (com.denizenscript.denizencore.objects.core.ElementTag)3 ArrayList (java.util.ArrayList)3 Player (org.bukkit.entity.Player)3 ScriptTag (com.denizenscript.denizencore.objects.core.ScriptTag)2 EntityTag (com.denizenscript.denizen.objects.EntityTag)1 InteractScriptContainer (com.denizenscript.denizen.scripts.containers.core.InteractScriptContainer)1 BukkitTagContext (com.denizenscript.denizen.tags.BukkitTagContext)1 Utilities (com.denizenscript.denizen.utilities.Utilities)1 Debug (com.denizenscript.denizen.utilities.debugging.Debug)1 InvalidArgumentsException (com.denizenscript.denizencore.exceptions.InvalidArgumentsException)1 InvalidArgumentsRuntimeException (com.denizenscript.denizencore.exceptions.InvalidArgumentsRuntimeException)1 Argument (com.denizenscript.denizencore.objects.Argument)1 ObjectTag (com.denizenscript.denizencore.objects.ObjectTag)1