vminecraftSettings.java 8.1 KB

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