feat(cli): add construct:move command
This commit is contained in:
@@ -0,0 +1,62 @@
|
|||||||
|
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 MoveCommand extends Command {
|
||||||
|
constructor() {
|
||||||
|
super({
|
||||||
|
name: 'move',
|
||||||
|
description: 'construct.commands.move',
|
||||||
|
mandatoryParameters: [
|
||||||
|
{ name: 'instanceName', type: CustomCommandParamType.String }
|
||||||
|
],
|
||||||
|
optionalParameters: [
|
||||||
|
{ 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 };
|
||||||
|
let dimensionId;
|
||||||
|
let location = pos;
|
||||||
|
if (location === undefined) {
|
||||||
|
if (!(source instanceof PlayerCommandOrigin))
|
||||||
|
return { status: CustomCommandStatus.Failure, message: 'construct.commands.move.posRequired' };
|
||||||
|
const player = source.getSource();
|
||||||
|
location = player.location;
|
||||||
|
dimensionId = player.dimension.id;
|
||||||
|
} else {
|
||||||
|
dimensionId = this.resolveDimensionId(source);
|
||||||
|
}
|
||||||
|
system.run(() => {
|
||||||
|
instance.move(dimensionId, location);
|
||||||
|
source.sendMessage({
|
||||||
|
rawtext: [{ translate: 'construct.commands.move.success',
|
||||||
|
with: [instanceName, String(Math.floor(location.x)), String(Math.floor(location.y)),
|
||||||
|
String(Math.floor(location.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 moveCommand = new MoveCommand();
|
||||||
@@ -16,6 +16,7 @@ import './commands/DeleteCommand';
|
|||||||
import './commands/RenameCommand';
|
import './commands/RenameCommand';
|
||||||
import './commands/ListCommand';
|
import './commands/ListCommand';
|
||||||
import './commands/PlaceCommand';
|
import './commands/PlaceCommand';
|
||||||
|
import './commands/MoveCommand';
|
||||||
|
|
||||||
// Other
|
// Other
|
||||||
import './classes/BlockInfo';
|
import './classes/BlockInfo';
|
||||||
|
|||||||
@@ -135,3 +135,8 @@ construct.commands.list.row=§a%1§r §8[§r%2§8]§r §7%3§r
|
|||||||
## construct:place
|
## construct:place
|
||||||
construct.commands.place=Place an instance at world coordinates (enables it).
|
construct.commands.place=Place an instance at world coordinates (enables it).
|
||||||
construct.commands.place.success=§aPlaced instance "%1" at %2 %3 %4 in %5.
|
construct.commands.place.success=§aPlaced instance "%1" at %2 %3 %4 in %5.
|
||||||
|
|
||||||
|
## construct:move
|
||||||
|
construct.commands.move=Reposition an instance without toggling its enabled state.
|
||||||
|
construct.commands.move.success=§aMoved instance "%1" to %2 %3 %4 in %5.
|
||||||
|
construct.commands.move.posRequired=§cMust provide coordinates when not running as a player.
|
||||||
|
|||||||
@@ -135,3 +135,8 @@ construct.commands.list.row=§a%1§r §8[§r%2§8]§r §7%3§r
|
|||||||
## construct:place
|
## construct:place
|
||||||
construct.commands.place=Place an instance at world coordinates (enables it).
|
construct.commands.place=Place an instance at world coordinates (enables it).
|
||||||
construct.commands.place.success=§aPlaced instance "%1" at %2 %3 %4 in %5.
|
construct.commands.place.success=§aPlaced instance "%1" at %2 %3 %4 in %5.
|
||||||
|
|
||||||
|
## construct:move
|
||||||
|
construct.commands.move=Reposition an instance without toggling its enabled state.
|
||||||
|
construct.commands.move.success=§aMoved instance "%1" to %2 %3 %4 in %5.
|
||||||
|
construct.commands.move.posRequired=§cMust provide coordinates when not running as a player.
|
||||||
|
|||||||
Reference in New Issue
Block a user