Solved Error occurred while enabling extraCommands v1.0 (Is it up to date?)

Discussion in 'Plugin Development' started by Futurekiller45, Dec 11, 2019.

Thread Status:
Not open for further replies.
  1. Offline

    Futurekiller45

    Hey Guys,
    I slowly want to become a Developer,
    I first started to code a Feed Plugin.
    But i have an error, i cant fix
    My Main:

    Code:
    package org.Futurekiller45.Server.main;
    
    import org.Futurekiller45.Server.commands.Feed_Command;
    import org.bukkit.Bukkit;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Main extends JavaPlugin {
      
        @Override
        public void onEnable() {
            getCommand("feed").setExecutor(new Feed_Command());
            Bukkit.getPluginManager().registerEvents(new Feed_Command(), this);
        }
      
    }
    My Feed_Command:

    Code:
    package org.Futurekiller45.Server.commands;
    
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Listener;
    
    public  class Feed_Command implements CommandExecutor, Listener{
    
        public boolean onCommand(CommandSender s, Command cmd, String l, String[] args) {
                if(s instanceof Player ) {
                    Player p = (Player) s;
                    if(p.hasPermission("Commands.feed")) {
                        if(args.length == 1) {
                            p.sendMessage("§aDu wurdest nun bis zum Rand voll gepumpt mit Essen!");
                            p.setFoodLevel(20);
                        }else if(args.length == 1);
                          
                        }else
                        p.sendMessage("§3 /feed <Name>");
                        p.setFoodLevel(20);
                }
                  
            return false;
          
        }
      
    }
    My plugin.yml:

    Code:
    Author: Futurekiller45
    name: extraCommands
    version: 1.0
    main: org.Futurekiller45.Server.main.Main
    api-version: 1.12.2
    commands:
    feed:
       description: futter dich hoch!
       usage: /<command>
       permission: Commands.feed
    Console Error:

    Code:
    [14:50:17 ERROR]: Error occurred while enabling extraCommands v1.0 (Is it up to date?)
    java.lang.NullPointerException: null
            at org.Futurekiller45.Server.main.Main.onEnable(Main.java:11) ~[?:?]
            at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:264) ~[spigot.jar:git-Spigot-dcd1643-e60fc34]
            at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:337) [spigot.jar:git-Spigot-dcd1643-e60fc34]
            at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:403) [spigot.jar:git-Spigot-dcd1643-e60fc34]
            at org.bukkit.craftbukkit.v1_12_R1.CraftServer.enablePlugin(CraftServer.java:381) [spigot.jar:git-Spigot-dcd1643-e60fc34]
            at org.bukkit.craftbukkit.v1_12_R1.CraftServer.enablePlugins(CraftServer.java:330) [spigot.jar:git-Spigot-dcd1643-e60fc34]
            at net.minecraft.server.v1_12_R1.MinecraftServer.t(MinecraftServer.java:422) [spigot.jar:git-Spigot-dcd1643-e60fc34]
            at net.minecraft.server.v1_12_R1.MinecraftServer.l(MinecraftServer.java:383) [spigot.jar:git-Spigot-dcd1643-e60fc34]
            at net.minecraft.server.v1_12_R1.MinecraftServer.a(MinecraftServer.java:338) [spigot.jar:git-Spigot-dcd1643-e60fc34]
            at net.minecraft.server.v1_12_R1.DedicatedServer.init(DedicatedServer.java:272) [spigot.jar:git-Spigot-dcd1643-e60fc34]
            at net.minecraft.server.v1_12_R1.MinecraftServer.run(MinecraftServer.java:545) [spigot.jar:git-Spigot-dcd1643-e60fc34]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_231]
     
    Last edited by a moderator: Dec 11, 2019
  2. Online

    timtower Moderator Moderator

  3. Offline

    KarimAKL

    @Futurekiller45
    1. If you need to register something more than once, create a variable that points to 1 instance of that class.
    2. A CommandExecutor doesn't need to be a Listener. (which means you don't need to register it with the PluginManager)
    3. You need to format your plugin.yml file correctly, here's how the command section should look:
    Code:
    commands:
      feed:
        description: ...
        usage: ...
        permission: ...
     
  4. Offline

    Futurekiller45

    Thanks man, now it is working ;D
     
Thread Status:
Not open for further replies.

Share This Page