Trouble saving players into a StringList

Discussion in 'Plugin Development' started by Mig_B, Aug 10, 2013.

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

    Mig_B

    My Upper Code:


    Code:java
    1. Theme m = new Theme();
    2.  
    3. protected List<String> gryffindor = new ArrayList<String>();
    4. protected List<String> slytherin = new ArrayList<String>();
    5. protected List<String> hufflepuff = new ArrayList<String>();
    6. protected List<String> ravenclaw = new ArrayList<String>();
    7. public ChatColor red = ChatColor.RED;
    8. public ChatColor gold = ChatColor.GOLD;
    9. public ChatColor green = ChatColor.GREEN;
    10. public ChatColor blue = ChatColor.BLUE;
    11. public ChatColor yellow = ChatColor.YELLOW;
    12.  
    13. @Override
    14. public void onEnable() {
    15.  
    16. PluginManager pm = getServer().getPluginManager();
    17. pm.registerEvents(new SortingListener(this), this);
    18.  
    19. this.getCommand("houseset").setExecutor(new setHouse(this));
    20.  
    21. FileConfiguration cfg = getConfig();
    22. cfg.addDefault("Gryffindor", gryffindor);
    23. cfg.addDefault("Slytherin", slytherin);
    24. cfg.addDefault("Hufflepuff", hufflepuff);
    25. cfg.addDefault("Ravenclaw", ravenclaw);
    26.  
    27. cfg.options().copyDefaults(true);
    28.  
    29. this.saveConfig();
    30. }




    My Command:

    Code:java
    1. @Override
    2. public boolean onCommand(CommandSender s, Command cmd, String label, String[] args) {
    3. if (s instanceof Player) {
    4. Player p = (Player) s;
    5. String player = s.getName();
    6.  
    7. if (cmd.getName().equalsIgnoreCase("answer")) {
    8. if (args.length == 1) {
    9. if (args[0].equalsIgnoreCase("Courage")) {
    10. if (!getConfig().getStringList("Gryffindor").contains(p.getName()) || !getConfig().getStringList("Slytherin").contains(p.getName()) || !getConfig().getStringList("Hufflepuff").contains(player) || !getConfig().getStringList("Ravenclaw").contains(p.getName())) {
    11. gryffindor.add(player);
    12. List<String> list = getConfig().getStringList("Gryffindor");
    13.  
    14. if(!list.contains(p.getName())){
    15. list.add(p.getName());
    16. getConfig().set("Gryffindor", list);
    17. this.saveConfig();
    18. }
    19. if(getConfig().getString("Gryffindor").contains(p.getName())){
    20. p.sendMessage(m.prefix + red + "You are already in a house!");
    21.  
    22. }
    23.  
    24.  
    25.  
    26. ItemStack chest = new ItemStack(Material.LEATHER_CHESTPLATE, 1);
    27. LeatherArmorMeta chestmeta = (LeatherArmorMeta) chest.getItemMeta();
    28. chestmeta.setColor(Color.RED);
    29. chestmeta.setDisplayName(red + "Gryffindor Robes");
    30. chest.setItemMeta(chestmeta);
    31.  
    32. ItemStack helm = new ItemStack(Material.LEATHER_HELMET, 1);
    33. LeatherArmorMeta helmmeta = (LeatherArmorMeta) helm.getItemMeta();
    34. helmmeta.setColor(Color.RED);
    35. helmmeta.setDisplayName(red + "Gryffindor Robes");
    36. helm.setItemMeta(helmmeta);
    37.  
    38. ItemStack legs = new ItemStack(Material.LEATHER_LEGGINGS, 1);
    39. LeatherArmorMeta legmeta = (LeatherArmorMeta) legs.getItemMeta();
    40. legmeta.setColor(Color.RED);
    41. legmeta.setDisplayName(red + "Gryffindor Robes");
    42. legs.setItemMeta(legmeta);
    43.  
    44. ItemStack boots = new ItemStack(Material.LEATHER_BOOTS, 1);
    45. LeatherArmorMeta bootmeta = (LeatherArmorMeta) boots.getItemMeta();
    46. bootmeta.setColor(Color.RED);
    47. bootmeta.setDisplayName(red + "Gryffindor Robes");
    48. boots.setItemMeta(bootmeta);
    49.  
    50. p.getInventory().setHelmet(helm);
    51. p.getInventory().setChestplate(chest);
    52. p.getInventory().setLeggings(legs);
    53. p.getInventory().setBoots(boots);
    54.  
    55. p.sendMessage(m.prefix + ChatColor.RED
    56. + "You have been sorted in Gryffindor!");
    57. Bukkit.broadcastMessage(m.prefix + ChatColor.RED + s.getName()
    58. + "as been sorted into Gryffindor!");
    59. TagAPI.refreshPlayer(p);
    60. } else {
    61. p.sendMessage(m.prefix + red + "You have already been sorted.");
    62. }
    63. } else if (args[0].equalsIgnoreCase("Cunning")) {
    64. if (!getConfig().getStringList("Gryffindor").contains(p.getName()) || !getConfig().getStringList("Slytherin").contains(p.getName()) || !getConfig().getStringList("Hufflepuff").contains(player) || !getConfig().getStringList("Ravenclaw").contains(p.getName())) {
    65. slytherin.add(player);
    66. List<String> list = getConfig().getStringList("Slytherin");
    67.  
    68. if(!list.contains(p.getName())){
    69. list.add(p.getName());
    70. getConfig().set("Slytherin", list);
    71. this.saveConfig();
    72. }
    73. if(getConfig().getString("Slytherin").contains(p.getName())){
    74. p.sendMessage(m.prefix + red + "You are already in a house!");
    75.  
    76. }
    77.  
    78.  
    79. ItemStack chest = new ItemStack(Material.LEATHER_CHESTPLATE, 1);
    80. LeatherArmorMeta chestmeta = (LeatherArmorMeta) chest.getItemMeta();
    81. chestmeta.setColor(Color.GREEN);
    82. chestmeta.setDisplayName(green + "Slytherin Robes");
    83. chest.setItemMeta(chestmeta);
    84.  
    85. ItemStack helm = new ItemStack(Material.LEATHER_HELMET, 1);
    86. LeatherArmorMeta helmmeta = (LeatherArmorMeta) helm.getItemMeta();
    87. helmmeta.setColor(Color.GREEN);
    88. helmmeta.setDisplayName(green + "Slytherin Robes");
    89. helm.setItemMeta(helmmeta);
    90.  
    91. ItemStack legs = new ItemStack(Material.LEATHER_LEGGINGS, 1);
    92. LeatherArmorMeta legmeta = (LeatherArmorMeta) legs.getItemMeta();
    93. legmeta.setColor(Color.GREEN);
    94. legmeta.setDisplayName(green + "Slytherin Robes");
    95. legs.setItemMeta(legmeta);
    96.  
    97. ItemStack boots = new ItemStack(Material.LEATHER_BOOTS, 1);
    98. LeatherArmorMeta bootmeta = (LeatherArmorMeta) boots.getItemMeta();
    99. bootmeta.setColor(Color.GREEN);
    100. bootmeta.setDisplayName(green + "Slytherin Robes");
    101. boots.setItemMeta(bootmeta);
    102.  
    103. p.getInventory().setHelmet(helm);
    104. p.getInventory().setChestplate(chest);
    105. p.getInventory().setLeggings(legs);
    106. p.getInventory().setBoots(boots);
    107.  
    108. p.sendMessage(m.prefix + ChatColor.GREEN
    109. + "You have been sorted in Slytherin!");
    110. Bukkit.broadcastMessage(m.prefix + ChatColor.GREEN + s.getName()
    111. + " as been sorted into Slytherin!");
    112. TagAPI.refreshPlayer(p);
    113.  
    114. } else {
    115. p.sendMessage(m.prefix + red + "You have already been sorted.");
    116. }
    117. } else if (args[0].equalsIgnoreCase("Loyal")) {
    118. if (!getConfig().getStringList("Gryffindor").contains(p.getName()) || !getConfig().getStringList("Slytherin").contains(p.getName()) || !getConfig().getStringList("Hufflepuff").contains(player) || !getConfig().getStringList("Ravenclaw").contains(p.getName())) {
    119. hufflepuff.add(player);
    120. List<String> list = getConfig().getStringList("Hufflepuff");
    121.  
    122. if(!list.contains(p.getName())){
    123. list.add(p.getName());
    124. getConfig().set("Hufflepuff", list);
    125. this.saveConfig();
    126. }
    127. if(getConfig().getString("Hufflepuff").contains(p.getName())){
    128. p.sendMessage(m.prefix + red + "You are already in a house!");
    129.  
    130. }
    131.  
    132. ItemStack chest = new ItemStack(Material.LEATHER_CHESTPLATE, 1);
    133. LeatherArmorMeta chestmeta = (LeatherArmorMeta) chest.getItemMeta();
    134. chestmeta.setColor(Color.YELLOW);
    135. chestmeta.setDisplayName(yellow + "Hufflepuff Robes");
    136. chest.setItemMeta(chestmeta);
    137.  
    138. ItemStack helm = new ItemStack(Material.LEATHER_HELMET, 1);
    139. LeatherArmorMeta helmmeta = (LeatherArmorMeta) helm.getItemMeta();
    140. helmmeta.setColor(Color.YELLOW);
    141. helmmeta.setDisplayName(yellow + "Hufflepuff Robes");
    142. helm.setItemMeta(helmmeta);
    143.  
    144. ItemStack legs = new ItemStack(Material.LEATHER_LEGGINGS, 1);
    145. LeatherArmorMeta legmeta = (LeatherArmorMeta) legs.getItemMeta();
    146. legmeta.setColor(Color.YELLOW);
    147. legmeta.setDisplayName(yellow + "Hufflepuff Robes");
    148. legs.setItemMeta(legmeta);
    149.  
    150. ItemStack boots = new ItemStack(Material.LEATHER_BOOTS, 1);
    151. LeatherArmorMeta bootmeta = (LeatherArmorMeta) boots.getItemMeta();
    152. bootmeta.setColor(Color.YELLOW);
    153. bootmeta.setDisplayName(yellow + "Hufflepuff Robes");
    154. boots.setItemMeta(bootmeta);
    155.  
    156. p.getInventory().setHelmet(helm);
    157. p.getInventory().setChestplate(chest);
    158. p.getInventory().setLeggings(legs);
    159. p.getInventory().setBoots(boots);
    160.  
    161. p.sendMessage(m.prefix + yellow + "You have been sorted in Hufflepuff!");
    162. Bukkit.broadcastMessage(m.prefix + yellow + s.getName()
    163. + " as been sorted into Hufflepuff!");
    164. TagAPI.refreshPlayer(p);
    165. } else {
    166. p.sendMessage(m.prefix + red + "You have already been sorted.");
    167. }
    168. } else if (args[0].equalsIgnoreCase("Clever")) {
    169. if (!getConfig().getStringList("Gryffindor").contains(p.getName()) || !getConfig().getStringList("Slytherin").contains(p.getName()) || !getConfig().getStringList("Hufflepuff").contains(player) || !getConfig().getStringList("Ravenclaw").contains(p.getName())) {
    170. ravenclaw.add(player);
    171. List<String> list = getConfig().getStringList("Ravenclaw");
    172.  
    173. if(!list.contains(p.getName())){
    174. list.add(p.getName());
    175. getConfig().set("Ravenclaw", list);
    176. this.saveConfig();
    177. }
    178. if(getConfig().getString("Ravenclaw").contains(p.getName())){
    179. p.sendMessage(m.prefix + red + "You are already in a house!");
    180.  
    181. }
    182.  
    183.  
    184.  
    185. ItemStack chest = new ItemStack(Material.LEATHER_CHESTPLATE, 1);
    186. LeatherArmorMeta chestmeta = (LeatherArmorMeta) chest.getItemMeta();
    187. chestmeta.setColor(Color.BLUE);
    188. chestmeta.setDisplayName(blue + "Ravenclaw Robes");
    189. chest.setItemMeta(chestmeta);
    190.  
    191. ItemStack helm = new ItemStack(Material.LEATHER_HELMET, 1);
    192. LeatherArmorMeta helmmeta = (LeatherArmorMeta) helm.getItemMeta();
    193. helmmeta.setColor(Color.BLUE);
    194. helmmeta.setDisplayName(blue + "Ravenclaw Robes");
    195. helm.setItemMeta(helmmeta);
    196.  
    197. ItemStack legs = new ItemStack(Material.LEATHER_LEGGINGS, 1);
    198. LeatherArmorMeta legmeta = (LeatherArmorMeta) legs.getItemMeta();
    199. legmeta.setColor(Color.BLUE);
    200. legmeta.setDisplayName(blue + "Ravenclaw Robes");
    201. legs.setItemMeta(legmeta);
    202.  
    203. ItemStack boots = new ItemStack(Material.LEATHER_BOOTS, 1);
    204. LeatherArmorMeta bootmeta = (LeatherArmorMeta) boots.getItemMeta();
    205. bootmeta.setColor(Color.BLUE);
    206. bootmeta.setDisplayName(blue + "Ravenclaw Robes");
    207. boots.setItemMeta(bootmeta);
    208.  
    209. p.getInventory().setHelmet(helm);
    210. p.getInventory().setChestplate(chest);
    211. p.getInventory().setLeggings(legs);
    212. p.getInventory().setBoots(boots);
    213.  
    214. p.sendMessage(m.prefix + blue + "You have been sorted in Ravenclaw!");
    215. Bukkit.broadcastMessage(m.prefix + blue + s.getName()
    216. + " as been sorted into Ravenclaw!");
    217. TagAPI.refreshPlayer(p);
    218.  
    219. } else {
    220. p.sendMessage(m.prefix + red + "You have already been sorted.");
    221. }
    222. }
    223.  
    224. } else {
    225. p.sendMessage(red + "Correct Arguments : Courage, Cunning, Loyal, Clever");
    226. }
    227.  
    228.  
    229. }
    230.  
    231. }
    232.  
    233.  
    234.  
    235.  
    236. return false;
    237.  
    238. }
    239.  
    240. }




    Please help, I cannot store the players, even when there name is in the config, they can still redo the command.

    Thanks :)
     
  2. Offline

    Robotia

    Don't put any runtime code in onEnable() that depends on the plugin being enabled, since the plugin is disabled during onEnable();)
     
Thread Status:
Not open for further replies.

Share This Page