Advertisement
Guest User

Untitled

a guest
Jun 19th, 2014
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.44 KB | None | 0 0
  1.     /**
  2.     * Play the sleep animation for every nearby player.
  3.     * @param alseep - the player asleep.
  4.     */
  5.     private void playSleepAnimation(Player asleep) {
  6.         final PacketContainer bedPacket = plugin.manager.createPacket(PacketType.Play.Server.BED, false);
  7.         final Location loc = asleep.getLocation();
  8.  
  9.         // [url]http://wiki.vg/Protocol#Use_Bed[/url]
  10.         bedPacket.getEntityModifier(asleep.getWorld()).write(0, asleep);
  11.         bedPacket.getIntegers().write(1, loc.getBlockX()).write(2, loc.getBlockY() + 1).write(3, loc.getBlockZ());
  12.         broadcastNearby(asleep, bedPacket);
  13.     }
  14.  
  15.     private void stopSleepAnimation(Player sleeping) {
  16.         final PacketContainer animation = plugin.manager.createPacket(PacketType.Play.Server.ANIMATION, false);
  17.  
  18.         // [url]http://wiki.vg/Protocol#Animation[/url]
  19.         animation.getEntityModifier(sleeping.getWorld()).
  20.             write(0, sleeping);
  21.         animation.getIntegers().
  22.             write(1, 2);
  23.  
  24.         broadcastNearby(sleeping, animation);
  25.     }
  26.  
  27.     private void broadcastNearby(Player asleep, PacketContainer bedPacket) {
  28.         for (Player observer : plugin.manager.getEntityTrackers(asleep)) {
  29.             try {
  30.                 plugin.manager.sendServerPacket(observer, bedPacket);
  31.             } catch (InvocationTargetException e) {
  32.                 throw new RuntimeException("Cannot send packet.", e);
  33.             }
  34.         }
  35.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement