Solved Command write to IntegerList

Discussion in 'Plugin Development' started by Unscrewed, Dec 21, 2012.

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

    Unscrewed

    Hello everyone,

    I am trying to make something that allows me to type in a command, in this case: "add list <integer>", and then take the integer, add it to the IntegerList in the configuration file and save it.
    I know it is better to write to let's say HashMaps instead of directly to the config, but this is just for testing purposes.

    Code:java
    1. if (arg[0].equalsIgnoreCase("add"))
    2. {
    3. if (arg.length > 1)
    4. {
    5. if(arg[1].equalsIgnoreCase("list"))
    6. {
    7. if (arg.length > 2)
    8. {
    9. try
    10. {
    11. this.getConfig().getIntegerList("List").add(Integer.parseInt(arg[2]));
    12. player.sendMessage(PrefixS() + ChatColor.RED + "Block ID: '" + Integer.parseInt(arg[2]) + "' added to the list.");
    13. this.saveConfig();
    14. this.reloadConfig();
    15. }
    16. {
    17. player.sendMessage(PrefixS() + ChatColor.RED + "The value you specified was incorrect.");
    18. }
    19. return true;
    20. }
    21. else
    22. {
    23. player.sendMessage(ChatColor.RED + "Too few arguments.");
    24. return true;
    25. }
    26. }
    27. else
    28. {
    29. player.sendMessage(ChatColor.RED + "You do not have permission to use this command, or this command does not exist.");
    30. }
    31. else
    32. {
    33. player.sendMessage(ChatColor.RED + "You do not have permission to use this command, or this command does not exist.");
    34. return true;
    35. }
    36. }
    37. else
    38. {
    39. player.sendMessage(ChatColor.RED + "Too few arguments.");
    40. return true;
    41. }
    42. }


    Thanks in advance - been stuck on this issue for quite a few hours and people over at #BukkitDev won't respond.
    Unscrewed

    Edit: [syntax~java] Unformatted my code, hope you can still read it.
    Edit 2: There are no errors, it displays the message: "Block ID: 'x' added to the list" too.
     
  2. Offline

    fireblast709

    Code:java
    1. List<Integer> list = this.getConfig().getIntegerList("List");
    2. list.add(Integer.parseInt(arg[2]));
    3. this.getConfig().set("List", list);
    4. this.saveConfig();
    getIntegerList("path") returns a copy of the config's list (as do all get*List methods do)
     
    Unscrewed likes this.
  3. Offline

    Unscrewed

    Oh, wow. I did not know that.
    Thanks a lot!
     
Thread Status:
Not open for further replies.

Share This Page