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

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

https://github.com/Ghomerr/TravelGates
Java | 820 lines | 544 code | 128 blank | 148 comment | 120 complexity | 83c4ffb8563d38e7792206dbc284ef2e MD5 | raw file
  1. package com.ghomerr.travelgates.utils;
  2. import java.util.List;
  3. import java.util.logging.Logger;
  4. import org.bukkit.Location;
  5. import org.bukkit.Material;
  6. import org.bukkit.World;
  7. import org.bukkit.block.Block;
  8. import org.bukkit.block.BlockFace;
  9. import org.bukkit.block.Sign;
  10. import com.ghomerr.travelgates.TravelGates;
  11. import com.ghomerr.travelgates.constants.TravelGatesConstants;
  12. import com.ghomerr.travelgates.enums.TravelGatesBlockFaces;
  13. import com.ghomerr.travelgates.enums.TravelGatesCommands;
  14. import com.ghomerr.travelgates.objects.TravelGatesPortalSign;
  15. public class TravelGatesUtils
  16. {
  17. private static final Logger _LOGGER = Logger.getLogger("Minecraft");
  18. private static boolean _isDebugEnabled = false;
  19. private static final String _debug = TravelGatesConstants.DEBUG_TAG;
  20. public static void setDebugState(final boolean state)
  21. {
  22. _isDebugEnabled = state;
  23. }
  24. public static String floor (final Number value)
  25. {
  26. final String str = String.valueOf(value);
  27. final String[] splt = str.split(TravelGatesConstants.FLOAT_DELIM_PATTERN);
  28. String ret = splt[0];
  29. if (splt.length == 2 && TravelGatesConstants.ZERO.equals(splt[1]))
  30. {
  31. // A negative bloc at location = -3.0 is from -2.0 to -3.0. ShortLocs are absolute
  32. final int intVal = Integer.parseInt(ret);
  33. if (intVal < 0)
  34. {
  35. ret = String.valueOf(intVal + 1);
  36. }
  37. }
  38. return ret;
  39. }
  40. // public static String floor(final Double value)
  41. // {
  42. // if (_isDebugEnabled)
  43. // {
  44. // _LOGGER.info(_debug + " Start floor(value=" + value + ")");
  45. // }
  46. //
  47. // final String str = String.valueOf(value);
  48. // final int i = str.indexOf(",");
  49. // final int index = (i > 0) ? i : str.indexOf(".");
  50. //
  51. // final String ret = str.substring(0, index);
  52. //
  53. // final String[] splt = str.split("[.,]");
  54. //
  55. // if (_isDebugEnabled)
  56. // {
  57. // _LOGGER.info(_debug + " End floor : " + ret);
  58. // }
  59. //
  60. // return splt[0];
  61. // }
  62. //
  63. // public static String floor(final Float value)
  64. // {
  65. // if (_isDebugEnabled)
  66. // {
  67. // _LOGGER.info(_debug + " Start floor(value=" + value + ")");
  68. // }
  69. //
  70. // final String str = String.valueOf(value);
  71. // final int i = str.indexOf(",");
  72. // final int index = (i > 0) ? i : str.indexOf(".");
  73. //
  74. // final String ret = str.substring(0, index);
  75. //
  76. // if (_isDebugEnabled)
  77. // {
  78. // _LOGGER.info(_debug + " End floor : " + ret);
  79. // }
  80. //
  81. // return ret;
  82. // }
  83. public static String locationToShortString(final Location location)
  84. {
  85. // if (_isDebugEnabled)
  86. // {
  87. // _LOGGER.info(_debug + " Start locationToShortString(location=" + location + ")");
  88. // }
  89. final StringBuilder strBldr = new StringBuilder();
  90. strBldr.append(location.getWorld().getName()).append(TravelGatesConstants.DELIMITER)
  91. .append(floor(location.getX())).append(TravelGatesConstants.DELIMITER).append(floor(location.getY()))
  92. .append(TravelGatesConstants.DELIMITER).append(floor(location.getZ()));
  93. // if (_isDebugEnabled)
  94. // {
  95. // _LOGGER.info(_debug + " End locationToShortString : " + strBldr.toString());
  96. // }
  97. return strBldr.toString();
  98. }
  99. public static String locationToFullString(final Location location)
  100. {
  101. // if (_isDebugEnabled)
  102. // {
  103. // _LOGGER.info(_debug + " Start locationToFullString(location=" + location + ")");
  104. // }
  105. final StringBuilder strBldr = new StringBuilder();
  106. strBldr.append(location.getWorld().getName()).append(TravelGatesConstants.DELIMITER)
  107. .append(floor(location.getX())).append(TravelGatesConstants.DELIMITER).append(floor(location.getY()))
  108. .append(TravelGatesConstants.DELIMITER).append(floor(location.getZ()))
  109. .append(TravelGatesConstants.DELIMITER).append(floor(location.getYaw()));
  110. //
  111. // if (_isDebugEnabled)
  112. // {
  113. // _LOGGER.info(_debug + " End locationToFullString : " + strBldr.toString());
  114. // }
  115. return strBldr.toString();
  116. }
  117. public static Location fullStringToLocation(final String fullString, final List<World> worlds)
  118. {
  119. if (_isDebugEnabled)
  120. {
  121. _LOGGER.info(_debug + " Start fullStringToLocation(fullString=" + fullString + ", worlds=" + worlds + ")");
  122. }
  123. final String[] tab = fullString.split(TravelGatesConstants.DELIMITER);
  124. World worldFound = null;
  125. Location newLoc = null;
  126. if (tab.length > 4)
  127. {
  128. for (final World world : worlds)
  129. {
  130. if (world.getName().equalsIgnoreCase(tab[0]))
  131. {
  132. worldFound = world;
  133. break;
  134. }
  135. }
  136. double posX = Double.parseDouble(tab[1]);
  137. double posZ = Double.parseDouble(tab[3]);
  138. posX = (posX >= 0) ? posX + 0.5 : posX - 0.5;
  139. posZ = (posZ >= 0) ? posZ + 0.5 : posZ - 0.5;
  140. newLoc = new Location(worldFound, posX, Double.parseDouble(tab[2]), posZ, Float.parseFloat(tab[4]), 0f);
  141. if (_isDebugEnabled)
  142. {
  143. _LOGGER.info(_debug + " Start fullStringToLocation : " + newLoc);
  144. }
  145. return newLoc;
  146. }
  147. else
  148. {
  149. _LOGGER.severe(TravelGatesConstants.PLUGIN_TAG + " The string '" + fullString + "' is invalid.");
  150. if (_isDebugEnabled)
  151. {
  152. _LOGGER.info(_debug + " End fullStringToLocation : null");
  153. }
  154. return null;
  155. }
  156. }
  157. public static Location shortStringToLocation(final String shortLoc, List<World> worlds)
  158. {
  159. // if (_isDebugEnabled)
  160. // {
  161. // _LOGGER.info(_debug + " Start shortStringToLocation(shortLoc=" + shortLoc + ", worlds=" + worlds + ")");
  162. // }
  163. final String[] tab = shortLoc.split(TravelGatesConstants.DELIMITER);
  164. World worldFound = null;
  165. Location newLoc = null;
  166. if (tab.length > 3)
  167. {
  168. for (final World world : worlds)
  169. {
  170. if (world.getName().equalsIgnoreCase(tab[0]))
  171. {
  172. worldFound = world;
  173. break;
  174. }
  175. }
  176. double posX = Double.parseDouble(tab[1]);
  177. double posZ = Double.parseDouble(tab[3]);
  178. posX = (posX >= 0) ? posX + 0.5 : posX - 0.5;
  179. posZ = (posZ >= 0) ? posZ + 0.5 : posZ - 0.5;
  180. newLoc = new Location(worldFound, posX, Double.parseDouble(tab[2]), posZ, 0f, 0f);
  181. // if (_isDebugEnabled)
  182. // {
  183. // _LOGGER.info(_debug + " Start shortStringToLocation : " + newLoc);
  184. // }
  185. return newLoc;
  186. }
  187. else
  188. {
  189. _LOGGER.severe(TravelGatesConstants.PLUGIN_TAG + " The string '" + shortLoc + "' is invalid.");
  190. // if (_isDebugEnabled)
  191. // {
  192. // _LOGGER.info(_debug + " End shortStringToLocation : null");
  193. // }
  194. return null;
  195. }
  196. }
  197. public static String fullStringToShortString(final String fullString)
  198. {
  199. if (_isDebugEnabled)
  200. {
  201. _LOGGER.info(_debug + " Start fullStringToShortString(fullString=" + fullString + ")");
  202. }
  203. final String[] split = fullString.split(TravelGatesConstants.DELIMITER);
  204. if (split.length > 3)
  205. {
  206. final StringBuilder strBuild = new StringBuilder();
  207. strBuild.append(split[0]).append(TravelGatesConstants.DELIMITER).append(split[1])
  208. .append(TravelGatesConstants.DELIMITER).append(split[2]).append(TravelGatesConstants.DELIMITER)
  209. .append(split[3]);
  210. if (_isDebugEnabled)
  211. {
  212. _LOGGER.info(_debug + " End fullStringToShortString : " + strBuild.toString());
  213. }
  214. return strBuild.toString();
  215. }
  216. else
  217. {
  218. _LOGGER.severe(TravelGatesConstants.PLUGIN_TAG + " The destinations file is invalid : " + fullString);
  219. if (_isDebugEnabled)
  220. {
  221. _LOGGER.info(_debug + " End fullStringToShortString : null");
  222. }
  223. return null;
  224. }
  225. }
  226. public static boolean isSign(final Block block)
  227. {
  228. return block.getType() == Material.SIGN || block.getType() == Material.WALL_SIGN
  229. || block.getType() == Material.SIGN_POST;
  230. }
  231. public static boolean isPortalSign(final TravelGates plugin, final String[] lines)
  232. {
  233. boolean hasTag = false;
  234. boolean hasState = false;
  235. final String onState = plugin.getPortalSignOnState();
  236. final String offState = plugin.getPortalSignOffState();
  237. boolean isPortalSign = false;
  238. for (final String line : lines)
  239. {
  240. if (TravelGatesCommands.containsTravelGatesCommand(line))
  241. {
  242. hasTag = true;
  243. }
  244. if (line.contains(onState) || line.contains(offState))
  245. {
  246. hasState = true;
  247. }
  248. isPortalSign = hasTag && hasState;
  249. if (isPortalSign)
  250. {
  251. break;
  252. }
  253. }
  254. return isPortalSign;
  255. }
  256. public static boolean stringIsBlank(final String str)
  257. {
  258. return (str == null || str.isEmpty() || str.matches(TravelGatesConstants.BLANK_STRING_PATTERN));
  259. }
  260. public static boolean stringIsNotBlank(final String str)
  261. {
  262. return !stringIsBlank(str);
  263. }
  264. public static TravelGatesPortalSign getPortalSignFromSign(final Sign sign)
  265. {
  266. if (_isDebugEnabled)
  267. {
  268. _LOGGER.info(_debug + " Start getDestinationInSign(sign=" + sign + ")");
  269. }
  270. final String[] lines = sign.getLines();
  271. TravelGatesPortalSign portalSign = new TravelGatesPortalSign();
  272. for (final String line : lines)
  273. {
  274. portalSign = getPortalSign(portalSign, line);
  275. }
  276. if (_isDebugEnabled)
  277. {
  278. _LOGGER.info(_debug + " End getDestinationInSign : " + portalSign.getDestination());
  279. }
  280. return portalSign;
  281. }
  282. public static int getAvailableLineOnSign(final TravelGates plugin, final Sign sign)
  283. {
  284. if (_isDebugEnabled)
  285. {
  286. _LOGGER.info(_debug + " Start getAvailableLineOnSign(sign=" + sign + ")");
  287. }
  288. int selectedLine = -1;
  289. TravelGatesPortalSign portalSign = new TravelGatesPortalSign();
  290. // Search filled or empty line
  291. for (int i = 0 ; i < sign.getLines().length ; i++)
  292. {
  293. final String line = sign.getLine(i);
  294. portalSign = getPortalSign(portalSign, plugin, line, i);
  295. }
  296. selectedLine = getSelectedLineFromPortalSign(portalSign, false);
  297. if (_isDebugEnabled)
  298. {
  299. _LOGGER.info(_debug + " End getAvailableLineOnSign : " + selectedLine);
  300. }
  301. return selectedLine;
  302. }
  303. public static TravelGatesPortalSign getPortalSignFromPortal(final TravelGates plugin, final Sign sign)
  304. {
  305. if (_isDebugEnabled)
  306. {
  307. _LOGGER.info(_debug + " Start getPortalSign(sign=" + sign + ")");
  308. }
  309. TravelGatesPortalSign portalSign = new TravelGatesPortalSign();
  310. // Search filled or empty line
  311. for (int i = 0 ; i < sign.getLines().length ; i++)
  312. {
  313. final String line = sign.getLine(i);
  314. portalSign = getPortalSign(portalSign, plugin, line, i);
  315. }
  316. portalSign.setFilledLine(getSelectedLineFromPortalSign(portalSign, true));
  317. if (_isDebugEnabled)
  318. {
  319. _LOGGER.info(_debug + " End getPortalSign : " + portalSign);
  320. }
  321. return portalSign;
  322. }
  323. public static int getSelectedLineFromPortalSign(final TravelGatesPortalSign portalSign, final boolean onlyFilledLine)
  324. {
  325. if (_isDebugEnabled)
  326. {
  327. _LOGGER.info(_debug + " Start getSelectedLineFromPortalSign(portalSign=" + portalSign + ", onlyFilledLine="
  328. + onlyFilledLine + ")");
  329. }
  330. int selectedLine = TravelGatesConstants.REGULAR_SIGN;
  331. if (portalSign.isValidSign() && portalSign.getDestination() != null)
  332. {
  333. if (portalSign.getFilledLine() >= 0)
  334. {
  335. selectedLine = portalSign.getFilledLine();
  336. }
  337. else if (!onlyFilledLine && portalSign.getEmptyLine() >= 0)
  338. {
  339. selectedLine = portalSign.getEmptyLine();
  340. }
  341. else
  342. {
  343. selectedLine = TravelGatesConstants.NO_AVAILABLE_LINE_ON_SIGN;
  344. }
  345. }
  346. else if (!portalSign.isValidSign())
  347. {
  348. selectedLine = TravelGatesConstants.NO_VALID_TRAVELGATE_SIGN;
  349. }
  350. else if (portalSign.getDestination() == null)
  351. {
  352. selectedLine = TravelGatesConstants.NO_DESTINATION_ON_SIGN;
  353. }
  354. if (_isDebugEnabled)
  355. {
  356. _LOGGER.info(_debug + " End getSelectedLineFromPortalSign : " + selectedLine);
  357. }
  358. return selectedLine;
  359. }
  360. private static TravelGatesPortalSign getPortalSign(final TravelGatesPortalSign portalSign, final String line)
  361. {
  362. if (_isDebugEnabled)
  363. {
  364. _LOGGER.info(_debug + " Start getPortalSign(portalSign=" + portalSign + ", line=" + line + ")");
  365. }
  366. // Travel Gates Config and eventually Destination
  367. if (!portalSign.isValidSign() && TravelGatesCommands.containsTravelGatesCommand(line))
  368. {
  369. portalSign.setValidSign(true);
  370. if (portalSign.getDestination() == null)
  371. {
  372. String newLine = null;
  373. if (line.startsWith("["))
  374. {
  375. newLine = line.substring(line.indexOf("]") + 1);
  376. }
  377. else
  378. {
  379. newLine = line.substring(0, line.indexOf("["));
  380. }
  381. newLine = newLine.replaceAll(" ", "");
  382. if (newLine.matches(TravelGatesConstants.DESTINATION_NAME_PATTERN))
  383. {
  384. portalSign.setDestination(newLine);
  385. }
  386. }
  387. }
  388. // Destination
  389. if (portalSign.getDestination() == null && line.matches(TravelGatesConstants.DESTINATION_NAME_PATTERN))
  390. {
  391. portalSign.setDestination(line);
  392. }
  393. if (_isDebugEnabled)
  394. {
  395. _LOGGER.info(_debug + " End getPortalSign : " + portalSign);
  396. }
  397. return portalSign;
  398. }
  399. private static TravelGatesPortalSign getPortalSign(final TravelGatesPortalSign portalSign,
  400. final TravelGates plugin, final String line, final int lineIndex)
  401. {
  402. if (_isDebugEnabled)
  403. {
  404. _LOGGER.info(_debug + " Start getPortalSign(portalSign=" + portalSign + ", plugin=TravelGates, line="
  405. + line + ", lineIndex=" + lineIndex + ")");
  406. }
  407. final String onState = plugin.getPortalSignOnState();
  408. final String offState = plugin.getPortalSignOffState();
  409. TravelGatesPortalSign localPortalSign = portalSign.clone();
  410. localPortalSign = getPortalSign(localPortalSign, line);
  411. // Filled Line
  412. if (localPortalSign.getFilledLine() < 0 && (line.contains(offState) || line.contains(onState)))
  413. {
  414. localPortalSign.setFilledLine(lineIndex);
  415. }
  416. // Empty Line
  417. if (localPortalSign.getEmptyLine() < 0 && TravelGatesUtils.stringIsBlank(line))
  418. {
  419. localPortalSign.setEmptyLine(lineIndex);
  420. }
  421. if (_isDebugEnabled)
  422. {
  423. _LOGGER.info(_debug + " End getPortalSign : " + localPortalSign);
  424. }
  425. return localPortalSign;
  426. }
  427. public static Location getDestinationLocation(final World world, final String[] positionData,
  428. final Location playerLoc, final int offset) throws IllegalArgumentException
  429. {
  430. if (_isDebugEnabled)
  431. {
  432. _LOGGER.info(_debug + " Start getDestinationLocation(world=" + world + ", positionData=" + positionData
  433. + ", playerLoc=" + playerLoc + ", offset=" + offset + ")");
  434. }
  435. Location destinationLocation = null;
  436. if (world != null)
  437. {
  438. Double posX = Double.parseDouble(positionData[0 + offset]);
  439. Double posZ = Double.parseDouble(positionData[2 + offset]);
  440. Double posY = null;
  441. final String strPosY = positionData[1 + offset];
  442. if (TravelGatesConstants.UNKNOWN_HEIGHT.equals(strPosY))
  443. {
  444. final int maxHeight = getHeighestFreeBlockAt(posX.intValue(), posZ.intValue(), world);
  445. posY = new Double(maxHeight);
  446. }
  447. else
  448. {
  449. posY = Double.parseDouble(strPosY) - 1;
  450. }
  451. if (posX.doubleValue() > TravelGatesConstants.MIN_COORDINATE
  452. && posX.doubleValue() < TravelGatesConstants.MAX_COORDINATE
  453. && posZ.doubleValue() > TravelGatesConstants.MIN_COORDINATE
  454. && posZ.doubleValue() < TravelGatesConstants.MAX_COORDINATE && posY.doubleValue() > 0
  455. && posY.doubleValue() < world.getMaxHeight())
  456. {
  457. destinationLocation = new Location(world, posX.doubleValue(), posY.doubleValue(), posZ.doubleValue(),
  458. playerLoc.getYaw(), 0f);
  459. }
  460. else
  461. {
  462. throw new IllegalArgumentException("Input values of position are out of bounds.");
  463. }
  464. }
  465. else
  466. {
  467. throw new IllegalArgumentException("Input world does not exist.");
  468. }
  469. if (_isDebugEnabled)
  470. {
  471. _LOGGER.info(_debug + " End getDestinationLocation : " + destinationLocation);
  472. }
  473. return destinationLocation;
  474. }
  475. public static int getHeighestFreeBlockAt(final int posX, final int posZ, final World world)
  476. {
  477. if (_isDebugEnabled)
  478. {
  479. _LOGGER.info(_debug + " Start getHeighestFreeBlockAt(x=" + posX + ", z=" + posZ + ", world=" + world + ")");
  480. }
  481. final int maxHeight = world.getMaxHeight();
  482. int searchedHeight = maxHeight - 1;
  483. Block lastBlock = null;
  484. while (searchedHeight > 0)
  485. {
  486. final Block block = world.getBlockAt(posX, searchedHeight, posZ);
  487. if (lastBlock != null && lastBlock.getType() == Material.AIR && block.getType() != Material.AIR)
  488. {
  489. break;
  490. }
  491. lastBlock = block;
  492. searchedHeight--;
  493. }
  494. searchedHeight++;
  495. if (_isDebugEnabled)
  496. {
  497. _LOGGER.info(_debug + " End getDestinationLocation : " + searchedHeight);
  498. }
  499. return searchedHeight;
  500. }
  501. public static Location getDestinationLocationNearPortal(final TravelGates plugin, final Location playerLoc, final Block portalBlock)
  502. {
  503. if (_isDebugEnabled)
  504. {
  505. _LOGGER.info(_debug + " Start getDestinationLocationNearPortal(plugin=" + plugin + ", playerLoc=" + playerLoc
  506. + ",portalBlock=" + portalBlock + ")");
  507. }
  508. Location destLocation = null;
  509. String str = plugin.getDestination(playerLoc);
  510. if (str != null)
  511. {
  512. // Player on dest
  513. destLocation = playerLoc;
  514. }
  515. else
  516. {
  517. final Location portalBlockLocation = portalBlock.getLocation();
  518. str = plugin.getDestination(portalBlockLocation);
  519. if (str != null)
  520. {
  521. // Portal block on dest
  522. destLocation = portalBlock.getLocation(portalBlockLocation);
  523. if (_isDebugEnabled)
  524. {
  525. _LOGGER.info(_debug + " Destination found under the portal block: " + destLocation);
  526. }
  527. }
  528. else
  529. {
  530. // Search nearest blocks
  531. for (TravelGatesBlockFaces tgFace : TravelGatesBlockFaces.values())
  532. {
  533. final Location relLoc = portalBlock.getRelative(tgFace.face()).getLocation();
  534. if (_isDebugEnabled)
  535. {
  536. _LOGGER.info(_debug + " Searching destination around portal block at: "
  537. + TravelGatesUtils.locationToShortString(relLoc) + " = " + relLoc);
  538. }
  539. if (plugin.getDestination(relLoc) != null)
  540. {
  541. destLocation = relLoc;
  542. if (_isDebugEnabled)
  543. {
  544. _LOGGER.info(_debug + " Destination found near the portal block: " + destLocation);
  545. }
  546. break;
  547. }
  548. }
  549. }
  550. }
  551. if (_isDebugEnabled)
  552. {
  553. _LOGGER.info(_debug + " End getDestinationLocationNearPortal : " + destLocation);
  554. }
  555. return destLocation;
  556. }
  557. public static Sign getSignOnPortalFrames(final Block portalBlock, final TravelGatesBlockFaces otherPortalBlockFace,
  558. final World world)
  559. {
  560. if (_isDebugEnabled)
  561. {
  562. _LOGGER.info(_debug + " Start getSignOnPortalFrames(portalBlock=" + portalBlock
  563. + ",otherPortalBlockFace=" + otherPortalBlockFace
  564. + ", world=" + world + ")");
  565. }
  566. final Block upperPortalBlock = portalBlock.getRelative(BlockFace.UP);
  567. if (upperPortalBlock.getType() != Material.PORTAL)
  568. {
  569. if (_isDebugEnabled)
  570. {
  571. _LOGGER.info(_debug + " End getSignOnPortalFrames : upper block is not a portal block.");
  572. }
  573. return null;
  574. }
  575. // Search the portal sign on the frame on the portal block side
  576. final Block portalFrame1 = getPortalFrameTo(otherPortalBlockFace.opposite(), upperPortalBlock);
  577. Sign portalSign = getSignOnFrame(portalFrame1);
  578. if (portalSign == null)
  579. {
  580. // Search the portal sign on the frame on the other portal block side
  581. final Block portalFrame2 = getPortalFrameTo(otherPortalBlockFace.face(), upperPortalBlock);
  582. portalSign = getSignOnFrame(portalFrame2);
  583. }
  584. // Search portal frame
  585. // for (TravelGatesBlockFaces tgFace : TravelGatesBlockFaces.values())
  586. // {
  587. // final Block adjacentBlock = portalBlock.getRelative(tgFace.face());
  588. //
  589. // if (adjacentBlock.getType() == Material.OBSIDIAN)
  590. // {
  591. // portalFrame = adjacentBlock;
  592. // break;
  593. // }
  594. // }
  595. // // Search sign on the first frame
  596. // if (portalFrame1 != null)
  597. // {
  598. // //final Block frameUpperBlock = portalFrame1.getRelative(BlockFace.UP);
  599. // BlockFace portalFace = null;
  600. //
  601. // for (TravelGatesBlockFaces tgFace : TravelGatesBlockFaces.values())
  602. // {
  603. // if (tgFace.isSimple())
  604. // {
  605. // final BlockFace currFace = tgFace.face();
  606. //
  607. // final Block adjacentFrameBlock = portalFrame1.getRelative(currFace);
  608. //
  609. // if (portalSign == null && isSign(adjacentFrameBlock))
  610. // {
  611. // portalSign = (Sign) adjacentFrameBlock.getState();
  612. // }
  613. //
  614. // if (portalFace == null && adjacentFrameBlock.getType() == Material.PORTAL)
  615. // {
  616. // portalFace = currFace;
  617. // }
  618. //
  619. // if (portalSign != null && portalFace != null)
  620. // {
  621. // break;
  622. // }
  623. // }
  624. // }
  625. //
  626. // // Search sign on the opposite frame
  627. // if (portalSign == null && portalFace != null)
  628. // {
  629. // final Block oppositeFrameUpperBlock = portalFrame1.getRelative(portalFace, 3);
  630. //
  631. // for (TravelGatesBlockFaces tgFace : TravelGatesBlockFaces.values())
  632. // {
  633. // if (tgFace.isSimple())
  634. // {
  635. // final BlockFace currFace = tgFace.face();
  636. //
  637. // final Block adjacentFrameBlock = oppositeFrameUpperBlock.getRelative(currFace);
  638. //
  639. // if (portalSign == null && isSign(adjacentFrameBlock))
  640. // {
  641. // portalSign = (Sign) adjacentFrameBlock.getState();
  642. // break;
  643. // }
  644. // }
  645. // }
  646. // }
  647. // }
  648. if (_isDebugEnabled)
  649. {
  650. _LOGGER.info(_debug + " End getSignOnPortalFrames : " + portalSign);
  651. }
  652. return portalSign;
  653. }
  654. private static Sign getSignOnFrame(final Block portalFrame)
  655. {
  656. Sign portalSign = null;
  657. if (portalFrame != null)
  658. {
  659. for (TravelGatesBlockFaces tgFace : TravelGatesBlockFaces.values())
  660. {
  661. if (tgFace.isSimple())
  662. {
  663. final Block adjacentFrameBlock = portalFrame.getRelative(tgFace.face());
  664. if (isSign(adjacentFrameBlock))
  665. {
  666. portalSign = (Sign) adjacentFrameBlock.getState();
  667. break;
  668. }
  669. }
  670. }
  671. }
  672. return portalSign;
  673. }
  674. private static Block getPortalFrameTo(final BlockFace direction, final Block portalBlock)
  675. {
  676. Block portalFrame = null;
  677. int i = 0;
  678. do
  679. {
  680. System.out.println("portalFrame="+portalFrame+", portalBlock="+portalBlock+", direction="+direction+", i="+i);
  681. portalFrame = portalBlock.getRelative(direction, ++i);
  682. }
  683. while (portalFrame != null && portalFrame.getType() == Material.PORTAL);
  684. return portalFrame;
  685. }
  686. public static int getCoordinateDiff(final int coordA, final int coordB)
  687. {
  688. final int max = Math.max(coordA, coordB);
  689. final int min = Math.min(coordA, coordB);
  690. return (max - min);
  691. }
  692. }