Multiple Commands w/ Multiple Arguments Help

Discussion in 'Plugin Development' started by yewtree8, Apr 13, 2014.

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

    yewtree8

    Hey so i'm developing a plugin and i can't get commands to work, i can get the /effectsigns to work but any other arguments and it just gives me the same message /effectsigns would.

    Code:java
    1. package me.mat.effectsigns;
    2.  
    3. import org.bukkit.ChatColor;
    4. import org.bukkit.command.Command;
    5. import org.bukkit.command.CommandSender;
    6. import org.bukkit.entity.Player;
    7. import org.bukkit.plugin.PluginManager;
    8. import org.bukkit.plugin.java.JavaPlugin;
    9. import org.fusesource.jansi.Ansi.Color;
    10.  
    11. public class Main extends JavaPlugin {
    12.  
    13.  
    14. String Prefix = ChatColor.GREEN + "[" + ChatColor.AQUA + "EffectSigns" + ChatColor.GREEN + "]";
    15.  
    16.  
    17. public void onEnable() {
    18.  
    19. System.out.println("EffectSigns Enabled");
    20.  
    21. PluginManager pm = getServer().getPluginManager();
    22.  
    23. pm.registerEvents(new PlayerListener(), this);
    24. pm.registerEvents(new SignListener(), this);
    25. pm.registerEvents(new BasicEvents(), this);
    26.  
    27.  
    28. }
    29.  
    30.  
    31. public void onDisable() {
    32.  
    33. System.out.println("EffectSigns Disabled");
    34.  
    35. }
    36.  
    37.  
    38. public boolean onCommand(CommandSender sender, Command command, String name, String[] args) {
    39. Player player = (Player) sender; {
    40. if(command.getName().equalsIgnoreCase("effectsigns")) {
    41.  
    42. player.sendMessage(Prefix + ChatColor.DARK_AQUA + " [" + ChatColor.AQUA + "V 0.1" + ChatColor.DARK_AQUA + "]"
    43. + ChatColor.GREEN +
    44. " This Plugin Was Created by Mat" + ChatColor.DARK_AQUA + " / " + ChatColor.YELLOW + "yewtree8");
    45.  
    46.  
    47. return true;
    48. }
    49.  
    50. if(command.getName().equalsIgnoreCase("effectsigns")) {
    51. if(args.length == 1) {
    52. if(args[0].equalsIgnoreCase("help")) {
    53. player.sendMessage(Prefix + ChatColor.GREEN + " Commands:" );
    54. player.sendMessage(Prefix + ChatColor.GOLD + " /EffectSigns "
    55. + ChatColor.LIGHT_PURPLE + "Gives Plugin Info & Version");
    56. player.sendMessage(Prefix + ChatColor.GOLD + "/EffectSigns help" + ChatColor.LIGHT_PURPLE + " Shows This Menu");
    57. player.sendMessage(Prefix + ChatColor.GOLD + " /EffectSigns Speed " + ChatColor.LIGHT_PURPLE + "Shows How To Make A Speed Sign" );
    58. player.sendMessage(Prefix + ChatColor.GOLD + " /EffectSigns Strength " + ChatColor.LIGHT_PURPLE + "Shows How To Make A Strength Sign" );
    59. }
    60. } else {
    61. player.sendMessage(ChatColor.RED + "That Command Isn't regognized, do " + ChatColor.GREEN +
    62. "/effectsigns help" + ChatColor.RED + " For More Help");
    63. }
    64.  
    65.  
    66.  
    67.  
    68.  
    69. return true;
    70. }
    71. if(command.getName().equalsIgnoreCase("effectsigns")) {
    72. if(args.length == 1) {
    73. if(args[0].equalsIgnoreCase("speed")) {
    74. if(player.hasPermission("effectsigns.command.speed")) {
    75. player.sendMessage(Prefix + ChatColor.DARK_RED + "-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|");
    76. player.sendMessage(Prefix + ChatColor.DARK_AQUA + " Creating A Speed Sign");
    77. player.sendMessage(Prefix + ChatColor.DARK_RED + "-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|");
    78. player.sendMessage(Prefix + ChatColor.GOLD + " [ES]");
    79. player.sendMessage(Prefix + ChatColor.GOLD + "Speed");
    80. player.sendMessage(Prefix + ChatColor.DARK_RED + "-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|");
    81. player.sendMessage(Prefix + ChatColor.RED + "You Must Have The Permission " + ChatColor.GREEN + "effectsigns.admin.speed");
    82. } else {
    83. player.sendMessage(Prefix + ChatColor.RED +
    84. " You Do Not Have The Permission" + ChatColor.GREEN + "effectsigns.command.speed");
    85. }
    86. }
    87. }
    88.  
    89.  
    90.  
    91.  
    92. }
    93.  
    94.  
    95.  
    96. if(command.getName().equalsIgnoreCase("effectsigns")) {
    97. if(args.length == 2) {
    98. if(args[0].equalsIgnoreCase("strength")) {
    99. if(player.hasPermission("effectsigns.command.strength")) {
    100. player.sendMessage(Prefix + ChatColor.DARK_RED + "-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|");
    101. player.sendMessage(Prefix + ChatColor.DARK_AQUA + " Creating A Speed Sign");
    102. player.sendMessage(Prefix + ChatColor.DARK_RED + "-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|");
    103. player.sendMessage(Prefix + ChatColor.GOLD + " [ES]");
    104. player.sendMessage(Prefix + ChatColor.GOLD + "Strength");
    105. player.sendMessage(Prefix + ChatColor.DARK_RED + "-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|");
    106. player.sendMessage(Prefix + ChatColor.RED + "You Must Have The Permission " + ChatColor.GREEN + "effectsigns.admin.strength");
    107.  
    108. } else {
    109. player.sendMessage(Prefix + ChatColor.RED + " You Do Not Have The Permission " + ChatColor.GREEN + "effectisigns.command.strength");
    110. }
    111. }
    112. }
    113. }
    114.  
    115.  
    116.  
    117. return true;
    118.  
    119. }
    120.  
    121. }
    122.  
    123. }





    So yeah, if anyone could help me where i went wrong that would be great?
     
  2. Offline

    TigerHix

    Obviously. Here is the fixed code, explanation is left to others. :p

    Code:java
    1.  
    2. public boolean onCommand(CommandSender sender, Command command, String name, String[] args) {
    3. Player player = (Player) sender; {
    4. if (command.getName().equalsIgnoreCase("effectsigns")) {
    5. if (args.length == 0) {
    6. player.sendMessage(Prefix + ChatColor.DARK_AQUA + " [" + ChatColor.AQUA + "V 0.1" + ChatColor.DARK_AQUA + "]" + ChatColor.GREEN +
    7. " This Plugin Was Created by Mat" + ChatColor.DARK_AQUA + " / " + ChatColor.YELLOW + "yewtree8");
    8. return true;
    9. } else if (args.length == 1) {
    10. if (args[0].equalsIgnoreCase("help")) {
    11. player.sendMessage(Prefix + ChatColor.GREEN + " Commands:");
    12. player.sendMessage(Prefix + ChatColor.GOLD + " /EffectSigns " + ChatColor.LIGHT_PURPLE + "Gives Plugin Info & Version");
    13. player.sendMessage(Prefix + ChatColor.GOLD + "/EffectSigns help" + ChatColor.LIGHT_PURPLE + " Shows This Menu");
    14. player.sendMessage(Prefix + ChatColor.GOLD + " /EffectSigns Speed " + ChatColor.LIGHT_PURPLE + "Shows How To Make A Speed Sign");
    15. player.sendMessage(Prefix + ChatColor.GOLD + " /EffectSigns Strength " + ChatColor.LIGHT_PURPLE + "Shows How To Make A Strength Sign");
    16. } else if (args[0].equalsIgnoreCase("speed")) {
    17. if (player.hasPermission("effectsigns.command.speed")) {
    18. player.sendMessage(Prefix + ChatColor.DARK_RED + "-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|");
    19. player.sendMessage(Prefix + ChatColor.DARK_AQUA + " Creating A Speed Sign");
    20. player.sendMessage(Prefix + ChatColor.DARK_RED + "-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|");
    21. player.sendMessage(Prefix + ChatColor.GOLD + " [ES]");
    22. player.sendMessage(Prefix + ChatColor.GOLD + "Speed");
    23. player.sendMessage(Prefix + ChatColor.DARK_RED + "-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|");
    24. player.sendMessage(Prefix + ChatColor.RED + "You Must Have The Permission " + ChatColor.GREEN + "effectsigns.admin.speed");
    25. } else {
    26. player.sendMessage(Prefix + ChatColor.RED +
    27. " You Do Not Have The Permission" + ChatColor.GREEN + "effectsigns.command.speed");
    28. }
    29. }
    30. return true;
    31. } else if (args.length == 2) {
    32. if (args[0].equalsIgnoreCase("strength")) {
    33. if (player.hasPermission("effectsigns.command.strength")) {
    34. player.sendMessage(Prefix + ChatColor.DARK_RED + "-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|");
    35. player.sendMessage(Prefix + ChatColor.DARK_AQUA + " Creating A Speed Sign");
    36. player.sendMessage(Prefix + ChatColor.DARK_RED + "-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|");
    37. player.sendMessage(Prefix + ChatColor.GOLD + " [ES]");
    38. player.sendMessage(Prefix + ChatColor.GOLD + "Strength");
    39. player.sendMessage(Prefix + ChatColor.DARK_RED + "-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|");
    40. player.sendMessage(Prefix + ChatColor.RED + "You Must Have The Permission " + ChatColor.GREEN + "effectsigns.admin.strength");
    41. } else {
    42. player.sendMessage(Prefix + ChatColor.RED + " You Do Not Have The Permission " + ChatColor.GREEN + "effectisigns.command.strength");
    43. }
    44. }
    45. }
    46. return true;
    47. }
    48. }
    49. }
    50. [syntax][/syntax]
     
    yewtree8 likes this.
  3. Offline

    Gater12

    yewtree8
    Do the argument check in the first effectsigns block OR check if the args is 0 in the first effectsigns block before executing the code for /effectsigns (Because laziness)
     
Thread Status:
Not open for further replies.

Share This Page