From 30475be268d1be3ddeb938ae56386d12f7f011a8 Mon Sep 17 00:00:00 2001 From: koneko-nyan <31385587+koneko-nyan@users.noreply.github.com> Date: Mon, 2 Oct 2017 17:42:22 +0200 Subject: [PATCH] Add RegionRename --- TShockAPI/DB/RegionManager.cs | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) 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 ///