How the heck do i do this?

Discussion in 'Plugin Development' started by amitlin14, Jan 3, 2013.

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

    amitlin14

    Im making a dueling plugin. I want to add a time limit to a duel, i thought about making a delayed timer and check the metadata if he is dueling against the person he started the duel with, but what if the player died in the previous duel, re spawned, and then dueled the same person again? the timer will check if the player is still dueling against the opponent, and will cancel the duel.

    How can i make it in a fail safe way?

    thanks
     
  2. Offline

    DjTamo

    You could do multiple delayed timers that check every few ticks.
     
  3. Offline

    suckycomedian

    How are you adding them to the duel? Are the duels limited to two people?
     
  4. Offline

    DjTamo

    So something like this:

    Code:
    Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable(){
        public void run(){
        if (/* Do your checking here */) {
    Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable(){
        public void run(){
        if (/* Do your checking here */) {
    Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable(){
        public void run(){
        if (/* Do your checking here */) {
    }
    }
    }, 20L);
    }
    }
    }, 20L);
    }
    }
    }, 20L);
    This will check every second for 3 seconds to see if they are still in a duel. Extend the code as for long as you want it to be.
     
  5. Offline

    fireblast709

    repeating tasks
     
  6. Another way of looking at this is by not using the scheduler, instead, doing Long comparisons on the EntityDamageByEntity events.

    For example, log the time when the players start the duel. Each time the player gets hit by the other player, record that time and compare it to the starting time. If it's greater than 3 minutes, cancel the duel. If the player dies, cancel the duel as well.
     
    suckycomedian likes this.
  7. Offline

    fireblast709

    ^ which is a better way, saving resources
     
    MeneXia likes this.
Thread Status:
Not open for further replies.

Share This Page