Skip to content

An integrated GeoIP for inexperienced programmers #18

Description

@Kallecrafter

General Troubleshooting

  • I am using the latest version of the LabyMod 4 Server API.
  • I have checked for similar issues on the Issue-tracker.
  • I have checked for Pull Requests that might already address this issue.

Feature Request

So that even inexperienced programmers can query the country of a player and then set the flag for it in a simplified manner.

Example Use-Case

public static String getCountryCode(String ip) {
        String apiUrl = "http://ip-api.com/json/" + ip;
        try {
            URL url = new URL(apiUrl);
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            conn.setRequestMethod("GET");

            BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
            Map<String, Object> json = new Gson().fromJson(reader, Map.class);
            reader.close();

            return json.containsKey("countryCode") ? (String) json.get("countryCode") : "Unknown";

        } catch (Exception e) {
            e.printStackTrace();
            return "Error";
        }
    }

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestpendingThis issue or pull request still needs to be looked at

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions