Finding something in a Config.yml

Discussion in 'Plugin Development' started by MrGermanrain, Aug 2, 2014.

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

    MrGermanrain

    So I just started making a Teams plugin when I ran into a brain-fart problem. How do I find a certain player's Team ?

    Code:java
    1. package me.mrgermanrain.main;
    2.  
    3. import org.bukkit.ChatColor;
    4. import org.bukkit.command.Command;
    5. import org.bukkit.command.CommandSender;
    6. import org.bukkit.entity.Player;
    7. import org.bukkit.plugin.java.JavaPlugin;
    8.  
    9. public class bbMain extends JavaPlugin
    10. {
    11. @Override
    12. public void onEnable()
    13. {
    14. getConfig().options().copyDefaults(true);
    15. saveConfig();
    16. }
    17.  
    18. @Override
    19. public void onDisable()
    20. {
    21.  
    22. }
    23.  
    24. public boolean onCommand(Command cmd, CommandSender s, String label, String[] args)
    25. {
    26. Player p = (Player) s;
    27. if (cmd.getLabel().equalsIgnoreCase("t") || cmd.getLabel().equalsIgnoreCase("team"))
    28. {
    29.  
    30. //Creating a Team
    31.  
    32. if (args[0].equalsIgnoreCase("create") && p.hasPermission("t.create"))
    33. {
    34. if (args.length == 2)
    35. {
    36. if(!(this.getConfig().getList("Teams").contains(args[1])))
    37. {
    38. this.getConfig().set("Teams", getConfig().getStringList("Teams").add(args[1]));
    39.  
    40. this.getConfig().set("Teams." + args[1], getConfig().getStringList("Teams." + args[1]).add("Leader"));
    41. this.getConfig().set("Teams." + args[1], getConfig().getStringList("Teams." + args[1]).add("Admin"));
    42. this.getConfig().set("Teams." + args[1], getConfig().getStringList("Teams." + args[1]).add("Mod"));
    43. this.getConfig().set("Teams." + args[1], getConfig().getStringList("Teams." + args[1]).add("Member"));
    44.  
    45. this.getConfig().set("Teams." + args[0] + ".Leader", getConfig().getStringList("Teams." + args[0] + ".Leader").add(p.getName()));
    46. this.saveConfig();
    47.  
    48. p.sendMessage(ChatColor.GREEN + "You have successfully created Team " + args[1] + "!");
    49. }
    50. else
    51. {
    52. p.sendMessage(ChatColor.RED + args[1] + " already exists!");
    53. p.sendMessage(ChatColor.RED + "If you think this is an error please report it to a staff member!");
    54. }
    55. }
    56. else
    57. {
    58. p.sendMessage(ChatColor.RED + "Wrong arguments!");
    59. p.sendMessage(ChatColor.RED + "Do /t help");
    60. }
    61. }
    62.  
    63. //Promoting a Player
    64.  
    65. if (cmd.getLabel().equalsIgnoreCase("promote"))
    66. {
    67. if (args.length == 2)
    68. {
    69. this.getConfig().set(//Need to Get the Team and add player);
    70. }
    71. else
    72. {
    73. p.sendMessage(ChatColor.RED + "Wrong arguments!");
    74. p.sendMessage(ChatColor.RED + "Do /t help");
    75. }
    76. }
    77. }
    78. return false;
    79.  
    80.  
    81. }
    82. }
    83.  


    On line 69 I have to find what Team the player is in.

    I tried doing: Config().contains though it did not work.
     
  2. Offline

    Dragonphase

    MrGermanrain

    Without more information on how your plugin operates and incorporates Teams using your config file, it's hard to help you. From what I can gather in your post, you could do something along the lines of this:

    Code:java
    1. for (String team : this.getConfig().getList("Teams")){
    2. for (String member : this.getConfig().getList("Teams." + team)){
    3. if (member.equalsIgnoreCase(p.getName()){
    4. //promote them
    5. }
    6. }
    7. }


    You should also use the player's UUID instead of their name.
     
  3. Offline

    MrGermanrain

    Thanks, I will be looking into this :)
     
Thread Status:
Not open for further replies.

Share This Page