vminecraftSettings.java 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. import java.io.*;
  2. import java.util.ArrayList;
  3. import java.util.logging.Level;
  4. import java.util.logging.Logger;
  5. //=====================================================================
  6. //Class: vminecraftSettings
  7. //Use: Controls the settings for vminecraft
  8. //Author: nossr50, TrapAlice, cerevisiae
  9. //=====================================================================
  10. public class vminecraftSettings {
  11. //private final static Object syncLock = new Object();
  12. protected static final Logger log = Logger.getLogger("Minecraft");
  13. private static volatile vminecraftSettings instance;
  14. //Invulnerability List
  15. //The feature settings
  16. static boolean toggle = true,
  17. adminChat = false,
  18. greentext = false,
  19. FFF = false,
  20. quakeColors = false,
  21. cmdFabulous = false,
  22. cmdPromote = false,
  23. cmdDemote = false,
  24. cmdWhoIs = false,
  25. cmdRules = false,
  26. cmdMasstp = false,
  27. cmdTp = false,
  28. cmdTphere = false,
  29. globalmessages = false,
  30. cmdSay = false,
  31. cmdWho = false,
  32. cmdEzModo = false;
  33. //An array of players currently in ezmodo
  34. static ArrayList<String> ezModo = new ArrayList<String>();
  35. //The max health for ezModo
  36. static int ezHealth = 30;
  37. private PropertiesFile properties;
  38. String file = "vminecraft.properties";
  39. public String rules[] = null;
  40. //=====================================================================
  41. //Function: loadSettings
  42. //Input: None
  43. //Output: None
  44. //Use: Loads the settings from the properties
  45. //=====================================================================
  46. public void loadSettings()
  47. {
  48. File theDir = new File("vminecraft.properties");
  49. if(!theDir.exists()){
  50. String location = "vminecraft.properties";
  51. properties = new PropertiesFile("vminecraft.properties");
  52. FileWriter writer = null;
  53. try {
  54. writer = new FileWriter(location);
  55. writer.write("#This plugin is modular\r\n");
  56. writer.write("#Turn any features you don't want to false and they won't be running\r\n");
  57. writer.write("#If you edit this file and save it, then use /reload it will reload the settings\r\n");
  58. writer.write("greentext=true\r\n");
  59. writer.write("quakeColors=true\r\n");
  60. writer.write("cmdTphere=true\r\n");
  61. writer.write("cmdFabulous=true\r\n");
  62. writer.write("cmdWhoIs=true\r\n");
  63. writer.write("cmdWho=true\r\n");
  64. writer.write("cmdPromote=true\r\n");
  65. writer.write("cmdDemote=true\r\n");
  66. writer.write("cmdMasstp=true\r\n");
  67. writer.write("cmdSay=true\r\n");
  68. writer.write("cmdTp=true\r\n");
  69. writer.write("cmdRules=true\r\n");
  70. writer.write("globalmessages=true\r\n");
  71. writer.write("FFF=true\r\n");
  72. writer.write("adminchat=true\r\n");
  73. writer.write("cmdEzModo=true\r\n");
  74. writer.write("ezModo=\r\n");
  75. writer.write("ezHealth=30\r\n");
  76. writer.write("rules=Rules@#1: No griefing@#2: No griefing\r\n");
  77. } catch (Exception e) {
  78. log.log(Level.SEVERE, "Exception while creating " + location, e);
  79. } finally {
  80. try {
  81. if (writer != null) {
  82. writer.close();
  83. }
  84. } catch (IOException e) {
  85. log.log(Level.SEVERE, "Exception while closing writer for " + location, e);
  86. }
  87. }
  88. } else {
  89. properties = new PropertiesFile("vminecraft.properties");
  90. try {
  91. properties.load();
  92. } catch (IOException e) {
  93. e.printStackTrace();
  94. }
  95. }
  96. try {
  97. adminChat = properties.getBoolean("adminchat",true);
  98. greentext = properties.getBoolean("greentext",true);
  99. FFF = properties.getBoolean("FFF",true);
  100. quakeColors = properties.getBoolean("quakeColors",true);
  101. cmdFabulous = properties.getBoolean("cmdFabulous",true);
  102. cmdPromote = properties.getBoolean("cmdPromote",true);
  103. cmdDemote = properties.getBoolean("cmdDemote",true);
  104. cmdWhoIs = properties.getBoolean("cmdWhoIs",true);
  105. cmdWho = properties.getBoolean("cmdWho",true);
  106. cmdRules = properties.getBoolean("cmdRules",true);
  107. cmdTp = properties.getBoolean("cmdTp",true);
  108. cmdMasstp = properties.getBoolean("cmdMasstp",true);
  109. cmdTphere = properties.getBoolean("cmdTphere",true);
  110. globalmessages = properties.getBoolean("globalmessages",true);
  111. cmdSay = properties.getBoolean("cmdSay",true);
  112. cmdEzModo = properties.getBoolean("cmdEzModo",true);
  113. rules = properties.getString("rules", "").split("@");
  114. String[] tempEz = properties.getString("ezModo").split(",");
  115. ezModo = new ArrayList<String>();
  116. for(int i = 0; i < tempEz.length; i++)
  117. ezModo.add(tempEz[i]);
  118. ezHealth = properties.getInt("ezHealth");
  119. log.log(Level.INFO, "vminecraft plugin successfully loaded");
  120. }
  121. catch (Exception e)
  122. {
  123. log.log(Level.SEVERE, "vminecraft Error: ERROR LOADING PROPERTIES FILE");
  124. }
  125. }
  126. //=====================================================================
  127. //Function: adminchat, greentext, FFF, quakeColors, cmdFabulous,
  128. // cmdPromote, cmdDemote, cmdWhoIs, cmdTp, cmdTphere, cmdSay
  129. // cmdRules, globalmessages, cmdMasstp, cmdEzModo
  130. //Input: None
  131. //Output: Boolan: If the feature is enabled
  132. //Use: Returns if the feature is enabled
  133. //=====================================================================
  134. public boolean adminchat() {return adminChat;}
  135. public boolean greentext() {return greentext;}
  136. public boolean FFF() {return FFF;}
  137. public boolean quakeColors() {return quakeColors;}
  138. public boolean cmdFabulous() {return cmdFabulous;}
  139. public boolean cmdPromote() {return cmdPromote;}
  140. public boolean cmdDemote() {return cmdDemote;}
  141. public boolean cmdWhoIs() {return cmdWhoIs;}
  142. public boolean cmdTp() {return cmdTp;}
  143. public boolean cmdTphere() {return cmdTphere;}
  144. public boolean cmdSay() {return cmdSay;}
  145. public boolean cmdRules() {return cmdRules;}
  146. public boolean globalmessages() {return globalmessages;}
  147. public boolean cmdMasstp() {return cmdMasstp;}
  148. public boolean cmdEzModo() {return cmdEzModo;}
  149. public boolean cmdWho() {return cmdWho;}
  150. //EzModo functions
  151. public boolean isEzModo(String playerName) {return ezModo.contains(playerName);}
  152. public void removeEzModo(String playerName) {ezModo.remove(ezModo.indexOf(playerName));}
  153. public void addEzModo(String playerName) {ezModo.add(playerName);}
  154. public int ezModoHealth() {return ezHealth;}
  155. public String ezModoList() {return ezModo.toString();}
  156. //=====================================================================
  157. //Function: getInstance
  158. //Input: None
  159. //Output: vminecraftSettings: The instance of the settings
  160. //Use: Returns the instance of the settings
  161. //=====================================================================
  162. public static vminecraftSettings getInstance() {
  163. if (instance == null) {
  164. instance = new vminecraftSettings();
  165. }
  166. return instance;
  167. }
  168. //=====================================================================
  169. //Function: getRules
  170. //Input: None
  171. //Output: String[]: The list of rules
  172. //Use: Gets the array containing the rules
  173. //=====================================================================
  174. public String[] getRules() {
  175. return rules;
  176. }
  177. }