Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import org.bukkit.Location;
- import org.bukkit.entity.Player;
- import java.lang.reflect.Constructor;
- import java.util.ArrayList;
- import java.util.List;
- /**
- * Created by Jakeeeee
- * https://bukkit.org/members/jakeeeee.91110457/
- */
- public class Hologram {
- private ArrayList<Object> entites = new ArrayList();
- private List<String> lines = new ArrayList();
- private Location location;
- public Hologram(ArrayList<String> lines, Location location) {
- this.lines = lines;
- this.location = location;
- }
- public void sendHologram(Player... players) {
- try {
- Constructor packetConstructor = Reflection.getNMSClass("PacketPlayOutSpawnEntityLiving")
- .getConstructor(Reflection.getNMSClass("EntityLiving"));
- Object[] packets = new Object[entites.size()];
- int counter = 0;
- for (Object entity : entites) {
- packets[counter] = packetConstructor.newInstance(entity);
- counter++;
- }
- for (Player player : players) {
- for (Object packet : packets)
- Reflection.sendPacket(player, packet);
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- public void hideHologram(Player... players) {
- try {
- Constructor<?> packetConstructor = Reflection.getNMSClass("PacketPlayOutEntityDestroy").getConstructor(int[].class);
- Object[] packets = new Object[entites.size()];
- int counter = 0;
- for (Object entity : entites) {
- Object entityID = entity.getClass().getMethod("getId").invoke(entity);
- packets[counter] = packetConstructor.newInstance(new int[]{(int) entityID});
- counter++;
- }
- for (Player player : players) {
- for (Object packet : packets)
- Reflection.sendPacket(player, packet);
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- public Hologram addLine(String line) {
- lines.add(line);
- return this;
- }
- public Hologram addLine(String line, int index) {
- lines.add(index, line);
- return this;
- }
- public Hologram removeLine(String line) {
- lines.remove(line);
- return this;
- }
- public Hologram removeLine(int index) {
- lines.remove(index);
- return this;
- }
- public Hologram rebuild() {
- entites.clear();
- build();
- return this;
- }
- public Hologram build() {
- try {
- Constructor entity = Reflection.getNMSClass("EntityArmorStand")
- .getConstructor(Reflection.getNMSClass("World"));
- Object world = Reflection.getCraftbukkitClass("CraftWorld").cast(location.getWorld());
- for (String line : lines) {
- Object entityStand = entity.newInstance(world.getClass().getMethod("getHandle").invoke(world));
- entityStand.getClass().getMethod("setCustomName", String.class).invoke(entityStand, line);
- entityStand.getClass().getMethod("setCustomNameVisible", boolean.class).invoke(entityStand, true);
- entityStand.getClass().getMethod("setInvisible", boolean.class).invoke(entityStand, true);
- entityStand.getClass().getMethod("setGravity", boolean.class).invoke(entityStand, false);
- entityStand.getClass().getMethod("setLocation", double.class, double.class, double.class, float.class, float.class)
- .invoke(entityStand, location.getX(), location.getY(), location.getZ(), 0.0F, 0.0F);
- entites.add(entityStand);
- location.subtract(0, 0.25, 0);
- }
- location.add(0, lines.size() * 0.25, 0);
- } catch (Exception e) {
- e.printStackTrace();
- }
- return this;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement