Java Reference
In-Depth Information
List <Player> list = Canary.getServer().getPlayerList();
Player closestPlayer = null;
double minDistance = -1;
for ( int i = 0; i < list.size(); i++) {
Player p = list.get(i);
Location ploc = p.getLocation();
if ( Math .abs(ploc.getY() - loc.getY()) < 15) {
double dist = distance(loc, ploc);
if (dist < minDistance || minDistance == -1) {
minDistance = dist;
closestPlayer = p;
}
}
}
return closestPlayer;
}
//
// Find the distance on the ground (ignores height)
// between two Locations
//
public double distance(Location loc1, Location loc2) {
return Math .sqrt(
Math .pow(loc1.getX() - loc2.getX(), 2) +
Math .pow(loc1.getZ() - loc2.getZ(), 2)
);
}
// Explode yourself
public void explode() {
plugin.cowDied(cow); // notify parent
Location cowLoc = cow.getLocation();
cow.getWorld().makeExplosion(cow,
cowLoc.getX(), cowLoc.getY(), cowLoc.getZ(),
3.0f, true);
removeMe();
}
// We are all done, either from chunk unload or explosion
public void removeMe() {
cow.kill();
Canary.getServer().removeSynchronousTask(this);
}
// Jump this cow toward the target
public void jump(Location target) {
Location cowLoc = cow.getLocation();
double multFactor = 0.075;
Vector3D v = new Vector3D(
(target.getX() - cowLoc.getX()) * multFactor,
0.8,
 
 
Search WWH ::




Custom Search