vMinecraftSettings.java 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  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. prefix = false,
  21. suffix = false,
  22. ignore = false,
  23. colors = false,
  24. nick = false,
  25. freeze = false,
  26. cmdFabulous = false,
  27. cmdPromote = false,
  28. cmdDemote = false,
  29. cmdWhoIs = false,
  30. cmdRules = false,
  31. cmdMasstp = false,
  32. cmdTp = false,
  33. cmdTphere = false,
  34. globalmessages = false,
  35. cmdSay = false,
  36. cmdWho = false,
  37. stopFire = false,
  38. stopTnt = false,
  39. cmdHeal = false,
  40. cmdSuicide = false,
  41. cmdAdminToggle = false,
  42. cmdEzModo = false;
  43. //An array of players currently in ezmodo
  44. static ArrayList<String> ezModo = new ArrayList<String>();
  45. //An array of players currently frozen
  46. static ArrayList<String> frozenplayers = new ArrayList<String>();
  47. //An array of players currently toggled for admin chat
  48. static ArrayList<String> adminChatList = new ArrayList<String>();
  49. //An array of blocks that won't catch on fire
  50. private PropertiesFile properties;
  51. String file = "vminecraft.properties";
  52. public String rules[] = new String[0];
  53. public static String deathMessages[] = new String[0];
  54. public static String ranks[] = new String[0];
  55. //=====================================================================
  56. //Function: loadSettings
  57. //Input: None
  58. //Output: None
  59. //Use: Loads the settings from the properties
  60. //=====================================================================
  61. public void loadSettings()
  62. {
  63. File theDir = new File("vminecraft.properties");
  64. if(!theDir.exists()){
  65. String location = "vminecraft.properties";
  66. properties = new PropertiesFile("vminecraft.properties");
  67. FileWriter writer = null;
  68. try {
  69. writer = new FileWriter(location);
  70. writer.write("#This plugin is modular\r\n");
  71. writer.write("#Turn any features you don't want to false and they won't be running\r\n");
  72. writer.write("#If you edit this file and save it, then use /reload it will reload the settings\r\n");
  73. writer.write("#Chat Options\r\n");
  74. writer.write("#Allows the use of color codes following ^ symbol\r\n");
  75. writer.write("ColoredChat=true\r\n");
  76. writer.write("#Text following a > will be colored green to mimic quoting of popular internet message boards\r\n");
  77. writer.write("QuotesAreGreen=true\r\n");
  78. writer.write("#Turns any chat message starting with FFF automagically blood red\r\n");
  79. writer.write("FFF=true\r\n");
  80. writer.write("\r\n");
  81. writer.write("#Admin Settings\r\n");
  82. writer.write("#Enables or disables the admin only chat\r\n");
  83. writer.write("adminchat=true\r\n");
  84. writer.write("#Lets non admins use admin chat if they have the /adminchat command permission\r\n");
  85. writer.write("/adminchat=true\r\n");
  86. writer.write("#Enables overriding of regular /tp and /tphere to make it so you can only teleport to players with lower permissions, and only bring players of lower permissions to you\r\n");
  87. writer.write("/tp=true\r\n");
  88. writer.write("/tphere=true\r\n");
  89. writer.write("#Mass Tp uses the same concept, anyone with this command only brings those with lower permissions to themselves\r\n");
  90. writer.write("/masstp=true\r\n");
  91. writer.write("\r\n");
  92. writer.write("#Server Settings\r\n");
  93. writer.write("#Enables or Disables the following commands, give groups/users permissions to use these commands for them to work\r\n");
  94. writer.write("/fabulous=true\r\n");
  95. writer.write("/prefix=true\r\n");
  96. writer.write("/freeze=true\r\n");
  97. writer.write("/suffix=true\r\n");
  98. writer.write("/ignore=true\r\n");
  99. writer.write("/colors=true\r\n");
  100. writer.write("/whois=true\r\n");
  101. writer.write("/nick=true\r\n");
  102. writer.write("/who=true\r\n");
  103. writer.write("/promote=true\r\n");
  104. writer.write("/demote=true\r\n");
  105. writer.write("/say=true\r\n");
  106. writer.write("/rules=true\r\n");
  107. writer.write("/suicide=true\r\n");
  108. writer.write("/ezmodo=true\r\n");
  109. writer.write("#Global Messages\r\n");
  110. writer.write("#Enable or Disable sending announcements about sensitive commands to the entire server\r\n");
  111. writer.write("globalmessages=true\r\n");
  112. writer.write("\r\n");
  113. writer.write("#Adding player names to this list will have them start off in ezmodo\r\n");
  114. writer.write("ezModo=\r\n");
  115. writer.write("#Stop fire from spreading\r\n");
  116. writer.write("stopFire=false\r\n");
  117. writer.write("\r\n");
  118. writer.write("#Organize your player ranks from lowest to highest.\r\n");
  119. writer.write("ranks=default,trusted,mods,admins,superadmins\r\n");
  120. writer.write("#Write the rules to be shown when /rules is used here, it works just like the MOTD does\r\n");
  121. writer.write("rules=Rules@#1: No griefing@#2: No griefing\r\n");
  122. writer.write("#The Random Death messages, seperate them by comma. All death messages start with the player name and a space.\r\n");
  123. writer.write("deathMessages=is no more,died horribly,went peacefully\r\n");
  124. } catch (Exception e) {
  125. log.log(Level.SEVERE, "Exception while creating " + location, e);
  126. } finally {
  127. try {
  128. if (writer != null) {
  129. writer.close();
  130. }
  131. } catch (IOException e) {
  132. log.log(Level.SEVERE, "Exception while closing writer for " + location, e);
  133. }
  134. }
  135. } else {
  136. properties = new PropertiesFile("vminecraft.properties");
  137. try {
  138. properties.load();
  139. } catch (IOException e) {
  140. log.log(Level.SEVERE, "Exception while loading vminecraft.properties", e);
  141. }
  142. }
  143. try {
  144. adminChat = properties.getBoolean("adminchat",true);
  145. greentext = properties.getBoolean("QuotesAreGreen",true);
  146. FFF = properties.getBoolean("FFF",true);
  147. quakeColors = properties.getBoolean("ColoredChat",true);
  148. prefix = properties.getBoolean("prefix",true);
  149. suffix = properties.getBoolean("suffix",true);
  150. ignore = properties.getBoolean("ignore",true);
  151. colors = properties.getBoolean("colors",true);
  152. nick = properties.getBoolean("nick",true);
  153. cmdFabulous = properties.getBoolean("/fabulous",true);
  154. cmdPromote = properties.getBoolean("/promote",true);
  155. cmdDemote = properties.getBoolean("/demote",true);
  156. cmdWhoIs = properties.getBoolean("/whois",true);
  157. cmdWho = properties.getBoolean("/who",true);
  158. cmdRules = properties.getBoolean("/rules",true);
  159. cmdTp = properties.getBoolean("/tp",true);
  160. cmdMasstp = properties.getBoolean("/masstp",true);
  161. cmdTphere = properties.getBoolean("/tphere",true);
  162. cmdSuicide = properties.getBoolean("/suicide", true);
  163. cmdHeal = properties.getBoolean("/heal",true);
  164. cmdAdminToggle = properties.getBoolean("/adminchat", true);
  165. globalmessages = properties.getBoolean("globalmessages",true);
  166. cmdSay = properties.getBoolean("/say",true);
  167. cmdEzModo = properties.getBoolean("/ezmodo",true);
  168. stopFire = properties.getBoolean("stopFire",true);
  169. rules = properties.getString("rules", "").split("@");
  170. deathMessages = properties.getString("deathmessages", "").split(",");
  171. String[] tempEz = properties.getString("ezModo").split(",");
  172. ezModo = new ArrayList<String>();
  173. for(String ezName : tempEz)
  174. ezModo.add(ezName);
  175. ranks = properties.getString("ranks").split(",");
  176. log.log(Level.INFO, "vminecraft plugin successfully loaded");
  177. }
  178. catch (Exception e)
  179. {
  180. log.log(Level.SEVERE, "vminecraft Error: ERROR LOADING PROPERTIES FILE");
  181. }
  182. }
  183. //=====================================================================
  184. //Function: adminchat, greentext, FFF, quakeColors, cmdFabulous,
  185. // cmdPromote, cmdDemote, cmdWhoIs, cmdTp, cmdTphere, cmdSay
  186. // cmdRules, globalmessages, cmdMasstp, cmdEzModo
  187. //Input: None
  188. //Output: Boolan: If the feature is enabled
  189. //Use: Returns if the feature is enabled
  190. //=====================================================================
  191. public boolean adminchat() {return adminChat;}
  192. public boolean adminChatToggle() {return cmdAdminToggle;}
  193. public boolean greentext() {return greentext;}
  194. public boolean FFF() {return FFF;}
  195. public boolean quakeColors() {return quakeColors;}
  196. public boolean prefix() {return prefix;}
  197. public boolean suffix() {return suffix;}
  198. public boolean ignore() {return ignore;}
  199. public boolean colors() {return colors;}
  200. public boolean nick() {return nick;}
  201. public boolean freeze() {return freeze;}
  202. public boolean cmdFabulous() {return cmdFabulous;}
  203. public boolean cmdPromote() {return cmdPromote;}
  204. public boolean cmdDemote() {return cmdDemote;}
  205. public boolean cmdWhoIs() {return cmdWhoIs;}
  206. public boolean cmdTp() {return cmdTp;}
  207. public boolean cmdTphere() {return cmdTphere;}
  208. public boolean cmdSay() {return cmdSay;}
  209. public boolean cmdRules() {return cmdRules;}
  210. public boolean globalmessages() {return globalmessages;}
  211. public boolean cmdMasstp() {return cmdMasstp;}
  212. public boolean cmdWho() {return cmdWho;}
  213. public boolean stopFire() {return stopFire;}
  214. public boolean stopTnt() {return stopTnt;}
  215. public boolean cmdSuicide() {return cmdSuicide;}
  216. public boolean cmdHeal() {return cmdHeal;}
  217. public String[] getRanks() {return ranks;}
  218. //EzModo methods
  219. public boolean cmdEzModo() {return cmdEzModo;}
  220. public boolean isEzModo(String playerName) {return ezModo.contains(playerName);}
  221. public boolean isAdminToggled(String playerName) {return adminChatList.contains(playerName);}
  222. public void removeEzModo(String playerName) {ezModo.remove(ezModo.indexOf(playerName));}
  223. public void removeAdminToggled(String playerName) {adminChatList.remove(adminChatList.indexOf(playerName));}
  224. public void addEzModo(String playerName) {ezModo.add(playerName);}
  225. public void addAdminToggled(String playerName) {adminChatList.add(playerName);}
  226. public void addFrozen(String playerName) {frozenplayers.add(playerName);}
  227. public void removeFrozen (String playerName) {frozenplayers.remove(frozenplayers.indexOf(playerName));}
  228. public String ezModoList() {return ezModo.toString();}
  229. //Random death message method
  230. public static String randomDeathMsg() {
  231. if (deathMessages == null) {
  232. return "died";
  233. }
  234. return deathMessages[ (int) (Math.random() * deathMessages.length)];
  235. }
  236. //=====================================================================
  237. //Function: getInstance
  238. //Input: None
  239. //Output: vminecraftSettings: The instance of the settings
  240. //Use: Returns the instance of the settings
  241. //=====================================================================
  242. public static vMinecraftSettings getInstance() {
  243. if (instance == null) {
  244. instance = new vMinecraftSettings();
  245. }
  246. return instance;
  247. }
  248. //=====================================================================
  249. //Function: getRules
  250. //Input: None
  251. //Output: String[]: The list of rules
  252. //Use: Gets the array containing the rules
  253. //=====================================================================
  254. public String[] getRules() {
  255. return rules;
  256. }
  257. }