Skip to content
Permalink
Browse files

avoid duplicating zadd/signadd permission check 4 times

  • Loading branch information...
UnknownShadow200 committed Sep 13, 2017
1 parent 5f714fb commit da084be7c95b5e6d8bbfab919eb354e4dac61d4c
Showing with 22 additions and 60 deletions.
  1. +22 −60 fCraft/Commands/ZoneCommands.cs
@@ -27,6 +27,24 @@ static class ZoneCommands {
const int maxDoorBlocks = 36; //change for max door area

#region ZoneAdd

static bool CheckZoneAdd( Player player, string type ) {
World playerWorld = player.World;
if( !player.Info.Rank.AllowSecurityCircumvention ) {
SecurityCheckResult buildCheck = playerWorld.BuildSecurity.CheckDetailed( player.Info );
switch( buildCheck ) {
case SecurityCheckResult.BlackListed:
player.Message( "Cannot add {1}s to world {0}&S: You are barred from building here.",
playerWorld.ClassyName, type );
return false;
case SecurityCheckResult.RankTooLow:
player.Message( "Cannot add {1}s to world {0}&S: You are not allowed to build here.",
playerWorld.ClassyName, type );
return false;
}
}
return true;
}

static readonly CommandDescriptor CdZoneAdd = new CommandDescriptor {
Name = "ZAdd",
@@ -49,20 +67,7 @@ static class ZoneCommands {
CdZoneAdd.PrintUsage( player );
return;
}

if( !player.Info.Rank.AllowSecurityCircumvention ) {
SecurityCheckResult buildCheck = playerWorld.BuildSecurity.CheckDetailed( player.Info );
switch( buildCheck ) {
case SecurityCheckResult.BlackListed:
player.Message( "Cannot add zones to world {0}&S: You are barred from building here.",
playerWorld.ClassyName );
return;
case SecurityCheckResult.RankTooLow:
player.Message( "Cannot add zones to world {0}&S: You are not allowed to build here.",
playerWorld.ClassyName );
return;
}
}
if( !CheckZoneAdd( player, "zone" ) ) return;

Zone newZone = new Zone();
ZoneCollection zoneCollection = player.WorldMap.Zones;
@@ -140,20 +145,7 @@ static class ZoneCommands {
static void ZoneAddCallback( Player player, Vector3I[] marks, object tag ) {
World playerWorld = player.World;
if( playerWorld == null ) PlayerOpException.ThrowNoWorld( player );

if( !player.Info.Rank.AllowSecurityCircumvention ) {
SecurityCheckResult buildCheck = playerWorld.BuildSecurity.CheckDetailed( player.Info );
switch( buildCheck ) {
case SecurityCheckResult.BlackListed:
player.Message( "Cannot add zones to world {0}&S: You are barred from building here.",
playerWorld.ClassyName );
return;
case SecurityCheckResult.RankTooLow:
player.Message( "Cannot add zones to world {0}&S: You are not allowed to build here.",
playerWorld.ClassyName );
return;
}
}
if( !CheckZoneAdd( player, "zone" ) ) return;

Zone zone = (Zone)tag;
if (zone.Name.CaselessStarts(SpecialZone.Checkpoint))
@@ -209,22 +201,7 @@ static void SignAddHandler(Player player, CommandReader cmd)
CdSignAdd.PrintUsage(player); return;
}
string givenZoneName = SpecialZone.Sign + cmd.Next();

if (!player.Info.Rank.AllowSecurityCircumvention)
{
SecurityCheckResult buildCheck = playerWorld.BuildSecurity.CheckDetailed(player.Info);
switch (buildCheck)
{
case SecurityCheckResult.BlackListed:
player.Message("Cannot add zones to world {0}&S: You are barred from building here.",
playerWorld.ClassyName);
return;
case SecurityCheckResult.RankTooLow:
player.Message("Cannot add zones to world {0}&S: You are not allowed to build here.",
playerWorld.ClassyName);
return;
}
}
if( !CheckZoneAdd( player, "sign" ) ) return;

Zone newZone = new Zone();
ZoneCollection zoneCollection = player.WorldMap.Zones;
@@ -279,22 +256,7 @@ static void SignAddCallback(Player player, Vector3I[] marks, object tag)
{
World playerWorld = player.World;
if (playerWorld == null) PlayerOpException.ThrowNoWorld(player);

if (!player.Info.Rank.AllowSecurityCircumvention)
{
SecurityCheckResult buildCheck = playerWorld.BuildSecurity.CheckDetailed(player.Info);
switch (buildCheck)
{
case SecurityCheckResult.BlackListed:
player.Message("Cannot add Sign to world {0}&S: You are barred from building here.",
playerWorld.ClassyName);
return;
case SecurityCheckResult.RankTooLow:
player.Message("Cannot add Sign to world {0}&S: You are not allowed to build here.",
playerWorld.ClassyName);
return;
}
}
if( !CheckZoneAdd( player, "sign" ) ) return;

Zone zone = (Zone)tag;
var zones = player.WorldMap.Zones;

0 comments on commit da084be

Please sign in to comment.
You can’t perform that action at this time.