Advertisement
Guest User

Untitled

a guest
Feb 20th, 2020
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 28.49 KB | None | 0 0
  1. HUGE_EXPLOSION("hugeexplosion", "EXPLOSION_HUGE"),
  2. LARGE_EXPLODE("largeexplode", "EXPLOSION_LARGE"),
  3. BUBBLE("bubble", "WATER_BUBBLE"),
  4. SUSPEND("suspended", "SUSPENDED"),
  5. DEPTH_SUSPEND("depthsuspend", "SUSPENDED_DEPTH"),
  6. MAGIC_CRIT("magicCrit", "CRIT_MAGIC"),
  7. MOB_SPELL("mobSpell", "SPELL_MOB", true),
  8. MOB_SPELL_AMBIENT("mobSpellAmbient", "SPELL_MOB_AMBIENT"),
  9. INSTANT_SPELL("instantSpell", "SPELL_INSTANT"),
  10. WITCH_MAGIC("witchMagic", "SPELL_WITCH"),
  11. EXPLODE("explode", "EXPLOSION_NORMAL"),
  12. SPLASH("splash", "WATER_SPLASH"),
  13. LARGE_SMOKE("largesmoke", "SMOKE_LARGE"),
  14. RED_DUST("reddust", "REDSTONE", true),
  15. SNOWBALL_POOF("snowballpoof", "SNOWBALL"),
  16. ANGRY_VILLAGER("angryVillager", "VILLAGER_ANGRY"),
  17. HAPPY_VILLAGER("happyVillager", "VILLAGER_HAPPY"),
  18. EXPLOSION_NORMAL(EXPLODE.getName()),
  19. EXPLOSION_LARGE(LARGE_EXPLODE.getName()),
  20. EXPLOSION_HUGE(HUGE_EXPLOSION.getName()),
  21. FIREWORKS_SPARK("fireworksSpark"),
  22. WATER_BUBBLE(BUBBLE.getName()),
  23. WATER_SPLASH(SPLASH.getName()),
  24. WATER_WAKE("wake"),
  25. SUSPENDED(SUSPEND.getName()),
  26. SUSPENDED_DEPTH(DEPTH_SUSPEND.getName()),
  27. CRIT("crit"),
  28. CRIT_MAGIC(MAGIC_CRIT.getName()),
  29. SMOKE_NORMAL("smoke"),
  30. SMOKE_LARGE(LARGE_SMOKE.getName()),
  31. SPELL("spell"),
  32. SPELL_INSTANT(INSTANT_SPELL.getName()),
  33. SPELL_MOB(MOB_SPELL.getName(), true),
  34. SPELL_MOB_AMBIENT(MOB_SPELL_AMBIENT.getName()),
  35. SPELL_WITCH(WITCH_MAGIC.getName()),
  36. DRIP_WATER("dripWater"),
  37. DRIP_LAVA("dripLava"),
  38. VILLAGER_ANGRY(ANGRY_VILLAGER.getName()),
  39. VILLAGER_HAPPY(HAPPY_VILLAGER.getName()),
  40. TOWN_AURA("townaura"),
  41. NOTE("note", true),
  42. PORTAL("portal"),
  43. ENCHANTMENT_TABLE("enchantmenttable"),
  44. FLAME("flame"),
  45. LAVA("lava"),
  46. FOOTSTEP("footstep"),
  47. CLOUD("cloud"),
  48. REDSTONE("reddust", true),
  49. SNOWBALL("snowballpoof"),
  50. SNOW_SHOVEL("snowshovel"),
  51. SLIME("slime"),
  52. HEART("heart"),
  53. BARRIER("barrier"),
  54. ITEM_CRACK("iconcrack_"),
  55. BLOCK_CRACK("blockcrack_"),
  56. BLOCK_DUST("blockdust_"),
  57. WATER_DROP("droplet"),
  58. ITEM_TAKE("take"),
  59. MOB_APPEARANCE("mobappearance");
  60.  
  61. private String particleName;
  62. private String enumValue;
  63. private boolean hasColor;
  64.  
  65. ParticleEffect(String particleName, String enumValue, boolean hasColor)
  66. {
  67. this.particleName = particleName;
  68. this.enumValue = enumValue;
  69. this.hasColor = hasColor;
  70. }
  71.  
  72. ParticleEffect(String particleName, String enumValue)
  73. {
  74. this(particleName, enumValue, false);
  75. }
  76.  
  77. ParticleEffect(String particleName)
  78. {
  79. this(particleName, null);
  80. }
  81.  
  82. ParticleEffect(String particleName, boolean hasColor)
  83. {
  84. this(particleName, null, hasColor);
  85. }
  86.  
  87. //<editor-fold desc="getName">
  88. public String getName()
  89. {
  90. return this.particleName;
  91. }
  92. //</editor-fold>
  93.  
  94. //<editor-fold desc="hasColor">
  95. public boolean hasColor()
  96. {
  97. return hasColor;
  98. }
  99. //</editor-fold>
  100.  
  101. private static Class<?> nmsPacketPlayOutParticle = ReflectionUtilities.getNMSClass("PacketPlayOutWorldParticles");
  102. private static Class<?> nmsEnumParticle;
  103. private static int particleRange = 25;
  104.  
  105. //<editor-fold desc="setRange">
  106. public static void setRange(int range)
  107. {
  108. if (range < 0)
  109. {
  110. throw new IllegalArgumentException("Range must be positive!");
  111. }
  112. particleRange = range;
  113. }
  114. //</editor-fold>
  115.  
  116. //<editor-fold desc="getRange">
  117. public static int getRange()
  118. {
  119. return particleRange;
  120. }
  121. //</editor-fold>
  122.  
  123. //<editor-fold desc="sendToPlayer">
  124. private void sendToPlayer(Player player, Location location, float offsetX, float offsetY, float offsetZ, float speed, int count, int... extra)
  125. {
  126. sendToPlayer(player, location, offsetX, offsetY, offsetZ, speed, count, false, extra);
  127. }
  128. //</editor-fold>
  129.  
  130. //<editor-fold desc="sendToPlayer">
  131. private void sendToPlayer(Player player, Location location, float offsetX, float offsetY, float offsetZ, float speed, int count, boolean force, int... extra)
  132. {
  133. if (!force && !isPlayerInRange(player, location))
  134. {
  135. return;
  136. }
  137. if (ReflectionUtilities.getVersion().contains("v1_8"))
  138. {
  139. try
  140. {
  141. if (nmsEnumParticle == null)
  142. {
  143. nmsEnumParticle = ReflectionUtilities.getNMSClass("EnumParticle");
  144. }
  145. if (this == BLOCK_CRACK)
  146. {
  147. int id = 0;
  148. int data = 0;
  149. if (extra.length > 0)
  150. {
  151. id = extra[0];
  152. }
  153. if (extra.length > 1)
  154. {
  155. data = extra[1];
  156. }
  157. extra = new int[]{
  158. id,
  159. id | data << 12};
  160. }
  161. Object packet = nmsPacketPlayOutParticle.getConstructor(new Class[]{
  162. nmsEnumParticle,
  163. boolean.class,
  164. float.class,
  165. float.class,
  166. float.class,
  167. float.class,
  168. float.class,
  169. float.class,
  170. float.class,
  171. int.class,
  172. int[].class}).newInstance(getEnum(nmsEnumParticle.getName() + "." + (this.enumValue != null ? this.enumValue : this.name().toUpperCase())), true, (float) location.getX(), (float) location.getY(), (float) location.getZ(), offsetX, offsetY, offsetZ, speed, count, extra);
  173. Object handle = ReflectionUtilities.getHandle(player);
  174. Object connection = ReflectionUtilities.getField(handle.getClass(), "playerConnection").get(handle);
  175. ReflectionUtilities.getMethod(connection.getClass(), "sendPacket", new Class[0]).invoke(connection, packet);
  176. } catch (Exception e)
  177. {
  178. try
  179. {
  180. throw e;
  181. } catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e1)
  182. {
  183. e1.printStackTrace();
  184. }
  185. }
  186. } else
  187. {
  188. try
  189. {
  190. if (this.particleName == null)
  191. {
  192. this.particleName = this.name().toLowerCase();
  193. }
  194. String name = this.particleName;
  195. if (this == BLOCK_CRACK || this == ITEM_CRACK || this == BLOCK_DUST)
  196. {
  197. int id = 0;
  198. int data = 0;
  199. if (extra.length > 0)
  200. {
  201. id = extra[0];
  202. }
  203. if (extra.length > 1)
  204. {
  205. data = extra[1];
  206. }
  207. name += id + "_" + data;
  208. }
  209. Object packet = nmsPacketPlayOutParticle.getConstructor(new Class[]{
  210. String.class,
  211. float.class,
  212. float.class,
  213. float.class,
  214. float.class,
  215. float.class,
  216. float.class,
  217. float.class,
  218. int.class}).newInstance(name, (float) location.getX(), (float) location.getY(), (float) location.getZ(), offsetX, offsetY, offsetZ, speed, count);
  219. Object handle = ReflectionUtilities.getHandle(player);
  220. Object connection = ReflectionUtilities.getField(handle.getClass(), "playerConnection").get(handle);
  221. ReflectionUtilities.getMethod(connection.getClass(), "sendPacket", new Class[0]).invoke(connection, packet);
  222. } catch (Exception e)
  223. {
  224. try
  225. {
  226. throw e;
  227. } catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e1)
  228. {
  229. e1.printStackTrace();
  230. }
  231. }
  232. }
  233. }
  234. //</editor-fold>
  235.  
  236. //<editor-fold desc="sendToPlayer">
  237. public void sendToPlayer(Player player, Location location, float offsetX, float offsetY, float offsetZ, float speed, int count, boolean force)
  238. {
  239. this.sendToPlayer(player, location, offsetX, offsetY, offsetZ, speed, count, force, new int[0]);
  240. }
  241. //</editor-fold>
  242.  
  243. //<editor-fold desc="sendToPlayer">
  244. public void sendToPlayer(Player player, Location location, float offsetX, float offsetY, float offsetZ, float speed, int count)
  245. {
  246. this.sendToPlayer(player, location, offsetX, offsetY, offsetZ, speed, count, false);
  247. }
  248. //</editor-fold>
  249.  
  250. //<editor-fold desc="sendToPlayer">
  251. public void sendToPlayers(Collection<? extends Player> players, Location location, float offsetX, float offsetY, float offsetZ, float speed, int count)
  252. {
  253. for (Player p : players)
  254. {
  255. this.sendToPlayer(p, location, offsetX, offsetY, offsetZ, speed, count);
  256. }
  257. }
  258. //</editor-fold>
  259.  
  260. //<editor-fold desc="sendToPlayer">
  261. public void sendToPlayers(Collection<? extends Player> players, Location location, float offsetX, float offsetY, float offsetZ, float speed, int count, boolean force)
  262. {
  263. for (Player p : players)
  264. {
  265. this.sendToPlayer(p, location, offsetX, offsetY, offsetZ, speed, count, force);
  266. }
  267. }
  268. //</editor-fold>
  269.  
  270. //<editor-fold desc="sendToPlayer">
  271. public void sendToPlayers(Player[] players, Location location, float offsetX, float offsetY, float offsetZ, float speed, int count)
  272. {
  273. for (Player p : players)
  274. {
  275. this.sendToPlayer(p, location, offsetX, offsetY, offsetZ, speed, count);
  276. }
  277. }
  278. //</editor-fold>
  279.  
  280. //<editor-fold desc="sendColor">
  281. public void sendColor(Player p, Location location, org.bukkit.Color color)
  282. {
  283. if (!this.hasColor)
  284. {
  285. return;
  286. }
  287. this.sendToPlayer(p, location, this.getColor(color.getRed()), this.getColor(color.getGreen()), this.getColor(color.getBlue()), 1, 0);
  288. }
  289. //</editor-fold>
  290.  
  291. //<editor-fold desc="sendColor">
  292. public void sendColor(Player p, Location location, org.bukkit.Color color, boolean force)
  293. {
  294. if (!this.hasColor)
  295. {
  296. return;
  297. }
  298. this.sendToPlayer(p, location, this.getColor(color.getRed()), this.getColor(color.getGreen()), this.getColor(color.getBlue()), 1, 0, force);
  299. }
  300. //</editor-fold>
  301.  
  302. //<editor-fold desc="sendColor">
  303. public void sendColor(Player p, Location location, java.awt.Color color)
  304. {
  305. if (!this.hasColor)
  306. {
  307. return;
  308. }
  309. this.sendToPlayer(p, location, this.getColor(color.getRed()), this.getColor(color.getGreen()), this.getColor(color.getBlue()), 1, 0);
  310. }
  311. //</editor-fold>
  312.  
  313. //<editor-fold desc="sendColor">
  314. public void sendColor(Player p, Location location, java.awt.Color color, boolean force)
  315. {
  316. if (!this.hasColor)
  317. {
  318. return;
  319. }
  320. this.sendToPlayer(p, location, this.getColor(color.getRed()), this.getColor(color.getGreen()), this.getColor(color.getBlue()), 1, 0, force);
  321. }
  322. //</editor-fold>
  323.  
  324. //<editor-fold desc="sendColor">
  325. public void sendColor(Collection<? extends Player> players, Location location, java.awt.Color color)
  326. {
  327. if (!this.hasColor)
  328. {
  329. return;
  330. }
  331. for (Player p : players)
  332. {
  333. this.sendColor(p, location, color);
  334. }
  335. }
  336. //</editor-fold>
  337.  
  338. //<editor-fold desc="sendColor">
  339. public void sendColor(Collection<? extends Player> players, Location location, java.awt.Color color, boolean force)
  340. {
  341. if (!this.hasColor)
  342. {
  343. return;
  344. }
  345. for (Player p : players)
  346. {
  347. this.sendColor(p, location, color, force);
  348. }
  349. }
  350. //</editor-fold>
  351.  
  352. //<editor-fold desc="sendColor">
  353. public void sendColor(Collection<? extends Player> players, Location location, org.bukkit.Color color)
  354. {
  355. if (!this.hasColor)
  356. {
  357. return;
  358. }
  359. for (Player p : players)
  360. {
  361. this.sendColor(p, location, color);
  362. }
  363. }
  364. //</editor-fold>
  365.  
  366. //<editor-fold desc="sendColor">
  367. public void sendColor(Collection<? extends Player> players, Location location, org.bukkit.Color color, boolean force)
  368. {
  369. if (!this.hasColor)
  370. {
  371. return;
  372. }
  373. for (Player p : players)
  374. {
  375. this.sendColor(p, location, color, force);
  376. }
  377. }
  378. //</editor-fold>
  379.  
  380. //<editor-fold desc="sendColor">
  381. public void sendColor(Player[] players, Location location, org.bukkit.Color color)
  382. {
  383. if (!this.hasColor)
  384. {
  385. return;
  386. }
  387. for (Player p : players)
  388. {
  389. this.sendColor(p, location, color);
  390. }
  391. }
  392. //</editor-fold>
  393.  
  394. //<editor-fold desc="Description">
  395. public void sendColor(Player[] players, Location location, java.awt.Color color)
  396. {
  397. if (!this.hasColor)
  398. {
  399. return;
  400. }
  401. for (Player p : players)
  402. {
  403. this.sendColor(p, location, color);
  404. }
  405. }
  406. //</editor-fold>
  407.  
  408. //<editor-fold desc="getColor">
  409. protected float getColor(float value)
  410. {
  411. if (value <= 0)
  412. {
  413. value = -1;
  414. }
  415. return value / 255;
  416. }
  417. //</editor-fold>
  418.  
  419. //<editor-fold desc="sendBlockCrack">
  420. public void sendBlockCrack(Player player, Location location, int id, byte data, float offsetX, float offsetY, float offsetZ, float speed, int count)
  421. {
  422. if (this != BLOCK_CRACK)
  423. {
  424. throw new IllegalArgumentException("This method is only available for BLOCK_CRACK!");
  425. }
  426. this.sendToPlayer(player, location, offsetX, offsetY, offsetZ, speed, count, id, data);
  427. }
  428. //</editor-fold>
  429.  
  430. //<editor-fold desc="sendBlockCrack">
  431. public void sendBlockCrack(Player player, Location location, int id, byte data, float offsetX, float offsetY, float offsetZ, float speed, int count, boolean force)
  432. {
  433. if (this != BLOCK_CRACK)
  434. {
  435. throw new IllegalArgumentException("This method is only available for BLOCK_CRACK!");
  436. }
  437. this.sendToPlayer(player, location, offsetX, offsetY, offsetZ, speed, count, force, id, data);
  438. }
  439. //</editor-fold>
  440.  
  441. //<editor-fold desc="sendBlockCrack">
  442. public void sendBlockCrack(Collection<? extends Player> players, Location location, int id, byte data, float offsetX, float offsetY, float offsetZ, float speed, int count)
  443. {
  444. if (this != BLOCK_CRACK)
  445. {
  446. throw new IllegalArgumentException("This method is only available for BLOCK_CRACK!");
  447. }
  448. for (Player p : players)
  449. {
  450. this.sendBlockCrack(p, location, id, data, offsetX, offsetY, offsetZ, speed, count);
  451. }
  452. }
  453. //</editor-fold>
  454.  
  455. //<editor-fold desc="sendBlockCrack">
  456. public void sendBlockCrack(Collection<? extends Player> players, Location location, int id, byte data, float offsetX, float offsetY, float offsetZ, float speed, int count, boolean force)
  457. {
  458. if (this != BLOCK_CRACK)
  459. {
  460. throw new IllegalArgumentException("This method is only available for BLOCK_CRACK!");
  461. }
  462. for (Player p : players)
  463. {
  464. this.sendBlockCrack(p, location, id, data, offsetX, offsetY, offsetZ, speed, count, force);
  465. }
  466. }
  467. //</editor-fold>
  468.  
  469. //<editor-fold desc="sendBlockCrack">
  470. public void sendBlockCrack(Player[] players, Location location, int id, byte data, float offsetX, float offsetY, float offsetZ, float speed, int count)
  471. {
  472. if (this != BLOCK_CRACK)
  473. {
  474. throw new IllegalArgumentException("This method is only available for BLOCK_CRACK!");
  475. }
  476. for (Player p : players)
  477. {
  478. this.sendBlockCrack(p, location, id, data, offsetX, offsetY, offsetZ, speed, count);
  479. }
  480. }
  481. //</editor-fold>
  482.  
  483. //<editor-fold desc="sendItemCrack">
  484. public void sendItemCrack(Player player, Location location, int id, byte data, float offsetX, float offsetY, float offsetZ, float speed, int count)
  485. {
  486. if (this != ITEM_CRACK)
  487. {
  488. throw new IllegalArgumentException("This method is only available for ITEM_CRACK!");
  489. }
  490. this.sendToPlayer(player, location, offsetX, offsetY, offsetZ, speed, count, id, data);
  491. }
  492. //</editor-fold>
  493.  
  494. //<editor-fold desc="sendItemCrack">
  495. public void sendItemCrack(Player player, Location location, int id, byte data, float offsetX, float offsetY, float offsetZ, float speed, int count, boolean force)
  496. {
  497. if (this != ITEM_CRACK)
  498. {
  499. throw new IllegalArgumentException("This method is only available for ITEM_CRACK!");
  500. }
  501. this.sendToPlayer(player, location, offsetX, offsetY, offsetZ, speed, count, force, id, data);
  502. }
  503. //</editor-fold>
  504.  
  505. //<editor-fold desc="sendItemCrack">
  506. public void sendItemCrack(Collection<? extends Player> players, Location location, int id, byte data, float offsetX, float offsetY, float offsetZ, float speed, int count)
  507. {
  508. if (this != ITEM_CRACK)
  509. {
  510. throw new IllegalArgumentException("This method is only available for ITEM_CRACK!");
  511. }
  512. for (Player p : players)
  513. {
  514. this.sendItemCrack(p, location, id, data, offsetX, offsetY, offsetZ, speed, count);
  515. }
  516. }
  517. //</editor-fold>
  518.  
  519. //<editor-fold desc="sendItemCrack">
  520. public void sendItemCrack(Collection<? extends Player> players, Location location, int id, byte data, float offsetX, float offsetY, float offsetZ, float speed, int count, boolean force)
  521. {
  522. if (this != ITEM_CRACK)
  523. {
  524. throw new IllegalArgumentException("This method is only available for ITEM_CRACK!");
  525. }
  526. for (Player p : players)
  527. {
  528. this.sendItemCrack(p, location, id, data, offsetX, offsetY, offsetZ, speed, count, force);
  529. }
  530. }
  531. //</editor-fold>
  532.  
  533. //<editor-fold desc="sendItemCrack">
  534. public void sendItemCrack(Player[] players, Location location, int id, byte data, float offsetX, float offsetY, float offsetZ, float speed, int count)
  535. {
  536. if (this != ITEM_CRACK)
  537. {
  538. throw new IllegalArgumentException("This method is only available for ITEM_CRACK!");
  539. }
  540. for (Player p : players)
  541. {
  542. this.sendItemCrack(p, location, id, data, offsetX, offsetY, offsetZ, speed, count);
  543. }
  544. }
  545. //</editor-fold>
  546.  
  547. //<editor-fold desc="sendBlockDust">
  548. public void sendBlockDust(Player p, Location location, int id, float offsetX, float offsetY, float offsetZ, float speed, int count)
  549. {
  550. if (this != BLOCK_DUST)
  551. {
  552. throw new IllegalArgumentException("This method is only available for BLOCK_DUST!");
  553. }
  554. this.sendToPlayer(p, location, offsetX, offsetY, offsetZ, speed, count, id);
  555. }
  556. //</editor-fold>
  557.  
  558. //<editor-fold desc="sendBlockDust">
  559. public void sendBlockDust(Player p, Location location, int id, float offsetX, float offsetY, float offsetZ, float speed, int count, boolean force)
  560. {
  561. if (this != BLOCK_DUST)
  562. {
  563. throw new IllegalArgumentException("This method is only available for BLOCK_DUST!");
  564. }
  565. this.sendToPlayer(p, location, offsetX, offsetY, offsetZ, speed, count, force, id);
  566. }
  567. //</editor-fold>
  568.  
  569. //<editor-fold desc="sendBlockDust">
  570. public void sendBlockDust(Collection<? extends Player> players, Location location, int id, float offsetX, float offsetY, float offsetZ, float speed, int count)
  571. {
  572. if (this != BLOCK_DUST)
  573. {
  574. throw new IllegalArgumentException("This method is only available for BLOCK_DUST!");
  575. }
  576. for (Player p : players)
  577. {
  578. this.sendBlockDust(p, location, id, offsetX, offsetY, offsetZ, speed, count);
  579. }
  580. }
  581. //</editor-fold>
  582.  
  583. //<editor-fold desc="sendBlockDust">
  584. public void sendBlockDust(Collection<? extends Player> players, Location location, int id, float offsetX, float offsetY, float offsetZ, float speed, int count, boolean force)
  585. {
  586. if (this != BLOCK_DUST)
  587. {
  588. throw new IllegalArgumentException("This method is only available for BLOCK_DUST!");
  589. }
  590. for (Player p : players)
  591. {
  592. this.sendBlockDust(p, location, id, offsetX, offsetY, offsetZ, speed, count, force);
  593. }
  594. }
  595. //</editor-fold>
  596.  
  597. //<editor-fold desc="sendBlockDust">
  598. public void sendBlockDust(Player[] players, Location location, int id, float offsetX, float offsetY, float offsetZ, float speed, int count)
  599. {
  600. if (this != BLOCK_DUST)
  601. {
  602. throw new IllegalArgumentException("This method is only available for BLOCK_DUST!");
  603. }
  604. for (Player p : players)
  605. {
  606. this.sendBlockDust(p, location, id, offsetX, offsetY, offsetZ, speed, count);
  607. }
  608. }
  609. //</editor-fold>
  610.  
  611. private static Class<?> nmsPlayerConnection;
  612. private static Class<?> nmsEntityPlayer;
  613. private static Class<?> ioNettyChannel;
  614. private static Method nmsNetworkGetVersion;
  615.  
  616. private static Field nmsFieldPlayerConnection;
  617. private static Field nmsFieldNetworkManager;
  618. private static Field nmsFieldNetworkManagerI;
  619. private static Field nmsFieldNetworkManagerM;
  620.  
  621. static
  622. {
  623. String ver = ReflectionUtilities.getVersion();
  624. try
  625. {
  626. nmsPlayerConnection = ReflectionUtilities.getNMSClass("PlayerConnection");
  627. nmsEntityPlayer = ReflectionUtilities.getNMSClass("EntityPlayer");
  628. ioNettyChannel = ver.contains("1_7") ? Class.forName("net.minecraft.util.io.netty.channel.Channel") : Class.forName("io.netty.channel.Channel");
  629.  
  630. nmsFieldPlayerConnection = ReflectionUtilities.getField(nmsEntityPlayer, "playerConnection");
  631. nmsFieldNetworkManager = ReflectionUtilities.getField(nmsPlayerConnection, "networkManager");
  632. nmsFieldNetworkManagerI = ReflectionUtilities.getField(nmsFieldNetworkManager.getType(), "i");
  633. nmsFieldNetworkManagerM = ReflectionUtilities.getField(nmsFieldNetworkManager.getType(), "m");
  634.  
  635. nmsNetworkGetVersion = ReflectionUtilities.getMethod(nmsFieldNetworkManager.getType(), "getVersion", ioNettyChannel);
  636.  
  637. } catch (Exception e)
  638. {
  639. System.err.println("[ParticleLIB] Error while loading: " + e.getMessage());
  640. e.printStackTrace(System.err);
  641. Bukkit.getPluginManager().disablePlugin(Bukkit.getPluginManager().getPlugin("ParticleLIB"));
  642. }
  643. }
  644.  
  645. //<editor-fold desc="getEnum">
  646. private static Enum<?> getEnum(String enumFullName)
  647. {
  648. String[] x = enumFullName.split("\\.(?=[^\\.]+$)");
  649. if (x.length == 2)
  650. {
  651. String enumClassName = x[0];
  652. String enumName = x[1];
  653. try
  654. {
  655. Class<Enum> cl = (Class<Enum>) Class.forName(enumClassName);
  656. return Enum.valueOf(cl, enumName);
  657. } catch (ClassNotFoundException e)
  658. {
  659. e.printStackTrace();
  660. }
  661. }
  662. return null;
  663. }
  664. //</editor-fold>
  665.  
  666. //<editor-fold desc="isPlayerInRange">
  667. public static boolean isPlayerInRange(Player p, Location center)
  668. {
  669. double distance = 0;
  670. if (!p.getLocation().getWorld().equals(center.getWorld()))
  671. {
  672. return false;
  673. }
  674. if ((distance = center.distanceSquared(p.getLocation())) > Double.MAX_VALUE)
  675. {
  676. return false;
  677. }
  678. return distance < particleRange * particleRange;
  679. }
  680. //</editor-fold>
  681.  
  682. //<editor-fold desc="ReflectionUtilities">
  683. public static class ReflectionUtilities {
  684.  
  685. public static void setValue(Object instance, String fieldName, Object value)
  686. {
  687. Field field = null;
  688. try
  689. {
  690. field = instance.getClass().getDeclaredField(fieldName);
  691. } catch (NoSuchFieldException e)
  692. {
  693. e.printStackTrace();
  694. }
  695. field.setAccessible(true);
  696. try
  697. {
  698. field.set(instance, value);
  699. } catch (IllegalAccessException e)
  700. {
  701. e.printStackTrace();
  702. }
  703. }
  704.  
  705. public static Object getValue(Object instance, String fieldName)
  706. {
  707. Field field = null;
  708. try
  709. {
  710. field = instance.getClass().getDeclaredField(fieldName);
  711. } catch (NoSuchFieldException e)
  712. {
  713. e.printStackTrace();
  714. }
  715. field.setAccessible(true);
  716. try
  717. {
  718. return field.get(instance);
  719. } catch (IllegalAccessException e)
  720. {
  721. e.printStackTrace();
  722. }
  723.  
  724. return null;
  725. }
  726.  
  727. public static String getVersion()
  728. {
  729. String name = Bukkit.getServer().getClass().getPackage().getName();
  730. String version = name.substring(name.lastIndexOf('.') + 1) + ".";
  731. return version;
  732. }
  733.  
  734. public static Class<?> getNMSClass(String className)
  735. {
  736. String fullName = "net.minecraft.server." + getVersion() + className;
  737. Class<?> clazz = null;
  738. try
  739. {
  740. clazz = Class.forName(fullName);
  741. } catch (Exception e)
  742. {
  743. e.printStackTrace();
  744. }
  745. return clazz;
  746. }
  747.  
  748. public static Class<?> getOBCClass(String className)
  749. {
  750. String fullName = "org.bukkit.craftbukkit." + getVersion() + className;
  751. Class<?> clazz = null;
  752. try
  753. {
  754. clazz = Class.forName(fullName);
  755. } catch (Exception e)
  756. {
  757. e.printStackTrace();
  758. }
  759. return clazz;
  760. }
  761.  
  762. public static Object getHandle(Object obj)
  763. {
  764. try
  765. {
  766. return getMethod(obj.getClass(), "getHandle", new Class[0]).invoke(obj, new Object[0]);
  767. } catch (Exception e)
  768. {
  769. e.printStackTrace();
  770. }
  771. return null;
  772. }
  773.  
  774. public static Field getField(Class<?> clazz, String name)
  775. {
  776. try
  777. {
  778. Field field = clazz.getDeclaredField(name);
  779. field.setAccessible(true);
  780. return field;
  781. } catch (Exception e)
  782. {
  783. e.printStackTrace();
  784. }
  785. return null;
  786. }
  787.  
  788. public static Method getMethod(Class<?> clazz, String name, Class<?>... args)
  789. {
  790. for (Method m : clazz.getMethods())
  791. {
  792. if (m.getName().equals(name) && (args.length == 0 || ClassListEqual(args, m.getParameterTypes())))
  793. {
  794. m.setAccessible(true);
  795. return m;
  796. }
  797. }
  798. return null;
  799. }
  800.  
  801. public static boolean ClassListEqual(Class<?>[] l1, Class<?>[] l2)
  802. {
  803. boolean equal = true;
  804. if (l1.length != l2.length)
  805. {
  806. return false;
  807. }
  808. for (int i = 0; i < l1.length; i++)
  809. {
  810. if (l1[i] != l2[i])
  811. {
  812. equal = false;
  813. break;
  814. }
  815. }
  816. return equal;
  817. }
  818. }
  819. //</editor-fold>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement