diff --git a/CHANGELOG.md b/CHANGELOG.md
index 99fb71bb..432f6b2d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -71,7 +71,8 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin
* Removed `Utils.ActivePlayers()` -- use `TShock.Players.Length` instead. (@hakusaro)
* Moved `Utils.Kick()` to `TSPlayer` since its first argument was a `TSPlayer` object. (@hakusaro)
* Removed `Utils.ForceKick()`. (@hakusaro)
-* removed `Utils.GetPlayerIP()`. (@hakusaro)
+* Removed `Utils.GetPlayerIP()`. (@hakusaro)
+* Moved `Utils.Ban()` to `TSPlayer.Ban()`. (@hakusaro)
## TShock 4.3.25
* Fixed a critical exploit in the Terraria protocol that could cause massive unpreventable world corruption as well as a number of other problems. Thanks to @bartico6 for reporting. Fixed by the efforts of @QuiCM, @hakusaro, and tips in the right directioon from @bartico6.
diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs
index 320affd9..9de92643 100644
--- a/TShockAPI/GetDataHandlers.cs
+++ b/TShockAPI/GetDataHandlers.cs
@@ -2384,7 +2384,7 @@ namespace TShockAPI
{
if (TShock.Config.BanOnHardcoreDeath)
{
- if (!TShock.Utils.Ban(args.Player, TShock.Config.HardcoreBanReason, false, "hardcore-death"))
+ if (!args.Player.Ban(TShock.Config.HardcoreBanReason, false, "hardcore-death"))
args.Player.Kick("You died! Normally, you'd be banned.", true, true);
}
else
@@ -2448,7 +2448,7 @@ namespace TShockAPI
{
if (TShock.Config.BanOnMediumcoreDeath)
{
- if (!TShock.Utils.Ban(args.Player, TShock.Config.MediumcoreBanReason, false, "mediumcore-death"))
+ if (!args.Player.Ban(TShock.Config.MediumcoreBanReason, false, "mediumcore-death"))
args.Player.Kick("You died! Normally, you'd be banned.", true, true);
}
else
diff --git a/TShockAPI/TSPlayer.cs b/TShockAPI/TSPlayer.cs
index bf7d776c..d38066ce 100644
--- a/TShockAPI/TSPlayer.cs
+++ b/TShockAPI/TSPlayer.cs
@@ -1574,6 +1574,32 @@ namespace TShockAPI
return false;
}
+ ///
+ /// Bans and disconnects the player from the server.
+ ///
+ /// The reason to be displayed to the server.
+ /// If the ban should bypass immunity to ban checks.
+ /// The player who initiated the ban.
+ public bool Ban(string reason, bool force = false, string adminUserName = null)
+ {
+ if (!ConnectionAlive)
+ return true;
+ if (force || !HasPermission(Permissions.immunetoban))
+ {
+ string ip = IP;
+ string uuid = UUID;
+ TShock.Bans.AddBan(ip, Name, uuid, "", reason, false, adminUserName);
+ Disconnect(string.Format("Banned: {0}", reason));
+ string verb = force ? "force " : "";
+ if (string.IsNullOrWhiteSpace(adminUserName))
+ TSPlayer.All.SendInfoMessage("{0} was {1}banned for '{2}'.", Name, verb, reason);
+ else
+ TSPlayer.All.SendInfoMessage("{0} {1}banned {2} for '{3}'.", adminUserName, verb, Name, reason);
+ return true;
+ }
+ return false;
+ }
+
[Conditional("DEBUG")]
private void LogStackFrame()
{
diff --git a/TShockAPI/Utils.cs b/TShockAPI/Utils.cs
index 642c109c..5e5e7580 100644
--- a/TShockAPI/Utils.cs
+++ b/TShockAPI/Utils.cs
@@ -507,34 +507,6 @@ namespace TShockAPI
Hooks.GeneralHooks.OnReloadEvent(player);
}
- ///
- /// Bans and kicks a player from the server.
- ///
- /// TSPlayer player
- /// string reason
- /// bool force (default: false)
- /// string adminUserName (default: null)
- public bool Ban(TSPlayer player, string reason, bool force = false, string adminUserName = null)
- {
- if (!player.ConnectionAlive)
- return true;
- if (force || !player.HasPermission(Permissions.immunetoban))
- {
- string ip = player.IP;
- string uuid = player.UUID;
- string playerName = player.Name;
- TShock.Bans.AddBan(ip, playerName, uuid, "", reason, false, adminUserName);
- player.Disconnect(string.Format("Banned: {0}", reason));
- string verb = force ? "force " : "";
- if (string.IsNullOrWhiteSpace(adminUserName))
- TSPlayer.All.SendInfoMessage("{0} was {1}banned for '{2}'.", playerName, verb, reason);
- else
- TSPlayer.All.SendInfoMessage("{0} {1}banned {2} for '{3}'.", adminUserName, verb, playerName, reason);
- return true;
- }
- return false;
- }
-
/// HasBanExpired - Returns whether or not a ban has expired or not.
/// ban - The ban object to check.
/// byName - Defines whether or not the ban should be checked by name.