Java 类net.minecraftforge.fml.common.network.FMLNetworkEvent.ServerCustomPacketEvent 实例源码

项目:Ambidextrous    文件:NetworkRouter.java   
@SubscribeEvent
public void serverPacket(
        final ServerCustomPacketEvent ev )
{
    // find player
    final NetHandlerPlayServer srv = (NetHandlerPlayServer) ev.getPacket().handler();

    try
    {
        if ( serverPacketHandler != null )
        {
            serverPacketHandler.onPacketData( ev.getPacket(), ev.getHandler(), srv.playerEntity );
        }
    }
    catch ( final ThreadQuickExitException ext )
    {
        ;
    }
}
项目:morecommands    文件:PacketDispatcher.java   
/**
 * Invoked when the server receives a packet from the client
 */
@SubscribeEvent
public void onClientPacket(final ServerCustomPacketEvent event) {
    if (!event.getPacket().channel().equals(Reference.CHANNEL)) return;

    ((NetHandlerPlayServer) event.getHandler()).player.getServerWorld().addScheduledTask(new Runnable() {
        @Override
        public void run() {
            try {handleClientPacket(event.getPacket(), ((NetHandlerPlayServer) event.getHandler()).player);}
            catch (Exception ex) {
                ex.printStackTrace(); 
                MoreCommands.INSTANCE.getLogger().warn("Error handling Packet");
            }
        }
    });
}
项目:Factorization    文件:HammerNet.java   
@SubscribeEvent
public void messageFromClient(ServerCustomPacketEvent event) {
    MinecraftServer.getServer().addScheduledTask(new Runnable() {
        @Override
        public void run() {
            EntityPlayerMP player = ((NetHandlerPlayServer) event.handler).playerEntity;
            try {
                handleMessageFromClient(player, event.packet.payload());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    });
}
项目:Factorization    文件:FzNetEventHandler.java   
@SubscribeEvent
public void onPacket(final ServerCustomPacketEvent event) {
    WorldServer world = ((NetHandlerPlayServer) event.handler).playerEntity.getServerForPlayer();
    if (!world.isCallingFromMinecraftThread()) {
        world.addScheduledTask(new Runnable() {
            public void run() {
                handlePacket(event, true, ((NetHandlerPlayServer) event.handler).playerEntity);
            }
        });
    } else {
        handlePacket(event, true, ((NetHandlerPlayServer) event.handler).playerEntity);
    }
}
项目:CustomOreGen    文件:CustomPacketPayloadHandler.java   
@SubscribeEvent
public void serverCustomPayload(ServerCustomPacketEvent event)
{
    EntityPlayerMP player = ((NetHandlerPlayServer)event.getHandler()).playerEntity;
    World handlerWorld = player.world;
    ServerState.checkIfServerChanged(handlerWorld.getMinecraftServer(), handlerWorld.getWorldInfo());
    CustomPacketPayload payload = CustomPacketPayload.decodePacket(event.getPacket());

    if (payload != null)
    {
        switch (payload.type)
        {
            case DebuggingGeometryRequest:
                GeometryData geometryData = null;

                if (player.mcServer.getPlayerList().canSendCommands(player.getGameProfile()));
                {
                    geometryData = ServerState.getDebuggingGeometryData((GeometryRequestData)payload.data);
                }

                if (geometryData == null)
                {
                    (new CustomPacketPayload(PayloadType.DebuggingGeometryRenderMode, "_DISABLE_")).sendToClient(player);
                }
                else
                {
                    (new CustomPacketPayload(PayloadType.DebuggingGeometryData, geometryData)).sendToClient(player);
                }

                break;

            default:
                throw new RuntimeException("Unhandled server packet type " + payload.type);
        }
    }
}