This method must return a result type of boolean

Discussion in 'Plugin Development' started by Robin Bi, Mar 20, 2014.

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

    Robin Bi

    It's me again, the biggest bukkit development noob on earth ;)


    Yesterday, my problem was pretty ease to solve, so this one won't really be more difficult...


    So this is my code:
    Code:java
    1. package myname.mywebsite.wizard;
    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.java.JavaPlugin;
    8.  
    9. public class Main extends JavaPlugin {
    10.  
    11.  
    12. @Override
    13. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    14.  
    15. // Umwandlung sender --> Player
    16. Player p = null;
    17. if (sender instanceof Player) {
    18. p = (Player)sender;
    19. }
    20.  
    21.  
    22. // Kommando /HEAL
    23.  
    24.  
    25. if (cmd.getName().equalsIgnoreCase("heal")) {
    26.  
    27. if (args.length == 0) {
    28. p.setHealth(20);
    29. p.setFoodLevel(20);
    30. p.sendMessage(ChatColor.GREEN + "[" + ChatColor.GOLD + "Wizard" + ChatColor.GREEN + "]" + ChatColor.WHITE + " Du wurdest geheilt.");
    31. return true;
    32. }
    33. else if (args.length == 1) {
    34. Player target = this.getServer().getPlayer(args[0]);
    35. target.setHealth(20);
    36. target.setFoodLevel(20);
    37. target.sendMessage(ChatColor.GREEN + "[" + ChatColor.GOLD + "Wizard" + ChatColor.GREEN + "] " + ChatColor.WHITE + p.getName() + " hat dich geheilt.");
    38. return true;
    39.  
    40. }
    41. else if (args.length > 1) {
    42. p.sendMessage(ChatColor.GREEN + "[" + ChatColor.GOLD + "Wizard" + ChatColor.GREEN + "] " + ChatColor.WHITE + "Usage: /heal [target]");
    43. return true;
    44. }
    45. else {
    46. return false;
    47. }
    48. }
    49.  
    50.  
    51. }
    52. }
    53.  



    Eclipse tells me that the method onCommand must return a result type of boolean, but i think i returned true or false in every single turnout, didn't I?



    Hope, help's coming soon :)



    Yours sincerely,
    Robin Bi
     
  2. Offline

    StealerSlain

    try this
    Code:java
    1. @Override
    2. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    3. return false;
    4. // Umwandlung sender --> Player
    5. Player p = null;
    6. if (sender instanceof Player) {
    7. p = (Player)sender;
    8. }
    9.  
    10.  
    11. // Kommando /HEAL
    12.  
    13.  
    14. if (cmd.getName().equalsIgnoreCase("heal")) {
    15.  
    16. if (args.length == 0) {
    17. p.setHealth(20);
    18. p.setFoodLevel(20);
    19. p.sendMessage(ChatColor.GREEN + "[" + ChatColor.GOLD + "Wizard" + ChatColor.GREEN + "]" + ChatColor.WHITE + " Du wurdest geheilt.");
    20. return true;
    21. }
    22. else if (args.length == 1) {
    23. Player target = this.getServer().getPlayer(args[0]);
    24. target.setHealth(20);
    25. target.setFoodLevel(20);
    26. target.sendMessage(ChatColor.GREEN + "[" + ChatColor.GOLD + "Wizard" + ChatColor.GREEN + "] " + ChatColor.WHITE + p.getName() + " hat dich geheilt.");
    27. return true;
    28.  
    29. }
    30. else if (args.length > 1) {
    31. p.sendMessage(ChatColor.GREEN + "[" + ChatColor.GOLD + "Wizard" + ChatColor.GREEN + "] " + ChatColor.WHITE + "Usage: /heal [target]");
    32. return true;
    33. }
    34. }
    35. }

    And no, you don't biggest bukkit noob on the earth ;)
     
  3. Offline

    iBieel

    You must return a Boolean value of the method.
    Try this:
    Code:java
    1. @Override
    2. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    3.  
    4. // Umwandlung sender --> Player
    5. Player p = null;
    6. if (sender instanceof Player) {
    7. p = (Player)sender;
    8. }
    9.  
    10.  
    11. // Kommando /HEAL
    12.  
    13.  
    14. if (cmd.getName().equalsIgnoreCase("heal")) {
    15.  
    16. if (args.length == 0) {
    17. p.setHealth(20);
    18. p.setFoodLevel(20);
    19. p.sendMessage(ChatColor.GREEN + "[" + ChatColor.GOLD + "Wizard" + ChatColor.GREEN + "]" + ChatColor.WHITE + " Du wurdest geheilt.");
    20.  
    21. }
    22. else if (args.length == 1) {
    23. Player target = this.getServer().getPlayer(args[0]);
    24. target.setHealth(20);
    25. target.setFoodLevel(20);
    26. target.sendMessage(ChatColor.GREEN + "[" + ChatColor.GOLD + "Wizard" + ChatColor.GREEN + "] " + ChatColor.WHITE + p.getName() + " hat dich geheilt.");
    27.  
    28.  
    29. }
    30. else if (args.length > 1) {
    31. p.sendMessage(ChatColor.GREEN + "[" + ChatColor.GOLD + "Wizard" + ChatColor.GREEN + "] " + ChatColor.WHITE + "Usage: /heal [target]");
    32.  
    33. }
    34. else {
    35.  
    36. }
    37. }
    38.  
    39. return false;
    40. }
     
  4. Offline

    GameplayJDK

    Robin Bi
    You didn't, at the end of the onCommand parentheses you need to return false
     
  5. Offline

    Robin Bi

    Wow, that was a whole range of solutions! To be honest, I didn't really get what StealerSlain and iBieel changed, but the post of GameplayJDK was understandable for me :)

    A HUGE thanks to all of you! I owe you one ^^



    Yours sincerely,
    Robin Bi
     
  6. Offline

    GameplayJDK

  7. Offline

    Mysticate

    What they did was add a return true line at the end of the code. That is what it means by return a boolean
     
  8. Offline

    StealerSlain

    Robin Bi i deleted this code
    Code:java
    1. else{
    2. return false
    3. }

    which is useless.
    and added in the method body "return false".
     
  9. Offline

    Robin Bi

    Oh okay! Makes sense now :)
    Thanks again.
     
Thread Status:
Not open for further replies.

Share This Page