/**
  * Helper method to Perform Reflection to Get Static Field of Provided Type. Field is assumed
  * Private.
  *
  * @param fieldName
  * @param type
  * @return
  */
 public static <T> T getFieldFromReflection(
     String fieldName, Class<?> containingClass, Class<T> type) {
   try {
     Field desiredField = containingClass.getDeclaredField(fieldName);
     desiredField.setAccessible(true);
     return type.cast(desiredField.get(null));
   } catch (NoSuchFieldException e) {
     JASLog.log()
         .severe(
             "Obfuscation needs to be updated to access the %s %s. Please notify modmaker Immediately.",
             fieldName, type.getSimpleName());
     e.printStackTrace();
   } catch (IllegalArgumentException e) {
     JASLog.log()
         .severe(
             "Obfuscation needs to be updated to access the %s %s. Please notify modmaker Immediately.",
             fieldName, type.getSimpleName());
     e.printStackTrace();
   } catch (IllegalAccessException e) {
     JASLog.log()
         .severe(
             "Obfuscation needs to be updated to access the %s %s. Please notify modmaker Immediately.",
             fieldName, type.getSimpleName());
     e.printStackTrace();
   } catch (SecurityException e) {
     JASLog.log()
         .severe(
             "Obfuscation needs to be updated to access the %s %s. Please notify modmaker Immediately.",
             fieldName, type.getSimpleName());
     e.printStackTrace();
   }
   return null;
 }
 /**
  * Helper method to Perform Reflection to Set non-static Field of Provided Type. Field is assumed
  * Private.
  *
  * @param fieldName
  * @param containingClass Class that contains desired field containerInstance should be castable
  *     to it. Required to get fields from parent classes
  * @param containterInstance Instance of the Object to get the non-static Field
  * @param isPrivate Whether the field is private and requires setAccessible(true)
  * @param type
  * @param value
  * @return
  * @throws NoSuchFieldException
  */
 public static <T> void setCatchableFieldUsingReflection(
     String fieldName,
     Class<?> containingClass,
     Object containterInstance,
     boolean isPrivate,
     T value)
     throws NoSuchFieldException {
   try {
     Field desiredField = containingClass.getDeclaredField(fieldName);
     if (isPrivate) {
       desiredField.setAccessible(true);
     }
     desiredField.set(containterInstance, value);
   } catch (IllegalArgumentException e) {
     JASLog.log()
         .severe(
             "Obfuscation needs to be updated to access the %s. Please notify modmaker Immediately.",
             fieldName);
     e.printStackTrace();
   } catch (IllegalAccessException e) {
     JASLog.log()
         .severe(
             "Obfuscation needs to be updated to access the %s. Please notify modmaker Immediately.",
             fieldName);
     e.printStackTrace();
   } catch (SecurityException e) {
     JASLog.log()
         .severe(
             "Obfuscation needs to be updated to access the %s. Please notify modmaker Immediately.",
             fieldName);
     e.printStackTrace();
   }
 }
Ejemplo n.º 3
0
 // Extract to NBT
 public boolean writenbt(String[] nbtOperations) {
   try {
     NBTTagCompound entityNBT = new NBTTagCompound();
     entity.writeToNBT(entityNBT);
     new NBTWriter(nbtOperations).writeToNBT(entityNBT);
     entity.readFromNBT(entityNBT);
     return true;
   } catch (IllegalFormatException e) {
     JASLog.log().severe("Skipping NBT Write due to %s", e.getMessage());
   } catch (IllegalArgumentException e) {
     JASLog.log().severe("Skipping NBT Write due to %s", e.getMessage());
   }
   return false;
 }
 public static <T> T getFieldFromReflection(
     String fieldName, Class<?> containingClass, Object containterInstance, Class<T> type) {
   try {
     return getCatchableFieldFromReflection(fieldName, containingClass, containterInstance, type);
   } catch (NoSuchFieldException e) {
     JASLog.log()
         .severe(
             "Obfuscation needs to be updated to access the %s %s. Please notify modmaker Immediately.",
             fieldName, type.getSimpleName());
     e.printStackTrace();
   }
   return null;
 }
 @Override
 public boolean parseChainable(
     String parseable, ArrayList<TypeValuePair> parsedChainable, ArrayList<Operand> operandvalue) {
   String[] pieces = parseable.split(",");
   Operand operand = parseOperand(pieces);
   if (pieces.length == 1) {
     parsedChainable.add(new TypeValuePair(key, isInverted(parseable)));
     operandvalue.add(operand);
     return true;
   } else {
     JASLog.log().severe("Error Parsing %s parameter. Invalid Argument Length.", key.key);
     return false;
   }
 }
 public static Object invokeMethod(
     String eclipseName,
     String seargeName,
     Class<?> containingClass,
     Object containterInstance,
     Object... args) {
   try {
     Method method;
     method = getIntanceOfMethod(eclipseName, seargeName, containterInstance);
     if (method == null) {
       throw new NoSuchMethodException();
     }
     method.setAccessible(true);
     return method.invoke(containterInstance, args);
   } catch (NoSuchMethodException e) {
     JASLog.log()
         .severe("Obfuscation needs updating to access method %s. Notify modmaker.", eclipseName);
     e.printStackTrace();
   } catch (SecurityException e) {
     JASLog.log()
         .severe("Obfuscation needs updating to access method %s. Notify modmaker.", eclipseName);
     e.printStackTrace();
   } catch (IllegalAccessException e) {
     JASLog.log()
         .severe("Obfuscation needs updating to access method %s. Notify modmaker.", eclipseName);
     e.printStackTrace();
   } catch (IllegalArgumentException e) {
     JASLog.log()
         .severe("Obfuscation needs updating to access method %s. Notify modmaker.", eclipseName);
     e.printStackTrace();
   } catch (InvocationTargetException e) {
     JASLog.log()
         .severe("Obfuscation needs updating to access method %s. Notify modmaker.", eclipseName);
     e.printStackTrace();
   }
   return null;
 }
  @Override
  public boolean parseChainable(
      String parseable, ArrayList<TypeValuePair> parsedChainable, ArrayList<Operand> operandvalue) {
    String[] pieces = parseable.split(",");
    Operand operand = parseOperand(pieces);

    if (pieces.length == 4) {
      int randInt = ParsingHelper.parseFilteredInteger(pieces[1], 16, "RandomRange " + key.key);
      int randOffset = ParsingHelper.parseFilteredInteger(pieces[2], 16, "RandomOffset " + key.key);
      int maximum = ParsingHelper.parseFilteredInteger(pieces[3], -1, "Maximum " + key.key);
      TypeValuePair typeValue =
          new TypeValuePair(
              key, new Object[] {isInverted(pieces[0]), randInt, randOffset, maximum});
      parsedChainable.add(typeValue);
      operandvalue.add(operand);
      return true;
    } else {
      JASLog.log().severe("Error Parsing %s Parameter. Invalid Argument Length.", key.key);
      return false;
    }
  }