001 package cpw.mods.fml.common.network; 002 003 import net.minecraft.server.MinecraftServer; 004 import net.minecraft.src.EntityPlayerMP; 005 import net.minecraft.src.Packet; 006 import net.minecraft.src.Packet250CustomPayload; 007 import cpw.mods.fml.common.FMLCommonHandler; 008 import cpw.mods.fml.common.FMLLog; 009 010 /** 011 * A simple utility class to send packet 250 packets around the place 012 * 013 * @author cpw 014 * 015 */ 016 public class PacketDispatcher 017 { 018 public static Packet250CustomPayload getPacket(String type, byte[] data) 019 { 020 return new Packet250CustomPayload(type, data); 021 } 022 023 public static void sendPacketToServer(Packet packet) 024 { 025 FMLCommonHandler.instance().getSidedDelegate().sendPacket(packet); 026 } 027 028 public static void sendPacketToPlayer(Packet packet, Player player) 029 { 030 if (player instanceof EntityPlayerMP) 031 { 032 ((EntityPlayerMP)player).serverForThisPlayer.sendPacketToPlayer(packet); 033 } 034 } 035 036 public static void sendPacketToAllAround(double X, double Y, double Z, double range, int dimensionId, Packet packet) 037 { 038 MinecraftServer server = FMLCommonHandler.instance().getMinecraftServerInstance(); 039 if (server != null) 040 { 041 server.getConfigurationManager().sendToAllNear(X, Y, Z, range, dimensionId, packet); 042 } 043 else 044 { 045 FMLLog.fine("Attempt to send packet to all around without a server instance available"); 046 } 047 } 048 }