Solved Null string with getCommand

Discussion in 'Spigot Plugin Development' started by SpyingBadge2143, Jun 26, 2021.

  1. I have a null string whenever I start my plugin on getCommand.

    Main script:
    Code (Java):
    package com.spyingbadge2143;

    import com.spyingbadge2143.Commands.Commands;
    import com.spyingbadge2143.Events.Events;
    import org.bukkit.ChatColor;
    import org.bukkit.event.Listener;
    import org.bukkit.plugin.java.JavaPlugin;


    public class TestPlugin extends JavaPlugin implements Listener {

        @Override
        public void onEnable() {
            this.getCommand("joindata").setExecutor(new Commands());
            getServer().getConsoleSender().sendMessage(ChatColor.GREEN + "2t2a plugin enabled.");
            getServer().getPluginManager().registerEvents(new Events(), this);

        }

        @Override
        public void onDisable() {
            getServer().getConsoleSender().sendMessage(ChatColor.RED + "2t2a plugin disabled");
        }
    }
    Command Script:

    Code (Java):
    package com.spyingbadge2143.Commands;

    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 Commands implements CommandExecutor {
        public String join = "joindate";

        @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(join)) {
                 player.sendMessage(ChatColor.BLACK + "You Joined on " + player.getFirstPlayed());

            }

            return true;
        }

    }
     
    Plugin.Yml:

    Code (Java):
    main: com.spyingbadge2143.TestPlugin
    name: Welcome Plugin
    version: 1.1
    author: SpyingBadge2143
    comands:
      joindate:
          usage: /<command>
          description: Use this command to find out your join date!



    Please respond if you can help.




    Forgot about the error:
    Code (Java):
    [16:50:33 ERROR]: Error occurred while enabling 2t2aPlugin v1.1 (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.spyingbadge2143.TestPlugin.getCommand(String)" is null
            at com.spyingbadge2143.TestPlugin.onEnable(TestPlugin.java:14) ~[?:?]
            at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:264) ~[patched_1.12.2.jar:git-Paper-1618]
            at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:316) ~[patched_1.12.2.jar:git-Paper-1618]
            at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:405) ~[patched_1.12.2.jar:git-Paper-1618]
            at org.bukkit.craftbukkit.v1_12_R1.CraftServer.enablePlugin(CraftServer.java:395) ~[patched_1.12.2.jar:git-Paper-1618]
            at org.bukkit.craftbukkit.v1_12_R1.CraftServer.enablePlugins(CraftServer.java:344) ~[patched_1.12.2.jar:git-Paper-1618]
            at net.minecraft.server.v1_12_R1.MinecraftServer.t(MinecraftServer.java:442) ~[patched_1.12.2.jar:git-Paper-1618]
            at net.minecraft.server.v1_12_R1.MinecraftServer.l(MinecraftServer.java:403) ~[patched_1.12.2.jar:git-Paper-1618]
            at net.minecraft.server.v1_12_R1.MinecraftServer.a(MinecraftServer.java:341) ~[patched_1.12.2.jar:git-Paper-1618]
            at net.minecraft.server.v1_12_R1.DedicatedServer.init(DedicatedServer.java:289) ~[patched_1.12.2.jar:git-Paper-1618]
            at net.minecraft.server.v1_12_R1.MinecraftServer.run(MinecraftServer.java:616) ~[patched_1.12.2.jar:git-Paper-1618]
            at java.lang.Thread.run(Thread.java:831) [?:?]
     
  2. There’s a typo. You wrote joindata but in your config it’s joindate so the command is null
     
  3. Changed it but still got the error
     
  4. Than the error code should be different. The error code basically means that the joindate command doesn’t exist
     
  5. Code (Java):
    [17:10:50 ERROR]: Error occurred while enabling 2t2aPlugin v1.1 (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.spyingbadge2143.TestPlugin.getCommand(String)" is null
            at com.spyingbadge2143.TestPlugin.onEnable(TestPlugin.java:14) ~[?:?]
            at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:264) ~[patched_1.12.2.jar:git-Paper-1618]
            at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:316) ~[patched_1.12.2.jar:git-Paper-1618]
            at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:405) ~[patched_1.12.2.jar:git-Paper-1618]
            at org.bukkit.craftbukkit.v1_12_R1.CraftServer.enablePlugin(CraftServer.java:395) ~[patched_1.12.2.jar:git-Paper-1618]
            at org.bukkit.craftbukkit.v1_12_R1.CraftServer.enablePlugins(CraftServer.java:344) ~[patched_1.12.2.jar:git-Paper-1618]
            at net.minecraft.server.v1_12_R1.MinecraftServer.t(MinecraftServer.java:442) ~[patched_1.12.2.jar:git-Paper-1618]
            at net.minecraft.server.v1_12_R1.MinecraftServer.l(MinecraftServer.java:403) ~[patched_1.12.2.jar:git-Paper-1618]
            at net.minecraft.server.v1_12_R1.MinecraftServer.a(MinecraftServer.java:341) ~[patched_1.12.2.jar:git-Paper-1618]
            at net.minecraft.server.v1_12_R1.DedicatedServer.init(DedicatedServer.java:289) ~[patched_1.12.2.jar:git-Paper-1618]
            at net.minecraft.server.v1_12_R1.MinecraftServer.run(MinecraftServer.java:616) ~[patched_1.12.2.jar:git-Paper-1618]
            at java.lang.Thread.run(Thread.java:831) [?:?]
     
  6. It’s still null. Did you export your new jar into the right directory?
     
  7. Yup it went in correctly checked the code from the jar file also. (That was in the plugins folder)
     
  8. In plugin.yml, it’s commands not comands
     
  9. No error works now thanks! Ik something looked wrong in the plugin.yml