return value of "me.memesupreme6.doubledrops.Main.getCommand(String)" is null

Discussion in 'Spigot Help' started by MemeSupreme6, Jul 12, 2021.

  1. Hi ive created a plugin of custom events but i figured i would add a commaynd to it. ive tried to do this many times, the only thing ive not tried is contacting spigot. Here is my main class:

    Code (Java):
    package me.memesupreme6.doubledrops;

    import me.memesupreme6.doubledrops.plugin.commands.Command1;
    import me.memesupreme6.doubledrops.plugin.moreores.*;
    import net.md_5.bungee.api.ChatMessageType;
    import org.bukkit.ChatColor;
    import org.bukkit.configuration.file.FileConfiguration;
    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;

    public final class Main extends JavaPlugin implements Listener {
        FileConfiguration config = getConfig();

        @Override
        public void onEnable() {
            System.out.println("DodgePvP Plugin Kit Has Been Enabled.");
            System.err.println("[DPK]-[ERROR] >> THE PERMISSION SYSTEMS ARE FAILING. THIS IS BEING WORKED ON");
            config.addDefault("SendPlayerMessage", true);
            config.addDefault("PlayerJoinMessage", true);
            config.addDefault("PlayerLeaveMessage", true);
            config.options().copyDefaults(true);
            saveConfig();
            getServer().getPluginManager().registerEvents(new ListinerDiamond(), this);
            getServer().getPluginManager().registerEvents(new ListinerIron(), this);
            getServer().getPluginManager().registerEvents(new ListinerCoal(), this);
            getServer().getPluginManager().registerEvents(new ListinerGold(), this);
            getServer().getPluginManager().registerEvents(new ListinerEmerald(), this);
            getServer().getPluginManager().registerEvents(new ListinerLapis(), this);
            getServer().getPluginManager().registerEvents(new ListinerRedstone(), this);
            getServer().getPluginManager().registerEvents(new ListinerNetherackGoldOre(), this);
            getServer().getPluginManager().registerEvents(new ListinerNetherQuartz(), this);
            getServer().getPluginManager().registerEvents(this, this);
            getCommand("thisbetterwork").setExecutor(new Command1());
        }
        // This method checks for incoming players and sends them a message
        @EventHandler
        public void onPlayerJoin(PlayerJoinEvent event) {
            Player player = event.getPlayer();
            if (config.getBoolean("SendPlayerMessage")) {
                player.sendMessage(ChatColor.DARK_GRAY + "_____________________DodgePvP________________________");
                player.sendMessage(ChatColor.DARK_GRAY + "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-");
                player.sendMessage(ChatColor.AQUA + "This Is Definitely Not Your Normal Survival Server,");
                player.sendMessage(ChatColor.AQUA + "This Is DODGEPVP's Survival! Here You Will Find");
                player.sendMessage(ChatColor.AQUA + "Up To 50 Other Legendary Enchants, GKITS, Mystery Crates,");
                player.sendMessage(ChatColor.AQUA + "And Its All For The One Roll, "+ChatColor.RED+"Slaying The Ender Dragon!");
                player.sendMessage(ChatColor.RED + "Watch Your Back, And Have Fun!");
                player.sendMessage(ChatColor.DARK_GRAY + "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-");
                player.sendMessage(ChatMessageType.ACTION_BAR+"DodgePvP's Survival");
            } else {
                player.sendMessage(ChatColor.AQUA + "DodgePvP >> Welcome To The Survival Server!");
                }
            if (config.getBoolean("PlayerJoinMessage")) {
                event.setJoinMessage(ChatColor.GOLD + "[+]" + ChatColor.DARK_GRAY + " - " + ChatColor.YELLOW + player.getName() + ChatColor.GOLD + " Connected!");
            } else {
                event.setJoinMessage(ChatColor.YELLOW + player.getName() + " Has Joined The Game");
            }
            }
        @EventHandler
        public void onPlayerQuit(PlayerQuitEvent event) {
            Player player = event.getPlayer();
            if (config.getBoolean("PlayerQuitMessage")){
                event.setQuitMessage(ChatColor.BLUE + "[-]"+ChatColor.DARK_GRAY+  " - " + ChatColor.AQUA + player.getName() + ChatColor.BLUE + " Left Survival.");
            } else {
                event.setQuitMessage(ChatColor.YELLOW + player.getName() + " Has Left The Game");
            }
            if (player.isFlying()){
                if (player.hasPermission("dpk.flyallow")) {
                } else {
                    player.sendMessage(ChatColor.DARK_RED+"You Have Not Been Permitted To Fly.");
                    player.kickPlayer("Kicked For Flying.");
                }
            }
        }
    }
     
    this is my plugin.yml:
    Code (YAML):
    name: DoubleDrops
    version
    : ${1.0}
    main
    : me.memesupreme6.doubledrops.Main
    api-version
    : 1.16
    authors
    : [ MemeSupreme6 ]
    description
    : cheese
    commands
    :
      thisbetterwork
    :
        usage
    : /thisbetterwork
        aliases
    : /ihopethisworks
        discription
    : hiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
    this is my command executor, (note this is in 2 packages, does that make a difference?)
    Code (Java):
    package me.memesupreme6.doubledrops.plugin.commands;
    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 Command1 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("thisbetterwork")) {
                double maxHealth = player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getDefaultValue();
                player.setHealth(maxHealth);
                return true;
            }
            return true;
        }
    }
     
    ive looked at forums and none of them has helped me. like i said, the only thing i havent tried is contacting real people. please help!
     
  2. 1) In Main split the the "getCommand" line into 2 - the "getCommand" into a variable, then a line to check if it's not not null and then set the executor.
    2) In plugin.yml change "aliases: /ihopethisworks" to "aliases: ihopethisworks"
    3) In Commands1 remove the if check "cmd.getName().equals..." - completely unnecessary.

    Also add log prints everywhere so you know what the problem is and where it starts - let us know.
     
  3. so how would i do the first one, ive done the second one and the third one, i dont understand how to turn the getCommand into a variable. would i simply just do this?:
    getCommand("thisbetterwork")
    .setExecutor(new Command1());
     
    #3 MemeSupreme6, Jul 12, 2021
    Last edited: Jul 12, 2021
  4. this is where the problem starst in the terminal.:
    [12.07 00:09:19] [Server] [Server thread/ERROR]: Error occurred while enabling DoubleDrops v1.0-SNAPSHOT (Is it up to date?) [12.07 00:09:19] [Server] java.lang.NullPointerExceptionCannot invoke "org.bukkit.command.PluginCommand.setExecutor(org.bukkit.command.CommandExecutor)" because the return value of "me.memesupreme6.doubledrops.Main.getCommand(String)" is null
     
  5. Try removing the last 3 lines in plugin.yml and running it like that and let me know
     
  6. still getting the following error:
    Code (Text):
    Error occurred while enabling DoubleDrops v1.0-SNAPSHOT (Is it up to date?)
    [12.07 12:44:29] [Server] java.lang.NullPointerExceptionCannot invoke "org.bukkit.command.PluginCommand.setExecutor(org.bukkit.command.CommandExecutor)" because the return value of "me.memesupreme6.doubledrops.Main.getCommand(String)" is null
    the following is my plugin.yml:
    Code (Java):
    name: DoubleDrops
    version: ${1.0}
    main: me.memesupreme6.doubledrops.Main
    api-version: 1.16
    authors: [ MemeSupreme6 ]
    description: cheese
    commands:
      thisbetterwork:
     
  7. Change to this and test:
    Code (Java):
    name: DoubleDrops
    version: 1.0
    main: me.memesupreme6.doubledrops.Main
    api-version: 1.16
    commands:
      thisbetterwork:
     
  8. it still didnt work...
     
  9. try use
    Code (Text):
    commands:
       thisbetterwork:
          description: Your description
     
  10. still not working, is my server broken?
     
  11. If you still can't fix it, I hope you learn how to write plugin.yml again. We gave a solution, but what doesn't work is that you did something wrong.