Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# User-specific stuff:
.idea
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/dictionaries
Expand Down Expand Up @@ -52,6 +53,7 @@ fabric.properties

config.properties

target
target/

src/test
22 changes: 17 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
<artifactId>Ptero4J</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>

<issueManagement>
<url>https://github.com/stanjg/Ptero4J/issues</url>
<system>GitHub Issues</system>
Expand All @@ -25,11 +31,16 @@
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Expand All @@ -47,4 +58,5 @@
</dependency>
</dependencies>


</project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@

import com.stanjg.ptero4j.PteroAdminAPI;
import com.stanjg.ptero4j.actions.PteroAction;
import com.stanjg.ptero4j.entities.objects.server.creation.CreationEnvironment;
import com.stanjg.ptero4j.entities.objects.server.creation.CreationFeatureLimits;
import com.stanjg.ptero4j.entities.objects.server.creation.CreationServerLimits;
import com.stanjg.ptero4j.entities.panel.admin.Server;
import com.stanjg.ptero4j.util.HTTPMethod;
import org.json.JSONArray;
import org.json.JSONObject;

import java.util.Arrays;
import java.util.List;

public class ServerCreateAction implements PteroAction<Server> {

private JSONObject json;
Expand Down Expand Up @@ -39,6 +43,11 @@ public ServerCreateAction setUserId(int id) {
return this;
}

public ServerCreateAction setNestId(int id) {
json.put("nest", id);
return this;
}

public ServerCreateAction setEggId(int id) {
json.put("egg", id);
return this;
Expand All @@ -59,17 +68,34 @@ public ServerCreateAction setStartupCommand(String command) {
return this;
}

public ServerCreateAction setEnvironmentVariables() {
return this; // TODO
public ServerCreateAction addEnvironmentValue(String name, String value) {
return addEnvironmentValue(new CreationEnvironment(name, value));
}

public ServerCreateAction addEnvironmentValue(CreationEnvironment environment) {
JSONObject environments = getOrCreateJSONObject(json, "environment");
environments.put(environment.getName(), environment.getValue());
return this;
}

public ServerCreateAction setEnvironmentValues(List<CreationEnvironment> environments) {
JSONObject environmentsJSON = new JSONObject();
environments.forEach(environment -> environmentsJSON.put(environment.getName(), environment.getValue()));
json.put("environment", environmentsJSON);
return this;
}

public ServerCreateAction setEnvironmentValues(CreationEnvironment... environments) {
return setEnvironmentValues(Arrays.asList(environments));
}

public ServerCreateAction setSkipScripts(boolean skipScripts) {
json.put("skip_scripts", skipScripts);
return this;
}

public ServerCreateAction setLimits(int memory, int swap, int disk, int io, int cpu) {
return setLimits(new CreationServerLimits(memory, swap, disk, io, cpu));
public ServerCreateAction setLimits(int disk, int memory, int swap, int io, int cpu) {
return setLimits(new CreationServerLimits(disk, memory, swap, io, cpu));
}

public ServerCreateAction setLimits(CreationServerLimits limits) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.stanjg.ptero4j.entities.objects.server.creation;

import org.json.JSONObject;

public class CreationEnvironment {

private String name, value;

public CreationEnvironment() {
}

public CreationEnvironment(String name, String value) {
this.name = name;
this.value = value;
}

public JSONObject getAsJSON() {
return new JSONObject()
.put("name", name)
.put("value", value);
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getValue() {
return value;
}

public void setValue(String value) {
this.value = value;
}
}