Skip to content

Commit e8b29a5

Browse files
committed
Updated addon for 1.20
1 parent d3496f6 commit e8b29a5

File tree

4 files changed

+353
-287
lines changed

4 files changed

+353
-287
lines changed

VoiceCraft BP/manifest.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,15 @@
5353
"dependencies": [
5454
{
5555
"module_name": "@minecraft/server",
56-
"version": "1.2.0-beta"
56+
"version": "1.3.0-beta"
5757
},
5858
{
5959
"module_name": "@minecraft/server-net",
6060
"version": "1.0.0-beta"
6161
},
6262
{
6363
"module_name": "@minecraft/server-ui",
64-
"version": "1.0.0-beta"
64+
"version": "1.1.0-beta"
6565
}
6666
]
6767
}
Lines changed: 73 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,88 @@
1-
import { world } from '@minecraft/server';
1+
import { world, system } from "@minecraft/server";
22

33
class CommandSystem {
4-
static Prefix = "!";
5-
static Commands = {};
4+
static Prefix = "!";
5+
static Commands = {};
66

7-
static RegisterCommand(name, callback, paramTypes, opOnly = false) {
8-
this.Commands[name] = {
9-
callback: callback,
10-
paramTypes: paramTypes,
11-
opOnly: opOnly
12-
};
13-
}
14-
15-
static executeCommand(input, source, event) {
16-
if (input.startsWith(CommandSystem.Prefix)) {
17-
event.cancel = true;
18-
const text = input.replace(this.Prefix, "");
19-
const parts = text.split(" ");
20-
const commandName = parts[0];
21-
const args = parts.slice(1);
7+
static RegisterCommand(name, callback, paramTypes, opOnly = false) {
8+
this.Commands[name] = {
9+
callback: callback,
10+
paramTypes: paramTypes,
11+
opOnly: opOnly,
12+
};
13+
}
2214

23-
if (this.Commands[commandName]) {
24-
const command = this.Commands[commandName];
25-
if (command.opOnly && !source.isOp()) {
26-
source.sendMessage("§cThis command can only be used by operators!");
27-
return;
28-
}
29-
const typedArgs = {};
15+
static executeCommand(input, source, event) {
16+
if (input.startsWith(CommandSystem.Prefix)) {
17+
event.cancel = true;
18+
system.run(() => {
19+
const text = input.replace(this.Prefix, "");
20+
const parts = text.split(" ");
21+
const commandName = parts[0];
22+
const args = parts.slice(1);
3023

31-
typedArgs["source"] = source;
24+
if (this.Commands[commandName]) {
25+
const command = this.Commands[commandName];
26+
if (command.opOnly && !source.isOp()) {
27+
source.sendMessage("§cThis command can only be used by operators!");
28+
return;
29+
}
30+
const typedArgs = {};
3231

33-
let i = 0;
34-
for (const [paramName, type] of Object.entries(command.paramTypes)) {
35-
let value = args[i];
32+
typedArgs["source"] = source;
3633

37-
switch (type) {
38-
case "string":
39-
if (value == undefined) {
40-
source.sendMessage(`§cInvalid Paramater Input: §e[${paramName}]§r. Received §e[${value}]§r, Expected §e[${type}]§r`);
41-
return;
42-
}
43-
break;
44-
case "integer": value = parseInt(value);
45-
if (isNaN(value)) {
46-
source.sendMessage(`§cInvalid Paramater Input: §e[${paramName}]§r. Received §e[${value}]§r, Expected §e[${type}]§r`);
47-
return;
48-
}
49-
break;
50-
case "float": value = parseFloat(value);
51-
if (isNaN(value)) {
52-
source.sendMessage(`§cInvalid Paramater Input: §e[${paramName}]§r. Received §e[${value}]§r, Expected §e[${type}]§r`);
53-
return;
54-
}
55-
break;
56-
default: source.sendMessage(`§cInvalid parameter type: ${type} for param ${paramName}`);
57-
return;
58-
}
34+
let i = 0;
35+
for (const [paramName, type] of Object.entries(command.paramTypes)) {
36+
let value = args[i];
5937

60-
typedArgs[paramName] = value;
61-
i++;
38+
switch (type) {
39+
case "string":
40+
if (value == undefined) {
41+
source.sendMessage(
42+
`§cInvalid Paramater Input: §e[${paramName}]§r. Received §e[${value}]§r, Expected §e[${type}]§r`
43+
);
44+
return;
6245
}
63-
command.callback.call(null, typedArgs);
64-
} else {
65-
source.sendMessage(`§cUnkown command: ${commandName}`);
46+
break;
47+
case "integer":
48+
value = parseInt(value);
49+
if (isNaN(value)) {
50+
source.sendMessage(
51+
`§cInvalid Paramater Input: §e[${paramName}]§r. Received §e[${value}]§r, Expected §e[${type}]§r`
52+
);
53+
return;
54+
}
55+
break;
56+
case "float":
57+
value = parseFloat(value);
58+
if (isNaN(value)) {
59+
source.sendMessage(
60+
`§cInvalid Paramater Input: §e[${paramName}]§r. Received §e[${value}]§r, Expected §e[${type}]§r`
61+
);
62+
return;
63+
}
64+
break;
65+
default:
66+
source.sendMessage(
67+
`§cInvalid parameter type: ${type} for param ${paramName}`
68+
);
69+
return;
6670
}
71+
72+
typedArgs[paramName] = value;
73+
i++;
74+
}
75+
command.callback.call(null, typedArgs);
76+
} else {
77+
source.sendMessage(`§cUnkown command: ${commandName}`);
6778
}
79+
});
6880
}
81+
}
6982
}
7083

71-
world.events.beforeChat.subscribe(ev => {
72-
CommandSystem.executeCommand(ev.message, ev.sender, ev);
73-
})
84+
world.beforeEvents.chatSend.subscribe((ev) => {
85+
CommandSystem.executeCommand(ev.message, ev.sender, ev);
86+
});
7487

75-
export { CommandSystem }
88+
export { CommandSystem };

0 commit comments

Comments
 (0)