Syntax error, insert "}" to complete class body. Help Please

Discussion in 'Plugin Development' started by samyounes03, Mar 15, 2015.

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

    samyounes03

    I've recently ran into a very annoying problem in my code. I don't know what to do about it, and i really need help. By looking at my code, you will see I am still a beginner. I started taking lessons 2 days ago, and I am only 11 years old. So, i will need a really good explanation in the replies if you could. This is the code: http://pastebin.com/L74ppbex
    The error is shown on line 31 which is the last one, and the error displays the following text when i hover my mouse over it: "Syntax error, insert "}" to complete class body"

    I would really appreciate good replies, Thank you :)
    [diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond]
    [diamondore][diamondore][diamondore][diamondore][diamondore][diamondore][diamondore][diamondore][diamondore][diamondore][diamondore][diamondore][diamondore][diamondore][diamondore][diamondore][diamondore][diamondore][diamondore][diamondore][diamondore][diamondore][diamondore][diamondore][diamondore][diamondore][diamondore][diamondore][diamondore][diamondore][diamondore][diamondore][diamondore][diamondore][diamondore][diamondore][diamondore][diamondore][diamondore][diamondore][diamondore][diamondore][diamondore][diamondore]
     
  2. @samyounes03 Your missing a } also they are really badly indented.
     
  3. Offline

    Ruptur

    @samyounes03
    It would help if you learn more of java before coding plugins. Its suprising how 5 mins looking at java books would help you help solve your problem

    Fix ..
    Code:java
    1.  
    2.  
    3. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    4. if (sender instanceof Player) {
    5. Player player = (Player) sender;
    6. //return false; < dont return here
    7.  
    8. if (cmd.getName().equalsIgnoreCase("hello")) {
    9. player.sendMessage(ChatColor.AQUA + "Hello, " + ChatColor.RED + player.getName() + ChatColor.AQUA + "!");
    10. return true;
    11. }
    12. if (cmd.getName().equalsIgnoreCase("hi")) {
    13. player.sendMessage(ChatColor.AQUA + "Hi, " + ChatColor.RED + player.getName() + ChatColor.AQUA + "!");
    14. return true;
    15. }
    16.  
    17. }
    18. return true;
    19. }
    20.  
    21.  
    22.  


    The problem was the syntax
    A method starts with a '{' and must end with a '}' nothing more to it. You had one to many brackets
    Again look into java before starting plugins


    EDIT: onCommand needs to turn a boolean, if the commandsender isnt an instance of player, then it would still the ifs, but it needs to return true. so at the end just add a return true. Like above
    ======================================
    If i helped set tag prefix as [Solved]
    Support: [Like]
    Ruptur -
     
    Last edited: Mar 15, 2015
    samyounes03 likes this.
  4. Offline

    Kilorbine

    +1 op!
    You have to indent nicelly your code, or else you will be really fast lost.
    here http://pastebin.com/XCYTzhAL is your code, indented and working.

    Just for you to know : For every '{' there hase to be an '}'
    And i can assure you that this will not working.
    You will NEVER have acces to your command!
    But I will let you search why :p
     
  5. Offline

    samyounes03

    This didn't fix it, it still has the exact same error on the last line, and when i add "}" , an error appears next to public boolean and the first "if' statement saying: Unreachable code.
     
  6. Offline

    Kilorbine

    Haha, this error is for the one i said you.
    I will give you help :
    When you have a "Return" in your function, it leave the current funtion and do not execute what is behind.
    So if I have this :
    Code:
    boolean hello()
    {
    return (true);
    print("hello world!\n");
    }
    It will never EVER print hello, because it quit the function hello() before he can print "hello"
     
  7. Offline

    samyounes03

    Code:
    package me.samyounes03.MyFirstPlugin;
    
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Main extends JavaPlugin {
       
        public void onEnable() {
            getLogger().info("Plugin Enabled");
        }
       
        public void onDisable() {
            getLogger().info("Plugin Disbaled");
        }
       
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            if (sender instanceof Player) {
                Player player = (Player) sender;
            return false;
                if (cmd.getName().equalsIgnoreCase("hello")) {
                    player.sendMessage(ChatColor.AQUA + "Hello, " + player.getName() + "!");
                   
            return false;
                }
                if (cmd.getName().equalsIgnoreCase("hi")) {
                    player.sendMessage(ChatColor.AQUA + "Hi, " + player.getName() + "!");
                }
    
            return false; }
            return false; } }
    

    Line 23 -> 27 unreachable code.
     
  8. Offline

    Ruptur

    @samyounes03
    Like a said above,
    Code:
    // som code
    return false;
    player.sendMessage("This wont work");
    
    If you return, then you are telling the program to leave that specify 'method' and anything after it will NOT run.

    You simply need to remove the
    Code:
    return false;
    
    And it will work

    ======================================
    If i helped set tag prefix as [Solved]
    Support: [Like]
    Ruptur -
     
  9. Also, use if you are using Eclipse, do Ctrl+Shift+F to format your code nicely for you,
     
  10. @samyounes03 PLEASE learn Java before trying to code with the Bukkif API. Even if you learn the basics, it'll make so much more sense. Trying to code with Bukkit before learning Java will get you nowhere and will leave you confused. Again, please learn Java before coding Bukkit. :)
     
Thread Status:
Not open for further replies.

Share This Page