fCraft.WorldCommands.Worlds C# (CSharp) Method

Worlds() static private method

static private Worlds ( Player player, Command cmd ) : void
player Player
cmd Command
return void
        internal static void Worlds( Player player, Command cmd ) {
            string param = cmd.Next();
            bool listVisible = true,
                 listHidden = false,
                 listAllLoaded = false;
            if( !String.IsNullOrEmpty( param ) ) {
                switch( Char.ToLower( param[0] ) ) {
                    case 'a':
                        listHidden = true;
                        break;
                    case 'h':
                        listVisible = false;
                        listHidden = true;
                        break;
                    case 'l':
                        listAllLoaded = true;
                        listVisible = false;
                        listHidden = false;
                        break;
                    default:
                        cdWorlds.PrintUsage( player );
                        return;
                }
            }

            StringBuilder sb = new StringBuilder();
            bool first = true;
            int count = 0;

            World[] worldListCache = WorldManager.WorldList;
            foreach( World world in worldListCache ) {
                bool visible = player.CanJoin( world ) && !world.IsHidden;
                if( (world.IsLoaded && listAllLoaded) || (visible && listVisible) || (!visible && listHidden) ) {
                    if( !first ) {
                        sb.Append( ", " );
                    }
                    sb.Append( world.GetClassyName() );
                    count++;
                    first = false;
                }
            }

            if( listAllLoaded ) {
                player.MessagePrefixed( "&S   ", "There are " + count + " loaded worlds: " + sb );
            } else if( listVisible && !listHidden ) {
                player.MessagePrefixed( "&S   ", "There are " + count + " available worlds: " + sb );
            } else if( !listVisible ) {
                player.MessagePrefixed( "&S   ", "There are " + count + " hidden worlds: " + sb );
            } else {
                player.MessagePrefixed( "&S   ", "There are " + count + " worlds total: " + sb );
            }
        }