repeating task

Discussion in 'Plugin Development' started by stamline, Apr 23, 2014.

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

    stamline

    Hi, i need to use a repeating task in another class:
    This class is "my own API" so i need to get it from other classes to....

    Here´s the code im using right now:
    Code:java
    1. public static void BarOfficial(final Player player){
    2. plugin.getServer().getScheduler().scheduleSyncRepeatingTask(//HERE, new Runnable(){
    3.  
    4. @Override
    5. public void run() {
    6. Random random = new Random();
    7. List<String> list = new ArrayList<>();
    8. list.add(ChatColor.GREEN + "Enjoy the fight");
    9. list.add(ChatColor.YELLOW + "Just another random Message!");
    10. String message = (String) list.get(random.nextInt(list.size()));
    11. BarAPI.setMessage(player, message);
    12. }
    13.  
    14. }, 0, 1 * 20);
    15. }

    It said i cant use "this".... and what can I use instead?.....
     
  2. Offline

    Zethariel

    Use the plugin instance. Get it from Bukkit's PluginManager
     
  3. Offline

    stamline

    Can you explain little more?



    You mean this:
    Code:java
    1. Main main;
    2. public <the class>(Main plugin) {
    3. this.main = plugin;
    4. }


    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  4. Offline

    itzrobotix

    Code:java
    1. private Plugin p;
    2.  
    3. //Method
    4. public Plugin getPlugin(){
    5. return p;
    6. }

    You mean like this because a scheduler takes a plugin.
     
  5. i need help with this aswell :(
     
  6. Offline

    stamline

    what should I put here?
    Code:java
    1. plugin.getServer().getScheduler().scheduleSyncRepeatingTask(HERE, new Runnable(){
     
  7. Offline

    itzrobotix

    Well is this;
    Code:java
    1. plugin.getServer().getScheduler().scheduleSyncRepeatingTask(HERE, new Runnable(){

    Inside the class that extends JavaPlugin?
     
  8. Offline

    stamline

    Yes, but.... in the code where it says "Here" what should I write instead?
     
  9. Offline

    SuppaTim

    If it's the main class (the JavaPlugin extending one) you should insert 'this' otherwise you should insert an instance of the main class.
     
Thread Status:
Not open for further replies.

Share This Page