runTaskLater() bugs

Discussion in 'Plugin Development' started by MrJoe223, Aug 17, 2013.

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

    MrJoe223

    Me again.

    I can't get this runTaskLater thing to work; I've consulted my buds, and even googled it. I keep getting errors at line 16, where it says that plugin(the first argument in the method) cannot be null. I don't have much experience with BukkitRunnable, so please forgive my ignorance.

    Class: http://pastebin.com/kBaFvW9S

    What'd I do wrong?
     
  2. Offline

    Axe2760

    I can only assume Sumo is your main class.

    Use a constructor:
    Code:
    public Game(Sumo plugin){
      this.plugin = plugin;
    }
    
    That way you can pass an instance of the main class to it when you call it, for example if you called it from the main class:
    Code:
    new Game(this)
    
    If you call it from another class, just repeat the process.
     
  3. Offline

    KedalionPlugins

    It doesn't work...
     
  4. Offline

    MrJoe223

    Unfortunately, that didn't seem to work either. However, we have a stack trace this time.
    Code:
    2013-08-17 13:13:05 [SEVERE] null
    org.bukkit.command.CommandException: Unhandled exception executing command 'sumo' in plugin Sumo v0.1
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46)
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:189)
        at org.bukkit.craftbukkit.v1_6_R2.CraftServer.dispatchCommand(CraftServer.java:523)
        at net.minecraft.server.v1_6_R2.PlayerConnection.handleCommand(PlayerConnection.java:964)
        at net.minecraft.server.v1_6_R2.PlayerConnection.chat(PlayerConnection.java:882)
        at net.minecraft.server.v1_6_R2.PlayerConnection.a(PlayerConnection.java:839)
        at net.minecraft.server.v1_6_R2.Packet3Chat.handle(SourceFile:49)
        at net.minecraft.server.v1_6_R2.NetworkManager.b(NetworkManager.java:296)
        at net.minecraft.server.v1_6_R2.PlayerConnection.e(PlayerConnection.java:118)
        at net.minecraft.server.v1_6_R2.ServerConnection.b(SourceFile:37)
        at net.minecraft.server.v1_6_R2.DedicatedServerConnection.b(SourceFile:30)
        at net.minecraft.server.v1_6_R2.MinecraftServer.t(MinecraftServer.java:590)
        at net.minecraft.server.v1_6_R2.DedicatedServer.t(DedicatedServer.java:226)
        at net.minecraft.server.v1_6_R2.MinecraftServer.s(MinecraftServer.java:486)
        at net.minecraft.server.v1_6_R2.MinecraftServer.run(MinecraftServer.java:419)
        at net.minecraft.server.v1_6_R2.ThreadServerApplication.run(SourceFile:582)
    Caused by: org.bukkit.plugin.IllegalPluginAccessException: Plugin attempted to register task while disabled
        at org.bukkit.craftbukkit.v1_6_R2.scheduler.CraftScheduler.validate(CraftScheduler.java:394)
        at org.bukkit.craftbukkit.v1_6_R2.scheduler.CraftScheduler.runTaskTimer(CraftScheduler.java:120)
        at org.bukkit.craftbukkit.v1_6_R2.scheduler.CraftScheduler.runTaskLater(CraftScheduler.java:104)
        at mrjoe.ked.Game.start(Game.java:21)
        at mrjoe.ked.PlayerCommandsExecutor.onCommand(PlayerCommandsExecutor.java:45)
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44)
        ... 15 more
     
  5. Offline

    KedalionPlugins

    Just so you know we call Game.start() in the command executor, that's why thees the first exception.
     
  6. Offline

    Quantix

    I'd do what Axe2760 did (not sure if you've added it already, but it's not in the link to the pastebin code you provided). In the Game class add a constructor like this:
    Code:java
    1. public Sumo plugin;
    2.  
    3. public Game(Sumo instance) {
    4. plugin = instance;
    5. }

    If you make an instance or object of the Game class use:
    Code:java
    1. Game game = new Game(this);

    Although, since all the methods in your Game class are static and I'm guessing you will never make an instance of the Game class, the method above would never be called because it is a constructor called only when an object of that class is created. So, you'd need to "initialize" the Game class in the Sumo main class (preferably in the onEnable() method) so that that static plugin variable in the Game class is created. Something along the lines of:
    Code:java
    1. public static Sumo plugin;
    2.  
    3. public static void Initialize(Sumo instance) {
    4. plugin = instance;
    5. }

    Replace your new static instance of the Sumo class (line 11) inside your Game class and instead reference your main plugin class using one of the two methods above. I don't think instantiating your main plugin class from any other class is a good thing to do in general. One last thing, you could code the countdown in your game class in a much simpler way in my opinion:
    Code:java
    1. public int secondsTillStart = 30;
    2.  
    3. Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {
    4. public void run() {
    5. if (secondsTillStart == 30) {
    6. //Broadcast a message to the players
    7. } else if (secondsTillStart == 20) {
    8. //Broadcast a different message to the players
    9. } else if (secondsTillStart == 10) {
    10. //Broadcast another message to the players and so forth
    11. }
    12. secondsTillStart--
    13. }
    14. }, 0L, 20L);
     
    Axe2760 likes this.
Thread Status:
Not open for further replies.

Share This Page