Solved BukkitTask help! Scheduler not working.

Discussion in 'Plugin Development' started by ziimzy, May 20, 2013.

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

    ziimzy

    Hey guys I used this code before:
    Code:
    if(commandLabel.equalsIgnoreCase("Delay")){
                    Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable(){
                        public void run() {
     
    }
    },0,60);
            }
    but it stopped working so now ive started using a different way. I have tried anything and nothing is working for me. Here is the three classes I use:

    Main:

    Code:
    package me.Ziimzy.youtube;
     
    import java.util.logging.Logger;
     
    import org.bukkit.Bukkit;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.java.JavaPlugin;
     
     
    public class Main extends JavaPlugin {
       
    public final Logger logger = Logger.getLogger("Minecraft");
       
        public static Main plugin;
       
        @Override
        public void onDisable() {
            PluginDescriptionFile pdfFile = this.getDescription();
            this.logger.info(pdfFile.getName() + " has been Disabled.");
        }
       
       
        @Override
        public void onEnable() {
            PluginDescriptionFile pdfFile = this.getDescription();
            this.logger.info(pdfFile.getName() + " Version" + pdfFile.getVersion() + " has been Enabled.");
            Bukkit.getServer().getPluginManager().registerEvents(new BukkitListener(this), this);
            this.saveDefaultConfig();
     
        }
       
    }
    Repeater:

    Code:
    package me.Ziimzy.youtube;
     
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.scheduler.BukkitRunnable;
     
    public class Repeater extends BukkitRunnable {
        //Extends BukkitRunnable to create a run method
       
        private final JavaPlugin plugin;
        //Declares your plugin variable
       
        public Repeater(JavaPlugin plugin) {
        this.plugin = plugin;
        }
        //This is called from your main class and sets your plugin variable
       
        public void run() {
     
            plugin.getServer().broadcastMessage("Welcome to Bukkit! Remember to read the documentation!");
           
           
        }
        }
    BukkitListener:

    Code:
    package me.Ziimzy.youtube;
     
     
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.scheduler.BukkitTask;
     
    public class BukkitListener implements Listener {
       
       
        private static Main plugin;
       
        public BukkitListener(Main plugin){
            this.plugin = plugin;
           
        }
     
     
        @EventHandler
        public void onJoin(PlayerJoinEvent event) {
            BukkitTask task = new Repeater(plugin).runTaskLater(plugin, 20);
        }
     
     
    }
    When someone joins nothing happens at all. There are no errors on startup at all. Only errors i get in eclipse are on

    BukkitTask task = new Repeater(plugin).runTaskLater(plugin, 20);

    saying "task" is not used and on

    public BukkitListener(Main plugin){
    this.plugin = plugin;

    saying that "The static field BukkitListener.plugin should be accessed in a static way"

    Thats it :( Any help is appreciated. As you can probably tell im not very experienced with Java but im learning! Thanks for any help!
     
  2. Offline

    Nitnelave

    In the Main class, what is the purpose of the static Main plugin? To keep a reference to itself? You don't seem to use it in other classes, because you pass the reference in the constructor.
    And you don't need the "this" everywhere. A simple saveDefaultConfig() without the this works too.

    I think you should review what static and final mean in Java : final is that it cannot be changed (one assignment in the constructor, nothing else), and static is that it depends only on the class, not on the instances. But you'll find better explanations out there.
     
  3. Offline

    ziimzy

    Nitnelave
    Okay I will change that. But will that help fix my problem?
     
  4. Offline

    Nitnelave

    I don't know, give it a try! You could also use the "print" debugging method: Print stuff to the screen as the program runs, to see what gets called. For example, you could add a Server.broadCast("A player joined") in the listener, just to check that it is called.
     
  5. Offline

    ziimzy

    Solved!
     
Thread Status:
Not open for further replies.

Share This Page