{"id":15281421,"url":"https://github.com/timluq/node-spigot-bridge","last_synced_at":"2025-04-12T19:22:16.749Z","repository":{"id":57367460,"uuid":"133039310","full_name":"TimLuq/node-spigot-bridge","owner":"TimLuq","description":"Allows writing (primarily async) plugins for Minecraft servers using TypeScript or JavaScript to be run in a node context.","archived":false,"fork":false,"pushed_at":"2018-07-11T14:52:14.000Z","size":97,"stargazers_count":8,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-10T07:57:41.269Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/TimLuq.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-05-11T12:51:45.000Z","updated_at":"2023-06-25T00:58:35.000Z","dependencies_parsed_at":"2022-08-23T19:30:40.532Z","dependency_job_id":null,"html_url":"https://github.com/TimLuq/node-spigot-bridge","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TimLuq%2Fnode-spigot-bridge","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TimLuq%2Fnode-spigot-bridge/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TimLuq%2Fnode-spigot-bridge/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TimLuq%2Fnode-spigot-bridge/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TimLuq","download_url":"https://codeload.github.com/TimLuq/node-spigot-bridge/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248618832,"owners_count":21134305,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-09-30T13:07:43.588Z","updated_at":"2025-04-12T19:22:16.700Z","avatar_url":"https://github.com/TimLuq.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# node-spigot-bridge\n\nA minecraft server plugin to enable other plugins to be written in TypeScript or JavaScript.\n(Or any other language where a transpiler or compiler can be made to build a Node.js module.)\n\n## Dependencies\n\nThe system running the plugin must have *Java 9* or greater running the Minecraft server, as well as *[Node.js 10](https://nodejs.org/)* or later installed.\n\n## Installing\n\nGet a hold of the JAR file and place it in the plugins folder. After the first run a couple of directories and files will be created if they did not exist before, these are\n- `plugins/NodeSpigotBridge/`\n  - `config.yml` - *see [configuration](#configuration)*\n  - `NodeBridge.js` - *overwritten with latest every startup*\n- `node-plugins/`\n  - `package.json` - *see [plugin package](#plugin-package)*\n\nThe JAR file may be released as a, well, \"[release](https://github.com/TimLuq/node-spigot-bridge/releases)\" at the GitHub repository or could be built from source using the following toolchains:\n - [TypeScript](https://www.typescriptlang.org/) - *a transpiler and ecosystem providing strong typing to JavaScript*\n - [rollup.js](https://rollupjs.org) - *a bundler for web or javascript projects*\n - [Gradle](https://gradle.org/) - *a tool for primarily java development and building*\n\n### Building\n\nPrepare by downloading the source:\n```sh\n\u003e git clone https://github.com/TimLuq/node-spigot-bridge.git\n```\n\nThen place `spigot-api-shaded.jar` into the `node-spigot-bridge/libs` directory.\n```sh\n\u003e cp Spigot/Spigot-API/target/spigot-api*-shaded.jar node-spigot-bridge/libs/spigot-api-shaded.jar\n```\n\nTo build run `gradle build` from the project directory as displayed here:\n```sh\n\u003e cd \"node-spigot-bridge\"\n\u003e gradle build; gradle build\n```\n\nThis will create a JAR file at `node-spigot-bridge/build/libs/node-spigot-bridge-*.jar` where the asterisk is the version of `node-spigot-bridge`.\n\n## Configuration\n\nThe file `plugins/NodeSpigotBridge/config.yml` contains only a few configurable options:\n- `directory: node-plugins`\n  *# which directory to use for finding packages (see [plugin package](#plugin-package)), relative to working directory of server*\n- `executable: node`\n  *# which executable should act as the Node.js process, may be an absolute path*\n\n## Plugin package\n\nThe `package.json` file used is located at `node-plugins/package.json` if not configured to be another path.\nThis file conatins information about which plugins are installed and which should be loaded.\n\nYou may manually change dependencies in this file but I would recommand a package manager, such as `yarn`.\n\nAdditionally, when neccessary, this file may contain one of the two optional fields `spigotmc` or `main` to describe which module should handle plugin loading if the default behavior is lacking in flexibility.\n\n### Package management\n\nA great way to install and manage plugins is using a package manager. Among the most common are `yarn` and `npm`.\nBoth of these use `npm-registry` to resolve packages and versions by default. It is open for anyone to publish their public packages to `npm-registry` without charge.\n\nThe recommended package manager is [`yarn`](https://yarnpkg.com), due to its ability to handle flat dependency graphs.\n\n#### Flat depenency graphs\n\nThe default `package.json` sets the option `flat: true` to signal use of a flat dependency graph to package managers supporting this feature.\n\nA flat dependency graph forces all plugins to use the same version of common libraries; lowering RAM usage and giving a slight improvement to performance.\nThe drawback is that this is hard to solve if not impossible when two plugins, one being activly maintained while the other has stagnated, depend on incompatible versions of the same library.\n\nUnless such a dependency conflict is noticed, the recommendation is to use flat dependencies.\n\n## Plugin development\n\nA plugin is a `Node.js` module exporting a subclass of `Plugin` from `spigot-bridge` as `default`.\n\n### Plugin example\n\n```javascript\nimport { Plugin, Player } from \"spigot-bridge\";\n\nexport default class SpamBotPlugin extends Plugin {\n    constructor() {\n        // if name or version are undefined or the empty string\n        // info will be loaded from package.json\n        this.name = \"@timluq/spigot-spambot\";\n        this.version = \"0.0.1\";\n\n        // initialize plugin variables\n        this.variance = 32000; // 32s\n        this.silence = 16000; // 16s\n        this.target = \"069a79f4-44e9-4726-a5be-fca90e38aaf5\";\n\n        // bind to `this` to be able to use `this` in method callbacks\n        this.spam = this.spam.bind(this);\n        this.spamtarget = this.spamtarget.bind(this);\n    }\n    start() {\n        this.registerCommand(\"spamtarget\", this.spamtarget, {\n            description: \"Changes which player to spam\",\n            permission: \"spam.target\",\n            usage: \"\u003ccommand\u003e \u003cUUID\u003e\"\n        });\n        this.timeout = setTimeout(this.spam, this.silence);\n    }\n    stop() {\n        clearTimeout(this.timeout);\n    }\n    spam() {\n        Player.get(this.target).sendMessage(\"This is spam!!!1!\");\n        const wait = this.silence + Math.random() * this.variance;\n        this.timeout = setTimeout(this.spam, wait);\n    }\n    spamtarget(sender, alias, arg1) {\n        if (sender.player) {\n            if (!arg1 || arg1 === \"self\" || arg1 === \"me\") {\n                arg1 = sender.player;\n            }\n            Player.get(sender.player).sendMessage(\"Changed spamtarget to: \" + arg1);\n        }\n        this.target = arg1;\n    }\n}\n```\n\n### Plugin package\n\nWhich module is loaded is decided by the `spigotmc` field, or `main` if that field is missing.\nThis gives you the possibility to expose parts of your plugin as a library for other plugins to use.\nThe module referenced must be the one to export a subclass of `Plugin` from `spigot-bridge` as `default`.\n\n`spigot-bridge` must be part of the devDependencies.\n\n```json\n{\n    \"name\": \"@timluq/my-spigot-plugin\",\n    \"version\": \"1.0.0\",\n    \"spigotmc\": \"dist/plugin.js\",\n    \"types\": \"typings/index.d.ts\",\n    \"main\": \"dist/library.js\",\n    \"dependencies\": {\n        \"@timluq/some-lib\": \"^1.2.3\"\n    },\n    \"devDependencies\": {\n        \"@types/node\": \"^10.0.0\",\n        \"spigot-bridge\": \"^0.1.0\"\n    }\n}\n```\n\n### Plugin distribution\n\nRecommended practice is publishing your plugin to [`npm-registry`](https://www.npmjs.com). This will allow standard package managers to be used.\n\nYou may additionally publish your work in any way you would like to give people the oppurtunity to use your plugin.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftimluq%2Fnode-spigot-bridge","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftimluq%2Fnode-spigot-bridge","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftimluq%2Fnode-spigot-bridge/lists"}