A "}" bug.

Discussion in 'Plugin Development' started by asacs, May 4, 2014.

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

    asacs

    main.Survivalgames.java

    Code:java
    1. package main;
    2.  
    3. import java.io.File;
    4. import java.io.IOException;
    5. import java.util.ArrayList;
    6. import java.util.HashMap;
    7.  
    8. import org.bukkit.Location;
    9. import org.bukkit.command.Command;
    10. import org.bukkit.command.CommandSender;
    11. import org.bukkit.configuration.file.FileConfiguration;
    12. import org.bukkit.configuration.file.YamlConfiguration;
    13. import org.bukkit.entity.Player;
    14. import org.bukkit.inventory.Inventory;
    15. import org.bukkit.plugin.java.JavaPlugin;
    16.  
    17.  
    18. public class SurvivalGames extends JavaPlugin {
    19.  
    20. public String prefix ="§7[§bSurvivalGames§7] ";
    21.  
    22. public ArrayList<Player> dead = new ArrayList<Player>();
    23. public ArrayList<Player> online = new ArrayList<Player>();
    24.  
    25. public HashMap<Location, Inventory> sgchest = new HashMap<Location, Inventory>();
    26.  
    27. public File file = new File("plugins/SurvivalGames", "config.yml");
    28. public FileConfiguration cfg = YamlConfiguration.loadConfiguration(this.file);
    29.  
    30. public boolean joinable;
    31. public boolean onspawn;
    32. public boolean friendly;
    33.  
    34. public int expid;
    35. public int exp;
    36.  
    37. public int startid;
    38. public int start;
    39. public int friede;
    40. public int friedeid;
    41.  
    42. public void onEnable() {
    43.  
    44. System.out.println("[SurvivalGames Asacs] Aktiviert!");
    45.  
    46. this.joinable = true;
    47. this.friendly = true;
    48. this.onspawn = false;
    49.  
    50. this.exp = 120;
    51. this.start = 15;
    52. this.friede = 180;
    53.  
    54. }
    55.  
    56. public boolean onCommand(CommandSender sender, Command cmd, String label,
    57. String[] args) {
    58.  
    59.  
    60. Player p = (Player)sender;
    61.  
    62. if(cmd.getName().equalsIgnoreCase("sg")) {
    63.  
    64. if(args.length == 0) {
    65. p.sendMessage("§7Das ist ein Survivalgames Plguin.");
    66. }
    67.  
    68. if(args.length == 1) {
    69. if(args[0].equalsIgnoreCase("start")) {
    70. if(p.hasPermission("sg.start")) {
    71. this.exp = 11;
    72. }
    73. }
    74. }
    75.  
    76. if(args.length == 2) {
    77.  
    78. if(args[0].equalsIgnoreCase("setlobby")) {
    79. if(p.hasPermission("sg.setlobby")) {
    80. this.cfg.set("SurvivalGames.Spawn.World", p.getWorld().getName());
    81. this.cfg.set("SurvivalGames.Spawn.X", Double.valueOf(p.getLocation().getX()));
    82. this.cfg.set("SurvivalGames.Spawn.Y", Double.valueOf(p.getLocation().getY()));
    83. this.cfg.set("SurvivalGames.Spawn.Z", Double.valueOf(p.getLocation().getZ()));
    84. this.cfg.set("SurvivalGames.Spawn.Yaw", Double.valueOf(p.getLocation().getYaw()));
    85. this.cfg.set("SurvivalGames.Spawn.Pitch", Double.valueOf(p.getLocation().getPitch()));
    86. try {
    87. this.cfg.save(this.file);
    88. p.sendMessage(this.prefix + "§aDie Map Spawn wurde gesetzt.");
    89. } catch (IOException e) {
    90. e.printStackTrace();
    91. }
    92. }
    93. }
    94. }
    95. }
    96. return false;
    97.  
    98. }
    99.  
    100.  


    The last one "}" shows "Syntax error, insert "}" to complete ClassBodySurvivalGames.java"


    plugin.yml

    Code:
    name: SurvivalGames
    version: 1.0
    author: Asacs
    website: www.asacsplay.me
    main: main.SurvivalGames
    


    Any stuff i forgett?
     
  2. Offline

    Adriani6

    To me the return from command looks like its in wrong place... try moving it one } up. Im on my phone right now so I might be wrong.
     
  3. Offline

    DxDy

    You need one more } at the end of your file to close your class's body.
     
  4. Offline

    asacs

    nope nothink change.

    DxDy

    Yep i had that too, but when I ingame not one command works. Any idea why?
     
  5. Offline

    Rocoty

    Return statement is outside the method

    EDIT: Never mind. I counted wrong
     
  6. Offline

    DxDy

    I think you really need to look at your brace-placement. Try to have a proper intendation, that goes a long way in solving your problems here ;) Each brace has to have one closing brace to it. And where they are defines what is executed.
     
  7. Offline

    asacs

    Dydy im new at java coding & not english.. so i dont get anythink what you said.
     
  8. Offline

    garbagemule

    The awesome thing about using proper indentation is that you will never run into these kinds of problems. What DxDy is talking about is the different between this:
    Code:
    public void someMethod() {
        if (somethingIsTrue) {
            doSomething();
        } else {
            doSomethingElse();
        }
    }
    And this:
    Code:
    public void someMethod()
                    {    if (somethingIsTrue)
    {           doSomething();
        }
    else                {
            doSomethingElse();    }
    }
    Do it the right way the first time (it's not that hard, especially considering all the help you get from modern IDEs and/or text editors), and you'll never have to worry about not being able to read your own code, which is exactly your problem here.

    Think of indentation and proper formatting of your code as the equivalent of formatting in your typical newspaper article. Which do you prefer? This:
    Code:
       This is a load of crap that I just
    came up with, just to give an example
    of proper formatting in article-type
    texts. The purpose of this text is to
    demonstrate just how important proper
    formatting is for the readability of
    a written work.
     
       Clearly, there is no doubt that if
    code (as well as any written work) is
    formatted properly, it is very simple
    to spot syntactical errors, because
    they will stand out from the rest.
    Or this:
    Code:
                        This is a
    load of       crap that I just came  
    up       with,just to give        an
    example      of proper        formatt
    ing in article - typetexts.The purpos
    e of this text is todemonstrate    ju
    st how important properform
    atting is for the read  ability ofa w
    ritten work. Clearly
     
      ,there is         no    doubt    th
    at if code (as well as any writ  ten
     work) isforma tted properly, it    i
    s very      simpleto spot syntacti cal 
    errors, beca use..they will stand out
    from the rest      .
    Edit: And just FYI, the Java compiler is very, very stable. If it says there is an error, it's most likely because there is. This is not a bug, but an invalid Java source file. There are times when the static analysis phase of a compiler fails (and it usually means there is a better/simpler/more logic way of doing what you're trying to do), but chances are very small that you'll run into them, especially at this stage.
     
    NDUGAR and DxDy like this.
Thread Status:
Not open for further replies.

Share This Page