Not able to execute the command in my custom plugin

Discussion in 'Plugin Development' started by MightyAkash, Mar 3, 2021.

  1. Offline


    I am creating a custom plugin, and I want to create a command which will give the player some items. But I am not able to execute the command, it is showing me --- "Unknown command. Type "/help" for help."

    Here are the codes \/

    This is the GiveCommand class file\/
    package tk.havenlands.survival.havenlandssurvival.commands;
    import org.bukkit.Material;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.inventory.ItemStack;
    public class GiveCommand implements CommandExecutor {
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            if(sender instanceof Player){
                Player plr = (Player) sender;
                    ItemStack sword = new ItemStack(Material.DIAMOND_SWORD, 1);
                    ItemStack soup = new ItemStack(Material.MUSHROOM_STEM,17);
                    plr.sendMessage("Kit has been added to your inventory!");
                    return true;
            return false;
    This is the main file \/
    package tk.havenlands.survival.havenlandssurvival;
    import org.bukkit.command.CommandExecutor;
    import tk.havenlands.survival.havenlandssurvival.commands.GiveCommand;
    import tk.havenlands.survival.havenlandssurvival.commands.HelloCommand;
    public class HavenLandsSurvival extends JavaPlugin {
        public void onEnable() {
            // Plugin startup logic
            System.out.println("Plugin started!");
            getServer().getPluginManager().registerEvents(new Events(), this);
            this.getCommand("hello").setExecutor(new HelloCommand());
            this.getCommand("kit").setExecutor(new GiveCommand());
        public void onDisable() {
            // Plugin shutdown logic
            System.out.println("Plugin disabled :(");
    This is the plugin.yml \/
    name: HavenLandsSurvival
    version: 1.0.0
    description: Survival plugin for HavenLands
    main: tk.havenlands.survival.havenlandssurvival.HavenLandsSurvival
        usage: /<command>
        description: Hello command !
        usage: /<command>
        description: Get the kit to figh
    Please help me out with these.
  2. Offline


    Any errors in the console?
  3. Offline


    Yes, it is giving me this error.
    java.lang.NullPointerException: Cannot invoke "org.bukkit.command.PluginCommand.setExecutor(org.bukkit.command.CommandExecutor)" because the return value of "tk.havenlands.survival.havenlandssurvival.HavenLandsSurvival.getCommand(String)" is null
            at tk.havenlands.survival.havenlandssurvival.HavenLandsSurvival.onEnable( ~[?:?]
            at ~[server.jar:git-Spigot-37d799b-3eb7236]
            at ~[server.jar:git-Spigot-37d799b-3eb7236]
            at org.bukkit.plugin.SimplePluginManager.enablePlugin( ~[server.jar:git-Spigot-37d799b-3eb7236]
            at org.bukkit.craftbukkit.v1_16_R3.CraftServer.enablePlugin( ~[server.jar:git-Spigot-37d799b-3eb7236]
            at org.bukkit.craftbukkit.v1_16_R3.CraftServer.enablePlugins( ~[server.jar:git-Spigot-37d799b-3eb7236]
            at org.bukkit.craftbukkit.v1_16_R3.CraftServer.reload( ~[server.jar:git-Spigot-37d799b-3eb7236]
            at org.bukkit.Bukkit.reload( ~[server.jar:git-Spigot-37d799b-3eb7236]
            at org.bukkit.command.defaults.ReloadCommand.execute( ~[server.jar:git-Spigot-37d799b-3eb7236]
            at org.bukkit.command.SimpleCommandMap.dispatch( ~[server.jar:git-Spigot-37d799b-3eb7236]
            at org.bukkit.craftbukkit.v1_16_R3.CraftServer.dispatchCommand( ~[server.jar:git-Spigot-37d799b-3eb7236]
            at org.bukkit.craftbukkit.v1_16_R3.CraftServer.dispatchServerCommand( ~[server.jar:git-Spigot-37d799b-3eb7236]
            at net.minecraft.server.v1_16_R3.DedicatedServer.handleCommandQueue( ~[server.jar:git-Spigot-37d799b-3eb7236]
            at net.minecraft.server.v1_16_R3.DedicatedServer.b( ~[server.jar:git-Spigot-37d799b-3eb7236]
            at net.minecraft.server.v1_16_R3.MinecraftServer.a( ~[server.jar:git-Spigot-37d799b-3eb7236]
            at net.minecraft.server.v1_16_R3.MinecraftServer.w( ~[server.jar:git-Spigot-37d799b-3eb7236]
            at net.minecraft.server.v1_16_R3.MinecraftServer.lambda$0( ~[server.jar:git-Spigot-37d799b-3eb7236]
  4. Offline


    @MightyAkash The stack trace provided does not seem to match the code provided. Did you change the code before posting this stack trace?
  5. Offline


    No, I didn't change, I just posted this as it was.
  6. Offline

    timtower Administrator Administrator Moderator

    @MightyAkash Did you export to the correct location? Because it seems that your plugin.yml isn't updated.
  7. Offline


    I have correctly put the path to the main file in plugin.yml. Do I have to put the path to the Commands file also in the plugin.yml?
  8. Offline

    timtower Administrator Administrator Moderator

    No, check the exported jar, check if it is in the right place, check if the content is the same as your code.
  9. Offline


    Actually, finally I found out that I had created one more plugin.yml file except that which is already created by the spigot plugin template. I fixed that and now it is working all good. :)

    Thanks a lot for all of your help and support.

Share This Page