vminecraftSettings.java 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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() throws IOException
  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. properties.load();
  91. }
  92. try {
  93. adminChat = properties.getBoolean("adminchat",true);
  94. greentext = properties.getBoolean("greentext",true);
  95. FFF = properties.getBoolean("FFF",true);
  96. quakeColors = properties.getBoolean("quakeColors",true);
  97. cmdFabulous = properties.getBoolean("cmdFabulous",true);
  98. cmdPromote = properties.getBoolean("cmdPromote",true);
  99. cmdDemote = properties.getBoolean("cmdDemote",true);
  100. cmdWhoIs = properties.getBoolean("cmdWhoIs",true);
  101. cmdWhoIs = properties.getBoolean("cmdWho",true);
  102. cmdRules = properties.getBoolean("cmdRules",true);
  103. cmdTp = properties.getBoolean("cmdTp",true);
  104. cmdMasstp = properties.getBoolean("cmdMasstp",true);
  105. cmdTphere = properties.getBoolean("cmdTphere",true);
  106. globalmessages = properties.getBoolean("globalmessages",true);
  107. cmdSay = properties.getBoolean("cmdSay",true);
  108. cmdEzModo = properties.getBoolean("cmdEzModo",true);
  109. rules = properties.getString("rules", "").split("@");
  110. String[] tempEz = properties.getString("ezModo").split(",");
  111. ezModo = new ArrayList<String>();
  112. for(int i = 0; i < tempEz.length; i++)
  113. ezModo.add(tempEz[i]);
  114. ezHealth = properties.getInt("ezHealth");
  115. log.log(Level.INFO, "vminecraft plugin successfully loaded");
  116. }
  117. catch (Exception e)
  118. {
  119. log.log(Level.SEVERE, "vminecraft Error: ERROR LOADING PROPERTIES FILE");
  120. }
  121. }
  122. //=====================================================================
  123. //Function: adminchat, greentext, FFF, quakeColors, cmdFabulous,
  124. // cmdPromote, cmdDemote, cmdWhoIs, cmdTp, cmdTphere, cmdSay
  125. // cmdRules, globalmessages, cmdMasstp, cmdEzModo
  126. //Input: None
  127. //Output: Boolan: If the feature is enabled
  128. //Use: Returns if the feature is enabled
  129. //=====================================================================
  130. public boolean adminchat() {return adminChat;}
  131. public boolean greentext() {return greentext;}
  132. public boolean FFF() {return FFF;}
  133. public boolean quakeColors() {return quakeColors;}
  134. public boolean cmdFabulous() {return cmdFabulous;}
  135. public boolean cmdPromote() {return cmdPromote;}
  136. public boolean cmdDemote() {return cmdDemote;}
  137. public boolean cmdWhoIs() {return cmdWhoIs;}
  138. public boolean cmdTp() {return cmdTp;}
  139. public boolean cmdTphere() {return cmdTphere;}
  140. public boolean cmdSay() {return cmdSay;}
  141. public boolean cmdRules() {return cmdRules;}
  142. public boolean globalmessages() {return globalmessages;}
  143. public boolean cmdMasstp() {return cmdMasstp;}
  144. public boolean cmdEzModo() {return cmdEzModo;}
  145. public boolean cmdWho() {return cmdWho;}
  146. //EzModo functions
  147. public boolean isEzModo(String playerName) {return ezModo.contains(playerName);}
  148. public void removeEzModo(String playerName) {ezModo.remove(ezModo.indexOf(playerName));}
  149. public void addEzModo(String playerName) {ezModo.add(playerName);}
  150. public int ezModoHealth() {return ezHealth;}
  151. public String ezModoList() {return ezModo.toString();}
  152. //=====================================================================
  153. //Function: getInstance
  154. //Input: None
  155. //Output: vminecraftSettings: The instance of the settings
  156. //Use: Returns the instance of the settings
  157. //=====================================================================
  158. public static vminecraftSettings getInstance() {
  159. if (instance == null) {
  160. instance = new vminecraftSettings();
  161. }
  162. return instance;
  163. }
  164. //=====================================================================
  165. //Function: getRules
  166. //Input: None
  167. //Output: String[]: The list of rules
  168. //Use: Gets the array containing the rules
  169. //=====================================================================
  170. public String[] getRules() {
  171. return rules;
  172. }
  173. }