Skip to content

Instantly share code, notes, and snippets.

@rafaeltab
Created December 9, 2017 21:52
Show Gist options
  • Save rafaeltab/48d2f8e71ea1092939d5226ba5ec6502 to your computer and use it in GitHub Desktop.
Save rafaeltab/48d2f8e71ea1092939d5226ba5ec6502 to your computer and use it in GitHub Desktop.
import java.util.HashMap;
import java.util.Map;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
public class Sort {
//Sorry ik ben eigenwijs geweest en heb ook nog een range toegevoegd
public Map<Entity, Double> findNear(int range, Player player){
Map<Entity, Double> map = new HashMap<Entity, Double>();
for(Entity entity : player.getWorld().getEntities()) {
float distance = (float)Math.sqrt(((float) Math.pow((player.getLocation().getX() - entity.getLocation().getX()), 2) + Math.pow((player.getLocation().getY() - entity.getLocation().getY()), 2) + Math.pow((player.getLocation().getZ() - entity.getLocation().getZ()), 2)));
if(distance < range) {
map.put(entity, (double) distance);
}
}
return map;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment