Advertisement
EntenPlayz

Untitled

Jun 9th, 2017
431
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 29.23 KB | None | 0 0
  1. package de.EntenPlayz.APIs;
  2.  
  3. import java.io.File;
  4. import java.io.IOException;
  5. import java.lang.reflect.Constructor;
  6. import java.lang.reflect.Field;
  7. import java.util.ArrayList;
  8. import java.util.HashMap;
  9. import java.util.List;
  10. import java.util.Random;
  11.  
  12. import org.bukkit.Bukkit;
  13. import org.bukkit.ChatColor;
  14. import org.bukkit.GameMode;
  15. import org.bukkit.Location;
  16. import org.bukkit.Material;
  17. import org.bukkit.configuration.file.FileConfiguration;
  18. import org.bukkit.configuration.file.YamlConfiguration;
  19. import org.bukkit.craftbukkit.v1_8_R3.CraftWorld;
  20. import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity;
  21. import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
  22. import org.bukkit.entity.ArmorStand;
  23. import org.bukkit.entity.Entity;
  24. import org.bukkit.entity.Item;
  25. import org.bukkit.entity.LivingEntity;
  26. import org.bukkit.entity.Player;
  27. import org.bukkit.inventory.ItemStack;
  28. import org.bukkit.inventory.meta.ItemMeta;
  29. import org.bukkit.inventory.meta.SkullMeta;
  30. import org.bukkit.potion.PotionEffect;
  31.  
  32. import com.google.common.io.ByteArrayDataOutput;
  33. import com.google.common.io.ByteStreams;
  34.  
  35. import de.EntenPlayz.Main;
  36. import net.minecraft.server.v1_8_R3.EntityArmorStand;
  37. import net.minecraft.server.v1_8_R3.EntityInsentient;
  38. import net.minecraft.server.v1_8_R3.EntityPlayer;
  39. import net.minecraft.server.v1_8_R3.EnumParticle;
  40. import net.minecraft.server.v1_8_R3.IChatBaseComponent;
  41. import net.minecraft.server.v1_8_R3.IChatBaseComponent.ChatSerializer;
  42. import net.minecraft.server.v1_8_R3.NBTTagCompound;
  43. import net.minecraft.server.v1_8_R3.Navigation;
  44. import net.minecraft.server.v1_8_R3.Packet;
  45. import net.minecraft.server.v1_8_R3.PacketPlayOutChat;
  46. import net.minecraft.server.v1_8_R3.PacketPlayOutEntityDestroy;
  47. import net.minecraft.server.v1_8_R3.PacketPlayOutPlayerListHeaderFooter;
  48. import net.minecraft.server.v1_8_R3.PacketPlayOutSpawnEntityLiving;
  49. import net.minecraft.server.v1_8_R3.PacketPlayOutWorldParticles;
  50. import net.minecraft.server.v1_8_R3.PathEntity;
  51. import net.minecraft.server.v1_8_R3.PlayerConnection;
  52.  
  53.  
  54. public class EntenAPI {
  55.  
  56. Main friends;
  57. String cp;
  58.  
  59. public EntenAPI(Main friends, String defaultplayercolor) {
  60. this.friends = friends;
  61. this.cp = defaultplayercolor;
  62. }
  63.  
  64. public ItemStack createItemwithID(int id, int subid, int amount, String DisplayName, ArrayList<String> lore) {
  65.  
  66. @SuppressWarnings("deprecation")
  67. ItemStack is = new ItemStack(id, amount, (short) subid);
  68. ItemMeta im = is.getItemMeta();
  69. im.setDisplayName(DisplayName);
  70. im.setLore(lore);
  71. is.setItemMeta(im);
  72. return is;
  73.  
  74. }
  75.  
  76. public ItemStack createItemwithMaterial(Material m, int subid, int amount, String DisplayName,
  77. ArrayList<String> lore) {
  78. ItemStack is = new ItemStack(m, amount, (short) subid);
  79. ItemMeta im = is.getItemMeta();
  80. im.setDisplayName(DisplayName);
  81. im.setLore(lore);
  82. is.setItemMeta(im);
  83. return is;
  84.  
  85. }
  86.  
  87. public ItemStack createHead(String owner, ArrayList<String> lore) {
  88.  
  89. ItemStack i = new ItemStack(Material.SKULL_ITEM, 1, (byte) 3);
  90. SkullMeta sm = (SkullMeta) i.getItemMeta();
  91. sm.setOwner(owner);
  92. sm.setLore(lore);
  93. i.setItemMeta(sm);
  94. return i;
  95. }
  96.  
  97. public ItemStack createHead(String owner, ArrayList<String> lore, String name) {
  98.  
  99. ItemStack i = new ItemStack(Material.SKULL_ITEM, 1, (byte) 3);
  100. SkullMeta sm = (SkullMeta) i.getItemMeta();
  101. sm.setOwner(owner);
  102. sm.setDisplayName(name);
  103. sm.setLore(lore);
  104. i.setItemMeta(sm);
  105. return i;
  106. }
  107.  
  108. public boolean isNumeric(String number) {
  109. try {
  110. Integer.parseInt(number);
  111. } catch (Exception exception) {
  112. return false;
  113. }
  114. return true;
  115. }
  116.  
  117. public int getRandom(int max) {
  118. Random r = new Random();
  119. return r.nextInt(max);
  120. }
  121.  
  122. public String getTime(int time) {
  123.  
  124. int minutes = (int) time / 60;
  125. String min;
  126. if (minutes <= 9) {
  127. min = "0" + minutes;
  128. } else {
  129. min = "" + minutes;
  130. }
  131.  
  132. int seconds = time - (minutes * 60);
  133. String sec;
  134. if (seconds <= 9) {
  135. sec = "0" + seconds;
  136. } else {
  137. sec = "" + seconds;
  138. }
  139.  
  140. return min + ":" + sec;
  141. }
  142.  
  143. public String getKD(int kills, int deaths, int splitafter) {
  144.  
  145. if (kills == 0 && deaths == 0) {
  146. return "" + 0.00;
  147. } else if (kills >= 1 && deaths == 0) {
  148. return "" + ((double)kills);
  149. } else {
  150. if(splitafter != 0){
  151. String kd = "" + ((double)kills / deaths);
  152. if(kd.length() >= splitafter){
  153. kd = kd.substring(0, splitafter);
  154. return kd;
  155. }else{
  156. return "" + ((double)kills / deaths);
  157. }
  158. }else{
  159. return "" + ((double)kills / deaths);
  160. }
  161. }
  162.  
  163. }
  164.  
  165. public String getPercentof(int hundredpercent, int div, int splitafter) {
  166.  
  167. String percent = "0.00%";
  168.  
  169. if(hundredpercent == 0) return percent;
  170.  
  171. double first = ((double)div/hundredpercent);
  172. double end = ((double)first * 100);
  173.  
  174. percent = "" + end;
  175.  
  176. if(splitafter != 0){
  177. String wl = percent;
  178. if(wl.length() >= splitafter){
  179. wl = wl.substring(0, splitafter);
  180. return wl + "%";
  181. }else{
  182. return percent + "%";
  183. }
  184. }else{
  185. return percent + "%";
  186. }
  187.  
  188. }
  189.  
  190. public List<String> convertStringArrayToArraylist(String str, String splitby) {
  191. List<String> strFragments = new ArrayList<>();
  192. String[] strArray = str.split(splitby);
  193.  
  194. for (int i = 0; i < strArray.length; i++) {
  195. strFragments.add(strArray[i]);
  196. }
  197. return strFragments;
  198. }
  199.  
  200. public long getCurrentTimeMillis() {
  201. return System.currentTimeMillis();
  202. }
  203.  
  204. public int getRemainingSeconds(long currenttimemillis, long timemillisbefore) {
  205. long millis = timemillisbefore - currenttimemillis;
  206. int seconds = 0;
  207. while (millis > 1000) {
  208. millis -= 1000;
  209. seconds++;
  210. }
  211. return seconds;
  212. }
  213.  
  214. public int getRemainingMinutes(int seconds) {
  215. int minutes = 0;
  216. while (seconds > 60) {
  217. seconds -= 60;
  218. minutes++;
  219. }
  220. return minutes;
  221. }
  222.  
  223. public int getRemainingHours(int minutes) {
  224. int hours = 0;
  225. while (minutes > 60) {
  226. minutes -= 60;
  227. hours++;
  228. }
  229. return hours;
  230. }
  231.  
  232. public int getRemainingDays(int hours) {
  233. int days = 0;
  234. while (hours > 24) {
  235. hours -= 24;
  236. days++;
  237. }
  238. return days;
  239. }
  240.  
  241. public int getRemainingWeeks(int days) {
  242. int weeks = 0;
  243. while (days > 7) {
  244. days -= 7;
  245. weeks++;
  246. }
  247. return weeks;
  248. }
  249.  
  250. public String getRemainingTime(long start, long timemillisbefore, String nullresult, String color) {
  251. long current = start;
  252. long end = timemillisbefore;
  253. if (end == -1) {
  254. return nullresult;
  255. }
  256. long millis = end - current;
  257. long seconds = 0;
  258. long minutes = 0;
  259. long hours = 0;
  260. long days = 0;
  261. long weeks = 0;
  262.  
  263. while (millis > 1000) {
  264. millis -= 1000;
  265. seconds++;
  266. }
  267. while (seconds > 60) {
  268. seconds -= 60;
  269. minutes++;
  270. }
  271. while (minutes > 60) {
  272. seconds -= 60;
  273. hours++;
  274. }
  275. while (hours > 24) {
  276. seconds -= 24;
  277. days++;
  278. }
  279. while (days > 7) {
  280. days -= 7;
  281. weeks++;
  282. }
  283.  
  284. return color + "" + weeks + " Woche(n) " + days + " Tag(e) " + hours + " Stunde(n) " + minutes + " Minute(n) "
  285. + seconds + " Sekunde(n)";
  286. }
  287.  
  288. public String getRemainingHours(long currenttimemillis, long timemillisbefore, String nullresult, String color) {
  289. long current = currenttimemillis;
  290. long end = timemillisbefore;
  291. if (end == -1) {
  292. return nullresult;
  293. }
  294. long millis = end - current;
  295. long seconds = 0;
  296. long minutes = 0;
  297. long hours = 0;
  298.  
  299. while (millis > 1000) {
  300. millis -= 1000;
  301. seconds++;
  302. }
  303. while (seconds > 60) {
  304. seconds -= 60;
  305. minutes++;
  306. }
  307. while (minutes > 60) {
  308. seconds -= 60;
  309. hours++;
  310. }
  311.  
  312. return color + "" + hours + " Stunde(n) " + minutes + " Minute(n) " + seconds + " Sekunde(n)";
  313. }
  314.  
  315. /*
  316. *
  317. * Players
  318. *
  319. */
  320.  
  321. public void refreshPlayer(Player player) {
  322. player.setExp(0);
  323. player.setFoodLevel(20);
  324. player.setHealth(20);
  325. player.setExp(0.0F);
  326. player.setLevel(0);
  327. player.setFireTicks(0);
  328. player.setGameMode(GameMode.SURVIVAL);
  329.  
  330. for (PotionEffect effect : player.getActivePotionEffects()) {
  331. player.removePotionEffect(effect.getType());
  332. }
  333. }
  334.  
  335. public void removePotionEffects(Player player) {
  336. for (PotionEffect effect : player.getActivePotionEffects()) {
  337. player.removePotionEffect(effect.getType());
  338. }
  339. }
  340.  
  341. public Player getRandomOnlinePlayer() {
  342.  
  343. List<Player> list = new ArrayList<>();
  344.  
  345. for (Player player : Bukkit.getOnlinePlayers()) {
  346. list.add(player);
  347. }
  348. int rn = getRandom(list.size());
  349.  
  350. return list.get(rn);
  351. }
  352.  
  353. public String getRandomString(List<String> list) {
  354. int rn = getRandom(list.size());
  355. return list.get(rn);
  356. }
  357.  
  358. public Player getRandomPlayer(List<Player> list) {
  359. int rn = getRandom(list.size());
  360. return list.get(rn);
  361. }
  362.  
  363. public Object getRandomObject(List<Object> list) {
  364. int rn = getRandom(list.size());
  365. return list.get(rn);
  366. }
  367.  
  368. public String getPlayerName(Player player) {
  369. return cp + player.getDisplayName();
  370. }
  371.  
  372. public void connect(Player player, String servername) {
  373. ByteArrayDataOutput out = ByteStreams.newDataOutput();
  374. out.writeUTF("Connect");
  375. out.writeUTF(servername);
  376. player.sendPluginMessage(friends, "BungeeCord", out.toByteArray());
  377. }
  378.  
  379. public void hidePlayer(Player player) {
  380. for (Player player2 : Bukkit.getOnlinePlayers()) {
  381. player2.hidePlayer(player);
  382. }
  383. }
  384.  
  385. public void showPlayer(Player player) {
  386. for (Player player2 : Bukkit.getOnlinePlayers()) {
  387. player2.showPlayer(player);
  388. }
  389. }
  390.  
  391. public void hidePlayertoIngames(Player player, List<Player> spectators) {
  392. for (Player player2 : Bukkit.getOnlinePlayers()) {
  393. if (spectators.contains(player2) == false) {
  394. player2.hidePlayer(player);
  395. }
  396. }
  397. }
  398.  
  399. public void showPlayertoIngames(Player player, List<Player> spectators) {
  400. for (Player player2 : Bukkit.getOnlinePlayers()) {
  401. if (spectators.contains(player2) == false) {
  402. player2.showPlayer(player);
  403. }
  404. }
  405. }
  406.  
  407. public static void findPath(LivingEntity e, Location l, float speed) {
  408. EntityInsentient ei = ((EntityInsentient) ((CraftEntity) e).getHandle());
  409. Navigation nav = (Navigation) ei.getNavigation();
  410. nav.a(true);
  411. PathEntity path = nav.a(l.getX(), l.getY(), l.getZ());
  412. nav.a(path, speed);
  413. }
  414.  
  415. public void freezeEntity(Entity en) {
  416. net.minecraft.server.v1_8_R3.Entity nmsEn = ((CraftEntity) en).getHandle();
  417. NBTTagCompound compound = new NBTTagCompound();
  418. nmsEn.c(compound);
  419. compound.setByte("NoAI", (byte) 1);
  420. nmsEn.f(compound);
  421. }
  422.  
  423. public void createNewFile(String filename, String path) {
  424.  
  425. File file = new File("plugins/" + path, filename);
  426. if (file.exists())
  427. return;
  428. try {
  429. file.createNewFile();
  430. } catch (IOException e) {
  431. e.printStackTrace();
  432. }
  433. }
  434.  
  435. public File getFile(String filename, String path) {
  436.  
  437. File file = new File("plugins/" + path, filename);
  438. return file;
  439.  
  440. }
  441.  
  442. public void deleteFile(String filename, String path) {
  443.  
  444. File file = new File("plugins/" + path, filename);
  445. file.delete();
  446.  
  447. }
  448.  
  449. public FileConfiguration getConfiguration(String filename, String path) {
  450. return YamlConfiguration.loadConfiguration(getFile(filename, path));
  451. }
  452.  
  453. public Location getLocation(String ymlname, String name, String path) {
  454.  
  455. FileConfiguration cfg = getConfiguration(ymlname, path);
  456. double x = cfg.getDouble(name + ".X");
  457. double y = cfg.getDouble(name + ".Y");
  458. double z = cfg.getDouble(name + ".Z");
  459. double yaw = cfg.getDouble(name + ".Yaw");
  460. double pitch = cfg.getDouble(name + ".Pitch");
  461. String world = cfg.getString(name + ".World");
  462.  
  463. Location l = new Location(Bukkit.getWorld(world), x, y, z);
  464. l.setYaw((float) yaw);
  465. l.setPitch((float) pitch);
  466. return l;
  467. }
  468.  
  469. public void saveLocation(Player p, String ymlname, String name, String path) {
  470.  
  471. FileConfiguration cfg = getConfiguration(ymlname, path);
  472.  
  473. cfg.set(name + ".X", p.getLocation().getX());
  474. cfg.set(name + ".Y", p.getLocation().getY());
  475. cfg.set(name + ".Z", p.getLocation().getZ());
  476. cfg.set(name + ".Yaw", p.getLocation().getYaw());
  477. cfg.set(name + ".Pitch", p.getLocation().getPitch());
  478. cfg.set(name + ".World", p.getWorld().getName());
  479.  
  480. try {
  481. cfg.save(getFile(ymlname, path));
  482. } catch (IOException e) {
  483. e.printStackTrace();
  484. }
  485.  
  486. }
  487.  
  488. public FlyingItem spawnFlyingItem(ItemStack item, Location location) {
  489.  
  490. FlyingItem fly = new FlyingItem();
  491.  
  492. fly.setLocation(location);
  493. fly.setHeight(2.25);
  494. fly.setItemStack(item);
  495. fly.spawn();
  496.  
  497. return fly;
  498. }
  499.  
  500. public void sendPacket(Player player, Object packet) {
  501. try {
  502. Object handle = player.getClass().getMethod("getHandle", new Class[0]).invoke(player, new Object[0]);
  503. Object playerConnection = handle.getClass().getField("playerConnection").get(handle);
  504. playerConnection.getClass().getMethod("sendPacket", new Class[] { getNMSClass("Packet") })
  505. .invoke(playerConnection, new Object[] { packet });
  506. } catch (Exception e) {
  507. e.printStackTrace();
  508. }
  509. }
  510.  
  511. public Class<?> getNMSClass(String name) {
  512. String version = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3];
  513. try {
  514. return Class.forName("net.minecraft.server." + version + "." + name);
  515. } catch (ClassNotFoundException e) {
  516. e.printStackTrace();
  517. }
  518. return null;
  519. }
  520.  
  521. public void sendTitle(Player player, String title, String subtitle) {
  522. int fadeIn = 1;
  523. int stay = 1;
  524. int fadeOut = 1;
  525. try {
  526. if (title != null) {
  527. title = ChatColor.translateAlternateColorCodes('&', title);
  528. title = title.replaceAll("%p%", player.getDisplayName());
  529. Object enumTitle = getNMSClass("PacketPlayOutTitle").getDeclaredClasses()[0].getField("TITLE")
  530. .get(null);
  531. Object chatTitle = getNMSClass("IChatBaseComponent").getDeclaredClasses()[0]
  532. .getMethod("a", new Class[] { String.class })
  533. .invoke(null, new Object[] { "{\"text\":\"" + title + "\"}" });
  534. Constructor<?> titleConstructor = getNMSClass("PacketPlayOutTitle")
  535. .getConstructor(new Class[] { getNMSClass("PacketPlayOutTitle").getDeclaredClasses()[0],
  536. getNMSClass("IChatBaseComponent"), Integer.TYPE, Integer.TYPE, Integer.TYPE });
  537. Object titlePacket = titleConstructor
  538. .newInstance(new Object[] { enumTitle, chatTitle, fadeIn, stay, fadeOut });
  539. sendPacket(player, titlePacket);
  540. }
  541. if (subtitle != null) {
  542. subtitle = ChatColor.translateAlternateColorCodes('&', subtitle);
  543. subtitle = subtitle.replaceAll("%p%", player.getDisplayName());
  544. Object enumSubtitle = getNMSClass("PacketPlayOutTitle").getDeclaredClasses()[0].getField("SUBTITLE")
  545. .get(null);
  546. Object chatSubtitle = getNMSClass("IChatBaseComponent").getDeclaredClasses()[0]
  547. .getMethod("a", new Class[] { String.class })
  548. .invoke(null, new Object[] { "{\"text\":\"" + subtitle + "\"}" });
  549. Constructor<?> subtitleConstructor = getNMSClass("PacketPlayOutTitle")
  550. .getConstructor(new Class[] { getNMSClass("PacketPlayOutTitle").getDeclaredClasses()[0],
  551. getNMSClass("IChatBaseComponent"), Integer.TYPE, Integer.TYPE, Integer.TYPE });
  552. Object subtitlePacket = subtitleConstructor
  553. .newInstance(new Object[] { enumSubtitle, chatSubtitle, fadeIn, stay, fadeOut });
  554. sendPacket(player, subtitlePacket);
  555. }
  556. } catch (Exception e) {
  557. e.printStackTrace();
  558. }
  559. }
  560.  
  561. public void sendActionbar(String msg, Player player) {
  562. msg = msg.replace("&", "�");
  563. msg = msg.replace("%p", player.getDisplayName());
  564.  
  565. PlayerConnection con = ((CraftPlayer) player).getHandle().playerConnection;
  566.  
  567. IChatBaseComponent chat = ChatSerializer.a("{\"text\": \"" + msg + "\"}");
  568. PacketPlayOutChat packet = new PacketPlayOutChat(chat, (byte) 2);
  569. con.sendPacket(packet);
  570. }
  571.  
  572. public void sendTabTitle(Player player, String header, String footer) {
  573. if (header == null)
  574. header = "";
  575.  
  576. if (footer == null)
  577. footer = "";
  578.  
  579. PlayerConnection connection = ((CraftPlayer) player).getHandle().playerConnection;
  580.  
  581. IChatBaseComponent tabTitle = ChatSerializer.a("{\"text\": \"" + header + "\"}");
  582.  
  583. IChatBaseComponent tabFoot = ChatSerializer.a("{\"text\": \"" + footer + "\"}");
  584.  
  585. PacketPlayOutPlayerListHeaderFooter headerPacket = new PacketPlayOutPlayerListHeaderFooter(tabTitle);
  586.  
  587. try {
  588.  
  589. Field field = headerPacket.getClass().getDeclaredField("b");
  590. field.setAccessible(true);
  591. field.set(headerPacket, tabFoot);
  592.  
  593. } catch (Exception e) {
  594.  
  595. e.printStackTrace();
  596.  
  597. } finally {
  598.  
  599. connection.sendPacket(headerPacket);
  600.  
  601. }
  602. }
  603. HashMap<Player, Hologram> holo = new HashMap<>();
  604. public void setHolo(Player player, String[] text, Location loc, boolean clearlast){
  605. Hologram hologram = new Hologram(text, loc);
  606. hologram.showPlayer(player);
  607. if(clearlast){
  608. if(holo.containsKey(player)){
  609. Hologram holotoclear = holo.get(player);
  610. holotoclear.hidePlayer(player);
  611. holo.remove(player);
  612. }
  613. }
  614. holo.put(player, hologram);
  615. }
  616. public void removeHolo(Player player){
  617. if(holo.containsKey(player)){
  618. Hologram hologram = holo.get(player);
  619. hologram.hidePlayer(player);
  620. holo.remove(player);
  621. }
  622. }
  623.  
  624. }
  625.  
  626. class FlyingItem {
  627.  
  628. private ArmorStand armorstand;
  629. private Location location;
  630. private String text = null;
  631. private Boolean h = false;
  632. private ItemStack itemstack;
  633. private double height = -1.3;
  634.  
  635. public FlyingItem() {
  636.  
  637. }
  638.  
  639. public void setLocation(Location location) {
  640. this.location = location;
  641. }
  642.  
  643. public void setText(String text) {
  644. this.text = text;
  645. }
  646.  
  647. public void setItemStack(ItemStack itemstack) {
  648. this.itemstack = itemstack;
  649. }
  650.  
  651. public void setHeight(double height) {
  652. this.height = height - 1.3;
  653. if (this.location != null) {
  654. this.location.setY(this.location.getY() + this.height);
  655. h = true;
  656. }
  657. }
  658.  
  659. public void remove() {
  660. this.location = null;
  661. this.armorstand.remove();
  662. this.armorstand.getPassenger().remove();
  663. this.armorstand = null;
  664. this.h = false;
  665. this.height = 0;
  666. this.text = null;
  667. this.itemstack = null;
  668. }
  669.  
  670. public void teleport(Location location) {
  671. if (this.location != null) {
  672. armorstand.teleport(location);
  673. this.location = location;
  674. }
  675. }
  676.  
  677. public void spawn() {
  678. if (!h) {
  679. this.location.setY(this.location.getY() + this.height);
  680. h = true;
  681. }
  682. armorstand = (ArmorStand) this.location.getWorld().spawn(this.location, ArmorStand.class);
  683. armorstand.setVisible(false);
  684. Item i = this.location.getWorld().dropItem(this.getLocation().add(0, 2, 0), this.itemstack);
  685. i.setPickupDelay(2147483647);
  686. if (this.text != null) {
  687. i.setCustomName(this.text);
  688. i.setCustomNameVisible(true);
  689. }
  690. armorstand.setPassenger(i);
  691. }
  692.  
  693. public Location getLocation() {
  694. return this.location;
  695. }
  696.  
  697. public ItemStack getItemStack() {
  698. return this.itemstack;
  699. }
  700.  
  701. public double getHeight() {
  702. return this.height;
  703. }
  704.  
  705. public String getText() {
  706. return this.text;
  707. }
  708. }
  709.  
  710. class Hologram {
  711.  
  712. private java.util.List<EntityArmorStand> List = new ArrayList<EntityArmorStand>();
  713. private String[] text;
  714. private Location loc;
  715. private double distance = 0.25D;
  716. int count;
  717.  
  718. public Hologram(String[] text, Location loc) {
  719.  
  720. this.text = text;
  721. this.loc = loc;
  722. create();
  723. }
  724.  
  725. public void create() {
  726. for (String text : this.text) {
  727. EntityArmorStand e = new EntityArmorStand(((CraftWorld) this.loc.getWorld()).getHandle(), this.loc.getX(),
  728. this.loc.getY(), this.loc.getZ());
  729.  
  730. e.setCustomName(text);
  731. e.setCustomNameVisible(true);
  732. e.setInvisible(true);
  733. e.setGravity(true);
  734. List.add(e);
  735. count++;
  736. this.loc.subtract(0, this.distance, 0);
  737.  
  738. }
  739. for (int i = 0; i < count; i++) {
  740. this.loc.add(0, this.distance, 0);
  741. }
  742. this.count++;
  743. }
  744.  
  745. public void hidePlayer(Player p) {
  746. for (EntityArmorStand a : List) {
  747. PacketPlayOutEntityDestroy packet = new PacketPlayOutEntityDestroy(a.getId());
  748. ((CraftPlayer) p).getHandle().playerConnection.sendPacket(packet);
  749.  
  750. }
  751.  
  752. }
  753.  
  754. public void showPlayer(Player p) {
  755. for (EntityArmorStand a : List) {
  756. PacketPlayOutSpawnEntityLiving packet = new PacketPlayOutSpawnEntityLiving(a);
  757. ((CraftPlayer) p).getHandle().playerConnection.sendPacket(packet);
  758.  
  759. }
  760.  
  761. }
  762.  
  763. }
  764.  
  765. class Particle {
  766.  
  767. EnumParticle particletype;
  768. boolean longdistance;
  769. Location location;
  770. float offsetx;
  771. float offsety;
  772. float offsetz;
  773. float speed;
  774. int amount;
  775.  
  776. public Particle(EnumParticle particletype, Location location, boolean longdistance, float offsetx, float offsety,
  777. float offsetz, float speed, int amount) {
  778. this.particletype = particletype;
  779. this.location = location;
  780. this.longdistance = longdistance;
  781. this.offsetx = offsetx;
  782. this.offsety = offsety;
  783. this.offsetz = offsetz;
  784. this.speed = speed;
  785. this.amount = amount;
  786. }
  787.  
  788. public void sendAll() {
  789. PacketPlayOutWorldParticles packet = new PacketPlayOutWorldParticles(this.particletype, this.longdistance,
  790. (float) this.location.getX(), (float) this.location.getY(), (float) this.location.getZ(), this.offsetx,
  791. this.offsety, this.offsetz, this.speed, this.amount, 0);
  792.  
  793. for (Player player : Bukkit.getOnlinePlayers()) {
  794. ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
  795. }
  796. }
  797.  
  798. public void sendPlayer(Player player) {
  799. PacketPlayOutWorldParticles packet = new PacketPlayOutWorldParticles(this.particletype, this.longdistance,
  800. (float) this.location.getX(), (float) this.location.getY(), (float) this.location.getZ(), this.offsetx,
  801. this.offsety, this.offsetz, this.speed, this.amount);
  802. ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
  803. }
  804.  
  805. }
  806.  
  807. class API_Form {
  808. public void playEffectWithForm(Player p, Location loc, ParticleType type, Form form, double length, double update,
  809. float speed) {
  810. Location middle = loc.clone();
  811. Location myLoc = loc.clone();
  812. Location before = myLoc.clone();
  813. if (form == Form.CIRCLE) {
  814.  
  815. for (double x = before.getX() - length - 0.25D; x < before.getX() + length + 0.25D; x += update) {
  816. for (double z = before.getZ() - length - 0.25D; z < before.getZ() + length + 0.25D; z += update) {
  817. myLoc.setX(x);
  818. myLoc.setZ(z);
  819. if ((middle.distance(myLoc) > length - update / 2.0D)
  820. && (middle.distance(myLoc) < length + update / 2.0D)) {
  821. playEffect(myLoc, type, 0.0F, 0.0F, 0.0F, speed, 1);
  822. }
  823. }
  824. }
  825. } else if (form == Form.SPHERE) {
  826. for (double x = before.getX() - length - 0.25D; x < before.getX() + length + 0.25D; x += update) {
  827. for (double y = before.getY() - length - 0.25D; y < before.getY() + length + 0.25D; y += update) {
  828. for (double z = before.getZ() - length - 0.25D; z < before.getZ() + length + 0.25D; z += update) {
  829. myLoc.setX(x);
  830. myLoc.setY(y);
  831. myLoc.setZ(z);
  832. if ((middle.distance(myLoc) > length - update / 2.0D)
  833. && (middle.distance(myLoc) < length + update / 2.0D)) {
  834. playEffect(myLoc, type, 0.0F, 0.0F, 0.0F, speed, 1);
  835. }
  836. }
  837. }
  838. }
  839. } else if (form == Form.SQUARE) {
  840. myLoc.setZ(before.getZ() - length / 2.0D);
  841. for (double x = before.getX() - length / 2.0D; x < before.getX() + length / 2.0D; x += update) {
  842. myLoc.setX(x);
  843.  
  844. playEffect(myLoc, type, 0.0F, 0.0F, 0.0F, speed, 1);
  845. }
  846. myLoc.setZ(before.getZ() + length / 2.0D);
  847. for (double x = before.getX() - length / 2.0D; x < before.getX() + length / 2.0D; x += update) {
  848. myLoc.setX(x);
  849.  
  850. playEffect(myLoc, type, 0.0F, 0.0F, 0.0F, speed, 1);
  851. }
  852. myLoc.setZ(before.getZ());
  853. myLoc.setX(before.getX() - length / 2.0D);
  854. for (double z = before.getZ() - length / 2.0D; z < before.getZ() + length / 2.0D; z += update) {
  855. myLoc.setZ(z);
  856.  
  857. playEffect(myLoc, type, 0.0F, 0.0F, 0.0F, speed, 1);
  858. }
  859. myLoc.setX(before.getX() + length / 2.0D);
  860. for (double z = before.getZ() - length / 2.0D; z < before.getZ() + length / 2.0D; z += update) {
  861. myLoc.setZ(z);
  862.  
  863. playEffect(myLoc, type, 0.0F, 0.0F, 0.0F, speed, 1);
  864. }
  865. } else if (form == Form.CUBE) {
  866. for (double y = before.getY() - length / 2.0D; y < before.getY() + length / 2.0D; y += update) {
  867. myLoc.setY(y);
  868. playEffectWithForm(p, myLoc, type, Form.SQUARE, length, update, speed);
  869. }
  870. myLoc.setY(before.getY() - length / 2.0D);
  871. for (double x = before.getX() - length / 2.0D; x < before.getX() + length / 2.0D; x += update) {
  872. for (double z = before.getZ() - length / 2.0D; z < before.getZ() + length / 2.0D; z += update) {
  873. myLoc.setX(x);
  874. myLoc.setZ(z);
  875. playEffect(p, myLoc, type, 0.0F, 0.0F, 0.0F, speed, 1);
  876. }
  877. }
  878. myLoc.setY(before.getY() + length / 2.0D);
  879. for (double x = before.getX() - length / 2.0D; x < before.getX() + length / 2.0D; x += update) {
  880. for (double z = before.getZ() - length / 2.0D; z < before.getZ() + length / 2.0D; z += update) {
  881. myLoc.setX(x);
  882. myLoc.setZ(z);
  883. playEffect(p, myLoc, type, 0.0F, 0.0F, 0.0F, speed, 1);
  884. }
  885. }
  886. }
  887. }
  888.  
  889. public void playEffectWithForm(Location loc, ParticleType type, Form form, double length, double update,
  890. float speed) {
  891. for (Player p : loc.getWorld().getPlayers()) {
  892. playEffectWithForm(p, loc, type, form, length, update, speed);
  893. }
  894. }
  895.  
  896. public void playEffect(Player p, Location loc, ParticleType type, float offX, float offY, float offZ, float speed,
  897. int amount) {
  898. sendPacket(p, getWorldParticlesPacket(type.getHandle(), (float) loc.getX(), (float) loc.getY(),
  899. (float) loc.getZ(), offX, offY, offZ, speed, amount));
  900. }
  901.  
  902. public void playEffect(Location loc, ParticleType type, float offX, float offY, float offZ, float speed,
  903. int amount) {
  904. for (Player p : loc.getWorld().getPlayers()) {
  905. playEffect(p, loc, type, offX, offY, offZ, speed, amount);
  906. }
  907. }
  908.  
  909. public enum Form {
  910. CIRCLE, SPHERE, SQUARE, CUBE;
  911. }
  912.  
  913. public enum ParticleType {
  914. BARRIER(EnumParticle.BARRIER), BLOCK_CRACK(EnumParticle.BLOCK_CRACK), BLOCK_DUST(
  915. EnumParticle.BLOCK_DUST), CLOUD(EnumParticle.CLOUD), CRIT(EnumParticle.CRIT), CRIT_MAGIC(
  916. EnumParticle.CRIT_MAGIC), DRIP_LAVA(EnumParticle.DRIP_LAVA), DRIP_WATER(
  917. EnumParticle.DRIP_WATER), ENCHANTMENT_TABLE(
  918. EnumParticle.ENCHANTMENT_TABLE), EXPLOSION_HUGE(
  919. EnumParticle.EXPLOSION_HUGE), EXPLOSION_LARGE(
  920. EnumParticle.EXPLOSION_LARGE), EXPLOSION_NORMAL(
  921. EnumParticle.EXPLOSION_NORMAL), FIREWORKS_SPARK(
  922. EnumParticle.FIREWORKS_SPARK), FLAME(
  923. EnumParticle.FLAME), FOOTSTEP(
  924. EnumParticle.FOOTSTEP), HEART(
  925. EnumParticle.HEART), ITEM_CRACK(
  926. EnumParticle.ITEM_CRACK), ITEM_TAKE(
  927. EnumParticle.ITEM_TAKE), LAVA(
  928. EnumParticle.LAVA), MOB_APPEARANCE(
  929. EnumParticle.MOB_APPEARANCE), NOTE(
  930. EnumParticle.NOTE), PORTAL(
  931. EnumParticle.PORTAL), REDSTONE(
  932. EnumParticle.REDSTONE), SLIME(
  933. EnumParticle.SLIME), SMOKE_LARGE(
  934. EnumParticle.SMOKE_LARGE), SMOKE_NORMAL(
  935. EnumParticle.SMOKE_NORMAL), SNOW_SHOVEL(
  936. EnumParticle.SNOW_SHOVEL), SNOWBALL(
  937. EnumParticle.SNOWBALL), SPELL(
  938. EnumParticle.SPELL), SPELL_INSTANT(
  939. EnumParticle.SPELL_INSTANT), SPELL_MOB(
  940. EnumParticle.SPELL_MOB), SPELL_MOB_AMBIENT(
  941. EnumParticle.SPELL_MOB_AMBIENT), SPELL_WITCH(
  942. EnumParticle.SPELL_WITCH), SUSPENDED(
  943. EnumParticle.SUSPENDED), SUSPENDED_DEPTH(
  944. EnumParticle.SUSPENDED_DEPTH), TOWN_AURA(
  945. EnumParticle.TOWN_AURA), VILLAGER_ANGRY(
  946. EnumParticle.VILLAGER_ANGRY), VILLAGER_HAPPY(
  947. EnumParticle.VILLAGER_HAPPY), WATER_BUBBLE(
  948. EnumParticle.WATER_BUBBLE), WATER_DROP(
  949. EnumParticle.WATER_DROP), WATER_SPLASH(
  950. EnumParticle.WATER_SPLASH), WATER_WAKE(
  951. EnumParticle.WATER_WAKE);
  952.  
  953. private EnumParticle handle;
  954.  
  955. private ParticleType(EnumParticle handle) {
  956. this.handle = handle;
  957. }
  958.  
  959. public EnumParticle getHandle() {
  960. return this.handle;
  961. }
  962. }
  963.  
  964. private static void sendPacket(Player player, Packet<?> packet) {
  965. EntityPlayer entityPlayer = ((CraftPlayer) player).getHandle();
  966. entityPlayer.playerConnection.sendPacket(packet);
  967. }
  968.  
  969. private static PacketPlayOutWorldParticles getWorldParticlesPacket(EnumParticle particle, float x, float y, float z,
  970. float offX, float offY, float offZ, float speed, int amount) {
  971. return new PacketPlayOutWorldParticles(particle, false, x, y, z, offX, offY, offZ, speed, amount, null);
  972. }
  973.  
  974. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement