👋🏻
stanjg / ptero4j Goto Github PK
View Code? Open in Web Editor NEWA java wrapper for the pterodactyl panel API
License: MIT License
A java wrapper for the pterodactyl panel API
License: MIT License
👋🏻
Hey, got the following while creating the user (creating worked)
An error occurred while making a request to the panel, if the issue persists please create an issue on github.
201 POST https://panel.example.com/api/application/users
Code used:
adminInterface.getAdminAPI().getUsersController().createNew()
.setEmail(customerId.toString() + "@example.com")
.setUsername(customerId.toString())
.setPassword(customerId.toString())
.setFirstName("Han")
.setLastName("Solo")
.setLanguage("en")
.execute();
Regards
Im not the admin of the panel and just got a user key. Can i use it anyways? And how do I get my server?
Hi im trying to use the api to get the server ID through a string such as Game1 so i can restart/suspend ect however i'm not entirely sure how i can do this iv tried an array and a list but i just don't know
any help would be much appreciated
It would be great if it would be possible to get the current console log as an string or an string array.
I think about something like this:
int logLines = 2;
String[] logList = userServer.getLogAsList(logLines);
//Output: {"Player234 joined the game","<Player234> Hi"}
String log = userServer.getLogAsString(logLines);
//Output: "Player234 joined the game\n<Player234> Hi"
Hey.
First of all, i really appreciate this project. A really good idea, and would be very useful if you make it working.
So now, i'm trying to use it first time and found the issue
Exception in thread "main" org.json.JSONException: JSONObject["databases"] is not an int.
when tried to get a server's name from userServersController.
Probably the code isn't working with the latest version of Pterodactyl panel, there was a huge API update, everything changed. For the reasons mentioned above, I do not think the code will work at all.
Hope you enjoy coding, and will fix it as you can.
public static void main(String[] args) {
System.out.println("test");
PteroUserAPI api = new PteroUserAPI("https://ptero.correct.url", "ptero.correct.api.token");
System.out.println(api.getServersController().getServers());
}
As soon as I run this code, it just shuts down and nothing appears on the console
I apologize for the terrible formatting here of the issue on github, I have no experience
Hi there,
I'm trying to make a system where I can deploy new servers from inside our Bungeecord proxy using this API. But now comes the point where I'm getting errors... I'm getting this:
>.... [02:27:49 INFO]: An error occurred while making a request to the panel, if the issue persists please create an issue on github.
>.... [02:27:49 INFO]: 422 POST https://panel.snl.bruijns.tech/api/application/servers
And this is my code:
public class ServerHandler extends Command {
public ServerHandler(ServerDeployer serverDeployer) {
super("deploypf");
}
public static void deployNew() {
PteroAdminAPI api = new PteroAdminAPI("https://panel.snl.bruijns.tech/", "I HAVE MY KEY HERE USUALLY, BUT REMOVED IT FOR NOW.");
ServerCreateAction server = api.getServersController().createNew();
server.setName("pf01").setDescription("TEST FOR PF01").setUserId(2).setAllocation(1).setPortRange(String.valueOf(25657)).setLimits(1024, -1, 0, 500, 0).setEggId(17).setPackId(1).setDockerImage("quay.io/pterodactyl/core:java").setStartOnCompletion(true).execute();
}
@Override
public void execute(CommandSender sender, String[] args) {
if(sender instanceof ProxiedPlayer) {
ProxiedPlayer p = (ProxiedPlayer) sender;
deployNew();
}
}
}
Is there any possibility you can help me solving my issue?
I hope to hear from you!
Bonjour,
Je voulais savoir est t'il possible de récupérer la console du panel Client ?
Validate given fields before sending them to the panel and throw an exception if the field is not valid
Good evening,
I want to use this API but when I get the panel url and the key it shows me this error I don't understand why.
Someone can help me please ?
Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: okhttp3/MediaType
at com.stanjg.ptero4j.controllers.Controller.<clinit>(Controller.java:20)
at com.stanjg.ptero4j.PteroAdminAPI.<init>(PteroAdminAPI.java:29)
at fr.blackbalrog.info.Connect.getInfo(Connect.java:12)
at fr.blackbalrog.PPanel.onEvent(PPanel.java:44)
at fr.theshark34.swinger.abstractcomponents.AbstractButton.mouseReleased(AbstractButton.java:81)
at java.desktop/java.awt.Component.processMouseEvent(Component.java:6614)
at java.desktop/javax.swing.JComponent.processMouseEvent(JComponent.java:3342)
at java.desktop/java.awt.Component.processEvent(Component.java:6379)
at java.desktop/java.awt.Container.processEvent(Container.java:2263)
at java.desktop/java.awt.Component.dispatchEventImpl(Component.java:4990)
at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2321)
at java.desktop/java.awt.Component.dispatchEvent(Component.java:4822)
at java.desktop/java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4919)
at java.desktop/java.awt.LightweightDispatcher.processMouseEvent(Container.java:4548)
at java.desktop/java.awt.LightweightDispatcher.dispatchEvent(Container.java:4489)
at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2307)
at java.desktop/java.awt.Window.dispatchEventImpl(Window.java:2769)
at java.desktop/java.awt.Component.dispatchEvent(Component.java:4822)
at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:772)
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721)
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:715)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:95)
at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:745)
at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:743)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:742)
at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
Caused by: java.lang.ClassNotFoundException: okhttp3.MediaType
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:606)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:168)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
... 35 more
Hello,
I have a question. I want to use the API as a admin-tool. So I tried to add a function which could start the servers:
(Server.java, package: com.stanjg.ptero4.entities.panel.admin)
`public boolean start() {
JSONObject test;
test = new JSONObject();
test.put("signal", "start");
System.out.println(test);
return new GenericAdminAction(api, "/servers/"+this.shortId+"/power", HTTPMethod.POST, test).execute() == 204;
}`
But the console returns an warning and the server doesn't start:
An invalid request was made by the library, please create an issue on github. POST https://control.junico.de/api/application/servers/8/power
I saw that you have to transmit a parameter to the server via the url so that the server know what poweraction you want to perform: https://dashflo.net/docs/api/pterodactyl/v0.7/#send-power-action
Now my question is: Is it possible to send poweractions with this API or what have I done wrong?
Sorry for my bad english.
I hope anyone can help me out with this. If you need any more informations just tell me.
I whish you all a beautiful day.
TheAimWolf
From what I could find, there is no documentation for the ServerCreateAction class. I'm looking to use this api to create servers and I've been unable to figure out the ServerCreateAction class. Perhaps documentation for it could be made?
Example client api contains “PteroAdminAPI”. Convert that with “PteroUserAPI”
Hi, I have a question. Is there a way to get the Console Output from the server?
(like starting,started,off,...)
This is my error
Ptero4J loaded! Successfully made contact with the panel. Exception in thread "main" java.lang.NoSuchMethodError: org.json.JSONObject.keySet()Ljava/util/Set; at com.stanjg.ptero4j.entities.objects.server.ServerContainer.getEnvironmentVariablesMap(ServerContainer.java:32) at com.stanjg.ptero4j.entities.objects.server.ServerContainer.<init>(ServerContainer.java:27) at com.stanjg.ptero4j.entities.objects.server.ServerContainer.<init>(ServerContainer.java:15) at com.stanjg.ptero4j.entities.panel.admin.Server.<init>(Server.java:39) at com.stanjg.ptero4j.controllers.admin.ServersController.getNewInstance(ServersController.java:70) at com.stanjg.ptero4j.controllers.admin.ServersController.getNewInstance(ServersController.java:18) at com.stanjg.ptero4j.controllers.admin.ResourceController.addPageToList(ResourceController.java:266) at com.stanjg.ptero4j.controllers.admin.ResourceController.getAllResources(ResourceController.java:204) at com.stanjg.ptero4j.controllers.admin.ServersController.getAllServers(ServersController.java:41) at Test.main(Test.java:21)
And this is my code
`import java.io.BufferedWriter;
import java.io.FileWriter;
import java.util.List;
import com.stanjg.ptero4j.PteroAdminAPI;
import com.stanjg.ptero4j.controllers.admin.ServersController;
import com.stanjg.ptero4j.controllers.admin.UsersController;
import com.stanjg.ptero4j.entities.panel.admin.Server;
import com.stanjg.ptero4j.entities.panel.admin.User;
public class Test {
public static void main(String[] args) {
PteroAdminAPI api = new PteroAdminAPI("http://panel.themajesticnetwork.com/", "s4nCuW6BAacGTcUQVXtq559AR6UrqhUyWm8LiZxIcrUlanwH");
// Then fetch the server using the ServersController
ServersController servers = api.getServersController();
List<Server> server = servers.getAllServers();
List<Server> serverPage = servers.getServerPage(1);
UsersController usersController = api.getUsersController();
List<User> users = usersController.getUsers("search");
try{
String serverSection = "SYHAT";
String userSection = "UYA";
// Create file
FileWriter fstream = new FileWriter("details.txt");
BufferedWriter out = new BufferedWriter(fstream);
out.write(serverSection + ": " + serverPage);
//Close the output stream
out.close();
}catch (Exception e){//Catch exception if any
System.err.println("Error: " + e.getMessage());
}
}
}
`
And I cant seem to find out how to fix this, help me please.
After a long time getting maven to work and compiling a version of the API i got the JAR.
But now im trying to create something and when doing this
Currently there is no error catching. For example if a key does not have permission for a certain action the result will not be pretty.
Start using the exceptions that I have created.
Hello, how to create server? I have code, but code dont working:
try {
Main.api.getServersController()
.createNew()
.setName(serverowner)
.setDescription("Owner: " + serverowner)
.setUserId(9)
.setEggId(3)
.setAllocation(1)
.setPackId(1)
.setDockerImage("quay.io/pterodactyl/core:java")
.setLimits(512, 0, 3000, 0, 100)
.setFeatureLimits(0, 0)
.setDedicatedIp(true)
.setPortRange(portRange)
.setStartOnCompletion(true)
.setFeatureLimits(0, 0)
.setDeployLocations(ids)
.setSkipScripts(false)
.setExternalId(503)
.execute();
} catch(Exception e) {
e.printStackTrace();
}
why?
error:
An error occurred while making a request to the panel, if the issue persists please create an issue on github.
422 POST https://panel.gamerhost.pro/api/application/servers
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.