Package com.comphenix.protocol.injector.PacketConstructor

Examples of com.comphenix.protocol.injector.PacketConstructor.Unwrapper


      return handleCollection((Collection<Object>) wrappedObject);
    } else if (Primitives.isWrapperType(currentClass) || wrappedObject instanceof String) {
      return null;
    }
   
    Unwrapper specificUnwrapper = getSpecificUnwrapper(currentClass);
   
    // Retrieve the handle
    if (specificUnwrapper != null)
      return specificUnwrapper.unwrapItem(wrappedObject);
    else
      return null;
  }
View Full Code Here


   
    try {
      final Method find = type.getMethod("getHandle");
     
      // It's thread safe, as getMethod should return the same handle
      Unwrapper methodUnwrapper = new Unwrapper() {
        @Override
        public Object unwrapItem(Object wrappedObject) {
          try {
            if (wrappedObject instanceof Class)
              return checkClass((Class<?>) wrappedObject, type, find.getReturnType());
            return find.invoke(wrappedObject);
           
          } catch (IllegalArgumentException e) {
            reporter.reportDetailed(this,
                Report.newBuilder(REPORT_ILLEGAL_ARGUMENT).error(e).callerParam(wrappedObject, find)
            );
          } catch (IllegalAccessException e) {
            // Should not occur either
            return null;
          } catch (InvocationTargetException e) {
            // This is really bad
            throw new RuntimeException("Minecraft error.", e);
          }
         
          return null;
        }
      };
     
      unwrapperCache.put(type, methodUnwrapper);
      return methodUnwrapper;
     
    } catch (SecurityException e) {
      reporter.reportDetailed(this,
          Report.newBuilder(REPORT_SECURITY_LIMITATION).error(e).callerParam(type)
      );
    } catch (NoSuchMethodException e) {
      // Try getting the field unwrapper too
      Unwrapper fieldUnwrapper = getFieldUnwrapper(type);
     
      if (fieldUnwrapper != null)
        return fieldUnwrapper;
      else
        reporter.reportDetailed(this,
View Full Code Here

  private Unwrapper getFieldUnwrapper(final Class<?> type) {
    final Field find = FieldUtils.getField(type, "handle", true);
   
    // See if we succeeded
    if (find != null) {
      Unwrapper fieldUnwrapper = new Unwrapper() {
        @Override
        public Object unwrapItem(Object wrappedObject) {
          try {
            if (wrappedObject instanceof Class)
              return checkClass((Class<?>) wrappedObject, type, find.getType());
View Full Code Here

   * @param nativeType - the native NMS type the converter produces.
   * @param converter - the converter.
   * @return The equivalent unwrapper.
   */
  public static Unwrapper asUnwrapper(final Class<?> nativeType, final EquivalentConverter<Object> converter) {
    return new Unwrapper() {
      @SuppressWarnings("rawtypes")
      @Override
      public Object unwrapItem(Object wrappedObject) {
        Class<?> type = PacketConstructor.getClass(wrappedObject);
       
View Full Code Here

TOP

Related Classes of com.comphenix.protocol.injector.PacketConstructor.Unwrapper

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.