vMinecraftUsers.java 2.1 KB

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