vminecraftSettings.java 8.6 KB

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