vConfig.java 15 KB

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