Package org.bukkit.scheduler

Examples of org.bukkit.scheduler.BukkitRunnable


        // Get the last entity on the list
        final Entity entity = entities.get(entities.size() - 1).getBukkitEntity();
        final LivingEntity finalController = controller != null ? controller.getLivingEntity() : null;

        BukkitRunnable task = new BukkitRunnable() {

            Location location = null;
            Boolean flying = true;

            public void run() {

                if (freeflight) {

                    // If freeflight is on, and the flying entity
                    // is ridden by another entity, let it keep
                    // flying where the controller is looking

                    if (!entity.isEmpty() && finalController.isInsideVehicle()) {
                        location = finalController.getEyeLocation()
                                     .add(finalController.getEyeLocation().getDirection()
                                     .multiply(30));
                    }
                    else {
                        flying = false;
                    }
                }
                else {

                    // If freelight is not on, keep flying only as long
                    // as there are destinations left

                    if (destinations.size() > 0) {
                        location = destinations.get(0);
                    }
                    else {
                        flying = false;
                    }
                }

                if (flying && entity.isValid()) {

                    // To avoid excessive turbulence, only have the entity rotate
                    // when it really needs to
                    if (!Rotation.isFacingLocation(entity, location, rotationThreshold)) {

                        Rotation.faceLocation(entity, location);
                    }

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

                    entity.setVelocity(v3);

                    // If freeflight is off, check if the entity has reached its
                    // destination, and remove the destination if that happens
                    // to be the case

                    if (!freeflight) {

                        if (Math.abs(v2.getX() - v1.getX()) < 2 && Math.abs(v2.getY() - v1.getY()) < 2
                            && Math.abs(v2.getZ() - v1.getZ()) < 2) {

                            destinations.remove(0);
                        }
                    }
                }
                else {

                    flying = false;
                    this.cancel();
                }
            }
        };

           task.runTaskTimer(DenizenAPI.getCurrentInstance(), 0, 3);
    }
View Full Code Here


        final int height = heightElement.asInt();
        final int depth = depthElement.asInt();

        no_physics = !doPhysics;
        if (delayed.asBoolean()) {
            new BukkitRunnable() {
                @Override
                public void run() {
                    boolean was_static = preSetup(locations);
                    int index = 0;
                    long start = System.currentTimeMillis();
View Full Code Here

        Messaging.send(sender, "Submitting...");
        final DebugSubmit submit = new DebugSubmit();
        submit.recording = dB.Recording.toString();
        dB.Recording = new StringBuilder();
        submit.start();
        BukkitRunnable task = new BukkitRunnable() {
            public void run() {
                if (!submit.isAlive()) {
                    if (submit.Result == null) {
                        Messaging.sendError(sender, "Error while submitting.");
                    }
                    else {
                        Messaging.send(sender, "Successfully submitted to http://mcmonkey.org" + submit.Result);
                    }
                    this.cancel();
                }
            }
        };
        task.runTaskTimer(DenizenAPI.getCurrentInstance(), 0, 10);
    }
View Full Code Here

        if (isArmor(item)) {
            for (final Player player : location.getWorld().getPlayers()) {
                if (Utilities.checkLocation(player, location, 2.5)) {
                    final ItemStack[] armor_contents = player.getInventory().getArmorContents().clone();
                    final Vector velocity = event.getVelocity();
                    new BukkitRunnable() {
                        @Override
                        public void run() {
                            ItemStack[] new_armor = player.getInventory().getArmorContents();
                            for (int i = 0; i < new_armor.length; i++) {
                                ItemStack before = armor_contents[i];
View Full Code Here

        Entity entity = event.getEntity();
        if (!(entity instanceof Player))
            return;
        final Player player = (Player) entity;
        final ItemStack[] oldArmor = player.getInventory().getArmorContents();
        new BukkitRunnable() {
            @Override
            public void run() {
                ItemStack[] newArmor = player.getInventory().getArmorContents();
                for (int i = 0; i < 4; i++) {
                    ItemStack o = oldArmor[i];
View Full Code Here

                                "player equips " + armor.identifySimple(),
                                "player equips " + armor.identifyMaterial()),
                null, new dPlayer(player), context).toUpperCase();

        if (determination.startsWith("CANCELLED")) {
            new BukkitRunnable() {
                @Override
                public void run() {
                    player.updateInventory();
                }
            }.runTaskLater(DenizenAPI.getCurrentInstance(), 1);
View Full Code Here

                                "player unequips " + armor.identifySimple(),
                                "player unequips " + armor.identifyMaterial()),
                null, new dPlayer(player), context).toUpperCase();

        if (determination.startsWith("CANCELLED")) {
            new BukkitRunnable() {
                @Override
                public void run() {
                    player.updateInventory();
                }
            }.runTaskLater(DenizenAPI.getCurrentInstance(), 1);
View Full Code Here

        // 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());
                        queue.addDefinition("pushed_entities", entityList.toString());
                        queue.addDefinition("last_entity", lastEntity.identify());
                        queue.start();
                    }
                    scriptEntry.setFinished(true);
                }
            }
        };
        task.runTaskTimer(DenizenAPI.getCurrentInstance(), 0, 2);
    }
View Full Code Here

        // 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

            if (entity.isSpawned()) {
                Rotation.faceLocation(entity.getBukkitEntity(), loc);
            }
        }
        if (duration != null && duration.getTicks() > 2) {
            BukkitRunnable task = new BukkitRunnable() {
                long bounces = 0;
                public void run() {
                    bounces += 2;
                    if (bounces > duration.getTicks()) {
                        this.cancel();
                        return;
                    }
                    for (dEntity entity : entities) {
                        if (entity.isSpawned()) {
                            Rotation.faceLocation(entity.getBukkitEntity(), loc);
                        }
                    }
                }
            };
            task.runTaskTimer(DenizenAPI.getCurrentInstance(), 0, 2);
        }
    }
View Full Code Here

TOP

Related Classes of org.bukkit.scheduler.BukkitRunnable

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.