[Unsolved]SOMEONE PLEASE HELP!!!

Discussion in 'Plugin Development' started by Heirteir, Mar 9, 2014.

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

    Heirteir

    Alright so i am making a plugin that will require creating a seperator yml file for every person that joins the server so far i have it to where it creates there file but it wont let me edit the file at all even though i setup the methods please tell me what i did wrong.

    FirstJoin Class:

    Code:java
    1. package me.heirteir.core;
    2.  
    3. import java.io.File;
    4. import java.io.IOException;
    5. import java.util.logging.Level;
    6.  
    7. import me.heirteir.core.settings.SettingsManager;
    8. import net.minecraft.server.v1_7_R1.ServerPingServerDataSerializer;
    9.  
    10. import org.bukkit.Bukkit;
    11. import org.bukkit.configuration.file.YamlConfiguration;
    12. import org.bukkit.entity.Player;
    13. import org.bukkit.event.EventHandler;
    14. import org.bukkit.event.Listener;
    15. import org.bukkit.event.player.PlayerJoinEvent;
    16. import org.bukkit.event.server.ServerListPingEvent;
    17. import org.bukkit.plugin.Plugin;
    18.  
    19. public class FirstJoin implements Listener {
    20. private FirstJoin() {
    21. };
    22.  
    23. private static FirstJoin instance = new FirstJoin();
    24.  
    25. static Plugin plugin;
    26.  
    27. public static FirstJoin getInstance(Plugin p) {
    28. plugin = p;
    29. return instance;
    30. }
    31.  
    32. private SettingsManager manager = SettingsManager.getInstance();
    33.  
    34. @EventHandler
    35. public void onPlayerJoin(PlayerJoinEvent e) {
    36. Player p = e.getPlayer();
    37. CheckIfFirstJoin(p);
    38.  
    39. manager.getPlayerFile(p).set("Hellotehre", "hello there");
    40. manager.savePlayerFile(p);
    41. }
    42.  
    43. public void checkIfFirstJoin(Player p){
    44. File file = new File(plugin.getDataFolder().getAbsolutePath(),
    45. "playerfiles" + File.separator + p.getName() + ".yml");
    46. if (file.exists() == false) {
    47. try {
    48. file.createNewFile();
    49. } catch (Exception event) {
    50. Bukkit.getLogger().log(Level.SEVERE, "Could Not Create " + p.getName() + ".yml\n"
    51. + "Reason: " + event.getMessage());
    52. }
    53. }
    54. }
    55. }
    56.  


    SettingsManager Class:

    Code:java
    1. package me.heirteir.core.settings;
    2.  
    3. import java.io.File;
    4. import java.io.IOException;
    5. import java.util.logging.Level;
    6.  
    7. import me.heirteir.core.FirstJoin;
    8.  
    9. import org.bukkit.Bukkit;
    10. import org.bukkit.ChatColor;
    11. import org.bukkit.configuration.file.FileConfiguration;
    12. import org.bukkit.configuration.file.YamlConfiguration;
    13. import org.bukkit.entity.Player;
    14. import org.bukkit.plugin.Plugin;
    15. import org.bukkit.plugin.PluginDescriptionFile;
    16.  
    17. public class SettingsManager
    18. {
    19. private SettingsManager() { }
    20.  
    21. static SettingsManager instance = new SettingsManager();
    22.  
    23. public static SettingsManager getInstance()
    24. {
    25. return instance;
    26. }
    27.  
    28. private SetupVault setupvault = SetupVault.getInstance();
    29.  
    30. Plugin plugin;
    31.  
    32. private File cFile;
    33.  
    34. private FileConfiguration config;
    35.  
    36. public void setup(Plugin p)
    37. {
    38. plugin = p;
    39. config = p.getConfig();
    40. p.saveConfig();
    41. cFile = new File(p.getDataFolder(), "config.yml");
    42.  
    43. setupvault.setupVault(p);
    44.  
    45. File playerfiledir = new File(p.getDataFolder(), "playerfiles");
    46. if (playerfiledir.exists() == false){
    47. playerfiledir.mkdir();
    48. }
    49. }
    50.  
    51. public FileConfiguration getConfig()
    52. {
    53. return config;
    54. }
    55.  
    56. public void saveConfig()
    57. {
    58. try
    59. {
    60. config.save(cFile);
    61. }
    62. catch (IOException e)
    63. {
    64. Bukkit.getServer().getLogger().severe(ChatColor.RED + "Could Not Save Config.yml");
    65. }
    66. }
    67. public PluginDescriptionFile getDesc()
    68. {
    69. return plugin.getDescription();
    70. }
    71.  
    72. public YamlConfiguration getPlayerFile(Player player){
    73. File pFile = new File(plugin.getDataFolder().getAbsolutePath(), "playerfiles" + File.separator + player.getName() + ".yml");
    74. if (pFile.exists() == false){
    75. Bukkit.getLogger().log(Level.SEVERE, "Player File Not Found Returning Null ");
    76. return null;
    77. }
    78. YamlConfiguration playerfile = YamlConfiguration.loadConfiguration(pFile);
    79. return playerfile;
    80. }
    81.  
    82. public void savePlayerFile(Player player){
    83. File pFile = new File(plugin.getDataFolder().getAbsolutePath(), "playerfiles" + File.separator + player.getName() + ".yml");
    84. if (pFile.exists() == false){
    85. Bukkit.getLogger().log(Level.SEVERE, "Player File Not Found Returning Null");
    86. return;
    87. }
    88. PlayerFiles.getPlayerYaml(player).save();
    89. }
    90.  
    91. public void reloadConfig()
    92. {
    93. config = YamlConfiguration.loadConfiguration(cFile);
    94. }
    95. }


    PlayerFiles Class (Warning pretty big):

    Code:java
    1. package me.heirteir.core.settings;
    2.  
    3. import java.io.File;
    4. import java.io.IOException;
    5. import java.nio.file.FileSystem;
    6.  
    7. import org.bukkit.configuration.file.YamlConfiguration;
    8. import org.bukkit.configuration.file.YamlConfigurationOptions;
    9. import org.bukkit.entity.Player;
    10. import org.bukkit.plugin.Plugin;
    11.  
    12. public class PlayerFiles {
    13. static Plugin plugin;
    14. public static PlayerFiles getPlayerYaml(Player player, Plugin plugin)
    15. {
    16.  
    17. return new PlayerFiles(plugin.getDataFolder().getAbsolutePath() + File.separator + "playerfiles" + File.separator + player.getName() + ".yml");
    18.  
    19. }
    20.  
    21. public static PlayerFiles getOfflinePlayerYaml(String string, Plugin plugin)
    22. {
    23.  
    24. return new PlayerFiles(plugin.getDataFolder().getAbsolutePath() + File.separator + "playerfiles" + File.separator + string + ".yml");
    25.  
    26. }
    27.  
    28. private File file = null;
    29.  
    30. private YamlConfiguration yaml = new YamlConfiguration();
    31.  
    32. public PlayerFiles(File file) {
    33.  
    34. this.file = file;
    35.  
    36. if (!file.exists()) {
    37.  
    38. try {
    39. file.createNewFile();
    40. } catch (IOException e) {
    41. e.printStackTrace();
    42. }
    43.  
    44. }
    45.  
    46. this.load();
    47.  
    48. }
    49.  
    50. public PlayerFiles(String path) {
    51.  
    52. this.file = new File(path);
    53.  
    54. if (!file.exists()) {
    55.  
    56. try {
    57. file.createNewFile();
    58. } catch (IOException e) {
    59. e.printStackTrace();
    60. }
    61. }
    62.  
    63. this.load();
    64.  
    65. }
    66.  
    67. private void load() {
    68.  
    69. try {
    70. this.yaml.load(this.file);
    71. } catch (Exception e) {
    72. e.printStackTrace();
    73. }
    74.  
    75. }
    76.  
    77. /**
    78. * Save the Yaml's data to the file passed in the constructor.
    79. */
    80. public void save() {
    81.  
    82. try {
    83. this.yaml.save(this.file);
    84. } catch (Exception e) {
    85. e.printStackTrace();
    86. }
    87.  
    88. }
    89.  
    90. public void save(File file) {
    91.  
    92. try {
    93. this.yaml.save(file);
    94. } catch (Exception e) {
    95. e.printStackTrace();
    96. }
    97.  
    98. }
    99.  
    100. public void delete() {
    101. try {
    102. this.file.delete();
    103. } catch (Exception e) {
    104. e.printStackTrace();
    105. }
    106. }
    107.  
    108. /**
    109. * Get an Integer from the given path.
    110. *
    111. * @param s
    112. * Path to the Integer.
    113. * @return Integer at given path.
    114. */
    115. public int getInteger(String s) {
    116.  
    117. return this.yaml.getInt(s);
    118.  
    119. }
    120.  
    121. /**
    122. * Save, then load the Yaml file. **Warning** Very Unstable.
    123. */
    124. public void reload() {
    125.  
    126. this.save();
    127.  
    128. this.load();
    129.  
    130. }
    131.  
    132. /**
    133. * Get a String from the path defined.
    134. *
    135. * @param s
    136. * Path to the String.
    137. * @return String at given path.
    138. */
    139. public String getString(String s) {
    140.  
    141. return this.yaml.getString(s);
    142.  
    143. }
    144.  
    145. /**
    146. * Gets an Object at the given path.
    147. *
    148. * @param s
    149. * Path to given Object.
    150. * @return An Object at the given Path.
    151. */
    152. public Object get(String s) {
    153.  
    154. return this.yaml.get(s);
    155.  
    156. }
    157.  
    158. /**
    159. * Gets a boolean at the given path.
    160. *
    161. * @param s
    162. * Path to the boolean.
    163. * @return Boolean at the given path.
    164. */
    165. public boolean getBoolean(String s) {
    166.  
    167. return this.yaml.getBoolean(s);
    168.  
    169. }
    170.  
    171. /**
    172. * If the given path has no variable, it will be given a variable.
    173. *
    174. * @param s
    175. * Path to look for.
    176. * @param o
    177. * Variable to be assigned if not existing.
    178. */
    179. public void add(String s, Object o) {
    180.  
    181. if (!this.contains(s)) {
    182.  
    183. this.set(s, o);
    184.  
    185. }
    186.  
    187. }
    188.  
    189. /**
    190. * Adds a String to a List of Strings.
    191. *
    192. * @param s
    193. * Path to given String List.
    194. * @param o
    195. * String to add to the String List.
    196. */
    197. public void addToStringList(String s, String o) {
    198.  
    199. this.yaml.getStringList(s).add(o);
    200.  
    201. }
    202.  
    203. /**
    204. * Removes a String to a List of Strings.
    205. *
    206. * @param s
    207. * Path to given String List.
    208. * @param o
    209. * String to remove from the String List.
    210. */
    211. public void removeFromStringList(String s, String o) {
    212.  
    213. this.yaml.getStringList(s).remove(o);
    214.  
    215. }
    216.  
    217. /**
    218. * Looks for a String List at given Path.
    219. *
    220. * @param s
    221. * Path to String List.
    222. * @return String List at given Path.
    223. */
    224. public java.util.List<String> getStringList(String s) {
    225.  
    226. return this.yaml.getStringList(s);
    227.  
    228. }
    229.  
    230. /**
    231. * Adds an Integer to a List of Integers.
    232. *
    233. * @param s
    234. * Path to given Integer List.
    235. * @param o
    236. * Integer to add to the Integer List.
    237. */
    238. public void addToIntegerList(String s, int o) {
    239.  
    240. this.yaml.getIntegerList(s).add(o);
    241.  
    242. }
    243.  
    244. /**
    245. * Removes an Integer to a List of Integers.
    246. *
    247. * @param s
    248. * Path to given Integer List.
    249. * @param o
    250. * Integer to remove to the Integer List.
    251. */
    252. public void removeFromIntegerList(String s, int o) {
    253.  
    254. this.yaml.getIntegerList(s).remove(o);
    255.  
    256. }
    257.  
    258. /**
    259. * Looks for a Integer List at given Path.
    260. *
    261. * @param s
    262. * Path to Integer List.
    263. * @return Integer List at given Path.
    264. */
    265. public java.util.List<Integer> getIntegerList(String s) {
    266.  
    267. return this.yaml.getIntegerList(s);
    268.  
    269. }
    270.  
    271. /**
    272. * Creates a new String List at given Path.
    273. *
    274. * @param s
    275. * Path to create String List at.
    276. * @param list
    277. * List to add.
    278. */
    279. public void createNewStringList(String s, java.util.List<String> list) {
    280.  
    281. this.yaml.set(s, list);
    282.  
    283. }
    284.  
    285. /**
    286. * Creates a new Integer List at given Path.
    287. *
    288. * @param s
    289. * Path to create Integer List at.
    290. * @param list
    291. * List to add.
    292. */
    293. public void createNewIntegerList(String s, java.util.List<Integer> list) {
    294.  
    295. this.yaml.set(s, list);
    296.  
    297. }
    298.  
    299. /**
    300. * **Untested/Unstable** Attempts to remove a variable at the given Path.
    301. *
    302. * @param s
    303. * Path to given variable needing removal.
    304. */
    305. public void remove(String s) {
    306.  
    307. this.set(s, null);
    308.  
    309. }
    310.  
    311. /**
    312. * Returns true if the given Path has a value.
    313. *
    314. * @param s
    315. * Path to value.
    316. * @return True if the given Path has a value.
    317. */
    318. public boolean contains(String s) {
    319.  
    320. return this.yaml.contains(s);
    321.  
    322. }
    323.  
    324. /**
    325. * Gets a double at the given Path.
    326. *
    327. * @param s
    328. * Path to double.
    329. * @return Double at given Path.
    330. */
    331. public double getDouble(String s) {
    332.  
    333. return this.yaml.getDouble(s);
    334.  
    335. }
    336.  
    337. /**
    338. * Sets a Object to the given Path.
    339. *
    340. * @param s
    341. * Path to variable being assigned.
    342. * @param o
    343. * Variable being assigned.
    344. */
    345. public void set(String s, Object o) {
    346.  
    347. this.yaml.set(s, o);
    348.  
    349. }
    350.  
    351. /**
    352. * Increases an Integer by 1.
    353. *
    354. * @param s
    355. * Path to Integer being incremented.
    356. */
    357. public void increment(String s) {
    358.  
    359. this.yaml.set(s, this.getInteger(s) + 1);
    360.  
    361. }
    362.  
    363. /**
    364. * Decreases an Integer by 1.
    365. *
    366. * @param s
    367. * Path to Integer being decremented.
    368. */
    369. public void decrement(String s) {
    370.  
    371. this.yaml.set(s, this.getInteger(s) - 1);
    372.  
    373. }
    374.  
    375. /**
    376. * Increases an Integer by i.
    377. *
    378. * @param s
    379. * Path to Integer being incremented.
    380. */
    381. public void increment(String s, int i) {
    382.  
    383. this.yaml.set(s, this.getInteger(s) + i);
    384.  
    385. }
    386.  
    387. /**
    388. * Decreases an Integer by 1.
    389. *
    390. * @param s
    391. * Path to Integer being decremented.
    392. */
    393. public void decrement(String s, int i) {
    394.  
    395. this.yaml.set(s, this.getInteger(s) - i);
    396.  
    397. }
    398.  
    399. /**
    400. * Returns the YamlConfiguration's Options.
    401. *
    402. * @return YamlConfiguration's Options.
    403. */
    404. public YamlConfigurationOptions options() {
    405.  
    406. return this.yaml.options();
    407.  
    408. }
    409. }


    Error code:

    Code:
    Could not pass event PlayerJoinEvent to Core v0.1
    org.bukkit.event.EventException
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:427) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.1-7-g15db099-b2973jnks]
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.1-7-g15db099-b2973jnks]
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:481) [craftbukkit.jar:git-Bukkit-1.7.2-R0.1-7-g15db099-b2973jnks]
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:466) [craftbukkit.jar:git-Bukkit-1.7.2-R0.1-7-g15db099-b2973jnks]
        at net.minecraft.server.v1_7_R1.PlayerList.c(PlayerList.java:225) [craftbukkit.jar:git-Bukkit-1.7.2-R0.1-7-g15db099-b2973jnks]
        at net.minecraft.server.v1_7_R1.PlayerList.a(PlayerList.java:116) [craftbukkit.jar:git-Bukkit-1.7.2-R0.1-7-g15db099-b2973jnks]
        at net.minecraft.server.v1_7_R1.LoginListener.c(LoginListener.java:78) [craftbukkit.jar:git-Bukkit-1.7.2-R0.1-7-g15db099-b2973jnks]
        at net.minecraft.server.v1_7_R1.LoginListener.a(LoginListener.java:42) [craftbukkit.jar:git-Bukkit-1.7.2-R0.1-7-g15db099-b2973jnks]
        at net.minecraft.server.v1_7_R1.NetworkManager.a(NetworkManager.java:149) [craftbukkit.jar:git-Bukkit-1.7.2-R0.1-7-g15db099-b2973jnks]
        at net.minecraft.server.v1_7_R1.ServerConnection.c(SourceFile:134) [craftbukkit.jar:git-Bukkit-1.7.2-R0.1-7-g15db099-b2973jnks]
        at net.minecraft.server.v1_7_R1.MinecraftServer.u(MinecraftServer.java:655) [craftbukkit.jar:git-Bukkit-1.7.2-R0.1-7-g15db099-b2973jnks]
        at net.minecraft.server.v1_7_R1.DedicatedServer.u(DedicatedServer.java:250) [craftbukkit.jar:git-Bukkit-1.7.2-R0.1-7-g15db099-b2973jnks]
        at net.minecraft.server.v1_7_R1.MinecraftServer.t(MinecraftServer.java:545) [craftbukkit.jar:git-Bukkit-1.7.2-R0.1-7-g15db099-b2973jnks]
        at net.minecraft.server.v1_7_R1.MinecraftServer.run(MinecraftServer.java:457) [craftbukkit.jar:git-Bukkit-1.7.2-R0.1-7-g15db099-b2973jnks]
        at net.minecraft.server.v1_7_R1.ThreadServerApplication.run(SourceFile:617) [craftbukkit.jar:git-Bukkit-1.7.2-R0.1-7-g15db099-b2973jnks]
    Caused by: java.lang.NullPointerException
        at me.heirteir.core.settings.PlayerFiles.getPlayerYaml(PlayerFiles.java:17) ~[?:?]
        at me.heirteir.core.settings.SettingsManager.savePlayerFile(SettingsManager.java:88) ~[?:?]
        at me.heirteir.core.FirstJoin.onPlayerJoin(FirstJoin.java:40) ~[?:?]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_51]
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_51]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_51]
        at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.7.0_51]
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:425) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.1-7-g15db099-b2973jnks]
        ... 14 more
    
    Please help me i need this really badly
     
  2. Offline

    Garris0n

    Again, to be in accordance with the Java naming conventions, that method must be "checkIfFirstJoin".

    Anyway, I don't see where you're doing the actual editing. I also really need to go to sleep, so explain that and either somebody else will help you or I'll wake up and do so.
     
  3. Offline

    Heirteir

    and i'm editing it in the FirstJoin class under where i called the checkIfFirstJoin() Method

    Also it's saving the /Core/playerfiles/Heirteir.yml correctly but it's just not changing the value inside of the yml file and i dont get why

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

    Garris0n

    Is the plugin ever set to anything in PlayerFiles?
     
  5. Offline

    Heirteir

    Garris0n Yes I have it to where it takes an input Player and Plugin
    in the getPlayerYaml
    and getOfflinePlayerYaml Methods at the top.

    bumb

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
Thread Status:
Not open for further replies.

Share This Page