vMinecraftUsers.java 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import java.io.*;
  2. import java.util.ArrayList;
  3. import java.util.logging.Level;
  4. import java.util.logging.Logger;
  5. public class vMinecraftUsers {
  6. private static volatile vMinecraftUsers instance;
  7. protected static final Logger log = Logger.getLogger("Minecraft");
  8. String file = "vminecraftusers.txt";
  9. private PropertiesFile properties;
  10. String location = "vminecraftusers.txt";
  11. public void loadUsers(){
  12. File theDir = new File("vminecraftusers.txt");
  13. if(!theDir.exists()){
  14. properties = new PropertiesFile("vminecraftusers.txt");
  15. FileWriter writer = null;
  16. try {
  17. writer = new FileWriter(location);
  18. writer.write("#Storage place for user information\r\n");
  19. writer.write("#username:nickname:suffix:ignore,list,names:alias,commands,here\r\n");
  20. } catch (Exception e) {
  21. log.log(Level.SEVERE, "Exception while creating " + location, e);
  22. } finally {
  23. try {
  24. if (writer != null) {
  25. writer.close();
  26. }
  27. } catch (IOException e) {
  28. log.log(Level.SEVERE, "Exception while closing writer for " + location, e);
  29. }
  30. }
  31. } else {
  32. properties = new PropertiesFile("vminecraftusers.txt");
  33. try {
  34. properties.load();
  35. } catch (IOException e) {
  36. log.log(Level.SEVERE, "Exception while loading vminecraftusers.txt", e);
  37. }
  38. }
  39. }
  40. public static void addUser(Player player){
  41. FileWriter writer = null;
  42. String location = "vminecraftusers.txt";
  43. try {
  44. writer = new FileWriter(location);
  45. writer.write(player.getName()+"::::");
  46. } catch (Exception e) {
  47. log.log(Level.SEVERE, "Exception while trying to add user with writer to " + location, e);
  48. }
  49. }
  50. public static vMinecraftUsers getInstance() {
  51. if (instance == null) {
  52. instance = new vMinecraftUsers();
  53. }
  54. return instance;
  55. }
  56. }