Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package net.noobsters.www.UHC.Listeners.Utils;
- import java.util.HashMap;
- import java.util.Map.Entry;
- import org.bukkit.Location;
- import org.bukkit.craftbukkit.v1_8_R3.CraftWorld;
- import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
- import org.bukkit.entity.Player;
- import org.bukkit.scheduler.BukkitRunnable;
- import org.bukkit.util.Vector;
- import net.minecraft.server.v1_8_R3.EntityWither;
- import net.minecraft.server.v1_8_R3.PacketPlayOutEntityDestroy;
- import net.minecraft.server.v1_8_R3.PacketPlayOutEntityMetadata;
- import net.minecraft.server.v1_8_R3.PacketPlayOutEntityTeleport;
- import net.minecraft.server.v1_8_R3.PacketPlayOutSpawnEntityLiving;
- import net.noobsters.www.UHC.UHC;
- public class HenixBar extends BukkitRunnable {
- private static String title;
- private static HashMap<Player, EntityWither> withers = new HashMap<Player, EntityWither>();
- public HenixBar(String title) {
- HenixBar.title = title;
- runTaskTimer(UHC.getInstance(), 0, 0);
- }
- public static void addPlayer(Player player) {
- EntityWither wither = new EntityWither(((CraftWorld) player.getWorld()).getHandle());
- Location location = getWitherLocation(player.getLocation());
- wither.setCustomName(title);
- wither.setInvisible(true);
- wither.setLocation(location.getX(), location.getY(), location.getZ(), 0, 0);
- PacketPlayOutSpawnEntityLiving packet = new PacketPlayOutSpawnEntityLiving(wither);
- ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
- withers.put(player, wither);
- }
- public static void clearBar() {
- withers.clear();
- }
- public static void removePlayer(Player player) {
- if (withers.containsKey(player)) {
- PacketPlayOutEntityDestroy packet = new PacketPlayOutEntityDestroy(withers.get(player).getId());
- withers.remove(player);
- ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
- }
- }
- public static void setTitle(String title) {
- HenixBar.title = title;
- for (Entry<Player, EntityWither> entry : withers.entrySet()) {
- EntityWither wither = entry.getValue();
- wither.setCustomName(title);
- PacketPlayOutEntityMetadata packet = new PacketPlayOutEntityMetadata(wither.getId(), wither.getDataWatcher(), true);
- ((CraftPlayer) entry.getKey()).getHandle().playerConnection.sendPacket(packet);
- }
- }
- public static void setProgress(float progress) {
- for (Entry<Player, EntityWither> entry : withers.entrySet()) {
- EntityWither wither = entry.getValue();
- if (progress <= 0) progress = (float) 0.001;
- wither.setHealth(progress * wither.getMaxHealth());
- PacketPlayOutEntityMetadata packet = new PacketPlayOutEntityMetadata(wither.getId(), wither.getDataWatcher(), true);
- ((CraftPlayer) entry.getKey()).getHandle().playerConnection.sendPacket(packet);
- }
- }
- public static Location getWitherLocation(Location location) {
- return location.add(location.getDirection().normalize().multiply(40).add(new Vector(0, 5, 0)));
- }
- public void run() {
- for (Entry<Player, EntityWither> entry : withers.entrySet()) {
- EntityWither wither = entry.getValue();
- Location location = getWitherLocation(entry.getKey().getEyeLocation());
- wither.setLocation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
- PacketPlayOutEntityTeleport packet = new PacketPlayOutEntityTeleport(wither);
- ((CraftPlayer) entry.getKey()).getHandle().playerConnection.sendPacket(packet);
- }
- }
- public static boolean hasPlayer(Player player) {
- return withers.containsKey(player);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement