Examples of dScript


Examples of net.aufdemrand.denizen.objects.dScript

    private static Map<String, Integer> durations = new ConcurrentHashMap<String, Integer>(8, 0.9f, 1);

    @Override
    public void execute(final ScriptEntry scriptEntry) throws CommandExecutionException {

        final dScript script = (dScript) scriptEntry.getObject("script");
        Duration duration = (Duration) scriptEntry.getObject("duration");

        dB.report(scriptEntry, getName(), ((BukkitScriptEntryData)scriptEntry.entryData).getPlayer().debug() + script.debug()
                + (scriptEntry.hasObject("step")
                ? scriptEntry.getElement("step").debug() : aH.debugObj("step", "++ (inc)"))
                + (duration != null ? duration.debug() : ""));

        String step = scriptEntry.hasObject("step") ? scriptEntry.getElement("step").asString() : null;

        // Let's get the current step for reference.
        String currentStep = InteractScriptHelper.getCurrentStep(((BukkitScriptEntryData)scriptEntry.entryData).getPlayer(), script.getName());

        // Special-case for backwards compatibility: ability to use ZAP to count up steps.
        if (step == null) {
            // Okay, no step was identified.. that means we should count up,
            // ie. if currentStep = 1, new step should = 2
            // If the currentStep is a number, increment it. If not, set it
            // to '1' so it can be incremented next time.
            if (aH.matchesInteger(currentStep)) {
                step = String.valueOf(aH.getIntegerFrom(currentStep) + 1);
            } else step = "1";
        }

        if (step.equalsIgnoreCase(currentStep)) {
            dB.echoError(scriptEntry.getResidingQueue(), "Zapping to own current step!");
            return;
        }

        // If the durationsMap already contains an entry for this player/script combination,
        // cancel the task since it's probably not desired to change back anymore if another
        // ZAP for this script is taking place.
        if (durations.containsKey(((BukkitScriptEntryData)scriptEntry.entryData).getPlayer().getSaveName() + "," + script.getName()))
            try {
                DenizenAPI.getCurrentInstance().getServer().getScheduler().cancelTask(durations.get(((BukkitScriptEntryData)scriptEntry.entryData).getPlayer().getSaveName() + "," + script.getName()));
            } catch (Exception e) { }

        // One last thing... check for duration.
        if (duration != null && duration.getSeconds() > 0) {
            // If a DURATION is specified, the currentStep should be remembered and
            // restored after the duration.
            scriptEntry.addObject("step", new Element(currentStep));
            // And let's take away the duration that was set to avoid a re-duration
            // inception-ion-ion-ion-ion... ;)
            scriptEntry.addObject("duration", Duration.ZERO);

            // Now let's add a delayed task to set it back after the duration

            // Delays are in ticks, so let's multiply our duration (which is in seconds) by 20.
            // 20 ticks per second.
            long delay = (long) (duration.getSeconds() * 20);

            // Set delayed task and put id in a map
            dB.log("Setting delayed task 'RESET ZAP' for '" + script.identify() + "'");
            durations.put(((BukkitScriptEntryData)scriptEntry.entryData).getPlayer().getSaveName() + "," + script.getName(),
                    DenizenAPI.getCurrentInstance().getServer().getScheduler().scheduleSyncDelayedTask(DenizenAPI.getCurrentInstance(),
                            new Runnable() {
                                @Override
                                public void run() {
                                    dB.log("Running delayed task 'RESET ZAP' for '" + script.identify() + "'");
                                    try {
                                        durations.remove(((BukkitScriptEntryData)scriptEntry.entryData).getPlayer().getSaveName() + "," + script.getName().toUpperCase());
                                        execute(scriptEntry);
                                    } catch (CommandExecutionException e) {
                                        dB.echoError(scriptEntry.getResidingQueue(), "Could not run delayed task!");
                                        dB.echoError(scriptEntry.getResidingQueue(), e);
                                    }
                                }
                            }, delay));
        }

        //
        // FINALLY! ZAP! Change the step in Saves... your step is now ZAPPED!
        // Fun fact: ZAP is named in homage of ZZT-OOPs ZAP command. Google it.
        //
        DenizenAPI.getCurrentInstance().getSaves().set("Players." + ((BukkitScriptEntryData)scriptEntry.entryData).getPlayer().getSaveName()
                + ".Scripts." + script.getName().toUpperCase() + "." + "Current Step", step);
    }
View Full Code Here

Examples of net.aufdemrand.denizen.objects.dScript

        if (!event.matches("proc", "pr")) return;

        Attribute attr = event.getAttributes();
        int attribs = 1;

        dScript script = null;
        String path = null;

        if (event.hasNameContext()) {
            if (event.getNameContext().indexOf('.') > 0) {
                String[] split = event.getNameContext().split("\\.", 2);
                path = split[1];
                script = dScript.valueOf(split[0]);

            } else script = dScript.valueOf(event.getNameContext());

        } else if (event.getValue() != null) {
            script = dScript.valueOf(event.getValue());

        } else {
            dB.echoError("Invalid procedure script tag '" + event.getValue() + "'!");
            return;
        }

        if (script == null) {
            dB.echoError("Missing script for procedure script tag '" + event.getValue() + "'!");
            return;
        }

        // Build script entries
        List<ScriptEntry> entries;
        if (path != null)
            entries = script.getContainer().getEntries(new BukkitScriptEntryData(event.getPlayer(), event.getNPC()), path);
        else
            entries = script.getContainer().getBaseEntries(new BukkitScriptEntryData(event.getPlayer(), event.getNPC()));

        // Return if no entries built
        if (entries.isEmpty()) return;

        // Create new ID -- this is what we will look for when determining an outcome
        long id = DetermineCommand.getNewId();

        // Add the reqId to each of the entries for referencing
        ScriptBuilder.addObjectToEntries(entries, "ReqId", id);

        InstantQueue queue = InstantQueue.getQueue(ScriptQueue.getNextId(script.getContainer().getName()));
        queue.addEntries(entries);
        queue.setReqId(id);
        if (event.hasType() &&
                event.getType().equalsIgnoreCase("context") &&
                event.hasTypeContext()) {
            attribs = 2;
            int x = 1;
            dList definitions = new dList(event.getTypeContext());
            String[] definition_names = null;

            try { definition_names = script.getContainer().getString("definitions").split("\\|");
            } catch (Exception e) { }

            for (String definition : definitions) {
                String name = definition_names != null && definition_names.length >= x ?
                        definition_names[x - 1].trim() : String.valueOf(x);
View Full Code Here

Examples of net.aufdemrand.denizen.objects.dScript

    public static void echoError(String message) {
        echoError(null, message);
    }

    public static void echoError(ScriptQueue source, String message) {
        dScript script = null;
        if (source != null && source.getEntries().size() > 0 && source.getEntries().get(0).getScript() != null) {
            script = source.getEntries().get(0).getScript();
        }
        else if (source != null && source.getLastEntryExecuted() != null && source.getLastEntryExecuted().getScript() != null) {
            script = source.getLastEntryExecuted().getScript();
        }
        if (ThrowErrorEvent) {
            ThrowErrorEvent = false;
            Map<String, dObject> context = new HashMap<String, dObject>();
            context.put("message", new Element(message));
            if (source != null)
                context.put("queue", source);
            if (script != null)
                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;
        }
        if (!showDebug) return;
        ConsoleSender.sendMessage(ChatColor.LIGHT_PURPLE + " " + ChatColor.RED + "ERROR" +
                (script != null ? " in script '" + script.getName() + "'": "") + "! "
                + ChatColor.WHITE + trimMessage(message));
    }
View Full Code Here

Examples of net.aufdemrand.denizen.objects.dScript

        // Get current ItemMeta from the book
        BookMeta bookInfo = (BookMeta) book.getItemStack().getItemMeta();

        if (contains("TITLE")) {
            String title = getString("TITLE");
            title = TagManager.tag(player, npc, title, false, null, dB.shouldDebug(this), new dScript(this));
            bookInfo.setTitle(title);
        }

        if (contains("SIGNED")) {
            if (getString("SIGNED").equalsIgnoreCase("false")) {
                book.getItemStack().setType(Material.BOOK_AND_QUILL);
            }
        }

        if (contains("AUTHOR")) {
            String author = getString("AUTHOR");
            author = TagManager.tag(player, npc, author, false);
            bookInfo.setAuthor(author);
        }

        if (contains("TEXT")) {
            List<String> pages = getStringList("TEXT");

            for (String page : pages) {
                page = TagManager.tag(player, npc, page, false, null, dB.shouldDebug(this), new dScript(this));
                bookInfo.addPage(page);
            }
        }

        book.getItemStack().setItemMeta(bookInfo);
View Full Code Here

Examples of net.aufdemrand.denizen.objects.dScript

    public void scriptTags(ReplaceableTagEvent event) {

        if (!event.matches("script", "s") || event.replaced()) return;

        // Stage the location
        dScript script = null;

        // Check name context for a specified script, or check
        // the ScriptEntry for a 'script' context
        if (event.hasNameContext() && dScript.matches(event.getNameContext()))
            script = dScript.valueOf(event.getNameContext());
        else if (event.getScript() != null)
            script = event.getScript();
        else if (event.getScriptEntry() == null)
            return;
        else if (event.getScriptEntry().getScript() != null)
            script = event.getScriptEntry().getScript();
        else if (event.getScriptEntry().hasObject("script"))
            script = (dScript) event.getScriptEntry().getObject("script");

        // Build and fill attributes
        Attribute attribute = new Attribute(event.raw_tag, event.getScriptEntry());

        // Check if location is null, return null if it is
        if (script == null) { return; }

        // Else, get the attribute from the script
        event.setReplaced(script.getAttribute(attribute.fulfill(1)));

    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.