Пример #1
0
        public PlayerGroup GetPlayerGroup(string playerName)
        {
            PlayerGroup playerGroup = PlayerGroup.Player;

            if (_skyCoreApi.GetPlayer(playerName) is SkyPlayer player)
            {
                return(player.PlayerGroup);
            }

            return(playerGroup);
        }
Пример #2
0
        public static bool ValueOf(string groupName, out PlayerGroup playerGroup)
        {
            playerGroup = null;

            switch (groupName.ToLower())
            {
            case "player": playerGroup = Player;
                break;

            case "vip": playerGroup = Vip;
                break;

            case "pro": playerGroup = Pro;
                break;

            case "mvp": playerGroup = Mvp;
                break;

            case "helper": playerGroup = Helper;
                break;

            case "mod": playerGroup = Mod;
                break;

            case "developer": playerGroup = Developer;
                break;

            case "youtuber": playerGroup = Youtuber;
                break;

            case "admin": playerGroup = Admin;
                break;
            }

            return(playerGroup != null);
        }
Пример #3
0
        public void CommandPermSet(MiNET.Player player, string targetName, string targetGroupName)
        {
            if (!(player is SkyPlayer skyPlayer) || !skyPlayer.PlayerGroup.IsAtLeast(PlayerGroup.Admin))
            {
                player.SendMessage("§c§l(!)§r §cYou do not have permission for this command.");
                return;
            }

            if (String.IsNullOrEmpty(targetName))
            {
                player.SendMessage($"{ChatColors.Red}Enter a valid player name.");
                return;
            }

            SkyPlayer target = _skyCoreApi.GetPlayer(targetName);

            if (target == null || !target.IsConnected)
            {
                player.SendMessage($"{ChatColors.Red}Target player is not online.");
                return;
            }

            //Format as our Enums
            targetGroupName = targetGroupName.ToLower();
            targetGroupName = Char.ToUpper(targetGroupName.ToCharArray()[0]) + targetGroupName.Substring(1);

            if (!PlayerGroup.ValueOf(targetGroupName, out var targetGroup))
            {
                player.SendMessage($"{ChatColors.Red}Unrecognized group name '{targetGroupName}'.");
                string possibleGroups = "";
                foreach (PlayerGroup groupLoop in PlayerGroup.Values)
                {
                    possibleGroups += groupLoop.GroupName + ",";
                }

                player.SendMessage($"Possible Groups: {possibleGroups}");
                return;
            }

            target.SetPlayerGroup(targetGroup);

            RunnableTask.RunTask(() =>
            {
                new DatabaseAction().Execute(
                    "INSERT INTO `player_groups`\n" +
                    "  (`player_xuid`, `group_name`)\n" +
                    "VALUES\n" +
                    "  (@xuid, @group)\n" +
                    "ON DUPLICATE KEY UPDATE\n" +
                    "  `player_xuid`    = VALUES(`player_xuid`),\n" +
                    "  `group_name`     = VALUES(`group_name`);",
                    (command) =>
                {
                    command.Parameters.AddWithValue("@xuid", target.CertificateData.ExtraData.Xuid);
                    command.Parameters.AddWithValue("@group", targetGroup.GroupName);
                },
                    new Action(delegate
                {
                    player.SendMessage($"{ChatColors.Yellow}Updated {target.Username}'s group to {targetGroup.GroupName}");
                })
                    );
            });
        }
Пример #4
0
 public bool IsAtLeast(PlayerGroup playerGroup)
 {
     return(CompareTo(playerGroup) >= 0);
 }
Пример #5
0
 public int CompareTo(PlayerGroup playerGroup)
 {
     return(EnumVal.CompareTo(playerGroup.EnumVal));
 }