vMinecraftSettings.java 12 KB

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