Solved [} else if ] error

Discussion in 'Plugin Development' started by Wither_Style, Mar 5, 2015.

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

    Wither_Style

    Hello,
    first of all , I just joined forums because I always refer for help on here but I never really got a chance to make an account since I'd find any answer no problemo.
    For the last like 3 hours, I have been trying coding a plugin that will change gamemodes, just to mess around with it, not anything special. But it seems that in Eclipse, it underlines the else on the code and I cant really use it. I tested without the else and the plugin is working just fine (I just removed those 3 lines).
    Here is my code:
    Code:
    package me.witherstyle.spigot;
    
    import java.util.logging.Logger;
    
    import net.md_5.bungee.api.ChatColor;
    
    import org.bukkit.GameMode;
    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 Main extends JavaPlugin {
    public static Main plugin;
    public final Logger logger = Logger.getLogger("Minecraft");
    
    @Override
    public void onEnable() {
        PluginDescriptionFile pdfFile = this.getDescription();
                this.logger.info( pdfFile.getName() + ("version" + pdfFile.getVersion() + ("is now enabled!")));
    }
    
    @Override
    public void onDisable() {
        PluginDescriptionFile pdfFile = this.getDescription();
                this.logger.info( pdfFile.getName() + ("version" + pdfFile.getVersion() + ("is now disabled!")));
    }
    public boolean onCommand (CommandSender sender, Command cmd , String commandLabel, String[] args ) {
        readCommand((Player) sender, commandLabel);
        return false;
    }
    
    public void readCommand(Player player, String command ) {
        if(command.equalsIgnoreCase("gmc")); {
        player.setGameMode(GameMode.CREATIVE);
        player.sendMessage(ChatColor.DARK_GREEN + ("Gamemode changed to CREATIVE."));
        }
        else if(command.equalsIgnoreCase("gms")); // The error is here
        player.setGameMode(GameMode.SURVIVAL);
        player.sendMessage(ChatColor.DARK_GREEN + ("Gamemode changed to SURVIVAL."));
       
    }
    }
    
    
    
    
    Thanks for trying to help me out. Any help will be appreciated!
    Regards
     
  2. Offline

    timtower Administrator Administrator Moderator

    @Wither_Style The enabled / disabled messages aren't needed, Bukkit does that for you.
    For the logger please use getLogger() instead of Logger.getLogger("minecraft");
    And you have a ; instead of {
    Code:
    ("gmc")); {
    Code:
    equalsIgnoreCase("gms")); 
     
  3. Offline

    Wither_Style

    Thats what I call a quick reply... Well that actually fixed it! Also, huge thanks with the Logger messages. I know they arent needed I just add them because why not ;P
     
  4. Offline

    timtower Administrator Administrator Moderator

    @Wither_Style Perks of being in the approval queue. Glad that I could help. Please mark this thread as solved. Top right corner, thread tools, edit thread.
     
Thread Status:
Not open for further replies.

Share This Page