Solved Pls help me

Discussion in 'Plugin Development' started by Randomguy, Jul 12, 2015.

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

    Randomguy

    Hi, I'm Zach, and I'm developing a plugin. Please don't copy my idea or code. So, it is a plugin that produces sounds to players. I have no errors but 1 thing... its in the server... There is a big error that I want to get rid of involving tons of else statements missing. I know what to do but I'm not sure where to actually put the else statements. This is the code:
    Code:
    package com.Zach.Soundmaker;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Sound;
    import org.bukkit.plugin.java.JavaPlugin;
    
    import java.util.logging.Logger;
    
    import org.bukkit.command.CommandSender;
    import org.bukkit.command.Command;
    import org.bukkit.entity.Player;
    
    
    public class Main extends JavaPlugin {
        public static Logger log = Logger.getLogger("Minecraft");
           
            public void onEnable() {
                log.info("Soundmaker 3000 playing sounds successfully!! Oh no! It's a zombie! Oh wait thats just this plugin...");
            }
            public void onDisable() {
                log.info("Soundmaker 3000 shutting dowwwwwwn");
            }
            public boolean onCommand(CommandSender sender, Command command, String commandLabel, String[] args ) {
            if(commandLabel.equalsIgnoreCase("GhastSound") && sender instanceof Player) {
                if (args.length == 0) {
                Player target = Bukkit.getPlayerExact(args[0]);
                Player player = (Player) sender;
                int volume = 1;
                float pitch = 1.0f;
                target.playSound(player.getLocation(), Sound.GHAST_SCREAM, volume, pitch );
                }
                else {
                    Player target = Bukkit.getPlayerExact(args[0]);
                    target.sendMessage(ChatColor.RED + "Unknown Command. Try /Soundmaker for help!");
                }
            }
            if(commandLabel.equalsIgnoreCase("ZombieSound") && sender instanceof Player) {
                if (args.length == 0) {
                Player target = Bukkit.getPlayerExact(args[0]);
                Player player = (Player) sender;
                int volume = 1;
                float pitch = 1.0f;
                target.playSound(player.getLocation(), Sound.ZOMBIE_IDLE, volume, pitch );
                }
                else {
                Player target = Bukkit.getPlayerExact(args[0]);
                target.sendMessage(ChatColor.RED + "Unknown Command. Try /Soundmaker for help!");
                }
            }
           
            if(commandLabel.equalsIgnoreCase("SkeletonSound") && sender instanceof Player) {
                if (args.length == 0) {
                Player target = Bukkit.getPlayerExact(args[0]);
                Player player = (Player) sender;
                int volume = 1;
                float pitch = 1.0f;
                target.playSound(player.getLocation(), Sound.SKELETON_IDLE, volume, pitch );
            }
                else {
                    Player target = Bukkit.getPlayerExact(args[0]);
                    target.sendMessage(ChatColor.RED + "Unknown Command. Try /Soundmaker for help!");
                }
            }
            if(commandLabel.equalsIgnoreCase("SpiderSound") && sender instanceof Player) {
                if (args.length == 0) {
                Player target = Bukkit.getPlayerExact(args[0]);
                Player player = (Player) sender;
                int volume = 1;
                float pitch = 1.0f;
                target.playSound(player.getLocation(), Sound.SPIDER_IDLE, volume, pitch );
            }
                else {
                    Player target = Bukkit.getPlayerExact(args[0]);
                    target.sendMessage(ChatColor.RED + "Unknown Command. Try /Soundmaker for help!");
                }
            }
            if(commandLabel.equalsIgnoreCase("SlimeSound") && sender instanceof Player) {
                if (args.length == 0) {
                Player player = (Player) sender;
                Player target = Bukkit.getPlayerExact(args[0]);
                int volume = 1;
                float pitch = 1.0f;
                target.playSound(player.getLocation(), Sound.SLIME_WALK, volume, pitch );
                }
                else {
                    Player target = Bukkit.getPlayerExact(args[0]);
                    target.sendMessage(ChatColor.RED + "Unknown Command. Try /Soundmaker for help!");
                }
            }
           
            if(commandLabel.equalsIgnoreCase("BlazeSound") && sender instanceof Player) {
                if (args.length == 0) {
                Player target = Bukkit.getPlayerExact(args[0]);
                Player player = (Player) sender;
                int volume = 1;
                float pitch = 1.0f;
                target.playSound(player.getLocation(), Sound.BLAZE_BREATH, volume, pitch );
            }
                else {
                    Player target = Bukkit.getPlayerExact(args[0]);
                    target.sendMessage(ChatColor.RED + "Unknown Command. Try /Soundmaker for help!");
                }
            }
            if(commandLabel.equalsIgnoreCase("EnderDragonSound") && sender instanceof Player) {
                if (args.length == 0) {
                Player target = Bukkit.getPlayerExact(args[0]);
                Player player = (Player) sender;
                int volume = 1;
                float pitch = 1.0f;
                target.playSound(player.getLocation(), Sound.ENDERDRAGON_GROWL, volume, pitch );
                }
                else {
                    Player target = Bukkit.getPlayerExact(args[0]);
                    target.sendMessage(ChatColor.RED + "Unknown Command. Try /Soundmaker for help!");
                }
            }
            if(commandLabel.equalsIgnoreCase("EndermanSound") && sender instanceof Player) {
                if (args.length == 0) {
                Player target = Bukkit.getPlayerExact(args[0]);
                Player player = (Player) sender;
                int volume = 1;
                float pitch = 1.0f;
                target.playSound(player.getLocation(), Sound.ENDERMAN_SCREAM, volume, pitch );
                target.playSound(player.getLocation(), Sound.ENDERMAN_TELEPORT, volume, pitch );
                    }
                else {
                    Player target = Bukkit.getPlayerExact(args[0]);
                    target.sendMessage(ChatColor.RED + "Unknown Command. Try /Soundmaker for help!");
                }
            }
            if(commandLabel.equalsIgnoreCase("SilverfishSound") && sender instanceof Player) {
                if (args.length == 0) {
                Player target = Bukkit.getPlayerExact(args[0]);
                Player player = (Player) sender;
                int volume = 1;
                float pitch = 1.0f;
                target.playSound(player.getLocation(), Sound.SILVERFISH_WALK, volume, pitch );
                        }
                else {
                    Player target = Bukkit.getPlayerExact(args[0]);
                    target.sendMessage(ChatColor.RED + "Unknown Command. Try /Soundmaker for help!");
                }
            }
            if(commandLabel.equalsIgnoreCase("MagmaCubeSound") && sender instanceof Player) {
                if (args.length == 0) {
                Player target = Bukkit.getPlayerExact(args[0]);
                Player player = (Player) sender;
                int volume = 1;
                float pitch = 1.0f;
                target.playSound(player.getLocation(), Sound.MAGMACUBE_JUMP, volume, pitch );
                }
                else {
                    Player target = Bukkit.getPlayerExact(args[0]);
                    target.sendMessage(ChatColor.RED + "Unknown Command. Try /Soundmaker for help!");
                }
            }
            if(commandLabel.equalsIgnoreCase("AnvilSound") && sender instanceof Player) {
                if (args.length == 0) {
                Player target = Bukkit.getPlayerExact(args[0]);
                Player player = (Player) sender;
                int volume = 1;
                float pitch = 1.0f;
                target.playSound(player.getLocation(), Sound.ANVIL_LAND, volume, pitch );
                }
                else {
                    Player target = Bukkit.getPlayerExact(args[0]);
                    target.sendMessage(ChatColor.RED + "Unknown Command. Try /Soundmaker for help!");
                }
            }
            if(commandLabel.equalsIgnoreCase("ArrowSound") && sender instanceof Player) {
                if (args.length == 0) {
                Player target = Bukkit.getPlayerExact(args[0]);
                Player player = (Player) sender;
                int volume = 1;
                float pitch = 1.0f;
                target.playSound(player.getLocation(), Sound.SHOOT_ARROW, volume, pitch );
                }
                else {
                    Player target = Bukkit.getPlayerExact(args[0]);
                    target.sendMessage(ChatColor.RED + "Unknown Command. Try /Soundmaker for help!");
                }
            }
            if(commandLabel.equalsIgnoreCase("CreeperSound") && sender instanceof Player) {
                if (args.length == 0) {
                Player target = Bukkit.getPlayerExact(args[0]);
                Player player = (Player) sender;
                int volume = 1;
                float pitch = 1.0f;
                target.playSound(player.getLocation(), Sound.CREEPER_HISS, volume, pitch );
                }
                else {
                    Player target = Bukkit.getPlayerExact(args[0]);
                    target.sendMessage(ChatColor.RED + "Unknown Command. Try /Soundmaker for help!");
                }
            }
            if(commandLabel.equalsIgnoreCase("WitherSound") && sender instanceof Player) {
                if (args.length == 0) {
                Player target = Bukkit.getPlayerExact(args[0]);
                Player player = (Player) sender;
                int volume = 1;
                float pitch = 1.0f;
                target.playSound(player.getLocation(), Sound.WITHER_SPAWN, volume, pitch );
                target.playSound(player.getLocation(), Sound.WITHER_SHOOT, volume, pitch );
                }
                else {
                    Player target = Bukkit.getPlayerExact(args[0]);
                    target.sendMessage(ChatColor.RED + "Unknown Command. Try /Soundmaker for help!");
                }
           
            }
            if (commandLabel.equalsIgnoreCase("Soundmaker") && sender instanceof Player) {
                Player player = (Player) sender;
                player.sendMessage(ChatColor.RED + "" + ChatColor.BOLD + "Type /Soundmaker help");
    
                if(args[2] == ("help")); {
                player.sendMessage(ChatColor.YELLOW + "" + ChatColor.BOLD + "Welcome To Soundmaker 3000, the ultimate trolling plugin!");
                player.sendMessage(ChatColor.YELLOW + "Type /Soundmaker (Sound) (Player) to start!"
                                        + "Options:"
                                        + "* /GhastSound"
                                        + "* /CreeperSound"
                                        + "* /ArrowSound"
                                        + "* /WitherSound"
                                        + "* /AnvilSound"
                                        + "* /MagmaCubeSound"
                                        + "* /SilverfishSound"
                                        + "* /EndermanSound"
                                        + "* /EnderDragonSound"
                                        + "* /BlazeSound"
                                        + "* /SlimeSound"
                                        + "* /SkeletonSound"
                                        + "* /ZombieSound"
                                        + "* /SpiderSound");                                           
                       
                }
            }
       
                else {
                   
               
                    Player player = (Player) sender;
                    player.sendMessage(ChatColor.RED + "That is not a valid command! Type /soundmaker for help!!");
                    }
            return false;
                }
            }
    and this is the server file thing:

    Please help!!
     
  2. @Randomguy
    It looks like you either have an extra { or } somewhere, or you need to put a { or } somewhere.
     
  3. Offline

    ark9026

    @Randomguy
    Well someone learned from a youtuber :p. Most youtubers teach bad methods such as getting minecraft's logger rather than using bukkit's built in logger. Rather than using "public static Logger log = Logger.getLogger("Minecraft"); " and using "log.info" you can just use "getLogger().info("Your message here");" in your onEnable method.

    Now that that's out of the way, let's get to the issue. For every start bracket as I call them, or "{" you need a end bracket, or "}". In an else statement, you'll need a start bracket, your code, and an end bracket. For every other statement you'll ever call, use start brackets and end brackets. If you use, say, a try catch statement inside of your else statement, it would work like:
    Code:
    } else {
    try {
       do.something;
    } catch(Exception ex) {
    system.out.printIn(ex);
    }
    }
    
    Understand?
     
    Lionhard and Asc_Nicholas like this.
  4. Offline

    Asc_Nicholas

    [QUOTE="Randomguy, post: 3168244, member: 90867990"-snip-[/QUOTE]

    Yep looks like you've ran into some syntax error (errors within the Java coding structure). It seems you are either missing or have an extra curly bracket present within your code. We could find this for you but I definitely think it would be a good learning experience to find it on your own.

    @ark9026 Did a great job of explaining the usage of the curly brackets. Essentially in Java, if you open a curly bracket you must close it as well!
     
  5. Offline

    ark9026

  6. Offline

    Randomguy

    thanks for this guys, i don't see any missing brackets... and i didn't learn from a youtuber i hadn't programmed for a year so watched a quick video because i had a logger error... There could be brackets out of order but i have no errors on eclipse...
     
  7. Offline

    _Error

    If he has Syntax errors, Im not sure if eclipse would even compile it, Inteli would not.
     
  8. Offline

    ark9026

    @Randomguy
    5 minutes of searching found your issue, but I won't just give it to you. Look over what I said above, and search for yourself. A little hint: You have an extra bracket in one place :p
     
  9. Offline

    Zombie_Striker

    @Randomguy
    Yeah, try picking up a book on Java first. There are a lot of problems that will make this plugin take up a lot of both physical and stored memory. Just go through and remember that ( ) are for constructors and these {} are for statements. If you are using an Developer program, such as notepad++, you should be able to see what statements are covered or if there are missing/added brackets.
     
  10. Offline

    WPM

    The error logs says it all

    [21:12:56] [Server thread/ERROR]: Could not load 'plugins/Soundmaker.jar' in folder 'plugins'
    org.bukkit.plugin.InvalidPluginException: java.lang.Error: Unresolved compilation problems:
    Syntax error, insert "}" to complete ClassBody
    target cannot be resolved
    Syntax error, insert "else Statement" to complete IfStatement
    Syntax error, insert "}" to complete Statement
    Syntax error, insert "else Statement" to complete IfStatement
    Syntax error, insert "}" to complete Statement
    Syntax error, insert "else Statement" to complete IfStatement
    Syntax error, insert "}" to complete Statement
    Syntax error, insert "else Statement" to complete IfStatement
    Syntax error, insert "}" to complete Statement
    Syntax error, insert "else Statement" to complete IfStatement
    Syntax error, insert "}" to complete Statement
    Syntax error, insert "else Statement" to complete IfStatement
    Syntax error, insert "}" to complete Statement
    Syntax error, insert "else Statement" to complete IfStatement
    Syntax error, insert "}" to complete Statement
    Syntax error, insert "else Statement" to complete IfStatement
    Syntax error, insert "}" to complete Statement
    Syntax error, insert "else Statement" to complete IfStatement
    Syntax error, insert "}" to complete Statement
    Syntax error, insert "else Statement" to complete IfStatement
    Syntax error, insert "}" to complete Statement
    Syntax error, insert "else Statement" to complete BlockStatements
    Syntax error, insert "}" to complete MethodBody
     
  11. Offline

    Randomguy

    THANKS SO MUCH!! I solved it... There was an extra bracket..
     
  12. Offline

    ark9026

    @Randomguy
    No problem :) Just be sure to set this thread to "solved".
     
  13. ArrayIndexOutOfBoundsException incoming .. :rolleyes:
     
  14. Offline

    ark9026

    Didn't even notice that :p
     
Thread Status:
Not open for further replies.

Share This Page