private static void ZoneRenameHandler( Player player, Command cmd )
{
World playerWorld = player.World;
if ( playerWorld == null )
PlayerOpException.ThrowNoWorld( player );
// make sure that both parameters are given
string oldName = cmd.Next();
string newName = cmd.Next();
if ( oldName == null || newName == null ) {
CdZoneRename.PrintUsage( player );
return;
}
// make sure that the new name is valid
if ( !World.IsValidName( newName ) ) {
player.Message( "\"{0}\" is not a valid zone name", newName );
return;
}
// find the old zone
var zones = player.WorldMap.Zones;
Zone oldZone = zones.Find( oldName );
if ( oldZone == null ) {
player.MessageNoZone( oldName );
return;
}
// Check if a zone with "newName" name already exists
Zone newZone = zones.FindExact( newName );
if ( newZone != null && newZone != oldZone ) {
player.Message( "A zone with the name \"{0}\" already exists.", newName );
return;
}
// check if any change is needed
string fullOldName = oldZone.Name;
if ( fullOldName == newName ) {
player.Message( "The zone is already named \"{0}\"", fullOldName );
return;
}
// actually rename the zone
zones.Rename( oldZone, newName );
// announce the rename
playerWorld.Players.Message( "&SZone \"{0}\" was renamed to \"{1}&S\" by {2}",
fullOldName, oldZone.ClassyName, player.ClassyName );
Logger.Log( LogType.UserActivity,
"Player {0} renamed zone \"{1}\" to \"{2}\" on world {3}",
player.Name, fullOldName, newName, playerWorld.Name );
}