Scheduler

Discussion in 'Plugin Development' started by King_Amun_Ra, Apr 11, 2014.

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

    King_Amun_Ra

    I'm getting a stack trace that I don't understand when I am using this.

    Code:java
    1. Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
    2.  
    3. public void run() {
    4.  
    5. settings.getData().set(p.getUniqueId().toString() + "kits." + ".junkie", false);
    6.  
    7. }
    8.  
    9. }, (60 * 2) * 20);



    Here's the stack trace

    Code:
    Could not pass event PlayerInteractEvent to Main v6.1
    org.bukkit.event.EventException
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:294) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-11-g08fad7a-b3036jnks]
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-11-g08fad7a-b3036jnks]
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:501) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-11-g08fad7a-b3036jnks]
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:486) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-11-g08fad7a-b3036jnks]
        at org.bukkit.craftbukkit.v1_7_R2.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:195) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-11-g08fad7a-b3036jnks]
        at net.minecraft.server.v1_7_R2.PlayerInteractManager.interact(PlayerInteractManager.java:374) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-11-g08fad7a-b3036jnks]
        at net.minecraft.server.v1_7_R2.PlayerConnection.a(PlayerConnection.java:628) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-11-g08fad7a-b3036jnks]
        at net.minecraft.server.v1_7_R2.PacketPlayInBlockPlace.a(SourceFile:60) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-11-g08fad7a-b3036jnks]
        at net.minecraft.server.v1_7_R2.PacketPlayInBlockPlace.handle(SourceFile:9) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-11-g08fad7a-b3036jnks]
        at net.minecraft.server.v1_7_R2.NetworkManager.a(NetworkManager.java:147) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-11-g08fad7a-b3036jnks]
        at net.minecraft.server.v1_7_R2.ServerConnection.c(SourceFile:134) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-11-g08fad7a-b3036jnks]
        at net.minecraft.server.v1_7_R2.MinecraftServer.v(MinecraftServer.java:657) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-11-g08fad7a-b3036jnks]
        at net.minecraft.server.v1_7_R2.DedicatedServer.v(DedicatedServer.java:250) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-11-g08fad7a-b3036jnks]
        at net.minecraft.server.v1_7_R2.MinecraftServer.u(MinecraftServer.java:548) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-11-g08fad7a-b3036jnks]
        at net.minecraft.server.v1_7_R2.MinecraftServer.run(MinecraftServer.java:459) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-11-g08fad7a-b3036jnks]
        at net.minecraft.server.v1_7_R2.ThreadServerApplication.run(SourceFile:618) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-11-g08fad7a-b3036jnks]
    Caused by: java.lang.IllegalArgumentException: Plugin cannot be null
        at org.apache.commons.lang.Validate.notNull(Validate.java:203) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-11-g08fad7a-b3036jnks]
        at org.bukkit.craftbukkit.v1_7_R2.scheduler.CraftScheduler.validate(CraftScheduler.java:391) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-11-g08fad7a-b3036jnks]
        at org.bukkit.craftbukkit.v1_7_R2.scheduler.CraftScheduler.runTaskTimer(CraftScheduler.java:120) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-11-g08fad7a-b3036jnks]
        at org.bukkit.craftbukkit.v1_7_R2.scheduler.CraftScheduler.scheduleSyncRepeatingTask(CraftScheduler.java:116) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-11-g08fad7a-b3036jnks]
        at org.bukkit.craftbukkit.v1_7_R2.scheduler.CraftScheduler.scheduleSyncDelayedTask(CraftScheduler.java:100) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-11-g08fad7a-b3036jnks]
        at kits.KitSigns.onPlayerInteract5(KitSigns.java:296) ~[?:?]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_51]
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_51]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_51]
        at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.7.0_51]
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:292) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-11-g08fad7a-b3036jnks]
        ... 15 more
    [22:34:18] [Server thread/INFO]: [Main] Disabling Main v6.1
     
  2. Offline

    Barnyard_Owl

    The plugin object needs to be set as an instance of your main class. onEnable { plugin = this }
     
  3. Offline

    MooshViolet

    the ticks are readed in the form L. For example your number would be 20L for 1 second
     
  4. Offline

    coasterman10

    This may not be the main class, so it may not necessarily be this. But it does need to be initialized, so +1 to that aspect.
     
  5. Offline

    Barnyard_Owl

  6. Offline

    coasterman10

    When you wrote :
    that would imply that this is the main plugin class, or plugin is a static variable, which would be a subpar design choice.
     
    xTigerRebornx likes this.
  7. Offline

    King_Amun_Ra

  8. Offline

    coasterman10

    King_Amun_Ra Whichever the plugin variable is needs to be initialized to your main class that extends JavaPlugin. If this code is in your main class, then just replace "plugin" with "this". If not, then you need to pass your plugin via a constructor.
     
  9. Offline

    King_Amun_Ra

    coasterman10 I did
    and this is still happening
    Code:
        public void KitSigns(main instance) {
            plugin = instance;
        }
     
  10. Offline

    coasterman10

    That's not a constructor, so it isn't being executed. This is what the code should be for it to be called as a constructor:
    Code:java
    1. public KitSigns(main instance) {
    2. plugin = instance;
    3. }
     
  11. Offline

    King_Amun_Ra

    coasterman10 Now I'm getting errors in my registering for events

    Code:
    Bukkit.getServer().getPluginManager().registerEvents(new KitSigns(), this);
     
    private final KitSigns kitSigns = new KitSigns();
    Both have errors

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

    Gater12

    King_Amun_Ra
    Because you specified in your constructor for the class for your Main class instance. So put this in the constructor.
     
  13. Offline

    King_Amun_Ra

    Gater12 What in my constructor?
     
  14. Offline

    coasterman10

    The constructor takes an argument:
    Code:java
    1. public KitSigns(main instance)

    You need to pass this argument. You should know this, it is basic Java.

    What are the errors?
     
  15. Offline

    King_Amun_Ra

    @coastman10 it just saids undefined for KitSigns and for the registering. I have the constructor working he just said add this to it and never said anything else.
     
  16. Offline

    xTigerRebornx

    King_Amun_Ra When Gater12 said put this in the constructor, he was referring to the keyword "this", which is used to reference to the current object you have (i.e. the instance of your class that extends JavaPlugin)
     
  17. Offline

    coasterman10

    King_Amun_Ra Is the class actually called KitSigns, and if so, is it in the same package as your main class? Did you forget to import it perhaps?
     
  18. Offline

    King_Amun_Ra

    coasterman10 Yes it is called KitSigns and no it is not in the same package I'll move it. And where would I add this? I've never really used this before sorry for not knowing to much about this. I moved it and no problems solve
     
  19. Offline

    coasterman10

    If it's not in the same package, that's fine. You just need to import it, which your IDE may offer as an automatic suggestion
     
  20. Offline

    King_Amun_Ra

    coasterman10 Yes I have to correct imports

    coasterman10 thanks for the help I really don't know what I'm doing here never had to do this before sorry for being kinda nooby about this

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

    King_Amun_Ra

    So can anyone help?
     
Thread Status:
Not open for further replies.

Share This Page