feat(cli): add command helpers and NotAPlayerError
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
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;
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
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);
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
import { PlayerCommandOrigin } from '../PlayerCommandOrigin';
|
||||
import { NotAPlayerError } from '../../Errors/NotAPlayerError';
|
||||
|
||||
export function requirePlayer(source) {
|
||||
if (!(source instanceof PlayerCommandOrigin))
|
||||
throw new NotAPlayerError();
|
||||
return source.getSource();
|
||||
}
|
||||
Reference in New Issue
Block a user