public Plugin(string name, string code, DirectoryInfo path, PluginType type) { Name = name; Code = code; RootDir = path; Type = type; Timers = new Dictionary <string, TimedEvent>(); if (type == PluginType.Python) { PyEngine = IronPython.Hosting.Python.CreateEngine(); Scope = PyEngine.CreateScope(); Scope.SetVariable("Plugin", this); Scope.SetVariable("Server", Pluton.Server.GetServer()); Scope.SetVariable("DataStore", DataStore.GetInstance()); Scope.SetVariable("Util", Util.GetUtil()); Scope.SetVariable("World", World.GetWorld()); Scope.SetVariable("Commands", PluginCommands.GetInstance()); PyEngine.Execute(code, Scope); Class = PyEngine.Operations.Invoke(Scope.GetVariable(name)); Globals = PyEngine.Operations.GetMemberNames(Class); } else { JSEngine = new Engine(cfg => cfg.AllowClr(typeof(UnityEngine.GameObject).Assembly, typeof(PlayerInventory).Assembly)) .SetValue("Server", Server.GetServer()) .SetValue("DataStore", DataStore.GetInstance()) .SetValue("Util", Util.GetUtil()) .SetValue("World", World.GetWorld()) .SetValue("Plugin", this) .SetValue("Commands", PluginCommands.GetInstance()) .Execute(code); JavaScriptParser parser = new JavaScriptParser(); Globals = (from function in parser.Parse(Code).FunctionDeclarations where (function.Id.Name.StartsWith("On_") || function.Id.Name.EndsWith("Callback")) select function.Id.Name).ToList <string>(); } }
// chat.say().Hooks.Chat() public static void Command(ConsoleSystem.Arg arg) { Player player = new Player(arg.Player()); string[] args = arg.ArgsStr.Substring(2, arg.ArgsStr.Length - 3).Replace("\\", "").Split(new string[] { " " }, StringSplitOptions.None); Command cmd = new Command(player, args); if (cmd.cmd == "") { return; } if (Config.GetBoolValue("Commands", "enabled")) { if (cmd.cmd == Config.GetValue("Commands", "ShowMyStats")) { PlayerStats stats = player.Stats; player.Message(String.Format("You have {0} kills and {1} deaths!", stats.Kills, stats.Deaths)); player.Message(String.Format("You have taken {0} dmg, and caused {1} in total!", stats.TotalDamageTaken, stats.TotalDamageDone)); return; } if (cmd.cmd == Config.GetValue("Commands", "ShowStatsOther")) { Player pOther = Player.Find(String.Join(" ", cmd.args)); if (pOther != null) { PlayerStats stats2 = pOther.Stats; player.Message(String.Format("You have {0} kills and {1} deaths!", stats2.Kills, stats2.Deaths)); player.Message(String.Format("You have taken {0} dmg, and caused {1} in total!", stats2.TotalDamageTaken, stats2.TotalDamageDone)); return; } player.Message("Can't find player: " + String.Join(" ", cmd.args)); return; } if (cmd.cmd == Config.GetValue("Commands", "ShowLocation")) { player.Message(player.Location.ToString()); return; } if (cmd.cmd == Config.GetValue("Commands", "ShowOnlinePlayers")) { string msg = Server.GetServer().Players.Count == 1 ? "You are alone!" : String.Format("There are: {0} players online!", Server.GetServer().Players.Count); player.Message(msg); return; } if (cmd.cmd == Config.GetValue("Commands", "Help")) { foreach (string key in Config.PlutonConfig.EnumSection("HelpMessage")) { player.Message(Config.GetValue("HelpMessage", key)); } } if (cmd.cmd == Config.GetValue("Commands", "Commands")) { player.Message(String.Join(", ", PluginCommands.GetInstance().getCommands().ToArray())); } // TODO: command description, usage } OnCommand.OnNext(cmd); if (cmd.ReplyWith != "") { arg.ReplyWith(cmd.ReplyWith); } }