Package com.comphenix.protocol.injector

Examples of com.comphenix.protocol.injector.ListenerInvoker


   * @param source - packet to invert.
   * @return The inverted packet.
   */
  @SuppressWarnings("deprecation")
  Object createNegativePacket(Object source) {
    ListenerInvoker invoker = injector.getInvoker();
   
    PacketType type = invoker.getPacketType(source);

    // We want to subtract the byte amount that were added to the running
    // total of outstanding packets. Otherwise, cancelling too many packets
    // might cause a "disconnect.overflow" error.
    //
    // We do that by constructing a special packet of the same type that returns
    // a negative integer for all zero-parameter integer methods. This includes the
    // size() method, which is used by the queue method to count the number of
    // bytes to add.
    //
    // Essentially, we have:
    //
    //   public class NegativePacket extends [a packet] {
    //      @Override
    //      public int size() {
    //         return -super.size();
    //      }
    //   ect.
    //   }
    Enhancer ex = EnhancerFactory.getInstance().createEnhancer();
    ex.setSuperclass(MinecraftReflection.getPacketClass());
    ex.setInterfaces(new Class[] { FakePacket.class } );
    ex.setUseCache(true);
    ex.setCallbackType(InvertedIntegerCallback.class);

    Class<?> proxyClass = ex.createClass();
    Enhancer.registerCallbacks(proxyClass, new Callback[] { callback });
   
    try {
      // Temporarily associate the fake packet class
      invoker.registerPacketClass(proxyClass, type.getLegacyId());
      Object proxy = proxyClass.newInstance();
     
      InjectedArrayList.registerDelegate(proxy, source);
      return proxy;
     
    } catch (Exception e) {
      // Don't pollute the throws tree
      throw new RuntimeException("Cannot create fake class.", e);
    } finally {
      // Remove this association
      invoker.unregisterPacketClass(proxyClass);
    }
  }
View Full Code Here

TOP

Related Classes of com.comphenix.protocol.injector.ListenerInvoker

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.