Inheritance: CountedInstance
Ejemplo n.º 1
0
 public Player(BasePlayer player)
     : base(player)
 {
     GameID = player.userID;
     _basePlayer = player;
     try {
         Stats = new PlayerStats(SteamID);
     } catch (Exception ex) {
         Logger.LogDebug("[Player] Couldn't load stats!");
         Logger.LogException(ex);
     }
 }
Ejemplo n.º 2
0
        // 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));
                    }
                }
            }
            OnCommand.OnNext(cmd);

            if (cmd.ReplyWith != "")
            {
                arg.ReplyWith(cmd.ReplyWith);
            }
        }
Ejemplo n.º 3
0
        // chat.say().Hooks.Chat()
        public static void Command(ConsoleSystem.Arg arg)
        {
            Player player = Server.GetPlayer(arg.Player());

            string[] args = arg.ArgsStr.Substring(2, arg.ArgsStr.Length - 3).Replace("\\", "").Split(new string[] { " " }, StringSplitOptions.None);

            CommandEvent cmd = new CommandEvent(player, args);

            if (cmd.cmd == "")
            {
                return;
            }

            foreach (KeyValuePair <string, BasePlugin> pl in PluginLoader.GetInstance().Plugins)
            {
                ChatCommand[] commands = pl.Value.chatCommands.getChatCommands(cmd.cmd);
                foreach (ChatCommand chatCmd in commands)
                {
                    if (chatCmd.callback == null)
                    {
                        continue;
                    }

                    CommandPermissionEvent permission = new CommandPermissionEvent(player, args, chatCmd);
                    OnCommandPermission.OnNext(permission);
                    if (permission.blocked)
                    {
                        player.Message(permission.Reply);
                        continue;
                    }

                    try {
                        chatCmd.callback(cmd.args, player);
                    } catch (Exception ex) {
                        Logger.LogError(chatCmd.plugin.FormatException(ex));
                    }
                }
            }

            if (Config.GetInstance().GetBoolValue("Commands", "enabled", true))
            {
                // TODO: make a plugin from these, no need to be in the core

                if (cmd.cmd == Config.GetInstance().GetValue("Commands", "ShowMyStats", "mystats"))
                {
                    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.GetInstance().GetValue("Commands", "ShowStatsOther", "statsof"))
                {
                    Player pOther = Player.Find(String.Join(" ", cmd.args));
                    if (pOther != null)
                    {
                        PlayerStats stats2 = pOther.Stats;
                        player.Message(String.Format(pOther.Name + " has {0} kills and {1} deaths!", stats2.Kills, stats2.Deaths));
                        player.Message(String.Format(pOther.Name + " has 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.GetInstance().GetValue("Commands", "ShowLocation", "whereami"))
                {
                    player.Message(player.Location.ToString());
                    return;
                }
                if (cmd.cmd == Config.GetInstance().GetValue("Commands", "ShowOnlinePlayers", "players"))
                {
                    string msg = Server.GetInstance().Players.Count == 1 ? "You are alone!" : String.Format("There are: {0} players online!", Server.GetInstance().Players.Count);
                    player.Message(msg);
                    return;
                }
                if (cmd.cmd == Config.GetInstance().GetValue("Commands", "Help", "help"))
                {
                    foreach (string key in Config.GetInstance().PlutonConfig.EnumSection("HelpMessage"))
                    {
                        player.Message(Config.GetInstance().GetValue("HelpMessage", key));
                    }
                }

                List <ChatCommands> cc = new List <ChatCommands>();
                foreach (KeyValuePair <string, BasePlugin> pl in PluginLoader.GetInstance().Plugins)
                {
                    cc.Add(pl.Value.chatCommands);
                }
                if (cmd.cmd == Config.GetInstance().GetValue("Commands", "Commands", "commands"))
                {
                    List <string> list = new List <string>();
                    foreach (ChatCommands cm in cc)
                    {
                        list.AddRange(cm.getCommands());
                    }
                    player.Message(String.Join(", ", list.ToArray()));
                }
                if (cmd.cmd == Config.GetInstance().GetValue("Commands", "Description", "whatis"))
                {
                    if (cmd.args.Length < 1)
                    {
                        player.Message("You must provide a command name");
                    }
                    else
                    {
                        List <string> list = new List <string>();
                        foreach (ChatCommands cm in cc)
                        {
                            list.AddRange(cm.getDescriptions(cmd.args[0]));
                        }
                        if (list.Count > 0)
                        {
                            player.Message(String.Join("\r\n", list.ToArray()));
                        }
                    }
                }
                if (cmd.cmd == Config.GetInstance().GetValue("Commands", "Usage", "howto"))
                {
                    if (cmd.args.Length < 1)
                    {
                        player.Message("You must provide a command name");
                    }
                    else
                    {
                        List <string> list = new List <string>();
                        foreach (ChatCommands cm in cc)
                        {
                            list.AddRange(cm.getUsages(cmd.args[0]));
                        }
                        foreach (var item in list)
                        {
                            player.Message(String.Format("/{0} {1}", cmd.args[0], item));
                        }
                    }
                }
            }
            OnCommand.OnNext(cmd);

            if (cmd.Reply != "")
            {
                arg.ReplyWith(cmd.Reply);
            }
        }