Unreachable Code

Discussion in 'Plugin Development' started by Speed_crafter007, Aug 29, 2014.

Thread Status:
Not open for further replies.
  1. So i began to learn bukkit programming with a help of a tutorial. After some learning of the programming i started to mess around with commands and created my first command. That worked perfect but then i created my second command and that then both commands didn't work and at the if line of the second command it says "unreachable Code" but in my opinion it should be reachable. Can you please help me fixing the problem?
    My Code:
    1. package de.nielster.test;
    3. import java.util.List;
    5. import org.bukkit.command.Command;
    6. import org.bukkit.command.CommandSender;
    7. import org.bukkit.entity.Player;
    8. import org.bukkit.plugin.java.JavaPlugin;
    10. public class Main extends JavaPlugin {
    12. //Laden des Plugins
    13. public void onLoad() {
    14. super.onLoad();
    15. System.out.println("Plugin wurde erfolgreich geladen");
    16. }
    18. //aktivieren des Plugins
    19. public void onEnable() {
    20. super.onEnable();
    21. System.out.println("Pluigin wurde aktviert");
    22. }
    24. //deaktivieren des Plugins
    25. public void onDisable() {
    26. super.onDisable();
    27. System.out.println("Plugin wurde deaktiviert");
    28. }
    30. //Commands
    31. public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    32. Player p = null;
    33. If (sender instanceof Player); p = (Player) sender;
    35. If (command.getName().equals("Test")); {
    36. p.sendMessage("Test Nachricht");
    38. return true;
    39. }
    42. If (command.getName().equals("info")); {
    43. String name = this.getDescription().getName();
    44. String version = this.getDescription().getVersion();
    45. List<String> authors = this.getDescription().getAuthors();
    46. String author = "";
    47. for (int i = 0; i < authors.size(); i++) author += authors.get(i) + " ";
    48. p.sendMessage("Name des Plugis: " + name + " " + version + "\n" + "Von:" + author);
    50. return true;
    51. }
    53. }
    55. private void If(boolean b) {
    56. // TODO Auto-generated method stub
    58. }
    60. }

    And my plugin.yml:

    name: Test
    version: 1.0
    author: nielster
    main: de.nielster.test.Main
          usage: /<command>
          description: nur zum Testen
          usage: /<command>
          description: informationen
    And if needed i could comment the code on english.
  2. Offline


    Why are you calling the super methods in your onLoad, onEnable, and onDisable methods?? You should be overriding the super methods with your new ones.

    Second, you shouldn't be using .equals on commands, instead equalsIgnoreCase, as not all people that use your plugin are guaranteed to write the commands in lower case.

    Third, on line 35 you write "; {" this does nothing. Literally nothing. Remove the semicolon.

    Fourth, write all java keywords in lowercase, capitalizing any character in one will remove its functionality.

    Fifth, don't write semicolons after an if statement.

    Sixth, <removed> learn java and don't waste people's time on the forums to answer questions <removed>.

    [edit by JaguarJo: removed insulting language. Please do not take out your frustrations on other forum members. Let's keep this discussion civil please.]
  3. Offline


    While everything you said is correct, give people a break. Jeez. Just because EVERYTHING isn't correct in his code doesn't mean he is a "Lazy ass." The whole point of the forums is to ask for help. Take a freaking chill pill dude.

    [edit by JaguarJo: fixed the quote box to reflect mod edits made in earlier post]
  4. Offline


    _Filip I agree. People should go elsewhere to learn Java in my opinion.
    es359 I agree. That certainly wasn't the best way to tell them that this is not the place to get help with basic Java.
    teej107 likes this.
  5. Offline


    Speed_crafter007 Sorry, but this is not the place for you to request help with Java, this is for people who already have a good understanding and wish to apply that to learning the CraftBukkit API. Until you are good enough at Java to do so, I don't recommend attempting to code for Bukkit at all. Java is an entire language, not just a way of writing things. It's very difficult to learn it on the fly. One thing at a time.

    You're right, he obviously does not grasp the basics of Java. But that was pretty rude and disrespectful, him being bad at Java or otherwise. He really isn't worth it.
    Rocoty and es359 like this.
Thread Status:
Not open for further replies.

Share This Page