Skip to content

Instantly share code, notes, and snippets.

@RestoreMonarchy
Last active April 25, 2020 17:22
Show Gist options
  • Save RestoreMonarchy/d4b3b7b7419937473a10d2427812eadf to your computer and use it in GitHub Desktop.
Save RestoreMonarchy/d4b3b7b7419937473a10d2427812eadf to your computer and use it in GitHub Desktop.
Manually registering RocketMod commands

ExamplePlugin.cs

using Example.Commands;
using Rocket.Core;
using Rocket.Core.Plugins;

namespace Example
{
    public class ExamplePlugin : RocketPlugin<ExampleConfiguration>
    {
        protected override void Load()
        {
            if (Configuration.Instance.MuteEnabled)
            {
                // injecting ExamplePlugin instance 'this'
                var cmd = new MuteCommand(this);
                // manually registering IRocketCommand
                R.Commands.Register(cmd);
            }
        }
    }
}

ExampleConfiguration.cs

using Rocket.API;

namespace Example
{
    public class ExampleConfiguration : IRocketPluginConfiguration
    {
        public bool MuteEnabled { get; set; }
        public string MuteCommandName { get; set; }

        public void LoadDefaults()
        {
            MuteEnabled = true;
            MuteCommandName = "mute";
        }
    }
}

Commands/MuteCommand.cs

using Rocket.API;
using System.Collections.Generic;

namespace Example.Commands
{
    public class MuteCommand : IRocketCommand
    {
        private readonly ExamplePlugin pluginInstance;

        // Constructor blocks rocket automatically registering IRocketCommand
        public MuteCommand(ExamplePlugin pluginInstance)
        {
            this.pluginInstance = pluginInstance;
        }

        public AllowedCaller AllowedCaller => AllowedCaller.Both;

        // using MuteCommandName from configuration
        public string Name => pluginInstance.Configuration.Instance.MuteCommandName;

        public string Help => string.Empty;

        public string Syntax => string.Empty;

        public List<string> Aliases => new List<string>();

        public List<string> Permissions => new List<string>();

        public void Execute(IRocketPlayer caller, string[] command)
        {
            // Your execute code here obviously
        }
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment