Advertisement
Guest User

Sending functions

a guest
Oct 1st, 2011
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.71 KB | None | 0 0
  1.     public static boolean send(Location location, Player to) {
  2.         return send(location.getBlockX() >> 4, location.getBlockZ() >> 4, to);
  3.     }
  4.     public static boolean send(int cx, int cz, Player to) {
  5.         try {
  6.             net.minecraft.server.World world = ((CraftWorld) to.getWorld()).getHandle();
  7.             Packet51MapChunk packet = new Packet51MapChunk(cx * 16, 0, cz * 16, 16, 128, 16, world);
  8.             net.minecraft.server.Chunk chunk = world.getChunkAt(cx, cz);
  9.             NetServerHandler handler = ((CraftPlayer) to).getHandle().netServerHandler;
  10.             //Send pre-chunk
  11.             handler.sendPacket(new Packet50PreChunk(cx * 16, cz * 16, true));
  12.             //Send chunk
  13.             handler.sendPacket(packet);
  14.             //Send entities
  15.             for (Object o : chunk.tileEntities.values()) {
  16.                 TileEntity entity = (TileEntity) o;
  17.                 handler.sendPacket(entity.l());
  18.             }
  19.             return true;
  20.         } catch (Exception ex) {}
  21.         return false;
  22.     }
  23.  
  24.     public static boolean safeSend(Location location, Player to) {
  25.         return safeSend(location.getBlockX() >> 4, location.getBlockZ() >> 4, to);
  26.     }
  27.     public static boolean safeSend(int cx, int cz, Player to) {
  28.         if (Bukkit.getServer().getPluginManager().isPluginEnabled("NoLaggChunks")) {
  29.             PlayerChunkLoader.clear(to, cx, cz);
  30.             return true;
  31.         } else {
  32.             return send(cx, cz, to);
  33.         }
  34.     }
  35.    
  36.     public static void safeSendAll(Location location) {
  37.         safeSendAll(location.getBlockX() >> 4, location.getBlockZ() >> 4, location.getWorld());
  38.     }
  39.     public static void safeSendAll(int cx, int cz, World world) {
  40.         if (Bukkit.getServer().getPluginManager().isPluginEnabled("NoLaggChunks")) {
  41.             PlayerChunkLoader.clearAll(world.getChunkAt(cx, cz));
  42.         } else {
  43.             for (Player player : world.getPlayers()) {
  44.                 send(cx, cz, player);
  45.             }
  46.         }
  47.     }
  48.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement