Skip to content

Commit

Permalink
Fixing Nullpointerexeption
Browse files Browse the repository at this point in the history
Fully working version just not all features i wanna implement.
- removed virables pterodactylAPIClient, pelicanAPIClient
- updated all methods to use apiClient

Took 16 minutes
  • Loading branch information
TubYoub committed Jul 17, 2024
1 parent 8c16bc1 commit 4fda6f8
Showing 1 changed file with 9 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,14 @@
*/
@Plugin(id = "velocity-ptero-power", name = "VelocityPteroPower", version = "0.9", authors = {"TubYoub"})
public class VelocityPteroPower {
private final String version = "0.9";
private final String version = "0.9.2";
private final int pluginId = 21465;
private final ProxyServer proxyServer;
private final ComponentLogger logger;
private final Path dataDirectory;
private Map<String, PteroServerInfo> serverInfoMap;
private final CommandManager commandManager;
private final ConfigurationManager configurationManager;
private PterodactylAPIClient pterodactylAPIClient;
private PelicanAPIClient pelicanAPIClient;
private PanelAPIClient apiClient;
private final Metrics.Factory metricsFactory;
private final Set<String> startingServers = ConcurrentHashMap.newKeySet();
Expand Down Expand Up @@ -141,8 +139,8 @@ public void scheduleServerShutdown(String serverName,String serverID, int timeou
}
logger.info("Scheduling server shutdown for " + serverName + " in " + timeout + " seconds.");
proxyServer.getScheduler().buildTask(this, () -> {
if (pterodactylAPIClient.isServerEmpty(serverName)) {
pterodactylAPIClient.powerServer(serverID, "stop");
if (apiClient.isServerEmpty(serverName)) {
apiClient.powerServer(serverID, "stop");
logger.info("Shutting down server: " + serverName);
}else {
logger.info("Shutdown cancelled for server: " + serverName + ". Players are present.");
Expand Down Expand Up @@ -175,7 +173,7 @@ public void onServerPreConnect(ServerPreConnectEvent event) {
.append(Component.text("] Server not found in configuration: " + serverName, NamedTextColor.WHITE)));
return;
}
if (pterodactylAPIClient.isServerOnline(serverInfo.getServerId())) {
if (apiClient.isServerOnline(serverInfo.getServerId())) {
if (startingServers.contains(serverName)){
startingServers.remove(serverName);
}
Expand All @@ -191,15 +189,15 @@ public void onServerPreConnect(ServerPreConnectEvent event) {
}

startingServers.add(serverName);
pterodactylAPIClient.powerServer(serverInfo.getServerId(), "start");
apiClient.powerServer(serverInfo.getServerId(), "start");
player.sendMessage(
Component.text("[", NamedTextColor.WHITE)
.append(Component.text("VPP", TextColor.color(66,135,245)))
.append(Component.text("] Starting server: " + serverName, NamedTextColor.WHITE)));
event.setResult(ServerPreConnectEvent.ServerResult.denied());

proxyServer.getScheduler().buildTask(this, () -> {
if (pterodactylAPIClient.isServerOnline(serverInfo.getServerId())) {
if (apiClient.isServerOnline(serverInfo.getServerId())) {
connectPlayer(player, serverName);
} else {
proxyServer.getScheduler().buildTask(this, () -> checkServerAndConnectPlayer(player, serverName)).schedule();
Expand All @@ -209,7 +207,7 @@ public void onServerPreConnect(ServerPreConnectEvent event) {

private void checkServerAndConnectPlayer(Player player, String serverName) {
PteroServerInfo serverInfo = serverInfoMap.get(serverName);
if (pterodactylAPIClient.isServerOnline(serverInfo.getServerId())) {
if (apiClient.isServerOnline(serverInfo.getServerId())) {
connectPlayer(player, serverName);
} else {
proxyServer.getScheduler().buildTask(this, () -> checkServerAndConnectPlayer(player, serverName)).delay(configurationManager.getStartupJoinDelay(), TimeUnit.SECONDS).schedule();
Expand All @@ -230,7 +228,7 @@ private void connectPlayer(Player player, String serverName) {
RegisteredServer server = proxyServer.getServer(serverName).orElseThrow(() -> new RuntimeException("Server not found: " + serverName));

if (!player.getCurrentServer().isPresent()) {
if (pterodactylAPIClient.isServerEmpty(serverName)){
if (apiClient.isServerEmpty(serverName)){
this.scheduleServerShutdown(serverName, serverInfoMap.get(serverName).getServerId(),serverInfoMap.get(serverName).getTimeout());
}
return;
Expand All @@ -240,7 +238,7 @@ private void connectPlayer(Player player, String serverName) {
return;
}

if (pterodactylAPIClient.isServerOnline(serverInfoMap.get(serverName).getServerId())) {
if (apiClient.isServerOnline(serverInfoMap.get(serverName).getServerId())) {
player.createConnectionRequest(server).fireAndForget();
startingServers.remove(serverName);
}
Expand Down

0 comments on commit 4fda6f8

Please sign in to comment.