Giter VIP home page Giter VIP logo

Comments (2)

QuiCM avatar QuiCM commented on August 14, 2024

I've implemented a class-based command system in another project. An example command is as follows:

public class TestCommand : ICommand
{
    public IEnumerable<string> Aliases => new[] { "t2" };

    public string Description => "A test command.";

    public bool Hidden => false;

    public string Name => "test2";

    public IEnumerable<Parameter> Parameters => new[]
    {
        new Parameter("RequiredMultiple", ParameterType.MultiRequired, typeof(int[]), 4),
        new Parameter("Optional", ParameterType.Optional, typeof(string))
    };

    public Response Execute(CommandContext context)
    {
        Console.WriteLine("TEST COMMAND DEFAULT FALLBACK");
        return new Response("TEST COMMAND DEFAULT FALLBACK");
    }

    public Response Execute(CommandContext context, int[] required, string optional = null)
    {
        Console.WriteLine("TEST COMMAND REAL CALLBACK");
        Console.WriteLine($"{string.Join(" ", required)} {optional ?? "null"}");
        return new Response("TEST COMMAND REAL CALLBACK");
    }
}

ICommand requires one Execute(CommandContext context) method to be present. Further execute methods must be manually added to match the parameter types specified in the command's Parameters enumerable.
When the command is run, the handler converts the provided string arguments into the required types for the command.
Eg test 1 2 3 4 test1 would output '1 2 3 4 test1' to the console.
test 1 2 3 4 would output '1 2 3 4 null' to the console.
test a 1 b 2 test would cause an error.

from orion-core.

kevzhao2 avatar kevzhao2 commented on August 14, 2024

Closing this -- we will revisit this in TShock.

from orion-core.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.