Solved Bukkit Runnable

Discussion in 'Plugin Development' started by JoeyDevs, Jul 13, 2014.

Thread Status:
Not open for further replies.
  1. Hey Guys,

    Maybe this is a little shame but I forget how to make a 1 second runnable or something like that.
     
  2. This should help you.
     
  3. Offline

    EnderTroll68

    Well a BukkitRunable just has to have a method in it named public void run() with an override attached. You said you wanted it to run every second so do something like this:
    Code:java
    1. Bukkit.getScheduler().scheduleSyncRepeatingTask(main, new BukkitRunnable() {
    2.  
    3. @Override
    4. public void run() {
    5. System.out.println("Boob");
    6. }
    7.  
    8. }, 0, 20);


    That will make it so the plugin will run that runnable with no delay, and it will run every 20 ticks, which is 1 second.
     
  4. JoeyDevs

    http://wiki.bukkit.org/Scheduler_Programming

    That's a good tutorial.

    EnderTroll68

    The @Override is a Java Annotation. I was reading an article on Annotations, apparently, you don't actually need the @Override annotation. It's just a compile-time annotation that will give you a warning if the method does NOT actually override a super class method.

    The run() method is probably a bad example since the name probably isn't going to change.

    Take me for example. My plugins depends on BattleArena by Alkarinv (latest version 3.9.7.9). Let's say that I override HIS onFinish() method:
    Code:java
    1. @Override
    2. public void onFinish() {
    3. // ...
    4. }


    Let's say Alkarinv changes the name of onFinish() to onDone() in the next version 3.9.8 ...Since I have the @Override annotation, I will get a compiler time warning that onFinish() does NOT override another method.

    Just wanted to explain to people reading this thread WHY you used the @Override annotation on the run() method. (if anyone was curious).

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  5. Got It! Thanks to you all
     
  6. Offline

    EnderTroll68

    Europia79
    Yes I am very much aware what the @Override annotation does, but considering he is asking a question that can easily be found in the Bukkit documentation, I was assuming that he did not want the big names to all the stuff, he just wanted to know how to do it.

    Edit: Realized this came off as a bit hostile, my bad
     
  7. EnderTroll68
    No man, you don't seem hostile at all. I figured you did know. I just wanted to add further explanation as to WHY in case anyone was curious.
    Me, I'm still pretty much a beginner... So I remember seeing some code with @Override and some code without it... and thinking to myself: "WTF ?"
     
Thread Status:
Not open for further replies.

Share This Page