Solved Command Arguments

Discussion in 'Spigot Plugin Development' started by IllegalSloth, Jun 1, 2017.

  1. I have no idea what is wrong
    ShardCommand.java:
    Code (Text):
    package me.illegaldev.battlecore;

    import org.bukkit.Bukkit;
    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.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;

    public class ShardCommand implements CommandExecutor {

        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
           
            // /shard <player> <type> //
           
            // VARIABLES //
           
            Player p = (Player) sender;
           
            // ITEM STACKS //
           
            ItemStack simples = new ItemStack(Material.PRISMARINE_SHARD, 1);
            ItemMeta simplesm = simples.getItemMeta();
            simplesm.setDisplayName("§8§lSIMPLE SHARD §7(Right Click)");
            simples.setItemMeta(simplesm);
           
            // COMMAND //
           
            if (args.length == 2) {
                if (Bukkit.getPlayerExact(args[0]) != null) {
                Player target = Bukkit.getPlayerExact(args[0]);
                   
                if (args[0].equalsIgnoreCase("simple")) {
                    p.sendMessage("§a§lSUCSESS! §eYou gave" + target.getDisplayName() + "§e a §8§lSIMPLE SHARD§e. " );
                    target.sendMessage("§a" + p.getDisplayName() + "§e Gave you a §8§lSIMPLE SHARD§e.");
                    target.getInventory().addItem(simples);
                }
               
                } else {
                    p.sendMessage("§e§lERROR: §eThe player specified is not online");
                    p.sendMessage("§e§lERRORHELP: §eNo help for NotOnlinePlayer");
                }
            } else {
                p.sendMessage("§e§lERROR: §eInvalid Usage: §a/shard <player> <type>");
                p.sendMessage("§e§lERRORHELP: §eUse §a/shard types§e to list the types.");
            }
           
            return false;
        }

    }
     
    Error in console:
    Code (Text):
    [10:49:42 ERROR]: Error occurred while enabling BattleCore v1.0 (Is it up to date?)
    java.lang.NullPointerException
            at me.illegaldev.battlecore.main.onEnable(main.java:11) ~[?:?]
            at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:321) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:340) [spigot.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:405) [spigot.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.craftbukkit.v1_8_R3.CraftServer.loadPlugin(CraftServer.java:357) [spigot.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.craftbukkit.v1_8_R3.CraftServer.enablePlugins(CraftServer.java:317) [spigot.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.craftbukkit.v1_8_R3.CraftServer.reload(CraftServer.java:741) [spigot.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.Bukkit.reload(Bukkit.java:535) [spigot.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:25) [spigot.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141) [spigot.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.craftbukkit.v1_8_R3.CraftServer.dispatchCommand(CraftServer.java:641) [spigot.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.craftbukkit.v1_8_R3.CraftServer.dispatchServerCommand(CraftServer.java:627) [spigot.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.DedicatedServer.aO(DedicatedServer.java:412) [spigot.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:375) [spigot.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:654) [spigot.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:557) [spigot.jar:git-Spigot-db6de12-18fbb24]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_121]
     
  2. Oops i set the shard type to arg 0 :>
     
  3. NPE show us yout main class and highlight line 11
     
  4. Still doesnt work
     
  5. getCommand("shard").setExecutor(new ShardCommand());
     
  6. Are you sure that the shard command is registered in your plugin.yml?

    [​IMG]
     
  7. Lol thanks
     
  8. Mark as solved, thanks.
     
  9. Doesnt work (I registered)
    Code (Text):
    java.lang.Error: Unresolved compilation problem:
            The method setExecutor(CommandExecutor) in the type PluginCommand is not applicable for the arguments (ShardCommand)

            at me.illegaldev.battlecore.main.onEnable(main.java:11) ~[?:?]
            at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:321) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:340) [spigot.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:405) [spigot.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.craftbukkit.v1_8_R3.CraftServer.loadPlugin(CraftServer.java:357) [spigot.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.craftbukkit.v1_8_R3.CraftServer.enablePlugins(CraftServer.java:317) [spigot.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.MinecraftServer.s(MinecraftServer.java:414) [spigot.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.MinecraftServer.k(MinecraftServer.java:378) [spigot.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.MinecraftServer.a(MinecraftServer.java:333) [spigot.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.DedicatedServer.init(DedicatedServer.java:263) [spigot.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:525) [spigot.jar:git-Spigot-db6de12-18fbb24]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_121]
    plugin.yml:
    Code (Text):
    main: me.illegaldev.battlecore.main
    author: IllegalDev
    name: BattleCore
    version: 1.0
    commands:
      shard:
        description: Give someone a shard
        aliases: [s]
     
  10. java.lang.Error: Unresolved compilation problem:
    The method setExecutor(CommandExecutor) in the type PluginCommand is not applicable for the arguments (ShardCommand)

    Can we see how your using setExecutor?
     
  11. Code (Text):
            getCommand("shard").setExecutor(new ShardCommand());
     
  12. F
    Fixed :) - Didnt implement commandexecutor