[Not Tested] Smelt Item EXP Source fix

exp is now given to the closest player, not just any
This commit is contained in:
ASangarin 2020-06-24 02:07:45 +02:00
parent 668856801d
commit 8506be5169

View File

@ -51,8 +51,19 @@ public class SmeltItemExperienceSource extends SpecificExperienceSource<ItemStac
} }
private Optional<Player> getNearbyPlayer(Location loc, double d) { private Optional<Player> getNearbyPlayer(Location loc, double d) {
double d2 = d * d; final double d2 = d * d;
return loc.getWorld().getPlayers().stream().filter(player -> player.getLocation().distanceSquared(loc) < d2).findAny(); final Player[] nearby = loc.getWorld().getPlayers().stream()
.filter(player -> player.getLocation().distanceSquared(loc) < d2).toArray(Player[]::new);
Player selected = null;
double lastDist = d2;
for(Player p : nearby) {
double currDist = p.getLocation().distance(loc);
if(currDist < lastDist) {
lastDist = currDist;
selected = p;
}
}
return Optional.ofNullable(selected);
} }
@Override @Override