Version 8 has again seen a large section of the nrelay codebase receive huge changes. However, the plugin API has remained relatively the same from version 7 to version 8.
This document is not an exhaustive list of every single breaking change, but is intended to be a guide which will help plugin developers convert plugins to the new version 8 style.
- The CLI
- Migrating plugins to the CLI style
- Changes to imports
- Changes to the CLI class
- Changes to the client event emitter
- Changes to static classes
The largest change from version 7 to version 8 is the creation of the nrelay command line interface. Previously, the entire nrelay codebase had to be cloned in order to run plugins, but the CLI provides a clean way of avoiding this issue.
To install the CLI, run the command
npm install -g nrelay-cli
This will globally install the CLI and make the nrelay
command available.
To migrate the plugins, first create a new nrelay project
nrelay new my-project-name
When this has completed, copy all of the plugins you want to migrate into the src/
directory of the newly generated project.
Since nrelay is now an npm module which is installed in all nrelay projects, the location of all imports has changed to simply be from 'nrelay'
.
Change
import { Library, PacketHook, Client } from './../core';
class HelloPlugin {
}
to
import { Library, PacketHook, Client } from 'nrelay';
class HelloPlugin {
}
The CLI class has been removed. The functionality which it provided is now provided by the Runtime class.
Change
class ExamplePlugin {
constructor() {
const clients = CLI.getClients();
Logger.log('Plugin', `There are ${clients.length} clients connected`);
}
}
to
class ExamplePlugin {
constructor(runtime: Runtime) {
const clients = runtime.getClients();
Logger.log('Plugin', `There are ${clients.length} clients connected`);
}
}
The static client event emitter has been replaced by an event emitter on the Runtime class. The event names have also been moved into an enum to provide stronger typing.
Change
import { Client } from './../core';
class ExamplePlugin {
constructor() {
Client.on('ready', (client) => {
Logger.log('Plugin', `${client.alias} is ready!`);
});
}
}
to
import { Client, Events, Runtime } from 'nrelay';
class ExamplePlugin {
constructor(runtime: Runtime) {
runtime.on(Events.ClientReady, (client: Client) => {
Logger.log('Plugin', `${client.alias} is ready!`);
});
}
}
The majority of the static classes, with the exception of the Logger
class, have been changed to be instance based. Instances of these previously static classes are available in the Runtime.
Change
class ExamplePlugin {
constructor() {
const itemCount = Object.keys(ResourceManager.items).length;
Logger.log('Plugin', `There are ${itemCount} items`);
}
}
to
class ExamplePlugin {
constructor(runtime: Runtime) {
const itemCount = Object.keys(runtime.resources.items).length;
Logger.log('Plugin', `There are ${itemCount} items`);
}
}
Other classes which are affected include:
AccountService
.LibraryManager
.Updater
.