Nothing happens when perform command :(

Discussion in 'Plugin Development' started by mickedplay, Mar 2, 2014.

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

    mickedplay

    I need help with my command in my plugin.
    If I perform the command "/rush", nothing happens:

    Both are in the main class:
    Code:java
    1. File file = new File("plugins/Rush", "loc.yml");
    2. FileConfiguration cfg = YamlConfiguration.loadConfiguration(file);
    3.  


    Code:java
    1. @Override
    2. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
    3. {
    4. Player p = (Player)sender;
    5. if(sender == p)
    6. {
    7. if(p.isOp())
    8. {
    9. String world = p.getWorld().getName();
    10. double x = p.getLocation().getX();
    11. double y = p.getLocation().getY();
    12. double z = p.getLocation().getZ();
    13. double yaw = p.getLocation().getYaw();
    14. double pitch = p.getLocation().getPitch();
    15.  
    16. if(cmd.getName().equalsIgnoreCase("rush"))
    17. {
    18. if(args.length == 0)
    19. {
    20. p.sendMessage(Rush.cmdRush);
    21. p.sendMessage(Rush.cmdRushStart);
    22. p.sendMessage(Rush.cmdRushSetLobby);
    23. p.sendMessage(Rush.cmdRushSetRedSpawn);
    24. p.sendMessage(Rush.cmdRushSetBlueSpawn);
    25. p.sendMessage(Rush.cmdRushSetRespawn);
    26. }
    27. else
    28. {
    29. if(args.length == 1)
    30. {
    31. if(args[0].equalsIgnoreCase("start"))
    32. {
    33. if(Bukkit.getOnlinePlayers().length < 2)
    34. {
    35. p.sendMessage(Rush.pr + "§4Error. Not enough players to start the game.");
    36. }
    37. else
    38. {
    39. Bukkit.getScheduler().scheduleSyncRepeatingTask(Rush.getInstance(), new Runnable()
    40. {
    41. @Override
    42. public void run()
    43. {
    44. BarAPI.setMessage("Game starts in: " + "§c" + Rush.LobbyCounter + " seconds.");
    45. if(Rush.LobbyCounter == 0)
    46. {
    47. Bukkit.broadcastMessage(Rush.pr + "Everybody got a protection time of " + Rush.LobbyCounter + " seconds.");
    48. GameStatus.GAME.setStatus();
    49. }
    50.  
    51. }
    52. }, 0L, Rush.LobbyCounter);
    53. Check.game();
    54. p.sendMessage(Rush.cmdRushStartMessage);
    55. }
    56. }
    57. if(args[0].equalsIgnoreCase("setLobby"))
    58. {
    59. cfg.set("Lobby.world", world);
    60. cfg.set("Lobby.x", x);
    61. cfg.set("Lobby.y", y);
    62. cfg.set("Lobby.z", z);
    63. cfg.set("Lobby.yaw", yaw);
    64. cfg.set("Lobby.pitch", pitch);
    65. try
    66. {
    67. cfg.save(file);
    68. p.sendMessage(Rush.cmdRushSetLobbyMessage);
    69. }
    70. catch (IOException e)
    71. {
    72. e.printStackTrace();
    73. }
    74. return true;
    75. }
    76. if(args[0].equalsIgnoreCase("setRedSpawn"))
    77. {
    78. cfg.set("Red.world", world);
    79. cfg.set("Red.x", x);
    80. cfg.set("Red.y", y);
    81. cfg.set("Red.z", z);
    82. cfg.set("Red.yaw", yaw);
    83. cfg.set("Red.pitch", pitch);
    84. try
    85. {
    86. cfg.save(file);
    87. p.sendMessage(Rush.cmdRushSetRedSpawnMessage);
    88. }
    89. catch (IOException e)
    90. {
    91. e.printStackTrace();
    92. }
    93. return true;
    94. }
    95. if(args[0].equalsIgnoreCase("setBlueSpawn"))
    96. {
    97. cfg.set("Blue.world", world);
    98. cfg.set("Blue.x", x);
    99. cfg.set("Blue.y", y);
    100. cfg.set("Blue.z", z);
    101. cfg.set("Blue.yaw", yaw);
    102. cfg.set("Blue.pitch", pitch);
    103. try
    104. {
    105. cfg.save(file);
    106. p.sendMessage(Rush.cmdRushSetBlueSpawnMessage);
    107. }
    108. catch (IOException e)
    109. {
    110. e.printStackTrace();
    111. }
    112. return true;
    113. }
    114. if(args[0].equalsIgnoreCase("setRespawn"))
    115. {
    116. cfg.set("Respawn.world", world);
    117. cfg.set("Respawn.x", x);
    118. cfg.set("Respawn.y", y);
    119. cfg.set("Respawn.z", z);
    120. cfg.set("Respawn.yaw", yaw);
    121. cfg.set("Respawn.pitch", pitch);
    122. try
    123. {
    124. cfg.save(file);
    125. p.sendMessage(Rush.cmdRushSetRespawnMessage);
    126. }
    127. catch (IOException e)
    128. {
    129. e.printStackTrace();
    130. }
    131. return true;
    132. }
    133. if(args[0].equalsIgnoreCase("setRedItemSpawn"))
    134. {
    135. cfg.set("RedItemSpawn.world", world);
    136. cfg.set("RedItemSpawn.x", x);
    137. cfg.set("RedItemSpawn.y", y);
    138. cfg.set("RedItemSpawn.z", z);
    139. cfg.set("RedItemSpawn.yaw", yaw);
    140. cfg.set("RedItemSpawn.pitch", pitch);
    141. try
    142. {
    143. cfg.save(file);
    144. p.sendMessage(Rush.pr + "Set item spawn for red team.");
    145. }
    146. catch (IOException e)
    147. {
    148. e.printStackTrace();
    149. }
    150. return true;
    151. }
    152. if(args[0].equalsIgnoreCase("setBlueItemSpawn"))
    153. {
    154. cfg.set("BlueItemSpawn.world", world);
    155. cfg.set("BlueItemSpawn.x", x);
    156. cfg.set("BlueItemSpawn.y", y);
    157. cfg.set("BlueItemSpawn.z", z);
    158. cfg.set("BlueItemSpawn.yaw", yaw);
    159. cfg.set("RedItemSpawn.pitch", pitch);
    160. try
    161. {
    162. cfg.save(file);
    163. p.sendMessage(Rush.pr + "Set item spawn for blue team.");
    164. }
    165. catch (IOException e)
    166. {
    167. e.printStackTrace();
    168. }
    169. return true;
    170. }
    171. }
    172. }
    173. }
    174. }
    175. else if(!p.isOp())
    176. {
    177. p.sendMessage(Rush.cmdRushAccessDenied);
    178. }
    179. }
    180. else
    181. {
    182. System.out.println("Only players are allowed to perform this command.");
    183. }
    184. return false;
    185. }


    Can you find whats wrong? :(
     
  2. Offline

    Gater12

    mickedplay
    Why can't you just put getDataFolder() ?
     
    Jombi likes this.
  3. Offline

    Minesuchtiiii

    put the if(p.isOp) and the double values under if(cmd.getName().equalsIgnoreCase("rush")
    .. Can't find any error
     
  4. Offline

    Maurdekye

    mickedplay Just put print statements everywhere. All over, under and around your if statements, to see what's being run and what isn't. Print statements are the ultimate debugging tool.
     
  5. Offline

    Jombi

  6. Offline

    mickedplay

  7. Offline

    Minesuchtiiii

    return true; ?
     
  8. Offline

    Jombi

    Show us your onEnable() method in your main class.
     
  9. Offline

    mickedplay

    Jombi
    onEnable:
    Code:java
    1. @Override
    2. public void onEnable()
    3. {
    4. m = this;
    5. startUP();
    6. GameStatus.LOBBY.setStatus();
    7. Iterator<Recipe> it = getServer().recipeIterator();
    8. Recipe recipe;
    9. while(it.hasNext())
    10. {
    11. recipe = it.next();
    12. if(recipe!=null && recipe.getResult().getType() == Material.BRICK)
    13. {
    14. it.remove();
    15. }
    16. }
    17. }


    startup:
    Code:java
    1. public void startUP()
    2. {
    3. Check.game();
    4. Lobby.startGame();
    5.  
    6. Bukkit.getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
    7.  
    8.  
    9. Bukkit.getPluginManager().registerEvents(new PingEvent(), this);
    10. Bukkit.getPluginManager().registerEvents(new PlayerJoin(), this);
    11. Bukkit.getPluginManager().registerEvents(new BlockInteract(), this);
    12. Bukkit.getPluginManager().registerEvents(new PlayerEvent(), this);
    13. Bukkit.getPluginManager().registerEvents(new PlayerDeath(), this);
    14. Bukkit.getPluginManager().registerEvents(new PlayerQuit(), this);
    15.  
    16. // this.getCommand("rush").setExecutor(new Rush_Command());
    17.  
    18. getConfig().addDefault("Rush.Prefix", "§4[§cRush§4] §7");
    19. getConfig().addDefault("Rush.worldToReset", "Rush");
    20. getConfig().addDefault("Rush.LobbyCounter", "120");
    21. getConfig().addDefault("Rush.GameCounter", "900");
    22. getConfig().addDefault("Rush.EndCounter", "15");
    23. getConfig().addDefault("Rush.minPlayer", "2");
    24. getConfig().addDefault("Rush.maxPlayer", "8");
    25. getConfig().addDefault("Rush.respawnTime", "1");
    26.  
    27. getConfig().addDefault("Rush.motdLobby", "§cLobby");
    28. getConfig().addDefault("Rush.motdWarmup", "§cWarmup");
    29. getConfig().addDefault("Rush.motdIngame", "§cIngame");
    30. getConfig().addDefault("Rush.motdRestart", "§cRestart");
    31.  
    32. getConfig().addDefault("Rush.cmdRush", "§7Not enough arguments.");
    33. getConfig().addDefault("Rush.cmdRushStart", "§c/rush start | Starts the game.");
    34. getConfig().addDefault("Rush.cmdRushSetLobby", "§c/rush setLobby | Set the spawn for the lobby.");
    35. getConfig().addDefault("Rush.cmdRushSetRedSpawn", "§c/rush setRedSpawn | Set the spawn for the red team.");
    36. getConfig().addDefault("Rush.cmdRushSetBlueSpawn", "§c/rush setBlueSpawn | Set the spawn for the blue team.");
    37. getConfig().addDefault("Rush.cmdRushSetRespawn", "§c/rush setRespawn | Set your respawn location.");
    38. getConfig().addDefault("Rush.cmdRushStartMessage", Rush.pr + "Game started.");
    39. getConfig().addDefault("Rush.cmdRushSetLobbyMessage", Rush.pr + "Spawn successful set.");
    40. getConfig().addDefault("Rush.cmdRushSetRedSpawnMessage", Rush.pr + "Red spawn set.");
    41. getConfig().addDefault("Rush.cmdRushSetBlueSpawnMessage", Rush.pr + "Blue spawn set.");
    42. getConfig().addDefault("Rush.cmdRushSetRespawnMessage", Rush.pr + "Respawn set.");
    43. getConfig().addDefault("Rush.cmdRushIllegalArgument", Rush.pr + "Illegal argument.");
    44. getConfig().addDefault("Rush.cmdRushAccessDenied", Rush.pr + "Access denied.");
    45.  
    46. getConfig().addDefault("Rush.mapDoesNotExist", "[RUSH] The chosen map does not exist. Sorry.");
    47.  
    48. getConfig().options().copyDefaults(true);
    49. saveConfig();
    50.  
    51. minPlayer = getConfig().getInt("Rush.minPlayer");
    52. maxPlayer = getConfig().getInt("Rush.maxPlayer");
    53.  
    54. respawnTime = getConfig().getInt("Rush.respawnTime");
    55.  
    56. LobbyCounter = getConfig().getInt("Rush.LobbyCounter");
    57. GameCounter = getConfig().getInt("Rush.GameCounter");
    58. EndCounter = getConfig().getInt("Rush.EndCounter");
    59.  
    60. motdLobby = getConfig().getString("Rush.motdLobby");
    61. motdWarmup = getConfig().getString("Rush.motdWarmup");
    62. motdIngame = getConfig().getString("Rush.motdIngame");
    63. motdRestart = getConfig().getString("Rush.motdRestart");
    64.  
    65. cmdRush = getConfig().getString("Rush.cmdRush");
    66. cmdRushStart = getConfig().getString("Rush.cmdRushStart");
    67. cmdRushSetLobby = getConfig().getString("Rush.cmdRushSetLobby");
    68. cmdRushSetRedSpawn = getConfig().getString("Rush.cmdRushSetRedSpawn");
    69. cmdRushSetBlueSpawn = getConfig().getString("Rush.cmdRushSetBlueSpawn");
    70. cmdRushSetRespawn = getConfig().getString("Rush.cmdRushSetRespawn");
    71. cmdRushStartMessage = getConfig().getString("Rush.cmdRushStartMessage");
    72. cmdRushSetLobbyMessage = getConfig().getString("Rush.cmdRushSetLobbyMessage");
    73. cmdRushSetRedSpawnMessage = getConfig().getString("Rush.cmdRushSetRedSpawnMessage");
    74. cmdRushSetBlueSpawnMessage = getConfig().getString("Rush.cmdRushSetBlueSpawnMessage");
    75. cmdRushSetRespawnMessage = getConfig().getString("Rush.cmdRushSetRespawnMessage");
    76. cmdRushIllegalArgument = getConfig().getString("Rush.cmdRushIllegalArgument");
    77. cmdRushAccessDenied = getConfig().getString("Rush.cmdRushAccessDenied");
    78.  
    79. mapDoesNotExist = getConfig().getString("Rush.mapDoesNotExist");
    80.  
    81. pr = ChatColor.translateAlternateColorCodes('&', getConfig().getString("Rush.Prefix"));
    82.  
    83. if(Bukkit.getWorld(getConfig().getString("Rush.worldToReset")) !=null)
    84. {
    85. worldtoreset = Bukkit.getWorld(getConfig().getString("Rush.WorldToReset"));
    86. worldtoreset.setAutoSave(false);
    87. }
    88. else
    89. {
    90. System.out.println(Rush.mapDoesNotExist);
    91. }
    92. }
     
  10. Offline

    Jombi

    mickedplay
    Where are you registering your command...?
     
  11. Offline

    mickedplay

    Jombi Only in plugin.yml
     
  12. Offline

    unon1100

    Couple minor adjustments

    Code:java
    1. Player p = (Player)sender;
    2. if(sender == p)
    3. {

    change to
    Code:java
    1. if(sender instanceof Player)
    2. {
    3. Player p = (Player) sender;



    Also, add some debug code. Each time you get a step further in the command, send the player a message. That way, you know what's happening and what isn't.
     
Thread Status:
Not open for further replies.

Share This Page