vMinecraftSettings.java 15 KB

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