Skip to content

Using the API with Java

Nullicorn edited this page Jun 1, 2020 · 5 revisions

This page provides examples of how to use the Hypixel PublicAPI in a Java program. It is assumed that you have already configured your IDE and downloaded PublicAPI on your own machine.

Contents

Prerequisites

In order to follow along with this tutorial, you will need the following:

  • A live internet connection
  • A licensed copy of Minecraft installed on your local machine
  • A Java IDE (we will be using IntelliJ for this tutorial)
  • Maven (if not already built into your IDE)

Getting your API Key

To use the PublicAPI, you will first need to have an API key. The Hypixel API uses keys to keep track of how frequently a user is sending requests, as well as to determine if your API key is compromised.

To obtain your personal API key, you must own a valid Minecraft account and have the Minecraft Launcher installed.

  1. Launch Minecraft on release 1.8.0 or later (snapshot versions will not work)
  2. Open the Multiplayer GUI and connect to mc.hypixel.net
  3. Once you are connected, open up the chat bar (this can be done by pressing the T key by default)
  4. In the chat bar, type /api new and press enter. You should receive a message in chat saying, Your new API key is xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx (with your API key in place of the x's)
  5. When you click on that message, your API key should be copied to your clipboard. Paste that somewhere safe for later

NOTE: Your API key is to be treated just like a password. You should never share your API key with anyone, or else it could be used for malicious purposes.


Setting Up your Workspace

To start using the Java API, you will first need to open up a Java IDE of your choice. For this tutorial, we will be using IntelliJ IDEA (2020.1.1).

1. Firstly, you will need to create a new project. In IntelliJ, there is a button for this on the welcome screen: "Create New Project" button

2. Then, select the Maven project option and click Next: Maven project

3. Type in the name of your project and press the Finish button. This will create your new Maven project with that name: Set project name & finish

4. In the Project window that appears, click on the folder with your project's name and double-click the pom.xml file: Open pom.xml

5. At the end of this file (before the </project> tag), paste the following:

<repositories>
  <repository>
    <id>jitpack.io</id>
    <url>https://jitpack.io</url>
  </repository>
</repositories>

<dependencies>
  <dependency>
    <groupId>com.github.HypixelDev.PublicAPI</groupId>
    <artifactId>Java</artifactId>
    <version>2.0.0</version>
  </dependency>
</dependencies>

NOTE: If some of the text is colored red, you may need to use the Load Maven Changes button in the top right (see screenshot) Hypixel API pom dependency

If all goes well, you now should be able to use the Hypixel API in your very own Java project! See below for more information on using the API in various projects [coming soon; for now, see here for various examples].


TODO

  • Add example usage in a plain java program
  • Add example usage in a Forge mod
  • Add example usage in a Bukkit plugin

Clone this wiki locally