Skip to content

Commit

Permalink
Add plugin command to rue
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaioru committed Nov 15, 2023
1 parent 3c8f4e9 commit b631d2d
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
46 changes: 46 additions & 0 deletions src/plugin/Edelstein.Plugin.Rue/Commands/Admin/PluginCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using System.Collections.Immutable;
using Edelstein.Protocol.Gameplay.Game.Contexts;
using Edelstein.Protocol.Gameplay.Game.Objects.User;
using Edelstein.Protocol.Plugin;

namespace Edelstein.Plugin.Rue.Commands.Admin;

public class PluginCommand : AbstractCommand
{
private readonly IPluginManager<GameContext> _pluginManager;

public PluginCommand(IPluginManager<GameContext> pluginManager)
=> _pluginManager = pluginManager;

public override string Name => "Plugins";

public override string Description => "Lists all loaded plugins";

public override async Task Execute(IFieldUser user, string[] args)
{
var id = 0;
var plugins = (await _pluginManager.RetrieveAll())
.ToImmutableDictionary(
h => id++,
h => h
);
var pluginMenu = plugins
.ToImmutableDictionary(
kv => kv.Key,
kv => kv.Value.Manifest?.Name ?? kv.Value.ID
);
var pluginSelect = await user.Prompt(target => target.AskMenu("Here are the currently loaded plugins", pluginMenu), -1);

if (pluginSelect == -1) return;

var plugin = plugins[pluginSelect];

await user.Prompt(target => target.Say(
plugin.Manifest == null
? "Plugin was not loaded with a manifest"
: $"Name: {plugin.Manifest.Name}\r\n" +
$"Description: {plugin.Manifest.Description}\r\n" +
$"EntryPoint: {plugin.Manifest.EntryPoint}"
), -1);
}
}
2 changes: 2 additions & 0 deletions src/plugin/Edelstein.Plugin.Rue/RueGamePlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ await commandManager.Insert(new QuestCommand(
await commandManager.Insert(new EquipCommand());
await commandManager.Insert(new StatCommand());
await commandManager.Insert(new TemporaryStatCommand());

await commandManager.Insert(new PluginCommand(host.Manager));
await commandManager.Insert(new DebugCommand());

ctx.Pipelines.FieldOnPacketUserChat.Add(PipelinePriority.High, new FieldOnPacketUserChatCommandPlug(commandManager));
Expand Down

0 comments on commit b631d2d

Please sign in to comment.