private string GetPluginScriptText(string name, Plugin.PluginType type) { string path = ""; if (type == Plugin.PluginType.Python) { path = GetPyPluginScriptPath(name); } else { path = GetJSPluginScriptPath(name); } if (path == "") { return(null); } return(File.ReadAllText(path)); }
public void LoadPlugin(string name, Plugin.PluginType type) { Logger.LogDebug("[PluginLoader] Loading plugin " + name + "."); if (plugins.ContainsKey(name)) { Logger.LogError("[PluginLoader] " + name + " plugin is already loaded."); throw new InvalidOperationException("[PluginLoader] " + name + " plugin is already loaded."); } try { string code = GetPluginScriptText(name, type); DirectoryInfo path = new DirectoryInfo(Path.Combine(pluginDirectory.FullName, name)); Plugin plugin = new Plugin(name, code, path, type); InstallHooks(plugin); plugins.Add(name, plugin); Logger.Log("[PluginLoader] " + name + " plugin was loaded successfuly."); } catch (Exception ex) { Server.GetServer().Broadcast(name + " plugin could not be loaded."); Logger.LogException(ex); } }