-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
129 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Obsidian.Commands.Framework; | ||
using Obsidian.Plugins; | ||
using System.Reflection; | ||
|
||
namespace Obsidian.Commands; | ||
public static class CommandModuleFactory | ||
{ | ||
public static object? CreateModule(ObjectFactory factory, CommandContext context, PluginContainer pluginContainer) | ||
{ | ||
var module = factory.Invoke(pluginContainer.ServiceScope.ServiceProvider, null); | ||
var moduleType = module.GetType(); | ||
|
||
var commandContextProperty = moduleType.GetProperties().FirstOrDefault(x => x.GetCustomAttribute<CommandContextAttribute>() != null) | ||
?? throw new InvalidOperationException("Failed to find CommandContext property."); | ||
|
||
commandContextProperty.SetValue(module, context); | ||
|
||
pluginContainer.InjectServices(null, module); | ||
|
||
return module; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace Obsidian.Commands.Framework; | ||
|
||
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = true)] | ||
public sealed class CommandContextAttribute : Attribute | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using Obsidian.API.Plugins; | ||
using System.Diagnostics; | ||
|
||
namespace Obsidian.Commands.Framework; | ||
public abstract class CommandModuleBase | ||
{ | ||
private CommandContext? commandContext; | ||
|
||
[CommandContext] | ||
public CommandContext CommandContext | ||
{ | ||
get | ||
{ | ||
if (commandContext == null) | ||
throw new UnreachableException();//TODO empty command context maybe?? | ||
|
||
return this.commandContext; | ||
} | ||
set | ||
{ | ||
ArgumentNullException.ThrowIfNull(value); | ||
|
||
this.commandContext = value; | ||
} | ||
} | ||
|
||
public IPlayer? Player => this.CommandContext.Player; | ||
public IServer Server => this.CommandContext.Server; | ||
public ICommandSender Sender => this.CommandContext.Sender; | ||
|
||
public bool IsPlayer => this.CommandContext.IsPlayer; | ||
|
||
public PluginBase? Plugin => this.CommandContext.Plugin; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters