mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2025-02-12 04:20:41 +00:00
Sort /near by nearest player.
This commit is contained in:
parent
a3eb58724f
commit
3395bab928
1 changed files with 16 additions and 4 deletions
|
@ -7,8 +7,12 @@ import org.bukkit.Location;
|
||||||
import org.bukkit.Server;
|
import org.bukkit.Server;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
|
|
||||||
|
import javafx.util.Pair;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.PriorityQueue;
|
||||||
|
import java.util.Queue;
|
||||||
|
|
||||||
import static com.earth2me.essentials.I18n.tl;
|
import static com.earth2me.essentials.I18n.tl;
|
||||||
|
|
||||||
|
@ -83,6 +87,8 @@ public class Commandnear extends EssentialsCommand {
|
||||||
final long radiusSquared = radius * radius;
|
final long radiusSquared = radius * radius;
|
||||||
boolean showHidden = user.canInteractVanished();
|
boolean showHidden = user.canInteractVanished();
|
||||||
|
|
||||||
|
Queue<Pair<User, Long>> playerDistances = new PriorityQueue<>(Comparator.comparingLong(Pair::getValue));
|
||||||
|
|
||||||
for (User player : ess.getOnlineUsers()) {
|
for (User player : ess.getOnlineUsers()) {
|
||||||
if (!player.equals(user) && (!player.isHidden(user.getBase()) || showHidden || user.getBase().canSee(player.getBase()))) {
|
if (!player.equals(user) && (!player.isHidden(user.getBase()) || showHidden || user.getBase().canSee(player.getBase()))) {
|
||||||
final Location playerLoc = player.getLocation();
|
final Location playerLoc = player.getLocation();
|
||||||
|
@ -92,13 +98,19 @@ public class Commandnear extends EssentialsCommand {
|
||||||
|
|
||||||
final long delta = (long) playerLoc.distanceSquared(loc);
|
final long delta = (long) playerLoc.distanceSquared(loc);
|
||||||
if (delta < radiusSquared) {
|
if (delta < radiusSquared) {
|
||||||
|
playerDistances.offer(new Pair<>(player, delta));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
while (!playerDistances.isEmpty()) {
|
||||||
if (output.length() > 0) {
|
if (output.length() > 0) {
|
||||||
output.append(", ");
|
output.append(", ");
|
||||||
}
|
}
|
||||||
output.append(player.getDisplayName()).append("§f(§4").append((long) Math.sqrt(delta)).append("m§f)");
|
Pair<User, Long> playerDistance = playerDistances.poll();
|
||||||
}
|
output.append(playerDistance.getKey().getDisplayName()).append("§f(§4").append((long) Math.sqrt(playerDistance.getValue())).append("m§f)");
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return output.length() > 1 ? output.toString() : tl("none");
|
return output.length() > 1 ? output.toString() : tl("none");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue