Skip to content

Commit dfc66ae

Browse files
Update index.js
1 parent b104893 commit dfc66ae

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

scripts/command-builder/index.js

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class commandBuilder {
7575
aliases: info.aliases || [],
7676
examples: info.examples || [],
7777
for_staff: info.for_staff || false,
78-
callback: callback || (() => { /* console.warn(`Command ${info.name} is missing it's callback function!`); */ serverBuild.msgDevs(`Command ${info.name} is missing it's callback function!`) }),
78+
callback: callback || (() => { console.warn(`Command ${info.name} is missing it's callback function!`); }),
7979
callbackWM: callbackWM || (() => { })
8080
}
8181
);
@@ -101,13 +101,6 @@ class commandBuilder {
101101
* @param {String} cmdName - Name of the command
102102
*/
103103
getCommand(cmdName) {
104-
if (!cmdName) {
105-
// console.warn('getCommand() parameter cmdName was not parsed');
106-
serverBuild.msgDevs('getCommand() parameter cmdName was not parsed');
107-
108-
return;
109-
};
110-
111104
const cmds = this.commands.find((cmd) => (cmd.name === cmdName || cmd.aliases.some((aliase) => cmdName === aliase)));
112105

113106
return cmds;
@@ -132,4 +125,24 @@ class commandBuilder {
132125
(data, args) => { }
133126
);
134127
*/
128+
135129
export const commandBuild = new commandBuilder();
130+
131+
world.beforeEvents.chatSend.subscribe((data) => {
132+
if (!data.message.startsWith('!') || data.message === '!') return; data.cancel = true;
133+
134+
const args = data.message.slice('!'.length).trim().split(new RegExp(/\s+/g));
135+
const sender = data.sender;
136+
const cmd = args.shift();
137+
const command = commandBuild.getCommand(cmd);
138+
139+
if (!command)
140+
return sender.sendMessage(`§cThe command §f${cmd}§c was not found`);
141+
142+
if (command.for_staff === true && sender.hasTag('someTag') === false)
143+
return sender.sendMessage(`§cThe command §f${cmd}§c is for staff only`);
144+
145+
system.run(() => {
146+
command.callback(data, args);
147+
});
148+
});

0 commit comments

Comments
 (0)