vminecraftSettings.java 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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. stopFire = false,
  33. stopTnt = false,
  34. cmdEzModo = false;
  35. //An array of players currently in ezmodo
  36. static ArrayList<String> ezModo = new ArrayList<String>();
  37. //The max health for ezModo
  38. static int ezHealth = 30;
  39. private PropertiesFile properties;
  40. String file = "vminecraft.properties";
  41. public String rules[] = new String[0];
  42. //=====================================================================
  43. //Function: loadSettings
  44. //Input: None
  45. //Output: None
  46. //Use: Loads the settings from the properties
  47. //=====================================================================
  48. public void loadSettings()
  49. {
  50. File theDir = new File("vminecraft.properties");
  51. if(!theDir.exists()){
  52. String location = "vminecraft.properties";
  53. properties = new PropertiesFile("vminecraft.properties");
  54. FileWriter writer = null;
  55. try {
  56. writer = new FileWriter(location);
  57. writer.write("#This plugin is modular\r\n");
  58. writer.write("#Turn any features you don't want to false and they won't be running\r\n");
  59. writer.write("#If you edit this file and save it, then use /reload it will reload the settings\r\n");
  60. writer.write("greentext=true\r\n");
  61. writer.write("quakeColors=true\r\n");
  62. writer.write("cmdTphere=true\r\n");
  63. writer.write("cmdFabulous=true\r\n");
  64. writer.write("cmdWhoIs=true\r\n");
  65. writer.write("cmdWho=true\r\n");
  66. writer.write("cmdPromote=true\r\n");
  67. writer.write("cmdDemote=true\r\n");
  68. writer.write("cmdMasstp=true\r\n");
  69. writer.write("cmdSay=true\r\n");
  70. writer.write("cmdTp=true\r\n");
  71. writer.write("cmdRules=true\r\n");
  72. writer.write("globalmessages=true\r\n");
  73. writer.write("FFF=true\r\n");
  74. writer.write("adminchat=true\r\n");
  75. writer.write("cmdEzModo=true\r\n");
  76. writer.write("#Adding player names to this list will have them start off in ezmodo\r\n");
  77. writer.write("ezModo=\r\n");
  78. writer.write("#The health ezmodo people will have while in ezmodo. Don't set to 0\r\n");
  79. writer.write("ezHealth=30\r\n");
  80. writer.write("stopFire=false");
  81. writer.write("stopTnt=false");
  82. writer.write("rules=Rules@#1: No griefing@#2: No griefing\r\n");
  83. } catch (Exception e) {
  84. log.log(Level.SEVERE, "Exception while creating " + location, e);
  85. } finally {
  86. try {
  87. if (writer != null) {
  88. writer.close();
  89. }
  90. } catch (IOException e) {
  91. log.log(Level.SEVERE, "Exception while closing writer for " + location, e);
  92. }
  93. }
  94. } else {
  95. properties = new PropertiesFile("vminecraft.properties");
  96. try {
  97. properties.load();
  98. } catch (IOException e) {
  99. log.log(Level.SEVERE, "Exception while loading vminecraft.properties", e);
  100. }
  101. }
  102. try {
  103. adminChat = properties.getBoolean("adminchat",true);
  104. greentext = properties.getBoolean("greentext",true);
  105. FFF = properties.getBoolean("FFF",true);
  106. quakeColors = properties.getBoolean("quakeColors",true);
  107. cmdFabulous = properties.getBoolean("cmdFabulous",true);
  108. cmdPromote = properties.getBoolean("cmdPromote",true);
  109. cmdDemote = properties.getBoolean("cmdDemote",true);
  110. cmdWhoIs = properties.getBoolean("cmdWhoIs",true);
  111. cmdWho = properties.getBoolean("cmdWho",true);
  112. cmdRules = properties.getBoolean("cmdRules",true);
  113. cmdTp = properties.getBoolean("cmdTp",true);
  114. cmdMasstp = properties.getBoolean("cmdMasstp",true);
  115. cmdTphere = properties.getBoolean("cmdTphere",true);
  116. globalmessages = properties.getBoolean("globalmessages",true);
  117. cmdSay = properties.getBoolean("cmdSay",true);
  118. cmdEzModo = properties.getBoolean("cmdEzModo",true);
  119. stopFire = properties.getBoolean("stopFire",true);
  120. stopTnt = properties.getBoolean("stopTNT",true);
  121. rules = properties.getString("rules", "").split("@");
  122. String[] tempEz = properties.getString("ezModo").split(",");
  123. ezModo = new ArrayList<String>();
  124. for(int i = 0; i < tempEz.length; i++)
  125. ezModo.add(tempEz[i]);
  126. ezHealth = properties.getInt("ezHealth");
  127. log.log(Level.INFO, "vminecraft plugin successfully loaded");
  128. }
  129. catch (Exception e)
  130. {
  131. log.log(Level.SEVERE, "vminecraft Error: ERROR LOADING PROPERTIES FILE");
  132. }
  133. }
  134. //=====================================================================
  135. //Function: adminchat, greentext, FFF, quakeColors, cmdFabulous,
  136. // cmdPromote, cmdDemote, cmdWhoIs, cmdTp, cmdTphere, cmdSay
  137. // cmdRules, globalmessages, cmdMasstp, cmdEzModo
  138. //Input: None
  139. //Output: Boolan: If the feature is enabled
  140. //Use: Returns if the feature is enabled
  141. //=====================================================================
  142. public boolean adminchat() {return adminChat;}
  143. public boolean greentext() {return greentext;}
  144. public boolean FFF() {return FFF;}
  145. public boolean quakeColors() {return quakeColors;}
  146. public boolean cmdFabulous() {return cmdFabulous;}
  147. public boolean cmdPromote() {return cmdPromote;}
  148. public boolean cmdDemote() {return cmdDemote;}
  149. public boolean cmdWhoIs() {return cmdWhoIs;}
  150. public boolean cmdTp() {return cmdTp;}
  151. public boolean cmdTphere() {return cmdTphere;}
  152. public boolean cmdSay() {return cmdSay;}
  153. public boolean cmdRules() {return cmdRules;}
  154. public boolean globalmessages() {return globalmessages;}
  155. public boolean cmdMasstp() {return cmdMasstp;}
  156. public boolean cmdEzModo() {return cmdEzModo;}
  157. public boolean cmdWho() {return cmdWho;}
  158. public boolean stopFire() {return stopFire;}
  159. public boolean stopTnt() {return stopTnt;}
  160. //EzModo functions
  161. public boolean isEzModo(String playerName) {return ezModo.contains(playerName);}
  162. public void removeEzModo(String playerName) {ezModo.remove(ezModo.indexOf(playerName));}
  163. public void addEzModo(String playerName) {ezModo.add(playerName);}
  164. public int ezModoHealth() {return ezHealth;}
  165. public String ezModoList() {return ezModo.toString();}
  166. //=====================================================================
  167. //Function: getInstance
  168. //Input: None
  169. //Output: vminecraftSettings: The instance of the settings
  170. //Use: Returns the instance of the settings
  171. //=====================================================================
  172. public static vminecraftSettings getInstance() {
  173. if (instance == null) {
  174. instance = new vminecraftSettings();
  175. }
  176. return instance;
  177. }
  178. //=====================================================================
  179. //Function: getRules
  180. //Input: None
  181. //Output: String[]: The list of rules
  182. //Use: Gets the array containing the rules
  183. //=====================================================================
  184. public String[] getRules() {
  185. return rules;
  186. }
  187. }