diff --git a/MCGalaxy/Modules/Compiling/CmdCompile.cs b/MCGalaxy/Modules/Compiling/CmdCompile.cs index 9ad220951..ebd7434bb 100644 --- a/MCGalaxy/Modules/Compiling/CmdCompile.cs +++ b/MCGalaxy/Modules/Compiling/CmdCompile.cs @@ -19,6 +19,7 @@ using System; using MCGalaxy.Commands; using MCGalaxy.Scripting; +using System.IO; namespace MCGalaxy.Modules.Compiling { @@ -64,24 +65,40 @@ namespace MCGalaxy.Modules.Compiling } protected virtual void CompilePlugin(Player p, string[] paths, ICompiler compiler) { - string dstPath = IScripting.PluginPath(paths[0]); + string pln = paths[0]; + string dstPath = IScripting.PluginPath(pln); for (int i = 0; i < paths.Length; i++) { paths[i] = compiler.PluginPath(paths[i]); } + paths = TryDirectory(ICompiler.PLUGINS_SOURCE_DIR, pln, paths, compiler); + CompilerOperations.Compile(p, compiler, "Plugin", paths, dstPath); } protected virtual void CompileCommand(Player p, string[] paths, ICompiler compiler) { - string dstPath = IScripting.CommandPath(paths[0]); + string cmd = paths[0]; + string dstPath = IScripting.CommandPath(cmd); for (int i = 0; i < paths.Length; i++) { paths[i] = compiler.CommandPath(paths[i]); } + paths = TryDirectory(ICompiler.COMMANDS_SOURCE_DIR, cmd, paths, compiler); + CompilerOperations.Compile(p, compiler, "Command", paths, dstPath); } + + // If first source file doesn't exist, try treating it as a directory instead + string[] TryDirectory(string root, string name, string[] srcPaths, ICompiler compiler) { + if (File.Exists(srcPaths[0])) return srcPaths; + + string dir = Path.Combine(root, name); + if (!Directory.Exists(dir)) return srcPaths; + + return Directory.GetFiles(dir, "*" + compiler.FileExtension); + } public override void Help(Player p) { ICompiler compiler = ICompiler.Compilers[0]; diff --git a/MCGalaxy/Modules/Compiling/CmdCompload.cs b/MCGalaxy/Modules/Compiling/CmdCompload.cs index 214617fb3..adf2f577b 100644 --- a/MCGalaxy/Modules/Compiling/CmdCompload.cs +++ b/MCGalaxy/Modules/Compiling/CmdCompload.cs @@ -28,9 +28,10 @@ namespace MCGalaxy.Modules.Compiling public override CommandAlias[] Aliases { get { return null; } } protected override void CompilePlugin(Player p, string[] paths, ICompiler compiler) { - string dst = IScripting.PluginPath(paths[0]); + string pln = paths[0]; + string dst = IScripting.PluginPath(pln); - UnloadPlugin(p, paths[0]); + UnloadPlugin(p, pln); base.CompilePlugin(p, paths, compiler); ScriptingOperations.LoadPlugins(p, dst); }