PageRenderTime 74ms CodeModel.GetById 28ms RepoModel.GetById 1ms app.codeStats 0ms

/TravelGates/src/com/ghomerr/travelgates/TravelGates.java

https://github.com/Ghomerr/TravelGates
Java | 1684 lines | 1381 code | 263 blank | 40 comment | 218 complexity | 3779aabd0a42aef35dccb0fa4d469b51 MD5 | raw file
  1. package com.ghomerr.travelgates;
  2. import java.io.File;
  3. import java.io.FileInputStream;
  4. import java.io.FileNotFoundException;
  5. import java.io.FileOutputStream;
  6. import java.io.FilenameFilter;
  7. import java.io.IOException;
  8. import java.util.ArrayList;
  9. import java.util.HashMap;
  10. import java.util.HashSet;
  11. import java.util.Properties;
  12. import java.util.logging.Logger;
  13. import org.bukkit.ChatColor;
  14. import org.bukkit.Chunk;
  15. import org.bukkit.DyeColor;
  16. import org.bukkit.Location;
  17. import org.bukkit.Material;
  18. import org.bukkit.TreeSpecies;
  19. import org.bukkit.World;
  20. import org.bukkit.WorldCreator;
  21. import org.bukkit.block.BlockFace;
  22. import org.bukkit.command.PluginCommand;
  23. import org.bukkit.entity.Player;
  24. import org.bukkit.inventory.PlayerInventory;
  25. import org.bukkit.plugin.Plugin;
  26. import org.bukkit.plugin.PluginManager;
  27. import org.bukkit.plugin.java.JavaPlugin;
  28. import ru.tehkode.permissions.PermissionManager;
  29. import ru.tehkode.permissions.bukkit.PermissionsEx;
  30. import com.ghomerr.travelgates.constants.TravelGatesConstants;
  31. import com.ghomerr.travelgates.enums.TravelGatesCommands;
  32. import com.ghomerr.travelgates.enums.TravelGatesConfigurations;
  33. import com.ghomerr.travelgates.enums.TravelGatesOptions;
  34. import com.ghomerr.travelgates.enums.TravelGatesPermissionsNodes;
  35. import com.ghomerr.travelgates.enums.TravelGatesWorldType;
  36. import com.ghomerr.travelgates.listeners.TravelGatesCommandExecutor;
  37. import com.ghomerr.travelgates.listeners.TravelGatesPlayerListener;
  38. import com.ghomerr.travelgates.listeners.TravelGatesPortalListener;
  39. import com.ghomerr.travelgates.listeners.TravelGatesSignListener;
  40. import com.ghomerr.travelgates.messages.TravelGatesMessages;
  41. import com.ghomerr.travelgates.messages.TravelGatesMessagesManager;
  42. import com.ghomerr.travelgates.objects.TravelGatesOptionsContainer;
  43. import com.ghomerr.travelgates.objects.TravelGatesTeleportBlock;
  44. import com.ghomerr.travelgates.utils.TravelGatesUtils;
  45. import com.nijiko.permissions.PermissionHandler;
  46. import com.nijikokun.bukkit.Permissions.Permissions;
  47. public class TravelGates extends JavaPlugin
  48. {
  49. private static final Logger _LOGGER = Logger.getLogger(TravelGatesConstants.MINECRAFT);
  50. // Misc
  51. private boolean _pluginEnabled = false;
  52. private PluginManager _pm = null;
  53. // config
  54. private String _language = TravelGatesConstants.DEFAULT_LANGUAGE;
  55. private boolean _usePermissions = false;
  56. private boolean _teleportWithSign = true;
  57. private boolean _teleportWithPortal = false;
  58. private boolean _clearAllInventory = false;
  59. private boolean _protectAdminInventory = false;
  60. private boolean _autosave = false;
  61. private boolean _isDebugEnabled = false;
  62. private boolean _isDisplayTeleportMessage = true;
  63. private TravelGatesTeleportBlock _tpBlock = new TravelGatesTeleportBlock();
  64. // messages
  65. private TravelGatesMessagesManager _messages = null;
  66. private String _portalSignOnState = null;
  67. private String _portalSignOffState = null;
  68. // Cache
  69. private HashMap<String, String> _mapShortLocationsByDest = new HashMap<String, String>();
  70. private HashMap<String, Location> _mapLocationsByDest = new HashMap<String, Location>();
  71. private HashMap<String, String> _mapDestinationsByShortLoc = new HashMap<String, String>();
  72. private HashMap<String, TravelGatesOptionsContainer> _mapOptionsByDest = new HashMap<String, TravelGatesOptionsContainer>();
  73. private HashMap<String, Integer> _mapMaterialIdByName = new HashMap<String, Integer>();
  74. private HashMap<String, DyeColor> _mapDyeColorByName = new HashMap<String, DyeColor>();
  75. private HashMap<String, TreeSpecies> _mapTreeSpeciesByName = new HashMap<String, TreeSpecies>();
  76. private HashSet<String> _setAdditionalWorlds = new HashSet<String>();
  77. // Files and data
  78. private Properties _configData = new Properties();
  79. private File _configFile = null;
  80. private Properties _destinationsData = new Properties();
  81. private File _destinationsFile = null;
  82. private Properties _restrictionsData = new Properties();
  83. private File _restrictionsFile = null;
  84. // Permissions
  85. private boolean _useNativePermissions = false;
  86. private boolean _usePermissionsBukkit = false;
  87. private boolean _usePermissionsEx = false;
  88. private PermissionHandler _permHandler = null;
  89. private PermissionManager _permManager = null;
  90. // Listeners
  91. public TravelGatesPlayerListener playerListener = null;
  92. public TravelGatesPortalListener portalListener = null;
  93. public TravelGatesSignListener portalSignListener = null;
  94. // Constants
  95. private final String _tag = TravelGatesConstants.PLUGIN_TAG;
  96. private final String _debug = TravelGatesConstants.DEBUG_TAG;
  97. public void onEnable()
  98. {
  99. super.onEnable();
  100. // Must be done before loadXXX() methods !
  101. _pm = getServer().getPluginManager();
  102. // Load Configuration
  103. _pluginEnabled = loadConfiguration();
  104. if (_pluginEnabled)
  105. {
  106. // Must be loaded before loadConfiguration()
  107. _pluginEnabled = _pluginEnabled && loadAdditionalWorld();
  108. _pluginEnabled = _pluginEnabled && loadMessages();
  109. _pluginEnabled = _pluginEnabled && loadPermissions();
  110. _pluginEnabled = _pluginEnabled && loadDestinations();
  111. }
  112. if (!_pluginEnabled)
  113. {
  114. _LOGGER.severe(_tag + " Plugin loading failed. All commands are disabled.");
  115. }
  116. else
  117. {
  118. playerListener = new TravelGatesPlayerListener(this);
  119. portalListener = new TravelGatesPortalListener(this);
  120. portalSignListener = new TravelGatesSignListener(this);
  121. final TravelGatesCommandExecutor commandeExecutor = new TravelGatesCommandExecutor(this);
  122. // Register commands
  123. for (final String cmd : TravelGatesCommands.TRAVELGATES.list())
  124. {
  125. final PluginCommand pluginCmd = this.getCommand(cmd);
  126. if (pluginCmd != null)
  127. {
  128. pluginCmd.setExecutor(commandeExecutor);
  129. }
  130. else
  131. {
  132. _LOGGER.severe(_tag + " Command " + cmd + " could not be added.");
  133. }
  134. }
  135. }
  136. // End
  137. _LOGGER.info(_tag + " Plugin loading done. There are " + _mapShortLocationsByDest.size() + " destinations loaded.");
  138. }
  139. public void onDisable()
  140. {
  141. super.onDisable();
  142. saveAll();
  143. _LOGGER.info(_tag + " Plugin unloading done.");
  144. }
  145. public boolean saveConfiguration()
  146. {
  147. if (_isDebugEnabled)
  148. {
  149. _LOGGER.info(_debug + " Start saveConfiguration()");
  150. }
  151. boolean saveSuccess = saveFile(_configFile, _configData, TravelGatesConstants.CONFIG_FILE_NAME);
  152. if (_isDebugEnabled)
  153. {
  154. _LOGGER.info(_debug + " End saveConfiguration : " + saveSuccess);
  155. }
  156. return saveSuccess;
  157. }
  158. public boolean saveDestinations()
  159. {
  160. if (_isDebugEnabled)
  161. {
  162. _LOGGER.info(_debug + " Start saveDestinations()");
  163. }
  164. boolean saveSuccess = saveFile(_destinationsFile, _destinationsData, TravelGatesConstants.DEST_FILE_NAME);
  165. if (_isDebugEnabled)
  166. {
  167. _LOGGER.info(_debug + " End saveDestinations : " + saveSuccess);
  168. }
  169. return saveSuccess;
  170. }
  171. public boolean saveRestrictions()
  172. {
  173. if (_isDebugEnabled)
  174. {
  175. _LOGGER.info(_debug + " Start saveRestrictions()");
  176. }
  177. boolean saveSuccess = saveFile(_restrictionsFile, _restrictionsData, TravelGatesConstants.RESTRICTIONS_FILE_NAME);
  178. if (_isDebugEnabled)
  179. {
  180. _LOGGER.info(_debug + " End saveRestrictions : " + saveSuccess);
  181. }
  182. return saveSuccess;
  183. }
  184. public boolean saveData()
  185. {
  186. return saveDestinations() && saveRestrictions();
  187. }
  188. public boolean saveAll()
  189. {
  190. return saveConfiguration() && saveData();
  191. }
  192. private boolean saveFile(final File file, final Properties data, final String fileName)
  193. {
  194. if (_isDebugEnabled)
  195. {
  196. _LOGGER.info(_debug + " Start saveFile : " + fileName);
  197. }
  198. boolean ret = false;
  199. if (file != null && file.exists())
  200. {
  201. if (data != null && !data.isEmpty())
  202. {
  203. FileOutputStream out = null;
  204. try
  205. {
  206. out = new FileOutputStream(file);
  207. }
  208. catch (final FileNotFoundException ex)
  209. {
  210. _LOGGER.severe(_tag + " File " + fileName + " not found. ");
  211. ex.printStackTrace();
  212. }
  213. try
  214. {
  215. data.store(out, null);
  216. out.close();
  217. if (_isDebugEnabled)
  218. {
  219. _LOGGER.info(_debug + " End saveFile : " + true);
  220. }
  221. ret = true;
  222. }
  223. catch (final IOException ex)
  224. {
  225. _LOGGER.severe(_tag + " " + fileName + " file update failed !");
  226. ex.printStackTrace();
  227. }
  228. }
  229. else
  230. {
  231. _LOGGER.info(_tag + " No data to save in " + fileName);
  232. ret = true;
  233. }
  234. }
  235. else
  236. {
  237. _LOGGER.severe(_tag + " File " + fileName + " doesn't exist !");
  238. }
  239. if (_isDebugEnabled)
  240. {
  241. _LOGGER.info(_debug + " End saveFile : " + ret);
  242. }
  243. return ret;
  244. }
  245. public boolean isPluginEnabled()
  246. {
  247. return _pluginEnabled;
  248. }
  249. public void addDestination(final Player player, final String destination, final Location loc, final TravelGatesOptionsContainer container)
  250. {
  251. if (_isDebugEnabled)
  252. {
  253. _LOGGER.info(_debug + " Start addDestination(destination=" + destination + ", container=" + container + ", player=" + player + ")");
  254. }
  255. final String shortLoc = TravelGatesUtils.locationToShortString(loc);
  256. String fullLoc = TravelGatesUtils.locationToFullString(loc);
  257. final String lowerCaseDest = destination.toLowerCase();
  258. _mapShortLocationsByDest.put(lowerCaseDest, shortLoc);
  259. _mapLocationsByDest.put(lowerCaseDest, TravelGatesUtils.shortStringToLocation(shortLoc, getServer().getWorlds()));
  260. _mapDestinationsByShortLoc.put(shortLoc, lowerCaseDest);
  261. fullLoc = fullLoc + TravelGatesConstants.DELIMITER + container.getOptionsForData();
  262. _destinationsData.put(lowerCaseDest, fullLoc);
  263. if (container.has(TravelGatesOptions.RESTRICTION))
  264. {
  265. _restrictionsData.put(destination, container.getRestrictionsListString());
  266. }
  267. if (container.has(TravelGatesOptions.SAVE) || _autosave)
  268. {
  269. final boolean saved = saveData();
  270. if (saved)
  271. {
  272. player.sendMessage(ChatColor.GREEN + _messages.get(TravelGatesMessages.SAVE_DONE));
  273. }
  274. else
  275. {
  276. player.sendMessage(ChatColor.RED + _messages.get(TravelGatesMessages.SAVE_FAILED));
  277. }
  278. }
  279. if (_isDebugEnabled)
  280. {
  281. _LOGGER.info(_debug + " End addDestination");
  282. }
  283. }
  284. public Location getLocationFromPosition(final Player player, final Location playerLoc, final String position)
  285. {
  286. if (_isDebugEnabled)
  287. {
  288. _LOGGER.info(_debug + " Start getLocationFromPosition(player=" + player + ", playerLoc=" + playerLoc + ", position=" + position + ")");
  289. }
  290. Location destinationLocation = null;
  291. if (TravelGatesUtils.stringIsBlank(position))
  292. {
  293. destinationLocation = playerLoc;
  294. }
  295. else
  296. {
  297. final String[] positionData = position.split(TravelGatesConstants.DELIMITER);
  298. final int numberOfItems = positionData.length;
  299. if (numberOfItems == 3)
  300. {
  301. try
  302. {
  303. final World world = player.getWorld();
  304. destinationLocation = TravelGatesUtils.getDestinationLocation(world, positionData, playerLoc,
  305. TravelGatesConstants.POSITION_WITHOUT_WORLD);
  306. }
  307. catch (final Throwable th)
  308. {
  309. player.sendMessage(ChatColor.RED + _messages.get(TravelGatesMessages.WRONG_POSITION_VALUE));
  310. if (_isDebugEnabled)
  311. {
  312. _LOGGER.info(_debug + " Exception caught : ");
  313. }
  314. th.printStackTrace();
  315. }
  316. }
  317. else if (numberOfItems == 4)
  318. {
  319. try
  320. {
  321. if (_isDebugEnabled)
  322. {
  323. _LOGGER.info(_debug + " World name : " + positionData[0]);
  324. }
  325. final World world = getServer().getWorld(positionData[0]);
  326. destinationLocation = TravelGatesUtils.getDestinationLocation(world, positionData, playerLoc,
  327. TravelGatesConstants.POSITION_WITH_WORLD);
  328. }
  329. catch (final Throwable th)
  330. {
  331. player.sendMessage(ChatColor.RED + _messages.get(TravelGatesMessages.WRONG_POSITION_VALUE));
  332. if (_isDebugEnabled)
  333. {
  334. _LOGGER.info(_debug + " Exception caught : ");
  335. }
  336. th.printStackTrace();
  337. }
  338. }
  339. else
  340. {
  341. player.sendMessage(ChatColor.RED + _messages.get(TravelGatesMessages.WRONG_POSITION_VALUE));
  342. }
  343. }
  344. if (_isDebugEnabled)
  345. {
  346. _LOGGER.info(_debug + " End getLocationFromPosition : " + destinationLocation);
  347. }
  348. return destinationLocation;
  349. }
  350. public void deleteDestination(final String destination, final boolean save, final Player player)
  351. {
  352. if (_isDebugEnabled)
  353. {
  354. _LOGGER.info(_debug + " Start deleteDestination(destination=" + destination + ")");
  355. }
  356. final String lowerCaseDest = destination.toLowerCase();
  357. _destinationsData.remove(lowerCaseDest);
  358. _restrictionsData.remove(lowerCaseDest);
  359. _mapDestinationsByShortLoc.remove(_mapShortLocationsByDest.get(lowerCaseDest));
  360. _mapLocationsByDest.remove(lowerCaseDest);
  361. _mapShortLocationsByDest.remove(lowerCaseDest);
  362. _mapOptionsByDest.get(lowerCaseDest).clear();
  363. _mapOptionsByDest.remove(lowerCaseDest);
  364. if (save || _autosave)
  365. {
  366. final boolean saved = saveData();
  367. if (saved)
  368. {
  369. player.sendMessage(ChatColor.GREEN + _messages.get(TravelGatesMessages.SAVE_DONE));
  370. }
  371. else
  372. {
  373. player.sendMessage(ChatColor.RED + _messages.get(TravelGatesMessages.SAVE_FAILED));
  374. }
  375. }
  376. if (_isDebugEnabled)
  377. {
  378. _LOGGER.info(_debug + " End deleteDestination");
  379. }
  380. }
  381. public boolean hasDestination(final String destination)
  382. {
  383. if (_isDebugEnabled)
  384. {
  385. _LOGGER.info(_debug + " Start hasDestination(destination=" + destination + ")");
  386. }
  387. final boolean hasDest = _mapShortLocationsByDest.containsKey(destination.toLowerCase());
  388. if (_isDebugEnabled)
  389. {
  390. _LOGGER.info(_debug + " End hasDestination : " + hasDest);
  391. }
  392. return hasDest;
  393. }
  394. public boolean hasLocation(final Location loc)
  395. {
  396. if (_isDebugEnabled)
  397. {
  398. _LOGGER.info(_debug + " Start hasLocation(loc=" + loc + ")");
  399. }
  400. final String shortLoc = TravelGatesUtils.locationToShortString(loc);
  401. final boolean hasLoc = hasShortLocation(shortLoc); // _shortLocations.containsValue(shortLoc);
  402. if (_isDebugEnabled)
  403. {
  404. _LOGGER.info(_debug + " End hasLocation : " + hasLoc);
  405. }
  406. return hasLoc;
  407. }
  408. public boolean hasShortLocation(final String shortLoc)
  409. {
  410. if (_isDebugEnabled)
  411. {
  412. _LOGGER.info(_debug + " Start hasShortLocation(loc=" + shortLoc + ")");
  413. }
  414. final boolean hasShortLoc = _mapDestinationsByShortLoc.containsKey(shortLoc);
  415. if (_isDebugEnabled)
  416. {
  417. _LOGGER.info(_debug + " End hasShortLocation : " + hasShortLoc);
  418. }
  419. return hasShortLoc;
  420. }
  421. public String getDestinationsList()
  422. {
  423. if (_isDebugEnabled)
  424. {
  425. _LOGGER.info(_debug + " Start destList()");
  426. }
  427. final StringBuilder strBuild = new StringBuilder();
  428. strBuild.append(_messages.get(TravelGatesMessages.AVAILABLE_DESTINATIONS));
  429. final int initLength = strBuild.length();
  430. for (final String dest : _mapShortLocationsByDest.keySet())
  431. {
  432. strBuild.append(" ").append(ChatColor.AQUA).append(dest).append(ChatColor.YELLOW).append(TravelGatesConstants.DELIMITER);
  433. }
  434. final int endLength = strBuild.length();
  435. if (initLength < endLength)
  436. {
  437. strBuild.deleteCharAt(endLength - 1);
  438. }
  439. else
  440. {
  441. strBuild.append(ChatColor.AQUA).append(_messages.get(TravelGatesMessages.NONE));
  442. }
  443. if (_isDebugEnabled)
  444. {
  445. _LOGGER.info(_debug + " End destList : " + strBuild.toString());
  446. }
  447. return strBuild.toString();
  448. }
  449. public String getRestrictionsList(final String destination)
  450. {
  451. if (_isDebugEnabled)
  452. {
  453. _LOGGER.info(_debug + " Start restrictionsList(destination=" + destination + ")");
  454. }
  455. final String lowerCaseDest = destination.toLowerCase();
  456. final StringBuilder strBuild = new StringBuilder();
  457. strBuild.append(_messages.get(TravelGatesMessages.RESTRICTED_DESTINATIONS_ARE, ChatColor.AQUA + lowerCaseDest + ChatColor.YELLOW));
  458. final int initLength = strBuild.length();
  459. final HashSet<String> restrictedDests = _mapOptionsByDest.get(destination).getRestrictionsList();
  460. if (restrictedDests != null)
  461. {
  462. for (final String dest : restrictedDests)
  463. {
  464. strBuild.append(" ").append(ChatColor.AQUA).append(dest).append(ChatColor.YELLOW).append(TravelGatesConstants.DELIMITER);
  465. }
  466. }
  467. final int endLength = strBuild.length();
  468. if (initLength < endLength)
  469. {
  470. strBuild.deleteCharAt(endLength - 1);
  471. }
  472. else
  473. {
  474. strBuild.append(ChatColor.AQUA).append(" ").append(_messages.get(TravelGatesMessages.ALL));
  475. }
  476. if (_isDebugEnabled)
  477. {
  478. _LOGGER.info(_debug + " End restrictionsList : " + strBuild.toString());
  479. }
  480. return strBuild.toString();
  481. }
  482. public String getDestinationsDetailsList()
  483. {
  484. if (_isDebugEnabled)
  485. {
  486. _LOGGER.info(_debug + " Start destDetailedList()");
  487. }
  488. final StringBuilder strBuild = new StringBuilder();
  489. strBuild.append(_messages.get(TravelGatesMessages.AVAILABLE_DESTINATIONS));
  490. final int initLength = strBuild.length();
  491. for (final String dest : _mapShortLocationsByDest.keySet())
  492. {
  493. strBuild.append(getDestinationDetails(dest));
  494. }
  495. final int endLength = strBuild.length();
  496. if (initLength == endLength)
  497. {
  498. strBuild.append(ChatColor.AQUA).append(_messages.get(TravelGatesMessages.NONE));
  499. }
  500. if (_isDebugEnabled)
  501. {
  502. _LOGGER.info(_debug + " End destDetailedList : " + strBuild.toString());
  503. }
  504. return strBuild.toString();
  505. }
  506. public String getDestinationDetails(final String dest)
  507. {
  508. final StringBuilder strBuild = new StringBuilder();
  509. if (strBuild.length() > 0)
  510. {
  511. strBuild.append(TravelGatesConstants.DELIMITER).append(" ");
  512. }
  513. final boolean inventoryCleared = getOptionOfDestination(dest, TravelGatesOptions.INVENTORY);
  514. final String msgInventory = (inventoryCleared) ? ChatColor.RED + _messages.get(TravelGatesMessages.INVENTORY_CLEAR) : ChatColor.GREEN
  515. + _messages.get(TravelGatesMessages.INVENTORY_KEEP);
  516. final boolean isAdminTP = getOptionOfDestination(dest, TravelGatesOptions.ADMINTP);
  517. final String msgAdmin = (isAdminTP) ? ChatColor.RED + _messages.get(TravelGatesMessages.ADMIN_TP) : ChatColor.GREEN
  518. + _messages.get(TravelGatesMessages.FREE_TP);
  519. final boolean isRestricted = getOptionOfDestination(dest, TravelGatesOptions.RESTRICTION);
  520. final String msgRestrictions = (isRestricted) ? ChatColor.RED + _messages.get(TravelGatesMessages.DEST_RESTRICTED) : ChatColor.GREEN
  521. + _messages.get(TravelGatesMessages.DEST_FREE);
  522. strBuild.append(ChatColor.AQUA).append(dest).append(ChatColor.YELLOW).append("=(").append(ChatColor.GREEN)
  523. .append(_mapShortLocationsByDest.get((String) dest).toLowerCase()).append(ChatColor.YELLOW).append(")[").append(msgAdmin)
  524. .append(ChatColor.YELLOW).append(TravelGatesConstants.DELIMITER).append(msgInventory).append(ChatColor.YELLOW)
  525. .append(TravelGatesConstants.DELIMITER).append(msgRestrictions).append(ChatColor.YELLOW).append("]");
  526. return strBuild.toString();
  527. }
  528. public String getCurrentConfiguration()
  529. {
  530. if (_isDebugEnabled)
  531. {
  532. _LOGGER.info(_debug + " Start getCurrentConfiguration()");
  533. }
  534. final StringBuilder strBuild = new StringBuilder();
  535. strBuild.append(ChatColor.YELLOW).append(_messages.get(TravelGatesMessages.CURRENT_CONFIG));
  536. for (final Object o : _configData.keySet())
  537. {
  538. final String key = o.toString();
  539. final String value = _configData.getProperty(key);
  540. final Boolean boolValue = new Boolean(value);
  541. if (TravelGatesConfigurations.LANGUAGE.value().equalsIgnoreCase(key))
  542. {
  543. strBuild.append(" ").append(ChatColor.AQUA).append(TravelGatesConfigurations.LANGUAGE.value()).append(ChatColor.YELLOW).append("=")
  544. .append(ChatColor.WHITE).append(_language);
  545. }
  546. else if (TravelGatesConfigurations.TPBLOCK.value().equalsIgnoreCase(key))
  547. {
  548. strBuild.append(" ").append(ChatColor.AQUA).append(TravelGatesConfigurations.TPBLOCK.value()).append(ChatColor.YELLOW).append("=")
  549. .append(ChatColor.WHITE).append(_tpBlock);
  550. }
  551. else if (TravelGatesConfigurations.WORLDS.value().equalsIgnoreCase(key))
  552. {
  553. strBuild.append(" ").append(ChatColor.AQUA).append(TravelGatesConfigurations.WORLDS.value()).append(ChatColor.YELLOW).append("=")
  554. .append(ChatColor.WHITE).append(getListOfAdditionnalWorld());
  555. }
  556. else
  557. {
  558. strBuild.append(" ").append(ChatColor.AQUA).append(key).append(ChatColor.YELLOW).append("=")
  559. .append((boolValue.booleanValue()) ? ChatColor.GREEN : ChatColor.RED).append(value);
  560. }
  561. }
  562. if (_isDebugEnabled)
  563. {
  564. _LOGGER.info(_debug + " End getCurrentConfiguration : " + strBuild.toString());
  565. }
  566. return strBuild.toString();
  567. }
  568. public TravelGatesOptionsContainer getOptionsOfDestination(final String destination)
  569. {
  570. if (_isDebugEnabled)
  571. {
  572. _LOGGER.info(_debug + " Start getOptionsOfDestination(destination=" + destination + ")");
  573. }
  574. final TravelGatesOptionsContainer container = _mapOptionsByDest.get(destination.toLowerCase());
  575. if (_isDebugEnabled)
  576. {
  577. _LOGGER.info(_debug + " End getOptionsOfDestination : " + container);
  578. }
  579. return container;
  580. }
  581. public boolean getOptionOfDestination(final String destination, final TravelGatesOptions option)
  582. {
  583. if (_isDebugEnabled)
  584. {
  585. _LOGGER.info(_debug + " Start getOptionOfDestination(destination=" + destination + ", option=" + option + ")");
  586. }
  587. String lowerDest = null;
  588. boolean optionValue = false;
  589. try
  590. {
  591. lowerDest = destination.toLowerCase();
  592. }
  593. catch (final Throwable th)
  594. {
  595. _LOGGER.severe(_tag + " Exception caught while getting lower case of destination : " + destination);
  596. th.printStackTrace();
  597. }
  598. if (lowerDest != null)
  599. {
  600. final TravelGatesOptionsContainer container = _mapOptionsByDest.get(lowerDest);
  601. optionValue = container.has(option);
  602. }
  603. if (_isDebugEnabled)
  604. {
  605. _LOGGER.info(_debug + " End getOptionOfDestination : " + optionValue);
  606. }
  607. return optionValue;
  608. }
  609. public void setOptionOfDestination(final String destination, final TravelGatesOptions option, final boolean newValue)
  610. {
  611. if (_isDebugEnabled)
  612. {
  613. _LOGGER.info(_debug + " Start setOptionOfDestination(destination=" + destination + ", option=" + option + ", newValue=" + newValue + ")");
  614. }
  615. final TravelGatesOptionsContainer container = _mapOptionsByDest.get(destination.toLowerCase());
  616. container.set(option, newValue);
  617. if (_isDebugEnabled)
  618. {
  619. _LOGGER.info(_debug + " End setOptionOfDestination");
  620. }
  621. }
  622. public String getShortLoc(final String destination)
  623. {
  624. if (_isDebugEnabled)
  625. {
  626. _LOGGER.info(_debug + " Start getShortLoc(destination=" + destination + ")");
  627. }
  628. final String shortLoc = _mapShortLocationsByDest.get(destination.toLowerCase());
  629. if (_isDebugEnabled)
  630. {
  631. _LOGGER.info(_debug + " End getShortLoc : " + shortLoc);
  632. }
  633. return shortLoc;
  634. }
  635. public Location getLocation(final String destination)
  636. {
  637. if (_isDebugEnabled)
  638. {
  639. _LOGGER.info(_debug + " Start getLocation(destination=" + destination + ")");
  640. }
  641. final Location loc = _mapLocationsByDest.get(destination.toLowerCase());
  642. if (_isDebugEnabled)
  643. {
  644. _LOGGER.info(_debug + " End getLocation : " + loc);
  645. }
  646. return loc;
  647. }
  648. public String getFullLoc(final String destination)
  649. {
  650. if (_isDebugEnabled)
  651. {
  652. _LOGGER.info(_debug + " Start getFullLoc(destination=" + destination + ")");
  653. }
  654. final String fullLoc = _destinationsData.getProperty(destination.toLowerCase());
  655. if (_isDebugEnabled)
  656. {
  657. _LOGGER.info(_debug + " End getFullLoc : " + fullLoc);
  658. }
  659. return fullLoc;
  660. }
  661. public String getDestination(final Location location)
  662. {
  663. String dest = null;
  664. final String shortLoc = TravelGatesUtils.locationToShortString(location);
  665. dest = getDestination(shortLoc);
  666. return dest;
  667. }
  668. public String getDestination(final String shortLoc)
  669. {
  670. if (_isDebugEnabled)
  671. {
  672. _LOGGER.info(_debug + " Start getDestination(shortLoc=" + shortLoc + ")");
  673. }
  674. String dest = null;
  675. dest = _mapDestinationsByShortLoc.get(shortLoc);
  676. if (_isDebugEnabled)
  677. {
  678. _LOGGER.info(_debug + " End getDestination : " + dest);
  679. }
  680. return dest;
  681. }
  682. public String getDestPattern()
  683. {
  684. return TravelGatesConstants.DESTINATION_NAME_PATTERN;
  685. }
  686. public boolean teleportPlayerToDest(final String dest, final Player player, final boolean destHasBeenChecked,
  687. final boolean ignorePlayerLocation, final String portalDestinationShortLoc)
  688. {
  689. if (_isDebugEnabled)
  690. {
  691. _LOGGER.info(_debug + " Start teleportPlayerToDest(dest=" + dest + ", player=" + player + ", destHasBeenChecked=" + destHasBeenChecked
  692. + ", ignorePlayerLocation=" + ignorePlayerLocation + ")");
  693. }
  694. final String destination = dest.toLowerCase();
  695. if (ignorePlayerLocation || destHasBeenChecked || hasDestination(destination))
  696. {
  697. final String fullLoc = getFullLoc(destination);
  698. final String shortLoc = getShortLoc(destination);
  699. if (getOptionOfDestination(destination, TravelGatesOptions.ADMINTP))
  700. {
  701. if (!hasPermission(player, TravelGatesPermissionsNodes.ADMINTP))
  702. {
  703. player.sendMessage(ChatColor.RED + _messages.get(TravelGatesMessages.ONLY_ADMIN_TP));
  704. return false;
  705. }
  706. }
  707. final Location playerLocation = player.getLocation();
  708. final String playerShortLoc = TravelGatesUtils.locationToShortString(playerLocation);
  709. final boolean targetAndCurrentLocationAreDifferent = !shortLoc.equalsIgnoreCase(playerShortLoc);
  710. final boolean playerIsOnExistingDestination = hasShortLocation(playerShortLoc);
  711. boolean playerNotOnTeleportBlock = false;
  712. String nearestDestinationShortLocation = null;
  713. if (!ignorePlayerLocation)
  714. {
  715. if (playerIsOnExistingDestination || portalDestinationShortLoc != null)
  716. {
  717. if (portalDestinationShortLoc == null && _tpBlock.isEnabled() && !_tpBlock.isTPBlock(player.getWorld().getBlockAt(playerLocation).getRelative(BlockFace.DOWN)))
  718. {
  719. playerNotOnTeleportBlock = true;
  720. }
  721. if (playerIsOnExistingDestination)
  722. {
  723. nearestDestinationShortLocation = playerShortLoc;
  724. }
  725. else if (portalDestinationShortLoc != null)
  726. {
  727. nearestDestinationShortLocation = portalDestinationShortLoc;
  728. }
  729. }
  730. else
  731. {
  732. if (_tpBlock.isEnabled())
  733. {
  734. if (_isDebugEnabled)
  735. {
  736. _LOGGER.info("#0 : Not on dest and tp block enabled");
  737. }
  738. final World currWorld = player.getWorld();
  739. if (_isDebugEnabled)
  740. {
  741. _LOGGER.info("#0-bis : currWorld = " + currWorld);
  742. _LOGGER.info("#0-ters : type block = " + currWorld.getBlockAt(playerLocation).getRelative(BlockFace.DOWN).getType());
  743. }
  744. playerNotOnTeleportBlock = !_tpBlock.isTPBlock(currWorld.getBlockAt(playerLocation).getRelative(BlockFace.DOWN));
  745. if (_isDebugEnabled)
  746. {
  747. _LOGGER.info("#1 : playerNotOnTeleportBlock = " + playerNotOnTeleportBlock);
  748. }
  749. if (!playerNotOnTeleportBlock)
  750. {
  751. // Search the locations in the current player's
  752. // world
  753. ArrayList<Location> rightWorldsList = new ArrayList<Location>();
  754. for (final Object key : _mapLocationsByDest.keySet())
  755. {
  756. final Location loc = _mapLocationsByDest.get(key);
  757. if (_isDebugEnabled)
  758. {
  759. _LOGGER.info("#1bis : key = " + key + " ; playerLocation.getWorld()=" + playerLocation.getWorld()
  760. + " ; loc.getWorld()= " + loc.getWorld());
  761. }
  762. if (playerLocation.getWorld() == loc.getWorld())
  763. {
  764. rightWorldsList.add(loc);
  765. }
  766. }
  767. if (_isDebugEnabled)
  768. {
  769. _LOGGER.info("#2 : rightWorldsList size = " + rightWorldsList.size());
  770. }
  771. if (!rightWorldsList.isEmpty())
  772. {
  773. // Search the locations at the same height
  774. ArrayList<Location> rightHeightList = new ArrayList<Location>();
  775. for (final Location loc : rightWorldsList)
  776. {
  777. if (loc.getBlockY() == playerLocation.getBlockY())
  778. {
  779. rightHeightList.add(loc);
  780. }
  781. }
  782. if (_isDebugEnabled)
  783. {
  784. _LOGGER.info("#3 : rightHeightList size = " + rightHeightList.size());
  785. }
  786. if (!rightHeightList.isEmpty())
  787. {
  788. // Search the nearest destination from
  789. // the
  790. // Player's location
  791. Location nearestDestinationLocation = null;
  792. int lastMinX = TravelGatesConstants.MAX_COORDINATE;
  793. int lastMinZ = TravelGatesConstants.MAX_COORDINATE;
  794. if (_isDebugEnabled)
  795. {
  796. _LOGGER.info("#3-a : nearestDestinationLocation = " + nearestDestinationLocation);
  797. }
  798. for (final Location loc : rightHeightList)
  799. {
  800. if (_isDebugEnabled)
  801. {
  802. _LOGGER.info("#3-b : loc = " + loc);
  803. }
  804. if (nearestDestinationLocation == null)
  805. {
  806. lastMinX = TravelGatesUtils.getCoordinateDiff(loc.getBlockX(), playerLocation.getBlockX());
  807. lastMinZ = TravelGatesUtils.getCoordinateDiff(loc.getBlockZ(), playerLocation.getBlockZ());
  808. nearestDestinationLocation = loc;
  809. if (_isDebugEnabled)
  810. {
  811. _LOGGER.info("#3-c : lastMinX = " + lastMinX + " ; lastMinZ = " + lastMinZ);
  812. }
  813. }
  814. else
  815. {
  816. final int xDiff = TravelGatesUtils.getCoordinateDiff(loc.getBlockX(), playerLocation.getBlockX());
  817. final int zDiff = TravelGatesUtils.getCoordinateDiff(loc.getBlockZ(), playerLocation.getBlockZ());
  818. if (_isDebugEnabled)
  819. {
  820. _LOGGER.info("#3-d : xDiff = " + xDiff + " ; zDiff = " + zDiff);
  821. _LOGGER.info("#3-e : lastMinX = " + lastMinX + " ; lastMinZ = " + lastMinZ);
  822. }
  823. if (xDiff + zDiff <= lastMinX + lastMinZ)
  824. {
  825. lastMinX = xDiff;
  826. lastMinZ = zDiff;
  827. nearestDestinationLocation = loc;
  828. }
  829. }
  830. if (_isDebugEnabled)
  831. {
  832. _LOGGER.info("#3-f : nearestDestinationLocation = " + nearestDestinationLocation);
  833. }
  834. }
  835. if (_isDebugEnabled)
  836. {
  837. _LOGGER.info("#4 : nearestDestinationLocation = " + nearestDestinationLocation);
  838. }
  839. if (nearestDestinationLocation != null)
  840. {
  841. int pX = playerLocation.getBlockX();
  842. int pZ = playerLocation.getBlockZ();
  843. if (_isDebugEnabled)
  844. {
  845. _LOGGER.info("#5 : pX = " + pX + " ; pZ = " + pZ);
  846. }
  847. final int dX = nearestDestinationLocation.getBlockX();
  848. final int dZ = nearestDestinationLocation.getBlockZ();
  849. if (_isDebugEnabled)
  850. {
  851. _LOGGER.info("#6 : dX = " + dX + " ; dZ = " + dZ);
  852. }
  853. int xDiff = TravelGatesUtils.getCoordinateDiff(dX, pX);
  854. int zDiff = TravelGatesUtils.getCoordinateDiff(dZ, pZ);
  855. if (_isDebugEnabled)
  856. {
  857. _LOGGER.info("#7 : xDiff = " + xDiff + " ; zDiff = " + zDiff);
  858. }
  859. // The nearest destination is at 5
  860. // blocks max from the player
  861. if (xDiff <= TravelGatesConstants.MAX_TARGET_RANGE && zDiff <= TravelGatesConstants.MAX_TARGET_RANGE)
  862. {
  863. final int offsetX = ((pX - dX) > 0) ? -1 : 1;
  864. final int offsetZ = ((pZ - dZ) > 0) ? -1 : 1;
  865. if (_isDebugEnabled)
  866. {
  867. _LOGGER.info("#8 : offsetX = " + offsetX + " ; offsetZ = " + offsetZ);
  868. }
  869. final int heightOfBeneathBlock = playerLocation.getBlockY() - 1;
  870. if (_isDebugEnabled)
  871. {
  872. _LOGGER.info("#9 : heightOfBeneathBlock = " + heightOfBeneathBlock);
  873. }
  874. // Is blocks between player and
  875. // the
  876. // nearest destination are TP
  877. // blocks
  878. // ?
  879. while (xDiff > 0 && !playerNotOnTeleportBlock)
  880. {
  881. pX += offsetX;
  882. playerNotOnTeleportBlock = !_tpBlock.isTPBlock(currWorld.getBlockAt(pX, heightOfBeneathBlock, pZ));
  883. xDiff = TravelGatesUtils.getCoordinateDiff(dX, pX);
  884. if (_isDebugEnabled)
  885. {
  886. _LOGGER.info("#10 : pX = " + pX + " ; xDiff = " + xDiff + " ; playerNotOnTeleportBlock = "
  887. + playerNotOnTeleportBlock);
  888. }
  889. }
  890. if (!playerNotOnTeleportBlock)
  891. {
  892. while (zDiff > 0 && !playerNotOnTeleportBlock)
  893. {
  894. pZ += offsetZ;
  895. playerNotOnTeleportBlock = !_tpBlock
  896. .isTPBlock(currWorld.getBlockAt(pX, heightOfBeneathBlock, pZ));
  897. zDiff = TravelGatesUtils.getCoordinateDiff(dZ, pZ);
  898. if (_isDebugEnabled)
  899. {
  900. _LOGGER.info("#11 : pZ = " + pZ + " ; zDiff = " + zDiff + " ; playerNotOnTeleportBlock = "
  901. + playerNotOnTeleportBlock);
  902. }
  903. }
  904. // Get the short loc of the
  905. // nearest destination
  906. if (!playerNotOnTeleportBlock)
  907. {
  908. nearestDestinationShortLocation = TravelGatesUtils
  909. .locationToShortString(nearestDestinationLocation);
  910. }
  911. }
  912. }
  913. else
  914. {
  915. playerNotOnTeleportBlock = true;
  916. }
  917. }
  918. else
  919. {
  920. playerNotOnTeleportBlock = true;
  921. }
  922. }
  923. else
  924. {
  925. playerNotOnTeleportBlock = true;
  926. }
  927. }
  928. else
  929. {
  930. playerNotOnTeleportBlock = true;
  931. }
  932. }
  933. }
  934. }
  935. }
  936. if (_isDebugEnabled)
  937. {
  938. _LOGGER.info("#12 : playerNotOnTeleportBlock = " + playerNotOnTeleportBlock);
  939. _LOGGER.info("#13 : nearestDestinationShortLocation = " + nearestDestinationShortLocation);
  940. }
  941. if (_tpBlock.isEnabled() && playerNotOnTeleportBlock)
  942. {
  943. player.sendMessage(ChatColor.RED
  944. + _messages.get(TravelGatesMessages.NOT_STANDING_ON_TPBLOCK, ChatColor.YELLOW + _tpBlock.toString() + ChatColor.RED));
  945. return false;
  946. }
  947. if (ignorePlayerLocation || targetAndCurrentLocationAreDifferent
  948. && (nearestDestinationShortLocation != null || !playerNotOnTeleportBlock && _tpBlock.isEnabled()))
  949. {
  950. final String currentDest = _mapDestinationsByShortLoc.get(nearestDestinationShortLocation);
  951. if (_isDebugEnabled)
  952. {
  953. _LOGGER.info("#14 : currentDest = " + currentDest);
  954. }
  955. if (!ignorePlayerLocation)
  956. {
  957. if (currentDest != null && getOptionOfDestination(currentDest, TravelGatesOptions.RESTRICTION))
  958. {
  959. final TravelGatesOptionsContainer container = _mapOptionsByDest.get(currentDest);
  960. if (container != null && !container.isDestinationAllowed(destination))
  961. {
  962. player.sendMessage(ChatColor.RED
  963. + _messages.get(TravelGatesMessages.DESTINATION_IS_RESTRICTED, ChatColor.AQUA + currentDest + ChatColor.RED,
  964. ChatColor.AQUA + destination + ChatColor.RED));
  965. return false;
  966. }
  967. }
  968. else if (currentDest == null)
  969. {
  970. player.sendMessage(ChatColor.RED + _messages.get(TravelGatesMessages.NO_STANDING_ON_DESTINATION));
  971. return false;
  972. }
  973. }
  974. final Location targetLocation = TravelGatesUtils.fullStringToLocation(fullLoc, player.getServer().getWorlds());
  975. if (targetLocation.getWorld() != null)
  976. {
  977. player.teleport(targetLocation);
  978. }
  979. else
  980. {
  981. player.sendMessage(ChatColor.RED
  982. + _messages.get(TravelGatesMessages.TELEPORT_CANCELLED_WORLD_UNLOADED, ChatColor.AQUA + destination + ChatColor.RED));
  983. return false;
  984. }
  985. if (ignorePlayerLocation)
  986. {
  987. _LOGGER.info(_tag + " " + player.getName() + " has forced the travel from " + playerShortLoc + " to " + destination);
  988. }
  989. else
  990. {
  991. _LOGGER.info(_tag + " " + player.getName() + " has travelled from " + currentDest + " to " + destination);
  992. }
  993. final boolean inventoryCleared = getOptionOfDestination(destination, TravelGatesOptions.INVENTORY);
  994. // System.out.println("inventoryCleared=" + inventoryCleared + "; _protectAdminInventory=" + _protectAdminInventory
  995. // + "; perm=" + hasPermission(player, TravelGatesPermissionsNodes.PROTECTADMININV));
  996. if (!inventoryCleared || isProtectedInventory(player))
  997. {
  998. if (_isDisplayTeleportMessage)
  999. {
  1000. player.sendMessage(ChatColor.YELLOW
  1001. + _messages.get(TravelGatesMessages.YOU_ARE_ARRIVED_AT, ChatColor.AQUA + destination + ChatColor.YELLOW)
  1002. + ChatColor.GREEN + _messages.get(TravelGatesMessages.INVENTORY_KEPT));
  1003. }
  1004. }
  1005. else
  1006. {
  1007. String inventoryMessage = "";
  1008. final PlayerInventory inventory = player.getInventory();
  1009. if (_clearAllInventory)
  1010. {
  1011. inventory.setArmorContents(null);
  1012. inventoryMessage = _messages.get(TravelGatesMessages.ALL_INVENTORY_LOST);
  1013. }
  1014. else
  1015. {
  1016. inventoryMessage = _messages.get(TravelGatesMessages.INVENTORY_LOST);
  1017. }
  1018. inventory.clear();
  1019. if (_isDisplayTeleportMessage)
  1020. {
  1021. player.sendMessage(ChatColor.YELLOW
  1022. + _messages.get(TravelGatesMessages.YOU_ARE_ARRIVED_AT, ChatColor.AQUA + destination + ChatColor.YELLOW) + ChatColor.RED
  1023. + inventoryMessage);
  1024. }
  1025. }
  1026. // If the arrival chunk is unloaded, it will be forced to load
  1027. final Chunk arrivalChunk = player.getWorld().getChunkAt(targetLocation);
  1028. if (!arrivalChunk.isLoaded())
  1029. {
  1030. if (_isDebugEnabled)
  1031. {
  1032. _LOGGER.info(_debug + " The " + destination + "'s chunk was not loaded at " + targetLocation);
  1033. }
  1034. arrivalChunk.load();
  1035. }
  1036. if (_isDebugEnabled)
  1037. {
  1038. _LOGGER.info(_debug + " End teleportPlayerToDest : true");
  1039. }
  1040. return true;
  1041. }
  1042. else
  1043. {
  1044. if (!targetAndCurrentLocationAreDifferent)
  1045. {
  1046. player.sendMessage(ChatColor.RED
  1047. + _messages.get(TravelGatesMessages.YOURE_ALREADY_AT, ChatColor.AQUA + destination + ChatColor.RED));
  1048. }
  1049. else if (!playerIsOnExistingDestination)
  1050. {
  1051. player.sendMessage(ChatColor.RED
  1052. + _messages.get(TravelGatesMessages.YOU_CANT_GO_THERE, ChatColor.AQUA + destination + ChatColor.RED));
  1053. }
  1054. }
  1055. }
  1056. else
  1057. {
  1058. player.sendMessage(ChatColor.RED
  1059. + _messages.get(TravelGatesMessages.DESTINATION_DOESNT_EXIST, ChatColor.AQUA + destination + ChatColor.RED));
  1060. }
  1061. if (_isDebugEnabled)
  1062. {
  1063. _LOGGER.info(_debug + " End teleportPlayerToDest : false");
  1064. }
  1065. return false;
  1066. }
  1067. public String getMessage(final TravelGatesMessages message, final String... vars)
  1068. {
  1069. return _messages.get(message, vars);
  1070. }
  1071. public boolean usePermissions()
  1072. {
  1073. return _usePermissions;
  1074. }
  1075. private boolean loadDestinations()
  1076. {
  1077. if (_isDebugEnabled)
  1078. {
  1079. _LOGGER.info(_debug + " Start loadDestinations()");
  1080. }
  1081. boolean ret = false;
  1082. boolean isfileCreated = false;
  1083. _destinationsFile = new File(TravelGatesConstants.PLUGIN_FILE_PATH);
  1084. if (!_destinationsFile.exists())
  1085. {
  1086. try
  1087. {
  1088. final File rootDir = new File(TravelGatesConstants.PLUGIN_ROOT_PATH);
  1089. isfileCreated = rootDir.mkdir();
  1090. isfileCreated &= _destinationsFile.createNewFile();
  1091. _destinationsFile.setReadable(true, false);
  1092. _destinationsFile.setWritable(true, false);
  1093. _destinationsFile.setExecutable(true, false);
  1094. }
  1095. catch (final IOException ioex)
  1096. {
  1097. _LOGGER.severe(_tag + " Destinations file creation failed !");
  1098. ioex.printStackTrace();
  1099. }
  1100. }
  1101. else
  1102. {
  1103. isfileCreated = true;
  1104. }
  1105. if (!isfileCreated)
  1106. {
  1107. _LOGGER.severe(_tag + " Destinations file creation failed !");
  1108. }
  1109. else
  1110. {
  1111. FileInputStream in = null;
  1112. try
  1113. {
  1114. in = new FileInputStream(_destinationsFile);
  1115. }
  1116. catch (final FileNotFoundException ex)
  1117. {
  1118. _LOGGER.info(_tag + " Destinations file failed to be read : ");
  1119. ex.printStackTrace();
  1120. }
  1121. if (in != null)
  1122. {
  1123. try
  1124. {
  1125. _destinationsData.load(in);
  1126. in.close();
  1127. }
  1128. catch (final IOException ex)
  1129. {
  1130. _LOGGER.severe(_tag + " Error while reading the Destinations file.");
  1131. ex.printStackTrace();
  1132. }
  1133. if (!_destinationsData.isEmpty())
  1134. {
  1135. for (final Object key : _destinationsData.keySet())
  1136. {
  1137. final String dest = String.valueOf(key).toLowerCase();
  1138. final String fullString = _destinationsData.getProperty(dest);
  1139. final String shortLoc = TravelGatesUtils.fullStringToShortString(fullString);
  1140. _mapShortLocationsByDest.put(dest, shortLoc);
  1141. _mapLocationsByDest.put(dest, TravelGatesUtils.shortStringToLocation(shortLoc, getServer().getWorlds()));
  1142. _mapDestinationsByShortLoc.put(shortLoc, dest);
  1143. final TravelGatesOptionsContainer container = new TravelGatesOptionsContainer(this, fullString.substring(1 + fullString
  1144. .lastIndexOf(TravelGatesConstants.DELIMITER)));
  1145. _mapOptionsByDest.put(dest, container);
  1146. }
  1147. loadRestrictions();
  1148. }
  1149. ret = true;
  1150. }
  1151. else
  1152. {
  1153. _LOGGER.info(_tag + " Destinations file could not be loaded.");
  1154. }
  1155. }
  1156. if (_isDebugEnabled)
  1157. {
  1158. _LOGGER.info(_debug + " End loadDestinations : " + ret);
  1159. }
  1160. return ret;
  1161. }
  1162. private void loadRestrictions()
  1163. {
  1164. if (_isDebugEnabled)
  1165. {
  1166. _LOGGER.info(_debug + " Start loadRestrictions()");
  1167. }
  1168. _restrictionsFile = new File(TravelGatesConstants.PLUGIN_RESTRICTIONS_FILE_PATH);
  1169. if (_restrictionsFile.exists())
  1170. {
  1171. FileInputStream in = null;
  1172. try
  1173. {
  1174. in = new FileInputStream(_restrictionsFile);
  1175. }
  1176. catch (final FileNotFoundException ex)
  1177. {
  1178. _LOGGER.info(_tag + " Restrictions file not found.");
  1179. ex.printStackTrace();
  1180. return;
  1181. }
  1182. if (in != null)
  1183. {
  1184. try
  1185. {
  1186. _restrictionsData.load(in);
  1187. in.close();
  1188. }
  1189. catch (final IOException ex)
  1190. {
  1191. _LOGGER.severe(_tag + " Error while reading the Restrictions file.");
  1192. ex.printStackTrace();
  1193. }
  1194. if (!_restrictionsData.isEmpty())
  1195. {
  1196. for (final Object key : _restrictionsData.keySet())
  1197. {
  1198. final String dest = String.valueOf(key).toLowerCase();
  1199. final TravelGatesOptionsContainer optionsContainer = _mapOptionsByDest.get(dest);
  1200. if (optionsContainer.has(TravelGatesOptions.RESTRICTION))
  1201. {
  1202. optionsContainer.setRestrictionsList(_restrictionsData.getProperty(dest));
  1203. }
  1204. }
  1205. }
  1206. }
  1207. }
  1208. else
  1209. {
  1210. _LOGGER.info(_tag + " Restrictions file not found. New file created with the name : " + TravelGatesConstants.RESTRICTIONS_FILE_NAME);
  1211. try
  1212. {
  1213. _restrictionsFile.createNewFile();
  1214. _restrictionsFile.setReadable(true, false);
  1215. _restrictionsFile.setWritable(true, false);
  1216. _restrictionsFile.setExecutable(true, false);
  1217. }
  1218. catch (final IOException e)
  1219. {
  1220. _LOGGER.severe(_tag + " Unable to create Restriction file: ");
  1221. e.printStackTrace();
  1222. }
  1223. }
  1224. if (_isDebugEnabled)
  1225. {
  1226. _LOGGER.info(_debug + " End loadRestrictions");
  1227. }
  1228. }
  1229. private boolean loadConfiguration()
  1230. {
  1231. _configFile = new File(TravelGatesConstants.PLUGIN_CONFIG_PATH);
  1232. if (_configFile.exists())
  1233. {
  1234. FileInputStream in = null;
  1235. try
  1236. {
  1237. in = new FileInputStream(_configFile);
  1238. }
  1239. catch (final Throwable ex)
  1240. {
  1241. _LOGGER.severe(_tag + " Unable to create a stream to read the configuration file.");
  1242. ex.printStackTrace();
  1243. return false;
  1244. }
  1245. if (in != null)
  1246. {
  1247. // LOAD CONFIGURATIONS
  1248. try
  1249. {
  1250. _configData.load(in);
  1251. in.close();
  1252. }
  1253. catch (final IOException ex)
  1254. {
  1255. _LOGGER.severe(_tag + " Error while loading the Configuration file.");
  1256. ex.printStackTrace();
  1257. return false;
  1258. }
  1259. // DEBUG
  1260. try
  1261. {
  1262. final String debugEnabled = _configData.getProperty(TravelGatesConfigurations.DEBUG.value());
  1263. if (TravelGatesUtils.stringIsNotBlank(debugEnabled))
  1264. {
  1265. _isDebugEnabled = Boolean.parseBoolean(debugEnabled.toLowerCase());
  1266. TravelGatesUtils.setDebugState(_isDebugEnabled);
  1267. }
  1268. else
  1269. {
  1270. _LOGGER.warning(_tag + " Debug configuration not found.");
  1271. }
  1272. _LOGGER.info(_tag + " Debug configuration set to : " + _isDebugEnabled);
  1273. }
  1274. catch (final Throwable th)
  1275. {
  1276. _LOGGER.severe(_tag + " Debug configuration reading failed.");
  1277. th.printStackTrace();
  1278. return false;
  1279. }
  1280. // DISPLAY TELEPORT MESSAGE
  1281. try
  1282. {
  1283. final String displayTeleportMessage =
  1284. _configData.getProperty(TravelGatesConfigurations.DISPLAYTELEPORTMESSAGE.value());
  1285. if (TravelGatesUtils.stringIsNotBlank(displayTeleportMessage))
  1286. {
  1287. _isDisplayTeleportMessage = Boolean.parseBoolean(displayTeleportMessage.toLowerCase());
  1288. }
  1289. else
  1290. {
  1291. _LOGGER.warning(_tag + " Display teleport message configuration not found.");
  1292. }
  1293. _LOGGER.info(_tag + " Display teleport message configuration set to : " + _isDisplayTeleportMessage);
  1294. }
  1295. catch (final Throwable th)
  1296. {
  1297. _LOGGER.severe(_tag + " Display teleport message configuration reading failed.");
  1298. th.printStackTrace();
  1299. return false;
  1300. }
  1301. // LANGUAGE
  1302. try
  1303. {
  1304. final String language = _configData.getProperty(TravelGatesConfigurations.LANGUAGE.value());
  1305. if (TravelGatesUtils.stringIsNotBlank(language))
  1306. {
  1307. _language = language.toLowerCase();
  1308. }
  1309. else
  1310. {
  1311. _LOGGER.warning(_tag + " Language configuration not found.");
  1312. }
  1313. _LOGGER.info(_tag + " Language configuration set to : " + _language);
  1314. }
  1315. catch (final Throwable th)
  1316. {
  1317. _LOGGER.severe(_tag + " Language configuration reading failed.");
  1318. th.printStackTrace();
  1319. return false;
  1320. }
  1321. // USE PERMISSIONS
  1322. try
  1323. {
  1324. final String usePermissions = _configData.getProperty(TravelGatesConfigurations.USEPERMISSIONS.value());
  1325. if (TravelGatesUtils.stringIsNotBlank(usePermissions))
  1326. {
  1327. _usePermissions = Boolean.parseBoolean(usePermissions.toLowerCase());
  1328. }
  1329. else
  1330. {
  1331. _LOGGER.warning(_tag + " Permissions configuration not found.");
  1332. }
  1333. _LOGGER.info(_tag + " Permissions configuration set to : " + _usePermissions);
  1334. }
  1335. catch (final Throwable th)
  1336. {
  1337. _LOGGER.severe(_tag + " Permissions configuration reading failed.");
  1338. th.printStackTrace();
  1339. return false;
  1340. }
  1341. // TELEPORT MODES
  1342. try
  1343. {
  1344. final String teleportWithSign = _configData.getProperty(TravelGatesConfigurations.TELEPORTWITHSIGN.value());
  1345. final String teleportWithPortal = _configData.getProperty(TravelGatesConfigurations.TELEPORTWITHPORTAL.value());
  1346. if (TravelGatesUtils.stringIsNotBlank(teleportWithSign))
  1347. {
  1348. _teleportWithSign = Boolean.parseBoolean(teleportWithSign.toLowerCase());
  1349. }
  1350. else
  1351. {
  1352. _LOGGER.warning(_tag + " Sign teleportation configuration not found.");
  1353. }
  1354. if (TravelGatesUtils.stringIsNotBlank(teleportWithPortal))
  1355. {
  1356. _teleportWithPortal = Boolean.parseBoolean(teleportWithPortal.toLowerCase());
  1357. }
  1358. else
  1359. {
  1360. _LOGGER.warning(_tag + " Portal teleportation configuration not found.");
  1361. }
  1362. _LOGGER.info(_tag + " Teleport modes configuration set to : sign=" + _teleportWithSign + ", portal=" + _teleportWithPortal);
  1363. }
  1364. catch (final Throwable th)
  1365. {
  1366. _LOGGER.severe(_tag + " Teleport modes configuration reading failed.");
  1367. th.printStackTrace();
  1368. return false;
  1369. }
  1370. // CLEAR ALL INVENTORY
  1371. try
  1372. {
  1373. final String clearAllInventory = _configData.getProperty(TravelGatesConfigurations.CLEARALLINVENTORY.value());
  1374. if (TravelGatesUtils.stringIsNotBlank(clearAllInventory))
  1375. {
  1376. _clearAllInventory = Boolean.parseBoolean(clearAllInventory.toLowerCase());
  1377. }
  1378. else
  1379. {
  1380. _LOGGER.warning(_tag + " Clear all inventory configuration not found.");
  1381. }
  1382. _LOGGER.info(_tag + " Clear all inventory configuration set to : " + _clearAllInventory);
  1383. }
  1384. catch (final Throwable th)
  1385. {
  1386. _LOGGER.severe(_tag + " Clear all inventory configuration reading failed.");
  1387. th.printStackTrace();
  1388. return false;
  1389. }
  1390. // PROTECT ADMIN INVENTORY
  1391. try
  1392. {
  1393. final String protectAdminInventory =
  1394. _configData.getProperty(TravelGatesConfigurations.PROTECTADMININVENTORY.value());
  1395. if (TravelGatesUtils.stringIsNotBlank(protectAdminInventory))
  1396. {
  1397. _protectAdminInventory = Boolean.parseBoolean(protectAdminInventory.toLowerCase());
  1398. }
  1399. else
  1400. {
  1401. _LOGGER.warning(_tag + " Protect admin inventory configuration not found.");
  1402. }
  1403. _LOGGER.info(_tag + " Protect admin inventory configuration set to : " + _protectAdminInventory);
  1404. }
  1405. catch (final Throwable th)
  1406. {
  1407. _LOGGER.severe(_tag + " Protect admin inventory configuration reading failed.");
  1408. th.printStackTrace();
  1409. return false;
  1410. }
  1411. // AUTO SAVE
  1412. try
  1413. {
  1414. final String autosave = _configData.getProperty(TravelGatesConfigurations.AUTOSAVE.value());
  1415. if (TravelGatesUtils.stringIsNotBlank(autosave))
  1416. {
  1417. _autosave = Boolean.parseBoolean(autosave.toLowerCase());
  1418. }
  1419. else
  1420. {
  1421. _LOGGER.warning(_tag + " Autosav