Added square method to remove ugly code.

This commit is contained in:
Jitse Boonstra
2020-04-15 22:24:01 +02:00
parent 4ae99ba9d5
commit 900451b053
@@ -129,7 +129,7 @@ public class PlayerListener implements Listener {
double distanceSquared = location.distanceSquared(npc.getLocation()); double distanceSquared = location.distanceSquared(npc.getLocation());
int tempRange = Bukkit.getViewDistance() << 4; int tempRange = Bukkit.getViewDistance() << 4;
boolean inRange = distanceSquared <= (hideDistance * hideDistance) && distanceSquared <= (tempRange * tempRange); // Avoids Math.pow due to how intensive it is. Could make a static utility function for it. boolean inRange = distanceSquared <= square(hideDistance) && distanceSquared <= square(tempRange);
if (npc.getAutoHidden().contains(player.getUniqueId())) { if (npc.getAutoHidden().contains(player.getUniqueId())) {
// Check if the player and NPC are within the range to sendShowPackets it again. // Check if the player and NPC are within the range to sendShowPackets it again.
if (inRange) { if (inRange) {
@@ -145,4 +145,9 @@ public class PlayerListener implements Listener {
} }
} }
} }
// Avoiding Math.pow due to how resource intensive it is.
private double square(double val) {
return val * val;
}
} }