public override void Use(Player p, string message, CommandData data) { if (message.Length == 0) { Help(p); return; } string[] args = message.SplitSpaces(); if (!Formatter.ValidFilename(p, args[0])) { return; } string language = args.Length > 1 ? args[1] : ""; ICompiler engine = CompilerOperations.GetCompiler(p, language); if (engine == null) { return; } string path = engine.CommandPath(args[0]); if (File.Exists(path)) { p.Message("File {0} already exists. Choose another name.", path); return; } string source = engine.GenExampleCommand(args[0]); File.WriteAllText(path, source); p.Message("Successfully saved example command &fCmd{0} &Sto {1}", args[0], path); }
static void CompilePlugin(Player p, string name, ICompiler compiler) { // either "source" or "source1,source2,source3" string[] paths = name.SplitComma(); string dstPath = IScripting.PluginPath(paths[0]); for (int i = 0; i < paths.Length; i++) { paths[i] = compiler.PluginPath(paths[i]); } CompilerOperations.Compile(p, compiler, "Plugin", paths, dstPath); }
public override void Use(Player p, string message, CommandData data) { string[] args = message.SplitSpaces(); bool plugin = args[0].CaselessEq("plugin"); string name, lang; if (plugin) { // compile plugin [name] <language> name = args.Length > 1 ? args[1] : ""; lang = args.Length > 2 ? args[2] : ""; } else { // compile [name] <language> name = args[0]; lang = args.Length > 1 ? args[1] : ""; } if (name.Length == 0) { Help(p); return; } if (!Formatter.ValidFilename(p, name)) { return; } ICompiler compiler = CompilerOperations.GetCompiler(p, lang); if (compiler == null) { return; } if (plugin) { CompilePlugin(p, name, compiler); } else { CompileCommand(p, name, compiler); } }