Package com.comphenix.protocol.events

Examples of com.comphenix.protocol.events.PacketEvent


      }
     
      Player sender = getInjector(networkManager, connection).getUpdatedPlayer();
      PacketType type = PacketType.findLegacy(id, Sender.CLIENT);
      PacketContainer container = new PacketContainer(type, packet);
      PacketEvent event = packetReceived(container, sender, readBufferedPackets.get(packet));
     
      if (!event.isCancelled())
        return event.getPacket().getHandle();
      else
        return null; // Cancel
    }
    // Don't change anything
    return packet;
View Full Code Here


      }
     
      Player reciever = getInjector(networkManager, connection).getUpdatedPlayer();
      PacketType type = PacketType.findLegacy(id, Sender.SERVER);
      PacketContainer container = new PacketContainer(type, packet);
      PacketEvent event = packetQueued(container, reciever);

      if (!event.isCancelled())
        return event.getPacket().getHandle();
      else
        return null; // Cancel
    }
    // Don't change anything
    return packet;
View Full Code Here

   * @param packet - the packet that is to be sent.
   * @param receiver - the receiver of this packet.
   * @return The packet event that was used.
   */
  PacketEvent packetQueued(PacketContainer packet, Player receiver) {
    PacketEvent event = PacketEvent.fromServer(this, packet, receiver);
   
    invoker.invokePacketSending(event);
    return event;
  }
View Full Code Here

   * @param sender - the client packet.
   * @return The packet event that was used.
   */
  PacketEvent packetReceived(PacketContainer packet, Player sender, byte[] buffered) {
    NetworkMarker marker = buffered != null ? new LegacyNetworkMarker(ConnectionSide.CLIENT_SIDE, buffered, packet.getType()) : null;
    PacketEvent event = PacketEvent.fromClient(this, packet, marker, sender);
   
    invoker.invokePacketRecieving(event);
    return event;
  }
View Full Code Here

     
      // Intercept all write methods
      channelField.setValue(new ChannelProxy(originalChannel, MinecraftReflection.getPacketClass()) {
        @Override
        protected <T> Callable<T> onMessageScheduled(final Callable<T> callable, FieldAccessor packetAccessor) {
          final PacketEvent event = handleScheduled(callable, packetAccessor);
         
          // Handle cancelled events
          if (event != null && event.isCancelled())
            return null;
         
          return new Callable<T>() {
            @Override
            public T call() throws Exception {
              T result = null;
             
              // This field must only be updated in the pipeline thread
              currentEvent = event;
              result = callable.call();
              currentEvent = null;
              return result;
            }
          };
        }
       
        @Override
        protected Runnable onMessageScheduled(final Runnable runnable, FieldAccessor packetAccessor) {
          final PacketEvent event = handleScheduled(runnable, packetAccessor);
         
          // Handle cancelled events
          if (event != null && event.isCancelled())
            return null;

          return new Runnable() {
            @Override
            public void run() {
              currentEvent = event;
              runnable.run();
              currentEvent = null;
            }
          };
        }
       
        protected PacketEvent handleScheduled(Object instance, FieldAccessor accessor) {
          // Let the filters handle this packet
          Object original = accessor.get(instance);
         
          // See if we've been instructed not to process packets
          if (!scheduleProcessPackets.get()) {
            NetworkMarker marker = getMarker(original);
           
            if (marker != null)  {
              PacketEvent result = new PacketEvent(ChannelInjector.class);
              result.setNetworkMarker(marker);
              return result;
            } else {
              return BYPASSED_PACKET;
            }
          }
          PacketEvent event = processSending(original);

          if (event != null && !event.isCancelled()) {
            Object changed = event.getPacket().getHandle();
           
            // Change packet to be scheduled
            if (original != changed)
              accessor.set(instance, changed);
          };
View Full Code Here

   * @param output - the output byte array.
   * @throws Exception If anything went wrong.
   */
  protected void encode(ChannelHandlerContext ctx, Object packet, ByteBuf output) throws Exception {
    NetworkMarker marker = null;
    PacketEvent event = currentEvent;
   
    try {
      // Skip every kind of non-filtered packet
      if (!scheduleProcessPackets.get()) {
        return;
      }
     
      // This packet has not been seen by the main thread
      if (event == null) {
        Class<?> clazz = packet.getClass();
       
        // Schedule the transmission on the main thread instead
        if (channelListener.hasMainThreadListener(clazz)) {
          // Delay the packet
          scheduleMainThread(packet);
          packet = null;
         
        } else {
          event = processSending(packet);
         
          // Handle the output
          if (event != null) {
            packet = !event.isCancelled() ? event.getPacket().getHandle() : null;
          }
        }
      }
      if (event != null) {
        // Retrieve marker without accidentally constructing it
View Full Code Here

   * @param ctx - current context.
   * @param packet - the packet that has been written.
   * @param promise - a promise.
   */
  protected void finalWrite(ChannelHandlerContext ctx, Object packet, ChannelPromise promise) {
    PacketEvent event = finalEvent;
   
    if (event != null) {
      // Necessary to prevent infinite loops
      finalEvent = null;
      currentEvent = null;
View Full Code Here

       
        if (channelListener.includeBuffer(packetClass)) {
          byteBuffer.resetReaderIndex();
          marker = new NettyNetworkMarker(ConnectionSide.CLIENT_SIDE, getBytes(byteBuffer));
        }
        PacketEvent output = channelListener.onPacketReceiving(this, input, marker);
       
        // Handle packet changes
        if (output != null) {
          if (output.isCancelled()) {
            it.remove();
            continue;
          } else if (output.getPacket().getHandle() != input) {
            it.set(output.getPacket().getHandle());
          }
         
          finishQueue.addLast(output);
        }
      }
View Full Code Here

   * @param ctx - current context.
   * @param msg - the current packet.
   */
  protected void finishRead(ChannelHandlerContext ctx, Object msg) {
    // Assume same order
    PacketEvent event = finishQueue.pollFirst();
   
    if (event != null) {
      NetworkMarker marker = NetworkMarker.getNetworkMarker(event);
     
      if (marker != null) {
View Full Code Here

TOP

Related Classes of com.comphenix.protocol.events.PacketEvent

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.