117 lines
3.8 KiB
Java
117 lines
3.8 KiB
Java
/*
|
|
* Copyright (c) 2017 univento.eu - All rights reserved
|
|
* You are not allowed to use, distribute or modify this code
|
|
*/
|
|
|
|
package eu.univento.core.api;
|
|
|
|
import eu.univento.core.Core;
|
|
import eu.univento.core.api.player.CustomPlayer;
|
|
import net.minecraft.server.v1_12_R1.EntityArmorStand;
|
|
import net.minecraft.server.v1_12_R1.EnumHand;
|
|
import net.minecraft.server.v1_12_R1.PacketPlayOutEntityDestroy;
|
|
import net.minecraft.server.v1_12_R1.PacketPlayOutSpawnEntityLiving;
|
|
import org.bukkit.Bukkit;
|
|
import org.bukkit.Location;
|
|
import org.bukkit.craftbukkit.v1_12_R1.CraftWorld;
|
|
import org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack;
|
|
import org.bukkit.inventory.ItemStack;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
@Deprecated
|
|
|
|
public class Hologram {
|
|
|
|
private final List<EntityArmorStand> entitylist = new ArrayList<>();
|
|
private final ItemStack item;
|
|
private final String[] text;
|
|
private final Location location;
|
|
private int count;
|
|
|
|
public Hologram(ItemStack item, String[] text, Location location) {
|
|
this.item = item;
|
|
this.text = text;
|
|
this.location = location;
|
|
create();
|
|
}
|
|
|
|
|
|
public void showPlayerTemp(final CustomPlayer p, int time){
|
|
showPlayer(p);
|
|
Bukkit.getScheduler().runTaskLater(Core.getInstance(), () -> hidePlayer(p), time);
|
|
}
|
|
|
|
|
|
public void showAllTemp(int time){
|
|
showAll();
|
|
Bukkit.getScheduler().runTaskLater(Core.getInstance(), this::hideAll, time);
|
|
}
|
|
|
|
public void showPlayer(CustomPlayer p) {
|
|
for (EntityArmorStand armor : entitylist) {
|
|
PacketPlayOutSpawnEntityLiving packet = new PacketPlayOutSpawnEntityLiving(armor);
|
|
p.sendPacket(packet);
|
|
}
|
|
}
|
|
|
|
public void hidePlayer(CustomPlayer p) {
|
|
for (EntityArmorStand armor : entitylist) {
|
|
PacketPlayOutEntityDestroy packet = new PacketPlayOutEntityDestroy(armor.getId());
|
|
p.sendPacket(packet);
|
|
|
|
}
|
|
}
|
|
|
|
public void showAll() {
|
|
for (CustomPlayer player : Core.getOnlinePlayers()) {
|
|
for (EntityArmorStand armor : entitylist) {
|
|
PacketPlayOutSpawnEntityLiving packet = new PacketPlayOutSpawnEntityLiving(armor);
|
|
player.sendPacket(packet);
|
|
}
|
|
}
|
|
}
|
|
|
|
public void hideAll() {
|
|
for (CustomPlayer player : Core.getOnlinePlayers()) {
|
|
for (EntityArmorStand armor : entitylist) {
|
|
PacketPlayOutEntityDestroy packet = new PacketPlayOutEntityDestroy(armor.getId());
|
|
player.sendPacket(packet);
|
|
}
|
|
}
|
|
}
|
|
|
|
public void destroy() {
|
|
for(EntityArmorStand armorStand : entitylist) {
|
|
armorStand.die();
|
|
}
|
|
}
|
|
|
|
private void create() {
|
|
double DISTANCE = 0.25D;
|
|
EntityArmorStand stand = new EntityArmorStand(((CraftWorld) this.location.getWorld()).getHandle(),this.location.getX(), this.location.getY(),this.location.getZ());
|
|
stand.a(EnumHand.MAIN_HAND, CraftItemStack.asNMSCopy(item));
|
|
stand.setInvisible(true);
|
|
stand.setNoGravity(true);
|
|
entitylist.add(stand);
|
|
this.location.subtract(0, DISTANCE, 0);
|
|
count++;
|
|
for (String text : this.text) {
|
|
EntityArmorStand entity = new EntityArmorStand(((CraftWorld) this.location.getWorld()).getHandle(),this.location.getX(), this.location.getY(),this.location.getZ());
|
|
entity.setCustomName(text);
|
|
entity.setCustomNameVisible(true);
|
|
entity.setInvisible(true);
|
|
entity.setNoGravity(true);
|
|
entitylist.add(entity);
|
|
this.location.subtract(0, DISTANCE, 0);
|
|
count++;
|
|
}
|
|
|
|
for (int i = 0; i < count; i++) {
|
|
this.location.add(0, DISTANCE, 0);
|
|
}
|
|
this.count = 0;
|
|
}
|
|
|
|
} |