[HorseMount] How to make a casting timer and make the player ride a horse?

Discussion in 'Plugin Development' started by BaHeTo0, Aug 12, 2014.

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

    BaHeTo0

    I realy need help with examples of code if you can please.

    So what i need is to know how can i do a casting timer. For example you rightclick a saddle and a 5 seconds start counting down and if you move or engage pvp the countdown stops and nothing happens but if you dont and the countdown reaches 0 you will be set to ride a horse and if you leave the horse it despawns!
     
  2. Offline

    Totom3

  3. To make the player ride the horse do a little code like this:

    Code:java
    1. horse.setPassenger(player);
     
  4. Offline

    BaHeTo0

    thanks, but still i dont know how to do the casting
     
  5. Offline

    Jordymt

    The countdown can be done with what Totom3 sais; scheduled programming.
     
  6. Offline

    fireblast709

    BaHeTo0 When you schedule the task, you either get a task ID or a BukkitTask object. Store that in a Map<UUID, Integer/BukkitTask> (depending on which methods you use), and check if they have a Map entry in the movement/damage listener. If existant, cancel the task.
     
  7. Offline

    BaHeTo0

    fireblast709

    as i said "I realy need help with examples of code if you can please."
     
  8. Offline

    mythbusterma

    BaHeTo0

    Code:
    new BukkitRunnable () {
      @Override
      public void run() {
        // mount the player on his horse
      }
    }.runTaskLater(plugin, time);
    That's an example.
     
    fireblast709 likes this.
  9. Offline

    fireblast709

    To expand it a tiny bit:
    Code:
    BukkitTask task = new BukkitRunnable()
    {
        @Override
        public void run()
        {
            // Mount
            // remove BukkitTask from Map
        } 
    }.runTaskLater(plugin, time);
    // add BukkitTask to Map
    Your listeners would do the following:
    • remove from Map, store the value returned
    • if the return value is not null, invoke cancel()
     
Thread Status:
Not open for further replies.

Share This Page