vConfig.java 16 KB

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