Solved How to Update Hologram (no API)

Discussion in 'Spigot Plugin Development' started by Merlin1009, May 12, 2016.

  1. Hi guys,
    First sry for my bad english :)!
    Now to my main problem...
    I recently code this little method:
    Code (Text):
    public static void spawnHologram(Location loc, String text, List<Player> players) {
       
              EntityArmorStand as = new EntityArmorStand(((CraftWorld) loc.getWorld() ).getHandle());
       
              as.setCustomName(text);
              as.setCustomNameVisible(true);
              as.setInvisible(true);
              as.setGravity(false);
              as.setLocation(loc.getX(), loc.getY(), loc.getZ(), 0F, 0F);
              PacketPlayOutSpawnEntityLiving packet = new PacketPlayOutSpawnEntityLiving(as);
       
              for(Player p : players) {
                 ((CraftPlayer) p).getHandle().playerConnection.sendPacket(packet);
                 main.Holograms.put(p, as);
              }
       
        }
    but now i have to update the Hologram but don't know how to do that!
    It would be nice if someone could help me xD

    Edit: The method works fine but i want to change the displayed text after some time
     
    #1 Merlin1009, May 12, 2016
    Last edited: May 12, 2016
  2. Maybe send a destroy packet and then spawn it again... I don't think there's a PacketPlayOutUpdateEntityLiving or?

    P.S. I'm not really good at NMS :D
     
  3. Thank you!! It works! For all who are interested in the code:

    1st Part:

    Code (Text):
    public static PacketPlayOutEntityDestroy destroyEntity(Entity entity) {
            return new PacketPlayOutEntityDestroy(entity.getId());
        }
    2nd Part:

    Code (Text):
    public static void spawnHologram(Location loc, String text, List<Player> players) {
           
              EntityArmorStand as = new EntityArmorStand(((CraftWorld) loc.getWorld() ).getHandle());
           
              as.setCustomName(text);
              as.setCustomNameVisible(true);
              as.setInvisible(true);
              as.setGravity(false);
              as.setLocation(loc.getX(), loc.getY(), loc.getZ(), 0F, 0F);
              PacketPlayOutSpawnEntityLiving packet = new PacketPlayOutSpawnEntityLiving(as);
           
              for(Player p : players) {
                  if(main.Holograms.containsKey(p)){
                            PacketPlayOutEntityDestroy packet2 = destroyEntity(main.Holograms.get(p));
                            ((CraftPlayer) p).getHandle().playerConnection.sendPacket(packet2);
                  }
                 ((CraftPlayer) p).getHandle().playerConnection.sendPacket(packet);
                 main.Holograms.put(p, as);
              }
           
        }
    So its SOLVED!
     
    • Like Like x 1