Search in sources :

Example 1 with Position

use of data.Position in project KaellyBot by Kaysoro.

the class DistanceCommand method request.

@Override
public boolean request(IMessage message) {
    if (super.request(message)) {
        Matcher m = getMatcher(message);
        m.find();
        Language lg = Translator.getLanguageFrom(message.getChannel());
        Position position = new Position(Integer.parseInt(m.group(1)), Integer.parseInt(m.group(2)));
        StringBuilder st = new StringBuilder();
        Transport zaap = null;
        Transport transportLimited = null;
        if (!position.isNull()) {
            double minDist = Double.MAX_VALUE;
            double minDistLimited = Double.MAX_VALUE;
            for (Transport transport : Transport.values()) {
                double tmp = transport.getPosition().getDistance(position);
                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.sendText(message.getChannel(), st.toString());
    }
    return false;
}
Also used : Language(enums.Language) Matcher(java.util.regex.Matcher) Position(data.Position) Transport(enums.Transport)

Aggregations

Position (data.Position)1 Language (enums.Language)1 Transport (enums.Transport)1 Matcher (java.util.regex.Matcher)1