Compare commits

..

2 Commits

Author SHA1 Message Date
e1ff91f1d8 Refactored to new domain name and locked spigot dependency version.
Some checks failed
RealYHD/mcswebapi/pipeline/head There was a failure building this commit
2022-12-08 20:08:05 +00:00
56e0c8f22a Commit for archival reasons. 2022-05-16 01:33:14 -05:00
15 changed files with 292 additions and 68 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": "net.reslate.mcswebapi.App",
"projectName": "mcswebapi"
},
{
"type": "java",
"name": "Attach",
"request": "attach",
"hostName": "localhost",
"port": "25577"
}
]
}

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

@ -0,0 +1,11 @@
{
"java.configuration.updateBuildConfiguration": "automatic",
"yaml.schemas": {
"https://json.schemastore.org/bukkit-plugin.json": "file:///home/ydeng/MCSWebAPI/plugin.yml"
},
"cSpell.words": [
"Javalin",
"mcswebapi"
],
"java.compile.nullAnalysis.mode": "automatic"
}

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'
}
}
}
}

6
environment.yml Normal file
View File

@ -0,0 +1,6 @@
name: mcswebapi
channels:
- conda-forge
dependencies:
- openjdk=17.0.*
- maven=3.8.*

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!" );
}
}

View File

@ -1,38 +0,0 @@
package xyz.reslate.mcswebapi;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
/**
* Unit test for simple App.
*/
public class AppTest
extends TestCase
{
/**
* Create the test case
*
* @param testName name of the test case
*/
public AppTest( String testName )
{
super( testName );
}
/**
* @return the suite of tests being tested
*/
public static Test suite()
{
return new TestSuite( AppTest.class );
}
/**
* Rigourous Test :-)
*/
public void testApp()
{
assertTrue( true );
}
}

65
pom.xml Normal file
View File

@ -0,0 +1,65 @@
<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>net.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>5.0.1</version>
</dependency>
<dependency>
<groupId>io.javalin</groupId>
<artifactId>javalin</artifactId>
<version>5.2.0</version>
</dependency>
<dependency>
<groupId>org.pac4j</groupId>
<artifactId>pac4j-oauth</artifactId>
<version>5.5.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>1.19.2-R0.1-SNAPSHOT</version>
<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 net.reslate.mcswebapi;
import java.util.logging.Logger;
import org.bukkit.plugin.java.JavaPlugin;
import io.javalin.Javalin;
import net.reslate.mcswebapi.controllers.ControllerGroup;
import net.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 net.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 net.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 net.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: net.reslate.mcswebapi.MCSWebAPI
name: MCSWebAPI
version: 0.0.1
author: Reslate
description: "A Minecraft Server Web API."

View File

@ -0,0 +1,14 @@
package net.reslate.mcswebapi;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;
class MyFirstJUnitJupiterTests {
@Test
void testCase() {
assertEquals(2, 2);
}
}