Class FlagContext

java.lang.Object
cloud.commandframework.arguments.flags.FlagContext

@API(status=STABLE) public final class FlagContext extends Object
Flag value mappings
  • Field Details

    • FLAG_PRESENCE_VALUE

      public static final Object FLAG_PRESENCE_VALUE
      Dummy object stored as a flag value when the flag has no associated parser
  • Method Details

    • create

      public static @NonNull FlagContext create()
      Create a new flag context instance
      Returns:
      Constructed instance
    • addPresenceFlag

      public void addPresenceFlag(@NonNull CommandFlag<?> flag)
      Indicate that a presence flag was supplied
      Parameters:
      flag - Flag instance
    • addValueFlag

      public <T> void addValueFlag(@NonNull CommandFlag<T> flag, @NonNull T value)
      Store a value associated with a value flag
      Type Parameters:
      T - Value type
      Parameters:
      flag - Value flag
      value - Flag value
    • count

      @API(status=STABLE, since="1.7.0") public <T> int count(@NonNull CommandFlag<T> flag)
      Returns the number of values associated with the given flag.
      Type Parameters:
      T - the flag value type
      Parameters:
      flag - the flag
      Returns:
      the number of values associated with the flag
      Since:
      1.7.0
    • count

      @API(status=STABLE, since="1.7.0") public int count(@NonNull String flag)
      Returns the number of values associated with the given flag.
      Parameters:
      flag - the flag
      Returns:
      the number of values associated with the flag
      Since:
      1.7.0
    • isPresent

      public boolean isPresent(@NonNull String flag)
      Check whether a presence flag is present. This will return false for all value flags.
      Parameters:
      flag - Flag name
      Returns:
      true if the flag is a presence flag and is present, else false
    • isPresent

      @API(status=STABLE, since="1.4.0") public boolean isPresent(@NonNull CommandFlag<Void> flag)
      Check whether a presence flag is present. This will return false for all value flags.
      Parameters:
      flag - A presence flag instance
      Returns:
      true if the flag is a presence flag and is present, else false
      Since:
      1.4.0
    • getValue

      @API(status=STABLE, since="1.2.0") public <T> @NonNull Optional<T> getValue(@NonNull String name)
      Returns a flag value.

      If using CommandFlag.FlagMode.SINGLE then this returns the only value, if it has been specified. If using CommandFlag.FlagMode.REPEATABLE then it'll return the first value.

      Type Parameters:
      T - Value type
      Parameters:
      name - Flag name
      Returns:
      Optional containing stored value if present
      Since:
      1.2.0
    • getValue

      @API(status=STABLE, since="1.4.0") public <T> @NonNull Optional<T> getValue(@NonNull CommandFlag<T> flag)
      Returns a flag value.

      If using CommandFlag.FlagMode.SINGLE then this returns the only value, if it has been specified. If using CommandFlag.FlagMode.REPEATABLE then it'll return the first value.

      Type Parameters:
      T - Value type
      Parameters:
      flag - Flag type
      Returns:
      Optional containing stored value if present
      Since:
      1.4.0
    • getValue

      public <T> @Nullable T getValue(@NonNull String name, @Nullable T defaultValue)
      Returns a flag value.

      If using CommandFlag.FlagMode.SINGLE then this returns the only value, if it has been specified. If using CommandFlag.FlagMode.REPEATABLE then it'll return the first value.

      Type Parameters:
      T - Value type
      Parameters:
      name - Flag name
      defaultValue - Default value
      Returns:
      Stored value, or the supplied default value
    • getValue

      @API(status=STABLE, since="1.4.0") public <T> @Nullable T getValue(@NonNull CommandFlag<T> name, @Nullable T defaultValue)
      Returns a flag value.

      If using CommandFlag.FlagMode.SINGLE then this returns the only value, if it has been specified. If using CommandFlag.FlagMode.REPEATABLE then it'll return the first value.

      Type Parameters:
      T - Value type
      Parameters:
      name - Flag value
      defaultValue - Default value
      Returns:
      Stored value, or the supplied default value
      Since:
      1.4.0
    • hasFlag

      @API(status=STABLE, since="1.2.0") public boolean hasFlag(@NonNull String name)
      Check whether a flag is present. This will return true if the flag is a presence flag and is present, or if the flag is a value flag and has a value provided.
      Parameters:
      name - Flag name
      Returns:
      whether the flag is present
      Since:
      1.2.0
    • hasFlag

      @API(status=STABLE, since="1.4.0") public boolean hasFlag(@NonNull CommandFlag<?> flag)
      Check whether a flag is present. This will return true if the flag is a presence flag and is present, or if the flag is a value flag and has a value provided.
      Parameters:
      flag - The flag instance
      Returns:
      whether the flag is present
      Since:
      1.4.0
    • contains

      @API(status=STABLE, since="1.3.0") public boolean contains(@NonNull String name)
      Check whether a flag is present. This will return true if the flag is a presence flag and is present, or if the flag is a value flag and has a value provided.
      Parameters:
      name - Flag name
      Returns:
      whether the flag is present
      Since:
      1.3.0
    • contains

      @API(status=STABLE, since="1.4.0") public boolean contains(@NonNull CommandFlag<?> flag)
      Check whether a flag is present. This will return true if the flag is a presence flag and is present, or if the flag is a value flag and has a value provided.
      Parameters:
      flag - Flag instance
      Returns:
      whether the flag is present
      Since:
      1.4.0
    • get

      @API(status=STABLE, since="1.3.0") public <T> @Nullable T get(@NonNull String name)
      Returns a flag value.

      If using CommandFlag.FlagMode.SINGLE then this returns the only value, if it has been specified. If using CommandFlag.FlagMode.REPEATABLE then it'll return the first value.

      Type Parameters:
      T - Value type
      Parameters:
      name - Flag name
      Returns:
      Stored value if present, else null
      Since:
      1.3.0
    • get

      @API(status=STABLE, since="1.4.0") public <T> @Nullable T get(@NonNull CommandFlag<T> flag)
      Returns a flag value.

      If using CommandFlag.FlagMode.SINGLE then this returns the only value, if it has been specified. If using CommandFlag.FlagMode.REPEATABLE then it'll return the first value.

      Type Parameters:
      T - Value type
      Parameters:
      flag - Flag name
      Returns:
      Stored value if present, else null
      Since:
      1.4.0
    • getAll

      @API(status=STABLE, since="1.7.0") public <T> @NonNull Collection<T> getAll(@NonNull CommandFlag<T> flag)
      Returns all supplied flag values for the given flag.
      Type Parameters:
      T - the flag value type
      Parameters:
      flag - the flag
      Returns:
      unmodifiable view of all stored flag values, or Collections.emptyList().
      Since:
      1.7.0
    • getAll

      @API(status=STABLE, since="1.7.0") public <T> @NonNull Collection<T> getAll(@NonNull String flag)
      Returns all supplied flag values for the given flag.
      Type Parameters:
      T - the flag value type
      Parameters:
      flag - the flag
      Returns:
      unmodifiable view of all stored flag values, or Collections.emptyList().
      Since:
      1.7.0