Skip to content

Commit 24291d0

Browse files
authored
Make the height that is protected configurable as well. (#402)
* Add the ability to protect an area surrounding the flag from building, to prevent abuse when the editable materials feature is used. Closes #398. * Also make the height that is protected configurable. * Fix line length
1 parent 9d27300 commit 24291d0

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

src/main/java/io/github/townyadvanced/flagwar/config/FlagWarConfig.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,13 @@ public static int getFlagAreaProtectedSize() {
578578
return PLUGIN.getConfig().getInt("warzone.protected_area_surrounding_flag");
579579
}
580580

581+
/**
582+
* @return the height of the protection area surrounding the flag.
583+
*/
584+
public static int getFlagAreaProtectedHeight() {
585+
return PLUGIN.getConfig().getInt("warzone.protected_area_above_flag");
586+
}
587+
581588
/** @return whether nations are allowed to toggle neutral.*/
582589
public static boolean isDeclaringNeutralAllowed() {
583590
return PLUGIN.getConfig().getBoolean("rules.nations_can_toggle_neutral");

src/main/java/io/github/townyadvanced/flagwar/listeners/WarzoneListener.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,7 @@ public void onBuild(final TownyBuildEvent townyBuildEvent) {
9797
return;
9898
}
9999

100-
if (isTooCloseToTheFlag(status, townyBuildEvent)) {
101-
return;
102-
}
103-
104-
if (!FlagWarConfig.isEditableMaterialInWarZone(mat)) {
100+
if (!FlagWarConfig.isEditableMaterialInWarZone(mat) || isTooCloseToTheFlag(status, townyBuildEvent)) {
105101
townyBuildEvent.setCancelled(true);
106102
townyBuildEvent.setCancelMessage(msgCannotEdit("build", mat));
107103
return;
@@ -273,8 +269,9 @@ private boolean isTooCloseToTheFlag(final TownBlockStatus townBlockStatus,
273269
Location blockLoc = townyActionEvent.getLocation();
274270
CellUnderAttack cellData = FlagWarAPI.getAttackData(Cell.parse(blockLoc));
275271
Location flagLoc = cellData.getFlagBaseBlock().getLocation();
276-
// We don't care if the flag is above the block being placed.
277-
if (blockLoc.getY() < flagLoc.getY()) {
272+
// We don't care if the flag is above the block being placed, or if the block is too high above the flag.
273+
if (blockLoc.getY() < flagLoc.getY()
274+
|| (blockLoc.getY() - flagLoc.getY()) > FlagWarConfig.getFlagAreaProtectedHeight()) {
278275
return false;
279276
}
280277
// Set the y value to the flag y value so we compare only the horizontal distance.

src/main/resources/config.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,8 @@ warzone:
160160

161161
# The space around the flag where editable materials cannot be used.
162162
protected_area_surrounding_flag: 0
163+
# The space above the flag where editable materials cannot be used.
164+
protected_area_above_flag: 20
163165
extra:
164166
# If enabled, show additional debug messages as warnings. Recommended keeping these disabled unless requested.
165167
debug: false

0 commit comments

Comments
 (0)