Solved runTaskLater Not working

Discussion in 'Plugin Development' started by theisevan, Jul 12, 2013.

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

    theisevan

    I'm making a cool down here's what I got:
    [​IMG]
    How do I use this!? Even the runTaskLater will not work!
     
  2. Offline

    foodyling

    Code:
    Bukkit.getScheduler().runTaskLater(this, new Runnable() {
      @Override
      public void run() {
        // code
      }
    }, time);
    You sure this doesn't work? use Bukkit.getScheduler(), not Bukkit.getServer().getScheduler()
     
  3. Offline

    Sagacious_Zed Bukkit Docs

    which getScheduler you use doesn't matter.

    theisevan
    Your capture shows us that eclipse found an error. Did you read the error message?
     
  4. Offline

    theisevan

    @Sagacious_Zed
    Still didn't work for ne, I got The method runTaskLater(Plugin, Runnable, long) in the type BukkitScheduler is not applicable for the arguments (EventReq, new Runnable(){}, int, int)
     
  5. Offline

    foodyling

  6. Offline

    theisevan

  7. Offline

    foodyling

    Post your code after modifying
     
  8. Offline

    theisevan


    Code:java
    1. if(!coolDown.contains(p)) {
    2. if(p.hasPermission("DPP.eventrec")){
    3. coolDown.add(p);
    4. p.sendMessage(ChatColor.GREEN + sender.getName() + " wants you to do an event!");
    5. Bukkit.getScheduler().runTaskLater(this, new Runnable() {
    6.  
    7. @Override
    8. public void run() {
    9. coolDown.remove(p);
    10.  
    11. }
    12.  
    13. }, 36000);


    am I doing it wrong?
     
  9. Offline

    foodyling

    Any specific error at this point?
     
  10. Offline

    theisevan

    same that is has been
    The method runTaskLater(Plugin, Runnable, long) in the type BukkitScheduler is not applicable for the arguments (EventReq, new Runnable(){}, int)
     
  11. Offline

    foodyling

    Change 36000 to 36000L, also is the class you're running this from your default class (that extends JavaPlugin)? The first argument is the instance of your main class
     
  12. Offline

    theisevan

    Adding the L did no difference and I don't know what you mean, this is a CommandExecutor class.
     
  13. Offline

    foodyling

    There's your problem then, if you're using "this" as the first argument and the class is a CommandExecuter and not a Plugin, it's not going to work. You have to use an instance of your plugin as the first argument.
     
  14. Offline

    theisevan

    So ,instanceof Main? Sorry i'm not understanding this.
     
  15. Offline

    foodyling

    Code:
    public class Main extends JavaPlugin {
      private static Plugin plugin; // <-- Where you store an instance of your main class
      @Override
      public void onEnable() {
        plugin = this;
      }
     
      public static Plugin getPlugin() {
        return plugin;
      }
    }
    Code:
    Bukkit.getScheduler().runTaskLater(Main.getPlugin(), new Runnable() {
      @Override
      public void run() {
     
      }
    }, 20L);
    Of course you'd have to change this to adapt to your plugin.
     
  16. Offline

    theisevan

    THANKS SO MUCH! NOW IT'S WORKING!
     
  17. Offline

    foodyling

    theisevan Mark the thread as solved then :p
     
  18. Offline

    theisevan

    foodyling sorry lol always forget

    foodyling actually, could you help me with a problem i'm having with config.getString("string")
    I'll paste the code.
    Code:java
    1. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    2. if(cmd.getName().equalsIgnoreCase("events")) {
    3. sender.sendMessage(ChatColor.AQUA + config.getString("events"));
    4. }

    It doesn't say any errors but if I do /events it returns this in the console.
    Code:
    20:13:38 [WARNING] Unexpected exception while parsing console command "events"
    org.bukkit.command.CommandException: Unhandled exception executing command 'even
    ts' in plugin DPP v1.0
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46)
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:18
    9)
            at org.bukkit.craftbukkit.v1_6_R2.CraftServer.dispatchCommand(CraftServe
    r.java:523)
            at org.bukkit.craftbukkit.v1_6_R2.CraftServer.dispatchServerCommand(Craf
    tServer.java:512)
            at net.minecraft.server.v1_6_R2.DedicatedServer.ar(DedicatedServer.java:
    262)
            at net.minecraft.server.v1_6_R2.DedicatedServer.t(DedicatedServer.java:2
    27)
            at net.minecraft.server.v1_6_R2.MinecraftServer.s(MinecraftServer.java:4
    86)
            at net.minecraft.server.v1_6_R2.MinecraftServer.run(MinecraftServer.java
    :419)
            at net.minecraft.server.v1_6_R2.ThreadServerApplication.run(SourceFile:5
    82)
    Caused by: java.lang.NullPointerException
            at com.EndlessWar.NightVision.EventsList.onCommand(EventsList.java:16)
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44)
            ... 8 more
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 3, 2016
  19. Offline

    foodyling

    theisevan Which line is the error occurring on? My current guess is that config is set to null.
     
  20. Offline

    theisevan

    It doesn't say there is an error. Nothing is wrong and everything says it all works! It's just doing that in the console?
     
  21. Offline

    foodyling

    Line 16 is throwing an error because of a NullPointerException, what is line 16?
     
  22. Offline

    theisevan

    foodyling sender.sendMessage(ChatColor.AQUA + config.getString("events"));
     
  23. Offline

    foodyling

    config is set to null, you need to have it set to something if you want to use it.
     
  24. Offline

    theisevan

    It has a message inside it if that's what you're saying?
     
  25. Offline

    foodyling

    Do you even know what 'null' means?
     
  26. Offline

    theisevan

    not really lol
     
  27. Offline

    foodyling

    Post your main class and your command executer class
     
  28. Offline

    theisevan

    foodyling
    Code:java
    1. package com.EndlessWar.NightVision;
    2.  
    3. import java.io.File;
    4.  
    5. import org.bukkit.Bukkit;
    6. import org.bukkit.ChatColor;
    7. import org.bukkit.configuration.file.FileConfiguration;
    8. import org.bukkit.plugin.Plugin;
    9. import org.bukkit.plugin.java.JavaPlugin;
    10.  
    11.  
    12.  
    13. public class Main extends JavaPlugin{
    14. private static Plugin plugin;
    15. FileConfiguration config;
    16. File cfile;
    17.  
    18.  
    19. @Override
    20. public void onEnable() {
    21. plugin = this;
    22. config = getConfig();
    23. config.options().copyDefaults(true);
    24. saveConfig();
    25. cfile = new File(getDataFolder(), "config.yml");
    26. //Enables all of the commands
    27. getCommand("NightVision").setExecutor(new Nightvision());
    28. getCommand("AllPotions").setExecutor(new AllPotions());
    29. getCommand("RemovePotions").setExecutor(new AllPotions());
    30. getCommand("Event").setExecutor(new Events());
    31. getCommand("events").setExecutor(new EventsList());
    32. getCommand("DayVision").setExecutor(new Nightvision());
    33. getCommand("RemovePotions").setExecutor(new AllPotions());
    34. getCommand("EventReq").setExecutor(new EventReq());
    35. //this is a sceduler that will broadcast "Want and event? Speak up and ask!" every 20 minutes.
    36. Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
    37. public void run() {
    38. Bukkit.getServer().broadcastMessage(ChatColor.RED + "Want an event? Do /eventreq!!");
    39. }
    40. }, 1200, 24000);
    41. }
    42. public static Plugin getPlugin() {
    43. return plugin;
    44. }
    45. //adding this in soon!
    46. //message printed to the console onDisable or as you'll know when the server shuts down.
    47. public void onDisable() {
    48. getLogger().info("Disabled DPP");
    49.  
    50. }
    51. }
    52.  


    Code:java
    1. package com.EndlessWar.NightVision;
    2.  
    3. import java.io.File;
    4.  
    5. import org.bukkit.ChatColor;
    6. import org.bukkit.command.Command;
    7. import org.bukkit.command.CommandExecutor;
    8. import org.bukkit.command.CommandSender;
    9. import org.bukkit.configuration.file.FileConfiguration;
    10.  
    11. public class EventsList implements CommandExecutor{
    12. FileConfiguration config;
    13. File cfile;
    14. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    15. if(cmd.getName().equalsIgnoreCase("events")) {
    16. sender.sendMessage(ChatColor.AQUA + config.getString("events"));
    17. }
    18. return true;
    19.  
    20. }
    21. }
    22.  


    do you have skype

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

    foodyling

    Yes, same name as my username
     
Thread Status:
Not open for further replies.

Share This Page