use of data.Coordinate in project KaellyBot by Kaysoro.
the class DistanceCommand method request.
@Override
public void request(MessageCreateEvent event, Message message, Matcher m, Language lg) {
Coordinate coordinate = new Coordinate(Integer.parseInt(m.group(1)), Integer.parseInt(m.group(2)));
StringBuilder st = new StringBuilder();
Transport zaap = null;
Transport transportLimited = null;
if (!coordinate.isNull()) {
double minDist = Double.MAX_VALUE;
double minDistLimited = Double.MAX_VALUE;
for (Transport transport : Transport.values()) {
double tmp = transport.getCoordinate().getDistance(coordinate);
if (transport.isFreeAccess() && (zaap == null || minDist > tmp)) {
zaap = transport;
minDist = tmp;
}
if (!transport.isFreeAccess() && (transportLimited == null || minDistLimited > tmp)) {
transportLimited = transport;
minDistLimited = tmp;
}
}
st.append(Translator.getLabel(lg, "distance.request.1")).append(" ").append(zaap.toDiscordString(lg));
if (minDist > minDistLimited)
st.append("\n").append(Translator.getLabel(lg, "distance.request.2")).append(" ").append(transportLimited.toDiscordString(lg));
} else
st.append(Translator.getLabel(lg, "distance.request.3"));
message.getChannel().flatMap(chan -> chan.createMessage(st.toString())).subscribe();
}
Aggregations