Running a bunch of code every specified interval?

Discussion in 'Plugin Development' started by n31ln3t, Jul 18, 2013.

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

    n31ln3t

    Hello there,

    I need to make a bit of code get executed for every 7 minutes, how would I go about doing this, I know there are schedulers, but I'm having some trouble trying to get it to work.

    So basically, I need this.

    [Syntax type="java"]
    every7minutes(Player player){
    getConfig.set("player.getDisplayName", getConfig.getInt("player.getDisplayName")-1));
    }
    [/Syntax]

    EDIT: Also, how do I make it so it makes that code on top like what people's code usually looks like on Bukkit? :D
     
  2. Offline

    blablubbabc

    This could contain mistakes, as I am writing it from head:
    PHP:
    plugin.getServer().getScheduler().runTaskTimer(plugin, new Runnable() {
    @
    Override
    public void run() {
    for (
    Player player Bukkit.getServer().getPlayersOnline()) {
    every7minutes(player);
    }
    }
     
    1L20 60L);
    Also, you should fix your every7minutes-method: "player.getDisplayName" will not do what you expect, because of the quotation marks.
     
  3. Offline

    Eats_Rainbows

    Wouldn't you use a repeating task?
     
  4. Offline

    blablubbabc

    This IS a repeating task.
     
  5. Offline

    Eats_Rainbows

    Ahhh, I read it as runTaskLater not runTaskTimer
     
  6. Offline

    pwnpk23

    You guys are so hasty to say the code but not where it goes inside. Do this:


    Code:java
    1. public void activateTheMethod(){ //this repeats every 7 seconds. Debounce it if nessesarry with a variable to keep from running too much.
    2. getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
    3. public void run() {
    4. every7Minutes(player);
    5. }
    6. }, 0, 20*7); //each 20 is one second. 1 tick = 1/20th of a second. Therefore 20*7=7 seconds
    7. }
    8.  
    9. public void onEnable(){
    10. activateTheMethod(); //add this to onEnable()
    11. }
     
Thread Status:
Not open for further replies.

Share This Page