Esempio n. 1
0
        public bool Execute(ArraySegment <string> arguments, ICommandSender sender, out string response)
        {
            MuteTranslation muteTranslation = Plugin.Singleton.Config.Translation.MuteTranslation;

            if (!sender.CheckPermission("ms.mute"))
            {
                response = muteTranslation.InvalidPermission.Replace("{permission}", "ms.mute");
                return(false);
            }

            if (arguments.Count < 2)
            {
                response = muteTranslation.WrongUsage;
                return(false);
            }

            HashSet <Collections.Player> targets = new();

            if (arguments.At(0).Split(',').Length > 1)
            {
                foreach (var player in arguments.At(0).Split(','))
                {
                    Collections.Player target = player.GetPlayer();
                    if (target is null)
                    {
                        response = muteTranslation.PlayerNotFound.Replace("{target}", player);
                        continue;
                    }

                    if (targets.Contains(target))
                    {
                        continue;
                    }
                    targets.Add(target);
                }
            }
            else
            {
                Collections.Player dPlayer = arguments.At(0).GetPlayer();
                if (dPlayer == null)
                {
                    response = muteTranslation.PlayerNotFound.Replace("{player}", arguments.At(0));
                    return(false);
                }

                if (!targets.Contains(dPlayer))
                {
                    targets.Add(dPlayer);
                }
            }

            DateTime?duration = ModerationSystemAPI.ConvertToDateTime(arguments.At(1));

            if (duration == null)
            {
                response = muteTranslation.InvalidDuration.Replace("{duration}", arguments.At(1));
                return(false);
            }

            string reason = string.Join(" ", arguments.Skip(2).Take(arguments.Count - 2));

            if (string.IsNullOrEmpty(reason))
            {
                response = muteTranslation.ReasonNull;
                return(false);
            }

            if (!ModerationSystemAPI.MaxDuration(arguments.At(1), Player.Get(sender)))
            {
                response = "You can't do this duration";
                return(false);
            }

            foreach (var dPlayer in targets)
            {
                if (dPlayer.IsMuted())
                {
                    response = muteTranslation.PlayerAlreadyMuted;
                    return(false);
                }

                ModerationSystemAPI.ApplyPunish(Player.Get($"{dPlayer.Id}@{dPlayer.Authentication}"), ((CommandSender)sender).GetStaffer(), dPlayer, PunishType.Mute, reason, arguments.At(1));
                ModerationSystemAPI.SendBroadcast(new Exiled.API.Features.Broadcast(Plugin.Singleton.Config.Translation.StaffTranslation.StaffMuteMessage.Content.Replace("{staffer}", sender.LogName).Replace("{target}", $"{dPlayer.Name} {dPlayer.Id}{dPlayer.Authentication}").Replace("{reason}", reason).Replace("{time}", duration.ToString())));
                response = muteTranslation.PlayerMuted.Replace("{player.name}", dPlayer.Name).Replace("{player.userid}", $"{dPlayer.Id}@{dPlayer.Authentication}").Replace("{duration}", duration.ToString()).Replace("{reason}", reason);
            }
            response = "";
            return(true);
        }
Esempio n. 2
0
        public bool Execute(ArraySegment <string> arguments, ICommandSender sender, out string response)
        {
            WarnTranslation warnTranslation = Plugin.Singleton.Config.Translation.WarnTranslation;

            if (!sender.CheckPermission("ms.warn"))
            {
                response = warnTranslation.InvalidPermission.Replace("{permission}", "ms.warn");
                return(false);
            }

            if (arguments.Count < 1)
            {
                response = warnTranslation.WrongUsage;
                return(false);
            }

            List <Collections.Player> targets = new();

            if (arguments.At(0).Split(',').Length > 1)
            {
                foreach (var player in arguments.At(0).Split(','))
                {
                    Collections.Player target = player.GetPlayer();
                    if (target is null)
                    {
                        response = warnTranslation.PlayerNotFound.Replace("{target}", player);
                        return(false);
                    }

                    if (targets.Contains(target))
                    {
                        continue;
                    }
                    targets.Add(target);
                }
            }
            else
            {
                Collections.Player dPlayer = arguments.At(0).GetPlayer();
                if (dPlayer == null)
                {
                    response = warnTranslation.PlayerNotFound.Replace("{player}", arguments.At(0));
                    return(false);
                }

                if (!targets.Contains(dPlayer))
                {
                    targets.Add(dPlayer);
                }
            }

            string reason = string.Join(" ", arguments.Skip(1).Take(arguments.Count - 1));

            if (string.IsNullOrEmpty(reason))
            {
                response = warnTranslation.ReasonNull;
                return(false);
            }

            foreach (var target in targets)
            {
                ModerationSystemAPI.ApplyPunish(Player.Get($"{target.Id}@{target.Authentication}"), ((CommandSender)sender).GetStaffer(), target, PunishType.Warn, reason, DateTime.MinValue.ToString(CultureInfo.InvariantCulture));
                ModerationSystemAPI.SendBroadcast(new Exiled.API.Features.Broadcast(Plugin.Singleton.Config.Translation.StaffTranslation.StaffWarnMessage.Content.Replace("{staffer}", sender.LogName).Replace("{target}", $"{target.Name} {target.Id}{target.Authentication}").Replace("{reason}", reason)));
            }

            response = warnTranslation.PlayerWarned;
            return(true);
        }