Package org.bukkit.scheduler

Examples of org.bukkit.scheduler.BukkitRunnable


            }
        }

        // 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());
                        queue.addDefinition("last_entity", lastEntity.identify());

                        // Handle hit_entities definition
                        dList hitEntities = new dList();
                        for (dEntity entity: entities) {
                            if (arrows.containsKey(entity.getUUID())) {
                                dEntity hit = arrows.get(entity.getUUID());
                                arrows.remove(entity.getUUID());
                                if (hit != null) {
                                    hitEntities.add(hit.identify());
                                }
                            }
                        }
                        queue.addDefinition("hit_entities", hitEntities.identify());

                        // Start it!
                        queue.start();
                    }

                    scriptEntry.setFinished(true);
                }
                else {
                    // Record it's position in case the entity dies
                    lastLocation = lastEntity.getLocation();
                    lastVelocity = lastEntity.getVelocity();
                }
            }
        };

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


    public static void displayLoadingBar(final String text, final String completeText, final Player player, final int healthAdd, final long delay, final boolean loadUp) {
        PacketPlayOutSpawnEntityLiving mobPacket = getMobPacket(text, player.getLocation(), 200);
        PacketHelper.sendPacket(player, mobPacket);
        hasHealthBar.put(player.getName(), true);
        new BukkitRunnable() {
            int health = (loadUp ? 0 : 300);

            @Override
            public void run() {
                if ((loadUp ? health < 300 : health > 0)) {
                    DataWatcher watcher = getWatcher(text, health);
                    PacketPlayOutEntityMetadata metaPacket = getMetadataPacket(watcher);
                    PacketHelper.sendPacket(player, metaPacket);
                    if (loadUp) {
                        health += healthAdd;
                    } else {
                        health -= healthAdd;
                    }
                } else {
                    DataWatcher watcher = getWatcher(text, (loadUp ? 300 : 0));
                    PacketPlayOutEntityMetadata metaPacket = getMetadataPacket(watcher);
                    PacketPlayOutEntityDestroy destroyEntityPacket = getDestroyEntityPacket();
                    PacketHelper.sendPacket(player, metaPacket);
                    PacketHelper.sendPacket(player, destroyEntityPacket);
                    hasHealthBar.put(player.getName(), false);
//Complete text
                    PacketPlayOutSpawnEntityLiving mobPacket = getMobPacket(completeText, player.getLocation(), 200);
                    PacketHelper.sendPacket(player, mobPacket);
                    hasHealthBar.put(player.getName(), true);
                    DataWatcher watcher2 = getWatcher(completeText, 300);
                    PacketPlayOutEntityMetadata metaPacket2 = getMetadataPacket(watcher2);
                    PacketHelper.sendPacket(player, metaPacket2);
                    new BukkitRunnable() {
                        @Override
                        public void run() {
                            PacketPlayOutEntityDestroy destroyEntityPacket = getDestroyEntityPacket();
                            PacketHelper.sendPacket(player, destroyEntityPacket);
                            hasHealthBar.put(player.getName(), false);
View Full Code Here

        String determination = EventManager.doEvents(events, null, player, context, true);

        if (determination.toUpperCase().startsWith("CANCELLED")) {
            event.setCancelled(true);
            final InventoryHolder holder = event.getInventory().getHolder();
            new BukkitRunnable() {
                @Override
                public void run() {
                    player.getPlayerEntity().updateInventory();
                    if (holder != null && holder instanceof Player)
                        ((Player) holder).updateInventory();
View Full Code Here

        String determination = EventManager.doEvents(events, null, player, context, true);

        if (determination.toUpperCase().startsWith("CANCELLED")) {
            event.setCancelled(true);
            final InventoryHolder holder = inventory.getHolder();
            new BukkitRunnable() {
                @Override
                public void run() {
                    player.getPlayerEntity().updateInventory();
                    if (holder != null && holder instanceof Player)
                        ((Player) holder).updateInventory();
View Full Code Here

            // So just add 1 more item to the stack.
            itemstack.setAmount(itemstack.getAmount()+1);
            // The event automatically resets durability to 0... instead,
            // let's delay a tick and set it back to what it was before.
            final Player player = event.getPlayer();
            new BukkitRunnable() {
                @Override
                public void run() {
                    itemstack.setDurability(itemstack.getType().getMaxDurability());
                    player.updateInventory();
                }
View Full Code Here

            // The Minecraft Help command doesn't like our added commands,
            // so let's force the server to use Bukkit's version if it's running
            // Mojang's version.
            // TODO: figure out a different workaround?
            // TODO: config option for this?
            new BukkitRunnable() {
                @Override
                public void run() {
                    if (!(knownCommands.get("help") instanceof VanillaCommandWrapper)) {
                        return;
                    }
View Full Code Here

        if(elevatorSlowMove) {

            final Location lastLocation = BukkitUtil.toLocation(player.getPosition());

            new BukkitRunnable(){
                @Override
                public void run () {
                    OfflinePlayer op = ((BukkitPlayer)player).getPlayer();
                    if(!op.isOnline()) {
                        cancel();
View Full Code Here

        button.setPowered(true);
        state.update();

        // todo: switch to block scheduling system when one is available
        (new BukkitRunnable() {
            @Override
            public void run() {
                button.setPowered(false);
                state.update();
            }
View Full Code Here

   * Installs the map if it is not already installed.
   */
  public void install()
  {
    // runnable downloads the map if it isn't installed
    BukkitRunnable runnable = new BukkitRunnable()
    {
      @Override public void run()
      { try { getZip(); } catch (IOException e) { e.printStackTrace(); } }
    };

    // run the task asynchronously to avoid locking up the main thread on a download
    runnable.runTaskAsynchronously(AutoReferee.getInstance());
  }
View Full Code Here

    @Override
    protected Prompt acceptValidatedInput(final ConversationContext context, boolean response)
    {
      if (response && context.getForWhom() instanceof Player)
        new BukkitRunnable()
        {
          @Override public void run()
          { match.joinMatch((Player) context.getForWhom()); }

        }.runTask(AutoReferee.getInstance());
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.