Package net.aufdemrand.denizen.scripts

Examples of net.aufdemrand.denizen.scripts.ScriptEntry


        DenizenSpeechContext context = (DenizenSpeechContext) speechContext;

        Talkable talker = context.getTalker();
        if (talker == null) return;

        ScriptEntry entry = context.getScriptEntry();
        ScriptQueue queue = entry.getResidingQueue();

        String defTalker = null;
        if (queue.hasDefinition("talker"))
            defTalker = queue.getDefinition("talker");
        queue.addDefinition("talker", new dEntity(talker.getEntity()).identify());
View Full Code Here


        // Check last ScriptEntry to see if it should be waited for
        if (shouldHold(scriptQueue))
            return;

        // Okay to run next scriptEntry
        ScriptEntry scriptEntry = scriptQueue.getNext();

        // Loop through the entries
        while (scriptEntry != null) {
            // Mark script entry with Queue that is sending it to the executor
            scriptEntry.setSendingQueue(scriptQueue);

            try {
                // Execute the scriptEntry
                getScriptExecuter().execute(scriptEntry);
            }
            // Absolutely NO errors beyond this point!
            catch (Throwable e) {
                dB.echoError(scriptEntry.getResidingQueue(), "Woah! An exception has been called with this command!");
                dB.echoError(scriptEntry.getResidingQueue(), e);
            }
            // Set as last entry executed
            scriptQueue.setLastEntryExecuted(scriptEntry);

            // Check if the scriptQueue is delayed (EG, via wait)
            if (scriptQueue instanceof Delayable) {
                if (((Delayable) scriptQueue).isDelayed())
                    break;
                if (((Delayable) scriptQueue).isPaused())
                    break;
            }

            // If the entry is instant, and not injected, get the next Entry
            if (scriptEntry.isInstant()) {
                // If it's holding, even if it's instant, just stop and wait
                if (shouldHold(scriptQueue))
                    return;
                // Remove from execution list
                scriptEntry = scriptQueue.getNext();
View Full Code Here

        // If the specified amount of possible entries is less than the queue size, print that instead
        //if (hyperdebug) dB.echoDebug(scriptEntry, "...with queue size: " + scriptEntry.getResidingQueue().getQueueSize());
        if (hyperdebug) dB.echoDebug(scriptEntry, "...with first command name: " + scriptEntry.getCommandName());
        if (hyperdebug) dB.echoDebug(scriptEntry, "...with first command arguments: " + scriptEntry.getArguments());

        ScriptEntry entry = scriptEntry;//scriptEntry.getResidingQueue().getEntry(0);
        if (hyperdebug) dB.echoDebug(scriptEntry, "Entry found: " + entry.getCommandName());

        // Loop through the arguments of each entry
        List<aH.Argument> argList = aH.interpret(entry.getArguments());

        // Set the variable to use for naming braced command lists; the first should be the command name
        String bracesName = scriptEntry.getCommandName();

        int startArg = 0;
        for (int i = 0; i < argList.size(); i++) {
            aH.Argument arg = argList.get(i);
            if (arg.asElement().asString().equals("{")) {
                startArg = i;
                break;
            }
        }

        for (int i = startArg; i < argList.size(); i++) {
            aH.Argument arg = argList.get(i);
            if (hyperdebug) dB.echoDebug(scriptEntry, "Arg found: " + arg.raw_value);

            // Listen for opened braces
            if (arg.matches("{")) {
                bracesEntered++;
                newCommand = false;
                waitingForDash = bracesEntered == 1;
                if (hyperdebug) dB.echoDebug(scriptEntry, "Opened brace; " + String.valueOf(bracesEntered) + " now");
                if (bracesEntered > 1) {
                    commandList.get(commandList.lastKey()).add(arg.raw_value);
                }
            }

            // Listen for closed braces
            else if (arg.matches("}")) {
                bracesEntered--;
                newCommand = false;
                if (hyperdebug) dB.echoDebug(scriptEntry, "Closed brace; " + String.valueOf(bracesEntered) + " now");
                if (bracesEntered > 0) {
                    commandList.get(commandList.lastKey()).add(arg.raw_value);
                }
                else {
                    if (bracedSections.containsKey(bracesName)) {
                        dB.echoError(scriptEntry.getResidingQueue(), "You may not have braced commands with the same arguments.");
                        break;
                    }
                    ArrayList<ScriptEntry> bracesSection = new ArrayList<ScriptEntry>();
                    for (ArrayList<String> command : commandList.values()) {
                        try {
                            if (command.isEmpty()) {
                                if (hyperdebug) dB.echoError(scriptEntry.getResidingQueue(), "Empty command?");
                                continue;
                            }
                            String cmd = command.get(0);
                            if (hyperdebug) dB.echoDebug(scriptEntry, "Calculating " + cmd);
                            command.remove(0);
                            String[] args = new String[command.size()];
                            args = command.toArray(args);
                            bracesSection.add(new ScriptEntry(cmd,
                                    args,
                                    scriptEntry.getScript() != null ? scriptEntry.getScript().getContainer() : null));
                            bracesSection.get(bracesSection.size() - 1).setPlayer(((BukkitScriptEntryData)scriptEntry.entryData).getPlayer());
                            bracesSection.get(bracesSection.size() - 1).setNPC(((BukkitScriptEntryData)scriptEntry.entryData).getNPC());
                            if (hyperdebug) dB.echoDebug(scriptEntry, "Command added: " + cmd + ", with " + String.valueOf(args.length) + " arguments");
View Full Code Here

            final ProcedureScriptContainer script = ScriptRegistry.getScriptContainer(attribute.getContext(1));
            if (script == null) {
                dB.echoError("'" + attribute.getContext(1) + "' is not a valid procedure script!");
                return getAttribute(attribute.fulfill(1));
            }
            final ScriptEntry entry = attribute.getScriptEntry();
            List<String> list = new ArrayList<String>(this);
            try {
                Collections.sort(list, new Comparator<String>() {
                    @Override
                    public int compare(String o1, String o2) {
View Full Code Here

        if (stop != null && stop.asBoolean()) {
            // Report to dB
            dB.report(scriptEntry, getName(), stop.debug());
            boolean hasnext = false;
            for (int i = 0; i < scriptEntry.getResidingQueue().getQueueSize(); i++) {
                ScriptEntry entry = scriptEntry.getResidingQueue().getEntry(i);
                List<String> args = entry.getOriginalArguments();
                if (entry.getCommandName().equalsIgnoreCase("while") && args.size() > 0 && args.get(0).equalsIgnoreCase("\0CALLBACK")) {
                    hasnext = true;
                    break;
                }
            }
            if (hasnext) {
                while (scriptEntry.getResidingQueue().getQueueSize() > 0) {
                    ScriptEntry entry = scriptEntry.getResidingQueue().getEntry(0);
                    List<String> args = entry.getOriginalArguments();
                    if (entry.getCommandName().equalsIgnoreCase("while") && args.size() > 0 && args.get(0).equalsIgnoreCase("\0CALLBACK")) {
                        scriptEntry.getResidingQueue().removeEntry(0);
                        break;
                    }
                    scriptEntry.getResidingQueue().removeEntry(0);
                }
            }
            else {
                dB.echoError(scriptEntry.getResidingQueue(), "Cannot stop while: not in one!");
            }
            return;
        }
        else if (next != null && next.asBoolean()) {
            // Report to dB
            dB.report(scriptEntry, getName(), next.debug());
            boolean hasnext = false;
            for (int i = 0; i < scriptEntry.getResidingQueue().getQueueSize(); i++) {
                ScriptEntry entry = scriptEntry.getResidingQueue().getEntry(i);
                List<String> args = entry.getOriginalArguments();
                if (entry.getCommandName().equalsIgnoreCase("while") && args.size() > 0 && args.get(0).equalsIgnoreCase("\0CALLBACK")) {
                    hasnext = true;
                    break;
                }
            }
            if (hasnext) {
                while (scriptEntry.getResidingQueue().getQueueSize() > 0) {
                    ScriptEntry entry = scriptEntry.getResidingQueue().getEntry(0);
                    List<String> args = entry.getOriginalArguments();
                    if (entry.getCommandName().equalsIgnoreCase("while") && args.size() > 0 && args.get(0).equalsIgnoreCase("\0CALLBACK")) {
                        break;
                    }
                    scriptEntry.getResidingQueue().removeEntry(0);
                }
            }
            else {
                dB.echoError(scriptEntry.getResidingQueue(), "Cannot stop while: not in one!");
            }
            return;
        }
        else if (callback != null && callback.asBoolean()) {
            if (scriptEntry.getOwner() != null && (scriptEntry.getOwner().getCommandName().equalsIgnoreCase("while") ||
                    scriptEntry.getOwner().getBracedSet() == null || scriptEntry.getOwner().getBracedSet().size() == 0 ||
                    scriptEntry.getBracedSet().get("WHILE").get(scriptEntry.getBracedSet().get("WHILE").size() - 1) != scriptEntry)) {
                WhileData data = (WhileData)scriptEntry.getOwner().getData();
                data.index++;
                if (System.currentTimeMillis() - data.LastChecked < 50) {
                    data.instaTicks++;
                    int max = Settings.whileMaxLoops();
                    if (data.instaTicks > max && max != 0)
                        return;
                }
                else {
                    data.instaTicks = 0;
                }
                data.LastChecked = System.currentTimeMillis();
                if (TagManager.tag(((BukkitScriptEntryData)scriptEntry.entryData).getPlayer(), ((BukkitScriptEntryData)scriptEntry.entryData).getNPC(),
                        data.value, false, scriptEntry).equalsIgnoreCase("true")) {
                    dB.echoDebug(scriptEntry, dB.DebugElement.Header, "While loop " + data.index);
                    scriptEntry.getResidingQueue().addDefinition("loop_index", String.valueOf(data.index));
                    ArrayList<ScriptEntry> bracedCommands = BracedCommand.getBracedCommands(scriptEntry.getOwner()).get("WHILE");
                    ScriptEntry callbackEntry = null;
                    try {
                        callbackEntry = new ScriptEntry("WHILE", new String[] { "\0CALLBACK" },
                                (scriptEntry.getScript() != null ? scriptEntry.getScript().getContainer(): null));
                        callbackEntry.copyFrom(scriptEntry);
                    }
                    catch (ScriptEntryCreationException e) {
                        dB.echoError(scriptEntry.getResidingQueue(), e);
                    }
                    callbackEntry.setOwner(scriptEntry.getOwner());
                    bracedCommands.add(callbackEntry);
                    for (int i = 0; i < bracedCommands.size(); i++) {
                        bracedCommands.get(i).setInstant(true);
                        bracedCommands.get(i).addObject("reqId", scriptEntry.getObject("reqId"));
                    }
                    scriptEntry.getResidingQueue().injectEntries(bracedCommands, 0);
                }
            }
            else {
                dB.echoError(scriptEntry.getResidingQueue(), "While CALLBACK invalid: not a real callback!");
            }
        }

        else {

            // Get objects
            Element value = scriptEntry.getElement("value");
            ArrayList<ScriptEntry> bracedCommandsList =
                    ((LinkedHashMap<String, ArrayList<ScriptEntry>>) scriptEntry.getObject("braces")).get("WHILE");

            if (bracedCommandsList == null || bracedCommandsList.isEmpty()) {
                dB.echoError(scriptEntry.getResidingQueue(), "Empty braces!");
                return;
            }

            // Report to dB
            dB.report(scriptEntry, getName(), value.debug());

            if (!TagManager.tag(((BukkitScriptEntryData)scriptEntry.entryData).getPlayer(), ((BukkitScriptEntryData)scriptEntry.entryData).getNPC(),
                    value.asString(), false, scriptEntry).equalsIgnoreCase("true"))
                return;

            WhileData datum = new WhileData();
            datum.index = 1;
            datum.value = value.asString();
            datum.LastChecked = System.currentTimeMillis();
            datum.instaTicks = 1;
            scriptEntry.setData(datum);
            ScriptEntry callbackEntry = null;
            try {
                callbackEntry = new ScriptEntry("WHILE", new String[] { "\0CALLBACK" },
                        (scriptEntry.getScript() != null ? scriptEntry.getScript().getContainer(): null));
                callbackEntry.copyFrom(scriptEntry);
            }
            catch (ScriptEntryCreationException e) {
                dB.echoError(scriptEntry.getResidingQueue(), e);
            }
            callbackEntry.setOwner(scriptEntry);
            bracedCommandsList.add(callbackEntry);
            scriptEntry.getResidingQueue().addDefinition("loop_index", "1");
            for (int i = 0; i < bracedCommandsList.size(); i++) {
                bracedCommandsList.get(i).setInstant(true);
                bracedCommandsList.get(i).addObject("reqId", scriptEntry.getObject("reqId"));
View Full Code Here

            // Get the entry_id from name context
            String id = event.getNameContext();

            Attribute attribute = new Attribute(event.raw_tag, event.getScriptEntry());
            ScriptEntry held = event.getScriptEntry().getResidingQueue().getHeldScriptEntry(id);
            if (held == null) { // Check if the ID is bad
                dB.echoDebug(event.getScriptEntry(), "Bad saved entry ID '" + id + "'");

            } else {
                if (!held.hasObject(attribute.getAttribute(2)) // Check if there's no such object
                        || held.getdObject(attribute.getAttribute(2)) == null) { // ... or if there is such an object
                    dB.echoDebug(event.getScriptEntry(), "Missing saved entry object '" + attribute.getAttribute(2) + "'"); // but it's not a dObject...

                } else { // Okay, now it's safe!
                    event.setReplaced(held.getdObject(attribute.getAttribute(2)).getAttribute(attribute.fulfill(2)));
                }
            }
        }

        //else event.setReplaced("null");
View Full Code Here

        if (event.matches("parse")) {
            if (!event.hasValue()) {
                dB.echoError("Escape tag '" + event.raw_tag + "' does not have a value!");
                return;
            }
            ScriptEntry se = event.getAttributes().getScriptEntry();
            String read = TagManager.tag((se != null ?se.getPlayer(): null),
                    (se != null ?se.getNPC(): null), TagManager.cleanOutputFully(event.getValue()), false, se);
            event.setReplaced(new Element(read).getAttribute(event.getAttributes().fulfill(1)));
        }
    }
View Full Code Here

                context.put("script", script);
            List<String> events = new ArrayList<String>();
            events.add("script generates error");
            if (script != null)
                events.add(script.identifySimple() + " generates error");
            ScriptEntry entry = (source != null ? source.getLastEntryExecuted(): null);
            String Determination = EventManager.doEvents(events, (entry != null ? ((BukkitScriptEntryData)entry.entryData).getNPC(): null),
                    (entry != null ? ((BukkitScriptEntryData)entry.entryData).getPlayer(): null), context, true);
            ThrowErrorEvent = true;
            if (Determination.equalsIgnoreCase("CANCELLED"))
                return;
View Full Code Here

                thrown = ex.getCause();
            }
            context.put("message", new Element(thrown.getMessage()));
            context.put("type", new Element(thrown.getClass().getSimpleName()));
            context.put("queue", source);
            ScriptEntry entry = (source != null ? source.getLastEntryExecuted(): null);
            String Determination = EventManager.doEvents(Arrays.asList("server generates exception"),
                    (entry != null ? ((BukkitScriptEntryData)entry.entryData).getNPC(): null), (entry != null ? ((BukkitScriptEntryData)entry.entryData).getPlayer(): null), context);
            ThrowErrorEvent = true;
            if (Determination.equalsIgnoreCase("CANCELLED"))
                return;
View Full Code Here

        if (!ScriptRegistry.containsScript(event.getScriptEntry().getScript().getName(),
                TaskScriptContainer.class)) return;

        TaskScriptContainer script = ScriptRegistry.getScriptContainer(event.getScriptEntry().getScript().getName());

        ScriptEntry entry = event.getScriptEntry();

        if (entry.hasObject("CONTEXT")) {
            // Get context
            Map<String, String> context = (HashMap<String, String>) entry.getObject("CONTEXT");
            // Build IDs
            Map<String, Integer> id = script.getContextMap();
            if (context.containsKey( String.valueOf(id.get(object.toUpperCase())))) {
                event.setReplaced(context.get(String.valueOf(id.get(object.toUpperCase()))));
            }
View Full Code Here

TOP

Related Classes of net.aufdemrand.denizen.scripts.ScriptEntry

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.