fCraft.WorldCommands.WorldRenameHandler C# (CSharp) Method

WorldRenameHandler() static private method

static private WorldRenameHandler ( Player player, Command cmd ) : void
player Player
cmd Command
return void
        static void WorldRenameHandler( Player player, Command cmd ) {
            string oldName = cmd.Next();
            string newName = cmd.Next();
            if( oldName == null || newName == null ) {
                CdWorldRename.PrintUsage( player );
                return;
            }

            World oldWorld = WorldManager.FindWorldOrPrintMatches( player, oldName );
            if( oldWorld == null ) return;
            oldName = oldWorld.Name;

            if( !World.IsValidName( newName ) ) {
                player.MessageInvalidWorldName( newName );
                return;
            }

            World newWorld = WorldManager.FindWorldExact( newName );
            if( !cmd.IsConfirmed && newWorld != null && newWorld != oldWorld ) {
                player.Confirm( cmd, "A world named {0}&S already exists. Replace it?", newWorld.ClassyName );
                return;
            }

            if( !cmd.IsConfirmed && File.Exists( Path.Combine( Paths.MapPath, newName + ".fcm" ) ) ) {
                player.Confirm( cmd, "Renaming this world will overwrite an existing map file \"{0}.fcm\".", newName );
                return;
            }

            try {
                WorldManager.RenameWorld( oldWorld, newName, true, true );
            } catch( WorldOpException ex ) {
                switch( ex.ErrorCode ) {
                    case WorldOpExceptionCode.NoChangeNeeded:
                        player.MessageNow( "WRename: World is already named \"{0}\"", oldName );
                        return;
                    case WorldOpExceptionCode.DuplicateWorldName:
                        player.MessageNow( "WRename: Another world named \"{0}\" already exists.", newName );
                        return;
                    case WorldOpExceptionCode.InvalidWorldName:
                        player.MessageNow( "WRename: Invalid world name: \"{0}\"", newName );
                        return;
                    case WorldOpExceptionCode.MapMoveError:
                        player.MessageNow( "WRename: World \"{0}\" was renamed to \"{1}\", but the map file could not be moved due to an error: {2}",
                                            oldName, newName, ex.InnerException );
                        return;
                    default:
                        player.MessageNow( "&WWRename: Unexpected error renaming world \"{0}\": {1}", oldName, ex.Message );
                        Logger.Log( LogType.Error,
                                    "WorldCommands.Rename: Unexpected error while renaming world {0} to {1}: {2}",
                                    oldWorld.Name, newName, ex );
                        return;
                }
            }

            WorldManager.SaveWorldList();
            Logger.Log( LogType.UserActivity,
                        "{0} renamed the world \"{1}\" to \"{2}\".",
                        player.Name, oldName, newName );
            Server.Message( "{0}&S renamed the world \"{1}\" to \"{2}\"",
                              player.ClassyName, oldName, newName );
        }

Same methods

WorldCommands::WorldRenameHandler ( Player player, CommandReader cmd ) : void
WorldCommands::WorldRenameHandler ( [ player, [ cmd ) : void