Help! Command Not working and causing this error message

Discussion in 'Plugin Development' started by Hypactic, Oct 22, 2020.

  1. Offline

    Hypactic

    Hey, I am making a plugin for my friends server and when I type /giveswordofswiftness it pops up this error message. The coding for it is below the error message

    org.bukkit.command.CommandException: Unhandled exception executing command 'giveswordofswiftness' in plugin SMP v1.0.1
    22.10 13:06:14 [Server] INFO at org.bukkit.command.PluginCommand.execute(PluginCommand.java:47) ~[patched_1.16.3.jar:git-Paper-244]
    22.10 13:06:14 [Server] INFO at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:159) ~[patched_1.16.3.jar:git-Paper-244]
    22.10 13:06:14 [Server] INFO at org.bukkit.craftbukkit.v1_16_R2.CraftServer.dispatchCommand(CraftServer.java:802) ~[patched_1.16.3.jar:git-Paper-244]
    22.10 13:06:14 [Server] INFO at net.minecraft.server.v1_16_R2.PlayerConnection.handleCommand(PlayerConnection.java:1918) ~[patched_1.16.3.jar:git-Paper-244]
    22.10 13:06:14 [Server] INFO at net.minecraft.server.v1_16_R2.PlayerConnection.a(PlayerConnection.java:1729) ~[patched_1.16.3.jar:git-Paper-244]
    22.10 13:06:14 [Server] INFO at net.minecraft.server.v1_16_R2.PacketPlayInChat.a(PacketPlayInChat.java:47) ~[patched_1.16.3.jar:git-Paper-244]
    22.10 13:06:14 [Server] INFO at net.minecraft.server.v1_16_R2.PacketPlayInChat.a(PacketPlayInChat.java:5) ~[patched_1.16.3.jar:git-Paper-244]
    22.10 13:06:14 [Server] INFO at net.minecraft.server.v1_16_R2.PlayerConnectionUtils.lambda$ensureMainThread$1(PlayerConnectionUtils.java:23) ~[patched_1.16.3.jar:git-Paper-244]
    22.10 13:06:14 [Server] INFO at net.minecraft.server.v1_16_R2.TickTask.run(SourceFile:18) ~[patched_1.16.3.jar:git-Paper-244]
    22.10 13:06:14 [Server] INFO at net.minecraft.server.v1_16_R2.IAsyncTaskHandler.executeTask(IAsyncTaskHandler.java:136) ~[patched_1.16.3.jar:git-Paper-244]
    22.10 13:06:14 [Server] INFO at net.minecraft.server.v1_16_R2.IAsyncTaskHandlerReentrant.executeTask(SourceFile:23) ~[patched_1.16.3.jar:git-Paper-244]
    22.10 13:06:14 [Server] INFO at net.minecraft.server.v1_16_R2.IAsyncTaskHandler.executeNext(IAsyncTaskHandler.java:109) ~[patched_1.16.3.jar:git-Paper-244]
    22.10 13:06:14 [Server] INFO at net.minecraft.server.v1_16_R2.MinecraftServer.ba(MinecraftServer.java:1135) ~[patched_1.16.3.jar:git-Paper-244]
    22.10 13:06:14 [Server] INFO at net.minecraft.server.v1_16_R2.MinecraftServer.executeNext(MinecraftServer.java:1128) ~[patched_1.16.3.jar:git-Paper-244]
    22.10 13:06:14 [Server] INFO at net.minecraft.server.v1_16_R2.IAsyncTaskHandler.awaitTasks(IAsyncTaskHandler.java:119) ~[patched_1.16.3.jar:git-Paper-244]
    22.10 13:06:14 [Server] INFO at net.minecraft.server.v1_16_R2.MinecraftServer.sleepForTick(MinecraftServer.java:1089) ~[patched_1.16.3.jar:git-Paper-244]
    22.10 13:06:14 [Server] INFO at net.minecraft.server.v1_16_R2.MinecraftServer.w(MinecraftServer.java:1003) ~[patched_1.16.3.jar:git-Paper-244]
    22.10 13:06:14 [Server] INFO at net.minecraft.server.v1_16_R2.MinecraftServer.lambda$a$0(MinecraftServer.java:177) ~[patched_1.16.3.jar:git-Paper-244]
    22.10 13:06:14 [Server] INFO at java.lang.Thread.run(Thread.java:748) [?:1.8.0_262]
    22.10 13:06:14 [Server] INFO Caused by: java.lang.IllegalArgumentException: Item cannot be null
    22.10 13:06:14 [Server] INFO at org.apache.commons.lang.Validate.noNullElements(Validate.java:364) ~[patched_1.16.3.jar:git-Paper-244]
    22.10 13:06:14 [Server] INFO at org.bukkit.craftbukkit.v1_16_R2.inventory.CraftInventory.addItem(CraftInventory.java:292) ~[patched_1.16.3.jar:git-Paper-244]
    22.10 13:06:14 [Server] INFO at com.hypactic.SMP.commands.SMPCommands.onCommand(SMPCommands.java:20) ~[?:?]
    22.10 13:06:14 [Server] INFO at org.bukkit.command.PluginCommand.execute(PluginCommand.java:45) ~[patched_1.16.3.jar:git-Paper-244]
    22.10 13:06:14 [Server] INFO ... 18 more

    package com.hypactic.SMP.commands;import com.hypactic.SMP.items.ItemManager;import org.bukkit.command.Command;import org.bukkit.command.CommandExecutor;import org.bukkit.command.CommandSender;import org.bukkit.entity.Player;public class SMPCommands implements CommandExecutor {

    @Overridepublic boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    if (!(sender instanceof Player)) {
    sender.sendMessage("Only Players can use that command"); return true;}
    Player player = (Player) sender; if (cmd.getName().equalsIgnoreCase( "giveswordofswiftness")) {
    player.getInventory().addItem(ItemManager.swordofswiftness);}
    return true;}
    }
     
  2. Offline

    spuddy

    Code:
    @Override
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
        if (!(sender instanceof Player)) {
            sender.sendMessage("Only Players can use that command");
            return true;
        }
        Player player = (Player) sender;
        if (cmd.getName().equalsIgnoreCase( "giveswordofswiftness")) {
            player.getInventory().addItem(ItemManager.swordofswiftness);
        }
        return true;
    }
    
    Please quote code in a code block like above, it makes it much easier to read. The code you supplied seems fine in and of itself. The issue appears to be something wrong with the static ItemStack object called "swordofswiftness" in the com.hypactic.SMP.items.ItemManager class. The stack trace you posted seems to be incomplete so I can't tell what Exception was actually thrown. Perhaps swordofswiftness is null or not initialized? I'm also not sure storing an ItemStack as a static like that is wise. You'd be giving the same item Object to every player that runs the command, maybe clone it?

    player.getInventory().addItem(ItemManager.swordofswiftness.clone());
     
    Last edited: Oct 22, 2020
  3. Offline

    Strahan

    The ItemManager.swordofswitness is null. You can't add a null item.

    Next time you post code, use [code] blocks please, God it's a headache to read that lol
     

Share This Page