Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2018
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.51 KB | None | 0 0
  1. package net.noobsters.www.UHC.Listeners.Utils;
  2.  
  3. import java.util.HashMap;
  4. import java.util.Map.Entry;
  5.  
  6. import org.bukkit.Location;
  7. import org.bukkit.craftbukkit.v1_8_R3.CraftWorld;
  8. import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
  9. import org.bukkit.entity.Player;
  10. import org.bukkit.scheduler.BukkitRunnable;
  11. import org.bukkit.util.Vector;
  12.  
  13. import net.minecraft.server.v1_8_R3.EntityWither;
  14. import net.minecraft.server.v1_8_R3.PacketPlayOutEntityDestroy;
  15. import net.minecraft.server.v1_8_R3.PacketPlayOutEntityMetadata;
  16. import net.minecraft.server.v1_8_R3.PacketPlayOutEntityTeleport;
  17. import net.minecraft.server.v1_8_R3.PacketPlayOutSpawnEntityLiving;
  18. import net.noobsters.www.UHC.UHC;
  19.  
  20.  
  21. public class HenixBar extends BukkitRunnable {
  22.  
  23. private static String title;
  24. private static HashMap<Player, EntityWither> withers = new HashMap<Player, EntityWither>();
  25.  
  26. public HenixBar(String title) {
  27. HenixBar.title = title;
  28. runTaskTimer(UHC.getInstance(), 0, 0);
  29. }
  30.  
  31. public static void addPlayer(Player player) {
  32. EntityWither wither = new EntityWither(((CraftWorld) player.getWorld()).getHandle());
  33. Location location = getWitherLocation(player.getLocation());
  34. wither.setCustomName(title);
  35. wither.setInvisible(true);
  36. wither.setLocation(location.getX(), location.getY(), location.getZ(), 0, 0);
  37. PacketPlayOutSpawnEntityLiving packet = new PacketPlayOutSpawnEntityLiving(wither);
  38. ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
  39. withers.put(player, wither);
  40. }
  41.  
  42. public static void clearBar() {
  43. withers.clear();
  44. }
  45.  
  46. public static void removePlayer(Player player) {
  47. if (withers.containsKey(player)) {
  48. PacketPlayOutEntityDestroy packet = new PacketPlayOutEntityDestroy(withers.get(player).getId());
  49. withers.remove(player);
  50. ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
  51. }
  52. }
  53.  
  54. public static void setTitle(String title) {
  55. HenixBar.title = title;
  56. for (Entry<Player, EntityWither> entry : withers.entrySet()) {
  57. EntityWither wither = entry.getValue();
  58. wither.setCustomName(title);
  59. PacketPlayOutEntityMetadata packet = new PacketPlayOutEntityMetadata(wither.getId(), wither.getDataWatcher(), true);
  60. ((CraftPlayer) entry.getKey()).getHandle().playerConnection.sendPacket(packet);
  61. }
  62. }
  63.  
  64. public static void setProgress(float progress) {
  65. for (Entry<Player, EntityWither> entry : withers.entrySet()) {
  66. EntityWither wither = entry.getValue();
  67. if (progress <= 0) progress = (float) 0.001;
  68. wither.setHealth(progress * wither.getMaxHealth());
  69. PacketPlayOutEntityMetadata packet = new PacketPlayOutEntityMetadata(wither.getId(), wither.getDataWatcher(), true);
  70. ((CraftPlayer) entry.getKey()).getHandle().playerConnection.sendPacket(packet);
  71. }
  72. }
  73.  
  74. public static Location getWitherLocation(Location location) {
  75. return location.add(location.getDirection().normalize().multiply(40).add(new Vector(0, 5, 0)));
  76. }
  77.  
  78. public void run() {
  79. for (Entry<Player, EntityWither> entry : withers.entrySet()) {
  80. EntityWither wither = entry.getValue();
  81. Location location = getWitherLocation(entry.getKey().getEyeLocation());
  82. wither.setLocation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
  83. PacketPlayOutEntityTeleport packet = new PacketPlayOutEntityTeleport(wither);
  84. ((CraftPlayer) entry.getKey()).getHandle().playerConnection.sendPacket(packet);
  85. }
  86. }
  87.  
  88. public static boolean hasPlayer(Player player) {
  89. return withers.containsKey(player);
  90. }
  91.  
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement