Ejemplo n.º 1
0
  @Override
  public void setItem(Hologram hologram, Object rawitem) {

    if (!(rawitem instanceof EntityItem))
      throw new IllegalStateException("The item has to be a instance of EntityItem!");

    EntityItem item = (EntityItem) rawitem;
    EntityArmorStand as = (EntityArmorStand) hologram.getArmorStand(0);

    if (hologram.hasItem()) {
      EntityItem oldItem = (EntityItem) hologram.getItem();

      for (Player p : hologram.getPlayers()) {
        PacketPlayOutEntityDestroy packet = new PacketPlayOutEntityDestroy(oldItem.getId());
        ((CraftPlayer) p).getHandle().playerConnection.sendPacket(packet);
      }
    }

    for (Player p : hologram.getPlayers()) {
      PlayerConnection playerConnection = ((CraftPlayer) p).getHandle().playerConnection;

      PacketPlayOutSpawnEntity itemPacket = new PacketPlayOutSpawnEntity(item, 2, 0);
      playerConnection.sendPacket(itemPacket);

      PacketPlayOutEntityMetadata itemMetaDataPacket =
          new PacketPlayOutEntityMetadata(item.getId(), item.getDataWatcher(), true);
      playerConnection.sendPacket(itemMetaDataPacket);

      PacketPlayOutAttachEntity attachEntityPacket = new PacketPlayOutAttachEntity(0, item, as);
      playerConnection.sendPacket(attachEntityPacket);
    }
  }
Ejemplo n.º 2
0
  @Override
  public void showPlayer(Hologram hologram, Player player) {

    PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection;

    for (Object as : hologram.getArmorStands()) {
      PacketPlayOutSpawnEntityLiving packet =
          new PacketPlayOutSpawnEntityLiving((EntityArmorStand) as);
      ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
    }

    if (hologram.hasItem()) {

      EntityItem item = (EntityItem) hologram.getItem();
      PacketPlayOutSpawnEntity itemPacket = new PacketPlayOutSpawnEntity(item, 2, 0);
      playerConnection.sendPacket(itemPacket);

      PacketPlayOutEntityMetadata itemMetaDataPacket =
          new PacketPlayOutEntityMetadata(item.getId(), item.getDataWatcher(), true);
      playerConnection.sendPacket(itemMetaDataPacket);

      PacketPlayOutAttachEntity attachEntityPacket =
          new PacketPlayOutAttachEntity(0, item, (EntityArmorStand) hologram.getArmorStand(0));
      playerConnection.sendPacket(attachEntityPacket);
    }
  }
Ejemplo n.º 3
0
  @Override
  public Object addMessage(Hologram hologram, String message) {

    EntityArmorStand lastAs =
        hologram.getArmorStands().size() == 0
            ? null
            : (EntityArmorStand) hologram.getArmorStand(hologram.getArmorStands().size() - 1);
    EntityArmorStand as;

    if (lastAs != null) {
      as = new EntityArmorStand(lastAs.world);
      as.setInvisible(true);
      as.setCustomName(message);
      as.setCustomNameVisible(true);
      as.setSmall(true);
      as.setGravity(false);
      as.setLocation(
          lastAs.locX, lastAs.locY - hologram.getDistance(), lastAs.locZ, lastAs.yaw, lastAs.pitch);

    } else {
      Location loc = hologram.getLocation();

      as = new EntityArmorStand(((CraftWorld) loc.getWorld()).getHandle());
      as.setInvisible(true);
      as.setCustomName(message);
      as.setCustomNameVisible(true);
      as.setSmall(true);
      as.setGravity(false);
      as.setLocation(loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch());
    }

    for (Player p : hologram.getPlayers()) {
      PacketPlayOutSpawnEntityLiving packet = new PacketPlayOutSpawnEntityLiving(as);
      ((CraftPlayer) p).getHandle().playerConnection.sendPacket(packet);
    }

    return as;
  }