Skip to content
This repository has been archived by the owner on Jun 7, 2022. It is now read-only.

Commit

Permalink
Add Core builders
Browse files Browse the repository at this point in the history
Rename API builders
Make ServerProcessMeta inherit from ServerProcessData
Remove custom server name functionality
Remove startGameServer methods
Remove a lot of priority stop functionality
  • Loading branch information
GiantTreeLP committed Mar 1, 2020
1 parent 8593e33 commit 6d4ee74
Show file tree
Hide file tree
Showing 25 changed files with 511 additions and 1,284 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import de.dytanic.cloudnet.api.CloudAPI;
import de.dytanic.cloudnet.api.CloudService;
import de.dytanic.cloudnet.api.builders.ServerProcessBuilder;
import de.dytanic.cloudnet.api.builders.ApiServerProcessBuilder;
import de.dytanic.cloudnet.api.handlers.NetworkHandler;
import de.dytanic.cloudnet.api.network.packet.out.PacketOutUpdateServerInfo;
import de.dytanic.cloudnet.bridge.event.bukkit.*;
Expand Down Expand Up @@ -164,9 +164,9 @@ public void changeToIngame() {
serverState = ServerState.INGAME;

if (allowAutoStart) {
ServerProcessBuilder.create(CloudAPI.getInstance().getGroup())
.template(template)
.startServer();
ApiServerProcessBuilder.create(CloudAPI.getInstance().getGroup())
.template(template)
.startServer();
allowAutoStart = false;

Bukkit.getScheduler().runTaskLater(bukkitBootstrap, () -> allowAutoStart = true, 6000);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.google.common.collect.Lists;
import de.dytanic.cloudnet.api.CloudAPI;
import de.dytanic.cloudnet.api.builders.ApiProxyProcessBuilder;
import de.dytanic.cloudnet.api.builders.ServerProcessBuilder;
import de.dytanic.cloudnet.api.builders.ApiServerProcessBuilder;
import de.dytanic.cloudnet.bridge.CloudProxy;
import de.dytanic.cloudnet.lib.DefaultType;
import de.dytanic.cloudnet.lib.NetworkUtils;
Expand Down Expand Up @@ -265,9 +265,9 @@ public void execute(CommandSender commandSender, String[] args) {
return;
} else if (args[0].equalsIgnoreCase("start") && commandSender.hasPermission("cloudnet.command.cloud.start")) {
if (CloudAPI.getInstance().getCloudNetwork().getServerGroups().containsKey(args[1])) {
ServerProcessBuilder.create(args[1])
.serverConfig(new ServerConfig())
.startServer();
ApiServerProcessBuilder.create(args[1])
.serverConfig(new ServerConfig())
.startServer();
commandSender.sendMessage(TextComponent.fromLegacyText(CloudAPI.getInstance()
.getPrefix() + "The information was sent to the cloud"));
} else if (CloudAPI.getInstance().getCloudNetwork().getProxyGroups().containsKey(args[1])) {
Expand Down Expand Up @@ -412,10 +412,10 @@ public void execute(CommandSender commandSender, String[] args) {
if (CloudAPI.getInstance().getServerGroupMap().containsKey(args[1])) {
if (NetworkUtils.checkIsNumber(args[2])) {
for (short i = 0; i < Integer.parseInt(args[2]); i++) {
ServerProcessBuilder.create(args[1])
.serverConfig(
new ServerConfig())
.startServer();
ApiServerProcessBuilder.create(args[1])
.serverConfig(
new ServerConfig())
.startServer();
}
commandSender.sendMessage(TextComponent.fromLegacyText(CloudAPI.getInstance()
.getPrefix() + "The information was sent to the cloud"));
Expand All @@ -427,11 +427,11 @@ public void execute(CommandSender commandSender, String[] args) {
.equalsIgnoreCase(args[2]))
.findFirst();
template.ifPresent(value -> {
ServerProcessBuilder.create(args[1])
.serverConfig(
new ServerConfig())
.template(value)
.startServer();
ApiServerProcessBuilder.create(args[1])
.serverConfig(
new ServerConfig())
.template(value)
.startServer();
commandSender.sendMessage(TextComponent.fromLegacyText(CloudAPI.getInstance()
.getPrefix() + "The information was sent to the cloud"));
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package de.dytanic.cloudnet.bridge.internal.listener.bukkit;

import de.dytanic.cloudnet.api.CloudAPI;
import de.dytanic.cloudnet.api.builders.ServerProcessBuilder;
import de.dytanic.cloudnet.api.builders.ApiServerProcessBuilder;
import de.dytanic.cloudnet.bridge.CloudServer;
import de.dytanic.cloudnet.bridge.event.bukkit.BukkitCloudNetworkUpdateEvent;
import de.dytanic.cloudnet.bridge.event.bukkit.BukkitCloudServerInitEvent;
Expand Down Expand Up @@ -184,14 +184,13 @@ public void handle(PlayerJoinEvent event) {
if (CloudServer.getInstance().getPercentOfPlayerNowOnline() >= CloudServer.getInstance()
.getGroupData()
.getPercentForNewServerAutomatically() &&
CloudServer.getInstance().getServerProcessMeta().getCustomServerDownload() == null &&
!CloudServer.getInstance().getGroupData().getMode().equals(ServerGroupMode.STATIC) &&
CloudServer.getInstance().isAllowAutoStart() &&
CloudServer.getInstance().getGroupData().getPercentForNewServerAutomatically() > 0) {
ServerProcessBuilder.create(CloudAPI.getInstance().getGroup())
.serverConfig(new ServerConfig())
.template(CloudServer.getInstance().getTemplate())
.startServer();
ApiServerProcessBuilder.create(CloudAPI.getInstance().getGroup())
.serverConfig(new ServerConfig())
.template(CloudServer.getInstance().getTemplate())
.startServer();
CloudServer.getInstance().setAllowAutoStart(false);

Bukkit.getScheduler().runTaskLater(CloudServer.getInstance().getPlugin(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package de.dytanic.cloudnet.api.builders;

import de.dytanic.cloudnet.api.CloudAPI;
import de.dytanic.cloudnet.api.network.packet.api.PacketOutStartServer;
import de.dytanic.cloudnet.lib.process.ServerProcessBuilder;
import de.dytanic.cloudnet.lib.process.ServerProcessData;
import de.dytanic.cloudnet.lib.server.ServerProcessMeta;

import java.util.UUID;
import java.util.concurrent.CompletableFuture;

/**
* Builder for a server process in the API for proxies and servers.
* Uses {@link ServerProcessData} for storing the data.
*/
public class ApiServerProcessBuilder extends ServerProcessBuilder {

/**
* Creates a new server process builder for a server of the specified server group.
* This value is mandatory as servers cannot be started without belonging to a group.
*
* @param serverGroupName the name of the server group that the server will be started from.
*
* @return the newly created server process builder.
*/
public static ServerProcessBuilder create(String serverGroupName) {
return new ApiServerProcessBuilder().serverGroupName(serverGroupName);
}

/**
* Requests the master to initiate this server startup.
* This will trigger a sequence of messages to be passed between the calling service,
* the master and the wrapper that will start the server.
* <p>
* Once the server is started, the returned future will be completed and contains the
* process metadata that was valid at the time of starting up.
* <p>
* Note that the delay between requesting the start (ie. this method) and the actual
* completion of the returned future is indefinite and the future may not actually
* be completed at all-
*
* @return a future that will be completed once the server is connected to the cloud network.
*/
public CompletableFuture<ServerProcessMeta> startServer() {
final UUID uuid = UUID.randomUUID();
this.getServerProcessData().getServerConfig().getProperties().append("cloudnet:requestId", uuid);
CloudAPI.getInstance().getNetworkConnection().sendAsynchronous(
new PacketOutStartServer(this.getServerProcessData())
);
return CloudAPI.getInstance().getCloudService().waitForServer(uuid);
}

}
Loading

1 comment on commit 6d4ee74

@GiantTreeLP
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Closes #236

Please sign in to comment.