Package net.aufdemrand.denizen.objects

Examples of net.aufdemrand.denizen.objects.Duration


    }

    @Override
    public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
        // Fetch objects
        Duration value = (Duration) scriptEntry.getObject("value");
        dWorld world = (dWorld) scriptEntry.getObject("world");
        Element type_element = scriptEntry.getElement("type");
        Type type = Type.valueOf(type_element.asString().toUpperCase());

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

        if (type.equals(Type.GLOBAL)) {
            world.getWorld().setTime(value.getTicks());
        }
        else {
            if (!((BukkitScriptEntryData)scriptEntry.entryData).hasPlayer())
                dB.echoError("Must have a valid player link!");
            else
                ((BukkitScriptEntryData)scriptEntry.entryData).getPlayer()
                        .getPlayerEntity().setPlayerTime(value.getTicks(), true);
        }
    }
View Full Code Here


        }

        if (!scriptEntry.hasObject("location"))
            throw new InvalidArgumentsException("Must specify a location!");

        scriptEntry.defaultObject("duration", new Duration(0));
        scriptEntry.defaultObject("switchstate", new Element("TOGGLE"));
    }
View Full Code Here

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

        // Get objects
        List<dEntity> entities = (List<dEntity>) scriptEntry.getObject("entities");
        Duration duration = (Duration) scriptEntry.getObject("duration");

        // Report to dB
        dB.report(scriptEntry, getName(), duration.debug() +
                aH.debugObj("entities", entities.toString()));

        // Go through all the entities and set them on fire
        for (dEntity entity : entities) {
            if (entity.isSpawned()) {
                entity.getBukkitEntity().setFireTicks(duration.getTicksAsInt());
            }
        }
    }
View Full Code Here

                    ((BukkitScriptEntryData)scriptEntry.entryData).hasNPC() ? ((BukkitScriptEntryData)scriptEntry.entryData).getNPC().getDenizenEntity() : null,
                    ((BukkitScriptEntryData)scriptEntry.entryData).hasPlayer() ? ((BukkitScriptEntryData)scriptEntry.entryData).getPlayer().getDenizenEntity() : null);
        }

        scriptEntry.defaultObject("speed", new Element(1.5));
        scriptEntry.defaultObject("duration", new Duration(20));

        // Check to make sure required arguments have been filled

        if (!scriptEntry.hasObject("entities"))
            throw new InvalidArgumentsException("Must specify entity/entities!");
View Full Code Here

     * time in between each revolution. '
     *
     * @return a Duration of the speed.
     */
    public Duration getSpeed() {
        return new Duration(ticks);
    }
View Full Code Here

    @Override
    public String getAttribute(Attribute attribute) {

        // Meta defined in TimedQueue
        if (attribute.startsWith("speed")) {
            return new Duration(0).getAttribute(attribute.fulfill(1));
        }

        // Meta defined in TimedQueue
        if (attribute.startsWith("type")) {
View Full Code Here

                (((BukkitScriptEntryData)scriptEntry.entryData).hasPlayer() ? Arrays.asList(((BukkitScriptEntryData)scriptEntry.entryData).getPlayer().getDenizenEntity()) : null),
                (((BukkitScriptEntryData)scriptEntry.entryData).hasNPC() ? Arrays.asList(((BukkitScriptEntryData)scriptEntry.entryData).getNPC().getDenizenEntity()) : null));

        scriptEntry.defaultObject("yaw", new Element(10));
        scriptEntry.defaultObject("pitch", new Element(0));
        scriptEntry.defaultObject("duration", new Duration(20));
        scriptEntry.defaultObject("frequency", Duration.valueOf("1t"));

        // Check to make sure required arguments have been filled
        if (!scriptEntry.hasObject("entities"))
            throw new InvalidArgumentsException("Must specify entity/entities!");
View Full Code Here

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

        final List<dEntity> entities = (List<dEntity>) scriptEntry.getObject("entities");
        final Duration duration = (Duration) scriptEntry.getObject("duration");
        final Duration frequency = (Duration) scriptEntry.getObject("frequency");
        final Element yaw = (Element) scriptEntry.getObject("yaw");
        final Element pitch = (Element) scriptEntry.getObject("pitch");
        boolean cancel = scriptEntry.hasObject("cancel");
        final boolean infinite = scriptEntry.hasObject("infinite");

        // Report to dB
        dB.report(scriptEntry, getName(), (cancel ? aH.debugObj("cancel", cancel) : "") +
                             aH.debugObj("entities", entities.toString()) +
                             (infinite ? aH.debugObj("duration", "infinite") : duration.debug()) +
                             frequency.debug() +
                             yaw.debug() +
                             pitch.debug());

        // Add entities to the rotatingEntities list or remove
        // them from it
        for (dEntity entity : entities)
            if (cancel) rotatingEntities.remove(entity.getUUID());
            else        rotatingEntities.add(entity.getUUID());

        // Go no further if we are canceling a rotation
        if (cancel) return;

        // Run a task that will keep rotating the entities
        BukkitRunnable task = new BukkitRunnable() {
            int ticks = 0;
            int maxTicks = duration.getTicksAsInt();

            // Track entities that are no longer used, to remove them from
            // the regular list
            Collection<dEntity> unusedEntities = new LinkedList<dEntity>();

            @Override
            public void run() {

                if (entities.isEmpty()) {
                    scriptEntry.setFinished(true);
                    this.cancel();
                }

                else if (infinite || ticks < maxTicks) {
                    for (dEntity entity : entities) {
                        if (entity.isSpawned() && rotatingEntities.contains(entity.getUUID())) {
                            Rotation.rotate(entity.getBukkitEntity(),
                                    Rotation.normalizeYaw(entity.getLocation().getYaw() + yaw.asFloat()),
                                    entity.getLocation().getPitch() + pitch.asFloat());
                        }
                        else {
                            rotatingEntities.remove(entity.getUUID());
                            unusedEntities.add(entity);
                        }
                    }

                    // Remove any entities that are no longer spawned
                    if (!unusedEntities.isEmpty()) {
                        for (dEntity unusedEntity : unusedEntities) {
                            entities.remove(unusedEntity);
                        }
                        unusedEntities.clear();
                    }

                    ticks = (int) (ticks + frequency.getTicks());
                }
                else {
                    scriptEntry.setFinished(true);
                    this.cancel();
                }
            }
        };
        task.runTaskTimer(DenizenAPI.getCurrentInstance(), 0, frequency.getTicks());
    }
View Full Code Here

    @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(),
View Full Code Here

    public TaskScriptContainer(YamlConfiguration configurationSection, String scriptContainerName) {
        super(configurationSection, scriptContainerName);
    }

    public Duration getSpeed() {
        Duration speed;
        if (contains("SPEED")) {
            if (getString("SPEED", "0").toUpperCase().equals("INSTANT"))
                speed = Duration.valueOf("0t");
            else
                speed = Duration.valueOf(getString("SPEED", "0t"));

        } else
            speed = new Duration(Duration.valueOf(Settings.scriptQueueSpeed()).getSeconds());

        return speed;
    }
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.