Ejemplo n.º 1
0
  /**
   * Сформировать внешность по данным с хмл.
   *
   * @param appearance внешность, в которую вносить данные.
   * @param vars таблица параметров.
   * @return новая внешность.
   */
  public static <T extends PlayerAppearance> T fromXML(T appearance, VarTable vars) {
    Array<Field> fields =
        ReflectionUtils.getAllFields(appearance.getClass(), Object.class, true, "pool", "objectId");

    try {
      for (Field field : fields) {
        boolean old = field.isAccessible();

        field.setAccessible(true);

        field.setInt(appearance, vars.getInteger(field.getName(), field.getInt(appearance)));

        field.setAccessible(old);
      }
    } catch (IllegalArgumentException | IllegalAccessException e) {
      Loggers.warning(appearance.getClass(), e);
    }

    return appearance;
  }
Ejemplo n.º 2
0
  public static String toXML(PlayerAppearance appearance, String id) {
    StringBuilder builder = new StringBuilder();

    builder.append("<appearance id=\"").append(id).append("\" >\n");

    Array<Field> fields =
        ReflectionUtils.getAllFields(appearance.getClass(), Object.class, true, "pool", "objectId");

    try {
      for (Field field : fields) {
        String name = field.getName();

        boolean old = field.isAccessible();

        field.setAccessible(true);

        String value = String.valueOf(field.get(appearance));

        builder
            .append("	<set name=\"")
            .append(name)
            .append("\" value=\"")
            .append(value)
            .append("\" />")
            .append("\n");

        field.setAccessible(old);
      }
    } catch (IllegalArgumentException | IllegalAccessException e) {
      Loggers.warning(appearance.getClass(), e);
    }

    builder.append("</appearance>");

    return builder.toString();
  }