Search in sources :

Example 1 with Coordinate

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();
}
Also used : Language(enums.Language) MessageCreateEvent(discord4j.core.event.domain.message.MessageCreateEvent) AbstractCommand(commands.model.AbstractCommand) Matcher(java.util.regex.Matcher) Message(discord4j.core.object.entity.Message) Transport(enums.Transport) Translator(util.Translator) Coordinate(data.Coordinate) Coordinate(data.Coordinate) Transport(enums.Transport)

Aggregations

AbstractCommand (commands.model.AbstractCommand)1 Coordinate (data.Coordinate)1 MessageCreateEvent (discord4j.core.event.domain.message.MessageCreateEvent)1 Message (discord4j.core.object.entity.Message)1 Language (enums.Language)1 Transport (enums.Transport)1 Matcher (java.util.regex.Matcher)1 Translator (util.Translator)1