An internal error occurred while attempting to perform this command

Discussion in 'Plugin Development' started by Qvint01, May 14, 2020.

  1. Offline

    Qvint01

    Code:
    package Classes;
    
    
    import net.md_5.bungee.api.ChatColor;
    
    import org.bukkit.GameMode;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    
    public class Commands implements CommandExecutor {
       
        private Main plugin;
       
        public Commands(Main plugin) {
            this.plugin = plugin;
        }
       
        public boolean onCommand(CommandSender sender, Command cmd, String label,String[] args) {
           
            Player p = (Player) sender;
            String mode = args[0];
           
            if(!sender.hasPermission("qplugin.gm")){
                sender.sendMessage(ChatColor.RED + "You don't have permission.");
                return false;
            }
           
            if(args.length == 0 ){
                return false;
            }
           
            if (args.length > 0){
                if(mode.equals("0")){
                    sender.sendMessage(ChatColor.GOLD + "You got survival!");
                    p.setGameMode(GameMode.SURVIVAL);
                    return true;
                } else if(mode.equals("1")){
                    sender.sendMessage(ChatColor.GOLD + "You got creative!");
                    p.setGameMode(GameMode.CREATIVE);
                    return true;
                }else if(mode.equals("2")){
                    sender.sendMessage(ChatColor.GOLD + "You got adventure!");
                    p.setGameMode(GameMode.ADVENTURE);
                    return true;
                }else if(mode.equals("3")){
                    sender.sendMessage(ChatColor.GOLD + "You got spectator!");
                    p.setGameMode(GameMode.SPECTATOR);
                    return true;
                }
            }
           
            return false;       
        }
    }
    
    When I write: /gm

    I get: An internal error occurred while attempting to perform this command

    help please
     
  2. Offline

    timtower Moderator Moderator

    @Qvint01 Check your console, it says what is wrong.
    You are using args[0] before you do the length check. That is causing the issue.
     
  3. Offline

    Qvint01

    Thank you
     

Share This Page