Advertisement
Guest User

Untitled

a guest
Dec 21st, 2014
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.32 KB | None | 0 0
  1. package mineplex.core.common.util;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.Collection;
  5. import java.util.HashMap;
  6. import java.util.HashSet;
  7. import net.minecraft.server.v1_7_R3.Chunk;
  8. import org.bukkit.Location;
  9. import org.bukkit.World;
  10. import org.bukkit.block.Block;
  11. import org.bukkit.block.BlockFace;
  12.  
  13.  
  14.  
  15. public class UtilText
  16. {
  17. public static enum TextAlign
  18. {
  19. LEFT,
  20. RIGHT,
  21. CENTER;
  22. }
  23.  
  24. public static HashMap<Character, int[][]> alphabet = new HashMap();
  25.  
  26. public static ArrayList<Location> GetTextLocations(String string, Location loc, BlockFace face)
  27. {
  28. if (alphabet.isEmpty()) {
  29. PopulateAlphabet();
  30. }
  31. ArrayList<Location> locs = new ArrayList();
  32.  
  33. Block block = loc.getBlock();
  34.  
  35.  
  36. int width = 0;
  37. for (char c : string.toLowerCase().toCharArray())
  38. {
  39. int[][] letter = (int[][])alphabet.get(Character.valueOf(c));
  40.  
  41. if (letter != null)
  42. {
  43.  
  44. width += (letter[0].length + 1) * 3;
  45. }
  46. }
  47.  
  48. block = block.getRelative(face, -1 * width / 2 + 1);
  49.  
  50.  
  51.  
  52. World world = block.getWorld();
  53. int bX = block.getX();
  54. int bY = block.getY();
  55. int bZ = block.getZ();
  56.  
  57.  
  58. for (char c : string.toLowerCase().toCharArray())
  59. {
  60. int[][] letter = (int[][])alphabet.get(Character.valueOf(c));
  61.  
  62. if (letter != null)
  63. {
  64.  
  65. for (int x = 0; x < letter.length; x++)
  66. {
  67. for (int y = 0; y < letter[x].length; y++)
  68. {
  69. if (letter[x][y] == 1) {
  70. locs.add(new Location(world, bX, bY, bZ));
  71. }
  72.  
  73. bX += face.getModX() * 3;
  74. bY += face.getModY() * 3;
  75. bZ += face.getModZ() * 3;
  76. }
  77.  
  78.  
  79. bX += face.getModX() * -3 * letter[x].length;
  80. bY += face.getModY() * -3 * letter[x].length;
  81. bZ += face.getModZ() * -3 * letter[x].length;
  82.  
  83.  
  84. bY -= 3;
  85. }
  86.  
  87. bY += 15;
  88. bX += face.getModX() * (letter[0].length + 1) * 3;
  89. bY += face.getModY() * (letter[0].length + 1) * 3;
  90. bZ += face.getModZ() * (letter[0].length + 1) * 3;
  91. }
  92. }
  93. return locs;
  94. }
  95.  
  96. public static Collection<Block> MakeText(String string, Location loc, BlockFace face, int id, byte data, TextAlign align)
  97. {
  98. return MakeText(string, loc, face, id, data, align, true);
  99. }
  100.  
  101. public static Collection<Block> MakeText(String string, Location loc, BlockFace face, int id, byte data, TextAlign align, boolean setAir)
  102. {
  103. HashSet<Block> changes = new HashSet();
  104.  
  105. if (alphabet.isEmpty()) {
  106. PopulateAlphabet();
  107. }
  108. Block block = loc.getBlock();
  109.  
  110.  
  111. int width = 0;
  112. for (char c : string.toLowerCase().toCharArray())
  113. {
  114. int[][] letter = (int[][])alphabet.get(Character.valueOf(c));
  115.  
  116. if (letter != null)
  117. {
  118.  
  119. width += letter[0].length + 1;
  120. }
  121. }
  122.  
  123. if ((align == TextAlign.CENTER) || (align == TextAlign.RIGHT))
  124. {
  125. int divisor = 1;
  126. if (align == TextAlign.CENTER) {
  127. divisor = 2;
  128. }
  129. block = block.getRelative(face, -1 * width / divisor + 1);
  130. }
  131.  
  132. HashSet<Chunk> chunks = new HashSet();
  133.  
  134. int i;
  135. if (setAir)
  136. {
  137. World world = loc.getWorld();
  138. int bX = loc.getBlockX();
  139. int bY = loc.getBlockY();
  140. int bZ = loc.getBlockZ();
  141. for (int y = 0; y < 5; y++)
  142. {
  143. if (align == TextAlign.CENTER) {
  144. for (int i = -64; i <= 64; i++)
  145. {
  146. chunks.add(MapUtil.ChunkBlockChange(world, bX + i * face.getModX(), bY + i * face.getModY(), bZ + i * face.getModZ(), 0, (byte)0));
  147. }
  148. }
  149.  
  150. if (align == TextAlign.LEFT) {
  151. for (int i = 0; i <= 128; i++)
  152. {
  153. chunks.add(MapUtil.ChunkBlockChange(world, bX + i * face.getModX(), bY + i * face.getModY(), bZ + i * face.getModZ(), 0, (byte)0));
  154. }
  155. }
  156.  
  157. if (align == TextAlign.RIGHT) {
  158. for (i = -128; i <= 0; i++)
  159. {
  160. chunks.add(MapUtil.ChunkBlockChange(world, bX + i * face.getModX(), bY + i * face.getModY(), bZ + i * face.getModZ(), 0, (byte)0));
  161. }
  162. }
  163.  
  164. bY--;
  165. }
  166. }
  167.  
  168. World world = block.getWorld();
  169. int bX = block.getX();
  170. int bY = block.getY();
  171. int bZ = block.getZ();
  172.  
  173.  
  174. for (char c : string.toLowerCase().toCharArray())
  175. {
  176. int[][] letter = (int[][])alphabet.get(Character.valueOf(c));
  177.  
  178. if (letter != null)
  179. {
  180.  
  181. for (int x = 0; x < letter.length; x++)
  182. {
  183. for (int y = 0; y < letter[x].length; y++)
  184. {
  185. if (letter[x][y] == 1)
  186. {
  187. changes.add(world.getBlockAt(bX, bY, bZ));
  188. chunks.add(MapUtil.ChunkBlockChange(world, bX, bY, bZ, id, data));
  189. }
  190.  
  191.  
  192. bX += face.getModX();
  193. bY += face.getModY();
  194. bZ += face.getModZ();
  195. }
  196.  
  197.  
  198. bX += face.getModX() * -1 * letter[x].length;
  199. bY += face.getModY() * -1 * letter[x].length;
  200. bZ += face.getModZ() * -1 * letter[x].length;
  201.  
  202.  
  203. bY--;
  204. }
  205.  
  206. bY += 5;
  207. bX += face.getModX() * (letter[0].length + 1);
  208. bY += face.getModY() * (letter[0].length + 1);
  209. bZ += face.getModZ() * (letter[0].length + 1);
  210. }
  211. }
  212. for (Chunk c : chunks)
  213. {
  214. c.initLighting();
  215. }
  216.  
  217. MapUtil.ResendChunksForNearbyPlayers(chunks);
  218.  
  219. return changes;
  220. }
  221.  
  222. private static void PopulateAlphabet()
  223. {
  224. alphabet.put(Character.valueOf('0'), new int[][] {
  225. { 1, 1, 1 },
  226. { 1, 0, 1 },
  227. { 1, 0, 1 },
  228. { 1, 0, 1 },
  229. { 1, 1, 1 } });
  230.  
  231.  
  232. alphabet.put(Character.valueOf('1'), new int[][] {
  233. { 1, 1 },
  234. { 0, 1 },
  235. { 0, 1 },
  236. { 0, 1 },
  237. { 1, 1, 1 } });
  238.  
  239.  
  240. alphabet.put(Character.valueOf('2'), new int[][] {
  241. { 1, 1, 1 },
  242. { 0, 0, 1 },
  243. { 1, 1, 1 },
  244. { 1 },
  245. { 1, 1, 1 } });
  246.  
  247.  
  248. alphabet.put(Character.valueOf('3'), new int[][] {
  249. { 1, 1, 1 },
  250. { 0, 0, 1 },
  251. { 1, 1, 1 },
  252. { 0, 0, 1 },
  253. { 1, 1, 1 } });
  254.  
  255.  
  256. alphabet.put(Character.valueOf('4'), new int[][] {
  257. { 1, 0, 1 },
  258. { 1, 0, 1 },
  259. { 1, 1, 1 },
  260. { 0, 0, 1 },
  261. { 0, 0, 1 } });
  262.  
  263.  
  264. alphabet.put(Character.valueOf('5'), new int[][] {
  265. { 1, 1, 1 },
  266. { 1 },
  267. { 1, 1, 1 },
  268. { 0, 0, 1 },
  269. { 1, 1, 1 } });
  270.  
  271.  
  272. alphabet.put(Character.valueOf('6'), new int[][] {
  273. { 1, 1, 1 },
  274. { 1 },
  275. { 1, 1, 1 },
  276. { 1, 0, 1 },
  277. { 1, 1, 1 } });
  278.  
  279.  
  280. alphabet.put(Character.valueOf('7'), new int[][] {
  281. { 1, 1, 1 },
  282. { 0, 0, 1 },
  283. { 0, 0, 1 },
  284. { 0, 0, 1 },
  285. { 0, 0, 1 } });
  286.  
  287.  
  288. alphabet.put(Character.valueOf('8'), new int[][] {
  289. { 1, 1, 1 },
  290. { 1, 0, 1 },
  291. { 1, 1, 1 },
  292. { 1, 0, 1 },
  293. { 1, 1, 1 } });
  294.  
  295.  
  296. alphabet.put(Character.valueOf('9'), new int[][] {
  297. { 1, 1, 1 },
  298. { 1, 0, 1 },
  299. { 1, 1, 1 },
  300. { 0, 0, 1 },
  301. { 1, 1, 1 } });
  302.  
  303.  
  304. alphabet.put(Character.valueOf('.'), new int[][] {
  305. new int[1],
  306. new int[1],
  307. new int[1],
  308. new int[1],
  309. { 1 } });
  310.  
  311.  
  312. alphabet.put(Character.valueOf('!'), new int[][] {
  313. { 1 },
  314. { 1 },
  315. { 1 },
  316. new int[1],
  317. { 1 } });
  318.  
  319.  
  320. alphabet.put(Character.valueOf(' '), new int[][] {
  321. new int[2],
  322. new int[2],
  323. new int[2],
  324. new int[2],
  325. new int[2] });
  326.  
  327.  
  328. alphabet.put(Character.valueOf('a'), new int[][] {
  329. { 1, 1, 1, 1 },
  330. { 1, 0, 0, 1 },
  331. { 1, 1, 1, 1 },
  332. { 1, 0, 0, 1 },
  333. { 1, 0, 0, 1 } });
  334.  
  335.  
  336. alphabet.put(Character.valueOf('b'), new int[][] {
  337. { 1, 1, 1 },
  338. { 1, 0, 0, 1 },
  339. { 1, 1, 1 },
  340. { 1, 0, 0, 1 },
  341. { 1, 1, 1 } });
  342.  
  343.  
  344. alphabet.put(Character.valueOf('c'), new int[][] {
  345. { 1, 1, 1, 1 },
  346. { 1 },
  347. { 1 },
  348. { 1 },
  349. { 1, 1, 1, 1 } });
  350.  
  351.  
  352. alphabet.put(Character.valueOf('d'), new int[][] {
  353. { 1, 1, 1 },
  354. { 1, 0, 0, 1 },
  355. { 1, 0, 0, 1 },
  356. { 1, 0, 0, 1 },
  357. { 1, 1, 1 } });
  358.  
  359.  
  360. alphabet.put(Character.valueOf('e'), new int[][] {
  361. { 1, 1, 1, 1 },
  362. { 1 },
  363. { 1, 1, 1 },
  364. { 1 },
  365. { 1, 1, 1, 1 } });
  366.  
  367.  
  368. alphabet.put(Character.valueOf('f'), new int[][] {
  369. { 1, 1, 1, 1 },
  370. { 1 },
  371. { 1, 1, 1 },
  372. { 1 },
  373. { 1 } });
  374.  
  375.  
  376. alphabet.put(Character.valueOf('g'), new int[][] {
  377. { 1, 1, 1, 1 },
  378. { 1 },
  379. { 1, 0, 1, 1 },
  380. { 1, 0, 0, 1 },
  381. { 1, 1, 1, 1 } });
  382.  
  383.  
  384. alphabet.put(Character.valueOf('h'), new int[][] {
  385. { 1, 0, 0, 1 },
  386. { 1, 0, 0, 1 },
  387. { 1, 1, 1, 1 },
  388. { 1, 0, 0, 1 },
  389. { 1, 0, 0, 1 } });
  390.  
  391.  
  392. alphabet.put(Character.valueOf('i'), new int[][] {
  393. { 1, 1, 1 },
  394. { 0, 1 },
  395. { 0, 1 },
  396. { 0, 1 },
  397. { 1, 1, 1 } });
  398.  
  399.  
  400. alphabet.put(Character.valueOf('j'), new int[][] {
  401. { 1, 1, 1, 1 },
  402. { 0, 0, 1 },
  403. { 0, 0, 1 },
  404. { 1, 0, 1 },
  405. { 1, 1, 1 } });
  406.  
  407.  
  408. alphabet.put(Character.valueOf('k'), new int[][] {
  409. { 1, 0, 0, 1 },
  410. { 1, 0, 1 },
  411. { 1, 1 },
  412. { 1, 0, 1 },
  413. { 1, 0, 0, 1 } });
  414.  
  415.  
  416. alphabet.put(Character.valueOf('l'), new int[][] {
  417. { 1 },
  418. { 1 },
  419. { 1 },
  420. { 1 },
  421. { 1, 1, 1, 1 } });
  422.  
  423.  
  424. alphabet.put(Character.valueOf('m'), new int[][] {
  425. { 1, 1, 1, 1, 1 },
  426. { 1, 0, 1, 0, 1 },
  427. { 1, 0, 1, 0, 1 },
  428. { 1, 0, 0, 0, 1 },
  429. { 1, 0, 0, 0, 1 } });
  430.  
  431.  
  432. alphabet.put(Character.valueOf('n'), new int[][] {
  433. { 1, 0, 0, 1 },
  434. { 1, 1, 0, 1 },
  435. { 1, 0, 1, 1 },
  436. { 1, 0, 0, 1 },
  437. { 1, 0, 0, 1 } });
  438.  
  439.  
  440. alphabet.put(Character.valueOf('o'), new int[][] {
  441. { 1, 1, 1, 1 },
  442. { 1, 0, 0, 1 },
  443. { 1, 0, 0, 1 },
  444. { 1, 0, 0, 1 },
  445. { 1, 1, 1, 1 } });
  446.  
  447.  
  448. alphabet.put(Character.valueOf('p'), new int[][] {
  449. { 1, 1, 1, 1 },
  450. { 1, 0, 0, 1 },
  451. { 1, 1, 1, 1 },
  452. { 1 },
  453. { 1 } });
  454.  
  455.  
  456. alphabet.put(Character.valueOf('q'), new int[][] {
  457. { 1, 1, 1, 1 },
  458. { 1, 0, 0, 1 },
  459. { 1, 0, 0, 1 },
  460. { 1, 0, 1 },
  461. { 1, 1, 0, 1 } });
  462.  
  463.  
  464. alphabet.put(Character.valueOf('r'), new int[][] {
  465. { 1, 1, 1, 1 },
  466. { 1, 0, 0, 1 },
  467. { 1, 1, 1 },
  468. { 1, 0, 0, 1 },
  469. { 1, 0, 0, 1 } });
  470.  
  471.  
  472. alphabet.put(Character.valueOf('s'), new int[][] {
  473. { 1, 1, 1, 1 },
  474. { 1 },
  475. { 1, 1, 1, 1 },
  476. { 0, 0, 0, 1 },
  477. { 1, 1, 1, 1 } });
  478.  
  479.  
  480. alphabet.put(Character.valueOf('t'), new int[][] {
  481. { 1, 1, 1, 1, 1 },
  482. { 0, 0, 1 },
  483. { 0, 0, 1 },
  484. { 0, 0, 1 },
  485. { 0, 0, 1 } });
  486.  
  487.  
  488. alphabet.put(Character.valueOf('u'), new int[][] {
  489. { 1, 0, 0, 1 },
  490. { 1, 0, 0, 1 },
  491. { 1, 0, 0, 1 },
  492. { 1, 0, 0, 1 },
  493. { 1, 1, 1, 1 } });
  494.  
  495.  
  496. alphabet.put(Character.valueOf('v'), new int[][] {
  497. { 1, 0, 0, 1 },
  498. { 1, 0, 0, 1 },
  499. { 1, 0, 0, 1 },
  500. { 1, 0, 0, 1 },
  501. { 0, 1, 1 } });
  502.  
  503.  
  504. alphabet.put(Character.valueOf('w'), new int[][] {
  505. { 1, 0, 0, 0, 1 },
  506. { 1, 0, 0, 0, 1 },
  507. { 1, 0, 1, 0, 1 },
  508. { 1, 0, 1, 0, 1 },
  509. { 1, 1, 1, 1, 1 } });
  510.  
  511.  
  512. alphabet.put(Character.valueOf('x'), new int[][] {
  513. { 1, 0, 0, 1 },
  514. { 1, 0, 0, 1 },
  515. { 0, 1, 1 },
  516. { 1, 0, 0, 1 },
  517. { 1, 0, 0, 1 } });
  518.  
  519.  
  520. alphabet.put(Character.valueOf('y'), new int[][] {
  521. { 1, 0, 0, 1 },
  522. { 1, 0, 0, 1 },
  523. { 1, 1, 1, 1 },
  524. { 0, 0, 0, 1 },
  525. { 1, 1, 1, 1 } });
  526.  
  527.  
  528. alphabet.put(Character.valueOf('z'), new int[][] {
  529. { 1, 1, 1, 1 },
  530. { 0, 0, 0, 1 },
  531. { 0, 0, 1 },
  532. { 0, 1 },
  533. { 1, 1, 1, 1 } });
  534. }
  535. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement