Advertisement
Guest User

Untitled

a guest
Sep 15th, 2021
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.95 KB | None | 0 0
  1. /**
  2.  * This should be run on a clock and will update the armour stands position
  3.  * @param p
  4.  * @throws Exception
  5.  */
  6. public void executeCycle(Player p) throws Exception
  7. {      
  8.     EntityPlayer ep = ((CraftPlayer) p).getHandle();
  9.     PacketPlayOutEntityTeleport teleportStand = new PacketPlayOutEntityTeleport(instance.getStand());
  10.    
  11.     // 0x08 = has no base plate
  12.     // 0x10 = is a marker type
  13.     byte armourStandMeta = 0x08 | 0x10;
  14.     byte invisibleMeta = 0x20;
  15.    
  16.     // Creates an armour stand that is used for holding the NPC name
  17.     nmsArmourStand.getDataWatcher().set(new DataWatcherObject<>(15,DataWatcherRegistry.a),armourStandMeta);
  18.     nmsArmourStand.getDataWatcher().set(new DataWatcherObject<>(0,DataWatcherRegistry.a),invisibleMeta);
  19.     ep.b.sendPacket(teleportStand);
  20. }
  21.  
  22. /**
  23.  * Set the text on the armour stand
  24.  * @param text
  25.  */
  26. public void setText(String text)
  27. {
  28.     Optional<IChatBaseComponent> name = Optional.of(new ChatMessage(text));
  29.     nmsArmourStand.getDataWatcher().set(new DataWatcherObject<>(2,DataWatcherRegistry.f),name);
  30. }
  31.  
  32. /**
  33.  * Create this armour stand (Send a packet to a player to tell their client it exists)
  34.  * @param p
  35.  */
  36. public void create(Player p)
  37. {
  38.     Location loc = p.getLocation();
  39.     nmsArmourStand = new EntityArmorStand(server,loc.getX(),loc.getY(),loc.getZ());
  40.    
  41.     EntityPlayer ep = ((CraftPlayer) p).getHandle();
  42.     PacketPlayOutSpawnEntityLiving spawnStand = new PacketPlayOutSpawnEntityLiving(nmsArmourStand);
  43.     PacketPlayOutEntityMetadata standMeta = new PacketPlayOutEntityMetadata(nmsArmourStand.getId(),nmsArmourStand.getDataWatcher(),true);
  44.     ep.b.sendPacket(spawnStand);
  45.     ep.b.sendPacket(standMeta);
  46. }
  47.  
  48. /**
  49.  * Destroy this armour stand (Send a packet to a player to tell their client it is gone)
  50.  * @param p
  51.  */
  52. public void destroy(Player p)
  53. {
  54.     EntityPlayer ep = ((CraftPlayer) p).getHandle();
  55.     PacketPlayOutEntityDestroy destroyStand = new PacketPlayOutEntityDestroy(nmsArmourStand.getId());
  56.     ep.b.sendPacket(destroyStand);
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement