Command Issues

Discussion in 'Plugin Development' started by nirajm34, Dec 1, 2013.

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

    nirajm34

    Hey guys , the last } is red underlined and i don't see why, can anyone help ?

    Code:java
    1. package com.saicogaming;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.ChatColor;
    5. import org.bukkit.Material;
    6. import org.bukkit.command.Command;
    7. import org.bukkit.command.CommandExecutor;
    8. import org.bukkit.command.CommandSender;
    9. import org.bukkit.enchantments.Enchantment;
    10. import org.bukkit.entity.Player;
    11. import org.bukkit.inventory.ItemStack;
    12.  
    13. public class StartCommandExecutor implements CommandExecutor {
    14.  
    15. @Override
    16. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    17. if (cmd.getName().equalsIgnoreCase("enchant")) {
    18. // Make sure that the player specified exactly one argument (the name of the player to give enchanted item too).
    19. if (args.length != 1) {
    20. // When onCommand() returns false, the help message associated with that command is displayed.
    21. return false;
    22. }
    23.  
    24. // Make sure the send is a player.
    25. if (!(sender instanceof Player)) {
    26. sender.sendMessage("Only players another player an item");
    27. sender.sendMessage("This is an arbitrary requirement for demonstration purposes only.");
    28. return true;
    29. }
    30.  
    31. // Get the player who should be set on fire. Remember that indecies start with 0, not 1.
    32. Player target = Bukkit.getServer().getPlayer(args[0]);
    33. // Make sure the player is online.
    34. if (target == null) {
    35. sender.sendMessage(args[0] + " is not currently online.");
    36. return true;
    37. }
    38. ItemStack item = new ItemStack(Material.DIAMOND_SWORD);
    39. item.addEnchantment( Enchantment.DAMAGE_ALL , 100);
    40. target.getInventory().addItem(item);
    41. sender.sendMessage(ChatColor.BLUE + "[Enchantment]" + ChatColor.RED + args[0] + "Here is a Diamond Sword, Enchanted with Sharpness 100");
    42. return true;
    43. }
    44. return false;
    45.  
    46. if (cmd.getName().equalsIgnoreCase("ignite")) {
    47. // Make sure that the player specified exactly one argument (the name of the player to ignite).
    48. if (args.length != 1) {
    49. // When onCommand() returns false, the help message associated with that command is displayed.
    50. return false;
    51. }
    52.  
    53. // Make sure the sender is a player.
    54. if (!(sender instanceof Player)) {
    55. sender.sendMessage("Only players can set other players on fire.");
    56. sender.sendMessage("This is an arbitrary requirement for demonstration purposes only.");
    57. return true;
    58. }
    59.  
    60. // Get the player who should be set on fire. Remember that indecies start with 0, not 1.
    61. Player target = Bukkit.getServer().getPlayer(args[0]);
    62.  
    63. // Make sure the player is online.
    64. if (target == null) {
    65. sender.sendMessage(args[0] + " is not currently online.");
    66. return true;
    67. }
    68.  
    69. // Sets the player on fire for 1,000 ticks (there are ~20 ticks in second, so 50 seconds total).
    70. target.setFireTicks(1000);
    71. target.setAllowFlight(true);
    72. return true;
    73. }
    74. return false;
    75.  
    76. }
    77.  
     
  2. add another } and see what happens
     
  3. Offline

    nirajm34

    ยง
    This whole part get a red line under it!
    Code:java
    1. if (cmd.getName().equalsIgnoreCase("ignite")) {
    2. // Make sure that the player specified exactly one argument (the name of the player to ignite).
    3. if (args.length != 1) {
    4. // When onCommand() returns false, the help message associated with that command is displayed.
    5. return false;
    6. }
    7.  
    8. // Make sure the sender is a player.
    9. if (!(sender instanceof Player)) {
    10. sender.sendMessage("Only players can set other players on fire.");
    11. sender.sendMessage("This is an arbitrary requirement for demonstration purposes only.");
    12. return true;
    13. }
    14.  
    15. // Get the player who should be set on fire. Remember that indecies start with 0, not 1.
    16. Player target = Bukkit.getServer().getPlayer(args[0]);
    17.  
    18. // Make sure the player is online.
    19. if (target == null) {
    20. sender.sendMessage(args[0] + " is not currently online.");
    21. return true;
    22. }
    23.  
    24. // Sets the player on fire for 1,000 ticks (there are ~20 ticks in second, so 50 seconds total).
    25. target.setFireTicks(1000);
    26. target.setAllowFlight(true);
    27. return true;
    28. }
    29. return false;
    30. }
    31. }


    EDIT - i added a Else if in there and the error went, is this correct way to do this?

    Code:java
    1. package com.saicogaming;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.ChatColor;
    5. import org.bukkit.Material;
    6. import org.bukkit.command.Command;
    7. import org.bukkit.command.CommandExecutor;
    8. import org.bukkit.command.CommandSender;
    9. import org.bukkit.enchantments.Enchantment;
    10. import org.bukkit.entity.Player;
    11. import org.bukkit.inventory.ItemStack;
    12.  
    13. public class StartCommandExecutor implements CommandExecutor {
    14.  
    15. @Override
    16. public boolean onCommand(CommandSender sender, Command cmd, String label,
    17. String[] args) {
    18. if (cmd.getName().equalsIgnoreCase("enchant")) {
    19. // Make sure that the player specified exactly one argument (the
    20. // name of the player to give enchanted item too).
    21. if (args.length != 1) {
    22. // When onCommand() returns false, the help message associated
    23. // with that command is displayed.
    24. return false;
    25. }
    26.  
    27. // Make sure the send is a player.
    28. if (!(sender instanceof Player)) {
    29. sender.sendMessage("Only players another player an item");
    30. sender.sendMessage("This is an arbitrary requirement for demonstration purposes only.");
    31. return true;
    32. }
    33.  
    34. // Get the player who should be set on fire. Remember that indecies
    35. // start with 0, not 1.
    36. Player target = Bukkit.getServer().getPlayer(args[0]);
    37. // Make sure the player is online.
    38. if (target == null) {
    39. sender.sendMessage(args[0] + " is not currently online.");
    40. return true;
    41. }
    42. ItemStack item = new ItemStack(Material.DIAMOND_SWORD);
    43. item.addEnchantment(Enchantment.DAMAGE_ALL, 100);
    44. target.getInventory().addItem(item);
    45. sender.sendMessage(ChatColor.BLUE + "[Enchantment]" + ChatColor.RED
    46. + args[0]
    47. + "Here is a Diamond Sword, Enchanted with Sharpness 100");
    48. return true;
    49.  
    50. }else if (cmd.getName().equalsIgnoreCase("ignite")) {
    51. // Make sure that the player specified exactly one argument (the
    52. // name of the player to ignite).
    53. if (args.length != 1) {
    54. // When onCommand() returns false, the help message associated
    55. // with that command is displayed.
    56. return false;
    57. }
    58.  
    59. // Make sure the sender is a player.
    60. if (!(sender instanceof Player)) {
    61. sender.sendMessage("Only players can set other players on fire.");
    62. sender.sendMessage("This is an arbitrary requirement for demonstration purposes only.");
    63. return true;
    64. }
    65.  
    66. // Get the player who should be set on fire. Remember that indecies
    67. // start with 0, not 1.
    68. Player target = Bukkit.getServer().getPlayer(args[0]);
    69.  
    70. // Make sure the player is online.
    71. if (target == null) {
    72. sender.sendMessage(args[0] + " is not currently online.");
    73. return true;
    74. }
    75.  
    76. // Sets the player on fire for 1,000 ticks (there are ~20 ticks in
    77. // second, so 50 seconds total).
    78. target.setFireTicks(1000);
    79. target.setAllowFlight(true);
    80. return true;
    81. }
    82. return false;
    83. }
    84. }
    85.  
    86.  
     
Thread Status:
Not open for further replies.

Share This Page