Help with ClearInventory plugin?

Discussion in 'Plugin Development' started by kevinspl2000, Oct 11, 2013.

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

    kevinspl2000

    Code:java
    1. package kKev.commands;
    2.  
    3. import kKevUtil.Util;
    4. import org.bukkit.Bukkit;
    5. import org.bukkit.ChatColor;
    6. import org.bukkit.command.Command;
    7. import org.bukkit.command.CommandExecutor;
    8. import org.bukkit.command.CommandSender;
    9. import org.bukkit.entity.Player;
    10. import org.bukkit.inventory.ItemStack;
    11.  
    12. public class kKevClearInv implements CommandExecutor {
    13. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String args[])
    14. {
    15. if(!(sender instanceof Player)){
    16. System.out.println("You must be a player to do this");
    17. return false;
    18. }
    19. Player player = (Player)sender;
    20. Player tp = Bukkit.getPlayer(args[0]);
    21. String color = Util.getColour(tp);
    22. if(commandLabel.equalsIgnoreCase("ci"))
    23. if(sender.hasPermission("kKev.clearinv"))
    24. {
    25. if(args.length == 0)
    26. {
    27. player.sendMessage(ChatColor.GRAY + "Your inventory was cleared.");
    28. player.getInventory().setContents(new ItemStack[36]);
    29. player.getInventory().setArmorContents(new ItemStack[4]);
    30. }
    31. if(args.length == 1) {
    32. tp.getInventory().setArmorContents(new ItemStack[4]);
    33. tp.getInventory().setContents(new ItemStack[36]);
    34. tp.sendMessage(ChatColor.GRAY + "Your inventory was cleared.");
    35. player.sendMessage(color + tp.getName() + ChatColor.GRAY + "'s inventory was cleared.");
    36. }
    37. else {
    38. player.sendMessage(ChatColor.GRAY + "Usage: /ci <playername>");
    39. }
    40. } else if (!(player.hasPermission("kKev.clearinv")))
    41. {
    42. String help = "\"help\"";
    43. player.sendMessage(ChatColor.WHITE + "Unknown command. Type" + help + " for help");
    44.  
    45. }
    46. return false;
    47. }}

    Getting errors! Help???
    Here is the console errors
    Code:
    21:59:59 [INFO] KevPvP issued server command: /ci
    21:59:59 [SEVERE] null
    org.bukkit.command.CommandException: Unhandled exception executing command 'ci'
    in plugin kKevPlugin v1.1
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46)
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:19
    2)
            at org.bukkit.craftbukkit.v1_6_R3.CraftServer.dispatchCommand(CraftServe
    r.java:523)
            at net.minecraft.server.v1_6_R3.PlayerConnection.handleCommand(PlayerCon
    nection.java:959)
            at net.minecraft.server.v1_6_R3.PlayerConnection.chat(PlayerConnection.j
    ava:877)
            at net.minecraft.server.v1_6_R3.PlayerConnection.a(PlayerConnection.java
    :834)
            at net.minecraft.server.v1_6_R3.Packet3Chat.handle(SourceFile:49)
            at net.minecraft.server.v1_6_R3.NetworkManager.b(NetworkManager.java:296
    )
            at net.minecraft.server.v1_6_R3.PlayerConnection.e(PlayerConnection.java
    :116)
            at net.minecraft.server.v1_6_R3.ServerConnection.b(SourceFile:37)
            at net.minecraft.server.v1_6_R3.DedicatedServerConnection.b(SourceFile:3
    0)
            at net.minecraft.server.v1_6_R3.MinecraftServer.t(MinecraftServer.java:5
    92)
            at net.minecraft.server.v1_6_R3.DedicatedServer.t(DedicatedServer.java:2
    27)
            at net.minecraft.server.v1_6_R3.MinecraftServer.s(MinecraftServer.java:4
    88)
            at net.minecraft.server.v1_6_R3.MinecraftServer.run(MinecraftServer.java
    :421)
            at net.minecraft.server.v1_6_R3.ThreadServerApplication.run(SourceFile:5
    83)
    Caused by: java.lang.IllegalArgumentException: Name cannot be null
            at org.apache.commons.lang.Validate.notNull(Validate.java:203)
            at org.bukkit.craftbukkit.v1_6_R3.CraftServer.getPlayer(CraftServer.java
    :323)
            at kKev.commands.kKevClearInv.onCommand(kKevClearInv.java:21)
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44)
            ... 15 more
     
  2. Offline

    bigbeno37

    You're getting an IllegalArgumentException, meaning that somewhere in your code you're attempting to use a variable that's null. Upon looking at your code, I believe you should have a look at line 21:

    Code:
            Player player = (Player)sender;
            Player tp = Bukkit.getPlayer(args[0]);
            String color = Util.getColour(tp);
    
    You're attempting to assign color to a value which doesn't necessarily exist which is why /ci throws up errors.

    Try putting it AFTER the if(args.length == 1) statement.

    EDIT: Thanks The_Doctor_123
     
  3. Offline

    The_Doctor_123

    bigbeno37
    That is not line 21. It is the line after you just stated. And if he didn't type 1 argument, that would throw an ArrayIndexOutOfBoundsException.
     
Thread Status:
Not open for further replies.

Share This Page