vMinecraftSettings.java 11 KB

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