Skip to content

Commit 2fdd00d

Browse files
committed
refactor: more robust server api supporting persistent servers
1 parent 65737f0 commit 2fdd00d

File tree

18 files changed

+447
-120
lines changed

18 files changed

+447
-120
lines changed

api/build.gradle.kts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -152,13 +152,6 @@ publishing {
152152
protoDep.appendNode("artifactId", "simplecloud_controller_protocolbuffers_java_lite")
153153
protoDep.appendNode("version", rootProject.libs.controller.proto.get().version.toString())
154154
protoDep.appendNode("scope", "compile")
155-
156-
// Add kotlin stdlib if needed
157-
val kotlinDep = deps.appendNode("dependency")
158-
kotlinDep.appendNode("groupId", "org.jetbrains.kotlin")
159-
kotlinDep.appendNode("artifactId", "kotlin-stdlib")
160-
kotlinDep.appendNode("version", rootProject.libs.kotlin.stdlib.get().version.toString())
161-
kotlinDep.appendNode("scope", "compile")
162155
}
163156

164157
// Note: io.nats, com.squareup.okhttp3, com.google.code.gson, and io.gsonfire are NOT added because they're shaded
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
package app.simplecloud.api.base;
2+
3+
import app.simplecloud.api.group.GroupServerType;
4+
import app.simplecloud.api.group.SourceConfig;
5+
import app.simplecloud.api.group.WorkflowsConfig;
6+
import org.jetbrains.annotations.Nullable;
7+
8+
import java.util.List;
9+
import java.util.Map;
10+
11+
/**
12+
* Common base interface for server configurations.
13+
*
14+
* <p>This interface represents the shared configuration between {@link app.simplecloud.api.group.Group}
15+
* and {@link app.simplecloud.api.persistentserver.PersistentServer}. A server can be spawned from either
16+
* a group (with scaling and deployment configuration) or a persistent server (a single long-lived instance).
17+
*
18+
* <p>Use this interface when you need to access common server configuration properties regardless
19+
* of whether the server was spawned from a group or persistent server.
20+
*/
21+
public interface ServerBase {
22+
23+
/**
24+
* Returns the human-readable name of this server configuration.
25+
*
26+
* @return the name
27+
*/
28+
String getName();
29+
30+
/**
31+
* Returns the minimum memory allocation (in MB).
32+
*
33+
* @return the minimum memory, or null if not set
34+
*/
35+
@Nullable Integer getMinMemory();
36+
37+
/**
38+
* Returns the maximum memory allocation (in MB).
39+
*
40+
* @return the maximum memory, or null if not set
41+
*/
42+
@Nullable Integer getMaxMemory();
43+
44+
/**
45+
* Returns the maximum number of players.
46+
*
47+
* @return the max players, or null if not set
48+
*/
49+
@Nullable Integer getMaxPlayers();
50+
51+
/**
52+
* Returns the source configuration.
53+
*
54+
* <p>Defines whether servers use a blueprint or container image.
55+
*
56+
* @return the source config, or null if not set
57+
*/
58+
@Nullable SourceConfig getSource();
59+
60+
/**
61+
* Returns the workflows configuration.
62+
*
63+
* <p>Defines automated workflows to run on server lifecycle events.
64+
*
65+
* @return the workflows config, or null if not set
66+
*/
67+
@Nullable WorkflowsConfig getWorkflows();
68+
69+
/**
70+
* Returns custom properties.
71+
*
72+
* @return the properties map, or null if none set
73+
*/
74+
@Nullable Map<String, Object> getProperties();
75+
76+
/**
77+
* Returns tags for organization and filtering.
78+
*
79+
* @return the list of tags, or null if none set
80+
*/
81+
@Nullable List<String> getTags();
82+
83+
/**
84+
* Returns the type (SERVER or PROXY).
85+
*
86+
* @return the server type
87+
*/
88+
GroupServerType getType();
89+
90+
/**
91+
* Returns the timestamp when this was created (ISO 8601 format).
92+
*
93+
* @return the creation timestamp
94+
*/
95+
String getCreatedAt();
96+
97+
/**
98+
* Returns the timestamp when this was last updated (ISO 8601 format).
99+
*
100+
* @return the update timestamp
101+
*/
102+
String getUpdatedAt();
103+
104+
/**
105+
* Returns whether this is a group configuration.
106+
*
107+
* @return true if this is a group, false if it's a persistent server
108+
*/
109+
default boolean isGroup() {
110+
return this instanceof app.simplecloud.api.group.Group;
111+
}
112+
113+
/**
114+
* Returns whether this is a persistent server configuration.
115+
*
116+
* @return true if this is a persistent server, false if it's a group
117+
*/
118+
default boolean isPersistentServer() {
119+
return this instanceof app.simplecloud.api.persistentserver.PersistentServer;
120+
}
121+
}
122+

api/src/main/java/app/simplecloud/api/event/server/ServerUpdatedEvent.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,4 @@ public interface ServerUpdatedEvent {
4545
}
4646

4747

48+
Lines changed: 5 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
package app.simplecloud.api.group;
22

3+
import app.simplecloud.api.base.ServerBase;
34
import org.jetbrains.annotations.Nullable;
45

5-
import java.util.List;
6-
import java.util.Map;
7-
86
/**
97
* Represents a server group configuration.
108
*
119
* <p>Server groups are templates that define how server instances should be
1210
* created, deployed, and scaled. Each group specifies memory limits, player capacity,
1311
* deployment strategy, scaling behavior, and source configuration.
12+
*
13+
* <p>This interface extends {@link ServerBase} to provide common configuration access
14+
* alongside group-specific properties like deployment and scaling configuration.
1415
*/
15-
public interface Group {
16+
public interface Group extends ServerBase {
1617

1718
/**
1819
* Returns the unique identifier of this server group.
@@ -21,34 +22,6 @@ public interface Group {
2122
*/
2223
String getServerGroupId();
2324

24-
/**
25-
* Returns the human-readable name of this server group.
26-
*
27-
* @return the group name
28-
*/
29-
String getName();
30-
31-
/**
32-
* Returns the minimum memory allocation for servers in this group (in MB).
33-
*
34-
* @return the minimum memory, or null if not set
35-
*/
36-
@Nullable Integer getMinMemory();
37-
38-
/**
39-
* Returns the maximum memory allocation for servers in this group (in MB).
40-
*
41-
* @return the maximum memory, or null if not set
42-
*/
43-
@Nullable Integer getMaxMemory();
44-
45-
/**
46-
* Returns the maximum number of players per server in this group.
47-
*
48-
* @return the max players, or null if not set
49-
*/
50-
@Nullable Integer getMaxPlayers();
51-
5225
/**
5326
* Returns the deployment configuration for this group.
5427
*
@@ -66,58 +39,4 @@ public interface Group {
6639
* @return the scaling config, or null if not set
6740
*/
6841
@Nullable ScalingConfig getScaling();
69-
70-
/**
71-
* Returns the source configuration for this group.
72-
*
73-
* <p>Defines whether servers use a blueprint or container image.
74-
*
75-
* @return the source config, or null if not set
76-
*/
77-
@Nullable SourceConfig getSource();
78-
79-
/**
80-
* Returns the workflows configuration for this group.
81-
*
82-
* <p>Defines automated workflows to run on server lifecycle events.
83-
*
84-
* @return the workflows config, or null if not set
85-
*/
86-
@Nullable WorkflowsConfig getWorkflows();
87-
88-
/**
89-
* Returns custom properties attached to this group.
90-
*
91-
* @return the properties map, or null if none set
92-
*/
93-
@Nullable Map<String, Object> getProperties();
94-
95-
/**
96-
* Returns tags assigned to this group for organization and filtering.
97-
*
98-
* @return the list of tags, or null if none set
99-
*/
100-
@Nullable List<String> getTags();
101-
102-
/**
103-
* Returns the type of servers in this group (SERVER or PROXY).
104-
*
105-
* @return the group type
106-
*/
107-
GroupServerType getType();
108-
109-
/**
110-
* Returns the timestamp when this group was created (ISO 8601 format).
111-
*
112-
* @return the creation timestamp
113-
*/
114-
String getCreatedAt();
115-
116-
/**
117-
* Returns the timestamp when this group was last updated (ISO 8601 format).
118-
*
119-
* @return the update timestamp
120-
*/
121-
String getUpdatedAt();
12242
}
123-

api/src/main/java/app/simplecloud/api/internal/event/server/ServerUpdatedEventImpl.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,4 @@ private String convertServerTypeToString(build.buf.gen.simplecloud.controller.v2
105105
}
106106

107107

108+

0 commit comments

Comments
 (0)