Skip to content

Commit a556bce

Browse files
Add MaxBarricadeHeight and MaxStructureHeight options
1 parent debe31a commit a556bce

File tree

4 files changed

+39
-2
lines changed

4 files changed

+39
-2
lines changed

BuildingRestrictions/BuildingRestrictions.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<TargetFramework>net48</TargetFramework>
55
<LangVersion>latest</LangVersion>
66
<RootNamespace>RestoreMonarchy.BuildingRestrictions</RootNamespace>
7-
<Version>1.0.0</Version>
7+
<Version>1.1.0</Version>
88
</PropertyGroup>
99

1010
<ItemGroup>

BuildingRestrictions/BuildingRestrictionsConfiguration.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ public class BuildingRestrictionsConfiguration : IRocketPluginConfiguration
1818
public int MaxStructures { get; set; }
1919
public bool BypassAdmin { get; set; }
2020

21+
public bool EnableMaxBarricadeHeight { get; set; } = false;
22+
public float MaxBarricadeHeight { get; set; } = 100;
23+
public bool EnableMaxStructureHeight { get; set; } = false;
24+
public float MaxStructureHeight { get; set; } = 100;
25+
2126
[XmlArrayItem("Barricade")]
2227
public BuildingRestriction[] Barricades { get; set; }
2328
[XmlArrayItem("Structure")]
@@ -36,6 +41,12 @@ public void LoadDefaults()
3641
EnableMaxStructures = false;
3742
MaxStructures = 150;
3843
BypassAdmin = false;
44+
45+
EnableMaxBarricadeHeight = false;
46+
MaxBarricadeHeight = 100;
47+
EnableMaxStructureHeight = false;
48+
MaxStructureHeight = 100;
49+
3950
Barricades =
4051
[
4152
new("sentries", 0, EBuild.SENTRY.ToString(), null, 5),

BuildingRestrictions/BuildingRestrictionsPlugin.cs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ protected override void Unload()
7676
{ "PlayerBuildingStats", "{0} have placed {1}{2} barricades and {3}{4} structures, so in total {5}{6} buildings." },
7777
{ "BuildingStats", "{0} players have built {1} barricades and {2} structures, so in total {3} buildings." },
7878
{ "PlayerNotFound", "Player {0} not found." },
79-
{ "BuildingStatsOtherNoPermission", "You don't have permission to check other player building stats." }
79+
{ "BuildingStatsOtherNoPermission", "You don't have permission to check other player building stats." },
80+
{ "MaxBarricadeHeightRestriction", "You can't build {0} because it's higher than max {1}m height above the ground." },
81+
{ "MaxStructureHeightRestriction", "You can't build {0} because it's higher than max {1}m height above the ground." }
8082
};
8183

8284
private void OnLevelLoaded(int level)
@@ -177,6 +179,15 @@ private void OnDeployBarricadeRequested(Barricade barricade, ItemBarricadeAsset
177179
return;
178180
}
179181

182+
float groundHeight = LevelGround.getHeight(point);
183+
float barricadeHeight = point.y - groundHeight;
184+
if (Configuration.Instance.EnableMaxBarricadeHeight && barricadeHeight > Configuration.Instance.MaxBarricadeHeight)
185+
{
186+
SendMessageToPlayer(unturnedPlayer, "MaxBarricadeHeightRestriction", asset.itemName, Configuration.Instance.MaxBarricadeHeight.ToString("N0"));
187+
shouldAllow = false;
188+
return;
189+
}
190+
180191
decimal multiplier = GetPlayerBuildingsMultiplier(unturnedPlayer);
181192
PlayerBuildings playerBuildings = Database.GetPlayerBuildings(owner);
182193

@@ -263,6 +274,15 @@ private void OnDeployStructureRequested(Structure structure, ItemStructureAsset
263274
return;
264275
}
265276

277+
float groundHeight = LevelGround.getHeight(point);
278+
float structureHeight = point.y - groundHeight;
279+
if (Configuration.Instance.EnableMaxStructureHeight && structureHeight > Configuration.Instance.MaxStructureHeight)
280+
{
281+
SendMessageToPlayer(unturnedPlayer, "MaxStructureHeightRestriction", asset.itemName, Configuration.Instance.MaxStructureHeight.ToString("N0"));
282+
shouldAllow = false;
283+
return;
284+
}
285+
266286
decimal multiplier = GetPlayerBuildingsMultiplier(unturnedPlayer);
267287
PlayerBuildings playerBuildings = Database.GetPlayerBuildings(owner);
268288

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ FORTIFICATION, BARRICADE, DOOR, GATE, BED, LADDER, STORAGE, FARM, TORCH, CAMPFIR
3636
<EnableMaxStructures>false</EnableMaxStructures>
3737
<MaxStructures>150</MaxStructures>
3838
<BypassAdmin>false</BypassAdmin>
39+
<EnableMaxBarricadeHeight>false</EnableMaxBarricadeHeight>
40+
<MaxBarricadeHeight>100</MaxBarricadeHeight>
41+
<EnableMaxStructureHeight>false</EnableMaxStructureHeight>
42+
<MaxStructureHeight>100</MaxStructureHeight>
3943
<Barricades>
4044
<Barricade Name="sentries" Build="SENTRY" Max="5" />
4145
<Barricade Name="stereos" Build="STEREO" Max="1" />
@@ -65,5 +69,7 @@ FORTIFICATION, BARRICADE, DOOR, GATE, BED, LADDER, STORAGE, FARM, TORCH, CAMPFIR
6569
<Translation Id="BuildingStats" Value="{0} players have built {1} barricades and {2} structures, so in total {3} buildings." />
6670
<Translation Id="PlayerNotFound" Value="Player {0} not found." />
6771
<Translation Id="BuildingStatsOtherNoPermission" Value="You don't have permission to check other player building stats." />
72+
<Translation Id="MaxBarricadeHeightRestriction" Value="You can't build {0} because it's higher than max {1}m height above the ground." />
73+
<Translation Id="MaxStructureHeightRestriction" Value="You can't build {0} because it's higher than max {1}m height above the ground." />
6874
</Translations>
6975
```

0 commit comments

Comments
 (0)