vminecraftSettings.java 8.5 KB

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