Examples of dScript


Examples of net.aufdemrand.denizen.objects.dScript

                        + (scriptEntry.hasObject("delay") ? scriptEntry.getdObject("delay").debug() : "")
                        + (scriptEntry.hasObject("id") ? scriptEntry.getdObject("id").debug() : "")
                        + (scriptEntry.hasObject("definitions") ? scriptEntry.getdObject("definitions").debug(): ""));

        // Get the script
        dScript script = scriptEntry.getdObject("script");

        // Get the entries
        List<ScriptEntry> entries;
        // If it's local
        if (scriptEntry.hasObject("local")) {
            entries = scriptEntry.getScript().getContainer().getEntries(scriptEntry.entryData.clone(),
                    scriptEntry.getElement("path").asString());
            script = scriptEntry.getScript();
        }

            // If it has a path
        else if (scriptEntry.hasObject("path") && scriptEntry.getObject("path") != null)
            entries = script.getContainer().getEntries(scriptEntry.entryData.clone(),
                    scriptEntry.getElement("path").asString());

            // Else, assume standard path
        else entries = script.getContainer().getBaseEntries(scriptEntry.entryData.clone());

        // Get the 'id' if specified
        String id = (scriptEntry.hasObject("id") ?
                (scriptEntry.getElement("id")).asString() : ScriptQueue.getNextId(script.getContainer().getName()));

        // Build the queue
        ScriptQueue queue;
        if (scriptEntry.hasObject("instant")) {
            queue = InstantQueue.getQueue(id).addEntries(entries);
        }
        else {
            queue = TimedQueue.getQueue(id).addEntries(entries);

            // Check speed of the script if a TimedQueue -- if identified, use the speed from the script.
            if (script != null && script.getContainer().contains("SPEED"))
                ((TimedQueue) queue).setSpeed(Duration.valueOf(script.getContainer().getString("SPEED", "0")).getTicks());

        }

        // Set any delay
        if (scriptEntry.hasObject("delay"))
            queue.delayUntil(System.currentTimeMillis() + ((Duration) scriptEntry.getObject("delay")).getMillis());

        // Set any definitions
        if (scriptEntry.hasObject("definitions")) {
            int x = 1;
            dList definitions = (dList) scriptEntry.getObject("definitions");
            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);
                queue.addDefinition(name, definition);
View Full Code Here

Examples of net.aufdemrand.denizen.objects.dScript

    }

    @Override
    public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
        // Grab objects from scriptEntry
        dScript script = (dScript) scriptEntry.getObject("script");
        dPlayer player = (dPlayer) scriptEntry.getObject("player");

        // Report to dB
        dB.report(scriptEntry, getName(),
                player.debug() + script.debug());

        failScript(player.getName(), script.getName());
    }
View Full Code Here

Examples of net.aufdemrand.denizen.objects.dScript

    public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {

        // 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 + "'!");
        }
View Full Code Here

Examples of net.aufdemrand.denizen.objects.dScript

        else if (instant)
            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()) : "")
                        + (((BukkitScriptEntryData)scriptEntry.entryData).getNPC() != null
                        ? aH.debugObj("NPC", ((BukkitScriptEntryData)scriptEntry.entryData).getNPC().toString()) : ""));

        if (instant) {
            // Instant, but no delay
            if (delay == null) {

                if (scriptEntry.getResidingQueue() != queue) {
                    // Instant, no delay, new queue
                    ((TaskScriptContainer) script.getContainer()).setSpeed(Duration.valueOf("0"))
                            .runTaskScript(queue.id,
                                    ((BukkitScriptEntryData)scriptEntry.entryData).getPlayer(),
                                    ((BukkitScriptEntryData)scriptEntry.entryData).getNPC(),
                                    context);
                }

                else {
                    // Instant, no delay, injection into current queue
                    ((TaskScriptContainer) script.getContainer()).setSpeed(Duration.valueOf("0"))
                            .injectTaskScript(queue.id,
                                    ((BukkitScriptEntryData)scriptEntry.entryData).getPlayer(),
                                    ((BukkitScriptEntryData)scriptEntry.entryData).getNPC(),
                                    context);
                }
            }

            else {
                // Instant, has delay, new queue
                ((TaskScriptContainer) script.getContainer()).setSpeed(Duration.valueOf("0"))
                        .runTaskScriptWithDelay(queue.id,
                                ((BukkitScriptEntryData)scriptEntry.entryData).getPlayer(),
                                ((BukkitScriptEntryData)scriptEntry.entryData).getNPC(),
                                context,
                                delay);
            }
        }
        else {

            if (delay == null) {

                // Not instant, no delay, new queue
                if (scriptEntry.getResidingQueue() != queue) {
                    ((TaskScriptContainer) script.getContainer())
                            .runTaskScript(queue.id,
                                    ((BukkitScriptEntryData)scriptEntry.entryData).getPlayer(),
                                    ((BukkitScriptEntryData)scriptEntry.entryData).getNPC(),
                                    context);
                }

                else {
                    // Not instant, no delay, injection into current queue
                    ((TaskScriptContainer) script.getContainer())
                            .injectTaskScript(queue.id,
                                    ((BukkitScriptEntryData)scriptEntry.entryData).getPlayer(),
                                    ((BukkitScriptEntryData)scriptEntry.entryData).getNPC(),
                                    context);
                }
            }

            else {
                // Not instant, delayed, new queue
                ((TaskScriptContainer) script.getContainer())
                        .runTaskScriptWithDelay(queue.id,
                                ((BukkitScriptEntryData)scriptEntry.entryData).getPlayer(),
                                ((BukkitScriptEntryData)scriptEntry.entryData).getNPC(),
                                context,
                                delay);
View Full Code Here

Examples of net.aufdemrand.denizen.objects.dScript

    }

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

        dScript script = scriptEntry.getdObject("script");

        // Report to dB
        dB.report(scriptEntry, getName(), scriptEntry.reportObject("action") + script.debug());

        // Perform desired action
        if (scriptEntry.getObject("action").equals(Action.SET))
            ((BukkitScriptEntryData)scriptEntry.entryData).getNPC().getCitizen().getTrait(AssignmentTrait.class)
                    .setAssignment(script.getName(), ((BukkitScriptEntryData)scriptEntry.entryData).getPlayer());

        else if (scriptEntry.getObject("action").equals(Action.REMOVE))
            ((BukkitScriptEntryData)scriptEntry.entryData).getNPC().getCitizen().getTrait(AssignmentTrait.class)
                    .removeAssignment(((BukkitScriptEntryData)scriptEntry.entryData).getPlayer());
    }
View Full Code Here

Examples of net.aufdemrand.denizen.objects.dScript

    }

    @Override
    public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
        // Grab objects from scriptEntry
        dScript script = (dScript) scriptEntry.getObject("script");
        dPlayer player = (dPlayer) scriptEntry.getObject("player");

        // Report to dB
        dB.report(scriptEntry, getName(),
                player.debug() + script.debug());

        finishScript(player.getName(), script.getName());
    }
View Full Code Here

Examples of net.aufdemrand.denizen.objects.dScript

            //
            // Replace tags and build arguments
            //
            List<String> argumentList = TagManager.fillArguments(aH.buildArgs(reqEntry),
                    new BukkitTagContext(context.player, context.npc, false, null, dB.shouldDebug(context.getScriptContainer()), new dScript(context.getScriptContainer())));
            String reqString = argumentList.get(0).toUpperCase();

            //
            // Evaluate the requirement
            //
View Full Code Here

Examples of net.aufdemrand.denizen.objects.dScript

    @Override
    public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
        Element action = scriptEntry.getElement("action");
        Element type = scriptEntry.getElement("type");
        Element id = scriptEntry.getElement("id");
        dScript finish_script = (dScript) scriptEntry.getObject("finish_script");

        dB.report(scriptEntry, getName(), action.debug() + (type != null ? type.debug() : "")
                + id.debug() + (finish_script != null ? finish_script.debug() : ""));

        List<aH.Argument> arguments = (ArrayList<aH.Argument>) scriptEntry.getObject("args");

        switch (Action.valueOf(action.asString().toUpperCase())) {
View Full Code Here

Examples of net.aufdemrand.denizen.objects.dScript

            scriptEntry.setFinished(true);
            return;
        }

        List<dEntity> entities = (List<dEntity>) scriptEntry.getObject("entities");
        final dScript script = (dScript) scriptEntry.getObject("script");

        final double speed = scriptEntry.getElement("speed").asDouble();
        final int maxTicks = ((Duration) scriptEntry.getObject("duration")).getTicksAsInt() / 2;

        // Report to dB
        dB.report(scriptEntry, getName(), aH.debugObj("origin", originEntity != null ? originEntity : originLocation) +
                             aH.debugObj("entities", entities.toString()) +
                             aH.debugObj("destination", destination) +
                             aH.debugObj("speed", speed) +
                             aH.debugObj("max ticks", maxTicks) +
                             (script != null ? script.debug() : "") +
                             (no_rotate ? aH.debugObj("no_rotate", "true"): ""));

        // Keep a dList of entities that can be called using <entry[name].pushed_entities>
        // later in the script queue
        final dList entityList = new dList();

        // Go through all the entities, spawning/teleporting and rotating them
        for (dEntity entity : entities) {
            entity.spawnAt(originLocation);

            // Only add to entityList after the entities have been
            // spawned, otherwise you'll get something like "e@skeleton"
            // instead of "e@57" on it
            entityList.add(entity.toString());

            if (!no_rotate)
                Rotation.faceLocation(entity.getBukkitEntity(), destination);

            // If the current entity is a projectile, set its shooter
            // when applicable
            if (entity.isProjectile() && originEntity != null) {
                entity.setShooter(originEntity);
            }
        }

        // Add entities to context so that the specific entities created/spawned
        // can be fetched.
        scriptEntry.addObject("pushed_entities", entityList);

        Position.mount(Conversion.convertEntities(entities));

        // Get the entity at the bottom of the entity list, because
        // only its gravity should be affected and tracked considering
        // that the other entities will be mounted on it
        final dEntity lastEntity = entities.get(entities.size() - 1);

        final Vector v2 = destination.toVector();

        BukkitRunnable task = new BukkitRunnable() {
            int runs = 0;
            dLocation lastLocation;
            @Override
            public void run() {

                if (runs < maxTicks && lastEntity.isValid()) {

                    Vector v1 = lastEntity.getLocation().toVector();
                    Vector v3 = v2.clone().subtract(v1).normalize().multiply(speed);

                    lastEntity.setVelocity(v3);
                    runs++;

                    // Check if the entity is close to its destination
                    if (Math.abs(v2.getX() - v1.getX()) < 2 && Math.abs(v2.getY() - v1.getY()) < 2
                        && Math.abs(v2.getZ() - v1.getZ()) < 2) {
                        runs = maxTicks;
                    }

                    // Check if the entity has collided with something
                    // using the most basic possible calculation
                    if (lastEntity.getLocation().add(v3).getBlock().getType() != Material.AIR) {
                        runs = maxTicks;
                    }

                    // Record the location in case the entity gets lost (EG, if a pushed arrow hits a mob)
                    lastLocation = lastEntity.getLocation();
                }
                else {
                    this.cancel();

                    if (script != null) {

                        List<ScriptEntry> entries = script.getContainer().getBaseEntries(scriptEntry.entryData.clone());
                        ScriptQueue queue = InstantQueue.getQueue(ScriptQueue.getNextId(script.getContainer().getName()))
                                .addEntries(entries);
                        if (lastEntity.getLocation() != null)
                            queue.addDefinition("location", lastEntity.getLocation().identify());
                        else
                            queue.addDefinition("location", lastLocation.identify());
View Full Code Here

Examples of net.aufdemrand.denizen.objects.dScript

            dB.report(scriptEntry, getName(), "No destination specified!");
            return;
        }

        final List<dEntity> entities = (List<dEntity>) scriptEntry.getObject("entities");
        final dScript script = (dScript) scriptEntry.getObject("script");
        dEntity shooter = (dEntity) scriptEntry.getObject("shooter");

        Element height = scriptEntry.getElement("height");
        Element gravity = scriptEntry.getElement("gravity");
        Element speed = scriptEntry.getElement("speed");
        Element spread = scriptEntry.getElement("spread");

        dLocation lead = (dLocation) scriptEntry.getObject("lead");

        // Report to dB
        dB.report(scriptEntry, getName(), aH.debugObj("origin", originEntity != null ? originEntity : originLocation) +
                             aH.debugObj("entities", entities.toString()) +
                             destination.debug() +
                             height.debug() +
                             (gravity != null ? gravity.debug(): "") +
                             (speed != null ? speed.debug(): "") +
                             (script != null ? script.debug() : "") +
                             (shooter != null ? shooter.debug() : "") +
                             (spread != null ? spread.debug() : "") +
                             (lead != null ? lead.debug(): "") +
                             (no_rotate ? aH.debugObj("no_rotate", "true"): ""));

        // Keep a dList of entities that can be called using <entry[name].shot_entities>
        // later in the script queue

        final dList entityList = new dList();

        // Go through all the entities, spawning/teleporting and rotating them
        for (dEntity entity : entities) {
            entity.spawnAt(originLocation);

            // Only add to entityList after the entities have been
            // spawned, otherwise you'll get something like "e@skeleton"
            // instead of "e@57" on it
            entityList.add(entity.toString());

            if (!no_rotate)
                Rotation.faceLocation(entity.getBukkitEntity(), destination);

            // If the current entity is a projectile, set its shooter
            // when applicable
            if (entity.isProjectile() && (shooter != null || originEntity != null)) {
                entity.setShooter(shooter != null ? shooter : originEntity);
                // Also, watch for it hitting a target
                arrows.put(entity.getUUID(), null);
            }
        }

        // Add entities to context so that the specific entities created/spawned
        // can be fetched.
        scriptEntry.addObject("shot_entities", entityList);

        if (spread == null)
            Position.mount(Conversion.convertEntities(entities));

        // Get the entity at the bottom of the entity list, because
        // only its gravity should be affected and tracked considering
        // that the other entities will be mounted on it
        final dEntity lastEntity = entities.get(entities.size() - 1);

        if (gravity == null) {

            String entityType = lastEntity.getEntityType().name();

            for (Gravity defaultGravity : Gravity.values()) {

                if (defaultGravity.name().equals(entityType)) {

                    gravity = new Element(defaultGravity.getGravity());
                }
            }

            // If the gravity is still null, use a default value
            if (gravity == null) {
                gravity = new Element(0.115);
            }
        }

        if (speed == null) {
            Vector v1 = lastEntity.getLocation().toVector();
            Vector v2 = destination.toVector();
            Vector v3 = Velocity.calculate(v1, v2, gravity.asDouble(), height.asDouble());
            lastEntity.setVelocity(v3);
        }
        else if (lead == null) {
            Vector relative = destination.clone().subtract(originLocation).toVector();
            lastEntity.setVelocity(relative.normalize().multiply(speed.asDouble()));
        }
        else {
            double g = 20;
            double v = speed.asDouble();
            Vector relative = destination.clone().subtract(originLocation).toVector();
            double testAng = Velocity.launchAngle(originLocation, destination.toVector(), v, relative.getY(), g);
            double hangTime = Velocity.hangtime(testAng, v, relative.getY(), g);
            Vector to = destination.clone().add(lead.clone().multiply(hangTime)).toVector();
            relative = to.clone().subtract(originLocation.toVector());
            Double dist = Math.sqrt(relative.getX() * relative.getX() + relative.getZ() * relative.getZ());
            if (dist == 0) dist = 0.1d;
            testAng = Velocity.launchAngle(originLocation, to, v, relative.getY(), g);
            relative.setY(Math.tan(testAng) * dist);
            relative = relative.normalize();
            v = v + (1.188 * Math.pow(hangTime, 2));
            relative = relative.multiply(v / 20.0d);
            lastEntity.setVelocity(relative);
        }

        if (spread != null) {
            Vector base = lastEntity.getVelocity().clone();
            float sf = spread.asFloat();
            for (dEntity entity: entities) {
                Vector newvel = Velocity.spread(base, (CoreUtilities.getRandom().nextDouble() > 0.5f ? 1: -1) * Math.toRadians(CoreUtilities.getRandom().nextDouble() * sf),
                        (CoreUtilities.getRandom().nextDouble() > 0.5f ? 1: -1) * Math.toRadians(CoreUtilities.getRandom().nextDouble() * sf));
                entity.setVelocity(newvel);
            }
        }

        // A task used to trigger a script if the entity is no longer
        // being shot, when the script argument is used
        BukkitRunnable task = new BukkitRunnable() {

            boolean flying = true;
            dLocation lastLocation = null;
            Vector lastVelocity = null;

            public void run() {

                // If the entity is no longer spawned, stop the task
                if (!lastEntity.isSpawned()) {
                    flying = false;
                }

                // Otherwise, if the entity is no longer traveling through
                // the air, stop the task
                else if (lastVelocity != null) {
                    if (lastVelocity.distance
                            (lastEntity.getBukkitEntity().getVelocity()) < 0.05) {
                        flying = false;
                    }
                }

                // Stop the task and run the script if conditions
                // are met
                if (!flying) {

                    this.cancel();

                    if (script != null) {
                        // Build a queue out of the targeted script
                        List<ScriptEntry> entries = script.getContainer().getBaseEntries(scriptEntry.entryData.clone());
                        ScriptQueue queue = InstantQueue.getQueue(ScriptQueue.getNextId(script.getContainer().getName()))
                                .addEntries(entries);

                        // Add relevant definitions
                        queue.addDefinition("location", lastLocation.identify());
                        queue.addDefinition("shot_entities", entityList.toString());
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.