Skip to content

Make default values more powerful #500

@Citymonstret

Description

@Citymonstret

In Cloud v1 the default values are stored in the arguments, and the argument builder has the ability to serialize objects into strings. These values are then pushed onto the input queue when parsing.

In Cloud v2 the default values are stored in the command components, instead of the arguments. This means they bypass the argument entirely, and we thus lose the ability to pre-serialize these objects. However, instead of bringing back that functionality, I am instead proposing a new mechanism for default values.

public interface DefaultValue<C, T> {

  @NonNull <T> evaluteDefault(@NonNull CommandContext<C> context);
}

We'd offer three types:

  • constant: DefaultValue.constant(5), DefaultValue.constant(Duration.ofSeconds(5L))
  • dynamic: DefaultValue.dynamic(ctx -> ctx.sender().getLocation())
  • parsed: DefaultValue.parsed("5"), DefaultValue.parsed("@p")

constant/dynamic would bypass the optional argument entirely, whereas parsed would still push the default value onto the input

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions