mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2025-02-14 05:01:28 +00:00
Merge pull request #2158 from pop4959/near-fix
Sort /near by nearest player.
This commit is contained in:
commit
d01e12ac14
1 changed files with 14 additions and 4 deletions
|
@ -9,6 +9,8 @@ import org.bukkit.World;
|
|||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.PriorityQueue;
|
||||
import java.util.Queue;
|
||||
|
||||
import static com.earth2me.essentials.I18n.tl;
|
||||
|
||||
|
@ -83,6 +85,8 @@ public class Commandnear extends EssentialsCommand {
|
|||
final long radiusSquared = radius * radius;
|
||||
boolean showHidden = user.canInteractVanished();
|
||||
|
||||
Queue<User> nearbyPlayers = new PriorityQueue<>((o1, o2) -> (int) (o1.getLocation().distanceSquared(loc) - o2.getLocation().distanceSquared(loc)));
|
||||
|
||||
for (User player : ess.getOnlineUsers()) {
|
||||
if (!player.equals(user) && (!player.isHidden(user.getBase()) || showHidden || user.getBase().canSee(player.getBase()))) {
|
||||
final Location playerLoc = player.getLocation();
|
||||
|
@ -92,13 +96,19 @@ public class Commandnear extends EssentialsCommand {
|
|||
|
||||
final long delta = (long) playerLoc.distanceSquared(loc);
|
||||
if (delta < radiusSquared) {
|
||||
if (output.length() > 0) {
|
||||
output.append(", ");
|
||||
}
|
||||
output.append(player.getDisplayName()).append("§f(§4").append((long) Math.sqrt(delta)).append("m§f)");
|
||||
nearbyPlayers.offer(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
while (!nearbyPlayers.isEmpty()) {
|
||||
if (output.length() > 0) {
|
||||
output.append(", ");
|
||||
}
|
||||
User nearbyPlayer = nearbyPlayers.poll();
|
||||
output.append(nearbyPlayer.getDisplayName()).append("§f(§4").append((long) nearbyPlayer.getLocation().distance(loc)).append("m§f)");
|
||||
}
|
||||
|
||||
return output.length() > 1 ? output.toString() : tl("none");
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue