From c1fa2fe285f1085af74930f08a21e98a997b0673 Mon Sep 17 00:00:00 2001 From: Robin Kanters Date: Thu, 14 May 2015 13:05:54 +0200 Subject: [PATCH] All implementations of Command are now automatically found and loaded by the commandmanager --- TrueCraft/Commands/CommandManager.cs | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/TrueCraft/Commands/CommandManager.cs b/TrueCraft/Commands/CommandManager.cs index 9f10d01..bcfa8a3 100644 --- a/TrueCraft/Commands/CommandManager.cs +++ b/TrueCraft/Commands/CommandManager.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Reflection; using System.Text; using TrueCraft.API.Server; using TrueCraft.API.Networking; @@ -19,15 +20,16 @@ namespace TrueCraft.Commands private void LoadCommands() { - Commands.Add(new PingCommand()); - Commands.Add(new GiveCommand()); - Commands.Add(new GiveMeCommand()); - Commands.Add(new HelpCommand()); - Commands.Add(new ResendInvCommand()); - Commands.Add(new PositionCommand()); - Commands.Add(new TimeCommand()); - Commands.Add(new LogCommand()); - Commands.Add(new TellCommand()); + var truecraftAssembly = Assembly.GetExecutingAssembly(); + + var types = truecraftAssembly.GetTypes() + .Where(t => typeof (ICommand).IsAssignableFrom(t)) + .Where(t => !t.IsAbstract); + + foreach (var command in types.Select(type => (ICommand)Activator.CreateInstance(type))) + { + Commands.Add(command); + } } ///