ApacheTech.VintageMods.FluentChatCommands 2.2.0

dotnet add package ApacheTech.VintageMods.FluentChatCommands --version 2.2.0                
NuGet\Install-Package ApacheTech.VintageMods.FluentChatCommands -Version 2.2.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ApacheTech.VintageMods.FluentChatCommands" Version="2.2.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ApacheTech.VintageMods.FluentChatCommands --version 2.2.0                
#r "nuget: ApacheTech.VintageMods.FluentChatCommands, 2.2.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install ApacheTech.VintageMods.FluentChatCommands as a Cake Addin
#addin nuget:?package=ApacheTech.VintageMods.FluentChatCommands&version=2.2.0

// Install ApacheTech.VintageMods.FluentChatCommands as a Cake Tool
#tool nuget:?package=ApacheTech.VintageMods.FluentChatCommands&version=2.2.0                

Fluent Chat Commands

Provides a framework for creating client-side, and server-side chat commands, using a Fluent Builder pattern. Supports lazy loading of chat commands, where they can be registered early, and configured at any stage.

The main idea is to simplify the process of writing complex commands, as well as separating the construction, business logic, and registration of chat commands.

The syntax string for the command is set automatically, by the sub-commands that are added. A command with no default handler, and no sub-commands, returns its help message to the user.

Support the Developer

If you find this dev tool useful, and you would like to show appreciation for the work I produce; please consider supporting me, and my work, using one of the methods below. Every single expression of support is most appreciated, and makes it easier to produce updates, and new features for my mods, and dev tools, moving fowards. Thank you.

Pre-requisites

This package assumes that you have Vintage Story installed on the computer, and that you have set the following environment variables, as per the Vintage Story Modding Best Practices.

  • %VINTAGE_STORY%: The installation directory for Vintage Story. The location of Vintagestory.exe. By default this is %APPDATA%\Vintagestory.

  • %VINTAGE_STORY_DATA%: The data directory for Vintage Story. By default this is %APPDATA%\VintagestoryData. However, you can check by opening the game, going to the Mod Manager, selecting Open Mods Folder, and going to the parent folder.

You can also do this through the Windows Control Panel, following these steps:

  • Windows 10 and Windows 8

    1. In Search, search for and then select: System (Control Panel)
    2. Click the Advanced system settings link.
    3. Click Environment Variables. In the section System Variables (for All Users), or User Variables (for just the Current User), find the PATH environment variable and select it. Click Edit. If the PATH environment variable does not exist, click New.
    4. In the Edit System Variable (or New System Variable) window, specify the value of the PATH environment variable. Click OK. Close all remaining windows by clicking OK.
  • Windows 7

    1. From the desktop, right click the Computer icon.
    2. Choose Properties from the context menu.
    3. Click the Advanced system settings link.
    4. Click Environment Variables. In the section System Variables (for All Users), or User Variables (for just the Current User), find the PATH environment variable and select it. Click Edit. If the PATH environment variable does not exist, click New.
    5. In the Edit System Variable (or New System Variable) window, specify the value of the PATH environment variable. Click OK. Close all remaining windows by clicking OK.

Further details and troubleshooting can be found here.

Code Examples

There are lots of ways you can use FluentChat, to your own liking. Here is just a small selection of ideas to help you get started.

Basic Example

In this example, we're setting a command called .test, with a basic default command handler.

    internal class MyMod : ModSystem
    {
        // ...
        
        public override void StartClientSide(ICoreClientAPI capi)
        {
            FluentChat.RegisterCommand("test", capi)
                .WithDescription("This is a test command.")
                .WithHandler((_,_,_) => capi.ShowChatMessage("Hello, World!"));
        }
        
        // ...
    }

Basic Example with Sub-Commands

In this example, we're setting a command called .test, with a basic default command handler, but also setting separate sub-commands for .test stuff and .test things. The only difference between the sub-commands is that one uses a lambda expression for its handler, and the other separates it's logic into a named method.

    internal class MyMod : ModSystem
    {
        // ...
        
        private ICoreClientAPI _capi;
        
        public override void StartClientSide(ICoreClientAPI capi)
        {
            capi.RegisterFluentCommand("test")
                .WithDescription("This is a test command.")
                .WithHandler((_,_,_) => capi.ShowChatMessage("Hello, World!"))
                .HasSubCommand("stuff" x => x.WithHandler(StuffHandler).Build())                
                .HasSubCommand("things", x =>x.WithHandler(
                    (_,_,_) => capi.ShowChatMessage("Doing Things!")).Build());
        }
        
        private void StuffHandler(string subCommandName, int groupId, CmdArgs args)
        {
            _capi.ShowChatMessage("Doing Stuff!");
        }
        
        // ...
    }

Advanced Example with Separation of Concerns

Here, we lazy load the /test command by immediately registering it with the API.

    internal class MyMod : ModSystem
    {
        // ...
        
        public override void StartServerSide(ICoreServerAPI sapi)
        {
            sapi.RegisterFluentCommand("test")
        }
        
        // ...
    }

We can then separate our logic into a separate class; even within a separate assembly.

    internal class TestChatCommand
    {
        private ICoreServerAPI _sapi;
        
        internal TestChatCommand(ICoreServerAPI sapi)
        {
            _sapi = sapi;
            var command = sapi.FluentCommand("test");
            
            // Set Description:
            command.WithDesctiption(Lang.Get("mymod:commands.test.description"));
            
            // Set Default Handler:
            command.WithHandler(DefaultHandler);
            
            // Set Required Privilege:
            command.RequiresPrivilege(Privilege.ControlServer);
            
            // Set Stuff Handler:
            command.HasSubCommand("stuff", x => x.WithHandler(StuffHandler).Build());
            
            // Set Things Handler:
            command.HasSubCommand("things", x => x.WithHandler(ThingsHandler).Build());
        }
    
        private void DefaultHandler(string subCommandName, IServerPlayer player, int groupId, CmdArgs args)
        {
            // Do stuff and things.
        }
    
        private void StuffHandler(string subCommandName, IServerPlayer player, int groupId, CmdArgs args)
        {
            // Do stuff.
        }
        
        private void ThingsHandler(string subCommandName, IServerPlayer player, int groupId, CmdArgs args)
        {
            // Do things.
        }
    }
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.2.0 224 4/21/2023
2.1.0 203 4/20/2023
2.0.2 201 4/20/2023
2.0.1 447 9/21/2022
2.0.0 423 9/20/2022
1.4.1 344 12/16/2021

Update to 2.2.0

- Fix: ClearChatCommands() now works.
- Fix: Privilege now set on server commands, defaults to "chat".