IW4M-Admin/Plugins/ScriptPlugins/BanBroadcasting.js

61 lines
2.2 KiB
JavaScript
Raw Normal View History

2023-04-04 19:24:13 -04:00
const init = (registerNotify, serviceResolver, config) => {
registerNotify('IManagementEventSubscriptions.ClientPenaltyAdministered', (penaltyEvent, _) => plugin.onClientPenalty(penaltyEvent));
plugin.onLoad(serviceResolver, config);
return plugin;
};
const plugin = {
2023-04-04 19:24:13 -04:00
author: 'Amos, RaidMax',
version: '2.0',
name: 'Broadcast Bans',
2023-04-04 19:24:13 -04:00
config: null,
logger: null,
translations: null,
manager: null,
2023-04-04 19:24:13 -04:00
onClientPenalty: function (penaltyEvent) {
if (!this.enableBroadcastBans) {
return;
}
2023-04-04 19:24:13 -04:00
let automatedPenaltyMessage;
penaltyEvent.penalty.punisher.administeredPenalties?.forEach(penalty => {
automatedPenaltyMessage = penalty.automatedOffense;
});
if (penaltyEvent.penalty.punisher.clientId === 1 && automatedPenaltyMessage !== undefined) {
let message = this.translations['PLUGINS_BROADCAST_BAN_ACMESSAGE'].replace('{{targetClient}}', penaltyEvent.client.cleanedName);
this.broadcastMessage(message);
} else {
let message = this.translations['PLUGINS_BROADCAST_BAN_MESSAGE'].replace('{{targetClient}}', penaltyEvent.client.cleanedName);
this.broadcastMessage(message);
}
},
2023-04-04 19:24:13 -04:00
broadcastMessage: function (message) {
this.manager.getServers().forEach(server => {
server.broadcast(message);
});
},
onLoad: function (serviceResolver, config) {
this.config = config;
this.config.setName(this.name);
this.enableBroadcastBans = this.config.getValue('EnableBroadcastBans');
this.manager = serviceResolver.resolveService('IManager');
this.logger = serviceResolver.resolveService('ILogger', ['ScriptPluginV2']);
this.translations = serviceResolver.resolveService('ITranslationLookup');
if (this.enableBroadcastBans === undefined) {
this.enableBroadcastBans = false;
2023-04-04 19:24:13 -04:00
this.config.setValue('EnableBroadcastBans', this.enableBroadcastBans);
}
2023-04-04 19:24:13 -04:00
this.logger.logInformation('{Name} {Version} by {Author} loaded. Enabled={enabled}', this.name, this.version,
this.author, this.enableBroadcastBans);
}
};