An internal error occured while attempting to perform this command

Discussion in 'Plugin Development' started by Deity, Sep 10, 2024.

  1. Offline

    Deity

    Hi, i'm trying to make my own command to set someones/your level in-game. But when i use the command in-game it says "An internal error occured while attempting to perform this command". Currently i'm aiming at changing the game level but i'd like to make a sort of a rpg plugin later on. I just started with java and before posting this i searched the forum & tried to fix it myself for an hour.

    Code:
        @Override
        public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
          if (command.getName().equalsIgnoreCase("levelset") && sender instanceof Player) {
          
            Player player = (Player) sender;
            int intendedlevel = Integer.parseInt(args[0]);
            if (args[1].length() == 0) {
                player.setLevel(intendedlevel); }
            else {
            Player target = Bukkit.getPlayerExact(args[1]);
            String targetname = target.getDisplayName();
            targetname.setLevel(intendedlevel);
            player.sendMessage(ChatColor.RED + "Level of player" + args[1] + "set to" + intendedlevel);
            return true;
            }
          } else {
            sender.sendMessage(ChatColor.RED + "You are not permitted to do this.");
          }
        sender.sendMessage(ChatColor.RED + "This command does not exist.");
        return false;
        }
    Thank you for your time and sorry for asking you to help me with what is probably a very trivial problem.
    Also i have one more question, into
    Code:
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
    can be put more than one commands, right?
     
  2. Offline

    timtower Administrator Administrator Moderator

    @Deity onCommand can handle as much commands as you want.
    My guess is that you have an ArrayOutOfBounds exception because you don't check the length of args.
     
  3. Offline

    Smeary_Subset

    Go into the server console and post the error message.
     

Share This Page