vMinecraftSettings.java 12 KB

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