Internal Error in Subcommand Bukkit Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of Internal Error in Subcommand Bukkit without wasting too much if your time.

The question is published on by Tutorial Guruji team.

I’ve been facing a problem lately with bukkit coding. When I launch the plugin and just type /akitz command label or name it pops up with an Internal Error but when I type /akitz {subcommand} it works fine! everything here basically works fine but just the /akitz <– alone when i type it, an error pops up! here’s the code:

package me.frostgamersa;

import org.bukkit.Material;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin;

public class Main extends JavaPlugin {
@Override
public void onEnable() {

}

@Override
public void onDisable() {

}

@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    if (label.equalsIgnoreCase("akitz")) {
        Player player = (Player) sender;

        if (args.length == 0 || args.length < 2) {
            player.sendMessage("§cIncorrect Arguements");

            if (args[0].equalsIgnoreCase("legend")) {
                player.sendMessage("§bYou have been Granted §3Legend §bKit!");
                CustomItems.givela(player);
                CustomItems.givels(player);
                player.getInventory().addItem(new ItemStack(Material.GOLDEN_APPLE, 64));
                return true;
            }
            if (args[0].equalsIgnoreCase("god")) {
                player.sendMessage("§bYou have been Granted §3God §bKit!");
                CustomItems.givega(player);
                CustomItems.givegs(player);
                player.getInventory().addItem(new ItemStack(Material.GOLDEN_APPLE, 64));
                return true;
            } else {
                player.sendMessage("§cIncorrect Arguements!");
                return true;
            }
        }

Answer

This is how command should look like..

    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {

    Player p = (Player) sender;

    if (cmd.getName().equalsIgnoreCase("akitz")) {

        if (args.length != 1) {

            p.sendMessage("§cIncorrect argument count!");

        }

        if (args[0].equalsIgnoreCase("legend")) {

            p.sendMessage("§bYou got a kit §3Legend");
            CustomItems.givela(p);
            CustomItems.givels(p);
            p.getInventory().addItem(new ItemStack(Material.GOLDEN_APPLE, 64));
            return true;

        }

        if (args[0].equalsIgnoreCase("god")) {

            p.sendMessage("§bYou got a kit §3God");
            CustomItems.givega(p);
            CustomItems.givegs(p);
            p.getInventory().addItem(new ItemStack(Material.GOLDEN_APPLE, 64));
            return true;

        }

        if (!args[0].equalsIgnoreCase("legend") | !args[0].equalsIgnoreCase("god")) {

            p.sendMessage("§cIncorrect argument!");

        }

    }

    return false;

}

Also, let your class implement CommandExecutor and add to your onEnable method this..

    public void onEnable() {

        getCommand("akitz").setExecutor(this);

}

which will register command, just for sure

We are here to answer your question about Internal Error in Subcommand Bukkit - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji