Error with Delayed Task

Discussion in 'Plugin Development' started by AXCoding, Jul 23, 2014.

?

How idiotic was my mistake?

  1. It was ok, hard to catch.

    0 vote(s)
    0.0%
  2. It was super obvious... Your an idiot.

    0 vote(s)
    0.0%
Thread Status:
Not open for further replies.
  1. Offline

    AXCoding

    Hi, I'm trying to make a delayed task so that it will send the player a message, wait 90 ticks, then send a different message(defined in the config). The problem is, the plugin sends all the messages defined in the config, then waits. I don't understand how it does this.
    MainClass:
    Code:java
    1. package me.JasonBourne685.KTutorial;
    2.  
    3. import java.util.logging.Logger;
    4.  
    5.  
    6.  
    7.  
    8.  
    9.  
    10. import org.bukkit.Bukkit;
    11. import org.bukkit.ChatColor;
    12. import org.bukkit.command.Command;
    13. import org.bukkit.command.CommandSender;
    14. import org.bukkit.entity.Player;
    15. import org.bukkit.plugin.PluginDescriptionFile;
    16. import org.bukkit.plugin.java.JavaPlugin;
    17.  
    18. public class main extends JavaPlugin{
    19.  
    20. public final static Logger logger = Logger.getLogger("Minecraft");
    21. public static main plugin;
    22. @Override
    23. public void onDisable() {
    24. PluginDescriptionFile pdfFile = this.getDescription();
    25. this.logger.info(pdfFile.getName() + " has been DISABLED!");
    26. plugin = null;
    27. }
    28.  
    29. @Override
    30. public void onEnable() {
    31. PluginDescriptionFile pdfFile = this.getDescription();
    32. plugin = this;
    33. getConfig().options().copyDefaults(true);
    34. saveConfig();
    35. this.logger.info(pdfFile.getName() + " Version " + pdfFile.getVersion() + " has been ENABLED!");
    36. }
    37. // ------------- Done with init Loading -----------------
    38. public boolean takingTutorial = false;
    39. //Loaded Booleans for listeners
    40. private int factiondelay = 90;
    41. private int factioncounter = 1;
    42. public String pluginPrefix = ChatColor.LIGHT_PURPLE + "" + ChatColor.BOLD + "[Tutorial] ";
    43. //Created the prefix :D
    44. public boolean onCommand(CommandSender sender,Command cmd,String commandLabel,String[] args){
    45. if(sender instanceof Player){
    46. if(commandLabel.equalsIgnoreCase("tutorial")){
    47. final Player player = (Player) sender;
    48. if((args.length >= 2)||(args.length == 0)){
    49. player.sendMessage(pluginPrefix + "Usage: /tutorial faction or /tutorial commands");
    50. }
    51. if(args.length == 1){
    52. if(args[0].equalsIgnoreCase("faction")){
    53. player.sendMessage(pluginPrefix + "Welcome to the " + ChatColor.GOLD + "Factions Tutorial " + ChatColor.LIGHT_PURPLE + "" + ChatColor.BOLD + player.getDisplayName());
    54. for (String factiontutorial : getConfig().getStringList("FactionTutorial")){
    55. factiondelay = factiondelay * factioncounter;
    56. factioncounter = factioncounter + 1;
    57. main.logger.info("Entered For Loop");
    58. main.logger.info(factiontutorial);
    59. this.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
    60. public void run() {
    61. main.logger.info("Entered Delay Loop!");
    62. }
    63.  
    64. }, factiondelay);
    65. player.sendMessage(pluginPrefix + ChatColor.GOLD + "" + ChatColor.BOLD + factiontutorial);
    66. }
    67. } else if(args[0].equalsIgnoreCase("commands")){
    68. player.sendMessage(pluginPrefix + "Welcome to the " + ChatColor.GREEN + "Commands Tutorial " + ChatColor.LIGHT_PURPLE + "" + ChatColor.BOLD + player.getDisplayName());
    69. } else {
    70. player.sendMessage(pluginPrefix + "Usage: /tutorial faction or /tutorial commands");
    71. }
    72. }
    73. }
    74. }
    75. return true;
    76. }
    77. }
    78.  


    Logs:
    Code:
    [12:24:44] [Server thread/INFO]: JasonBourne685 issued server command: /tutorial faction
    [12:24:44] [Server thread/INFO]: Entered For Loop
    [12:24:44] [Server thread/INFO]: c&lJasonBourne685
    [12:24:44] [Server thread/INFO]: Entered For Loop
    [12:24:44] [Server thread/INFO]: 6&lxoblitz
    [12:24:44] [Server thread/INFO]: Entered For Loop
    [12:24:44] [Server thread/INFO]: Notch
    [12:24:44] [Server thread/INFO]: Entered For Loop
    [12:24:44] [Server thread/INFO]: Jeb
    [12:24:48] [Server thread/INFO]: Entered Delay Loop!
    [12:24:53] [Server thread/INFO]: Entered Delay Loop!
    [12:24:56] [Server thread/WARN]: [WorldEdit] No compatible nms block class found.
    [12:25:11] [Server thread/INFO]: Entered Delay Loop!
    [12:26:32] [Server thread/INFO]: Entered Delay Loop!
     
  2. Offline

    ZodiacTheories

    AXCoding

    From what I see, you are looping through the string list, not getting a single string
     
  3. Offline

    AXCoding

  4. Offline

    ZodiacTheories

    AXCoding

    Only pick one string, not the whole string list
     
  5. Offline

    AXCoding

    ZodiacTheories... So what would the for loop be? Sorry if im a noob. :(
     
  6. Offline

    ZodiacTheories

    AXCoding

    Are you sending them a random message, or a specified message?
     
  7. Offline

    The_Coder

    You didn't check if the list exists
     
  8. Offline

    AXCoding

    Specified Message, its a tutorial plugin so in the config it looks like:
    FactionMessage:
    -Line1
    -Line2
    -Line3

    ZodiacTheories

    The_Coder I will do that but for now lets assume the list exists.

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

    The_Coder

    AXCoding
    You send the message in the "Delay Loop"
     
  10. Offline

    AXCoding

    The_Coder but then I have to make the message a final but the message changes :(

    Any help, this is pretty urgent :(

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
Thread Status:
Not open for further replies.

Share This Page