Skip to content

Easy chat-command API #2

Open
Open

Description

@Cheatoid

By using Reflection, it is possible to make certain things easier.
The goal is to make it really easy to add chat-commands for Starfall projects.
V1 code example:

[ChatCommand("test")] // Permission defaults to myself-only.
public static void TestCmd(BasePlayer invoker, string args) {
    Assert(invoker == Owner, "BUGCHECK");
    printf("Test chat command.  args=%s", args);
}

[ChatCommand("hidden", HideChat=true)] // Hides owner's chat
public static void HideTestCmd(BasePlayer invoker, string args) {
    print("Hidden command entered.");
}

[ChatCommand("join", ChatCommandPermission.Anyone)] // Let anyone run this
public static void JoinCmd(BasePlayer invoker, string args) {
    printf("%s has joined the party!", invoker.Name);
}

The above design could be upgraded by implementing a parser and have arguments fully-typed out method.
V2 code example:

[ChatCommand("install")]
public static void InstallCmd(BasePlayer invoker, string name, int num = 5, bool flag = false) {
    printf("Installing...  name=%q num=%i flag=%s", name, num, flag);
}

This version is slightly more complex to make it work, but it would be nicer and more fluent.
To run the command, you'd say:
/install --name "a string here" --flag true
Which should output the following:

Installing... name="a string here" num=5 flag=true

Activity

  1. added
    enhancement
    api-starfall
    realm-serverside
    on Feb 1, 2021
  2. self-assigned this
    on Feb 1, 2021
  3. added this to the v0.1.4 milestone on Feb 2, 2021
  4. modified the milestones: v0.1.4, vNext on Apr 2, 2021
  5. Cheatoid commented on Apr 2, 2021

    @Cheatoid
    ContributorAuthor

    Moved to vNext; This will be added in future version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

api-starfallenhancementrealm-serverside

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions