Solved Scheduled Task doesn't work

Discussion in 'Plugin Development' started by TGF, Apr 7, 2013.

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

    TGF

    Hi. It's my Scheduled code:
    PHP:
    final Long time config.getLong("time");
    int id Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {
        public 
    void run() {
            if (
    time != 0) {
                
    player.sendMessage(ChatColor.BLUE "Good");
            }
        }
    }, 
    20Ltime 20L);
    In console it's return me that this cannot be null;
    What's wrong here? :)
     
  2. Offline

    1SmallVille1

    sigh... you can't just say "it doesn't work! fix it!" you have to show us the error or something if there isn't one, tell us where it's going wrong and what you're trying to do
     
  3. Offline

    TGF

    Okay then. It's my new
    Task.class (open)

    PHP:
    package pl.shaquu.eventsguardian;
     
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.entity.Player;
     
    public class 
    Task{
     
            public static 
    Free plugin;
        public 
    Task(Free plugin) {
        }
        public static 
    void startScheduler(){
            final 
    Long time Free.config.getLong("Memory.time");
            
    int id Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable(){
                public 
    void run(){
                    if(
    time != 0){
                        
    //do sth
                    
    }
                }
            }, 
    20Ltime*20L);
        }
     
    }

    I use it in onEnable as Task.startScheduler();

    I get errors:
    java.lang.IllegalArgumentException: Plugin cannot be null
    at pl.shaquu.eventsguardian.Task.startScheduler(Task.java:19)
    at pl.shaquu.eventsguardian.Free.onEnable(Free.java:27) 27 line is this with int id = Bukkit[...]

    I am complete lost now ;)
     
  4. ... on public Task(FreePlugin plugin) do this.plugin = plugin...

    Learn to read error logs: [...] Plugin cannot be null
     
  5. Offline

    Compressions

    TGF Use a BukkitRunnable.
     
  6. Compressions
    He would get the same error because he's giving a null value to the task.
     
    Compressions likes this.
  7. Offline

    TGF

    Another problem.
    I have created this in the main class:
    PHP:
        public void startScheduler(){
            final 
    Long time Free.config.getLong("Memory.time");
                if(
    time != 0){
                    new 
    BukkitRunnable() {
                        @
    Override
                        
    public void run() {
                            
    Boolean debug config.getBoolean(".debug");
                                if(
    debug == true){
                                    for(
    Player player Bukkit.getOnlinePlayers()){
                                        if(
    player.isOp()){
                                            
    player.sendMessage(ChatColor.BLUE "blah bla");
                                        }
                                    }
                                }
                            }
                    }.
    runTaskTimer(this20time*20);
                }
        }
    startScheduler() in onEnable
    No errors, not working.

    But it looks like it's working...
    Spigot stats:
    Pct Total Pct Tick Total Avg Count Vio Event
    6.64% 522.41% 1.045 s 261.2025 ms 0.00k 48.72%Task: interval 80

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
  8. Debug your config values because apparently you're heavily relying on them.

    Most likely the ".debug" key doesn't exist since it's not valid.
     
  9. Offline

    Compressions

    TGF We do not offer support for Spigot issues.
     
  10. Offline

    TGF

    Digi I have removed "." and the same happen. I will debug config ;)

    Compressions It't just event's timings to show You that it's sth wrong... Normally I run on CB.
     
Thread Status:
Not open for further replies.

Share This Page