fCraft.InfoCommands.ListHandler C# (CSharp) Method

ListHandler() static private method

static private ListHandler ( Player player, Command cmd ) : void
player Player
cmd Command
return void
        internal static void ListHandler( Player player, Command cmd )
        {
            string Option = cmd.Next();
            if ( Option == null ) {
                CdList.PrintUsage( player );
                player.Message( "  Sections include: Staff, DisplayedNames, Idles, Portals, Rank, Top10, Emotes" );
                return;
            }
            switch ( Option.ToLower() ) {
                default:
                    CdList.PrintUsage( player );
                    player.Message( "  Sections include: Staff, DisplayedNames, Idles, Portals, Rank, Top10, Emotes" );
                    break;

                case "emotes":
                    const string Usage = "Shows a list of all available emotes and their keywords. " +
                                         "There are 31 emotes, spanning 3 pages. Use &h/List emotes 2&s and &h/List emotes 3&s to see pages 2 and 3.";
                    int page = 1;
                    if ( cmd.HasNext ) {
                        if ( !cmd.NextInt( out page ) ) {
                            player.Message( Usage );
                            return;
                        }
                    }
                    if ( page < 1 || page > 3 ) {
                        player.Message( Usage );
                        return;
                    }

                    var emoteChars = Chat.EmoteKeywords
                                         .Values
                                         .Distinct()
                                         .Skip( ( page - 1 ) * 11 )
                                         .Take( 11 );

                    player.Message( "List of emotes, page {0} of 3:", page );
                    foreach ( char ch in emoteChars ) {
                        char ch1 = ch;
                        string keywords = Chat.EmoteKeywords
                                              .Where( pair => pair.Value == ch1 )
                                              .Select( kvp => "{&F" + kvp.Key.UppercaseFirst() + "&7}" )
                                              .JoinToString( " " );
                        player.Message( "&F  {0} &7= {1}", ch, keywords );
                    }
                    if ( page < 3 )
                        player.Message( "Type /List Emotes {0} for the next page", page + 1 );

                    break;

                case "top10":
                    List<World> WorldNames = new List<World>( WorldManager.Worlds.Where( w => w.VisitCount > 0 )
                                         .OrderBy( c => c.VisitCount )
                                         .ToArray()
                                         .Reverse() );
                    string list = WorldNames.Take( 10 ).JoinToString( w => String.Format( "{0}&S: {1}", w.ClassyName, w.VisitCount ) );
                    if ( WorldNames.Count() < 1 ) {
                        player.Message( "&WNo results found" );
                        return;
                    }
                    player.Message( "&WShowing worlds with the most visits: " + list );
                    WorldNames.Clear();
                    break;

                case "idles":
                case "idle":
                    var Idles = Server.Players.Where( p => p.IdleTime.TotalMinutes > 5 ).ToArray();
                    var visiblePlayers = Idles.Where( player.CanSee );
                    if ( visiblePlayers.Count() > 0 )
                        player.Message( "Listing players idle for 5 mins or more: {0}",
                                        visiblePlayers.JoinToString( r => String.Format( "{0}&S (Idle {1}", r.ClassyName, r.IdleTime.ToMiniString() ) ) );
                    else
                        player.Message( "No players have been idle for more than 5 minutes" );
                    break;

                case "portals":
                    if ( player.World == null ) {
                        player.Message( "/List portals cannot be used from Console" );
                        return;
                    }
                    if ( player.World.Map.Portals == null ||
                        player.World.Map.Portals.Count == 0 ) {
                        player.Message( "There are no portals in {0}&S.", player.World.ClassyName );
                    } else {
                        String[] portalNames = new String[player.World.Map.Portals.Count];
                        StringBuilder output = new StringBuilder( "There are " + player.World.Map.Portals.Count + " portals in " + player.World.ClassyName + "&S: " );

                        for ( int i = 0; i < player.World.Map.Portals.Count; i++ ) {
                            portalNames[i] = ( ( fCraft.Portals.Portal )player.World.Map.Portals[i] ).Name;
                        }
                        output.Append( portalNames.JoinToString( ", " ) );
                        player.Message( output.ToString() );
                    }
                    break;

                case "staff":
                    var StaffNames = PlayerDB.PlayerInfoList
                                         .Where( r => r.Rank.Can( Permission.ReadStaffChat ) &&
                                             r.Rank.Can( Permission.Ban ) &&
                                             r.Rank.Can( Permission.Promote ) )
                                             .OrderBy( p => p.Rank )
                                             .ToArray();
                    if ( StaffNames.Length < 1 ) {
                        player.Message( "&WNo results found" );
                        return;
                    }
                    if ( StaffNames.Length <= PlayersPerPage ) {
                        player.MessageManyMatches( "staff", StaffNames );
                    } else {
                        int offset;
                        if ( !cmd.NextInt( out offset ) )
                            offset = 0;
                        if ( offset >= StaffNames.Length )
                            offset = Math.Max( 0, StaffNames.Length - PlayersPerPage );
                        PlayerInfo[] StaffPart = StaffNames.Skip( offset ).Take( PlayersPerPage ).ToArray();
                        player.MessageManyMatches( "staff", StaffPart );
                        if ( offset + StaffPart.Length < StaffNames.Length )
                            player.Message( "Showing {0}-{1} (out of {2}). Next: &H/List {3} {4}",
                                            offset + 1, offset + StaffPart.Length, StaffNames.Length,
                                            "staff", offset + StaffPart.Length );
                        else
                            player.Message( "Showing matches {0}-{1} (out of {2}).",
                                            offset + 1, offset + StaffPart.Length, StaffNames.Length );
                    }
                    break;

                case "rank":
                    string rankName = cmd.Next();
                    if ( rankName == null ) {
                        player.Message( "Usage: /List rank rankName" );
                        return;
                    }
                    Rank rank = RankManager.FindRank( rankName );
                    var RankNames = PlayerDB.PlayerInfoList
                                         .Where( r => r.Rank == rank )
                                             .ToArray();
                    if ( RankNames.Length < 1 ) {
                        player.Message( "&WNo results found" );
                        return;
                    }
                    if ( RankNames.Length <= PlayersPerPage ) {
                        player.MessageManyMatches( "players", RankNames );
                    } else {
                        int offset;
                        if ( !cmd.NextInt( out offset ) )
                            offset = 0;
                        if ( offset >= RankNames.Length )
                            offset = Math.Max( 0, RankNames.Length - PlayersPerPage );
                        PlayerInfo[] RankPart = RankNames.Skip( offset ).Take( PlayersPerPage ).ToArray();
                        player.MessageManyMatches( "rank list", RankPart );
                        if ( offset + RankPart.Length < RankNames.Length )
                            player.Message( "Showing {0}-{1} (out of {2}). Next: &H/List {3} {4}",
                                            offset + 1, offset + RankPart.Length, RankNames.Length,
                                            "rank " + rank.ClassyName, offset + RankPart.Length );
                        else
                            player.Message( "Showing matches {0}-{1} (out of {2}).",
                                            offset + 1, offset + RankPart.Length, RankNames.Length );
                    }
                    break;

                case "displayednames":
                case "displayedname":
                case "dn":
                    var DisplayedNames = PlayerDB.PlayerInfoList
                                             .Where( r => r.DisplayedName != null ).OrderBy( p => p.Rank ).ToArray();
                    if ( DisplayedNames.Length < 1 ) {
                        player.Message( "&WNo results found" );
                        return;
                    }
                    if ( DisplayedNames.Length <= 15 ) {
                        player.MessageManyDisplayedNamesMatches( "DisplayedNames", DisplayedNames );
                    } else {
                        int offset;
                        if ( !cmd.NextInt( out offset ) )
                            offset = 0;
                        if ( offset >= DisplayedNames.Count() )
                            offset = Math.Max( 0, DisplayedNames.Length - 15 );
                        PlayerInfo[] DnPart = DisplayedNames.Skip( offset ).Take( 15 ).ToArray();
                        player.MessageManyDisplayedNamesMatches( "DisplayedNames", DnPart );
                        if ( offset + DisplayedNames.Length < DisplayedNames.Length )
                            player.Message( "Showing {0}-{1} (out of {2}). Next: &H/List {3} {4}",
                                            offset + 1, offset + DnPart.Length, DisplayedNames.Length,
                                            "DisplayedNames", offset + DnPart.Length );
                        else
                            player.Message( "Showing matches {0}-{1} (out of {2}).",
                                            offset + 1, offset + DnPart.Length, DisplayedNames.Length );
                    }
                    break;
            }
        }