Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import de.bytevalue.gameapi.GameAPI;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.UUID;
- import net.minecraft.server.v1_8_R3.EntityArmorStand;
- import net.minecraft.server.v1_8_R3.PacketPlayOutEntityDestroy;
- import net.minecraft.server.v1_8_R3.PacketPlayOutSpawnEntityLiving;
- import org.bukkit.Bukkit;
- 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.EntityType;
- import org.bukkit.entity.Player;
- public class HologramAPI {
- private static HashMap<UUID, ArrayList> caches = new HashMap<>();
- private final UUID uuid;
- private final Location location;
- private final String[] lore;
- public HologramAPI(UUID uuid, String[] lore, Location location){
- this.uuid = uuid;
- this.lore = lore;
- this.location = location;
- ArrayList<EntityArmorStand> armorStands = new ArrayList<>();
- caches.put(this.uuid, armorStands);
- }
- public void createHologram()
- {
- ArrayList<EntityArmorStand> armorStands = caches.get(this.uuid);
- for(String line : lore)
- {
- EntityArmorStand entity = new EntityArmorStand(((CraftWorld) this.location.getWorld()).getHandle(),this.location.getX(), this.location.getY(),this.location.getZ());
- entity.setCustomNameVisible(true);
- entity.setCustomName(line);
- entity.setInvisible(true);
- entity.setGravity(false);
- this.location.subtract(0, 0.25D, 0);
- armorStands.add(entity);
- }
- caches.replace(this.uuid, armorStands);
- }
- public void showHologram()
- {
- Player player = Bukkit.getPlayer(this.uuid);
- ArrayList<EntityArmorStand> armorStands = caches.get(this.uuid);
- armorStands.forEach((armor ->
- {
- PacketPlayOutSpawnEntityLiving entityLiving = new PacketPlayOutSpawnEntityLiving(armor);
- ((CraftPlayer)player).getHandle().playerConnection.sendPacket(entityLiving);
- }));
- }
- public void hideHologram() {
- Player player = Bukkit.getPlayer(this.uuid);
- ArrayList<EntityArmorStand> armorStands = caches.get(this.uuid);
- armorStands.forEach((armor ->{
- PacketPlayOutEntityDestroy destroy = new PacketPlayOutEntityDestroy(armor.getId());
- ((CraftPlayer)player).getHandle().playerConnection.sendPacket(destroy);
- }));
- armorStands.clear();
- caches.remove(this.uuid);
- }
- public void hideHologram(Integer time) {
- Bukkit.getScheduler().runTaskLaterAsynchronously(GameAPI.getInstance(), () -> {
- this.hideHologram();
- }, time);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement