public static void Reload() { Base.Info($"Reloading plugins. Clearing lists and dictionaries"); plugins.Clear(); allEvents.Clear(); allCommands.Clear(); commandInstances.Clear(); PluginPreLoad(); }
private static void LoadPlugins(string pluginsFolder) { if (Directory.Exists(pluginsFolder)) { Base.Info("Loading plugins..."); List <string> files = Directory.GetFiles(pluginsFolder).ToList <string>(); foreach (string dllfile in files) { if (dllfile.EndsWith(".dll")) { Assembly asm = Assembly.LoadFrom(dllfile); Base.Info("PLUGIN LOADER | Loading plugin " + asm.GetName().Name); try { foreach (Type t in asm.GetTypes()) { if (t.IsSubclassOf(typeof(Plugin)) && t != typeof(Plugin)) { plugins.Add(asm); object obj = Activator.CreateInstance(t); try { MethodInfo method = t.GetMethod("initializePlugin"); string aaa = (string)method.Invoke(obj, null); AddCommands(asm); } catch (Exception e) { Base.Error("PLUGIN LOADER | Failed to load file: " + asm.GetName().Name); Base.Error($"PLUGIN LOADER | {e.Message}"); Base.Error($"PLUGIN LOADER | {e.InnerException}"); }; } } } catch (Exception e) { Base.Error("PLUGIN LOADER | Failed to load file: " + asm.GetName().Name); Base.Error($"PLUGIN LOADER | {e.Message}"); Base.Error($"PLUGIN LOADER | {e.InnerException}"); } } } Base.Info("Plugins loaded!"); } }
private static void LoadDependencies(string pluginsFolder) { if (Directory.Exists(pluginsFolder)) { Base.Info("Loading dependancies..."); List <string> files = Directory.GetFiles(pluginsFolder).ToList <string>(); foreach (string dllfile in files) { if (dllfile.EndsWith(".dll")) { Assembly asm = Assembly.LoadFrom(dllfile); Base.Info("DEPENDENCY LOADER | Loading dependency " + asm.GetName().Name); } } Base.Info("Dependancies loaded!"); } }
internal static bool TriggerConsoleCommand(CommandInfo cInfo) { if (!allCommands.ContainsKey(cInfo.commandName)) { return(false); } MethodInfo cmd = allCommands[cInfo.commandName]; if (cmd == null || cmd.Equals(default(Type))) { return(false); } PMConsoleRunnable cR = (PMConsoleRunnable)cmd.GetCustomAttribute(typeof(PMConsoleRunnable)); if (cR == null || !cR.consoleRunnable) { Base.Info($"{cInfo.commandName.ToUpper()} is not runnable via the server console"); return(false); } object instance; if (commandInstances.ContainsKey(cmd)) { instance = commandInstances[cmd]; } else { instance = Activator.CreateInstance(cmd.DeclaringType); commandInstances.Add(cmd, instance); } cmd.Invoke(instance, new object[] { cInfo }); return(true); }
public static void AddCommand(Plugin plugin, ICommand command, string name, string[] alias) { Base.Info(name); if (allCommands.ContainsKey(name) || oldCommands.ContainsKey(name)) { Base.Error($"{plugin.Details.name} tried to register a pre-existing command: {name.ToUpper()}"); } else { oldCommands.Add(name.ToUpper(), command); } if (alias != null) { foreach (string cmdalias in alias) { if (!allCommands.ContainsKey(cmdalias) && !oldCommands.ContainsKey(cmdalias)) { oldCommands.Add(cmdalias.ToUpper(), command); } } } }