use of com.wynntils.webapi.profiles.LocationProfile in project Wynntils by Wynntils.
the class CommandLocate method execute.
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
if (args.length == 0) {
throw new WrongUsageException("/" + getUsage(sender));
}
List<LocationProfile> knownProfiles = mapFeatures.get(args[0]);
if (knownProfiles == null) {
// Try case insensitive search
Optional<String> match = mapFeatures.keySet().stream().filter(key -> key.toLowerCase().equals(args[0].toLowerCase())).findFirst();
if (!match.isPresent()) {
throw new WrongUsageException("Unknown map feature: " + args[0]);
} else {
knownProfiles = mapFeatures.get(match.get());
}
}
Map<Double, LocationProfile> distanceToLocations = new TreeMap<>();
Location currentLocation = new Location(McIf.player());
for (LocationProfile locationProfile : knownProfiles) {
Location location = new Location(locationProfile.getX(), currentLocation.getY(), locationProfile.getZ());
double distance = location.distance(currentLocation);
distanceToLocations.put(distance, locationProfile);
}
int numPrinted = 0;
for (Map.Entry<Double, LocationProfile> entry : distanceToLocations.entrySet()) {
double distance = entry.getKey();
LocationProfile mmp = entry.getValue();
ITextComponent startingPointMsg = new TextComponentString(mmp.getTranslatedName() + " is located at [" + mmp.getX() + ", " + mmp.getZ() + "] (" + (int) distance + " blocks)");
startingPointMsg.getStyle().setColor(GRAY);
sender.sendMessage(startingPointMsg);
numPrinted++;
if (numPrinted >= 3)
break;
}
}
Aggregations