Problem with Delayed Tasks

Discussion in 'Plugin Development' started by lucaspeedstack, Apr 27, 2014.

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

    lucaspeedstack

    I want to make a delayed task and I am using this method.
    I created a method in my Main Class which contains this:

    Code:java
    1. public static Main getPlugin() {
    2. return (Main) Bukkit.getServer().getPluginManager().getPlugin("VoidKits");
    3. }


    Then in another class I did this:

    Code:java
    1. Main.getPlugin().getServer().getScheduler().scheduleSyncDelayedTask(Main.getPlugin(), new Runnable() {
    2. public void run() {
    3. cooldown.remove(p.getName());
    4. Chat.getChat().sendMessage(p, "&cYou are no longer on cooldown!");
    5.  
    6. }


    And I get this error:
    Code:
    [11:56:29 ERROR]: Could not pass event PlayerInteractEvent to MystiKits v0.9
    org.bukkit.event.EventException
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja
    va:320) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
            at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.jav
    a:62) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
            at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.j
    ava:486) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
            at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.j
    ava:471) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
            at org.bukkit.craftbukkit.v1_7_R1.event.CraftEventFactory.callPlayerInte
    ractEvent(CraftEventFactory.java:195) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b30
    20jnks]
            at org.bukkit.craftbukkit.v1_7_R1.event.CraftEventFactory.callPlayerInte
    ractEvent(CraftEventFactory.java:165) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b30
    20jnks]
            at net.minecraft.server.v1_7_R1.PlayerConnection.a(PlayerConnection.java
    :604) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
            at net.minecraft.server.v1_7_R1.PacketPlayInBlockPlace.a(SourceFile:60)
    [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
            at net.minecraft.server.v1_7_R1.PacketPlayInBlockPlace.handle(SourceFile
    :9) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
            at net.minecraft.server.v1_7_R1.NetworkManager.a(NetworkManager.java:146
    ) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
            at net.minecraft.server.v1_7_R1.ServerConnection.c(SourceFile:134) [craf
    tbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
            at net.minecraft.server.v1_7_R1.MinecraftServer.u(MinecraftServer.java:6
    55) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
            at net.minecraft.server.v1_7_R1.DedicatedServer.u(DedicatedServer.java:2
    50) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
            at net.minecraft.server.v1_7_R1.MinecraftServer.t(MinecraftServer.java:5
    45) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
            at net.minecraft.server.v1_7_R1.MinecraftServer.run(MinecraftServer.java
    :457) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
            at net.minecraft.server.v1_7_R1.ThreadServerApplication.run(SourceFile:6
    17) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    Caused by: java.lang.NullPointerException
            at me.lucaspeedstack.skits.events.FrogInteract.onInteract(FrogInteract.j
    ava:40) ~[?:?]
            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.ja
    va:318) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
            ... 15 more
    
    Help?
     
  2. Offline

    BlazingBroGamer

    lucaspeedstack
    Can show your full code, since it says its at line "40" of FrogInteract.java
     
  3. Offline

    lucaspeedstack

    Line 40 is the line:
    Code:java
    1. Main.getPlugin().getServer().getScheduler().scheduleSyncDelayedTask(Main.getPlugin(), new Runnable() {
     
  4. Offline

    BlazingBroGamer

    lucaspeedstack
    It says its null, so are you sure you have the plugin in your folder with the exact name?
     
  5. Offline

    lucaspeedstack

    yes

    BlazingBroGamer
    Fixed! Wrong name in Plugin.yml
    Thanks so much :D

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  6. lucaspeedstack Where ever possible, you should avoid hard-coded references. Especially if this is going to be a public thing. You should just store the instance rather than using the getPlugin thing because, as you've already seen, it messes up if the name isn't right. You could get the name from the description file I guess which would solve that issue but it's easier (in my opinion) to just use the instance.
     
    BillyGalbreath likes this.
Thread Status:
Not open for further replies.

Share This Page