vMinecraftSettings.java 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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. //The feature settings
  15. static boolean toggle = true,
  16. adminChat = false,
  17. greentext = false,
  18. FFF = false,
  19. quakeColors = false,
  20. cmdFabulous = false,
  21. cmdPromote = false,
  22. cmdDemote = false,
  23. cmdWhoIs = false,
  24. cmdRules = false,
  25. cmdMasstp = false,
  26. cmdTp = false,
  27. cmdTphere = false,
  28. globalmessages = false,
  29. cmdSay = false,
  30. cmdWho = false,
  31. stopFire = false,
  32. stopTnt = false,
  33. cmdHeal = false,
  34. cmdSuicide = false,
  35. cmdAdminToggle = false,
  36. cmdEzModo = false;
  37. //An array of players currently in ezmodo
  38. static ArrayList<String> ezModo = new ArrayList<String>();
  39. //An array of players currently toggled for admin chat
  40. static ArrayList<String> adminChatList = new ArrayList<String>();
  41. //The max health for ezModo
  42. static int ezHealth = 30;
  43. private PropertiesFile properties;
  44. String file = "vminecraft.properties";
  45. public String rules[] = new String[0];
  46. public static String deathMessages[] = new String[0];
  47. //=====================================================================
  48. //Function: loadSettings
  49. //Input: None
  50. //Output: None
  51. //Use: Loads the settings from the properties
  52. //=====================================================================
  53. public void loadSettings()
  54. {
  55. File theDir = new File("vminecraft.properties");
  56. if(!theDir.exists()){
  57. String location = "vminecraft.properties";
  58. properties = new PropertiesFile("vminecraft.properties");
  59. FileWriter writer = null;
  60. try {
  61. writer = new FileWriter(location);
  62. writer.write("#This plugin is modular\r\n");
  63. writer.write("#Turn any features you don't want to false and they won't be running\r\n");
  64. writer.write("#If you edit this file and save it, then use /reload it will reload the settings\r\n");
  65. writer.write("greentext=true\r\n");
  66. writer.write("quakeColors=true\r\n");
  67. writer.write("cmdTphere=true\r\n");
  68. writer.write("cmdFabulous=true\r\n");
  69. writer.write("cmdWhoIs=true\r\n");
  70. writer.write("cmdWho=true\r\n");
  71. writer.write("cmdPromote=true\r\n");
  72. writer.write("cmdDemote=true\r\n");
  73. writer.write("cmdMasstp=true\r\n");
  74. writer.write("cmdSay=true\r\n");
  75. writer.write("cmdTp=true\r\n");
  76. writer.write("cmdRules=true\r\n");
  77. writer.write("cmdSuicide=true\r\n");
  78. writer.write("cmdAdminToggle=true\r\n");
  79. writer.write("globalmessages=true\r\n");
  80. writer.write("FFF=true\r\n");
  81. writer.write("adminchat=true\r\n");
  82. writer.write("cmdEzModo=true\r\n");
  83. writer.write("#Adding player names to this list will have them start off in ezmodo\r\n");
  84. writer.write("ezModo=\r\n");
  85. writer.write("#The health ezmodo people will have while in ezmodo. Don't set to 0\r\n");
  86. writer.write("ezHealth=30\r\n");
  87. writer.write("stopFire=false\r\n");
  88. writer.write("stopTnt=false\r\n");
  89. writer.write("rules=Rules@#1: No griefing@#2: No griefing\r\n");
  90. writer.write("#Death messages, seperate them by comma. All death messages start with the player name and a space.\r\n");
  91. writer.write("deathMessages=is no more,died horribly,went peacefully\r\n");
  92. } catch (Exception e) {
  93. log.log(Level.SEVERE, "Exception while creating " + location, e);
  94. } finally {
  95. try {
  96. if (writer != null) {
  97. writer.close();
  98. }
  99. } catch (IOException e) {
  100. log.log(Level.SEVERE, "Exception while closing writer for " + location, e);
  101. }
  102. }
  103. } else {
  104. properties = new PropertiesFile("vminecraft.properties");
  105. try {
  106. properties.load();
  107. } catch (IOException e) {
  108. log.log(Level.SEVERE, "Exception while loading vminecraft.properties", e);
  109. }
  110. }
  111. try {
  112. adminChat = properties.getBoolean("adminchat",true);
  113. greentext = properties.getBoolean("greentext",true);
  114. FFF = properties.getBoolean("FFF",true);
  115. quakeColors = properties.getBoolean("quakeColors",true);
  116. cmdFabulous = properties.getBoolean("cmdFabulous",true);
  117. cmdPromote = properties.getBoolean("cmdPromote",true);
  118. cmdDemote = properties.getBoolean("cmdDemote",true);
  119. cmdWhoIs = properties.getBoolean("cmdWhoIs",true);
  120. cmdWho = properties.getBoolean("cmdWho",true);
  121. cmdRules = properties.getBoolean("cmdRules",true);
  122. cmdTp = properties.getBoolean("cmdTp",true);
  123. cmdMasstp = properties.getBoolean("cmdMasstp",true);
  124. cmdTphere = properties.getBoolean("cmdTphere",true);
  125. cmdSuicide = properties.getBoolean("cmdSuicide", true);
  126. cmdHeal = properties.getBoolean("cmdHeal",true);
  127. cmdAdminToggle = properties.getBoolean("cmdAdminToggle", true);
  128. globalmessages = properties.getBoolean("globalmessages",true);
  129. cmdSay = properties.getBoolean("cmdSay",true);
  130. cmdEzModo = properties.getBoolean("cmdEzModo",true);
  131. stopFire = properties.getBoolean("stopFire",true);
  132. stopTnt = properties.getBoolean("stopTNT",true);
  133. rules = properties.getString("rules", "").split("@");
  134. deathMessages = properties.getString("deathmessages", "").split(",");
  135. String[] tempEz = properties.getString("ezModo").split(",");
  136. ezModo = new ArrayList<String>();
  137. for(String ezName : tempEz)
  138. ezModo.add(ezName);
  139. ezHealth = properties.getInt("ezHealth");
  140. log.log(Level.INFO, "vminecraft plugin successfully loaded");
  141. }
  142. catch (Exception e)
  143. {
  144. log.log(Level.SEVERE, "vminecraft Error: ERROR LOADING PROPERTIES FILE");
  145. }
  146. }
  147. //=====================================================================
  148. //Function: adminchat, greentext, FFF, quakeColors, cmdFabulous,
  149. // cmdPromote, cmdDemote, cmdWhoIs, cmdTp, cmdTphere, cmdSay
  150. // cmdRules, globalmessages, cmdMasstp, cmdEzModo
  151. //Input: None
  152. //Output: Boolan: If the feature is enabled
  153. //Use: Returns if the feature is enabled
  154. //=====================================================================
  155. public boolean adminchat() {return adminChat;}
  156. public boolean adminChatToggle() {return cmdAdminToggle;}
  157. public boolean greentext() {return greentext;}
  158. public boolean FFF() {return FFF;}
  159. public boolean quakeColors() {return quakeColors;}
  160. public boolean cmdFabulous() {return cmdFabulous;}
  161. public boolean cmdPromote() {return cmdPromote;}
  162. public boolean cmdDemote() {return cmdDemote;}
  163. public boolean cmdWhoIs() {return cmdWhoIs;}
  164. public boolean cmdTp() {return cmdTp;}
  165. public boolean cmdTphere() {return cmdTphere;}
  166. public boolean cmdSay() {return cmdSay;}
  167. public boolean cmdRules() {return cmdRules;}
  168. public boolean globalmessages() {return globalmessages;}
  169. public boolean cmdMasstp() {return cmdMasstp;}
  170. public boolean cmdWho() {return cmdWho;}
  171. public boolean stopFire() {return stopFire;}
  172. public boolean stopTnt() {return stopTnt;}
  173. public boolean cmdSuicide() {return cmdSuicide;}
  174. public boolean cmdHeal() {return cmdHeal;}
  175. //EzModo methods
  176. public boolean cmdEzModo() {return cmdEzModo;}
  177. public boolean isEzModo(String playerName) {return ezModo.contains(playerName);}
  178. public boolean isAdminToggled(String playerName) {return adminChatList.contains(playerName);}
  179. public void removeEzModo(String playerName) {ezModo.remove(ezModo.indexOf(playerName));}
  180. public void removeAdminToggled(String playerName) {adminChatList.remove(adminChatList.indexOf(playerName));}
  181. public void addEzModo(String playerName) {ezModo.add(playerName);}
  182. public void addAdminToggled(String playerName) {adminChatList.add(playerName);}
  183. public int ezModoHealth() {return ezHealth;}
  184. public String ezModoList() {return ezModo.toString();}
  185. //Random death message method
  186. public static String randomDeathMsg() {
  187. if (deathMessages == null) {
  188. return "died";
  189. }
  190. return deathMessages[ (int) (Math.random() * deathMessages.length)];
  191. }
  192. //=====================================================================
  193. //Function: getInstance
  194. //Input: None
  195. //Output: vminecraftSettings: The instance of the settings
  196. //Use: Returns the instance of the settings
  197. //=====================================================================
  198. public static vMinecraftSettings getInstance() {
  199. if (instance == null) {
  200. instance = new vMinecraftSettings();
  201. }
  202. return instance;
  203. }
  204. //=====================================================================
  205. //Function: getRules
  206. //Input: None
  207. //Output: String[]: The list of rules
  208. //Use: Gets the array containing the rules
  209. //=====================================================================
  210. public String[] getRules() {
  211. return rules;
  212. }
  213. }