sound not cancelling after else statement

Discussion in 'Plugin Development' started by shohouku, Apr 30, 2013.

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

    shohouku

    Code:
        @Override
        public boolean onCommand(CommandSender sender, Command command,
                String label, String[] args) {
           
            if (label.equalsIgnoreCase("test1"));
           
            if (sender instanceof Player) {
                Player player = (Player)sender;
              Location location = player.getEyeLocation();
               
               
               
                if (player.getItemInHand().getType() == Material.WOOD_SWORD)
                      player.playEffect(location, Effect.SMOKE, 50);
               
               
               
                if(!player.getItemInHand().getType().equals(Material.WOOD_SWORD)) player.sendMessage( ChatColor.RED + "You do not require an item in your hand to activate a skill.");
                else
                    player.sendMessage( ChatColor.DARK_AQUA + "Default Skill Activated!");
                player.playSound(location, Sound.PORTAL_TRAVEL, 10, 10);

    help? :\
     
  2. Offline

    Terradominik

    when you don't make brackets, the if/else statements only go one row, also your first if makes clearly no sense cause there is nothing in there.
     
  3. Offline

    shohouku

    Heres the full code:

    I put it there because it should play the sound effect when "Default Skill Activated" message goes..

    Code:
    package plugin;
     
    import java.util.logging.Logger;
     
    import org.bukkit.ChatColor;
    import org.bukkit.Effect;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.Sound;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
     
     
     
     
     
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.java.JavaPlugin;
     
     
     
    public class feature extends JavaPlugin {
    public final Logger logger = Logger.getLogger("Minecraft");
    public static feature plugin;
     
     
     
     
     
     
     
     
     
        public final Logger log = Logger.getLogger("Minecraft");
     
        @Override
        public void onEnable() {
            PluginDescriptionFile pdfFile = this.getDescription();
            this.logger.info(pdfFile.getName() + " Has Been Enabled!");
        }
     
        @Override
        public void onDisable() {
            PluginDescriptionFile pdfFile = this.getDescription();
            this.logger.info(pdfFile.getName() + " Has Been Disabled!");
        }
     
     
        @Override
        public boolean onCommand(CommandSender sender, Command command,
                String label, String[] args) {
         
            if (label.equalsIgnoreCase("test1"));
         
            if (sender instanceof Player) {
                Player player = (Player)sender;
              Location location = player.getEyeLocation();
             
             
             
                if (player.getItemInHand().getType() == Material.WOOD_SWORD)
                      player.playEffect(location, Effect.SMOKE, 50);
             
             
             
                if(!player.getItemInHand().getType().equals(Material.WOOD_SWORD)) player.sendMessage( ChatColor.RED + "You do not require an item in your hand to activate a skill.");
                else
                    player.sendMessage( ChatColor.DARK_AQUA + "Default Skill Activated!");
                player.playSound(location, Sound.PORTAL_TRAVEL, 10, 10);
     
     
     
     
            }else{
                sender.sendMessage("You are not a player.");
             
                     
     
            }
            return true;
        }
     
    }
    
     
  4. Offline

    Terradominik

    simply make the else things in braces
     
  5. Offline

    shohouku

    braces? or brackets?

    Brackets won't work because there's already a else statement with brackets..
     
  6. Offline

    Terradominik

    braces (curly barckets) sorry i often mistake these two, because in german they are called the same...
    and they would work ;)
     
  7. Offline

    shohouku

    Brackets around the else statements don't work :(

    (else) ??
     
  8. Offline

    Terradominik

    no these things: "{}" (braces/curly brackets) and not around it. Just around the whole else statement.

    basically like

    else {
    //Code which only gets called if the if is false
    } //End of Else
     
  9. shohouku
    You should use your IDE's auto-format feature, that way you'll see how it indents it and you should understand how the code flows. For Eclipse it's Ctrl+Shift+F, I don't know for other IDEs.
     
  10. Offline

    shohouku

    thanks!! :D
     
  11. Offline

    Terradominik

    no problem, but you should learn some simple java formatting/syntax before you come to a forum like this, it would help you to solve problems such as this for yourself and you will laugh at how easy your question is ;)
     
    shohouku likes this.
Thread Status:
Not open for further replies.

Share This Page