Optimized getClosestPlayer
This commit is contained in:
Binary file not shown.
@@ -51,9 +51,6 @@ public class MASpawnThread implements Runnable
|
|||||||
|
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
// Make a new ArrayList with all the players for fast lookup
|
|
||||||
playerList = new ArrayList<Player>(ArenaManager.playerSet);
|
|
||||||
|
|
||||||
// Check if we need to grant more rewards with the recurrent waves.
|
// Check if we need to grant more rewards with the recurrent waves.
|
||||||
for (Integer i : ArenaManager.everyWaveMap.keySet())
|
for (Integer i : ArenaManager.everyWaveMap.keySet())
|
||||||
{
|
{
|
||||||
@@ -215,9 +212,9 @@ public class MASpawnThread implements Runnable
|
|||||||
public static Player getClosestPlayer(Entity e)
|
public static Player getClosestPlayer(Entity e)
|
||||||
{
|
{
|
||||||
// Grab the coordinates.
|
// Grab the coordinates.
|
||||||
double ex = e.getLocation().getX();
|
double x = e.getLocation().getX();
|
||||||
double ey = e.getLocation().getY();
|
double y = e.getLocation().getY();
|
||||||
double ez = e.getLocation().getZ();
|
double z = e.getLocation().getZ();
|
||||||
|
|
||||||
// Set up the comparison variable and the result.
|
// Set up the comparison variable and the result.
|
||||||
double current = Double.POSITIVE_INFINITY;
|
double current = Double.POSITIVE_INFINITY;
|
||||||
@@ -225,12 +222,10 @@ public class MASpawnThread implements Runnable
|
|||||||
|
|
||||||
/* Iterate through the ArrayList, and update current and result every
|
/* Iterate through the ArrayList, and update current and result every
|
||||||
* time a squared distance smaller than current is found. */
|
* time a squared distance smaller than current is found. */
|
||||||
for (int i = 0; i < playerList.size(); i++)
|
for (Player p : ArenaManager.playerSet)
|
||||||
{
|
{
|
||||||
Player p = playerList.get(i);
|
double dist = distance(p.getLocation(), x, y, z);
|
||||||
double dist = distance(p.getLocation(), ex, ey, ez);
|
if (dist < current)
|
||||||
|
|
||||||
if (dist < current || current == -1.0D)
|
|
||||||
{
|
{
|
||||||
current = dist;
|
current = dist;
|
||||||
result = p;
|
result = p;
|
||||||
|
|||||||
Reference in New Issue
Block a user