Bukkit/eclipse Error "Error occurred while enabling Command v1.8 (Is it up to date?)"

Discussion in 'Plugin Development' started by d1cM4c, Apr 11, 2022.

  1. Offline

    d1cM4c

    I dont know what i should do im new into java.

    Code:
    [15:12:21 ERROR]: Error occurred while enabling Command v1.8 (Is it up to date?)
    java.lang.NullPointerException: Cannot invoke "org.bukkit.command.PluginCommand.setExecutor(org.bukkit.command.CommandExecutor)" because the return value of "com.Vitacraft.Command.Main.getCommand(String)" is null
            at com.Vitacraft.Command.Main.onEnable(Main.java:19) ~[?:?]
            at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:321) ~[patched_1.8.8.jar:git-PaperSpigot-445]
            at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:332) [patched_1.8.8.jar:git-PaperSpigot-445]
            at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:407) [patched_1.8.8.jar:git-PaperSpigot-445]
            at org.bukkit.craftbukkit.v1_8_R3.CraftServer.loadPlugin(CraftServer.java:359) [patched_1.8.8.jar:git-PaperSpigot-445]
            at org.bukkit.craftbukkit.v1_8_R3.CraftServer.enablePlugins(CraftServer.java:318) [patched_1.8.8.jar:git-PaperSpigot-445]
            at net.minecraft.server.v1_8_R3.MinecraftServer.s(MinecraftServer.java:408) [patched_1.8.8.jar:git-PaperSpigot-445]
            at net.minecraft.server.v1_8_R3.MinecraftServer.k(MinecraftServer.java:372) [patched_1.8.8.jar:git-PaperSpigot-445]
            at net.minecraft.server.v1_8_R3.MinecraftServer.a(MinecraftServer.java:327) [patched_1.8.8.jar:git-PaperSpigot-445]
            at net.minecraft.server.v1_8_R3.DedicatedServer.init(DedicatedServer.java:267) [patched_1.8.8.jar:git-PaperSpigot-445]
            at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:563) [patched_1.8.8.jar:git-PaperSpigot-445]
            at java.lang.Thread.run(Thread.java:833) [?:?]

    I just wanted to code some random things and hat an error and dont know how to solve it.


    Main:
    Code:
    package com.Vitacraft.Command;
    
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.event.player.PlayerQuitEvent;
    import org.bukkit.plugin.java.JavaPlugin;
    
    import net.md_5.bungee.api.ChatColor;
    
    public class Main extends JavaPlugin implements Listener {
       
        @Override
        public void onEnable() {
            getServer().getPluginManager().registerEvents(this, this);
            getServer().getConsoleSender().sendMessage(ChatColor.GREEN + "WelcomePlugin Started");
            getCommand("hello").setExecutor(new CommandHello());
            getCommand("foodHelp").setExecutor(new FoodHelpCommand());
           
        }
       
        @Override
        public void onDisable() {
           
        }
       
        @EventHandler
        public void onPlayerJoin(PlayerJoinEvent e) {
            Player p = e.getPlayer();
            if(p.hasPlayedBefore()) {
                e.setJoinMessage(ChatColor.MAGIC + p.getName() + ChatColor.DARK_GREEN + "Joined" );
        }
                                   
            e.setJoinMessage( ChatColor.RED + "Hello " + ChatColor.AQUA + p.getName() + ChatColor.RED + " Welcome to Vitacraft!");
        }
       
        @EventHandler
        public void onPlayerQuit(PlayerQuitEvent e) {
            Player p = e.getPlayer();
            e.setQuitMessage(p.getName() + ChatColor.DARK_BLUE  + "has left the Sever :(");   
        }
       
    }
    plugin.yml
    Code:
    name: Command
    main: com.Vitacraft.Command.Main
    version: 1.8
    author: Olle_Palle
    commands:
       hello:
          description: basic command that reurns "hello" to the player who sends it
          usage: /hello
    extracommand:
       food:
          description: food
          usage: /foodHelp


    something other
    Code:
    package com.Vitacraft.Command;
    
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    
    
    public class CommandHello implements CommandExecutor {
    
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            if(sender instanceof Player) {
            Player player = (Player) sender;
            player.sendMessage(ChatColor.YELLOW + "Hey i wish you a good Day!");
            }
            return false;
        }
    
    }
    

    something other 2
    Code:
    package com.Vitacraft.Command;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    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.Inventory;
    import org.bukkit.inventory.ItemStack;
    
    
    public class FoodHelpCommand implements CommandExecutor {
    
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
                   
            if(sender instanceof Player) {
                Player player = (Player) sender;
                player.sendMessage(ChatColor.YELLOW + "!");
               
                Inventory foodHelp = Bukkit.createInventory(player, 9, "Your FoodHelp");
                       
                ItemStack item1 = new ItemStack(Material.COOKED_BEEF, 64);
               
                foodHelp.setItem(3 , item1);
               
                player.openInventory(foodHelp);
               
           
            }else {
                System.out.println(ChatColor.RED + "Du musst ein Spieler sein um diesen Command durchführen zu können.");
            }
               
               
               
               
               
               
           
            return false;
        }
    
    }
    
     
  2. Online

    timtower Administrator Administrator Moderator

    @d1cM4c Command in code is "foodHelp", command in plugin.yml is "food"
     

Share This Page