Search in sources :

Example 6 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 7 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)

Example 8 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 9 with BukkitScriptEntryData

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

the class BukkitQueueProperties method registerTags.

public static void registerTags() {
    // <--[tag]
    // @attribute <QueueTag.npc>
    // @returns NPCTag
    // @mechanism QueueTag.linked_npc
    // @description
    // Returns the NPCTag linked to a queue.
    // -->
    PropertyParser.<BukkitQueueProperties, NPCTag>registerTag(NPCTag.class, "npc", (attribute, object) -> {
        NPCTag npc = null;
        if (object.queue.getLastEntryExecuted() != null) {
            npc = ((BukkitScriptEntryData) object.queue.getLastEntryExecuted().entryData).getNPC();
        } else if (object.queue.getEntries().size() > 0) {
            npc = ((BukkitScriptEntryData) object.queue.getEntries().get(0).entryData).getNPC();
        } else if (!attribute.hasAlternative()) {
            attribute.echoError("Can't determine a linked NPC.");
        }
        return npc;
    });
    // <--[tag]
    // @attribute <QueueTag.player>
    // @returns PlayerTag
    // @mechanism QueueTag.linked_player
    // @description
    // Returns the PlayerTag linked to a queue.
    // -->
    PropertyParser.<BukkitQueueProperties, PlayerTag>registerTag(PlayerTag.class, "player", (attribute, object) -> {
        PlayerTag player = null;
        if (object.queue.getLastEntryExecuted() != null) {
            player = ((BukkitScriptEntryData) object.queue.getLastEntryExecuted().entryData).getPlayer();
        } else if (object.queue.getEntries().size() > 0) {
            player = ((BukkitScriptEntryData) object.queue.getEntries().get(0).entryData).getPlayer();
        } else {
            attribute.echoError("Can't determine a linked player.");
        }
        return player;
    });
}
Also used : BukkitScriptEntryData(com.denizenscript.denizen.utilities.implementation.BukkitScriptEntryData) PlayerTag(com.denizenscript.denizen.objects.PlayerTag) NPCTag(com.denizenscript.denizen.objects.NPCTag)

Example 10 with BukkitScriptEntryData

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

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