Got some errors on my RestartTimer class

Discussion in 'Plugin Development' started by PerezHD, Nov 30, 2014.

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

    PerezHD

    Here is my code right now,

    Code:java
    1. public class RestartTimer implements CommandExecutor {
    2.  
    3. Main main;
    4. public class RestartTimer (Main pl) {
    5. this.main = pl; {
    6.  
    7. }
    8. }
    9. public int number = 30;
    10.  
    11. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    12. Player p = (Player) sender;
    13. if (cmd.getName().equalsIgnoreCase("frestart")) {
    14. if (!p.hasPermission("flexrestart.restart")) {
    15. p.sendMessage(ChatColor.RED + "You do not have permission");
    16. }
    17. else {
    18. Main.plugin.getServer().getScheduler()
    19. .scheduleSyncRepeatingTask(Main.plugin, new Runnable() {
    20.  
    21. public void run(){
    22. number--;
    23. if (number != -1) {
    24. if (number != 0){
    25. switch (number) {
    26. case 30:
    27. case 15:
    28. case 10:
    29. case 5:
    30. case 4:
    31. case 3:
    32. case 2:
    33. case 1:
    34. Bukkit.broadcastMessage(Main.plugin.prefix + "§eServer restarting in " + number);
    35. number--;
    36. } else {
    37. Main.plugin.broadcastMessage(Main.plugin.prefix + "§eServer restarting NOW!");
    38. Main.plugin.getServer().dispatchCommand(Main.plugin.getConsoleSender(), "restart");
    39. number--;
    40. }
    41. }
    42. }
    43. }
    44. , 0L, 20L);
    45. }
    46. }
    47. return false;
    48. }


    I got errors on } else {

    and also above near instance
     
  2. Offline

    bwfcwalshy Retired Staff

    PerezHD Replace, Main.plugin.getServer() with main.getServer().

    Also why are all your cases empty?
     
  3. Offline

    PerezHD

    Code:java
    1. public class RestartTimer implements CommandExecutor {
    2.  
    3. Main main;
    4. public class RestartTimer (Main pl) {
    5. this.main = pl; {
    6.  
    7. }
    8. }
    9.  
    10. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    11. Player p = (Player) sender;
    12. if (cmd.getName().equalsIgnoreCase("frestart")) {
    13. if (!p.hasPermission("flexrestart.restart")) {
    14. p.sendMessage(ChatColor.RED + "You do not have permission");
    15. }
    16. else {
    17. Main.plugin.getServer().getScheduler()
    18. .scheduleSyncRepeatingTask(Main, new Runnable() {
    19.  
    20. public void run(){
    21. Main.number--;
    22. if (number != -1) {
    23. if (number != 0){
    24. switch (number) {
    25. case 30:
    26. Bukkit.broadcastMessage(Main.plugin.prefix + "§eServer restarting in " + number);
    27. break;
    28. case 15:
    29. Bukkit.broadcastMessage(Main.plugin.prefix + "§eServer restarting in " + number);
    30. break;
    31. case 10:
    32. Bukkit.broadcastMessage(Main.plugin.prefix + "§eServer restarting in " + number);
    33. break;
    34. case 5:
    35. Bukkit.broadcastMessage(Main.plugin.prefix + "§eServer restarting in " + number);
    36. break;
    37. case 4:
    38. Bukkit.broadcastMessage(Main.plugin.prefix + "§eServer restarting in " + number);
    39. break;
    40. case 3:
    41. Bukkit.broadcastMessage(Main.plugin.prefix + "§eServer restarting in " + number);
    42. break;
    43. case 2:
    44. Bukkit.broadcastMessage(Main.plugin.prefix + "§eServer restarting in " + number);
    45. break;
    46. case 1:
    47. Bukkit.broadcastMessage(Main.plugin.prefix + "§eServer restarting in " + number);
    48. break;
    49. } else {
    50. Bukkit.broadcastMessage(Main.plugin.prefix + "§eServer restarting NOW!");
    51. Main.getServer().dispatchCommand(Main.plugin.getConsoleSender(), "restart");
    52. number--;
    53. }
    54. }
    55. }
    56. }
    57. , 0L, 20L);
    58. }
    59. }
    60. return false;
    61. }



    Image of whats happening uptop:
    http://gyazo.com/f5dd172e8e5878fc04bc560b951b4c4e

    bwfcwalshy

    <Edited by bwfcwalshy: Merged posts, please use the edit button rather than double posting.>
     
  4. Offline

    bwfcwalshy Retired Staff

    PerezHD Because you did, public class RestartTimer. It is a constructor, do public ResetTimer.

    For a tutorial on Switch statement look HERE.
     
  5. Offline

    PerezHD

  6. Offline

    bwfcwalshy Retired Staff

    PerezHD Do you have an extra } somewhere. Make sure your else statement matches with what you want.
     
Thread Status:
Not open for further replies.

Share This Page