|
1 | | -# ZenithProxy Example Plugin |
| 1 | +# ZenithProxy Web API Plugin |
2 | 2 |
|
3 | | -[ZenithProxy](https://github.com/rfresh2/ZenithProxy) is a Minecraft proxy and bot. |
| 3 | +Runs a local web server that lets you interact with the ZenithProxy instance. |
4 | 4 |
|
5 | | -This repository is an example core plugin for ZenithProxy, allowing you to add custom modules and commands. |
| 5 | +# Commands |
6 | 6 |
|
7 | | -## Installing Plugins |
| 7 | +## `webApi` |
8 | 8 |
|
9 | | -Plugins are only supported on the `java` ZenithProxy release channel (i.e. not `linux`). |
| 9 | +* `webApi on/off` -> default: on |
| 10 | +* `webApi port <port>` -> default: 8080 |
| 11 | +* `webApi auth <token>` |
10 | 12 |
|
11 | | -Place plugin jars in the `plugins` folder inside the same folder as the ZenithProxy launcher. |
| 13 | +# HTTP API |
12 | 14 |
|
13 | | -Restart ZenithProxy to load plugins. Loading plugins after launch or hot reloading is not supported. |
| 15 | +## Authorization |
14 | 16 |
|
15 | | -## Creating Plugins |
| 17 | +All HTTP requests must have an `Authorization` header. |
16 | 18 |
|
17 | | -Use this repository as a template to create your own plugin repository. |
| 19 | +A default auth token is generated on first launch. |
18 | 20 |
|
19 | | -### Plugin Structure |
| 21 | +Or it can be set with the `webApi auth <token>` command. |
20 | 22 |
|
21 | | -Each plugin needs a main class that implements `ZenithProxyPlugin` and is annotated with `@Plugin`. |
| 23 | +## POST `/command` |
22 | 24 |
|
23 | | -Plugin metadata like its unique id, version, and supported MC versions is defined in the `@Plugin` annotation. |
| 25 | +### Request Body |
24 | 26 |
|
25 | | -[See example](https://github.com/rfresh2/ZenithProxyExamplePlugin/blob/1.21.0/src/main/java/org/example/ExamplePlugin.java) |
| 27 | +```json |
| 28 | +{ |
| 29 | + "command": "status" |
| 30 | +} |
| 31 | +``` |
26 | 32 |
|
27 | | -### Plugin API |
| 33 | +### Response |
28 | 34 |
|
29 | | -The `ZenithProxyPlugin` interface requires you to implement an `onLoad` method. |
| 35 | +```json |
| 36 | +{ |
| 37 | + "embed": "\nZenithProxy 0.0.0 - Unknown\n\nStatus\nDisconnected\nConnected Player\nNone\nOnline For\nNot Online!\nHealth\n20.0\nDimension\nNone\nPing\n0ms\nProxy IP\nlocalhost\nServer\nconnect.2b2t.org:25565\nPriority Queue\nno [unbanned]\nSpectators\non\n2b2t Queue\nPriority: 15 [00:25:49]\nRegular: 688 [07:49:27]\nCoordinates\n||[0, 0, 0]||\nAutoUpdate\non", |
| 38 | + "embedComponent": "{\"color\":\"#E91E63\",\"extra\":[\"\\n\",{\"bold\":true,\"text\":\"ZenithProxy 0.0.0 - Unknown\"},\"\\n\",\"\\n\",{\"bold\":true,\"extra\":[\"\\n\"],\"text\":\"Status\"},{\"extra\":[\"Disconnected\"],\"text\":\"\"},\"\\n\",{\"bold\":true,\"extra\":[\"\\n\"],\"text\":\"Connected Player\"},{\"extra\":[\"None\"],\"text\":\"\"},\"\\n\",{\"bold\":true,\"extra\":[\"\\n\"],\"text\":\"Online For\"},{\"extra\":[\"Not Online!\"],\"text\":\"\"},\"\\n\",{\"bold\":true,\"extra\":[\"\\n\"],\"text\":\"Health\"},{\"extra\":[\"20.0\"],\"text\":\"\"},\"\\n\",{\"bold\":true,\"extra\":[\"\\n\"],\"text\":\"Dimension\"},{\"extra\":[\"None\"],\"text\":\"\"},\"\\n\",{\"bold\":true,\"extra\":[\"\\n\"],\"text\":\"Ping\"},{\"extra\":[\"0ms\"],\"text\":\"\"},\"\\n\",{\"bold\":true,\"extra\":[\"\\n\"],\"text\":\"Proxy IP\"},{\"extra\":[\"localhost\"],\"text\":\"\"},\"\\n\",{\"bold\":true,\"extra\":[\"\\n\"],\"text\":\"Server\"},{\"extra\":[\"connect.2b2t.org:25565\"],\"text\":\"\"},\"\\n\",{\"bold\":true,\"extra\":[\"\\n\"],\"text\":\"Priority Queue\"},{\"extra\":[\"no [unbanned]\"],\"text\":\"\"},\"\\n\",{\"bold\":true,\"extra\":[\"\\n\"],\"text\":\"Spectators\"},{\"extra\":[\"on\"],\"text\":\"\"},\"\\n\",{\"bold\":true,\"extra\":[\"\\n\"],\"text\":\"2b2t Queue\"},{\"extra\":[\"Priority: 15 [00:25:49]\\nRegular: 688 [07:49:27]\"],\"text\":\"\"},\"\\n\",{\"bold\":true,\"extra\":[\"\\n\"],\"text\":\"Coordinates\"},{\"extra\":[\"||[0, 0, 0]||\"],\"text\":\"\"},\"\\n\",{\"bold\":true,\"extra\":[\"\\n\"],\"text\":\"AutoUpdate\"},{\"extra\":[\"on\"],\"text\":\"\"}],\"text\":\"\"}", |
| 39 | + "multiLineOutput": [] |
| 40 | +} |
| 41 | +``` |
30 | 42 |
|
31 | | -This method provides a `PluginAPI` object that you can use to register modules, commands, and config files. |
| 43 | +The `embedComponent` can be parsed back from json with [Kyori Adventure](https://docs.advntr.dev/getting-started.html) |
| 44 | +```java |
| 45 | +Component c = GsonComponentSerializer.gson().deserialize(embedComponent); |
| 46 | +``` |
32 | 47 |
|
33 | | -`Module` and `Command` classes are implemented the same as in the ZenithProxy source code. |
| 48 | +### Example |
34 | 49 |
|
35 | | -I recommend looking at existing modules and commands for examples. |
| 50 | +```bash |
| 51 | +curl --location 'http://localhost:8080/command' \ |
| 52 | +--header 'Authorization: c05598ed-d123-4e8f-9aa7-40c11e657f23' \ |
| 53 | +--header 'Content-Type: application/json' \ |
| 54 | +--data '{"command":"status"}' |
| 55 | +``` |
36 | 56 |
|
37 | | -* [Module](https://github.com/rfresh2/ZenithProxy/tree/1.21.0/src/main/java/com/zenith/module) |
38 | | -* [Command](https://github.com/rfresh2/ZenithProxy/tree/1.21.0/src/main/java/com/zenith/command) |
| 57 | +# FAQ |
39 | 58 |
|
40 | | -### Building Plugins |
| 59 | +## How do I call the API from the public internet? |
41 | 60 |
|
42 | | -Execute the Gradle `build` task: `./gradlew build` - or double-click the task in Intellij |
| 61 | +Depends on where and how you are hosting the ZenithProxy instance. |
43 | 62 |
|
44 | | -The built plugin jar will be in the `build/libs` directory. |
| 63 | +It's the same as accessing the ZenithProxy MC server from the public internet. |
45 | 64 |
|
46 | | -### Testing Plugins |
| 65 | +So if you had to change firewall settings, port forwarding, or set up tunneling you'd do the same for the web API's port. |
47 | 66 |
|
48 | | -Execute the `run` task: `./gradlew run` - or double-click the task in Intellij |
| 67 | +## I'm running multiple ZenithProxy instance on the same server, can they all have web APIs? |
49 | 68 |
|
50 | | -This will run ZenithProxy with your plugin loaded in the `run` directory. |
51 | | - |
52 | | -### New Plugin Checklist |
53 | | - |
54 | | -1. Edit `gradle.properties`: |
55 | | - - `plugin_name` - Name of your plugin, used in the plugin jar name (e.g. `ExamplePlugin`) |
56 | | - - `maven_group` - Java package for your project (e.g. `com.github.rfresh2`) |
57 | | -1. Move files to your new corresponding package / maven group: |
58 | | - - Example: `src/main/java/org/example` -> `src/main/java/com/github/rfresh2` |
59 | | - - First create the new package in `src/main/java`. Then click and drag original subpackages/classes to your new one |
60 | | - - Do this with Intellij to avoid manually editing all the source files |
61 | | - - You must also move folders/package for the `src/main/templates` folder |
62 | | - - Also make sure to update the package import at the very top of `BuiltConstants.java`, it will not be done automatically |
63 | | -1. Edit `ExamplePlugin.java`, or remove it and create a new main class |
64 | | - - Make sure to update the `@Plugin` annotation |
| 69 | +Yes, but each needs to be configured to use a different port: `webApi port <port>` |
0 commit comments