Package net.aufdemrand.denizen.objects

Examples of net.aufdemrand.denizen.objects.dLocation


    public void onPlayerMove(PlayerMoveEvent event) {
        // Your code here (Or in a different event, of course! Just remember to add any events to breakDown() )
        // Create a context map
        Map<String, dObject> context = new HashMap<String, dObject>();
        // Add some things to it
        context.put("location", new dLocation(event.getTo()));
        // Fire the event!
        String determination = EventManager.doEvents(Arrays.asList("x or y or z"), null /* NPC */,
                new dPlayer(event.getPlayer()), context);
        // Parse the determination and edit the event accordingly here
        if (determination.equalsIgnoreCase("CANCELLED"))
View Full Code Here


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

        // Fetch required objects

        dLocation location = (dLocation) scriptEntry.getObject("location");
        Player player = ((BukkitScriptEntryData)scriptEntry.entryData).getPlayer().getPlayerEntity();


        // Debug the execution

        dB.report(scriptEntry, getName(), location.debug());


        player.setCompassTarget(location);

View Full Code Here

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

        dEntity originEntity = (dEntity) scriptEntry.getObject("originEntity");
        dLocation originLocation = scriptEntry.hasObject("originLocation") ?
                                   (dLocation) scriptEntry.getObject("originLocation") :
                                   new dLocation(originEntity.getEyeLocation()
                                               .add(originEntity.getEyeLocation().getDirection())
                                               .subtract(0, 0.4, 0));
        boolean no_rotate = scriptEntry.hasObject("no_rotate") && scriptEntry.getElement("no_rotate").asBoolean();

        // If there is no destination set, but there is a shooter, get a point
        // in front of the shooter and set it as the destination
        final dLocation destination = scriptEntry.hasObject("destination") ?
                                      (dLocation) scriptEntry.getObject("destination") :
                                      (originEntity != null ? new dLocation(originEntity.getEyeLocation()
                                                               .add(originEntity.getEyeLocation().getDirection()
                                                               .multiply(30)))
                                                            : null);

        // TODO: Should this be checked in argument parsing?
        if (destination == null) {
            dB.report(scriptEntry, getName(), "No destination specified!");
            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
View Full Code Here

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

        Element id = scriptEntry.getElement("map-id");
        dWorld create = scriptEntry.getdObject("new");
        dLocation reset = scriptEntry.getdObject("reset");
        Element image = scriptEntry.getElement("image");
        Element resize = scriptEntry.getElement("resize");
        Element text = scriptEntry.getElement("text");
        Element x = scriptEntry.getElement("x-value");
        Element y = scriptEntry.getElement("y-value");

        dB.report(scriptEntry, getName(), (id != null ? id.debug() : "") + (create != null ? create.debug() : "")
                + (reset != null ? reset.debug() : "") + (image != null ? image.debug() : "") + resize.debug()
                + (text != null ? text.debug() : "") + x.debug() + y.debug());

        MapView map = null;
        if (create != null) {
            map = Bukkit.getServer().createMap(create.getWorld());
            scriptEntry.addObject("created_map", new Element(map.getId()));
        }
        else if (id != null) {
            map = Bukkit.getServer().getMap((short) id.asInt());
            if (map == null)
                throw new CommandExecutionException("No map found for ID '" + id.asInt() + "'!");
        }
        else {
            throw new CommandExecutionException("The map command failed somehow! Report this to a developer!");
        }

        if (reset != null) {
            for (MapRenderer renderer : map.getRenderers()) {
                if (renderer instanceof DenizenMapRenderer) {
                    map.removeRenderer(renderer);
                    for (MapRenderer oldRenderer : ((DenizenMapRenderer) renderer).getOldRenderers())
                        map.addRenderer(oldRenderer);
                    map.setCenterX(reset.getBlockX());
                    map.setCenterZ(reset.getBlockZ());
                    map.setWorld(reset.getWorld());
                }
            }
        }
        else {
            DenizenMapRenderer dmr = null;
View Full Code Here

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

        dLocation location = (dLocation) scriptEntry.getObject("location");
        List<dEntity> entities = (List<dEntity>) scriptEntry.getObject("entities");

        // Report to dB
        dB.report(scriptEntry, getName(), aH.debugObj("location", location) +
                             aH.debugObj("entities", entities.toString()));
View Full Code Here

        if (event.getBlock().getType().hasGravity() // Must have gravity (sand, gravel, ...)
                && event.getBlock().getRelative(BlockFace.DOWN).getType().equals(Material.AIR)) { // Must be above air

            Map<String, dObject> context = new HashMap<String, dObject>();

            context.put("location", new dLocation(event.getBlock().getLocation()));

            String determination = EventManager.doEvents(Arrays.asList("block falls",
                    dMaterial.getMaterialFrom(event.getBlock().getType(),
                            event.getBlock().getData()).identifySimple() + " falls"), null, null, context, true);
View Full Code Here

    //
    // -->
    @EventHandler
    public void onBlockRedstone(BlockRedstoneEvent event) {
        Map<String, dObject> context = new HashMap<String, dObject>();
        context.put("location", new dLocation(event.getBlock().getLocation()));
        context.put("old_current", new Element(event.getOldCurrent()));
        context.put("new_current", new Element(event.getNewCurrent()));
        String determination = EventManager.doEvents(Arrays.asList("redstone recalculated"), null, null, context, true);
        Element det = new Element(determination);
        if (det.isInt())
View Full Code Here

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

        dEntity originEntity = (dEntity) scriptEntry.getObject("originEntity");
        dLocation originLocation = scriptEntry.hasObject("originLocation") ?
                                   (dLocation) scriptEntry.getObject("originLocation") :
                                   new dLocation(originEntity.getEyeLocation()
                                               .add(originEntity.getEyeLocation().getDirection()));
        boolean no_rotate = scriptEntry.hasObject("no_rotate") && scriptEntry.getElement("no_rotate").asBoolean();

        // If there is no destination set, but there is a shooter, get a point
        // in front of the shooter and set it as the destination
        final dLocation destination = scriptEntry.hasObject("destination") ?
                                      (dLocation) scriptEntry.getObject("destination") :
                                      (originEntity != null ? new dLocation(originEntity.getEyeLocation()
                                                               .add(originEntity.getEyeLocation().getDirection()
                                                               .multiply(30)))
                                                            : null);

        // TODO: Same as PUSH -- is this the place to do this?
        if (destination == null) {
            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);
 
View Full Code Here

        if (NotableManager.isType(id, dLocation.class)) {
            dB.echoError("Notable tag '" + event.raw_tag + "': id was not found.");
        }

        dLocation location = (dLocation) NotableManager.getSavedObject(id);

        Attribute attribute = new Attribute(event.raw_tag, event.getScriptEntry());
        attribute.fulfill(1);
        tag = location.getAttribute(attribute);

        event.setReplaced(tag);

    }
View Full Code Here

    public void locationTags(ReplaceableTagEvent event) {

        if (!event.matches("location", "l") || event.replaced()) return;

        // Stage the location
        dLocation loc = null;

        // Check name context for a specified location, or check
        // the ScriptEntry for a 'location' context
        String context = event.getNameContext();
        if (event.hasNameContext() && dLocation.matches(context))
            loc = dLocation.valueOf(context);
        else if (event.getScriptEntry().hasObject("location"))
            loc = (dLocation) event.getScriptEntry().getObject("location");

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

        // Build and fill attributes
        Attribute attribute = event.getAttributes();
        event.setReplaced(loc.getAttribute(attribute.fulfill(1)));

    }
View Full Code Here

TOP

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

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.