A java wrapper for the pterodactyl panel API
A java library to interact with the Admin API of Pterodactyl Panel.
Controllers are the objects that make the requests to the panel. There is a controller class for every Model and they all derive from Controller
.
With a controller class you can fetch resources from the panel, instantiate Action objects and perform generic actions.
All Controllers are instantiated and 'kept' in the PteroAdminAPI or PteroUserAPI class.
Example:
UsersController usersController = api.getUsersController();
List<User> users = usersController.getAllUsers();
There are two type of actions in this library; Explicit
and Generic
. Explicit Actions often need more details.
execute()
method and it will make the call to the panel API.suspend()
on a Server
object.Example:
// Explicit Action
server.editBuild().setMemory(2048).execute();
// Generic Action
server.suspend();
The library is split into two seperate APIs, the PteroUserAPI and the PteroAdminAPI. This is done because the Pterodactyl Panel API is actually split up into these two sections aswell.
In your pom.xml you need add the Jitpack repository and the panel dependency
<repositories>
<!-- Jitpack repo -->
<repository>
<id>jitpack</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
<dependencies>
<!-- Panel API -->
<dependency>
<groupId>com.github.stanjg</groupId>
<artifactId>Ptero4J</artifactId>
<version>master-SNAPSHOT</version>
</dependency>
</dependencies>
Or you can clone the project and run a "mvn clean install" to get a compiled jar file.
Let's imagine that a server is overdue, you have it's ID and you want to suspend the server
public static void main(String[] args) {
// First you instantiate the API class (Admin in this case)
// and give it your panel URL and API key
PteroAdminAPI api = new PteroAdminAPI("https://panel.pterodactyl.io/", "api key");
// Then fetch the server using the ServersController
Server server = api.getServersController().getServer(12 /* Server ID */);
// Now you can suspend the server using it's generic action
server.suspend();
// You're all set! The server has been suspended.
}
Now let's imagine that you want to change the amount of ram a server can use, here's how:
public static void main(String[] args) {
// First you instantiate the API class (Admin in this case)
// and give it your panel URL and API key
PteroAdminAPI api = new PteroAdminAPI("https://panel.pterodactyl.io/", "api key");
// Then fetch the server using the ServersController
Server server = api.getServersController().getServer(12 /* Server ID */);
// Now you can update memory of the server using it's explicit action
server.editBuild().setMemory(4096 /* in MBs, so this is 4GB */).execute();
// You're all set! The memory has been updated.
}
One last example, you want to update the email and the name of a user
public static void main(String[] args) {
// First you instantiate the API class (Admin in this case)
// and give it your panel URL and API key
PteroAdminAPI api = new PteroAdminAPI("https://panel.pterodactyl.io/", "api key");
// Then fetch the user using the UsersController
User user = api.getUsersController().getUser(88 /* User ID */);
// Now you can update the users emai and username using it's explicit action
user.edit().setEmail("[email protected]").setName("stanjg").execute();
// You're all set! The email and username has been updated.
}
// Fields
server.getLongId()
server.getName()
server.getDescription()
server.getUuid()
server.getShortId()
server.getAllocationId()
server.getEggId()
server.getNestId()
server.getExternalId()
server.getPackId()
server.getNodeId()
server.getOwnerId()
server.isSuspended()
// Field sub classes
server.getContainer()
container.getStartupCommand()
container.getImage()
container.isInstalled()
container.getEnvironmentVariables()
server.getLimits()
limits.getDisk()
limits.getMemory()
limits.getSwap()
limits.getIo()
limits.getCpu()
server.getFeatureLimits()
featureLimits.getMaxDatabases()
featureLimits.getMaxAllocations()
// Relationships
server.getOwner()
server.getLocation()
server.getNode()
ServersController controller = api.getServersController();
// Fetch All Servers
List<Server> servers = controller.getAllServers();
// Fetch Servers With Search Query
List<Server> servers = controller.getServers("search");
// Fetch Single Server By ID
Server server = controller.getServer(8888);
// Fetch Page of Servers
List<Server> servers = controller.getServerPage(1);
// Fetch Servers For User by ID
List<Server> servers = controller.getServersForUser(88);
// Explicit Actions
server.editDetails() -> ServerUpdateDetailsAction
server.editBuild() -> ServerUpdateBuildAction
server.editStartup() -> ServerUpdateStartupAction
serversController.createNew() -> ServerCreateAction
// Generic Actions
server.suspend()
server.unsuspend()
server.reinstall()
server.rebuild()
server.delete()
// Fields
user.getId()
user.getExternalId()
user.getUuid()
user.getUsername()
user.getEmail()
user.getFirstName()
user.getLastName()
user.getLangauge()
user.isAdmin()
user.hasTotpEnabled()
// Relationships
user.getServers()
UsersController controller = api.getUsersController();
// Fetch All Users
List<User> users = controller.getAllUsers();
// Fetch Users With Search Query
List<User> users = controller.getUsers("search");
// Fetch Single User By ID
User users = controller.getUser(8888);
// Fetch Page of Users
List<User> users = controller.getUserPage(1);
// Fetch Users For User by ID
List<User> users = controller.getServersForUser(88);
// Explicit Actions
user.edit() -> UserUpdateAction
usersController.createNew() -> UserCreateAction
// Generic Actions
user.delete()
// Fields
server.getId()
server.getUuid()
server.getName()
server.getDescription()
server.isOwner()
server.getLimits()
server.getFeatureLimits()
// Field sub classes
server.getLimits()
limits.getDisk()
limits.getMemory()
limits.getSwap()
limits.getIo()
limits.getCpu()
server.getFeatureLimits()
featureLimits.getMaxDatabases()
featureLimits.getMaxAllocations()
UserServersController controller = api.getServersController();
// Fetch all servers you have access to
List<Server> servers = controller.getServers();
// Fetch server by ID
UserServer server = controller.getServer("aaaa88");
// Generic Actions
server.sendCommand("kick stanjg")
server.start()
server.stop()
server.restart()
server.kill()
server.sendPowerAction(PowerAction.START)
That's it :)