Can't find any tutorials regarding this...

Discussion in 'Bukkit Help' started by uyscutix, Sep 15, 2017.

Thread Status:
Not open for further replies.
  1. Offline

    uyscutix

    Hi, I want to make an in-game IP lookup command in my plugin using an IP lookup API, but I don't know how! I can't find any tutorials around that teach how to make Java connect to an API site and retrieve that information.

    I want to make a /lookup [IP] command in-game. It will go to this site (http://ip-api.com) and the IP typed in the command parameters is what it will retrieve from the website's API. For example on that site you see City, Country, etc. I basically want to move all that info in-game by displaying the info to the command sender through sender.sendMessage().

    Are there any tutorials that teach something like this? It doesn't have to be exactly how to lookup an IP, but any tutorials online related to using Java to connect to an API site and retrieve that online information. I am struggling to find tutorials to do something like this, i'm not sure if there's a correct term/phrase to describe this but if there is, it might be the reason for why I can't find any.
     
  2. Offline

    Zombie_Striker

    @uyscutix
    Why exactly would you want this information? There should be no reason to get a player's home address.
     
  3. @uyscutix
    You need to use the HttpURLConnection class. It contains methods to both write to and read from the website, which will allow you to get the data the API returned. One thing you should be mindful of is that it should only be done async, to avoid halting the main thread if the connection takes a long time.

    I have created an implementation which makes to Mojang's API over HTTP, which is basically the same principle, at least for the actual connection. You can have a look at that here (and also, since that code is MIT, you are free to use the code as you like):
    https://github.com/Alvin-LB/BukkitU...ingholm/mojangapiutil/v1_0/MojangAPIUtil.java
     
  4. Offline

    uyscutix

    IP lookups don't show someone's exact address (usually only the ISP of the IP). They just show the general info which anyone can see such as City, Country, Timezone, etc.

    I want to make it because I find it interesting. Something else that could also be handy (more useful) is a /namehistory command. Similar to IP lookup, but looks up someone's IGN history by connecting to a site like http://namemc.com and sending the command sender all their past IGNs and dates/times they changed it.
     
Thread Status:
Not open for further replies.

Share This Page