Skip to content

Commit

Permalink
Version 0.9.1
Browse files Browse the repository at this point in the history
Fully working version just not all features i wanna implement.
- Added PanelAPIClient for the ease of implementing new API's from different Panels.
- Added PelicanAPIClient for the support of the Pelican Panel
- Add new variable to the ConfigurationManager to atomaticly detect what Panel is beeing used using the API key
- updated config.yml

Took 3 hours 29 minutes
  • Loading branch information
TubYoub committed Jul 14, 2024
1 parent e6daf53 commit 85e50d7
Show file tree
Hide file tree
Showing 11 changed files with 161 additions and 84 deletions.
53 changes: 1 addition & 52 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>de.tubyoub</groupId>
<artifactId>VelocityPteroPower</artifactId>
<version>0.9</version>
<version>0.9.1</version>
<packaging>jar</packaging>

<name>VelocityPteroPower</name>
Expand All @@ -20,48 +20,6 @@
<profile>
<id>beta</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
Expand Down Expand Up @@ -168,15 +126,6 @@
</plugins>
</build>

<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.2.0</version>
</plugin>
</plugins>
</reporting>

<repositories>
<repository>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

package de.tubyoub.velocitypteropower;

import de.tubyoub.velocitypteropower.api.PanelType;
import dev.dejvokep.boostedyaml.YamlDocument;
import dev.dejvokep.boostedyaml.block.implementation.Section;
import dev.dejvokep.boostedyaml.dvs.versioning.BasicVersioning;
Expand All @@ -47,10 +48,11 @@
*/

public class ConfigurationManager {
private Path dataDirectory;
private Path dataDirectory;
private YamlDocument config;
private String pterodactylUrl;
private String pterodactylApiKey;
private String panelUrl;
private String apiKey;
private PanelType panel;
private boolean checkUpdate;
private int startupJoinDelay;
private final VelocityPteroPower plugin;
Expand Down Expand Up @@ -108,11 +110,12 @@ public void loadConfig(){
pterodactyl.put(key, value);
}
}
pterodactylUrl = (String) pterodactyl.get("url");
if (!pterodactylUrl.endsWith("/")) {
pterodactylUrl += "/";
panelUrl = (String) pterodactyl.get("url");
if (!panelUrl.endsWith("/")) {
panelUrl += "/";
}
pterodactylApiKey = (String) pterodactyl.get("apiKey");
apiKey = (String) pterodactyl.get("apiKey");
panel = detectPanelType(apiKey);


Section serversSection = config.getSection("servers");
Expand Down Expand Up @@ -163,6 +166,17 @@ public Map<String, PteroServerInfo> processServerSection(Section serversSection)
return serverInfoMap;
}

private PanelType detectPanelType(String apiKey) {
if (apiKey.startsWith("ptlc_")) {
return PanelType.pterodactyl;
} else if (apiKey.startsWith("peli_")) {
return PanelType.pelican;
} else {
// Default to Pterodactyl if the prefix is not recognized
return PanelType.pterodactyl;
}
}


/**
* This method returns the map of server names to PteroServerInfo objects.
Expand All @@ -179,7 +193,7 @@ public Map<String, PteroServerInfo> getServerInfoMap() {
* @return the Pterodactyl URL
*/
public String getPterodactylUrl() {
return pterodactylUrl;
return panelUrl;
}

/**
Expand All @@ -188,7 +202,7 @@ public String getPterodactylUrl() {
* @return the Pterodactyl API key
*/
public String getPterodactylApiKey() {
return pterodactylApiKey;
return apiKey;
}

/**
Expand All @@ -209,4 +223,7 @@ public int getStartupJoinDelay() {
return startupJoinDelay;
}

}
public PanelType getPanelType(){
return panel;
}
}
9 changes: 5 additions & 4 deletions src/main/java/de/tubyoub/velocitypteropower/PteroCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.velocitypowered.api.command.SimpleCommand;
import com.velocitypowered.api.proxy.Player;
import com.velocitypowered.api.proxy.ProxyServer;
import de.tubyoub.velocitypteropower.api.PanelAPIClient;
import de.tubyoub.velocitypteropower.api.PterodactylAPIClient;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
Expand All @@ -48,7 +49,7 @@ public class PteroCommand implements SimpleCommand {
private final ProxyServer proxyServer;
private final VelocityPteroPower plugin;
private final Logger logger;
private final PterodactylAPIClient pterodactylAPIClient;
private final PanelAPIClient apiClient;
private final ConfigurationManager configurationManager;

/**
Expand All @@ -59,7 +60,7 @@ public PteroCommand(VelocityPteroPower plugin) {
this.plugin = plugin;
this.proxyServer = plugin.getProxyServer();
this.logger = plugin.getLogger();
this.pterodactylAPIClient = plugin.getPterodactylAPIClient();
this.apiClient = plugin.getAPIClient();
this.configurationManager = plugin.getConfigurationManager();
}

Expand Down Expand Up @@ -126,7 +127,7 @@ private void startServer(Player player, String[] args) {
Map<String, PteroServerInfo> serverInfoMap = plugin.getServerInfoMap();
if (serverInfoMap.containsKey(serverName)) {
PteroServerInfo serverInfo = serverInfoMap.get(serverName);
pterodactylAPIClient.powerServer(serverInfo.getServerId(), "start");
apiClient.powerServer(serverInfo.getServerId(), "start");
player.sendMessage(getSPPPrefix().append(Component.text("The server: "+ serverName + " is starting")));
} else {
}
Expand All @@ -147,7 +148,7 @@ private void stopServer(Player player, String[] args) {
Map<String, PteroServerInfo> serverInfoMap = plugin.getServerInfoMap();
if (serverInfoMap.containsKey(serverName)) {
PteroServerInfo serverInfo = serverInfoMap.get(serverName);
pterodactylAPIClient.powerServer(serverInfo.getServerId(), "stop");
apiClient.powerServer(serverInfo.getServerId(), "stop");
player.sendMessage(getSPPPrefix().append(Component.text("The server: "+ serverName + " is stopping")));
} else {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@

package de.tubyoub.velocitypteropower;

import java.util.List;

/**
* This class represents the server information for a Pterodactyl server.
* It includes the server ID, timeout, and join delay.
Expand All @@ -35,7 +33,6 @@ public class PteroServerInfo {
private final int timeout;
private final int joinDelay;


/**
* Constructor for the PteroServerInfo class.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import com.velocitypowered.api.proxy.ProxyServer;
import com.velocitypowered.api.proxy.ServerConnection;
import com.velocitypowered.api.proxy.server.RegisteredServer;
import de.tubyoub.velocitypteropower.api.PanelAPIClient;
import de.tubyoub.velocitypteropower.api.PterodactylAPIClient;
import org.slf4j.Logger;

Expand All @@ -47,7 +48,7 @@ public class ServerSwitchListener {
private final Logger logger;
private final VelocityPteroPower plugin;
private final ProxyServer proxyServer;
private final PterodactylAPIClient pterodactylAPIClient;
private final PanelAPIClient apiClient;
private final ConfigurationManager configurationManager;
private final Set<String> startingServers = ConcurrentHashMap.newKeySet();
private Map<String, PteroServerInfo> serverInfoMap;
Expand All @@ -61,7 +62,7 @@ public ServerSwitchListener(VelocityPteroPower plugin){
this.plugin = plugin;
this.logger = plugin.getLogger();
this.proxyServer = plugin.getProxyServer();
this.pterodactylAPIClient = plugin.getPterodactylAPIClient();
this.apiClient = plugin.getAPIClient();
this.configurationManager = plugin.getConfigurationManager();
this.serverInfoMap = configurationManager.getServerInfoMap();
}
Expand All @@ -78,7 +79,7 @@ public void onDisconnect(DisconnectEvent event) {
if (serverConnection.isPresent()) {
String serverName = serverConnection.get().getServerInfo().getName();
PteroServerInfo serverInfo = plugin.getServerInfoMap().get(serverName);
if (serverInfo != null && pterodactylAPIClient.isServerEmpty(serverName)) {
if (serverInfo != null && apiClient.isServerEmpty(serverName)) {
plugin.scheduleServerShutdown(serverName, serverInfo.getServerId(), serverInfo.getTimeout());
}
}
Expand All @@ -96,7 +97,7 @@ public void onServerSwitch(ServerConnectedEvent event) {
if (previousServerConnection.isPresent()) {
String serverName = previousServerConnection.get().getServerInfo().getName();
PteroServerInfo serverInfo = plugin.getServerInfoMap().get(serverName);
if (serverInfo != null && pterodactylAPIClient.isServerEmpty(serverInfo.getServerId())) {
if (serverInfo != null && apiClient.isServerEmpty(serverInfo.getServerId())) {
plugin.scheduleServerShutdown(serverName, serverInfo.getServerId(), serverInfo.getTimeout());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
import com.velocitypowered.api.proxy.Player;
import com.velocitypowered.api.proxy.ProxyServer;
import com.velocitypowered.api.proxy.server.RegisteredServer;
import de.tubyoub.velocitypteropower.api.PanelAPIClient;
import de.tubyoub.velocitypteropower.api.PanelType;
import de.tubyoub.velocitypteropower.api.PelicanAPIClient;
import de.tubyoub.velocitypteropower.api.PterodactylAPIClient;
import de.tubyoub.velocitypteropower.libs.Metrics;
import net.kyori.adventure.text.Component;
Expand All @@ -43,6 +46,7 @@
import net.kyori.adventure.text.minimessage.MiniMessage;

import java.nio.file.Path;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
Expand All @@ -63,6 +67,8 @@ public class VelocityPteroPower {
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 @@ -101,7 +107,14 @@ public void onProxyInitialize(ProxyInitializeEvent event) {
logger.info(MiniMessage.miniMessage().deserialize("<#4287f5> \\ / | | | |"+ "<#00ff77> VelocityPteroPower <#6b6c6e>v" + version));
logger.info(MiniMessage.miniMessage().deserialize("<#4287f5> \\___/ |____|tero|____|ower" + "<#A9A9A9> Running with Blackmagic on Velocity"));
configurationManager.loadConfig();
this.pterodactylAPIClient = new PterodactylAPIClient(this);
if (configurationManager.getPanelType() == PanelType.pelican) {
logger.info("detected the pelican panel");
this.apiClient = new PelicanAPIClient(this);
} else {
logger.info("detected the pterodactyl panel");
this.apiClient = new PterodactylAPIClient(this);
}

commandManager.register("ptero", new PteroCommand(this));
proxyServer.getEventManager().register(this,new ServerSwitchListener(this));

Expand Down Expand Up @@ -133,7 +146,7 @@ public void scheduleServerShutdown(String serverName,String serverID, int timeou
logger.info("Shutting down server: " + serverName);
}else {
logger.info("Shutdown cancelled for server: " + serverName + ". Players are present.");
}
}
}).delay(timeout, TimeUnit.SECONDS).schedule();
}
/**
Expand Down Expand Up @@ -283,8 +296,8 @@ public Path getDataDirectory(){
*
* @return the PterodactylAPIClient instance
*/
public PterodactylAPIClient getPterodactylAPIClient(){
return pterodactylAPIClient;
public PanelAPIClient getAPIClient() {
return apiClient;
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package de.tubyoub.velocitypteropower.api;

public interface PanelAPIClient {
void powerServer(String serverId, String signal);
boolean isServerOnline(String serverId);
boolean isServerEmpty(String serverName);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package de.tubyoub.velocitypteropower.api;

public enum PanelType {
pterodactyl,
pelican
}
Loading

0 comments on commit 85e50d7

Please sign in to comment.