From 8506be516978486e6d7527df6ac05883fe5096e2 Mon Sep 17 00:00:00 2001 From: ASangarin Date: Wed, 24 Jun 2020 02:07:45 +0200 Subject: [PATCH] [Not Tested] Smelt Item EXP Source fix exp is now given to the closest player, not just any --- .../source/SmeltItemExperienceSource.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/Indyuce/mmocore/api/experience/source/SmeltItemExperienceSource.java b/src/main/java/net/Indyuce/mmocore/api/experience/source/SmeltItemExperienceSource.java index 60ebf6c9..04015462 100644 --- a/src/main/java/net/Indyuce/mmocore/api/experience/source/SmeltItemExperienceSource.java +++ b/src/main/java/net/Indyuce/mmocore/api/experience/source/SmeltItemExperienceSource.java @@ -51,8 +51,19 @@ public class SmeltItemExperienceSource extends SpecificExperienceSource getNearbyPlayer(Location loc, double d) { - double d2 = d * d; - return loc.getWorld().getPlayers().stream().filter(player -> player.getLocation().distanceSquared(loc) < d2).findAny(); + final double d2 = d * d; + 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