PageRenderTime 882ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/src/etc.java

http://github.com/traitor/Minecraft-Server-Mod
Java | 1080 lines | 560 code | 113 blank | 407 comment | 96 complexity | 7d6e5c7d09ff7d0f2700b2f78b53d799 MD5 | raw file
  1. import java.io.BufferedReader;
  2. import java.io.File;
  3. import java.io.IOException;
  4. import java.io.InputStreamReader;
  5. import java.sql.Connection;
  6. import java.sql.DriverManager;
  7. import java.sql.SQLException;
  8. import java.util.ArrayList;
  9. import java.util.Collection;
  10. import java.util.HashSet;
  11. import java.util.LinkedHashMap;
  12. import java.util.List;
  13. import java.util.Set;
  14. import java.util.logging.Level;
  15. import java.util.logging.Logger;
  16. import net.minecraft.server.MinecraftServer;
  17. /**
  18. * etc.java - My catch-all class for a bunch of shit. If there's something you
  19. * need it's probably in here.
  20. *
  21. * @author James
  22. */
  23. public class etc {
  24. private static final Logger log = Logger.getLogger("Minecraft");
  25. private static final etc instance = new etc();
  26. private static MinecraftServer server;
  27. private String usersLoc = "users.txt", kitsLoc = "kits.txt", homeLoc = "homes.txt", warpLoc = "warps.txt", itemLoc = "items.txt", groupLoc = "groups.txt";
  28. private String whitelistLoc = "whitelist.txt", reservelistLoc = "reservelist.txt";
  29. private String whitelistMessage = "Not on whitelist.";
  30. private Set<Integer> allowedItems = new HashSet<Integer>();
  31. private Set<Integer> disallowedItems = new HashSet<Integer>();
  32. private Set<Integer> itemSpawnBlacklist = new HashSet<Integer>();
  33. private String[] motd = null;
  34. private boolean saveHomes = true;
  35. private boolean whitelistEnabled = false;
  36. private boolean reservelistEnabled = false;
  37. private int playerLimit = 20;
  38. private int spawnProtectionSize = 16;
  39. private LinkedHashMap<String, String> commands = new LinkedHashMap<String, String>();
  40. private String dataSourceType;
  41. private DataSource dataSource;
  42. private PropertiesFile properties;
  43. private PluginLoader loader;
  44. private boolean logging = false;
  45. private boolean enableHealth = true;
  46. private PluginLoader.HookResult autoHeal = PluginLoader.HookResult.DEFAULT_ACTION;
  47. private boolean showUnknownCommand = true;
  48. private String versionStr;
  49. private boolean tainted = true;
  50. // Version, DO NOT CHANGE (is loaded from file version.txt)!
  51. private int version = 1;
  52. private String username, password, db;
  53. private String[] animals = new String[] {};
  54. private String[] monsters = new String[] {};
  55. private String[] waterAnimals = new String[] {};
  56. private int mobSpawnRate = 100;
  57. private boolean mobReload = false;
  58. private List<OSpawnListEntry> animalsList, monsterList, waterAnimalsList;
  59. private etc() {
  60. commands.put("/help", "[Page] - Shows a list of commands. 7 per page.");
  61. commands.put("/playerlist", "- Shows a list of players");
  62. commands.put("/reload", "- Reloads config");
  63. commands.put("/banlist", "<IP or bans> - Gives a list of bans");
  64. commands.put("/banip", "[Player] <Reason> - Bans the player's IP");
  65. commands.put("/unbanip", "[IP] - Unbans the IP");
  66. commands.put("/ban", "[Player] <Reason> - Bans the player");
  67. commands.put("/unban", "[Player] - Unbans the player");
  68. commands.put("/mute", "[Player] - Toggles mute on player.");
  69. commands.put("/tp", "[Player] - Teleports to player. Credits to Zet from SA");
  70. commands.put("/tphere", "[Player] - Teleports the player to you");
  71. commands.put("/kick", "[Player] <Reason> - Kicks player");
  72. commands.put("/item", "[ID] <Amount> <Damage> <Player> - Gives items");
  73. commands.put("/cloth", "[Amount] [Color] - Gives cloth");
  74. commands.put("/kit", "[Kit] - Gives a kit. To get a list of kits type /kit");
  75. commands.put("/listwarps", "- Gives a list of available warps");
  76. commands.put("/home", "- Teleports you home");
  77. commands.put("/sethome", "- Sets your home");
  78. commands.put("/setspawn", "- Sets the spawn point to your position.");
  79. commands.put("/me", "[Message] - * hey0 says hi!");
  80. commands.put("/msg", "[Player] [Message] - Sends a message to player");
  81. commands.put("/spawn", "- Teleports you to spawn");
  82. commands.put("/warp", "[Warp] - Warps to the specified warp.");
  83. commands.put("/setwarp", "[Warp] - Sets the warp to your current position.");
  84. commands.put("/removewarp", "[Warp] - Removes the specified warp.");
  85. commands.put("/getpos", "- Displays your current position.");
  86. commands.put("/compass", "- Gives you a compass reading.");
  87. commands.put("/time", "[time|'day|night|check|raw'] (rawtime) - Changes or checks the time");
  88. commands.put("/lighter", "- Gives you a lighter for lighting furnaces");
  89. commands.put("/motd", "- Displays the MOTD");
  90. commands.put("/modify", "[player] [key] [value] - Type /modify for more info");
  91. commands.put("/whitelist", "[operation (add or remove)] [player]");
  92. commands.put("/reservelist", "[operation (add or remove)] [player]");
  93. commands.put("/enableplugin", "[plugin] - Enables plugin");
  94. commands.put("/disableplugin", "[plugin] - Disables plugin");
  95. commands.put("/listplugins", "- Lists all plugins");
  96. commands.put("/reloadplugin", "[plugin] - Reloads plugin");
  97. commands.put("/clearinventory", "- Clears your inventory");
  98. load();
  99. }
  100. private void loadIds(Collection<Integer> storage, String rawData) {
  101. for (String id : rawData.split(",")) {
  102. id = id.trim();
  103. if (id.length() > 0)
  104. try {
  105. storage.add(Integer.parseInt(id));
  106. } catch (NumberFormatException e) {
  107. log.log(Level.SEVERE, "While parsing the config: '" + id + "' is not a number");
  108. }
  109. }
  110. }
  111. /**
  112. * Loads or reloads the mod
  113. */
  114. public final void load() {
  115. if (properties == null)
  116. properties = new PropertiesFile("server.properties");
  117. else
  118. try {
  119. properties.load();
  120. } catch (IOException e) {
  121. log.log(Level.SEVERE, "Exception while reading from server.properties", e);
  122. }
  123. try {
  124. dataSourceType = properties.getString("data-source", "flatfile");
  125. loadIds(allowedItems, properties.getString("alloweditems", ""));
  126. loadIds(disallowedItems, properties.getString("disalloweditems", ""));
  127. loadIds(itemSpawnBlacklist, properties.getString("itemspawnblacklist", ""));
  128. motd = properties.getString("motd", "Type /help for a list of commands.").split("@");
  129. playerLimit = properties.getInt("max-players", 20);
  130. saveHomes = properties.getBoolean("save-homes", true);
  131. whitelistEnabled = properties.getBoolean("whitelist", false);
  132. whitelistMessage = properties.getString("whitelist-message", "Not on whitelist.");
  133. reservelistEnabled = properties.getBoolean("reservelist", false);
  134. if (dataSourceType.equalsIgnoreCase("flatfile")) {
  135. usersLoc = properties.getString("admintxtlocation", "users.txt");
  136. kitsLoc = properties.getString("kitstxtlocation", "kits.txt");
  137. homeLoc = properties.getString("homelocation", "homes.txt");
  138. warpLoc = properties.getString("warplocation", "warps.txt");
  139. itemLoc = properties.getString("itemstxtlocation", "items.txt");
  140. groupLoc = properties.getString("group-txt-location", "groups.txt");
  141. whitelistLoc = properties.getString("whitelist-txt-location", "whitelist.txt");
  142. reservelistLoc = properties.getString("reservelist-txt-location", "reservelist.txt");
  143. } else {
  144. PropertiesFile sql = new PropertiesFile("mysql.properties");
  145. sql.getString("driver", "com.mysql.jdbc.Driver");
  146. username = sql.getString("user", "root");
  147. password = sql.getString("pass", "root");
  148. db = sql.getString("db", "jdbc:mysql://localhost:3306/minecraft");
  149. }
  150. spawnProtectionSize = properties.getInt("spawn-protection-size", 16);
  151. logging = properties.getBoolean("logging", false);
  152. enableHealth = properties.getBoolean("enable-health", true);
  153. animals = properties.getString("natural-animals", "Sheep,Pig,Chicken,Cow").split(",");
  154. if (animals.length == 1 && (animals[0].equals(" ") || animals[0].equals("")))
  155. animals = new String[] {};
  156. validateMobGroup(animals, "natural-animals", new String[] { "Sheep", "Pig", "Chicken", "Cow", "Wolf" });
  157. monsters = properties.getString("natural-monsters", "Spider,Zombie,Skeleton,Creeper,Slime").split(",");
  158. if (monsters.length == 1 && (monsters[0].equals(" ") || monsters[0].equals("")))
  159. monsters = new String[] {};
  160. validateMobGroup(monsters, "natural-monsters", new String[] { "PigZombie", "Ghast", "Slime", "Giant", "Spider", "Zombie", "Skeleton", "Creeper" });
  161. waterAnimals = properties.getString("natural-wateranimals", "Squid").split(",");
  162. if (waterAnimals.length == 1 && (waterAnimals[0].equals(" ") || waterAnimals[0].equals("")))
  163. waterAnimals = new String[] {};
  164. validateMobGroup(waterAnimals, "natural-wateranimals", new String[] { "Squid" });
  165. mobReload = true;
  166. mobSpawnRate = properties.getInt("natural-spawn-rate", mobSpawnRate);
  167. String autoHealString = properties.getString("auto-heal", "default");
  168. if (autoHealString.equalsIgnoreCase("true"))
  169. autoHeal = PluginLoader.HookResult.ALLOW_ACTION;
  170. else if (autoHealString.equalsIgnoreCase("false"))
  171. autoHeal = PluginLoader.HookResult.PREVENT_ACTION;
  172. showUnknownCommand = properties.getBoolean("show-unknown-command", true);
  173. File file = new File("version.txt");
  174. if (file.exists()) {
  175. InputStreamReader ins = new InputStreamReader(file.toURI().toURL().openStream());
  176. BufferedReader bufferedReader = new BufferedReader(ins);
  177. String versionParam = bufferedReader.readLine();
  178. if (versionParam.startsWith("git-")) { // recommended
  179. // version.txt for git
  180. // builds:
  181. // git-<gituser>-<shorttag>
  182. // example: git-sk89q-591c662cf4afc8e3e09a
  183. version = -1;
  184. versionStr = versionParam;
  185. tainted = true;
  186. } else {
  187. version = Integer.parseInt(versionParam);
  188. versionStr = Integer.toString(version); // and back to a
  189. // string.
  190. tainted = false; // looks official. We hope.
  191. }
  192. ins.close();
  193. bufferedReader.close();
  194. } else {
  195. // I'm a tainted build, probably.
  196. version = -1;
  197. versionStr = "Undefined version";
  198. tainted = true;
  199. // If any mods check the version.. #@!$
  200. }
  201. } catch (Exception e) {
  202. log.log(Level.SEVERE, "Exception while reading from server.properties", e);
  203. // Just in case...
  204. motd = new String[] { "Type /help for a list of commands." };
  205. }
  206. }
  207. /**
  208. * Loads or reloads the data source
  209. */
  210. public void loadData() {
  211. if (dataSourceType.equalsIgnoreCase("flatfile") && dataSource == null)
  212. dataSource = new FlatFileSource();
  213. else if (dataSourceType.equalsIgnoreCase("mysql") && dataSource == null)
  214. dataSource = new MySQLSource();
  215. dataSource.initialize();
  216. }
  217. public String getDataSourceType() {
  218. return dataSourceType;
  219. }
  220. /**
  221. * Returns the instance
  222. *
  223. * @return
  224. */
  225. public static etc getInstance() {
  226. return instance;
  227. }
  228. /**
  229. * Sets the server to be used.
  230. *
  231. * @param s
  232. */
  233. public static void setServer(MinecraftServer s) {
  234. server = s;
  235. }
  236. /**
  237. * Returns the minecraft server
  238. *
  239. * @return
  240. */
  241. public static MinecraftServer getMCServer() {
  242. return server;
  243. }
  244. /**
  245. * Returns the data source
  246. *
  247. * @return
  248. */
  249. public static DataSource getDataSource() {
  250. return etc.getInstance().getSource();
  251. }
  252. /**
  253. * Returns the minecraft server interface
  254. *
  255. * @return
  256. */
  257. public static Server getServer() {
  258. return etc.getLoader().getServer();
  259. }
  260. /**
  261. * Returns the plugin loader
  262. *
  263. * @return
  264. */
  265. public static PluginLoader getLoader() {
  266. if (instance.loader == null)
  267. instance.loader = new PluginLoader(server);
  268. return instance.loader;
  269. }
  270. /**
  271. * Returns the default group
  272. *
  273. * @return default group
  274. */
  275. public Group getDefaultGroup() {
  276. Group group = dataSource.getDefaultGroup();
  277. if (group == null)
  278. log.log(Level.SEVERE, "No default group! Expect lots of errors!");
  279. return group;
  280. }
  281. /**
  282. * Adds or modifies the home.
  283. *
  284. * @param home
  285. */
  286. public void changeHome(Warp home) {
  287. if (dataSource.getHome(home.Name) == null)
  288. dataSource.addHome(home);
  289. else
  290. dataSource.changeHome(home);
  291. }
  292. /**
  293. * Adds or modifies the warp
  294. *
  295. * @param warp
  296. */
  297. public void setWarp(Warp warp) {
  298. if (dataSource.getWarp(warp.Name) == null)
  299. dataSource.addWarp(warp);
  300. else
  301. dataSource.changeWarp(warp);
  302. }
  303. /**
  304. * Returns true if the item is on the blacklist
  305. *
  306. * @param id
  307. * @return
  308. */
  309. public boolean isOnItemBlacklist(int id) {
  310. return itemSpawnBlacklist.contains(id);
  311. }
  312. /**
  313. * Returns the data source
  314. *
  315. * @return
  316. */
  317. public DataSource getSource() {
  318. return dataSource;
  319. }
  320. /**
  321. * Returns true if we're logging commands and such
  322. *
  323. * @return
  324. */
  325. public boolean isLogging() {
  326. return logging;
  327. }
  328. /**
  329. * Returns true if we want health to be enabled.
  330. *
  331. * @return
  332. */
  333. public boolean isHealthEnabled() {
  334. return enableHealth;
  335. }
  336. /**
  337. * Returns the status of auto-heal.
  338. *
  339. * @return
  340. */
  341. public PluginLoader.HookResult autoHeal() {
  342. return autoHeal;
  343. }
  344. /**
  345. * Adds command to the /help list
  346. *
  347. * @param command
  348. * @param description
  349. */
  350. public void addCommand(String command, String description) {
  351. commands.put(command, description);
  352. }
  353. /**
  354. * Removes command from /help list
  355. *
  356. * @param command
  357. */
  358. public void removeCommand(String command) {
  359. commands.remove(command);
  360. }
  361. /**
  362. * Toggles the whitelist (doesn't persist)
  363. *
  364. * @return
  365. */
  366. public boolean toggleWhitelist() {
  367. whitelistEnabled = !whitelistEnabled;
  368. return whitelistEnabled;
  369. }
  370. /**
  371. * Callback object for notifications sent by executed ServerCommands. so
  372. * that they appear in server log.
  373. */
  374. private MessageReceiver serverConsole = new MessageReceiver() {
  375. @Override
  376. public String getName() {
  377. return "<Server>";
  378. }
  379. @Override
  380. public void notify(String message) {
  381. // Strip the colors.
  382. message = message.replaceAll("\\u00A7[a-f0-9]", "");
  383. if (message != null)
  384. log.info(message);
  385. }
  386. };
  387. /**
  388. * Parses a console command
  389. *
  390. * @param command
  391. * @param server
  392. * @return
  393. */
  394. public boolean parseConsoleCommand(String command, MinecraftServer server) {
  395. if (getMCServer() == null)
  396. setServer(server);
  397. String[] split = command.split(" ");
  398. if ((Boolean) getLoader().callHook(PluginLoader.Hook.SERVERCOMMAND, new Object[] { split }))
  399. return true;
  400. if (split.length == 0)
  401. return false;
  402. boolean dontParseRegular = true;
  403. if (split[0].equalsIgnoreCase("save-all")) {
  404. dontParseRegular = false;
  405. getServer().saveInventories();
  406. } else if (split[0].equalsIgnoreCase("help") || split[0].equalsIgnoreCase("mod-help")) {
  407. if (split[0].equalsIgnoreCase("help"))
  408. dontParseRegular = false;
  409. log.info("Server mod help:");
  410. log.info("help Displays this mod's and server's help");
  411. log.info("mod-help Displays this mod's help");
  412. log.info("version Displays the server version");
  413. log.info("reload Reloads the config");
  414. log.info("modify Type modify for more info");
  415. log.info("whitelist Type whitelist for more info");
  416. log.info("reservelist Type reservelist for more info");
  417. log.info("listplugins Lists all plugins");
  418. log.info("enableplugin Enables a plugin");
  419. log.info("disableplugin Disables a plugin");
  420. log.info("reloadplugin Reloads a plugin");
  421. } else
  422. dontParseRegular = ServerConsoleCommands.parseServerConsoleCommand(serverConsole, split[0], split);
  423. return dontParseRegular;
  424. }
  425. /**
  426. * Returns compass direction according to your rotation
  427. *
  428. * @param degrees
  429. * @return
  430. */
  431. public static String getCompassPointForDirection(double degrees) {
  432. if (0 <= degrees && degrees < 22.5)
  433. return "N";
  434. else if (22.5 <= degrees && degrees < 67.5)
  435. return "NE";
  436. else if (67.5 <= degrees && degrees < 112.5)
  437. return "E";
  438. else if (112.5 <= degrees && degrees < 157.5)
  439. return "SE";
  440. else if (157.5 <= degrees && degrees < 202.5)
  441. return "S";
  442. else if (202.5 <= degrees && degrees < 247.5)
  443. return "SW";
  444. else if (247.5 <= degrees && degrees < 292.5)
  445. return "W";
  446. else if (292.5 <= degrees && degrees < 337.5)
  447. return "NW";
  448. else if (337.5 <= degrees && degrees < 360.0)
  449. return "N";
  450. else
  451. return "ERR";
  452. }
  453. /**
  454. * Combines the string array into a string at the specified start with the
  455. * separator separating each string.
  456. *
  457. * @param startIndex
  458. * @param string
  459. * @param seperator
  460. * @return combined string
  461. */
  462. public static String combineSplit(int startIndex, String[] string, String seperator) {
  463. StringBuilder builder = new StringBuilder();
  464. for (int i = startIndex; i < string.length; i++) {
  465. builder.append(string[i]);
  466. builder.append(seperator);
  467. }
  468. builder.deleteCharAt(builder.length() - seperator.length()); // remove
  469. // the
  470. // extra
  471. // seperator
  472. return builder.toString();
  473. }
  474. /**
  475. * Returns a list of allowed items for /item
  476. *
  477. * @return list of allowed items
  478. */
  479. public Set<Integer> getAllowedItems() {
  480. return allowedItems;
  481. }
  482. /**
  483. * Returns the list of commands
  484. *
  485. * @return
  486. */
  487. public LinkedHashMap<String, String> getCommands() {
  488. return commands;
  489. }
  490. /**
  491. * Returns a list of disallowed items for /item
  492. *
  493. * @return
  494. */
  495. public Set<Integer> getDisallowedItems() {
  496. return disallowedItems;
  497. }
  498. /**
  499. * Returns the location of groups.txt
  500. *
  501. * @return
  502. */
  503. public String getGroupLocation() {
  504. return groupLoc;
  505. }
  506. /**
  507. * Returns the location of homes.txt
  508. *
  509. * @return
  510. */
  511. public String getHomeLocation() {
  512. return homeLoc;
  513. }
  514. /**
  515. * Returns the location of items.txt
  516. *
  517. * @return
  518. */
  519. public String getItemLocation() {
  520. return itemLoc;
  521. }
  522. /**
  523. * Returns list of banned blocks
  524. *
  525. * @return
  526. */
  527. public Set<Integer> getItemSpawnBlacklist() {
  528. return itemSpawnBlacklist;
  529. }
  530. /**
  531. * Returns the location of kits.txt
  532. *
  533. * @return
  534. */
  535. public String getKitsLocation() {
  536. return kitsLoc;
  537. }
  538. /**
  539. * Returns the MOTD.
  540. *
  541. * @return
  542. */
  543. public String[] getMotd() {
  544. return motd;
  545. }
  546. /**
  547. * Returns the player limit
  548. *
  549. * @return
  550. */
  551. public int getPlayerLimit() {
  552. return playerLimit;
  553. }
  554. /**
  555. * Return reservelist enabled.
  556. *
  557. * @return true if enabled.
  558. */
  559. public boolean isReservelistEnabled() {
  560. return reservelistEnabled;
  561. }
  562. /**
  563. * Returns the location of reservelist.txt
  564. *
  565. * @return
  566. */
  567. public String getReservelistLocation() {
  568. return reservelistLoc;
  569. }
  570. /**
  571. * Returns true if the server is saving homes
  572. *
  573. * @return true if server can save homes
  574. */
  575. public boolean canSaveHomes() {
  576. return saveHomes;
  577. }
  578. /**
  579. * Returns the spawn protection size
  580. *
  581. * @return
  582. */
  583. public int getSpawnProtectionSize() {
  584. return spawnProtectionSize;
  585. }
  586. /**
  587. * Returns the location of users.txt
  588. *
  589. * @return
  590. */
  591. public String getUsersLocation() {
  592. return usersLoc;
  593. }
  594. /**
  595. * Returns the location of warps.txt
  596. *
  597. * @return
  598. */
  599. public String getWarpLocation() {
  600. return warpLoc;
  601. }
  602. /**
  603. * Returns true if the whitelist is enabled
  604. *
  605. * @return
  606. */
  607. public boolean isWhitelistEnabled() {
  608. return whitelistEnabled;
  609. }
  610. /**
  611. * Returns the location of whitelist.txt
  612. *
  613. * @return
  614. */
  615. public String getWhitelistLocation() {
  616. return whitelistLoc;
  617. }
  618. /**
  619. * Returns the message the kick will show if a player isn't on the whitelist
  620. *
  621. * @return
  622. */
  623. public String getWhitelistMessage() {
  624. return whitelistMessage;
  625. }
  626. /**
  627. * Sets the list of allowed items
  628. *
  629. * @param allowedItems
  630. */
  631. public void setAllowedItems(int[] allowedItems) {
  632. this.allowedItems.clear();
  633. // this.allowedItems.addAll(Arrays.asList(allowedItems)); <-- if only
  634. // java was smart >.>
  635. for (int item : allowedItems)
  636. this.allowedItems.add(item);
  637. }
  638. /**
  639. * Sets the list of disallowed items
  640. *
  641. * @param disallowedItems
  642. */
  643. public void setDisallowedItems(int[] disallowedItems) {
  644. this.disallowedItems.clear();
  645. // this.allowedItems.addAll(Arrays.asList(allowedItems)); <-- if only
  646. // java was smart >.>
  647. for (int item : disallowedItems)
  648. this.disallowedItems.add(item);
  649. }
  650. /**
  651. * Sets the location of groups.txt
  652. *
  653. * @param groupLoc
  654. */
  655. public void setGroupLocation(String groupLoc) {
  656. this.groupLoc = groupLoc;
  657. }
  658. /**
  659. * Sets the location of homes.txt
  660. *
  661. * @param homeLoc
  662. */
  663. public void setHomeLocation(String homeLoc) {
  664. this.homeLoc = homeLoc;
  665. }
  666. /**
  667. * Sets the location of items.txt
  668. *
  669. * @param itemLoc
  670. */
  671. public void setItemLocation(String itemLoc) {
  672. this.itemLoc = itemLoc;
  673. }
  674. /**
  675. * Sets the item spawn blacklist
  676. *
  677. * @param itemSpawnBlacklist
  678. */
  679. public void setItemSpawnBlacklist(int[] itemSpawnBlacklist) {
  680. this.itemSpawnBlacklist.clear();
  681. // this.allowedItems.addAll(Arrays.asList(allowedItems)); <-- if only
  682. // java was smart >.>
  683. for (int item : itemSpawnBlacklist)
  684. this.itemSpawnBlacklist.add(item);
  685. }
  686. /**
  687. * Sets the location of kits.txt
  688. *
  689. * @param kitsLoc
  690. */
  691. public void setKitsLocation(String kitsLoc) {
  692. this.kitsLoc = kitsLoc;
  693. }
  694. /**
  695. * If set to true the server will log all commands used.
  696. *
  697. * @param logging
  698. */
  699. public void setLogging(boolean logging) {
  700. this.logging = logging;
  701. }
  702. /**
  703. * Set the MOTD
  704. *
  705. * @param motd
  706. */
  707. public void setMotd(String[] motd) {
  708. this.motd = motd;
  709. }
  710. /**
  711. * Set the player limit
  712. *
  713. * @param playerLimit
  714. */
  715. public void setPlayerLimit(int playerLimit) {
  716. this.playerLimit = playerLimit;
  717. }
  718. /**
  719. * Set the location of reservelist.txt
  720. *
  721. * @param reservelistLoc
  722. */
  723. public void setReservelistLocation(String reservelistLoc) {
  724. this.reservelistLoc = reservelistLoc;
  725. }
  726. /**
  727. * If true the server will save homes. If false homes won't be saved and
  728. * will be wiped the next server restart.
  729. *
  730. * @param saveHomes
  731. */
  732. public void setSaveHomes(boolean saveHomes) {
  733. this.saveHomes = saveHomes;
  734. }
  735. /**
  736. * Set the spawn protection size (def: 16)
  737. *
  738. * @param spawnProtectionSize
  739. */
  740. public void setSpawnProtectionSize(int spawnProtectionSize) {
  741. this.spawnProtectionSize = spawnProtectionSize;
  742. }
  743. /**
  744. * Sets the location of users.txt
  745. *
  746. * @param usersLoc
  747. */
  748. public void setUsersLocation(String usersLoc) {
  749. this.usersLoc = usersLoc;
  750. }
  751. /**
  752. * Sets the location of warps.txt
  753. *
  754. * @param warpLoc
  755. */
  756. public void setWarpLocation(String warpLoc) {
  757. this.warpLoc = warpLoc;
  758. }
  759. /**
  760. * If true the whitelist is enabled
  761. *
  762. * @param whitelistEnabled
  763. */
  764. public void setWhitelistEnabled(boolean whitelistEnabled) {
  765. this.whitelistEnabled = whitelistEnabled;
  766. }
  767. /**
  768. * Sets the location of whitelist.txt
  769. *
  770. * @param whitelistLoc
  771. */
  772. public void setWhitelistLocation(String whitelistLoc) {
  773. this.whitelistLoc = whitelistLoc;
  774. }
  775. /**
  776. * Sets the whitelist message to show when it kicks someone
  777. *
  778. * @param whitelistMessage
  779. */
  780. public void setWhitelistMessage(String whitelistMessage) {
  781. this.whitelistMessage = whitelistMessage;
  782. }
  783. /**
  784. * Returns true if "Unknown command" is shown to a player when they enter an
  785. * unknown command (For wrappers and such)
  786. *
  787. * @return show unknown command
  788. */
  789. public boolean showUnknownCommand() {
  790. return showUnknownCommand;
  791. }
  792. /**
  793. * Sets whether or not to show "Unknown command" to players.
  794. *
  795. * @param showUnknownCommand
  796. * whether or not to show it
  797. */
  798. public void setShowUnknownCommand(boolean showUnknownCommand) {
  799. this.showUnknownCommand = showUnknownCommand;
  800. }
  801. /**
  802. * Return the current build of the mod
  803. *
  804. * @return build/version
  805. */
  806. public int getVersion() {
  807. return version;
  808. }
  809. /**
  810. * Return whether this build is "tainted"
  811. *
  812. * @return tainted
  813. */
  814. public boolean getTainted() {
  815. return tainted;
  816. }
  817. /**
  818. * Return the specified string version of the build
  819. *
  820. * @return build/version
  821. */
  822. public String getVersionStr() {
  823. return versionStr;
  824. }
  825. /**
  826. * Returns a list of animals that are allowed to spawn naturally
  827. *
  828. * @return a list of animals
  829. */
  830. public String[] getAnimals() {
  831. return animals;
  832. }
  833. /**
  834. * Sets a list of animals that are allowed to spawn naturally
  835. *
  836. * @param animals
  837. * a list of animals
  838. */
  839. public void setAnimals(String[] animals) {
  840. this.animals = animals;
  841. }
  842. /**
  843. * Returns a list of animals that are allowed to spawn naturally
  844. *
  845. * @return a list of animals
  846. */
  847. public String[] getWaterAnimals() {
  848. return waterAnimals;
  849. }
  850. /**
  851. * Sets a list of animals that are allowed to spawn naturally
  852. *
  853. * @param animals
  854. * a list of animals
  855. */
  856. public void setWaterAnimals(String[] animals) {
  857. waterAnimals = animals;
  858. }
  859. /**
  860. * Returns a list of mobs that are allowed to spawn naturally
  861. *
  862. * @return a list of mobs
  863. */
  864. public String[] getMonsters() {
  865. return monsters;
  866. }
  867. public List getMonstersClass(OMobSpawnerBase biomeSpawner) {
  868. if (mobReload)
  869. reloadMonsterClass();
  870. return monsterList;
  871. }
  872. public List getAnimalsClass(OMobSpawnerBase biomeSpawner) {
  873. if (mobReload)
  874. reloadMonsterClass();
  875. // Wolfies also like to spawn
  876. ArrayList toRet = new ArrayList(animalsList); // Create a copy.
  877. if ((biomeSpawner instanceof OMobSpawnerTaiga) || (biomeSpawner instanceof OMobSpawnerForest)) {
  878. OSpawnListEntry wolfEntry = OSpawnListEntry.getSpawnListEntry(OEntityWolf.class);
  879. if (!toRet.contains(wolfEntry))
  880. toRet.add(wolfEntry);
  881. }
  882. return toRet;
  883. }
  884. public List getWaterAnimalsClass(OMobSpawnerBase biomeSpawner) {
  885. if (mobReload)
  886. reloadMonsterClass();
  887. return waterAnimalsList;
  888. }
  889. private void reloadMonsterClass() {
  890. monsterList = new ArrayList(getMonsters().length);
  891. animalsList = new ArrayList(getAnimals().length);
  892. waterAnimalsList = new ArrayList(getWaterAnimals().length);
  893. for (String monster : getMonsters())
  894. monsterList.add(OSpawnListEntry.getSpawnListEntry(OEntityList.getEntity(monster)));
  895. for (String animal : getAnimals())
  896. animalsList.add(OSpawnListEntry.getSpawnListEntry(OEntityList.getEntity(animal)));
  897. for (String waterAnimal : getWaterAnimals())
  898. waterAnimalsList.add(OSpawnListEntry.getSpawnListEntry(OEntityList.getEntity(waterAnimal)));
  899. mobReload = false;
  900. }
  901. /**
  902. * Sets a list of mobs that are allowed to spawn naturally
  903. *
  904. * @param monsters
  905. * a list of mobs
  906. */
  907. public void setMonsters(String[] monsters) {
  908. this.monsters = monsters;
  909. }
  910. /**
  911. * Returns the % from 0 to 100 that a mob or animal will spawn
  912. *
  913. * @return a percentage from 0 to 100
  914. */
  915. public int getMobSpawnRate() {
  916. return mobSpawnRate;
  917. }
  918. /**
  919. * Sets the % from 0 to 100 that a mob or animal will spawn
  920. *
  921. * @param rate
  922. * a percentage from 0 to 100
  923. */
  924. public void setMobSpawnRate(int rate) {
  925. mobSpawnRate = rate;
  926. }
  927. private Connection _getSQLConnection() {
  928. try {
  929. return DriverManager.getConnection(db + "?autoReconnect=true&user=" + username + "&password=" + password);
  930. } catch (SQLException ex) {
  931. log.log(Level.SEVERE, "Unable to retreive connection", ex);
  932. }
  933. return null;
  934. }
  935. /**
  936. * Returns a SQL connection
  937. *
  938. * @return sql connection
  939. */
  940. public static Connection getSQLConnection() {
  941. return getInstance()._getSQLConnection();
  942. }
  943. public static int floor(float paramFloat) {
  944. int i = (int) paramFloat;
  945. return paramFloat < i ? i - 1 : i;
  946. }
  947. public static int floor(double paramDouble) {
  948. int i = (int) paramDouble;
  949. return paramDouble < i ? i - 1 : i;
  950. }
  951. private static void validateMobGroup(String[] mobs, String groupname, String[] allowed) {
  952. lb1: for (String i : mobs) {
  953. for (String al : allowed)
  954. if (al.equals(i))
  955. continue lb1;
  956. log.warning("Invalid mobType '" + i + "' in group '" + groupname + "', please remove it from your config file!");
  957. System.exit(0);
  958. }
  959. }
  960. public static boolean isInValidLivingGroup(String classname, Class<?> objectgroup) {
  961. Class<?> entity = OEntityList.getEntity(classname);
  962. if (entity != null)
  963. return objectgroup.isAssignableFrom(entity);
  964. else
  965. return false;
  966. }
  967. }