vMinecraftSettings.java 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. import java.io.*;
  2. import java.util.ArrayList;
  3. import java.util.logging.Level;
  4. import java.util.Set;
  5. import java.util.logging.Logger;
  6. //=====================================================================
  7. //Class: vminecraftSettings
  8. //Use: Controls the settings for vminecraft
  9. //Author: nossr50, TrapAlice, cerevisiae
  10. //=====================================================================
  11. public class vMinecraftSettings {
  12. //private final static Object syncLock = new Object();
  13. protected static final Logger log = Logger.getLogger("Minecraft");
  14. private static volatile vMinecraftSettings instance;
  15. //The block IDs fire won't spread to will be stored here
  16. public static Set<Integer> fireNoSpread;
  17. //The feature settings
  18. static boolean toggle = true,
  19. adminChat = false,
  20. greentext = false,
  21. FFF = false,
  22. quakeColors = false,
  23. cmdFabulous = false,
  24. cmdPromote = false,
  25. cmdDemote = false,
  26. cmdWhoIs = false,
  27. cmdRules = false,
  28. cmdMasstp = false,
  29. cmdTp = false,
  30. cmdTphere = false,
  31. globalmessages = false,
  32. cmdSay = false,
  33. cmdWho = false,
  34. stopFire = false,
  35. stopTnt = false,
  36. cmdHeal = false,
  37. cmdSuicide = false,
  38. cmdAdminToggle = false,
  39. cmdEzModo = false;
  40. //An array of players currently in ezmodo
  41. static ArrayList<String> ezModo = new ArrayList<String>();
  42. //An array of players currently toggled for admin chat
  43. static ArrayList<String> adminChatList = new ArrayList<String>();
  44. //An array of blocks that won't catch on fire
  45. private PropertiesFile properties;
  46. String file = "vminecraft.properties";
  47. public String rules[] = new String[0];
  48. public static String deathMessages[] = new String[0];
  49. //=====================================================================
  50. //Function: loadSettings
  51. //Input: None
  52. //Output: None
  53. //Use: Loads the settings from the properties
  54. //=====================================================================
  55. public void loadSettings()
  56. {
  57. File theDir = new File("vminecraft.properties");
  58. if(!theDir.exists()){
  59. String location = "vminecraft.properties";
  60. properties = new PropertiesFile("vminecraft.properties");
  61. FileWriter writer = null;
  62. try {
  63. writer = new FileWriter(location);
  64. writer.write("#This plugin is modular\r\n");
  65. writer.write("#Turn any features you don't want to false and they won't be running\r\n");
  66. writer.write("#If you edit this file and save it, then use /reload it will reload the settings\r\n");
  67. writer.write("greentext=true\r\n");
  68. writer.write("quakeColors=true\r\n");
  69. writer.write("cmdTphere=true\r\n");
  70. writer.write("cmdFabulous=true\r\n");
  71. writer.write("cmdWhoIs=true\r\n");
  72. writer.write("cmdWho=true\r\n");
  73. writer.write("cmdPromote=true\r\n");
  74. writer.write("cmdDemote=true\r\n");
  75. writer.write("cmdMasstp=true\r\n");
  76. writer.write("cmdSay=true\r\n");
  77. writer.write("cmdTp=true\r\n");
  78. writer.write("cmdRules=true\r\n");
  79. writer.write("cmdSuicide=true\r\n");
  80. writer.write("cmdAdminToggle=true\r\n");
  81. writer.write("globalmessages=true\r\n");
  82. writer.write("FFF=true\r\n");
  83. writer.write("adminchat=true\r\n");
  84. writer.write("cmdEzModo=true\r\n");
  85. writer.write("#Adding player names to this list will have them start off in ezmodo\r\n");
  86. writer.write("ezModo=\r\n");
  87. writer.write("stopFire=false\r\n");
  88. writer.write("#Flame Immune blocks will never have fire spread to them, seperate with comma. Needs stopFire to be true\r\n");
  89. writer.write("fireNoSpread=5,17,18");
  90. writer.write("stopTnt=false\r\n");
  91. writer.write("rules=Rules@#1: No griefing@#2: No griefing\r\n");
  92. writer.write("#Death messages, seperate them by comma. All death messages start with the player name and a space.\r\n");
  93. writer.write("deathMessages=is no more,died horribly,went peacefully\r\n");
  94. } catch (Exception e) {
  95. log.log(Level.SEVERE, "Exception while creating " + location, e);
  96. } finally {
  97. try {
  98. if (writer != null) {
  99. writer.close();
  100. }
  101. } catch (IOException e) {
  102. log.log(Level.SEVERE, "Exception while closing writer for " + location, e);
  103. }
  104. }
  105. } else {
  106. properties = new PropertiesFile("vminecraft.properties");
  107. try {
  108. properties.load();
  109. } catch (IOException e) {
  110. log.log(Level.SEVERE, "Exception while loading vminecraft.properties", e);
  111. }
  112. }
  113. try {
  114. adminChat = properties.getBoolean("adminchat",true);
  115. greentext = properties.getBoolean("greentext",true);
  116. FFF = properties.getBoolean("FFF",true);
  117. quakeColors = properties.getBoolean("quakeColors",true);
  118. cmdFabulous = properties.getBoolean("cmdFabulous",true);
  119. cmdPromote = properties.getBoolean("cmdPromote",true);
  120. cmdDemote = properties.getBoolean("cmdDemote",true);
  121. cmdWhoIs = properties.getBoolean("cmdWhoIs",true);
  122. cmdWho = properties.getBoolean("cmdWho",true);
  123. cmdRules = properties.getBoolean("cmdRules",true);
  124. cmdTp = properties.getBoolean("cmdTp",true);
  125. cmdMasstp = properties.getBoolean("cmdMasstp",true);
  126. cmdTphere = properties.getBoolean("cmdTphere",true);
  127. cmdSuicide = properties.getBoolean("cmdSuicide", true);
  128. cmdHeal = properties.getBoolean("cmdHeal",true);
  129. cmdAdminToggle = properties.getBoolean("cmdAdminToggle", true);
  130. globalmessages = properties.getBoolean("globalmessages",true);
  131. cmdSay = properties.getBoolean("cmdSay",true);
  132. cmdEzModo = properties.getBoolean("cmdEzModo",true);
  133. stopFire = properties.getBoolean("stopFire",true);
  134. stopTnt = properties.getBoolean("stopTNT",true);
  135. rules = properties.getString("rules", "").split("@");
  136. deathMessages = properties.getString("deathmessages", "").split(",");
  137. String[] tempEz = properties.getString("ezModo").split(",");
  138. ezModo = new ArrayList<String>();
  139. for(String ezName : tempEz)
  140. ezModo.add(ezName);
  141. log.log(Level.INFO, "vminecraft plugin successfully loaded");
  142. }
  143. catch (Exception e)
  144. {
  145. log.log(Level.SEVERE, "vminecraft Error: ERROR LOADING PROPERTIES FILE");
  146. }
  147. }
  148. //=====================================================================
  149. //Function: adminchat, greentext, FFF, quakeColors, cmdFabulous,
  150. // cmdPromote, cmdDemote, cmdWhoIs, cmdTp, cmdTphere, cmdSay
  151. // cmdRules, globalmessages, cmdMasstp, cmdEzModo
  152. //Input: None
  153. //Output: Boolan: If the feature is enabled
  154. //Use: Returns if the feature is enabled
  155. //=====================================================================
  156. public boolean adminchat() {return adminChat;}
  157. public boolean adminChatToggle() {return cmdAdminToggle;}
  158. public boolean greentext() {return greentext;}
  159. public boolean FFF() {return FFF;}
  160. public boolean quakeColors() {return quakeColors;}
  161. public boolean cmdFabulous() {return cmdFabulous;}
  162. public boolean cmdPromote() {return cmdPromote;}
  163. public boolean cmdDemote() {return cmdDemote;}
  164. public boolean cmdWhoIs() {return cmdWhoIs;}
  165. public boolean cmdTp() {return cmdTp;}
  166. public boolean cmdTphere() {return cmdTphere;}
  167. public boolean cmdSay() {return cmdSay;}
  168. public boolean cmdRules() {return cmdRules;}
  169. public boolean globalmessages() {return globalmessages;}
  170. public boolean cmdMasstp() {return cmdMasstp;}
  171. public boolean cmdWho() {return cmdWho;}
  172. public boolean stopFire() {return stopFire;}
  173. public boolean stopTnt() {return stopTnt;}
  174. public boolean cmdSuicide() {return cmdSuicide;}
  175. public boolean cmdHeal() {return cmdHeal;}
  176. //EzModo methods
  177. public boolean cmdEzModo() {return cmdEzModo;}
  178. public boolean isEzModo(String playerName) {return ezModo.contains(playerName);}
  179. public boolean isAdminToggled(String playerName) {return adminChatList.contains(playerName);}
  180. public void removeEzModo(String playerName) {ezModo.remove(ezModo.indexOf(playerName));}
  181. public void removeAdminToggled(String playerName) {adminChatList.remove(adminChatList.indexOf(playerName));}
  182. public void addEzModo(String playerName) {ezModo.add(playerName);}
  183. public void addAdminToggled(String playerName) {adminChatList.add(playerName);}
  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. }