From 1377d3db51efb403d5ab9485cc481130f1ce7c91 Mon Sep 17 00:00:00 2001 From: Llm Dl Date: Tue, 23 Nov 2021 16:22:46 -0600 Subject: [PATCH] Split vertical distance requirements surrounding capping into separate up and down values. New Config Options: - war.siege.distances.banner_control_vertical_distance_blocks_up", - 16 - This is the vertical distance a soldier must be within above the Banner. - Note that the horizontal distance is always the same as the Towny townblock size. - war.siege.distances.banner_control_vertical_distance_blocks_down", - 4 - This is the vertical distance a soldier must be within below the Banner. - Note that the horizontal distance is always the same as the Towny townblock size. Removed Config Option: war.siege.distances.banner_control_vertical_distance_blocks Closes #405. --- .../siegewar/settings/ConfigNodes.java | 12 +++++++++--- .../siegewar/settings/SiegeWarSettings.java | 8 ++++++-- .../utils/SiegeWarBannerControlUtil.java | 3 ++- .../siegewar/utils/SiegeWarDistanceUtil.java | 19 +++++++++++-------- src/main/resources/english.yml | 2 +- src/main/resources/french.yml | 2 +- 6 files changed, 30 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/gmail/goosius/siegewar/settings/ConfigNodes.java b/src/main/java/com/gmail/goosius/siegewar/settings/ConfigNodes.java index b24ffa342..53256bc1d 100644 --- a/src/main/java/com/gmail/goosius/siegewar/settings/ConfigNodes.java +++ b/src/main/java/com/gmail/goosius/siegewar/settings/ConfigNodes.java @@ -417,11 +417,17 @@ public enum ConfigNodes { "# The radius of the 'siege zone'.", "# This radius applies only horizontally, so players can never get above a siegezone (e.g. to place lava there or something).", "# Various siege related effects can apply in this zone e.g. lose points on death, keep inv on death, cannot claim here."), - WAR_SIEGE_BANNER_CONTROL_VERTICAL_DISTANCE_BLOCKS( - "war.siege.distances.banner_control_vertical_distance_blocks", + WAR_SIEGE_BANNER_CONTROL_VERTICAL_DISTANCE_UP_BLOCKS( + "war.siege.distances.banner_control_vertical_distance_blocks_up", "16", "", - "# This is the vertical distance a soldier must be from the banner to get banner control.", + "# This is the vertical distance a soldier must be within above the Banner.", + "# Note that the horizontal distance is always the same as the Towny townblock size."), + WAR_SIEGE_BANNER_CONTROL_VERTICAL_DISTANCE_DOWN_BLOCKS( + "war.siege.distances.banner_control_vertical_distance_blocks_down", + "4", + "", + "# This is the vertical distance a soldier must be within below the Banner.", "# Note that the horizontal distance is always the same as the Towny townblock size."), WAR_SIEGE_SCORING( "war.siege.scoring", diff --git a/src/main/java/com/gmail/goosius/siegewar/settings/SiegeWarSettings.java b/src/main/java/com/gmail/goosius/siegewar/settings/SiegeWarSettings.java index 9c1351baa..f49a86971 100644 --- a/src/main/java/com/gmail/goosius/siegewar/settings/SiegeWarSettings.java +++ b/src/main/java/com/gmail/goosius/siegewar/settings/SiegeWarSettings.java @@ -422,8 +422,12 @@ public static int getWarCommonPeacefulTownsNewTownConfirmationRequirementDays() return Settings.getInt(ConfigNodes.PEACEFUL_TOWNS_NEW_TOWN_CONFIRMATION_REQUIREMENT_DAYS); } - public static int getBannerControlVerticalDistanceBlocks() { - return Settings.getInt(ConfigNodes.WAR_SIEGE_BANNER_CONTROL_VERTICAL_DISTANCE_BLOCKS); + public static int getBannerControlVerticalDistanceUpBlocks() { + return Settings.getInt(ConfigNodes.WAR_SIEGE_BANNER_CONTROL_VERTICAL_DISTANCE_UP_BLOCKS); + } + + public static int getBannerControlVerticalDistanceDownBlocks() { + return Settings.getInt(ConfigNodes.WAR_SIEGE_BANNER_CONTROL_VERTICAL_DISTANCE_DOWN_BLOCKS); } public static boolean getWarCommonPeacefulTownsAllowedToTogglePVP() { diff --git a/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarBannerControlUtil.java b/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarBannerControlUtil.java index ccf60d427..5f189e4b9 100644 --- a/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarBannerControlUtil.java +++ b/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarBannerControlUtil.java @@ -117,7 +117,8 @@ private static void addNewBannerControlSession(Siege siege, final Player player, Messaging.sendMsg(player, String.format( Translation.of(messageKey), TownySettings.getTownBlockSize(), - SiegeWarSettings.getBannerControlVerticalDistanceBlocks(), + SiegeWarSettings.getBannerControlVerticalDistanceUpBlocks(), + SiegeWarSettings.getBannerControlVerticalDistanceDownBlocks(), sessionDurationText)); //Notify player in action bar diff --git a/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarDistanceUtil.java b/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarDistanceUtil.java index 3ce082046..1f5381f7a 100644 --- a/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarDistanceUtil.java +++ b/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarDistanceUtil.java @@ -11,6 +11,7 @@ import com.palmergames.bukkit.towny.object.TownBlock; import com.palmergames.bukkit.towny.object.TownyWorld; import com.palmergames.bukkit.towny.object.WorldCoord; +import com.palmergames.util.MathUtil; import org.bukkit.Location; import org.bukkit.block.Block; @@ -86,7 +87,7 @@ public static boolean isInSiegeZone(Entity entity, Siege siege) { } public static boolean isInTimedPointZone(Location location, Siege siege) { - return areLocationsClose(location, siege.getFlagLocation(), TownySettings.getTownBlockSize(), SiegeWarSettings.getBannerControlVerticalDistanceBlocks()); + return areLocationsClose(location, siege.getFlagLocation(), TownySettings.getTownBlockSize()); } public static boolean areTownsClose(Town town1, Town town2, int radiusTownblocks) { @@ -116,18 +117,21 @@ private static boolean areCoordsClose(TownyWorld world1, Coord coord1, TownyWorl return distanceTownblocks < radiusTownblocks; } - private static boolean areLocationsClose(Location location1, Location location2, int maxHorizontalDistance, int maxVerticalDistance) { + private static boolean areLocationsClose(Location location1, Location location2, int maxHorizontalDistance) { if(!location1.getWorld().getName().equalsIgnoreCase(location2.getWorld().getName())) return false; //Check horizontal distance - double xzDistance = Math.sqrt(Math.pow(location1.getX() - location2.getX(), 2) + Math.pow(location1.getZ() - location2.getZ(), 2)); + double xzDistance = MathUtil.distance(location1.getX(), location2.getX(), location1.getZ(), location2.getZ()); if(xzDistance > maxHorizontalDistance) return false; //Check vertical distance - double yDistance = Math.abs(Math.abs(location1.getY() - location2.getY())); - if(yDistance > maxVerticalDistance) + if (location1.getY() == location2.getY()) + return true; + if (location1.getY() > location2.getY() && location1.getY() - location2.getY() > SiegeWarSettings.getBannerControlVerticalDistanceUpBlocks()) + return false; + if (location2.getY() > location1.getY() && location2.getY() - location1.getY() > SiegeWarSettings.getBannerControlVerticalDistanceDownBlocks()) return false; return true; @@ -139,8 +143,7 @@ public static boolean areLocationsCloseHorizontally(Location location1, Location return false; //Check horizontal distance - double xzDistance = Math.sqrt(Math.pow(location1.getX() - location2.getX(), 2) + Math.pow(location1.getZ() - location2.getZ(), 2)); - return xzDistance < radius; + return MathUtil.distance(location1.getX(), location2.getX(), location1.getZ(), location2.getZ()) < radius; } private static Location getTopNorthWestCornerLocation(WorldCoord worldCoord) { @@ -188,6 +191,6 @@ public static boolean campTooClose(Location location) { * @param camp {@link SiegeCamp} to check against. */ public static boolean isInSiegeCampZone(Location location, SiegeCamp camp) { - return areLocationsClose(location, camp.getBannerBlock().getLocation(), TownySettings.getTownBlockSize(), SiegeWarSettings.getBannerControlVerticalDistanceBlocks()); + return areLocationsClose(location, camp.getBannerBlock().getLocation(), TownySettings.getTownBlockSize()); } } diff --git a/src/main/resources/english.yml b/src/main/resources/english.yml index d663f3221..bd7f3ea7a 100644 --- a/src/main/resources/english.yml +++ b/src/main/resources/english.yml @@ -240,7 +240,7 @@ msg_siege_war_version: '&bThe current SiegeWar version is: %s.' #Added in 0.14 msg_err_cannot_alter_blocks_below_banner_in_timed_point_zone: 'You cannot place/destroy blocks below banner altitude in the timed point zone.' msg_siege_war_banner_control_session_started: '&bBanner control session started. Remain close to the siege-banner (%d blocks horizonally, %d blocks vertically), not in the town, and not flying, for %s. If your session succeeds, you will gain banner control for your side (or be added to the banner control list).' -msg_siege_war_banner_control_session_started_with_altitude: '&bBanner control session started. Remain close to the siege-banner (%d blocks horizonally, %d blocks vertically), not below its altitude, not in the town, and not flying, for %s. If your session succeeds, you will gain banner control for your side (or be added to the banner control list).' +msg_siege_war_banner_control_session_started_with_altitude: '&bBanner control session started. Remain close to the siege-banner (%d blocks horizonally, %d blocks above, %d blocks below), not below its altitude, not in the town, and not flying, for %s. If your session succeeds, you will gain banner control for your side (or be added to the banner control list).' msg_siege_war_banner_control_session_failure: '&cBanner control session failed!. Common causes for this include: dying, going too far from the banner, going into the town, or flying.' msg_siege_war_banner_control_session_failure_with_altitude: '&cBanner control session failed!. Common causes for this include: dying, going too far from the banner, going below the altitude of the banner, going into the town, or flying.' diff --git a/src/main/resources/french.yml b/src/main/resources/french.yml index 96fd214f3..fca2363bf 100644 --- a/src/main/resources/french.yml +++ b/src/main/resources/french.yml @@ -250,7 +250,7 @@ msg_swa_set_siege_balance_success: '&bSuccessfully set siege balance to %d for % #Added in 0.14 msg_err_cannot_alter_blocks_below_banner_in_timed_point_zone: 'You cannot place/destroy blocks below banner altitude in the timed point zone.' msg_siege_war_banner_control_session_started: '&bBanner control session started. Remain close to the siege-banner (%d blocks horizonally, %d blocks vertically), not in the town, and not flying, for %s. If your session succeeds, you will gain banner control for your side (or be added to the banner control list).' -msg_siege_war_banner_control_session_started_with_altitude: '&bBanner control session started. Remain close to the siege-banner (%d blocks horizonally, %d blocks vertically), not below its altitude, not in the town, and not flying, for %s. If your session succeeds, you will gain banner control for your side (or be added to the banner control list).' +msg_siege_war_banner_control_session_started_with_altitude: '&bBanner control session started. Remain close to the siege-banner (%d blocks horizonally, %d blocks above, %d blocks below), not below its altitude, not in the town, and not flying, for %s. If your session succeeds, you will gain banner control for your side (or be added to the banner control list).' msg_siege_war_banner_control_session_failure: '&cBanner control session failed!. Common causes for this include: dying, going too far from the banner, going into the town, or flying.' msg_siege_war_banner_control_session_failure_with_altitude: '&cBanner control session failed!. Common causes for this include: dying, going too far from the banner, going below the altitude of the banner, going into the town, or flying.'