Config.yml

Discussion in 'Plugin Development' started by Wazup93, Oct 7, 2013.

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

    Wazup93

    Hi all again ..
    I was updating my OneInTheChamper plugin and then I thought that I can get my own experience and can make my own way in coding so .. All of this is about the arena creating .. I mean that you can make ANY Arena just when typing its name But I got an error .. The code SHOULD be like this in config.yml
    <ArenaName>:
    SetLobby: <Loc>
    SetWin: <Loc>
    SetLose: <Loc>
    <Future>: <Add Cash To Winner> (Not Needed Now)

    So this is my code ..
    Code:java
    1. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
    2. Player player = (Player) sender;
    3. String playerName = player.getName();
    4.  
    5. if(sender instanceof Player) {
    6. if(commandLabel.equalsIgnoreCase("OITC-CreateArena")) {
    7. if(args.length == 0) {
    8. player.sendMessage(ChatColor.BLACK + "[" + ChatColor.AQUA + "OneInTheChamper" + ChatColor.BLACK + "] " + ChatColor.RED + "Usage: [ /OITC-CreateArena <ArenaID> ]");
    9. }
    10. if(args.length == 1) {
    11. if(player.hasPermission("OneInTheChamper.*")) {
    12. int x = getConfig().getInt(args[1] + ".SetLobby" + ".x"), y = getConfig().getInt(args[1] + ".SetLobby" + ".y"), z = getConfig().getInt(args[1] + ".SetLobby" + ".z");
    13. int x1 = getConfig().getInt(args[1] + ".SetWin" + ".x"), y1 = getConfig().getInt(args[1] + ".SetWin" + ".y"), z1 = getConfig().getInt(args[1] + ".SetWin" + ".z");
    14. int x2 = getConfig().getInt(args[1] + ".SetLose" + ".x"), y2 = getConfig().getInt(args[1] + ".SetLose" + ".y"), z2 = getConfig().getInt(args[1] + ".SetLose" + ".z");
    15. getConfig().set(args[1] + ".SetLobby", x + y + z);
    16. getConfig().set(args[1] + ".SetWin", x1 + y1 + z1);
    17. getConfig().set(args[1] + ".SetLose", x2 + y2 + z2);
    18. saveConfig();
    19. player.sendMessage(ChatColor.BLACK + "[" + ChatColor.AQUA + "OneInTheChamper" + ChatColor.BLACK + "] " + ChatColor.GRAY + "Created an Arena with the name of: " + ChatColor.AQUA + args[1] + ChatColor.GRAY + " !!");
    20. }
    21. }
    22. }
    23. }
    24. if(sender instanceof Player) {
    25. if(commandLabel.equalsIgnoreCase("OITC-SetLobby")) {
    26. if(args.length == 0) {
    27. player.sendMessage(ChatColor.BLACK + "[" + ChatColor.AQUA + "OneInTheChamper" + ChatColor.BLACK + "] " + ChatColor.RED + "Usage: [ /OITC-SetLobby <ArenaID> ]");
    28. }
    29. if(args.length == 1) {
    30. if(player.hasPermission("OneInTheChamper.*")) {
    31. int x = getConfig().getInt(args[1] + ".SetLobby" + ".x"), y = getConfig().getInt(args[1] + ".SetLobby" + ".y"), z = getConfig().getInt(args[1] + ".SetLobby" + ".z");
    32. getConfig().set(args[1] + ".SetLobby" + ".x", x);
    33. getConfig().set(args[1] + ".SetLobby" + ".y", y);
    34. getConfig().set(args[1] + ".SetLobby" + ".z", z);
    35. saveConfig();
    36. player.sendMessage(ChatColor.BLACK + "[" + ChatColor.AQUA + "OneInTheChamper" + ChatColor.BLACK + "] " + ChatColor.GRAY + "Sat the Lobby of Arena: " + ChatColor.AQUA + args[1] + ChatColor.GRAY + " !!");
    37. }
    38. }
    39. }
    40. }
    41. if(sender instanceof Player) {
    42. if(commandLabel.equalsIgnoreCase("OITC-SetWin")) {
    43. if(args.length == 0) {
    44. player.sendMessage(ChatColor.BLACK + "[" + ChatColor.AQUA + "OneInTheChamper" + ChatColor.BLACK + "] " + ChatColor.RED + "Usage: [ /OITC-SetWin <ArenaID> ]");
    45. }
    46. if(args.length == 1) {
    47. if(player.hasPermission("OneInTheChamper.*")) {
    48. int x1 = getConfig().getInt(args[1] + ".SetWin" + ".x"), y1 = getConfig().getInt(args[1] + ".SetWin" + ".y"), z1 = getConfig().getInt(args[1] + ".SetWin" + ".z");
    49. getConfig().set(args[1] + ".SetWin" + ".x", x1);
    50. getConfig().set(args[1] + ".SetWin" + ".y", y1);
    51. getConfig().set(args[1] + ".SetWin" + ".z", z1);
    52. saveConfig();
    53. player.sendMessage(ChatColor.BLACK + "[" + ChatColor.AQUA + "OneInTheChamper" + ChatColor.BLACK + "] " + ChatColor.GRAY + "Sat the Win of Arena: " + ChatColor.AQUA + args[1] + ChatColor.GRAY + " !!");
    54. }
    55. }
    56. }
    57. }
    58. if(sender instanceof Player) {
    59. if(commandLabel.equalsIgnoreCase("OITC-SetLose")) {
    60. if(args.length == 0) {
    61. player.sendMessage(ChatColor.BLACK + "[" + ChatColor.AQUA + "OneInTheChamper" + ChatColor.BLACK + "] " + ChatColor.RED + "Usage: [ /OITC-SetLose <ArenaID> ]");
    62. }
    63. if(args.length == 1) {
    64. if(player.hasPermission("OneInTheChamper.*")) {
    65. int x2 = getConfig().getInt(args[1] + ".SetLose" + ".x"), y2 = getConfig().getInt(args[1] + ".SetLose" + ".y"), z2 = getConfig().getInt(args[1] + ".SetLose" + ".z");
    66. getConfig().set(args[1] + ".SetLose" + ".x", x2);
    67. getConfig().set(args[1] + ".SetLose" + ".y", y2);
    68. getConfig().set(args[1] + ".SetLose" + ".z", z2);
    69. saveConfig();
    70. player.sendMessage(ChatColor.BLACK + "[" + ChatColor.AQUA + "OneInTheChamper" + ChatColor.BLACK + "] " + ChatColor.GRAY + "Sat the Lose of Arena: " + ChatColor.AQUA + args[1] + ChatColor.GRAY + " !!");
    71. }
    72. }
    73. }
    74. }

    Now the error is ...
    Code:
    10:18:34 PM [SEVERE] null
    10:18:34 PM org.bukkit.command.CommandException: Unhandled exception executing command 'oitc-createarena' in plugin OneInTheChamper v1.0
    10:18:34 PM at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46)
    10:18:34 PM at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:192)
    10:18:34 PM at org.bukkit.craftbukkit.v1_6_R3.CraftServer.dispatchCommand(CraftServer.java:523)
    10:18:34 PM at net.minecraft.server.v1_6_R3.PlayerConnection.handleCommand(PlayerConnection.java:959)
    10:18:34 PM at net.minecraft.server.v1_6_R3.PlayerConnection.chat(PlayerConnection.java:877)
    10:18:34 PM at net.minecraft.server.v1_6_R3.PlayerConnection.a(PlayerConnection.java:834)
    10:18:34 PM at net.minecraft.server.v1_6_R3.Packet3Chat.handle(SourceFile:49)
    10:18:34 PM at net.minecraft.server.v1_6_R3.NetworkManager.b(NetworkManager.java:296)
    10:18:34 PM at net.minecraft.server.v1_6_R3.PlayerConnection.e(PlayerConnection.java:116)
    10:18:34 PM at net.minecraft.server.v1_6_R3.ServerConnection.b(SourceFile:37)
    10:18:34 PM at net.minecraft.server.v1_6_R3.DedicatedServerConnection.b(SourceFile:30)
    10:18:34 PM at net.minecraft.server.v1_6_R3.MinecraftServer.t(MinecraftServer.java:592)
    10:18:34 PM at net.minecraft.server.v1_6_R3.DedicatedServer.t(DedicatedServer.java:227)
    10:18:34 PM at net.minecraft.server.v1_6_R3.MinecraftServer.s(MinecraftServer.java:488)
    10:18:34 PM at net.minecraft.server.v1_6_R3.MinecraftServer.run(MinecraftServer.java:421)
    10:18:34 PM at net.minecraft.server.v1_6_R3.ThreadServerApplication.run(SourceFile:583)
    10:18:34 PM Caused by: java.lang.ArrayIndexOutOfBoundsException: 1
    10:18:34 PM at me.Wazup91.OneInTheChamper.OneInTheChamper.onCommand(OneInTheChamper.java:69)
    10:18:34 PM at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44)
    Error line is :
    Code:
                          int x = getConfig().getInt(args[1] + ".SetLobby" + ".x"), y = getConfig().getInt(args[1] + ".SetLobby" + ".y"), z = getConfig().getInt(args[1] + ".SetLobby" + ".z");
    
    And I don't really know whats the error !
    I'll be very thankful for any Success helping :)
    ThezKiller

    Bro .. if I knew that so why should I ask ? and I know that args 1 is the second part of the command .. if I was wrong so please correct my code by the way I want if you know how and explain more please ?

    bump

    Maybe you mean this ? ..
    Code:java
    1. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
    2. Player player = (Player) sender;
    3. String playerName = player.getName();
    4.  
    5. if(sender instanceof Player) {
    6. if(commandLabel.equalsIgnoreCase("OITC-CreateArena")) {
    7. if(args.length == 0) {
    8. player.sendMessage(ChatColor.BLACK + "[" + ChatColor.AQUA + "OneInTheChamper" + ChatColor.BLACK + "] " + ChatColor.RED + "Usage: [ /OITC-CreateArena <ArenaID> ]");
    9. }
    10. if(args.length == 1) {
    11. if(player.hasPermission("OneInTheChamper.*")) {
    12. int x = getConfig().getInt(args[1] + ".SetLobby" + ".x"), y = getConfig().getInt(args[1] + ".SetLobby" + ".y"), z = getConfig().getInt(args[1] + ".SetLobby" + ".z");
    13. int x1 = getConfig().getInt(args[1] + ".SetWin" + ".x"), y1 = getConfig().getInt(args[1] + ".SetWin" + ".y"), z1 = getConfig().getInt(args[1] + ".SetWin" + ".z");
    14. int x2 = getConfig().getInt(args[1] + ".SetLose" + ".x"), y2 = getConfig().getInt(args[1] + ".SetLose" + ".y"), z2 = getConfig().getInt(args[1] + ".SetLose" + ".z");
    15. getConfig().set(args[1] + ".SetLobby", x + y + z);
    16. getConfig().set(args[1] + ".SetWin", x1 + y1 + z1);
    17. getConfig().set(args[1] + ".SetLose", x2 + y2 + z2);
    18. saveConfig();
    19. player.sendMessage(ChatColor.BLACK + "[" + ChatColor.AQUA + "OneInTheChamper" + ChatColor.BLACK + "] " + ChatColor.GRAY + "Created an Arena with the name of: " + ChatColor.AQUA + args[1] + ChatColor.GRAY + " !!");
    20. }
    21. }
    22. }
    23. }
    24. if(sender instanceof Player) {
    25. if(commandLabel.equalsIgnoreCase("OITC-SetLobby")) {
    26. if(args.length == 0) {
    27. player.sendMessage(ChatColor.BLACK + "[" + ChatColor.AQUA + "OneInTheChamper" + ChatColor.BLACK + "] " + ChatColor.RED + "Usage: [ /OITC-SetLobby <ArenaID> ]");
    28. }
    29. if(args.length == 1) {
    30. if(player.hasPermission("OneInTheChamper.*")) {
    31. int x = getConfig().getInt(args[1] + ".SetLobby" + ".x"), y = getConfig().getInt(args[1] + ".SetLobby" + ".y"), z = getConfig().getInt(args[1] + ".SetLobby" + ".z");
    32. getConfig().set(args[1] + ".SetLobby" + ".x", x);
    33. getConfig().set(args[1] + ".SetLobby" + ".y", y);
    34. getConfig().set(args[1] + ".SetLobby" + ".z", z);
    35. saveConfig();
    36. player.sendMessage(ChatColor.BLACK + "[" + ChatColor.AQUA + "OneInTheChamper" + ChatColor.BLACK + "] " + ChatColor.GRAY + "Sat the Lobby of Arena: " + ChatColor.AQUA + args[1] + ChatColor.GRAY + " !!");
    37. }
    38. }
    39. }
    40. }
    41. if(sender instanceof Player) {
    42. if(commandLabel.equalsIgnoreCase("OITC-SetWin")) {
    43. if(args.length == 0) {
    44. player.sendMessage(ChatColor.BLACK + "[" + ChatColor.AQUA + "OneInTheChamper" + ChatColor.BLACK + "] " + ChatColor.RED + "Usage: [ /OITC-SetWin <ArenaID> ]");
    45. }
    46. if(args.length == 1) {
    47. if(player.hasPermission("OneInTheChamper.*")) {
    48. int x1 = getConfig().getInt(args[1] + ".SetWin" + ".x"), y1 = getConfig().getInt(args[1] + ".SetWin" + ".y"), z1 = getConfig().getInt(args[1] + ".SetWin" + ".z");
    49. getConfig().set(args[1] + ".SetWin" + ".x", x1);
    50. getConfig().set(args[1] + ".SetWin" + ".y", y1);
    51. getConfig().set(args[1] + ".SetWin" + ".z", z1);
    52. saveConfig();
    53. player.sendMessage(ChatColor.BLACK + "[" + ChatColor.AQUA + "OneInTheChamper" + ChatColor.BLACK + "] " + ChatColor.GRAY + "Sat the Win of Arena: " + ChatColor.AQUA + args[1] + ChatColor.GRAY + " !!");
    54. }
    55. }
    56. }
    57. }
    58. if(sender instanceof Player) {
    59. if(commandLabel.equalsIgnoreCase("OITC-SetLose")) {
    60. if(args.length == 0) {
    61. player.sendMessage(ChatColor.BLACK + "[" + ChatColor.AQUA + "OneInTheChamper" + ChatColor.BLACK + "] " + ChatColor.RED + "Usage: [ /OITC-SetLose <ArenaID> ]");
    62. }
    63. if(args.length == 1) {
    64. if(player.hasPermission("OneInTheChamper.*")) {
    65. int x2 = getConfig().getInt(args[1] + ".SetLose" + ".x"), y2 = getConfig().getInt(args[1] + ".SetLose" + ".y"), z2 = getConfig().getInt(args[1] + ".SetLose" + ".z");
    66. getConfig().set(args[1] + ".SetLose" + ".x", x2);
    67. getConfig().set(args[1] + ".SetLose" + ".y", y2);
    68. getConfig().set(args[1] + ".SetLose" + ".z", z2);
    69. saveConfig();
    70. player.sendMessage(ChatColor.BLACK + "[" + ChatColor.AQUA + "OneInTheChamper" + ChatColor.BLACK + "] " + ChatColor.GRAY + "Sat the Lose of Arena: " + ChatColor.AQUA + args[1] + ChatColor.GRAY + " !!");
    71. }
    72. }
    73. }
    74. }

    I got args ... But I don't know a lot in it but I just got args and when I get args 1 it should get the name .. but it doesn't .. please explain ..

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 4, 2016
  2. Offline

    BaranCODE

    Oh, I think I see the mistake you did. You probably thought args[1] meant the first argument, right?
    args[0] would give you the first argument, args[1] would give you the second, because that's how computers work. So when you do if(args.length == 1) that argument will be in args[0]
    Was that your mistake? If it is, then let me assure you, everybody has been there :D
     
  3. Wazup93 what you're asking here is a common java newbie question, and this forums topic is normally for bukkit api related questions. Searching for <Edit by Moderator: Redacted bit url>

    Anyways: arrays in java are 0 based, meaning the index of the first element in the array is 0. So if the array.length is 1, the index for the element is 0, If array.length is 2, The both elements are at index 0 and index 1, and so on. So when array.length == 1 is true, then array[1] will always throw an ArrayIndexOutOfBoundsException, as there is no such element with index 1.

    PS: and again 5 mins. of support time wasted.
     
    Last edited by a moderator: Feb 15, 2017
  4. Offline

    Wazup93

    [quote uid=90837291 name="BaranCODE" post=1894056]Oh, I think I see the mistake you did. You probably thought args[1] meant the first argument, right?
    args[0] would give you the first argument, args[1] would give you the second, because that's how computers work. So when you do if(args.length == 1) that argument will be in args[0]
    Was that your mistake? If it is, then let me assure you, everybody has been there :D[/quote]
    For sure lemme know if I just knew what you said .. so when I write args [0] it gives me the second part of command ?
    ??? I'm sooo confused %^%£^$£^£&%$%£

    [quote uid=90653230 name="hapm" post=1894065]Wazup93 what you're asking here is a common java newbie question, and this forums topic is normally for bukkit api related questions. Searching for <Edit by Moderator: Redacted bit url>

    Anyways: arrays in java are 0 based, meaning the index of the first element in the array is 0. So if the array.length is 1, the index for the element is 0, If array.length is 2, The both elements are at index 0 and index 1, and so on. So when array.length == 1 is true, then array[1] will always throw an ArrayIndexOutOfBoundsException, as there is no such element with index 1.

    PS: and again 5 mins. of support time wasted.[/quote]
    About that .. i'm arab .. so maybe its some hard for me to understand this ..
    Whatever thanks for helping ...

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Feb 15, 2017
  5. Offline

    BaranCODE

    Let me put it like this:

    Commands are used like this:
    /command <argument 1> <argument 2> <argument 3>
    Ok?

    So, in the code, doing args[0] will give you argument 1, and so on. Get it?
     
  6. Offline

    Tehmaker

    /command args[0] args[1]
    /command buy 1

    if that makes it any easier

    Replace your args[1], with args[0]
     
  7. Offline

    Wazup93

    Oh Thx !!!!
     
Thread Status:
Not open for further replies.

Share This Page