Skip to content

Commit daa5cc5

Browse files
Don't allow making doors in worlds and zones you can't build in.
1 parent c325d75 commit daa5cc5

File tree

1 file changed

+35
-14
lines changed

1 file changed

+35
-14
lines changed

fCraft/Commands/ZoneCommands.cs

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,26 +1029,47 @@ static void DoorTestCallback(Player player, Vector3I[] marks, object tag) {
10291029
}
10301030

10311031
static void DoorAdd(Player player, Vector3I[] marks, object tag) {
1032-
int sx = Math.Min(marks[0].X, marks[1].X);
1033-
int ex = Math.Max(marks[0].X, marks[1].X);
1034-
int sy = Math.Min(marks[0].Y, marks[1].Y);
1035-
int ey = Math.Max(marks[0].Y, marks[1].Y);
1036-
int sh = Math.Min(marks[0].Z, marks[1].Z);
1037-
int eh = Math.Max(marks[0].Z, marks[1].Z);
1038-
1039-
int volume = (ex - sx + 1) * (ey - sy + 1) * (eh - sh + 1);
1040-
if (volume > maxDoorBlocks) {
1041-
player.Message("Doors are only allowed to be {0} blocks", maxDoorBlocks);
1032+
BoundingBox bounds = new BoundingBox(marks[0], marks[1]);
1033+
if (bounds.Volume > maxDoorBlocks) {
1034+
player.Message("Doors are only allowed to be up to {0} blocks in size", maxDoorBlocks);
1035+
return;
1036+
}
1037+
1038+
World world = player.World;
1039+
switch (world.BuildSecurity.CheckDetailed(player.Info)) {
1040+
case SecurityCheckResult.RankTooLow:
1041+
player.Message("&WYour rank is not allowed to build a door in this world.");
1042+
return;
1043+
case SecurityCheckResult.BlackListed:
1044+
player.Message( "&WYou are not allowed to build a door in this world." );
1045+
return;
1046+
}
1047+
1048+
Vector3I min = bounds.MinVertex, max = bounds.MaxVertex;
1049+
for (int z = min.Z; z <= max.Z; z++)
1050+
for (int y = min.Y; y <= max.Y; y++)
1051+
for (int x = min.X; x <= max.X; x++)
1052+
{
1053+
Vector3I coords = new Vector3I(x, y, z);
1054+
PermissionOverride perm = world.Map.Zones.Check(coords, player);
1055+
if (perm != PermissionOverride.Deny) continue;
1056+
1057+
Zone deniedZone = player.WorldMap.Zones.FindDenied(coords, player);
1058+
if (deniedZone != null) {
1059+
player.Message("&WYou are not allowed to build a door in zone \"{0}\".", deniedZone.Name);
1060+
} else {
1061+
player.Message("&WYou are not allowed to build a door here.");
1062+
}
10421063
return;
10431064
}
10441065

10451066
Zone door = (Zone)tag;
1046-
door.Create(new BoundingBox(marks[0], marks[1]), player.Info);
1067+
door.Create(bounds, player.Info);
10471068
player.WorldMap.Zones.Add(door);
10481069
Logger.Log(LogType.UserActivity, "{0} created door {1} (on world {2})", player.Name, door.Name, player.World.Name);
1049-
player.Message("Door created: {0}x{1}x{2}", door.Bounds.Dimensions.X,
1050-
door.Bounds.Dimensions.Y,
1051-
door.Bounds.Dimensions.Z);
1070+
player.Message("Door created: {0}x{1}x{2}", bounds.Dimensions.X,
1071+
bounds.Dimensions.Y,
1072+
bounds.Dimensions.Z);
10521073
}
10531074

10541075
#endregion

0 commit comments

Comments
 (0)