Created
February 26, 2014 00:55
-
-
Save PaulBGD/9221257 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Hologram { | |
private static final double distance = 0.25; | |
private List<String> lines = new ArrayList<String>(); | |
private List<Integer> ids = new ArrayList<Integer>(); | |
private boolean showing = false; | |
private Location location; | |
public Hologram(String... lines) { | |
this.lines.addAll(Arrays.asList(lines)); | |
} | |
public void change(String... lines) { | |
destroy(); | |
this.lines = Arrays.asList(lines); | |
show(this.location); | |
} | |
public void show(Location loc) { | |
if (showing == true) { | |
try { | |
throw new Exception("Is already showing!"); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
} | |
Location first = loc.clone().add(0, (this.lines.size() / 2) * distance, 0); | |
for (int i = 0; i < this.lines.size(); i++) { | |
ids.addAll(showLine(first.clone(), this.lines.get(i))); | |
first.subtract(0, distance, 0); | |
} | |
showing = true; | |
this.location = loc; | |
} | |
public void show(Location loc, long ticks) { | |
show(loc); | |
new BukkitRunnable() { | |
@Override | |
public void run() { | |
destroy(); | |
} | |
}.runTaskLater(MMGames.getPlugin(), ticks); | |
} | |
public void destroy() { | |
if (showing == false) { | |
try { | |
throw new Exception("Isn't showing!"); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
} | |
int[] ints = new int[this.ids.size()]; | |
for (int i = 0; i < ints.length; i++) { | |
ints[i] = ids.get(i); | |
} | |
PacketPlayOutEntityDestroy packet = new PacketPlayOutEntityDestroy(ints); | |
for (Player player : Bukkit.getOnlinePlayers()) { | |
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); | |
} | |
showing = false; | |
this.location = null; | |
} | |
private static List<Integer> showLine(Location loc, String text) { | |
WorldServer world = ((CraftWorld) loc.getWorld()).getHandle(); | |
EntityWitherSkull skull = new EntityWitherSkull(world); | |
skull.setLocation(loc.getX(), loc.getY() + 1 + 55, loc.getZ(), 0, 0); | |
((CraftWorld) loc.getWorld()).getHandle().addEntity(skull); | |
EntityHorse cow = new EntityHorse(world); | |
cow.setLocation(loc.getX(), loc.getY() + 55, loc.getZ(), 0, 0); | |
cow.setAge(-1700000); | |
cow.setCustomName(text); | |
cow.setCustomNameVisible(true); | |
PacketPlayOutSpawnEntityLiving packedt = new PacketPlayOutSpawnEntityLiving(cow); | |
for (Player player : loc.getWorld().getPlayers()) { | |
EntityPlayer nmsPlayer = ((CraftPlayer) player).getHandle(); | |
nmsPlayer.playerConnection.sendPacket(packedt); | |
PacketPlayOutAttachEntity pa = new PacketPlayOutAttachEntity(0, cow, skull); | |
nmsPlayer.playerConnection.sendPacket(pa); | |
} | |
return Arrays.asList(skull.getId(), cow.getId()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment