scheduleSyncDelayedTask

Discussion in 'Plugin Development' started by StefanXX, May 14, 2014.

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

    StefanXX

    Hello im making a plugin for my server
    and im new so.
    i have this code that is not working because it's not in the main javaplugin class
    but i don't knoW how to fix it:
    http://pastebin.com/uVhWjUFz
    thanks in advice
     
  2. StefanXX Forgive me if this is wrong - I can't access pastebin at work. But it sounds like you're trying to use a scheduleSyncDelayedTask in a class that isn't your main class? If that's what you mean, then all you need to do is pass an instance of your main class to whichever class you're using, and then use that.
     
  3. Offline

    StefanXX

    how do i do that (im new) just a simple example what i type im the main class the code that is probably breaking everything is this:
    Bukkit.getScheduler().scheduleSyncDelayedTask((Plugin) this, new Runnable()
    it would work if it was like this:
    Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable()
    but this is only used in the main class
     
  4. Offline

    Bailey Payne

  5. Offline

    KanTe

    if it isn't in your main class:
    Create a instance of your plugin:

    Code:
    private YourPluginClass plugin;
     
    public YouClass(YourPluginClass plugin) {
        this.plugin = plugin;
    }
    
    YourPluginClass is the name of your main class; YouClass is the class where your Listener is

    then use this line of code:

    Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable()

    Because you can't can't cast a class which doesn't extend JavaPlugin to a JavaPlugin class
     
  6. Offline

    Drew1080

    StefanXX
    Pass the instance of your main class as the argument, instead of casting that class to the Plugin class.
     
  7. Offline

    StefanXX

    你说什么?
     
  8. Offline

    Drew1080

    I said you need to pass the instance of your main class like KanTe showed you how todo as the argument and not cast your listener class to Plugin.
     
  9. Offline

    StefanXX

    works perfectly thanks :)
     
Thread Status:
Not open for further replies.

Share This Page