diff --git a/TShockAPI/DB/RegionManager.cs b/TShockAPI/DB/RegionManager.cs index 661ec1c5..8649dedf 100644 --- a/TShockAPI/DB/RegionManager.cs +++ b/TShockAPI/DB/RegionManager.cs @@ -401,7 +401,41 @@ namespace TShockAPI.DB } return false; } + + /// + /// Renames a region + /// + /// Name of the region to rename + /// New name of the region + /// true if renamed successfully, false otherwise + public bool RenameRegion(string oldName, string newName) + { + Region region = null; + string worldID = Main.worldID.ToString(); + bool result = false; + + try + { + int q = database.Query("UPDATE Regions SET RegionName = @0 WHERE RegionName=@1 AND WorldID=@2", + newName, oldName, worldID); + + if (q > 0) + { + region = Regions.First(r => r.Name == oldName && r.WorldID == worldID); + region.Name = newName; + Hooks.RegionHooks.OnRegionRenamed(region, oldName, newName); + result = true; + } + } + catch (Exception ex) + { + TShock.Log.Error(ex.ToString()); + } + + return result; + } + /// /// Removes an allowed user from a region ///