mirror of
https://github.com/AsgardEternal/SquadJS.git
synced 2024-09-28 16:24:25 -05:00
52 lines
1.4 KiB
JavaScript
52 lines
1.4 KiB
JavaScript
import Logger from 'core/logger';
|
|
|
|
export default class BasePlugin {
|
|
constructor(server, options, connectors) {
|
|
this.server = server;
|
|
this.options = {};
|
|
this.rawOptions = options;
|
|
|
|
for (const [optionName, option] of Object.entries(this.constructor.optionsSpecification)) {
|
|
if (option.connector) {
|
|
this.options[optionName] = connectors[this.rawOptions[optionName]];
|
|
} else {
|
|
if (option.required) {
|
|
if (!(optionName in this.rawOptions))
|
|
throw new Error(`${this.constructor.name}: ${optionName} is required but missing.`);
|
|
if (option.default === this.rawOptions[optionName])
|
|
throw new Error(
|
|
`${this.constructor.name}: ${optionName} is required but is the default value.`
|
|
);
|
|
}
|
|
|
|
this.options[optionName] =
|
|
typeof this.rawOptions[optionName] !== 'undefined'
|
|
? this.rawOptions[optionName]
|
|
: option.default;
|
|
}
|
|
}
|
|
}
|
|
|
|
async prepareToMount() {}
|
|
|
|
async mount() {}
|
|
|
|
async unmount() {}
|
|
|
|
static get description() {
|
|
throw new Error('Plugin missing "static get description()" method.');
|
|
}
|
|
|
|
static get defaultEnabled() {
|
|
throw new Error('Plugin missing "static get defaultEnabled()" method.');
|
|
}
|
|
|
|
static get optionsSpecification() {
|
|
throw new Error('Plugin missing "static get optionSpecification()" method.');
|
|
}
|
|
|
|
verbose(...args) {
|
|
Logger.verbose(this.constructor.name, ...args);
|
|
}
|
|
}
|