Package net.aufdemrand.denizen.objects

Examples of net.aufdemrand.denizen.objects.Duration


        // Initialize necessary fields
        Map<String, String> context = null;
        Boolean instant = false;
        dScript script = null;
        Duration delay = null;
        String queue = scriptEntry.getResidingQueue().id;

        // Iterate through Arguments to extract needed information
        for (String arg : scriptEntry.getArguments()) {

            // Specify scriptContainer to use
            if (aH.matchesScript(arg)) {
                script = aH.getScriptFrom(arg);

            }   // Delay the start of the queue
            else if (aH.matchesValueArg("DELAY", arg, aH.ArgumentType.Duration)) {
                delay = aH.getDurationFrom(arg);

            }   // Use a specific queue
            else if (aH.matchesQueue(arg)) {
                queue = aH.getStringFrom(arg);

            }   // TODO: Remove this argument for version 1.0
            else if (aH.matchesValueArg("SPEED", arg, aH.ArgumentType.Duration)) {
                dB.log("SPEED argument has been removed from RUNTASK! Instead, specify " +
                        "a speed on the task script itself, or use the 'QUEUE SET_SPEED:#' command " +
                        "inside the task script. This warning will be removed in version 1.0 " +
                        "and this command will be deprecated.");

            }   // Gets a new, randomly named queue
            else if (aH.matchesArg("QUEUE", arg)) {
                queue = ScriptQueue.getNextId("RUNTASK");
                instant = false;

            }   // Run the script instantly.
            else if (aH.matchesArg("INSTANT, INSTANTLY", arg)) {
                queue = ScriptQueue.getNextId("RUNTASK");
                instant = true;

            }   // Build context map if specified
            else if (aH.matchesContext(arg)) {
                context = aH.getContextFrom(arg);

            }   // Specify a script name without the 'script:' prefix
            else if (ScriptRegistry.containsScript(aH.getStringFrom(arg))) {
                script = aH.getScriptFrom(arg);
                if (!script.getType().equalsIgnoreCase("TASK"))
                    script = null;

            } else throw new InvalidArgumentsException("Unknown argument '" + arg + "'!");
        }

        // Must specify at least a valid script to run...
        if (script == null)
            throw new InvalidArgumentsException("Must define a SCRIPT to be run.");
        // If not queue, and delayed, throw an exception... this cannot happen.
        if (queue.equals(scriptEntry.getResidingQueue().id) && delay != null)
            throw new InvalidArgumentsException("Cannot delay an INJECTED task script! Use 'QUEUE'.");

        // Put important objects inside the scriptEntry to be sent to execute()
        scriptEntry.addObject("instant", instant)
                .addObject("queue", queue)
                .addObject("delay", (delay != null ? delay.setPrefix("Delay") : null))
                .addObject("script", script)
                .addObject("context", context);
    }
View Full Code Here


            queue = InstantQueue.getQueue(id);
        else queue = TimedQueue.getQueue(id);

        Map<String, String> context = (HashMap<String, String>) scriptEntry.getObject("context");
        dScript script = (dScript) scriptEntry.getObject("script");
        Duration delay = (Duration) scriptEntry.getObject("delay");

        // Debug output
        dB.report(scriptEntry, getName(),
                script.debug()
                        + (delay != null ? delay.debug() : "")
                        + aH.debugObj("Instant", instant.toString())
                        + aH.debugObj("Queue", id)
                        + (context != null ? aH.debugObj("Context", context.toString()) : "")
                        + (((BukkitScriptEntryData)scriptEntry.entryData).getPlayer() != null
                        ? aH.debugObj("Player", ((BukkitScriptEntryData)scriptEntry.entryData).getPlayer().getName()) : "")
View Full Code Here

    @Override
    public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {

        // Initialize required fields
        ScriptQueue queue = scriptEntry.getResidingQueue();
        Duration delay = new Duration(3);

        // Iterate through arguments
        for (String arg : scriptEntry.getArguments()) {

            // Set duration
View Full Code Here

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

        ScriptQueue queue = (ScriptQueue) scriptEntry.getObject("queue");
        Duration delay = (Duration) scriptEntry.getObject("delay");

        dB.report(scriptEntry, getName(),
                aH.debugObj("queue", queue.id) + delay.debug());

        // Tell the queue to delay
        if (queue instanceof Delayable)
               ((Delayable) queue).delayFor(delay);
        else {
View Full Code Here

        // No potion specified? Problem!
        if (!scriptEntry.hasObject("effect"))
            throw new InvalidArgumentsException("Must specify a valid PotionType!");

        scriptEntry.defaultObject("duration", new Duration(60));
        scriptEntry.defaultObject("amplifier", new Element(1));
        scriptEntry.defaultObject("remove", Element.FALSE);

    }
View Full Code Here

    public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
        // Fetch objects
        List<dEntity> entities = (List<dEntity>) scriptEntry.getObject("entities");
        PotionEffectType effect = (PotionEffectType) scriptEntry.getObject("effect");
        int amplifier = scriptEntry.getElement("amplifier").asInt();
        Duration duration = (Duration) scriptEntry.getObject("duration");
        boolean remove = scriptEntry.getElement("remove").asBoolean();

        // Report to dB
        dB.report(scriptEntry, getName(),
                aH.debugObj("Target(s)", entities.toString())
                        + aH.debugObj("Effect", effect.getName())
                        + aH.debugObj("Amplifier", amplifier)
                        + duration.debug());

        // Apply the PotionEffect to the targets!
        for (dEntity entity : entities) {
            if (entity.getLivingEntity().hasPotionEffect(effect))
                entity.getLivingEntity().removePotionEffect(effect);
            if (remove) continue;
            PotionEffect potion = new PotionEffect(effect, duration.getTicksAsInt(), amplifier);
            if (!potion.apply(entity.getLivingEntity()))
                dB.echoError(scriptEntry.getResidingQueue(), "Bukkit was unable to apply '" + potion.getType().getName() + "' to '" + entity.toString() + "'.");
        }
    }
View Full Code Here

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

        ScriptQueue queue = (ScriptQueue) scriptEntry.getObject("queue");
        Action action = (Action) scriptEntry.getObject("action");
        Duration delay = (Duration) scriptEntry.getObject("delay");

        // Debugger
        dB.report(scriptEntry, getName(), queue.debug()
                + aH.debugObj("Action", action.toString())
                + (action == Action.DELAY ? delay.debug() : ""));

        switch (action) {

            case CLEAR:
                queue.clear();
                return;

            case STOP:
                queue.clear();
                queue.stop();
                return;

            case PAUSE:
                if (queue instanceof Delayable) {
                    ((Delayable) queue).setPaused(true);
                }
                else {
                    queue.forceToTimed(new Duration(1L)).setPaused(true);
                }
                return;

            case RESUME:
                if (queue instanceof Delayable)
View Full Code Here

    public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {

        Element toggle = scriptEntry.getElement("toggle");
        Element trigger = scriptEntry.getElement("trigger");
        Element radius = scriptEntry.getElement("radius");
        Duration cooldown = (Duration) scriptEntry.getObject("cooldown");
        dNPC npc = scriptEntry.hasObject("npc") ? (dNPC) scriptEntry.getObject("npc") : ((BukkitScriptEntryData)scriptEntry.entryData).getNPC();

        dB.report(scriptEntry, getName(),
                trigger.debug() + toggle.debug() +
                        (radius != null ? radius.debug(): "") +
                        (cooldown != null ? cooldown.debug(): "") +
                        npc.debug());

        // Add trigger trait
        if (!npc.getCitizen().hasTrait(TriggerTrait.class)) npc.getCitizen().addTrait(TriggerTrait.class);

        TriggerTrait trait = npc.getCitizen().getTrait(TriggerTrait.class);

        switch (Toggle.valueOf(toggle.asString().toUpperCase())) {

            case TOGGLE:
                trait.toggleTrigger(trigger.asString());
                break;

            case TRUE:
                trait.toggleTrigger(trigger.asString(), true);
                break;

            case FALSE:
                trait.toggleTrigger(trigger.asString(), false);
                break;
        }

        if (radius != null)
            trait.setLocalRadius(trigger.asString(), radius.asInt());

        if (cooldown != null && cooldown.getSeconds() > 0)
            trait.setLocalCooldown(trigger.asString(), cooldown.getSeconds());
    }
View Full Code Here

                // TODO: figure out why this is here
            }

        }

        scriptEntry.defaultObject("duration", new Duration(0));

    }
View Full Code Here

    }

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

        Duration duration = scriptEntry.getdObject("duration");

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

        if (duration.getSecondsAsInt() > 0)
            setEngaged(((BukkitScriptEntryData)scriptEntry.entryData).getNPC().getCitizen(), duration.getSecondsAsInt());
        else
            setEngaged(((BukkitScriptEntryData)scriptEntry.entryData).getNPC().getCitizen(), true);

    }
View Full Code Here

TOP

Related Classes of net.aufdemrand.denizen.objects.Duration

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.