feat: rework commands and fix bugs

This commit is contained in:
ForestOfLight
2026-05-20 17:08:03 -07:00
Unverified
parent b1370b5d28
commit 7ea64d1e6a
38 changed files with 527 additions and 525 deletions
+12 -3
View File
@@ -1,4 +1,4 @@
import { CustomCommandSource, CustomCommandStatus, Player, system } from "@minecraft/server";
import { CustomCommandParamType, CustomCommandSource, CustomCommandStatus, Player, RawMessageError, system } from "@minecraft/server";
import { Commands } from "./Commands.js";
import { BlockCommandOrigin } from "./BlockCommandOrigin";
import { EntityCommandOrigin } from "./EntityCommandOrigin";
@@ -60,8 +60,15 @@ export class Command {
this.callback = (origin, ...args) => {
const source = Command.resolveCommandOrigin(origin);
if (this.#commandSourceIsNotAllowed(source))
return { status: CustomCommandStatus.Failure, message: 'commands.generic.invalidsource' };
return this.customCommand.callback(source, ...args);
return { status: CustomCommandStatus.Failure, message: 'construct.error.invalidCommandSource' };
try {
return this.customCommand.callback(source, ...args);
} catch (error) {
if (error instanceof RawMessageError)
error.sendTo(source);
else
throw error;
}
}
}
@@ -88,6 +95,8 @@ export class Command {
return [];
for (const parameter of parameters) {
if (parameter.name)
parameter.name = `${parameter.name}`;
if (parameter.type === CustomCommandParamType.Enum)
parameter.name = `${PACK_IDENTIFIER}:${parameter.name}`;
}
return parameters;
@@ -1,9 +0,0 @@
import { CustomCommandStatus } from '@minecraft/server';
import { NotAPlayerError } from '../../Errors/NotAPlayerError';
export function commandError(source, err) {
if (err instanceof NotAPlayerError) {
return { status: CustomCommandStatus.Failure, message: 'construct.commands.error.notAPlayer' };
}
throw err;
}
@@ -1,12 +0,0 @@
import { system } from '@minecraft/server';
import { structureCollection } from '../../Structure/StructureCollection';
export function findInstance(source, name) {
if (!structureCollection.has(name)) {
system.run(() => source.sendMessage({
rawtext: [{ translate: 'construct.commands.error.instanceNotFound', with: [name] }]
}));
return null;
}
return structureCollection.get(name);
}
@@ -1,8 +0,0 @@
import { PlayerCommandOrigin } from '../PlayerCommandOrigin';
import { NotAPlayerError } from '../../Errors/NotAPlayerError';
export function requirePlayer(source) {
if (!(source instanceof PlayerCommandOrigin))
throw new NotAPlayerError();
return source.getSource();
}