Files
Construct/packs/BP/scripts/commands/PlaceCommand.js
T
ForestOfLight b1370b5d28 chore(cli): drop unused imports and orphan lang key
- Remove unused `world` import from ListCommand.js and PlaceCommand.js
  (plan code blocks included it but neither command uses it).
- Delete orphaned `construct.commands.construct.denyorigin` lang key
  from en_US and zh_CN — its sole consumer was the original
  commands/construct.js, which was replaced by ConstructCommand using
  the shared `construct.commands.error.notAPlayer` key.
- Carry the previously-orphaned Chinese translation forward to the
  notAPlayer key in zh_CN.lang.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-20 03:26:58 -07:00

51 lines
2.1 KiB
JavaScript

import { CustomCommandParamType, CustomCommandStatus, system } from '@minecraft/server';
import { Command } from '../classes/Commands/Command';
import { findInstance } from '../classes/Commands/lib/findInstance';
import { commandError } from '../classes/Commands/lib/commandError';
import { PlayerCommandOrigin } from '../classes/Commands/PlayerCommandOrigin';
import { BlockCommandOrigin } from '../classes/Commands/BlockCommandOrigin';
import { EntityCommandOrigin } from '../classes/Commands/EntityCommandOrigin';
export class PlaceCommand extends Command {
constructor() {
super({
name: 'place',
description: 'construct.commands.place',
mandatoryParameters: [
{ name: 'instanceName', type: CustomCommandParamType.String },
{ name: 'pos', type: CustomCommandParamType.Location }
],
callback: (source, instanceName, pos) => this.run(source, instanceName, pos)
});
}
run(source, instanceName, pos) {
try {
const instance = findInstance(source, instanceName);
if (!instance) return { status: CustomCommandStatus.Failure };
const dimensionId = this.resolveDimensionId(source);
system.run(() => {
instance.place(dimensionId, pos);
source.sendMessage({
rawtext: [{ translate: 'construct.commands.place.success',
with: [instanceName, String(pos.x), String(pos.y), String(pos.z),
dimensionId.replace('minecraft:', '')] }]
});
});
return { status: CustomCommandStatus.Success };
} catch (err) {
return commandError(source, err);
}
}
resolveDimensionId(source) {
if (source instanceof PlayerCommandOrigin || source instanceof EntityCommandOrigin)
return source.getSource().dimension.id;
if (source instanceof BlockCommandOrigin)
return source.getSource().dimension.id;
return 'minecraft:overworld';
}
}
export const placeCommand = new PlaceCommand();