Commit for archival reasons.

This commit is contained in:
Harrison Deng 2022-05-16 01:33:14 -05:00
parent 2866df727f
commit 56e0c8f22a
13 changed files with 280 additions and 30 deletions

22
.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,22 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "java",
"name": "Launch App",
"request": "launch",
"mainClass": "xyz.reslate.mcswebapi.App",
"projectName": "mcswebapi"
},
{
"type": "java",
"name": "Attach",
"request": "attach",
"hostName": "localhost",
"port": "25577"
}
]
}

6
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,6 @@
{
"java.configuration.updateBuildConfiguration": "automatic",
"yaml.schemas": {
"https://json.schemastore.org/bukkit-plugin.json": "file:///home/ydeng/MCSWebAPI/plugin.yml"
}
}

45
.vscode/tasks.json vendored Normal file
View File

@ -0,0 +1,45 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "verify",
"type": "shell",
"command": "mvn -B verify",
"group": "build"
},
{
"label": "package",
"type": "shell",
"command": "mvn -B package",
"group": "build"
},
{
"label": "test",
"type": "shell",
"command": "mvn -B test",
"group": "test"
},
{
"label": "load latest build",
"type": "shell",
"command": "python3",
"args": [
"${workspaceFolder}/SpigotPluginBaseTools/load_plugin.py"
],
"dependsOn": "package",
"problemMatcher": []
},
{
"label": "launch dev. server",
"type": "shell",
"command": "python3",
"dependsOn": "load latest build",
"args": [
"${workspaceFolder}/SpigotPluginBaseTools/start_server.py"
],
"problemMatcher": []
},
]
}

10
Jenkinsfile vendored Normal file
View File

@ -0,0 +1,10 @@
pipeline {
agent any
stages {
stage('tests') {
steps {
sh 'mvn -B test'
}
}
}
}

View File

@ -1,17 +0,0 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>xyz.reslate.mcswebapi</groupId>
<artifactId>mcswebapi</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>mcswebapi</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency><groupId>org.spigotmc</groupId><artifactId>spigot-api</artifactId><version>LATEST</version><type>jar</type><scope>provided</scope></dependency></dependencies>
<repositories><repository><id>spigot-repo</id><url>https://hub.spigotmc.org/nexus/content/repositories/public/</url></repository></repositories></project>

View File

@ -1,13 +0,0 @@
package xyz.reslate.mcswebapi;
/**
* Hello world!
*
*/
public class App
{
public static void main( String[] args )
{
System.out.println( "Hello World!" );
}
}

78
pom.xml Normal file
View File

@ -0,0 +1,78 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>xyz.reslate.mcswebapi</groupId>
<artifactId>mcswebapi</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
</properties>
<name>mcswebapi</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>org.reflections</groupId>
<artifactId>reflections</artifactId>
<version>0.10.2</version>
</dependency>
<dependency>
<groupId>org.pac4j</groupId>
<artifactId>javalin-pac4j</artifactId>
<version>4.0.0</version>
</dependency>
<dependency>
<groupId>io.javalin</groupId>
<artifactId>javalin</artifactId>
<version>4.3.0</version>
</dependency>
<dependency>
<groupId>org.pac4j</groupId>
<artifactId>pac4j-oauth</artifactId>
<version>5.3.0</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.8.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>LATEST</version>
<type>jar</type>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.22.2</version>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/public/</url>
</repository>
</repositories>
</project>

View File

@ -0,0 +1,43 @@
package xyz.reslate.mcswebapi;
import java.util.logging.Logger;
import org.bukkit.plugin.java.JavaPlugin;
import io.javalin.Javalin;
import xyz.reslate.mcswebapi.controllers.ControllerGroup;
import xyz.reslate.mcswebapi.controllers.PublicServerInformation;
public class MCSWebAPI extends JavaPlugin
{
private Javalin javalin;
@Override
public void onEnable() {
Logger logger = getLogger();
logger.info("Enabling MCSWebAPI...");
javalin = Javalin.create();
javalin.start(8080);
prepareControllers(javalin);
super.onEnable();
logger.info("Enabled MCSWebAPI.");
}
@Override
public void onDisable() {
Logger logger = getLogger();
logger.info("Disabling MCSWebAPI...");
javalin.close();
super.onDisable();
logger.info("Disabled MCSWebAPI.");
}
public void prepareControllers(Javalin javalin) {
ControllerGroup controllerGroup = new ControllerGroup(javalin,
new PublicServerInformation()
);
controllerGroup.loadAll();
}
}

View File

@ -0,0 +1,22 @@
package xyz.reslate.mcswebapi.controllers;
import java.util.Arrays;
import java.util.HashSet;
import io.javalin.Javalin;
public class ControllerGroup {
private final HashSet<WebControllable> controllers;
private final Javalin javalin;
public ControllerGroup(Javalin javalin, WebControllable... controllers) {
super();
this.javalin = javalin;
this.controllers = new HashSet<>(Arrays.asList(controllers));
}
public void loadAll() {
for (WebControllable controller : controllers) {
controller.register(javalin);
}
}
}

View File

@ -0,0 +1,38 @@
package xyz.reslate.mcswebapi.controllers;
import java.util.ArrayList;
import org.bukkit.Bukkit;
import io.javalin.Javalin;
import io.javalin.http.Context;
public class PublicServerInformation implements WebControllable {
private String route = "/api/GeneralServerInfo";
public void getNumPlayersOnline(Context ctx) {
ctx.json(Bukkit.getOnlinePlayers().size());
}
public void getMaximumNumPlayers(Context ctx) {
ctx.json(Bukkit.getMaxPlayers());
}
public void getServerVersion(Context ctx) {
ctx.json(Bukkit.getBukkitVersion());
}
public void getWhitelistedPlayers(Context ctx) {
ArrayList<String> playerNames = new ArrayList<>();
Bukkit.getWhitelistedPlayers().forEach(player -> playerNames.add(player.getName()));
ctx.json(playerNames);
}
@Override
public void register(Javalin javalin) {
javalin.get(route + "/numPlayersOnline", this::getNumPlayersOnline);
javalin.get(route + "/maximumNumPlayers", this::getMaximumNumPlayers);
javalin.get(route + "/serverVersion", this::getServerVersion);
javalin.get(route + "/whitelistedPlayernames", this::getWhitelistedPlayers);
}
}

View File

@ -0,0 +1,11 @@
package xyz.reslate.mcswebapi.controllers;
import io.javalin.Javalin;
public interface WebControllable {
/**
* Register the endpoints with their respective functions.
* @param javalin The running Javalin instance these endpoints will be hosted on.
*/
public void register(Javalin javalin);
}

View File

@ -0,0 +1,5 @@
main: xyz.reslate.mcswebapi.MCSWebAPI
name: MCSWebAPI
version: 0.0.1
author: reslate
description: "A Minecraft Server Web API."