Scheduled Delay

Discussion in 'Plugin Development' started by Giorgio, Dec 1, 2012.

Thread Status:
Not open for further replies.
  1. Offline

    Giorgio

    Hello Everyone, Ive recently been working with Bukkit schedule. And was woundering how to implement a scheduled delay to an event?

    if i was to define player once more inside these bracekets it would not work:

    Code:
    public void run(){
     
    }
    Also for my event it looks like this but does not work at all:

    Code:
        @EventHandler
            public void onInteract(PlayerInteractEvent event) {
            this.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
                public void run() {
                    Player player = event.getPlayer();
                    if (player.getItemInHand().getType() == Material.IRON_SWORD && (event.getAction() == Action.RIGHT_CLICK_BLOCK)) {
                            player.setVelocity(player.getVelocity().add(new Vector(0, 1.0, 0)))
                }
            }, 60L);
                    }
     
  2. Offline

    skwh

    I'm not sure if this was just a typo, but you might want a semicolon after you set the player's velocity.
     
  3. Offline

    CeramicTitan Retired Staff

    Lucky for you i'm a professional when it comes to schedulers:
    Code:
    private *main class name* plugin;
     
    private  *class name*(*Main class name* plugin){
            this.plugin = plugin;
    }
     
    @EventHandler
          public void onInteract(PlayerInteractEvent event) {
          final Player player = event.getPlayer();
          if (player.getItemInHand().getType() == Material.IRON_SWORD && (event.getAction() == Action.RIGHT_CLICK_BLOCK)) {
          Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
              @Override
              public void run() {
              player.setVelocity(player.getVelocity().add(new Vector(0, 1.0, 0)));
              }
          }, -time in seconds-*20L);
      }
    }
    }
     
    DPOH-VAR likes this.
Thread Status:
Not open for further replies.

Share This Page