Commands not functioning

Discussion in 'Plugin Development' started by aidan573, Dec 15, 2013.

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

    aidan573

    Hey, I'm trying to make a Cheating plugin and when the player tries to use a command (/CheaterCheater) all I get is
    Code:
    [23:49:04 INFO]: Client> [23:49:04] [Client thread/INFO]: [CHAT] §cAn internal error occurred while attempting to perform this command
    
    Here is my code....
    Code:java
    1. package uk.co.infinityflame;
    2.  
    3. import java.io.File;
    4.  
    5. import org.bukkit.ChatColor;
    6. import org.bukkit.command.Command;
    7. import org.bukkit.command.CommandSender;
    8. import org.bukkit.configuration.file.FileConfiguration;
    9. import org.bukkit.configuration.file.YamlConfiguration;
    10. import org.bukkit.entity.Player;
    11. import org.bukkit.plugin.java.JavaPlugin;
    12.  
    13. public class CHEAT extends JavaPlugin {
    14.  
    15. @Override
    16. public void onEnable()
    17. {
    18. cfg = getConfig();
    19. getLogger().info("Cheat Codes Enabled!");
    20. }
    21.  
    22. @Override
    23. public void onDisable()
    24. {
    25. getLogger().info("Cheat Codes Disabled!");
    26. }
    27.  
    28. private File file = new File("plugins/CheatCodes", "config.yml");
    29. private FileConfiguration cfg = YamlConfiguration.loadConfiguration(file);
    30.  
    31. public boolean onCommand (CommandSender sender, Command command, String commandLabel, String[] args)
    32. {
    33.  
    34. if (!(sender instanceof Player))
    35. {
    36. sender.sendMessage("Why Console, do you want to cheat?");
    37. return true;
    38. } else {
    39.  
    40. Player player = (Player) sender;
    41.  
    42. if (commandLabel.equalsIgnoreCase("CheaterCheater"))
    43. {
    44. if (player.hasPermission("cc.cheat"))
    45. {
    46.  
    47. if(!(cfg.contains("cheatercheater." + player.getPlayer().getName())))
    48. {
    49. cfg.set("cheatercheater." + player.getName(), true);
    50. saveConfig();
    51. }
    52.  
    53. if (args.length == 0)
    54. {
    55.  
    56. player.sendMessage(ChatColor.GREEN + "Cheater Cheater 'FireEater'! ");
    57. return true;
    58. }

    And here is the stuff
    Code:
    2013-12-15 23:49:57 [INFO] aidan573 issued server command: /cheaterCheater
    2013-12-15 23:49:57 [SEVERE] null
    org.bukkit.command.CommandException: Unhandled exception executing command 'cheatercheater' in plugin CheatCodes v1.0.0
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46)
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:192)
        at org.bukkit.craftbukkit.v1_6_R3.CraftServer.dispatchCommand(CraftServer.java:532)
        at net.minecraft.server.v1_6_R3.PlayerConnection.handleCommand(PlayerConnection.java:986)
        at net.minecraft.server.v1_6_R3.PlayerConnection.chat(PlayerConnection.java:897)
        at net.minecraft.server.v1_6_R3.PlayerConnection.a(PlayerConnection.java:838)
        at net.minecraft.server.v1_6_R3.Packet3Chat.handle(Packet3Chat.java:47)
        at org.spigotmc.netty.NettyNetworkManager.b(NettyNetworkManager.java:237)
        at net.minecraft.server.v1_6_R3.PlayerConnection.e(PlayerConnection.java:117)
        at net.minecraft.server.v1_6_R3.ServerConnection.b(SourceFile:37)
        at org.spigotmc.netty.NettyServerConnection.b(NettyServerConnection.java:131)
        at net.minecraft.server.v1_6_R3.MinecraftServer.t(MinecraftServer.java:604)
        at net.minecraft.server.v1_6_R3.DedicatedServer.t(DedicatedServer.java:240)
        at net.minecraft.server.v1_6_R3.MinecraftServer.s(MinecraftServer.java:493)
        at net.minecraft.server.v1_6_R3.MinecraftServer.run(MinecraftServer.java:425)
        at net.minecraft.server.v1_6_R3.ThreadServerApplication.run(SourceFile:583)
    Caused by: java.lang.ArrayIndexOutOfBoundsException: 0
        at uk.co.infinityflame.CHEAT.onCommand(CHEAT.java:50)
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44)
        ... 15 more
    I am In despair and have no idea what could be null...
     
  2. Offline

    pope_on_dope

    you're getting an error on saveConfig(); do some debugging
     
  3. Offline

    1Rogue

    Please get an up-to-date error in accordance to your code. Your current error doesn't match up with the line numbers.
     
  4. Offline

    aidan573

    Whithout or With saveConfig(); the error does not change

    IDon't think that I is the wrong error......... but just incase here is another.

    Code:java
    1. package uk.co.infinityflame;
    2.  
    3. import java.io.File;
    4.  
    5. import org.bukkit.ChatColor;
    6. import org.bukkit.command.Command;
    7. import org.bukkit.command.CommandSender;
    8. import org.bukkit.configuration.file.FileConfiguration;
    9. import org.bukkit.configuration.file.YamlConfiguration;
    10. import org.bukkit.entity.Player;
    11. import org.bukkit.plugin.java.JavaPlugin;
    12.  
    13. public class CHEAT extends JavaPlugin {
    14.  
    15. @Override
    16. public void onEnable()
    17. {
    18. cfg = getConfig();
    19. getLogger().info("Cheat Codes Enabled!");
    20. }
    21.  
    22. @Override
    23. public void onDisable()
    24. {
    25. getLogger().info("Cheat Codes Disabled!");
    26. }
    27.  
    28. private File file = new File("plugins/CheatCodes", "config.yml");
    29. private FileConfiguration cfg = YamlConfiguration.loadConfiguration(file);
    30.  
    31.  
    32.  
    33.  
    34. public boolean onCommand (CommandSender sender, Command command, String commandLabel, String[] args)
    35. {
    36.  
    37. if (!(sender instanceof Player))
    38. {
    39. sender.sendMessage("Why Console, do you want to cheat?");
    40. return true;
    41. } else {
    42.  
    43. Player player = (Player) sender;
    44. if (commandLabel.equalsIgnoreCase("CheaterCheater"))
    45. {
    46. if (player.hasPermission("cc.cheat"))
    47. {
    48.  
    49. if(!(cfg.contains("cheatercheater." + player.getPlayer().getName())))
    50. {
    51. cfg.set("cheatercheater." + player.getName(), true);
    52. saveConfig();
    53. }
    54.  
    55. if (args.length == 0)
    56. {
    57.  
    58. player.sendMessage(ChatColor.GREEN + "Cheater Cheater FireEater! ");
    59. return true;
    60. }


    Error
    Code:
    2013-12-16 00:20:42 [INFO] aidan573 issued server command: /cheatercheater
    2013-12-16 00:20:42 [SEVERE] null
    org.bukkit.command.CommandException: Unhandled exception executing command 'cheatercheater' in plugin CheatCodes v1.0.0
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46)
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:192)
        at org.bukkit.craftbukkit.v1_6_R3.CraftServer.dispatchCommand(CraftServer.java:532)
        at net.minecraft.server.v1_6_R3.PlayerConnection.handleCommand(PlayerConnection.java:986)
        at net.minecraft.server.v1_6_R3.PlayerConnection.chat(PlayerConnection.java:897)
        at net.minecraft.server.v1_6_R3.PlayerConnection.a(PlayerConnection.java:838)
        at net.minecraft.server.v1_6_R3.Packet3Chat.handle(Packet3Chat.java:47)
        at org.spigotmc.netty.NettyNetworkManager.b(NettyNetworkManager.java:237)
        at net.minecraft.server.v1_6_R3.PlayerConnection.e(PlayerConnection.java:117)
        at net.minecraft.server.v1_6_R3.ServerConnection.b(SourceFile:37)
        at org.spigotmc.netty.NettyServerConnection.b(NettyServerConnection.java:131)
        at net.minecraft.server.v1_6_R3.MinecraftServer.t(MinecraftServer.java:604)
        at net.minecraft.server.v1_6_R3.DedicatedServer.t(DedicatedServer.java:240)
        at net.minecraft.server.v1_6_R3.MinecraftServer.s(MinecraftServer.java:493)
        at net.minecraft.server.v1_6_R3.MinecraftServer.run(MinecraftServer.java:425)
        at net.minecraft.server.v1_6_R3.ThreadServerApplication.run(SourceFile:583)
    Caused by: java.lang.ArrayIndexOutOfBoundsException: 0
        at uk.co.infinityflame.CHEAT.onCommand(CHEAT.java:50)
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44)
        ... 15 more
    2013-12-16 00:20:46 [WARNING] [WorldEdit] No compatible nms block class found.
    2013-12-16 00:22:19 [INFO] CONSOLE: Stopping the server..[m
    2013-12-16 00:22:19 [INFO] Stopping server
    2013-12-16 00:22:19 [INFO] [EssentialsSpawn] Disabling EssentialsSpawn v2.11.1
    2013-12-16 00:22:19 [INFO] [EssentialsChat] Disabling EssentialsChat v2.11.1
    2013-12-16 00:22:19 [INFO] [Essentials] Disabling Essentials v2.11.1
    2013-12-16 00:22:19 [INFO] [CheatCodes] Disabling CheatCodes v1.0.0
    2013-12-16 00:22:19 [INFO] [CheatCodes] Cheat Codes Disabled!
    2013-12-16 00:22:19 [INFO] [WorldGuard] Disabling WorldGuard v5.7.5
    2013-12-16 00:22:19 [INFO] [WorldEdit] Disabling WorldEdit v5.5.6
    2013-12-16 00:22:19 [INFO] Saving players
    2013-12-16 00:22:19 [INFO] [0;33;1maidan573 left the game.[m
    2013-12-16 00:22:19 [INFO] Saving worlds
    2013-12-16 00:22:19 [INFO] Saving chunks for level 'world'/Overworld
    
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 5, 2016
Thread Status:
Not open for further replies.

Share This Page