Command not working (Own plugin)

Discussion in 'Plugin Development' started by martinke123, May 29, 2014.

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

    martinke123

    I made my own plugin but i am getting a error the hole time when i try to use the command for the plugin.
    I get the error: An internal error occurred while attempting to perform this command.


    And this is the error i get in the console:


    Code:java
    1. org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[craftbukkit-beta2-os.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    2. 29.05 17:14:00 [Server] INFO at me.martinke123.main.main.onCommand(main.java:36) ~[?:?]
    3. 29.05 17:14:00 [Server] INFO Caused by: java.lang.NullPointerException
    4. 29.05 17:14:00 [Server] INFO at net.minecraft.server.v1_7_R1.ThreadServerApplication.run(SourceFile:617) [craftbukkit-beta2-os.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    5. 29.05 17:14:00 [Server] INFO at net.minecraft.server.v1_7_R1.MinecraftServer.run(MinecraftServer.java:457) [craftbukkit-beta2-os.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    6. 29.05 17:14:00 [Server] INFO at net.minecraft.server.v1_7_R1.MinecraftServer.t(MinecraftServer.java:545) [craftbukkit-beta2-os.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    7. 29.05 17:14:00 [Server] INFO at net.minecraft.server.v1_7_R1.DedicatedServer.u(DedicatedServer.java:250) [craftbukkit-beta2-os.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    8. 29.05 17:14:00 [Server] INFO at net.minecraft.server.v1_7_R1.MinecraftServer.u(MinecraftServer.java:655) [craftbukkit-beta2-os.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    9. 29.05 17:14:00 [Server] INFO at net.minecraft.server.v1_7_R1.ServerConnection.c(SourceFile:134) [craftbukkit-beta2-os.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    10. 29.05 17:14:00 [Server] INFO at net.minecraft.server.v1_7_R1.NetworkManager.a(NetworkManager.java:146) [craftbukkit-beta2-os.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    11. 29.05 17:14:00 [Server] INFO at net.minecraft.server.v1_7_R1.PacketPlayInChat.handle(PacketPlayInChat.java:47) [craftbukkit-beta2-os.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    12. 29.05 17:14:00 [Server] INFO at net.minecraft.server.v1_7_R1.PacketPlayInChat.a(PacketPlayInChat.java:28) [craftbukkit-beta2-os.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    13. 29.05 17:14:00 [Server] INFO at net.minecraft.server.v1_7_R1.PlayerConnection.a(PlayerConnection.java:814) [craftbukkit-beta2-os.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    14. 29.05 17:14:00 [Server] INFO at net.minecraft.server.v1_7_R1.PlayerConnection.handleCommand(PlayerConnection.java:952) [craftbukkit-beta2-os.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    15. 29.05 17:14:00 [Server] INFO at org.bukkit.craftbukkit.v1_7_R1.CraftServer.dispatchCommand(CraftServer.java:683) ~[craftbukkit-beta2-os.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    16. 29.05 17:14:00 [Server] INFO at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:175) ~[craftbukkit-beta2-os.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    17. 29.05 17:14:00 [Server] INFO at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[craftbukkit-beta2-os.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    18. 29.05 17:14:00 [Server] INFO org.bukkit.command.CommandException: Unhandled exception executing command 'kitpvp' in plugin KitPvp v0.1
    19. 29.05 17:14:00 [Server] ERROR null




    And this is my plugin code:


    Code:java
    1. package me.martinke123.main;
    2.  
    3. import java.io.File;
    4. import java.io.IOException;
    5.  
    6. import org.bukkit.ChatColor;
    7. import org.bukkit.command.Command;
    8. import org.bukkit.command.CommandSender;
    9. import org.bukkit.configuration.file.FileConfiguration;
    10. import org.bukkit.entity.Player;
    11. import org.bukkit.inventory.ItemStack;
    12. import org.bukkit.plugin.java.JavaPlugin;
    13.  
    14. public class main extends JavaPlugin {
    15.  
    16. public void onEnable() {
    17. try{
    18. saveConfig();
    19. setupConfig(getConfig());
    20. saveConfig();
    21. } catch (Exception e) {
    22. e.printStackTrace();
    23. }
    24.  
    25. }
    26.  
    27. @SuppressWarnings("deprecation")
    28. public boolean onCommand(CommandSender sender, Command command, String commandLabel, String[] args) {
    29.  
    30. if(commandLabel.equalsIgnoreCase("kitpvp")){
    31. if(sender instanceof Player){
    32. Player player = (Player) sender;
    33.  
    34. if(args.length == 0) {
    35. String[] classes = getConfig().getString("Kit.Names")
    36. .split(",");
    37. for (String s : classes) {
    38. if(s != null) {
    39. player.sendMessage("[" + ChatColor.AQUA + s + ChatColor.WHITE + "] " + ChatColor.GRAY + ": " + ChatColor.DARK_GRAY + "Adds you to the " + s + " Class!");
    40.  
    41. }
    42. }
    43. } else {
    44.  
    45. for(String s : getConfig().getConfigurationSection("Kits")
    46. .getKeys(false)) {
    47. if(args[0].equalsIgnoreCase("s")) {
    48. player.getInventory().clear();
    49. try {
    50. String Items = getConfig().getString(
    51. "Kits." + s + ".Items");
    52.  
    53. String[] indiItems = Items.split(",");
    54.  
    55. for(String s1 : indiItems){
    56. String[] itemAmounts = s1.split("-");
    57. ItemStack item = new ItemStack(
    58. Integer.valueOf(itemAmounts[0]),
    59. Integer.valueOf(itemAmounts[1]));
    60.  
    61. player.getInventory().addItem(item);
    62. }
    63. player.updateInventory();
    64. } catch (Exception e) {
    65. e.printStackTrace();
    66.  
    67. }
    68. }
    69. }
    70. }
    71.  
    72.  
    73. }
    74. }
    75.  
    76. return false;
    77.  
    78. }
    79.  
    80. private void setupConfig(FileConfiguration config) throws IOException {
    81. if (!new File(getDataFolder(), "RESET.FILE").exists()) {
    82. config.set("Kits.Mage.Items", "50-64,278-1,277-4");
    83. config.set("Kits.Archer.Items", "64-64,1-1,5-4");
    84. config.set("Kits.Names", "Mage,Archer");
    85.  
    86. new File(getDataFolder(), "RESET.FILE").createNewFile();
    87. }
    88.  
    89. }
    90.  
    91.  
    92.  
    93. }
    94.  




    I hope you guys can help me whit this because i want to use it for my own server.
     
  2. Offline

    chikenlitle99



    The error is ".split(",");"

    Try ".split("/");"
     
  3. Offline

    martinke123


    Still getting this error:

    Code:
    30.05 09:20:22 [Server] INFO ... 13 more
    30.05 09:20:22 [Server] INFO at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[craftbukkit-beta2-os.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    30.05 09:20:22 [Server] INFO at me.martinke123.main.main.onCommand(main.java:36) ~[?:?]
    30.05 09:20:22 [Server] INFO Caused by: java.lang.NullPointerException
    30.05 09:20:22 [Server] INFO at net.minecraft.server.v1_7_R1.ThreadServerApplication.run(SourceFile:617) [craftbukkit-beta2-os.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    30.05 09:20:22 [Server] INFO at net.minecraft.server.v1_7_R1.MinecraftServer.run(MinecraftServer.java:457) [craftbukkit-beta2-os.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    30.05 09:20:22 [Server] INFO at net.minecraft.server.v1_7_R1.MinecraftServer.t(MinecraftServer.java:545) [craftbukkit-beta2-os.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    30.05 09:20:22 [Server] INFO at net.minecraft.server.v1_7_R1.DedicatedServer.u(DedicatedServer.java:250) [craftbukkit-beta2-os.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    30.05 09:20:22 [Server] INFO at net.minecraft.server.v1_7_R1.MinecraftServer.u(MinecraftServer.java:655) [craftbukkit-beta2-os.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    30.05 09:20:22 [Server] INFO at net.minecraft.server.v1_7_R1.ServerConnection.c(SourceFile:134) [craftbukkit-beta2-os.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    30.05 09:20:22 [Server] INFO at net.minecraft.server.v1_7_R1.NetworkManager.a(NetworkManager.java:146) [craftbukkit-beta2-os.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    30.05 09:20:22 [Server] INFO at net.minecraft.server.v1_7_R1.PacketPlayInChat.handle(PacketPlayInChat.java:47) [craftbukkit-beta2-os.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    30.05 09:20:22 [Server] INFO at net.minecraft.server.v1_7_R1.PacketPlayInChat.a(PacketPlayInChat.java:28) [craftbukkit-beta2-os.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    30.05 09:20:22 [Server] INFO at net.minecraft.server.v1_7_R1.PlayerConnection.a(PlayerConnection.java:814) [craftbukkit-beta2-os.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    30.05 09:20:22 [Server] INFO at net.minecraft.server.v1_7_R1.PlayerConnection.handleCommand(PlayerConnection.java:952) [craftbukkit-beta2-os.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    30.05 09:20:22 [Server] INFO at org.bukkit.craftbukkit.v1_7_R1.CraftServer.dispatchCommand(CraftServer.java:683) ~[craftbukkit-beta2-os.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    30.05 09:20:22 [Server] INFO at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:175) ~[craftbukkit-beta2-os.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    30.05 09:20:22 [Server] INFO at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[craftbukkit-beta2-os.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    30.05 09:20:22 [Server] INFO org.bukkit.command.CommandException: Unhandled exception executing command 'kitpvp' in plugin KitPvp v0.1
    30.05 09:20:22 [Server] ERROR null
     
  4. Offline

    Monkey_Swag

    martinke123 show line 36 of your main class please.
     
  5. Offline

    Plo124

    martinke123
    This is because the line in the config is null, does not contain a , in the first place, or is empty.
    Please post the config.yml you are using. (put it in a spoiler if its big)
     
  6. Offline

    martinke123


    This is line 36: .split("/");


    It isn't that bigg:

    Code:
    Kits:
      Mage:
        Items: 50-64,278-1,277-4
      Archer:
        Items: 64-64,1-1,5-4
      Names: Mage,Archer
    
    Somthing is wrong in this but i don't know what.

    Code:java
    1. if(args.length == 0) {
    2. String[] classes = getConfig().getString("Kit.Names")
    3. .split("/");
    4. for (String s : classes) {
    5. if(s != null) {
    6. player.sendMessage("[" + ChatColor.AQUA + s + ChatColor.WHITE + "] " + ChatColor.GRAY + ": " + ChatColor.DARK_GRAY + "Adds you to the " + s + " Class!");
    7.  


    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jul 1, 2016
  7. Offline

    Plo124

    martinke123
    Its because now your splitting with the / not , character,
    Also in your config.yml the top bit is Kits but its just Kit in your code.
     
Thread Status:
Not open for further replies.

Share This Page