From 7d4baa93cf1e0b5ef6f2ad591da41b1b34df384f Mon Sep 17 00:00:00 2001 From: q13x <84165981+WorldEditAxe@users.noreply.github.com> Date: Wed, 5 Jul 2023 10:23:54 -0700 Subject: [PATCH] add example plugins --- example_plugins/AutokickPlugin/config.ts | 4 ++ example_plugins/AutokickPlugin/index.ts | 64 +++++++++++++++++++ example_plugins/AutokickPlugin/metadata.json | 14 ++++ example_plugins/AutokickPlugin/types.d.ts | 5 ++ .../ExamplePlugin/index.js | 0 .../ExamplePlugin}/metadata.json | 0 tsconfig.json | 4 +- 7 files changed, 89 insertions(+), 2 deletions(-) create mode 100644 example_plugins/AutokickPlugin/config.ts create mode 100644 example_plugins/AutokickPlugin/index.ts create mode 100644 example_plugins/AutokickPlugin/metadata.json create mode 100644 example_plugins/AutokickPlugin/types.d.ts rename example_plugin/index.ts => example_plugins/ExamplePlugin/index.js (100%) rename {example_plugin => example_plugins/ExamplePlugin}/metadata.json (100%) diff --git a/example_plugins/AutokickPlugin/config.ts b/example_plugins/AutokickPlugin/config.ts new file mode 100644 index 0000000..47bb07d --- /dev/null +++ b/example_plugins/AutokickPlugin/config.ts @@ -0,0 +1,4 @@ +export const config = { + bindInternalServerPort: 25569, + bindInternalServerIp: "127.0.0.1", +}; diff --git a/example_plugins/AutokickPlugin/index.ts b/example_plugins/AutokickPlugin/index.ts new file mode 100644 index 0000000..e6cca7a --- /dev/null +++ b/example_plugins/AutokickPlugin/index.ts @@ -0,0 +1,64 @@ +import metadata from "./metadata.json" assert { type: "json" }; +import { createServer } from "minecraft-protocol"; +import { config } from "./config.js"; + +const PluginManager = PLUGIN_MANAGER as any; + +const Logger = PluginManager.Logger; +const Enums = PluginManager.Enums; +const Chat = PluginManager.Chat; +const Constants = PluginManager.Constants; +const Motd = PluginManager.Motd; +const Player = PluginManager.Player; +const MineProtocol = PluginManager.MineProtocol; +const EaglerSkins = PluginManager.EaglerSkins; +const Util = PluginManager.Util; + +const logger = new Logger("EaglerProxyAAS"); +logger.info(`Starting ${metadata.name} v${metadata.version}...`); +logger.info( + `(internal server port: ${config.bindInternalServerPort}, internal server IP: ${config.bindInternalServerPort})` +); + +logger.info("Starting internal server..."); +let server = createServer({ + host: config.bindInternalServerIp, + port: config.bindInternalServerPort, + motdMsg: `${Enums.ChatColor.GOLD}EaglerProxy as a Service`, + "online-mode": false, + version: "1.8.9", +}); + +server.on("login", (client) => { + logger.info( + `Client ${client.username} has connected to the authentication server.` + ); + client.on("end", () => { + logger.info( + `Client ${client.username} has disconnected from the authentication server.` + ); + }); + client.write("kick_disconnect", { + reason: + Enums.ChatColor.GREEN + + "Hi there!\n" + + Enums.ChatColor.GOLD + + "This server will be down for a while as I migrate the server from existing hardware to new, faster hardware.\nThis process will take approximately " + + Enums.ChatColor.RED + + "3-5 days" + + Enums.ChatColor.GOLD + + " to complete. Until then, you will be unable to connect or access the server.\n" + + "Thank you for your understanding! :)", + }); +}); + +logger.info( + "Redirecting backend server IP... (this is required for the plugin to function)" +); +CONFIG.adapter.server = { + host: config.bindInternalServerIp, + port: config.bindInternalServerPort, +}; +CONFIG.adapter.motd = { + l1: Enums.ChatColor.RED + "Server Under Maintenance", +}; diff --git a/example_plugins/AutokickPlugin/metadata.json b/example_plugins/AutokickPlugin/metadata.json new file mode 100644 index 0000000..62e992e --- /dev/null +++ b/example_plugins/AutokickPlugin/metadata.json @@ -0,0 +1,14 @@ +{ + "name": "AutoKick", + "id": "autokick", + "version": "1.2.0", + "entry_point": "index.js", + "load_after": [], + "requirements": [], + "incompatibilities": [ + { + "id": "eagpaas", + "version": "^0.0.0" + } + ] +} diff --git a/example_plugins/AutokickPlugin/types.d.ts b/example_plugins/AutokickPlugin/types.d.ts new file mode 100644 index 0000000..fa9b794 --- /dev/null +++ b/example_plugins/AutokickPlugin/types.d.ts @@ -0,0 +1,5 @@ +declare global { + var PLUGIN_MANAGER; +} + +export {}; diff --git a/example_plugin/index.ts b/example_plugins/ExamplePlugin/index.js similarity index 100% rename from example_plugin/index.ts rename to example_plugins/ExamplePlugin/index.js diff --git a/example_plugin/metadata.json b/example_plugins/ExamplePlugin/metadata.json similarity index 100% rename from example_plugin/metadata.json rename to example_plugins/ExamplePlugin/metadata.json diff --git a/tsconfig.json b/tsconfig.json index 8973c8c..3fdff2f 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -2,12 +2,12 @@ "compilerOptions": { "module": "esnext", "esModuleInterop": true, - "target": "es2017", + "target": "ESNext", "moduleResolution": "node", "sourceMap": false, "outDir": "build", "resolveJsonModule": true }, - "include": ["src/**/*.json", "src/**/*"], + "include": ["src/**/*.json", "src/**/*", "example_plugins/AutokickPlugin"], "hooks": ["copy-files"] }