Class UpgradeParsers

java.lang.Object
de.Keyle.MyPet.api.skill.UpgradeParsers

public final class UpgradeParsers extends Object
Helpers for UpgradeParser implementations. Each parseXxx method takes a JsonElement from an upgrade JSON node and returns the corresponding modifier, or null if the element is absent or has the wrong shape.
  • Method Details

    • get

      public static JsonElement get(JsonObject o, String key)
      Looks up a key in a JSON object, ignoring case. Returns null if the object is null or no key matches.
      Parameters:
      o - the JSON object to read
      key - the key to look for
      Returns:
      the value, or null when the key is absent
    • parseNumber

      public static UpgradeNumberModifier parseNumber(JsonElement modifier)
      Parses a JSON string element into a numeric upgrade modifier. Expects a string prefixed with "+" (add) or "-" (subtract) followed by a decimal number (e.g. "+5", "-2.5").
      Parameters:
      modifier - the JSON element to parse
      Returns:
      the modifier, or null if the element is not a prefixed numeric string
    • parseInteger

      public static UpgradeIntegerModifier parseInteger(JsonElement modifier)
      Parses a JSON string element into an integer upgrade modifier. Same format as parseNumber(JsonElement) but truncates the parsed value to an int.
      Parameters:
      modifier - the JSON element to parse
      Returns:
      the modifier, or null if the element is not a prefixed numeric string
    • parseBoolean

      public static UpgradeBooleanModifier parseBoolean(JsonElement modifier)
      Parses a JSON boolean primitive into a boolean upgrade modifier.
      Parameters:
      modifier - the JSON element to parse
      Returns:
      UpgradeBooleanModifier.True or UpgradeBooleanModifier.False, or null if the element is not a boolean primitive
    • parseEnum

      public static <T extends Enum<T>> UpgradeEnumModifier<T> parseEnum(JsonElement modifier, Class<T> enumClass)
      Parses a JSON string into an enum upgrade modifier by matching the string (case-insensitive) against the constants of the given enum class.
      Type Parameters:
      T - the enum type
      Parameters:
      modifier - the JSON element to parse
      enumClass - the enum type to match against
      Returns:
      the matching modifier, or null if no constant matches or the element is not a string