Overview
The MyMCLib
library provides a convenient way to interact with the My-MC.Link API for managing Minecraft servers. It includes methods for performing various actions such as retrieving server information, managing server settings, controlling gameplay, and interacting with players.
Installation
To use the MyMCLib
library in your project, install it via Maven:
<dependency>
<groupId>io.github.mrmasrozytlive</groupId>
<artifactId>mymc-java-lib</artifactId>
<version>1.2.0</version>
</dependency>
or via Gradle:
implementation group: 'io.github.mrmasrozytlive', name: 'mymc-java-lib', version: '1.2.0'
For other ways, visit:
https://central.sonatype.com/artifact/io.github.mrmasrozytlive/mymc-java-lib.
Usage
First, import the library into your project:
import net.mitask.MyMCLib;
Then, create an instance of MyMCLib
by providing your API token:
MyMCLib myMcLink = new MyMCLib("API_KEY_HERE");
Example Usage
import net.mitask.MyMCLib;
public class YourClass {
public void yourMethod() {
MyMCLib myMcLink = new MyMCLib("API_KEY_HERE");
// Will print information about API key expiration date
System.out.println(myMcLink.getTime().toString());
}
}
Output:
{
success: true,
keyexpireString: 'Tue Apr 15 2025 06:14:59 GMT-0400 (Eastern Daylight Time)',
expireDate: '2025-04-15T10:14:59.000Z',
expireEpoch: 1744712099000
}
Code Examples
Getting Server Time
JSONObject timeData = myMcLink.getTime();
System.out.println(timeData.toString());
Getting Server Statistics
JSONObject statsData = myMcLink.getStats();
System.out.println(statsData.toString());
Getting Server Logs
JSONObject logData = myMcLink.getLog();
System.out.println(logData.toString());
Starting the Minecraft Server
JSONObject startResult = myMcLink.startServer();
System.out.println(startResult.toString());
Stopping the Minecraft Server
JSONObject stopResult = myMcLink.stopServer();
System.out.println(stopResult.toString());
Restarting the Minecraft Server
JSONObject restartResult = myMcLink.restartServer();
System.out.println(restartResult.toString());
Creating a Custom Link
JSONObject customLinkResult = myMcLink.createMyLink();
System.out.println(customLinkResult.toString());
Deleting a Custom Link
JSONObject deleteLinkResult = myMcLink.deleteMyLink();
System.out.println(deleteLinkResult.toString());
Creating an SFTP Link
JSONObject sftpLinkResult = myMcLink.createLinkSFTP();
System.out.println(sftpLinkResult.toString());
Deleting an SFTP Link
JSONObject deleteSftpLinkResult = myMcLink.deleteLinkSFTP();
System.out.println(deleteSftpLinkResult.toString());
Getting Connection Hash
JSONObject hashData = myMcLink.getConnectionHash();
System.out.println(hashData.toString());
Getting SFTP Connection Hash
JSONObject sftpHashData = myMcLink.getConnectionHashSFTP();
System.out.println(sftpHashData.toString());
Getting Online Players
JSONObject playersData = myMcLink.getOnlinePlayers();
System.out.println(playersData.toString());
Getting Server's Website URL
JSONObject websiteURL = myMcLink.getWebsiteURL();
System.out.println(websiteURL.toString());
Getting Server's Map URL
JSONObject mapURL = myMcLink.getMapURL();
System.out.println(mapURL.toString());
Banning a Player
JSONObject banResult = myMcLink.postBan("username");
System.out.println(banResult.toString());
Unbanning a Player
JSONObject unbanResult = myMcLink.postUnban("username");
System.out.println(unbanResult.toString());
Sending a Message to All Players
JSONObject sayResult = myMcLink.postSay("Hello, everyone!");
System.out.println(sayResult.toString());
Sending a Private Message to a Player
JSONObject tellResult = myMcLink.postTell("username", "Hey, how are you?");
System.out.println(tellResult.toString());
Executing a Command in Server Console
JSONObject consoleResult = myMcLink.postConsole("say Hello, world!");
System.out.println(consoleResult.toString());
Giving an Item to a Player
JSONObject giveResult = myMcLink.postGive("username", "item", 1);
System.out.println(giveResult.toString());
Installing a Mod by ID
String modID = "exampleMod123";
JSONObject installResult = myMcLink.installMod(modID);
System.out.println(installResult.toString());
Uninstalling a Mod by ID
String modID = "exampleMod123";
JSONObject uninstallResult = myMcLink.uninstallMod(modID);
System.out.println(uninstallResult.toString());
Retrieving a List of Installed Mods
JSONObject installedMods = myMcLink.getInstalledMods();
System.out.println(installedMods.toString());
API Reference
MyMCLib Class
Constructor
public MyMCLib(String token)
Creates an instance of the MyMCLib
class with the provided API token.
Methods
JSONObject getTime()
- Retrieves the current server time.JSONObject getStats()
- Retrieves server statistics.JSONObject getLog()
- Retrieves server logs.JSONObject startServer()
- Starts the Minecraft server.JSONObject stopServer()
- Stops the Minecraft server.JSONObject restartServer()
- Restarts the Minecraft server.JSONObject createMyLink()
- Creates a custom link.JSONObject deleteMyLink()
- Deletes a custom link.JSONObject createLinkSFTP()
- Creates an SFTP link.JSONObject deleteLinkSFTP()
- Deletes an SFTP link.JSONObject getConnectionHash()
- Retrieves a connection hash.JSONObject getConnectionHashSFTP()
- Retrieves an SFTP connection hash.JSONObject getOnlinePlayers()
- Retrieves a list of online players.JSONObject getWebsiteURL()
- Retrieves the server's website URL.JSONObject getMapURL()
- Retrieves the server's map URL.JSONObject postBan(String username)
- Bans a player by username.JSONObject postUnban(String username)
- Unbans a player by username.JSONObject postSay(String message)
- Sends a message to all players.JSONObject postTell(String username, String message)
- Sends a private message to a player.JSONObject postConsole(String command)
- Executes a command in the server console.JSONObject postGive(String username, String item, int amount)
- Gives an item to a player.JSONObject installMod(String modID)
- Installs a mod by ID.JSONObject uninstallMod(String modID)
- Uninstalls a mod by ID.JSONObject getInstalledMods()
- Retrieves a list of installed mods.
ApiUtils Class
Methods
JSONObject getRequest(ApiEndpoint endpoint, String token)
- Makes a GET request to the specified API endpoint.JSONObject deleteRequest(ApiEndpoint endpoint, String token)
- Makes a DELETE request to the specified API endpoint.JSONObject postRequest(ApiEndpoint endpoint, String token, JSONObject data)
- Makes a POST request to the specified API endpoint with the provided data.
Explore More
Ready to automate your server?
Join our community, dive into our resources, and start building with the My-MC.Link API and MyMCLib.