vMinecraftUsers.java 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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.append(player.getName()+"::::");
  46. } catch (Exception e) {
  47. log.log(Level.SEVERE, "Exception while trying to add user with writer to " + location, e);
  48. } finally {
  49. try {
  50. if (writer != null) {
  51. writer.close();
  52. }
  53. } catch (IOException e) {
  54. log.log(Level.SEVERE, "Exception while closing writer for " + location, e);
  55. }
  56. }
  57. }
  58. public static vMinecraftUsers getInstance() {
  59. if (instance == null) {
  60. instance = new vMinecraftUsers();
  61. }
  62. return instance;
  63. }
  64. }