Migrate most of CheckTilePermission to TSPlayer
TShock.CheckTilePermission(ply, x, y, paint) has been replaced with TSPlayer.HasPaintPermission and TSPlayer.HasBuildPermission respectively. These two methods dramatically simplify the logic required to process build permissions. Still todo after this commit: 1. Implement warnings for when a player fails a permission check on build. This is probably going to be accomplished by a default argument to the HasBuildPermission signature. 2. Create a variant that checks for ice tile permission and use like HasPaintPermission() so as to remove the other TShock.CheckTilePermission method. Annoyingly, all of the existing methods that start with Check seem to "check" if they player _doesn't_ have permission (true = no permission), which makes nearly every call negative.
This commit is contained in:
parent
fbfb509cc9
commit
195a23a7e5
4 changed files with 64 additions and 83 deletions
|
|
@ -1842,75 +1842,6 @@ namespace TShockAPI
|
|||
return false;
|
||||
}
|
||||
|
||||
/// <summary>CheckTilePermission - Checks to see if a player has the ability to modify a tile at a given position.</summary>
|
||||
/// <param name="player">player - The TSPlayer object.</param>
|
||||
/// <param name="tileX">tileX - The x coordinate of the tile.</param>
|
||||
/// <param name="tileY">tileY - The y coordinate of the tile.</param>
|
||||
/// <param name="paint">paint - Whether or not the tile is paint.</param>
|
||||
/// <returns>bool - True if the player should not be able to modify the tile.</returns>
|
||||
public static bool CheckTilePermission(TSPlayer player, int tileX, int tileY, bool paint = false)
|
||||
{
|
||||
if ((!paint && !player.HasPermission(Permissions.canbuild)) ||
|
||||
(paint && !player.HasPermission(Permissions.canpaint)))
|
||||
{
|
||||
if (((DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond) - player.BPm) > 2000)
|
||||
{
|
||||
if (paint)
|
||||
{
|
||||
player.SendErrorMessage("You do not have permission to paint!");
|
||||
}
|
||||
else
|
||||
{
|
||||
player.SendErrorMessage("You do not have permission to build!");
|
||||
}
|
||||
player.BPm = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!Regions.CanBuild(tileX, tileY, player))
|
||||
{
|
||||
if (((DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond) - player.RPm) > 2000)
|
||||
{
|
||||
player.SendErrorMessage("This region is protected from changes.");
|
||||
player.RPm = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if (Config.DisableBuild)
|
||||
{
|
||||
if (!player.HasPermission(Permissions.antibuild))
|
||||
{
|
||||
if (((DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond) - player.WPm) > 2000)
|
||||
{
|
||||
player.SendErrorMessage("The world is protected from changes.");
|
||||
player.WPm = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (Config.SpawnProtection)
|
||||
{
|
||||
if (!player.HasPermission(Permissions.editspawn))
|
||||
{
|
||||
if (Utils.IsInSpawn(tileX, tileY))
|
||||
{
|
||||
if (((DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond) - player.SPm) > 1000)
|
||||
{
|
||||
player.SendErrorMessage("Spawn is protected from changes.");
|
||||
player.SPm = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>Distance - Determines the distance between two vectors.</summary>
|
||||
/// <param name="value1">value1 - The first vector location.</param>
|
||||
/// <param name="value2">value2 - The second vector location.</param>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue