Skip to content

Commit

Permalink
fix legacy and catch possible exception
Browse files Browse the repository at this point in the history
  • Loading branch information
xGinko committed Aug 5, 2024
1 parent e68f123 commit 8a5dd99
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,13 @@ private void onEntityTargetAcquire(EntityTargetEvent event) {
return;
}

double targetDistanceSquared = event.getEntity().getLocation().distanceSquared(targetEntity.getLocation());
double targetDistanceSquared;
try {
targetDistanceSquared = event.getEntity().getLocation().distanceSquared(targetEntity.getLocation());
} catch (IllegalArgumentException e) {
if (logIsEnabled) error("Unable to measure distance between entity and target.", e);
return;
}

if (globalDistanceEnabled) {
if (targetDistanceSquared > globalMaxDistanceSquared) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,13 @@ private void onEntityPathfind(EntityPathfindEvent event) {
return;
}

double targetDistanceSquared = event.getEntity().getLocation().distanceSquared(event.getLoc());
double targetDistanceSquared;
try {
targetDistanceSquared = event.getEntity().getLocation().distanceSquared(event.getLoc());
} catch (IllegalArgumentException e) {
if (logIsEnabled) error("Unable to measure distance between entity and target.", e);
return;
}

if (globalDistanceEnabled) {
if (targetDistanceSquared > globalMaxDistanceSquared) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,13 @@ private void onEntityTargetAcquire(EntityTargetEvent event) {
return;
}

double targetDistanceSquared = event.getEntity().getLocation().distanceSquared(targetEntity.getLocation());
double targetDistanceSquared;
try {
targetDistanceSquared = event.getEntity().getLocation().distanceSquared(targetEntity.getLocation());
} catch (IllegalArgumentException e) {
if (logIsEnabled) error("Unable to measure distance between entity and target.", e);
return;
}

if (globalDistanceEnabled) {
if (targetDistanceSquared > globalMaxDistanceSquared) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,21 @@ public Pathfinding() {
14.0,
120.0
);
this.config.addComment(configPath+".enable", """
Limits entities deciding to pathfind to a specific location\s
within a configurable radius and timeframe to help reduce lag\s
by cancelling burst activity hotspots.""");
this.limit = config.getInt(configPath + ".entity-pathfind-event-limit", 512, """
Maximum number of times an entity can decide to start moving\s
towards a location within the configured timeframe before the\s
area will be put on cooldown.""");
this.config.addComment(configPath+".enable",
"Limits entities deciding to pathfind to a specific location\n" +
"within a configurable radius and timeframe to help reduce lag\n" +
"by cancelling burst activity hotspots.");
this.limit = config.getInt(configPath + ".entity-pathfind-event-limit", 512,
"Maximum number of times an entity can decide to start moving\n" +
"towards a location within the configured timeframe before the\n" +
"area will be put on cooldown.");

this.globalDistanceEnabled = config.getBoolean(configPath + ".distance-limit.global-limit.enable", false);
this.globalMaxDistanceSquared = NumberConversions.square(
config.getDouble(configPath + ".distance-limit.global-limit.max-target-distance", 20.0, """
The max distance no mob pathfinding should exceed.\s
You always want this to be higher than your highest max distance\s
for a specific mob."""));
config.getDouble(configPath + ".distance-limit.global-limit.max-target-distance", 20.0,
"The max distance no mob pathfinding should exceed.\n" +
"You always want this to be higher than your highest max distance\n" +
"for a specific mob."));

this.perTypeDistanceEnabled = config.getBoolean(configPath + ".distance-limit.custom-limits.enable", true);
Map<XEntityType, Double> defaults = new EnumMap<>(XEntityType.class);
Expand Down Expand Up @@ -102,7 +102,13 @@ private void onEntityPathfind(EntityPathfindEvent event) {
return;
}

double targetDistanceSquared = event.getEntity().getLocation().distanceSquared(event.getLoc());
double targetDistanceSquared;
try {
targetDistanceSquared = event.getEntity().getLocation().distanceSquared(event.getLoc());
} catch (IllegalArgumentException e) {
if (logIsEnabled) error("Unable to measure distance between entity and target.", e);
return;
}

if (globalDistanceEnabled) {
if (targetDistanceSquared > globalMaxDistanceSquared) {
Expand Down

0 comments on commit 8a5dd99

Please sign in to comment.