Java 类net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler 实例源码

项目:Mods    文件:UdpChannelHandlerClient.java   
@Override
protected void channelRead0(ChannelHandlerContext ctx, DatagramPacket msg) throws Exception {
    ByteBuf buffer = msg.content();

    int seq = buffer.readUnsignedShort();
    int msgid = buffer.readByte();

    IMessage message = TF2weapons.network.messages[msgid].newInstance();
    //buffer.discardReadBytes();
    message.fromBytes(buffer);
    IMessageHandler<IMessage, IMessage> handler = TF2weapons.network.handlerList.get(message.getClass());
    if(constr == null) {
        constr =MessageContext.class.getDeclaredConstructor(INetHandler.class, Side.class);
        constr.setAccessible(true);
    }
    MessageContext context = constr.newInstance(Minecraft.getMinecraft().player.connection, Side.CLIENT); 
    handler.onMessage(message, context);
    System.out.println("PacketFrom: "+msg.sender().getAddress()+ " "+msg.sender().getPort()+" ");

}
项目:Malgra    文件:PacketDispatcher.java   
/**
 * Registers an {@link AbstractMessage} to the appropriate side(s)
 */
private static final <T extends AbstractMessage<T> & IMessageHandler<T, IMessage>> void registerMessage(Class<T> clazz) {
    // We can tell by the message class which side to register it on by using #isAssignableFrom (google it)

    // Also, one can see the convenience of using a static counter 'packetId' to keep
    // track of the current index, rather than hard-coding them all, plus it's one less
    // parameter to pass.
    if (AbstractMessage.AbstractClientMessage.class.isAssignableFrom(clazz)) {
        PacketDispatcher.dispatcher.registerMessage(clazz, clazz, packetId++, Side.CLIENT);
    } else if (AbstractMessage.AbstractServerMessage.class.isAssignableFrom(clazz)) {
        PacketDispatcher.dispatcher.registerMessage(clazz, clazz, packetId++, Side.SERVER);
    } else {
        // hopefully you didn't forget to extend the right class, or you will get registered on both sides
        PacketDispatcher.dispatcher.registerMessage(clazz, clazz, packetId, Side.CLIENT);
        PacketDispatcher.dispatcher.registerMessage(clazz, clazz, packetId++, Side.SERVER);
    }
}
项目:EnderPay    文件:PacketDispatcher.java   
/**
 * Registers an {@link AbstractMessage} to the appropriate side(s)
 */
public static final <T extends AbstractMessage<T> & IMessageHandler<T, IMessage>> void registerMessage(Class<T> clazz) {
    // We can tell by the message class which side to register it on by using #isAssignableFrom (google it)

    // Also, one can see the convenience of using a static counter 'packetId' to keep
    // track of the current index, rather than hard-coding them all, plus it's one less
    // parameter to pass.
    if (AbstractMessage.AbstractClientMessage.class.isAssignableFrom(clazz)) {
        PacketDispatcher.dispatcher.registerMessage(clazz, clazz, packetId++, Side.CLIENT);
    } else if (AbstractMessage.AbstractServerMessage.class.isAssignableFrom(clazz)) {
        PacketDispatcher.dispatcher.registerMessage(clazz, clazz, packetId++, Side.SERVER);
    } else {
        // hopefully you didn't forget to extend the right class, or you will get registered on both sides
        PacketDispatcher.dispatcher.registerMessage(clazz, clazz, packetId, Side.CLIENT);
        PacketDispatcher.dispatcher.registerMessage(clazz, clazz, packetId++, Side.SERVER);
    }
}
项目:VendingBlock    文件:PacketDispatcher.java   
/**
 * Registers an {@link AbstractMessage} to the appropriate side(s)
 */
public static final <T extends AbstractMessage<T> & IMessageHandler<T, IMessage>> void registerMessage(Class<T> clazz) {
    // We can tell by the message class which side to register it on by using #isAssignableFrom (google it)

    // Also, one can see the convenience of using a static counter 'packetId' to keep
    // track of the current index, rather than hard-coding them all, plus it's one less
    // parameter to pass.
    if (AbstractMessage.AbstractClientMessage.class.isAssignableFrom(clazz)) {
        PacketDispatcher.dispatcher.registerMessage(clazz, clazz, packetId++, Side.CLIENT);
    } else if (AbstractMessage.AbstractServerMessage.class.isAssignableFrom(clazz)) {
        PacketDispatcher.dispatcher.registerMessage(clazz, clazz, packetId++, Side.SERVER);
    } else {
        // hopefully you didn't forget to extend the right class, or you will get registered on both sides
        PacketDispatcher.dispatcher.registerMessage(clazz, clazz, packetId, Side.CLIENT);
        PacketDispatcher.dispatcher.registerMessage(clazz, clazz, packetId++, Side.SERVER);
    }
}
项目:Skills    文件:PacketDispatcher.java   
/**
 * Registers an {@link AbstractMessage} to the appropriate side(s)
 */
private static final <T extends AbstractMessage<T> & IMessageHandler<T, IMessage>> void registerMessage(Class<T> clazz) {
    // We can tell by the message class which side to register it on by using #isAssignableFrom (google it)

    // Also, one can see the convenience of using a static counter 'packetId' to keep
    // track of the current index, rather than hard-coding them all, plus it's one less
    // parameter to pass.
    if (AbstractMessage.AbstractClientMessage.class.isAssignableFrom(clazz)) {
        PacketDispatcher.dispatcher.registerMessage(clazz, clazz, packetId++, Side.CLIENT);
    } else if (AbstractMessage.AbstractServerMessage.class.isAssignableFrom(clazz)) {
        PacketDispatcher.dispatcher.registerMessage(clazz, clazz, packetId++, Side.SERVER);
    } else {
        // hopefully you didn't forget to extend the right class, or you will get registered on both sides
        PacketDispatcher.dispatcher.registerMessage(clazz, clazz, packetId, Side.CLIENT);
        PacketDispatcher.dispatcher.registerMessage(clazz, clazz, packetId++, Side.SERVER);
    }
}
项目:AllPI    文件:PacketHelper.java   
public static <REQ extends IMessage, REPLY extends IMessage> void registerPacket(SimpleNetworkWrapper network, Class<REQ> requestMessageType, Class<? extends IMessageHandler<REQ, REPLY>> messageHandler, Side side) {
    String packetPackageName = requestMessageType.getPackage().getName();
    Iterator<String> iterator = packetByteDiscriminators.keySet().iterator();

    byte discriminator = -1;
    while(iterator.hasNext()) {
        String pack = iterator.next();

        if(pack.contains(packetPackageName)) {
            packetByteDiscriminators.get(packetPackageName);
        }
    }

    if(discriminator == -1) {
        packetByteDiscriminators.put(packetPackageName, (byte) 0);
    }

    network.registerMessage(messageHandler, requestMessageType, packetByteDiscriminators.get(packetPackageName), side);
}
项目:minedriod    文件:APacket.java   
public static HandlersInfo getHandlers(Class message) {
    Class[] handlerCandidates = message.getDeclaredClasses();
    Class clientHandler = null, serverHandler = null;

    for (int x = 0; x < handlerCandidates.length; x++) {
        if (IMessageHandler.class.isAssignableFrom(handlerCandidates[x])) {
            if (ClientHandler.class.isAssignableFrom(handlerCandidates[x])) {
                clientHandler = handlerCandidates[x];
            }

            if (ServerHandler.class.isAssignableFrom(handlerCandidates[x])) {
                serverHandler = handlerCandidates[x];
            }

            if (serverHandler != null && clientHandler != null) break;
        }
    }

    HandlersInfo info = new HandlersInfo();
    info.client = clientHandler;
    info.server = serverHandler;

    return info;
}
项目:Waypoints    文件:PacketDispatcher.java   
/**
 * Registers an {@link AbstractMessage} to the appropriate side(s)
 */
public static final <T extends AbstractMessage<T> & IMessageHandler<T, IMessage>> void registerMessage(Class<T> clazz) {
    // We can tell by the message class which side to register it on by using #isAssignableFrom (google it)

    // Also, one can see the convenience of using a static counter 'packetId' to keep
    // track of the current index, rather than hard-coding them all, plus it's one less
    // parameter to pass.
    if (AbstractMessage.AbstractClientMessage.class.isAssignableFrom(clazz)) {
        PacketDispatcher.dispatcher.registerMessage(clazz, clazz, packetId++, Side.CLIENT);
    } else if (AbstractMessage.AbstractServerMessage.class.isAssignableFrom(clazz)) {
        PacketDispatcher.dispatcher.registerMessage(clazz, clazz, packetId++, Side.SERVER);
    } else {
        // hopefully you didn't forget to extend the right class, or you will get registered on both sides
        PacketDispatcher.dispatcher.registerMessage(clazz, clazz, packetId, Side.CLIENT);
        PacketDispatcher.dispatcher.registerMessage(clazz, clazz, packetId++, Side.SERVER);
    }
}
项目:customstuff4    文件:NetworkHelper.java   
public static <T extends IMessage> boolean checkThreadAndEnqueue(final T message, final IMessageHandler<T, IMessage> handler, final MessageContext ctx, IThreadListener listener)
{
    if (!listener.isCallingFromMinecraftThread())
    {
        listener.addScheduledTask(() -> handler.onMessage(message, ctx));
        return true;
    }

    return false;
}
项目:Mods    文件:UdpChannelHandlerServer.java   
@Override
protected void channelRead0(ChannelHandlerContext ctx, DatagramPacket msg) throws Exception {
    ByteBuf buffer = msg.content();

    int plid = buffer.readShort();
    int seq = buffer.readUnsignedShort();
    int msgid = buffer.readByte();

    if(msgid == (byte)-128) {
        server.outboundTargets.put((short) plid, SocketUtils.socketAddress(msg.sender().getAddress().getHostAddress(),msg.sender().getPort()));
    }
    else {
        EntityPlayerMP player = server.playerList.get((short)plid);
        IMessage message = TF2weapons.network.messages[msgid].newInstance();
        //buffer.discardReadBytes();
        message.fromBytes(buffer);
        IMessageHandler<IMessage, IMessage> handler = TF2weapons.network.handlerList.get(message.getClass());
        if(constr == null) {
            constr =MessageContext.class.getDeclaredConstructor(INetHandler.class, Side.class);
            constr.setAccessible(true);
        }
        MessageContext context = constr.newInstance(player.connection, Side.SERVER); 
        handler.onMessage(message, context);
    }
    System.out.println("PacketFrom: "+msg.sender().getAddress()+ " "+msg.sender().getPort()+" ");

}
项目:Mods    文件:TF2NetworkWrapper.java   
public <REQ extends IMessage, REPLY extends IMessage> void registerMessage(Class<? extends IMessageHandler<REQ, REPLY>> messageHandler, Class<REQ> requestMessageType, int discriminator, Side side, boolean useUdp)
  {
      try {
    registerMessage(messageHandler.newInstance(), requestMessageType, discriminator, side, useUdp);
} catch (Exception e) {

}
  }
项目:Mods    文件:TF2NetworkWrapper.java   
public <REQ extends IMessage, REPLY extends IMessage> void registerMessage(IMessageHandler<? super REQ, ? extends REPLY> messageHandler, Class<REQ> requestMessageType, int discriminator, Side side, boolean useUdp)
{
    super.registerMessage(messageHandler, requestMessageType, discriminator, side);
    if(useUdp) {
        handlerList.put(requestMessageType, (IMessageHandler<IMessage, IMessage>) messageHandler);
        messages[discriminator] = requestMessageType;
        discriminators.put(requestMessageType, (byte)discriminator);

    }
}
项目:CommonUtils    文件:ProxyModBase.java   
public <REQ extends IMessage, REPLY extends IMessage> void addNetworkPacket(
        Class<? extends IMessageHandler<REQ, REPLY>> messageHandler, Class<REQ> requestMessageType,
        int discriminator, Side side) {
    if (netChannel == null)
        netChannel = NetworkRegistry.INSTANCE.newSimpleChannel(modId);
    netChannel.registerMessage(messageHandler, requestMessageType, discriminator, side);
}
项目:wolfarmor    文件:PacketHandler.java   
private static <T extends MessageBase<T> & IMessageHandler<T, IMessage>>void registerMessage(Class<T> clazz) {
    if(ClientMessageBase.class.isAssignableFrom(clazz)) {
        CHANNEL.registerMessage(clazz, clazz, ID++, Side.CLIENT);
        return;
    }
    if(ServerMessageBase.class.isAssignableFrom(clazz)) {
        CHANNEL.registerMessage(clazz, clazz, ID++, Side.SERVER);
        return;
    }
    CHANNEL.registerMessage(clazz, clazz, ID, Side.CLIENT);
    CHANNEL.registerMessage(clazz, clazz, ID++, Side.SERVER);
}
项目:geomastery    文件:Geomastery.java   
/** Helper for registering server -> client packets. */
private static <REQ extends IMessage, REPLY extends IMessage> void
        cPacket(Class<? extends IMessageHandler<REQ, REPLY>> handler,
        Class<REQ> packet) {

    NETWORK.registerMessage(handler, packet, packetID++, Side.CLIENT);
}
项目:geomastery    文件:Geomastery.java   
/** Helper for registering client -> server packets. */
private static <REQ extends IMessage, REPLY extends IMessage> void
        sPacket(Class<? extends IMessageHandler<REQ, REPLY>> handler,
        Class<REQ> packet) {

    NETWORK.registerMessage(handler, packet, packetID++, Side.SERVER);
}
项目:Bonfires    文件:PacketDispatcher.java   
private static <T extends AbstractMessage<T> & IMessageHandler<T, IMessage>> void registerMessage (Class<T> clazz) {
    if (AbstractMessage.AbstractClientMessage.class.isAssignableFrom(clazz))
        PacketDispatcher.dispatcher.registerMessage(clazz, clazz, packetId++, Side.CLIENT);
    else if (AbstractMessage.AbstractServerMessage.class.isAssignableFrom(clazz))
        PacketDispatcher.dispatcher.registerMessage(clazz, clazz, packetId++, Side.SERVER);
    else {
        PacketDispatcher.dispatcher.registerMessage(clazz, clazz, packetId, Side.CLIENT);
        PacketDispatcher.dispatcher.registerMessage(clazz, clazz, packetId++, Side.SERVER);
    }
}
项目:Kingdom-Keys-Re-Coded    文件:PacketDispatcher.java   
private static final <T extends AbstractMessage<T> & IMessageHandler<T, IMessage>> void registerMessage (Class<T> clazz) {
    if (AbstractMessage.AbstractClientMessage.class.isAssignableFrom(clazz))
        PacketDispatcher.dispatcher.registerMessage(clazz, clazz, packetId++, Side.CLIENT);
    else if (AbstractMessage.AbstractServerMessage.class.isAssignableFrom(clazz))
        PacketDispatcher.dispatcher.registerMessage(clazz, clazz, packetId++, Side.SERVER);
    else {
        PacketDispatcher.dispatcher.registerMessage(clazz, clazz, packetId, Side.CLIENT);
        PacketDispatcher.dispatcher.registerMessage(clazz, clazz, packetId++, Side.SERVER);
    }
}
项目:MagicaSolaris    文件:MessageDispatcher.java   
public static final <T extends AbstractMessage<T> & IMessageHandler<T, IMessage>> void registerMessage(Class<T> registee){
    if(AbstractMessage.AbstractClientMessage.class.isAssignableFrom(registee)){
        MessageDispatcher.INSTANCE.registerMessage(registee, registee, packetid++, Side.CLIENT);
    }else if (AbstractMessage.AbstractServerMessage.class.isAssignableFrom(registee)){
        MessageDispatcher.INSTANCE.registerMessage(registee,registee,packetid++,Side.SERVER);
    }else{
        MessageDispatcher.INSTANCE.registerMessage(registee,registee,packetid++,Side.CLIENT);
        MessageDispatcher.INSTANCE.registerMessage(registee,registee,packetid++,Side.SERVER);

    }
}
项目:AbyssalCraft    文件:PacketDispatcher.java   
/**
 * Registers an {@link AbstractMessage} to the appropriate side(s)
 */
private static final <T extends AbstractMessage<T> & IMessageHandler<T, IMessage>> void registerMessage(Class<T> clazz) {
    // We can tell by the message class which side to register it on by using #isAssignableFrom (google it)

    if (AbstractMessage.AbstractClientMessage.class.isAssignableFrom(clazz))
        PacketDispatcher.dispatcher.registerMessage(clazz, clazz, packetId++, Side.CLIENT);
    else if (AbstractMessage.AbstractServerMessage.class.isAssignableFrom(clazz))
        PacketDispatcher.dispatcher.registerMessage(clazz, clazz, packetId++, Side.SERVER);
    else {
        PacketDispatcher.dispatcher.registerMessage(clazz, clazz, packetId, Side.CLIENT);
        PacketDispatcher.dispatcher.registerMessage(clazz, clazz, packetId++, Side.SERVER);
    }
}
项目:ZeldaSwordSkills    文件:PacketDispatcher.java   
/**
 * Registers an {@link AbstractMessage} to the appropriate side(s)
 */
private static final <T extends AbstractMessage<T> & IMessageHandler<T, IMessage>> void registerMessage(Class<T> clazz) {
    if (AbstractMessage.AbstractClientMessage.class.isAssignableFrom(clazz)) {
        PacketDispatcher.dispatcher.registerMessage(clazz, clazz, packetId++, Side.CLIENT);
    } else if (AbstractMessage.AbstractServerMessage.class.isAssignableFrom(clazz)) {
        PacketDispatcher.dispatcher.registerMessage(clazz, clazz, packetId++, Side.SERVER);
    } else {
        PacketDispatcher.dispatcher.registerMessage(clazz, clazz, packetId, Side.CLIENT);
        PacketDispatcher.dispatcher.registerMessage(clazz, clazz, packetId++, Side.SERVER);
    }
}
项目:rezolve    文件:RezolvePacketHandler.java   
public static <REQ extends IMessage, REPLY extends IMessage> 
void registerMessage(Class<? extends IMessageHandler<REQ, REPLY>> handler, Class<REQ> message, Side side) {
    RezolvePacketHandler.INSTANCE.registerMessage(handler, message, nextPacketID++, side);
}
项目:MineCamera    文件:NetworkLoader.java   
private static <REQ extends IMessage, REPLY extends IMessage> void registerMessage(
        Class<? extends IMessageHandler<REQ, REPLY>> messageHandler, Class<REQ> requestMessageType, Side side) {
    instance.registerMessage(messageHandler, requestMessageType, nextID++, side);
}
项目:Solar    文件:PacketHandler.java   
private static <H extends IMessageHandler<M, IMessage>, M extends IMessage> void register(Class<H> handler, Class<M> message, Side side) {
    NETWORK.registerMessage(handler, message, id++, side);
}
项目:metamorph    文件:Dispatcher.java   
private static <REQ extends IMessage, REPLY extends IMessage> void register(Class<REQ> message, Class<? extends IMessageHandler<REQ, REPLY>> handler, Side side)
{
    DISPATCHER.registerMessage(handler, message, PACKET_ID++, side);
}
项目:AquaRegia    文件:ModMessages.java   
private static <REQ extends IMessage, REPLY extends IMessage> void registerMessage(Class<? extends IMessageHandler<REQ, REPLY>> messageHandler, Class<REQ> requestMessageType, Side receivingSide) {
    AquaRegia.network.registerMessage(messageHandler, requestMessageType, messageID++, receivingSide);
}
项目:blockbuster    文件:Dispatcher.java   
/**
 * Register given message with given message handler on a given side
 */
public static <REQ extends IMessage, REPLY extends IMessage> void register(Class<REQ> message, Class<? extends IMessageHandler<REQ, REPLY>> handler, Side side)
{
    DISPATCHER.registerMessage(handler, message, PACKET_ID++, side);
}
项目:Toms-Mod    文件:NetworkHandler.java   
private static <REQ extends IMessage, REPLY extends IMessage> void register(Class<? extends IMessageHandler<REQ, REPLY>> messageHandler, Class<REQ> requestMessageType, Side side, int id) {
    CoreInit.log.info("Registering Message {} with id {}", messageHandler.getName(), id);
    INSTANCE.registerMessage(messageHandler, requestMessageType, id, side);
}
项目:Alchemy    文件:AlchemyNetworkHandler.java   
private static <T extends IMessage & IMessageHandler<T, IMessage>> void registerMessage(Class<T> clazz, Side side) {
    network_wrapper.registerMessage(clazz, clazz, next(), side);
    AlchemyInitHook.push_event(clazz);
}
项目:Alchemy    文件:AlchemyNetworkHandler.java   
public static <T extends IMessage & IMessageHandler<T, IMessage>> void registerMessage(INetworkMessage.Client<T> handle) {
    network_wrapper.registerMessage(Tool.instance(handle.getClientMessageClass()), handle.getClientMessageClass(), next(), Side.CLIENT);
}
项目:Alchemy    文件:AlchemyNetworkHandler.java   
public static <T extends IMessage & IMessageHandler<T, IMessage>> void registerMessage(INetworkMessage.Server<T> handle) {
    network_wrapper.registerMessage(Tool.instance(handle.getServerMessageClass()), handle.getServerMessageClass(), next(), Side.SERVER);
}
项目:Alchemy    文件:AlchemyNetworkHandler.java   
public static <T extends IMessage & IMessageHandler<T, IMessage>> void init() {
    AlchemyModLoader.checkInvokePermissions();
    AlchemyModLoader.checkState();
    for (Entry<Class<?>, Side> entry : message_mapping.entrySet())
        registerMessage((Class<T>) entry.getKey(), entry.getValue());
}
项目:BlockSystems    文件:BlockSystems.java   
private static <T extends BaseMessage<T> & IMessageHandler<T, IMessage>> void registerMessage(Class<T> message, Side... sides) {
    for (Side side : sides) {
        NETWORK_WRAPPER.registerMessage(message, message, messageID++, side);
    }
}
项目:TaleCraft    文件:TaleCraftNetwork.java   
private static <REQ extends IMessage, REPLY extends IMessage> void register(Class<? extends IMessageHandler<REQ, REPLY>> handler, Class<REQ> packet, Side side){
    network.registerMessage(handler, packet, discriminator, side);
    discriminator++;
}
项目:ClockworkPhase2    文件:PacketHandler.java   
private static <REQ extends IMessage, REPLY extends IMessage> void registerMessage(Class<? extends IMessageHandler<REQ, REPLY>> messageHandler, Class<REQ> requestMessageType, Side side) {
    INSTANCE.registerMessage(messageHandler, requestMessageType, messageID++, side);
}
项目:HCoreLib    文件:PacketHandler.java   
private static <REQ extends IMessage, REPLY extends IMessage> void registerMessageHandler(
        Class<? extends IMessageHandler<REQ, REPLY>> messageHandler, Class<REQ> requestMessageType, int discriminator, Side side) {

    NETWORK_WRAPPER.registerMessage(messageHandler, requestMessageType, discriminator, side);
}
项目:Recall-Stones    文件:NetworkHandler.java   
public static <REQ extends IMessage> void registerMessageHandler(IMessageHandler<? super REQ, ? extends IMessage> messageHandler, Class<REQ> requestMessageType, Side side) {
    CHANNEL.registerMessage(messageHandler, requestMessageType, discriminationByte++, side);
}
项目:Recall-Stones    文件:NetworkHandler.java   
public static <REQ extends IMessage, REPLY extends IMessage> void registerMessageHandler(
        Class<? extends IMessageHandler<REQ, REPLY>> messageHandler, Class<REQ> requestMessageType, Side side) {
    CHANNEL.registerMessage(messageHandler, requestMessageType, discriminationByte++, side);
}
项目:ProgressiveAutomation    文件:NetworkHandler.java   
public static <REQ extends IMessage> void registerMessageHandler(IMessageHandler<? super REQ, ? extends IMessage> messageHandler, Class<REQ> requestMessageType, Side side) {
    CHANNEL.registerMessage(messageHandler, requestMessageType, discriminationByte++, side);
}
项目:ProgressiveAutomation    文件:NetworkHandler.java   
public static <REQ extends IMessage, REPLY extends IMessage> void registerMessageHandler(
        Class<? extends IMessageHandler<REQ, REPLY>> messageHandler, Class<REQ> requestMessageType, Side side) {
    CHANNEL.registerMessage(messageHandler, requestMessageType, discriminationByte++, side);
}