Error occurred when enabling yoCores v1.0-SNAPSHOT (Is it up to date?)

Discussion in 'Plugin Development' started by Yochran, Sep 14, 2020.

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

    Yochran

    Hey, so I'm a little new to java developing, and I'm making my core plugin right now. My event handlers are fine, and everything worked fine until I tried to add some commands, in which these errors in my console popped up:


    Code:
    [18:12:48 ERROR]: Error occurred while enabling yoCores v1.0-SNAPSHOT (Is it up to date?)
    java.lang.NullPointerException
            at me.yochran.yocores.yoCores.onEnable(yoCores.java:16) ~[?:?]
            at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:321) ~[spigot.jar:git-Spigot-21fe707-e1ebe52]
            at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:340) [spigot.jar:git-Spigot-21fe707-e1ebe52]
            at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:405) [spigot.jar:git-Spigot-21fe707-e1ebe52]
            at org.bukkit.craftbukkit.v1_8_R3.CraftServer.loadPlugin(CraftServer.java:357) [spigot.jar:git-Spigot-21fe707-e1ebe52]
            at org.bukkit.craftbukkit.v1_8_R3.CraftServer.enablePlugins(CraftServer.java:317) [spigot.jar:git-Spigot-21fe707-e1ebe52]
            at net.minecraft.server.v1_8_R3.MinecraftServer.s(MinecraftServer.java:414) [spigot.jar:git-Spigot-21fe707-e1ebe52]
            at net.minecraft.server.v1_8_R3.MinecraftServer.k(MinecraftServer.java:378) [spigot.jar:git-Spigot-21fe707-e1ebe52]
            at net.minecraft.server.v1_8_R3.MinecraftServer.a(MinecraftServer.java:333) [spigot.jar:git-Spigot-21fe707-e1ebe52]
            at net.minecraft.server.v1_8_R3.DedicatedServer.init(DedicatedServer.java:263) [spigot.jar:git-Spigot-21fe707-e1ebe52]
            at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:525) [spigot.jar:git-Spigot-21fe707-e1ebe52]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_221]
    I'm not sure at all what the problem is, my plugin.yml is fine i'm sure. Here is all of my project files just in case:

    Code:
    package me.yochran.yocores;
    
    import me.yochran.yocores.commands.HealFeed;
    import me.yochran.yocores.events.JoinLeaveEvent;
    import org.bukkit.ChatColor;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class yoCores extends JavaPlugin {
    
        @Override
        public void onEnable() {
            // Plugin startup logic
            HealFeed healfeedcommand = new HealFeed();
            System.out.println(ChatColor.GREEN + "[yoCores]: yoCores v1.0-SNAPSHOT has successfully loaded.");
            getServer().getPluginManager().registerEvents(new JoinLeaveEvent(), this);
            getCommand("heal").setExecutor(healfeedcommand);
            getCommand("feed").setExecutor(healfeedcommand);
    
        }
    
        @Override
        public void onDisable() {
            // Plugin shutdown logic
            System.out.println(ChatColor.RED + "[yoCores]: yoCores v1.0-SNAPSHOT has successfully unloaded.");
        }
    }
    this is the commands class

    Code:
    package me.yochran.yocores.commands;
    
    import org.bukkit.ChatColor;
    import org.bukkit.attribute.Attribute;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    
    public class HealFeed implements CommandExecutor {
    
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            if (!(sender instanceof Player)) { return true; }
            Player player = (Player) sender;
    
            if (cmd.getName().equalsIgnoreCase("heal")) {
                double maxHealth = player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getDefaultValue();
                player.setHealth(maxHealth);
                player.setFoodLevel(20);
                return true;
            }
    
            if (cmd.getName().equalsIgnoreCase("feed")) {
                player.setFoodLevel(20);
                return true;
            }
    
            return true;
        }
    }
    
    this is my plugin.yml:

    Code:
    name: yoCores
    version: 1.0
    author: Yochran
    main: me.yochran.yocores.yoCores
    api-version: 1.8.8
    commands:
      heal:
        description: Heals the player.
        usage: /<command>
        permission: yocores.heal
      feed:
          description: Feeds the player.
          usage: /<command>
          permission: yocores.feed
    could anyone help me resolve this issue? I'm using Spigot API, running 1.8.8 spigot.
     
  2. Offline

    gochi9

    In your main class line 16 returns null

    Ok so if i am able to count than this is your line 16
    Code:
    getCommand("heal").setExecutor(healfeedcommand);
    EDIT: Also there is no api-version: 1.8.8 only from 1.13
     
    Last edited: Sep 14, 2020
  3. Offline

    Yochran

    upload_2020-9-15_8-24-26.png
    There's no errors in my code I don't really see what I did wrong, am I supposed to put return true; at the end of it?
     
  4. Offline

    gochi9

  5. Offline

    Yochran

    Ok, I removed that and just did player.setHealth(20);

    How can i fix the error where it returns null?
     
  6. Offline

    gochi9

    If you did that and removed the api-version: 1.8.8 from your plugin.yml than it should work now
     
  7. Offline

    Yochran

    Done that, same error. This is my new plugin.yml:

    Code:
    name: yoCores
    version: 1.0
    description: yoCores Plugin made by me
    author: Yochran
    main: me.yochran.yocores.yoCores
    commands:
      Heal:
        description: Heals the player.
        usage: /<command>
        permission: yocores.heal
      Feed:
        description: Feeds the player.
        usage: /<command>
        permission: yocores.feed
     
  8. Offline

    Shqep

    Your command names in the yaml file is capitalized whereas the ones that get retrieved in the plugin are not?

    ( So like you put "Heal" in the yml file but you tried to get the command "heal"? )
     
  9. Offline

    gochi9

    Yes but in the first post it was low case but still try to put "heal" instead of "Heal" same for feed
     
Thread Status:
Not open for further replies.

Share This Page