From aaa84d1ba9c010dae726b207a1dab6bfc0de518e Mon Sep 17 00:00:00 2001 From: koneko-nyan <31385587+koneko-nyan@users.noreply.github.com> Date: Mon, 2 Oct 2017 17:45:57 +0200 Subject: [PATCH] Add 'rename' sub-command to /region --- TShockAPI/Commands.cs | 46 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs index fbc6c061..615ba59f 100644 --- a/TShockAPI/Commands.cs +++ b/TShockAPI/Commands.cs @@ -4530,6 +4530,51 @@ namespace TShockAPI args.Player.SendErrorMessage("Invalid syntax! Proper syntax: {0}region resize ", Specifier); break; } + case "rename": + { + if (args.Parameters.Count != 3) + { + args.Player.SendErrorMessage("Invalid syntax! Proper syntax: {0}region rename ", Specifier); + break; + } + else + { + string oldName = args.Parameters[1]; + string newName = args.Parameters[2]; + + if (oldName == newName) + { + args.Player.SendErrorMessage("Error: both names are the same."); + break; + } + + Region oldRegion = TShock.Regions.GetRegionByName(oldName); + + if (oldRegion == null) + { + args.Player.SendErrorMessage("Invalid region \"{0}\".", oldName); + break; + } + + Region newRegion = TShock.Regions.GetRegionByName(newName); + + if (newRegion != null) + { + args.Player.SendErrorMessage("Region \"{0}\" already exists.", newName); + break; + } + + if(TShock.Regions.RenameRegion(oldName, newName)) + { + args.Player.SendInfoMessage("Region renamed successfully!"); + } + else + { + args.Player.SendErrorMessage("Failed to rename the region."); + } + } + break; + } case "tp": { if (!args.Player.HasPermission(Permissions.tp)) @@ -4570,6 +4615,7 @@ namespace TShockAPI "define - Defines the region with the given name.", "delete - Deletes the given region.", "name [-u][-z][-p] - Shows the name of the region at the given point.", + "rename - Renames the given region.", "list - Lists all regions.", "resize - Resizes a region.", "allow - Allows a user to a region.",