feat: rework commands and fix bugs
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
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 { CustomCommandParamType, CustomCommandStatus, CommandPermissionLevel, system } from '@minecraft/server';
|
||||
import { structureCollection } from '../classes/Structure/StructureCollection';
|
||||
|
||||
export class ActiveCommand extends Command {
|
||||
constructor() {
|
||||
@@ -12,32 +11,29 @@ export class ActiveCommand extends Command {
|
||||
{ name: 'instanceName', type: CustomCommandParamType.String },
|
||||
{ name: 'state', type: CustomCommandParamType.Boolean }
|
||||
],
|
||||
permissionLevel: CommandPermissionLevel.Any,
|
||||
callback: (source, instanceName, state) => this.run(source, instanceName, state)
|
||||
});
|
||||
}
|
||||
|
||||
run(source, instanceName, state) {
|
||||
try {
|
||||
const instance = findInstance(source, instanceName);
|
||||
if (!instance) return { status: CustomCommandStatus.Failure };
|
||||
if (state && !instance.hasLocation()) {
|
||||
system.run(() => source.sendMessage({
|
||||
rawtext: [{ translate: 'construct.commands.error.noLocation', with: [instanceName] }]
|
||||
}));
|
||||
return { status: CustomCommandStatus.Failure };
|
||||
}
|
||||
system.run(() => {
|
||||
if (state) instance.enable();
|
||||
else instance.disable();
|
||||
source.sendMessage({
|
||||
rawtext: [{ translate: 'construct.commands.active.success',
|
||||
with: [instanceName, String(state)] }]
|
||||
});
|
||||
});
|
||||
return { status: CustomCommandStatus.Success };
|
||||
} catch (err) {
|
||||
return commandError(source, err);
|
||||
const instance = structureCollection.get(instanceName);
|
||||
if (state && !instance.hasLocation()) {
|
||||
source.sendMessage({ translate: 'construct.commands.error.noLocation', with: [instanceName] });
|
||||
return void 0;
|
||||
}
|
||||
system.run(() => {
|
||||
if (state)
|
||||
instance.enable();
|
||||
else
|
||||
instance.disable();
|
||||
this.sendFeedback(source, instanceName, state);
|
||||
});
|
||||
return { status: CustomCommandStatus.Success };
|
||||
}
|
||||
|
||||
sendFeedback(source, instanceName, state) {
|
||||
source.sendMessage({ translate: state ? 'construct.commands.active.true' : 'construct.commands.active.false', with: [instanceName] });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
import { CommandPermissionLevel, CustomCommandStatus, EntityComponentTypes, ItemStack, system } from '@minecraft/server';
|
||||
import { Command } from '../classes/Commands/Command';
|
||||
import { PlayerCommandOrigin } from '../classes/Commands/PlayerCommandOrigin';
|
||||
import { requirePlayer } from '../classes/Commands/lib/requirePlayer';
|
||||
import { commandError } from '../classes/Commands/lib/commandError';
|
||||
import { MENU_ITEM } from '../consts';
|
||||
|
||||
export class ConstructCommand extends Command {
|
||||
@@ -10,28 +8,29 @@ export class ConstructCommand extends Command {
|
||||
super({
|
||||
name: 'construct',
|
||||
description: 'construct.commands.construct',
|
||||
permissionLevel: CommandPermissionLevel.Any,
|
||||
cheatsRequired: false,
|
||||
allowedSources: [PlayerCommandOrigin],
|
||||
permissionLevel: CommandPermissionLevel.Any,
|
||||
callback: (source) => this.run(source)
|
||||
});
|
||||
}
|
||||
|
||||
run(source) {
|
||||
try {
|
||||
const player = requirePlayer(source);
|
||||
system.run(() => {
|
||||
const remaining = player.getComponent(EntityComponentTypes.Inventory)
|
||||
?.container?.addItem(new ItemStack(MENU_ITEM));
|
||||
if (remaining)
|
||||
player.sendMessage({ translate: 'construct.commands.construct.fail' });
|
||||
else
|
||||
player.sendMessage({ translate: 'construct.commands.construct.success' });
|
||||
});
|
||||
return { status: CustomCommandStatus.Success };
|
||||
} catch (err) {
|
||||
return commandError(source, err);
|
||||
}
|
||||
const player = source.getSource();
|
||||
system.run(() => {
|
||||
this.giveMenuItem(player);
|
||||
});
|
||||
return { status: CustomCommandStatus.Success };
|
||||
}
|
||||
|
||||
giveMenuItem(player) {
|
||||
const inventoryComponent = player.getComponent(EntityComponentTypes.Inventory);
|
||||
const inventoryContainer = inventoryComponent?.container;
|
||||
const remaining = inventoryContainer?.addItem(new ItemStack(MENU_ITEM));
|
||||
if (remaining)
|
||||
player.sendMessage({ translate: 'construct.commands.construct.fail' });
|
||||
else
|
||||
player.sendMessage({ translate: 'construct.commands.construct.success' });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
import { CustomCommandParamType, CustomCommandStatus, system } from '@minecraft/server';
|
||||
import { Command } from '../classes/Commands/Command';
|
||||
import { CustomCommandParamType, CustomCommandStatus, CommandPermissionLevel, system } from '@minecraft/server';
|
||||
import { structureCollection } from '../classes/Structure/StructureCollection';
|
||||
import { findInstance } from '../classes/Commands/lib/findInstance';
|
||||
import { commandError } from '../classes/Commands/lib/commandError';
|
||||
|
||||
export class DeleteCommand extends Command {
|
||||
constructor() {
|
||||
@@ -12,24 +10,18 @@ export class DeleteCommand extends Command {
|
||||
mandatoryParameters: [
|
||||
{ name: 'instanceName', type: CustomCommandParamType.String }
|
||||
],
|
||||
permissionLevel: CommandPermissionLevel.Any,
|
||||
callback: (source, instanceName) => this.run(source, instanceName)
|
||||
});
|
||||
}
|
||||
|
||||
run(source, instanceName) {
|
||||
try {
|
||||
const instance = findInstance(source, instanceName);
|
||||
if (!instance) return { status: CustomCommandStatus.Failure };
|
||||
system.run(() => {
|
||||
structureCollection.delete(instanceName);
|
||||
source.sendMessage({
|
||||
rawtext: [{ translate: 'construct.commands.delete.success', with: [instanceName] }]
|
||||
});
|
||||
});
|
||||
return { status: CustomCommandStatus.Success };
|
||||
} catch (err) {
|
||||
return commandError(source, err);
|
||||
}
|
||||
const instance = structureCollection.get(instanceName);
|
||||
system.run(() => {
|
||||
structureCollection.delete(instanceName);
|
||||
source.sendMessage({ translate: 'construct.commands.delete.success', with: [instanceName] });
|
||||
});
|
||||
return { status: CustomCommandStatus.Success };
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { CustomCommandParamType, CustomCommandStatus, system } from '@minecraft/server';
|
||||
import { CommandPermissionLevel, 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 { structureCollection } from '../classes/Structure/StructureCollection';
|
||||
import { Vector } from '../lib/Vector';
|
||||
|
||||
export class InfoCommand extends Command {
|
||||
constructor() {
|
||||
@@ -11,46 +11,63 @@ export class InfoCommand extends Command {
|
||||
mandatoryParameters: [
|
||||
{ name: 'instanceName', type: CustomCommandParamType.String }
|
||||
],
|
||||
permissionLevel: CommandPermissionLevel.Any,
|
||||
callback: (source, instanceName) => this.run(source, instanceName)
|
||||
});
|
||||
}
|
||||
|
||||
run(source, instanceName) {
|
||||
try {
|
||||
const instance = findInstance(source, instanceName);
|
||||
if (!instance) return { status: CustomCommandStatus.Failure };
|
||||
const rawtext = [
|
||||
{ translate: 'construct.commands.info.header', with: [instance.getName()] },
|
||||
{ text: '\n' },
|
||||
{ translate: 'construct.commands.info.structure', with: [instance.getStructureId()] },
|
||||
{ text: '\n' },
|
||||
{ translate: 'construct.commands.info.enabled', with: [String(instance.isEnabled())] },
|
||||
{ text: '\n' }
|
||||
];
|
||||
if (instance.hasLocation()) {
|
||||
const { dimensionId, location } = instance.getLocation();
|
||||
rawtext.push({ translate: 'construct.commands.info.location',
|
||||
with: [String(location.x), String(location.y), String(location.z),
|
||||
dimensionId.replace('minecraft:', '')] });
|
||||
} else {
|
||||
rawtext.push({ translate: 'construct.commands.info.noLocation' });
|
||||
}
|
||||
rawtext.push({ text: '\n' });
|
||||
rawtext.push({ translate: 'construct.commands.info.layer',
|
||||
with: [String(instance.getLayer()), String(instance.getMaxLayer())] });
|
||||
rawtext.push({ text: '\n' });
|
||||
rawtext.push({ translate: 'construct.commands.info.verifier',
|
||||
with: [String(instance.options.verifier.isEnabled)] });
|
||||
rawtext.push({ text: '\n' });
|
||||
const bounds = instance.getBounds();
|
||||
rawtext.push({ translate: 'construct.commands.info.bounds',
|
||||
with: [String(bounds.min.x), String(bounds.min.y), String(bounds.min.z),
|
||||
String(bounds.max.x), String(bounds.max.y), String(bounds.max.z)] });
|
||||
system.run(() => source.sendMessage({ rawtext }));
|
||||
return { status: CustomCommandStatus.Success };
|
||||
} catch (err) {
|
||||
return commandError(source, err);
|
||||
}
|
||||
const instance = structureCollection.get(instanceName);
|
||||
const message = { rawtext: [
|
||||
this.getHeaderText(instance),
|
||||
{ text: '\n' },
|
||||
this.getStructureIdText(instance),
|
||||
{ text: '\n' },
|
||||
this.getLocationText(instance),
|
||||
{ text: '\n' },
|
||||
this.getEnabledText(instance),
|
||||
{ text: '\n' },
|
||||
this.getLayerText(instance),
|
||||
{ text: '\n' },
|
||||
this.getVerifierText(instance),
|
||||
{ text: '\n' },
|
||||
this.getSizeText(instance)
|
||||
]};
|
||||
source.sendMessage(message);
|
||||
return { status: CustomCommandStatus.Success };
|
||||
}
|
||||
|
||||
getHeaderText(instance) {
|
||||
return { translate: 'construct.commands.info.header', with: [instance.getName()] };
|
||||
}
|
||||
|
||||
getStructureIdText(instance) {
|
||||
return { translate: 'construct.commands.info.structure', with: [instance.getStructureId()] };
|
||||
}
|
||||
|
||||
getLocationText(instance) {
|
||||
if (!instance.hasLocation())
|
||||
return { translate: 'construct.commands.info.noLocation' };
|
||||
const { dimensionId, location } = instance.getLocation();
|
||||
return { translate: 'construct.commands.info.location', with: [location.toString(), dimensionId.replace('minecraft:', '')] };
|
||||
}
|
||||
|
||||
getEnabledText(instance) {
|
||||
return { translate: 'construct.commands.info.enabled', with: [String(instance.isEnabled())] };
|
||||
}
|
||||
|
||||
getLayerText(instance) {
|
||||
return { translate: 'construct.commands.info.layer', with: [String(instance.getLayer()), String(instance.getMaxLayer())] };
|
||||
}
|
||||
|
||||
getVerifierText(instance) {
|
||||
const verifier = instance.options.verifier;
|
||||
return { translate: 'construct.commands.info.verifier', with: [String(verifier.isEnabled)] };
|
||||
}
|
||||
|
||||
getSizeText(instance) {
|
||||
const bounds = instance.getBounds();
|
||||
return { translate: 'construct.commands.info.size', with: [bounds.max.toString(), Vector.volume(bounds.min, bounds.max).toString()] };
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
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 { CommandPermissionLevel, CustomCommandParamType, CustomCommandStatus, system } from '@minecraft/server';
|
||||
import { structureCollection } from '../classes/Structure/StructureCollection';
|
||||
|
||||
export class LayerCommand extends Command {
|
||||
constructor() {
|
||||
@@ -12,33 +11,21 @@ export class LayerCommand extends Command {
|
||||
{ name: 'instanceName', type: CustomCommandParamType.String },
|
||||
{ name: 'layer', type: CustomCommandParamType.Integer }
|
||||
],
|
||||
permissionLevel: CommandPermissionLevel.Any,
|
||||
callback: (source, instanceName, layer) => this.run(source, instanceName, layer)
|
||||
});
|
||||
}
|
||||
|
||||
run(source, instanceName, layer) {
|
||||
try {
|
||||
const instance = findInstance(source, instanceName);
|
||||
if (!instance) return { status: CustomCommandStatus.Failure };
|
||||
const max = instance.getMaxLayer();
|
||||
if (layer < 0 || layer > max) {
|
||||
system.run(() => source.sendMessage({
|
||||
rawtext: [{ translate: 'construct.commands.layer.outOfBounds',
|
||||
with: [String(layer), instanceName, String(max)] }]
|
||||
}));
|
||||
return { status: CustomCommandStatus.Failure };
|
||||
}
|
||||
system.run(() => {
|
||||
instance.setLayer(layer);
|
||||
source.sendMessage({
|
||||
rawtext: [{ translate: 'construct.commands.layer.success',
|
||||
with: [instanceName, String(layer)] }]
|
||||
});
|
||||
});
|
||||
return { status: CustomCommandStatus.Success };
|
||||
} catch (err) {
|
||||
return commandError(source, err);
|
||||
const instance = structureCollection.get(instanceName);
|
||||
const max = instance.getMaxLayer();
|
||||
if (layer < 0 || layer > max) {
|
||||
source.sendMessage({ translate: 'construct.commands.layer.outOfBounds', with: [String(layer), instanceName, String(max)] });
|
||||
return void 0;
|
||||
}
|
||||
instance.setLayer(layer);
|
||||
source.sendMessage({ translate: 'construct.commands.layer.success', with: [instanceName, String(layer)] });
|
||||
return { status: CustomCommandStatus.Success };
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,53 +1,51 @@
|
||||
import { CustomCommandStatus, system } from '@minecraft/server';
|
||||
import { CommandPermissionLevel, CustomCommandStatus, system } from '@minecraft/server';
|
||||
import { Command } from '../classes/Commands/Command';
|
||||
import { structureCollection } from '../classes/Structure/StructureCollection';
|
||||
import { commandError } from '../classes/Commands/lib/commandError';
|
||||
|
||||
export class ListCommand extends Command {
|
||||
constructor() {
|
||||
super({
|
||||
name: 'list',
|
||||
description: 'construct.commands.list',
|
||||
permissionLevel: CommandPermissionLevel.Any,
|
||||
callback: (source) => this.run(source)
|
||||
});
|
||||
}
|
||||
|
||||
run(source) {
|
||||
try {
|
||||
const names = structureCollection.getInstanceNames();
|
||||
if (names.length === 0) {
|
||||
return { status: CustomCommandStatus.Success, message: 'construct.commands.list.empty' };
|
||||
}
|
||||
system.run(() => {
|
||||
const rawtext = [
|
||||
{ translate: 'construct.commands.list.header', with: [String(names.length)] },
|
||||
{ text: '\n' }
|
||||
];
|
||||
for (const name of names) {
|
||||
const instance = structureCollection.get(name);
|
||||
const status = this.formatStatus(instance);
|
||||
rawtext.push({
|
||||
translate: 'construct.commands.list.row',
|
||||
with: [name, instance.getStructureId(), status]
|
||||
});
|
||||
rawtext.push({ text: '\n' });
|
||||
}
|
||||
source.sendMessage({ rawtext });
|
||||
const names = structureCollection.getInstanceNames();
|
||||
if (names.length === 0)
|
||||
return { status: CustomCommandStatus.Success, message: 'construct.commands.list.empty' };
|
||||
const rawtext = [
|
||||
{ translate: 'construct.commands.list.header', with: [String(names.length)] },
|
||||
{ text: '\n' }
|
||||
];
|
||||
for (const name of names) {
|
||||
const instance = structureCollection.get(name);
|
||||
const status = this.formatStatus(instance);
|
||||
rawtext.push({
|
||||
translate: 'construct.commands.list.row',
|
||||
with: { rawtext: [{ text: name }, { text: instance.getStructureId() }, status] }
|
||||
});
|
||||
return { status: CustomCommandStatus.Success };
|
||||
} catch (err) {
|
||||
return commandError(source, err);
|
||||
rawtext.push({ text: '\n' });
|
||||
}
|
||||
source.sendMessage({ rawtext });
|
||||
return { status: CustomCommandStatus.Success };
|
||||
}
|
||||
|
||||
formatStatus(instance) {
|
||||
if (!instance.hasLocation())
|
||||
return 'no location';
|
||||
if (!instance.isEnabled())
|
||||
return 'disabled';
|
||||
const { dimensionId, location } = instance.getLocation();
|
||||
const dim = dimensionId.replace('minecraft:', '');
|
||||
return `enabled @ ${location.x} ${location.y} ${location.z} (${dim})`;
|
||||
const statusMessage = { rawtext: [] };
|
||||
if (instance.isEnabled())
|
||||
statusMessage.rawtext.push({ translate: 'construct.commands.list.row.enabled' });
|
||||
else
|
||||
statusMessage.rawtext.push({ translate: 'construct.commands.list.row.disabled' });
|
||||
if (instance.hasLocation()) {
|
||||
const { dimensionId, location } = instance.getLocation();
|
||||
statusMessage.rawtext.push({ translate: 'construct.commands.list.row.location', with: [location.toString(), dimensionId.replace('minecraft:', '')] });
|
||||
} else {
|
||||
statusMessage.rawtext.push({ translate: 'construct.commands.list.row.nolocation' });
|
||||
}
|
||||
return statusMessage;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { CustomCommandParamType, CustomCommandStatus, EntityComponentTypes, system } from '@minecraft/server';
|
||||
import { CommandPermissionLevel, CustomCommandParamType, CustomCommandStatus, EntityComponentTypes, system } from '@minecraft/server';
|
||||
import { Command } from '../classes/Commands/Command';
|
||||
import { findInstance } from '../classes/Commands/lib/findInstance';
|
||||
import { requirePlayer } from '../classes/Commands/lib/requirePlayer';
|
||||
import { commandError } from '../classes/Commands/lib/commandError';
|
||||
import { structureCollection } from '../classes/Structure/StructureCollection';
|
||||
import { PlayerCommandOrigin } from '../classes/Commands/PlayerCommandOrigin';
|
||||
import { NotAPlayerError } from '../classes/Errors/NotAPlayerError';
|
||||
|
||||
export class MaterialsCommand extends Command {
|
||||
constructor() {
|
||||
@@ -15,44 +15,45 @@ export class MaterialsCommand extends Command {
|
||||
optionalParameters: [
|
||||
{ name: 'missing', type: CustomCommandParamType.Boolean }
|
||||
],
|
||||
permissionLevel: CommandPermissionLevel.Any,
|
||||
callback: (source, instanceName, missing) => this.run(source, instanceName, missing)
|
||||
});
|
||||
}
|
||||
|
||||
run(source, instanceName, missing) {
|
||||
try {
|
||||
const instance = findInstance(source, instanceName);
|
||||
if (!instance) return { status: CustomCommandStatus.Failure };
|
||||
const onlyMissing = missing === true;
|
||||
let container;
|
||||
let headerKey;
|
||||
if (onlyMissing) {
|
||||
const player = requirePlayer(source);
|
||||
container = player.getComponent(EntityComponentTypes.Inventory)?.container;
|
||||
headerKey = 'construct.commands.materials.headerMissing';
|
||||
} else {
|
||||
headerKey = 'construct.commands.materials.headerAll';
|
||||
}
|
||||
system.run(() => {
|
||||
const materials = instance.getActiveMaterials();
|
||||
const materialsMap = onlyMissing
|
||||
? materials.getMaterialsDifference(container)
|
||||
: undefined;
|
||||
const list = materials.formatString(materialsMap);
|
||||
const rawtext = [
|
||||
{ translate: headerKey, with: [instanceName] },
|
||||
{ text: '\n' }
|
||||
];
|
||||
if (!list.rawtext || list.rawtext.length === 0)
|
||||
rawtext.push({ translate: 'construct.commands.materials.empty' });
|
||||
else
|
||||
rawtext.push(list);
|
||||
source.sendMessage({ rawtext });
|
||||
});
|
||||
return { status: CustomCommandStatus.Success };
|
||||
} catch (err) {
|
||||
return commandError(source, err);
|
||||
const instance = structureCollection.get(instanceName);
|
||||
const onlyMissing = missing === true;
|
||||
if (onlyMissing)
|
||||
this.assertIsPlayer(source);
|
||||
const headerKey = onlyMissing ? 'construct.commands.materials.headerMissing' : 'construct.commands.materials.headerAll';
|
||||
const rawtext = [
|
||||
{ translate: headerKey, with: [instanceName] },
|
||||
{ text: '\n' }
|
||||
];
|
||||
const list = this.getMaterialList(source, instance, onlyMissing);
|
||||
if (!list.rawtext || list.rawtext.length === 0)
|
||||
rawtext.push({ translate: 'construct.commands.materials.empty' });
|
||||
else
|
||||
rawtext.push(list);
|
||||
source.sendMessage({ rawtext });
|
||||
return { status: CustomCommandStatus.Success };
|
||||
}
|
||||
|
||||
assertIsPlayer(source) {
|
||||
if (!(source instanceof PlayerCommandOrigin))
|
||||
throw new NotAPlayerError();
|
||||
}
|
||||
|
||||
getMaterialList(source, instance, onlyMissing) {
|
||||
const materials = instance.getActiveMaterials();
|
||||
let container;
|
||||
if (onlyMissing) {
|
||||
const player = source.getSource();
|
||||
const inventoryComponent = player?.getComponent(EntityComponentTypes.Inventory);
|
||||
container = inventoryComponent?.container;
|
||||
}
|
||||
const materialsMap = onlyMissing ? materials.getMaterialsDifference(container) : void 0;
|
||||
return materials.formatString(materialsMap);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
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 { CommandPermissionLevel, CustomCommandParamType, CustomCommandStatus, system, world } from '@minecraft/server';
|
||||
import { Vector } from '../lib/Vector';
|
||||
import { structureCollection } from '../classes/Structure/StructureCollection';
|
||||
import { PlayerCommandOrigin } from '../classes/Commands/PlayerCommandOrigin';
|
||||
import { BlockCommandOrigin } from '../classes/Commands/BlockCommandOrigin';
|
||||
import { EntityCommandOrigin } from '../classes/Commands/EntityCommandOrigin';
|
||||
|
||||
export class MoveCommand extends Command {
|
||||
constructor() {
|
||||
@@ -15,47 +13,34 @@ export class MoveCommand extends Command {
|
||||
{ name: 'instanceName', type: CustomCommandParamType.String }
|
||||
],
|
||||
optionalParameters: [
|
||||
{ name: 'pos', type: CustomCommandParamType.Location }
|
||||
{ name: 'dimensionId', type: CustomCommandParamType.Enum }, // Enum defined in PlaceCommand.js
|
||||
{ name: 'location', type: CustomCommandParamType.Location }
|
||||
],
|
||||
callback: (source, instanceName, pos) => this.run(source, instanceName, pos)
|
||||
permissionLevel: CommandPermissionLevel.Any,
|
||||
callback: (source, instanceName, dimensionId, location) => this.run(source, instanceName, dimensionId, location)
|
||||
});
|
||||
}
|
||||
|
||||
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);
|
||||
run(source, instanceName, dimensionId, location) {
|
||||
const instance = structureCollection.get(instanceName);
|
||||
if (dimensionId === void 0 || location === void 0) {
|
||||
if (!(source instanceof PlayerCommandOrigin))
|
||||
return { status: CustomCommandStatus.Failure, message: 'construct.commands.move.locationRequired' };
|
||||
const player = source.getSource();
|
||||
location = player.location;
|
||||
dimensionId = player.dimension.id;
|
||||
}
|
||||
this.assertDimensionExists(dimensionId);
|
||||
const flooredLocation = Vector.from(location).floor();
|
||||
system.run(() => {
|
||||
instance.move(dimensionId, flooredLocation);
|
||||
source.sendMessage({ translate: 'construct.commands.move.success', with: [instanceName, flooredLocation.toString(), dimensionId.replace('minecraft:', '')] });
|
||||
});
|
||||
return { status: CustomCommandStatus.Success };
|
||||
}
|
||||
|
||||
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';
|
||||
assertDimensionExists(dimensionId) {
|
||||
return world.getDimension(dimensionId) !== void 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { CustomCommandParamType, CustomCommandStatus, system } from '@minecraft/server';
|
||||
import { Command } from '../classes/Commands/Command';
|
||||
import { CommandPermissionLevel, CustomCommandParamType, CustomCommandStatus, system } from '@minecraft/server';
|
||||
import { structureCollection } from '../classes/Structure/StructureCollection';
|
||||
import { commandError } from '../classes/Commands/lib/commandError';
|
||||
import { InstanceExistsError } from '../classes/Errors/InstanceExistsError';
|
||||
import { StructureNotFoundError } from '../classes/Errors/StructureNotFoundError';
|
||||
|
||||
export class NewCommand extends Command {
|
||||
constructor() {
|
||||
@@ -12,35 +13,38 @@ export class NewCommand extends Command {
|
||||
{ name: 'instanceName', type: CustomCommandParamType.String },
|
||||
{ name: 'structureId', type: CustomCommandParamType.String }
|
||||
],
|
||||
permissionLevel: CommandPermissionLevel.Any,
|
||||
callback: (source, instanceName, structureId) => this.run(source, instanceName, structureId)
|
||||
});
|
||||
}
|
||||
|
||||
run(source, instanceName, structureId) {
|
||||
try {
|
||||
if (structureCollection.has(instanceName)) {
|
||||
system.run(() => source.sendMessage({
|
||||
rawtext: [{ translate: 'construct.commands.new.duplicateName', with: [instanceName] }]
|
||||
}));
|
||||
return { status: CustomCommandStatus.Failure };
|
||||
}
|
||||
if (!structureCollection.getWorldStructureIds().includes(structureId)) {
|
||||
system.run(() => source.sendMessage({
|
||||
rawtext: [{ translate: 'construct.commands.new.unknownStructure', with: [structureId] }]
|
||||
}));
|
||||
return { status: CustomCommandStatus.Failure };
|
||||
}
|
||||
system.run(() => {
|
||||
structureCollection.add(instanceName, structureId);
|
||||
source.sendMessage({
|
||||
rawtext: [{ translate: 'construct.commands.new.success', with: [instanceName, structureId] }]
|
||||
});
|
||||
});
|
||||
return { status: CustomCommandStatus.Success };
|
||||
} catch (err) {
|
||||
return commandError(source, err);
|
||||
}
|
||||
this.tryAddStructure(source, instanceName, structureId);
|
||||
return { status: CustomCommandStatus.Success };
|
||||
}
|
||||
|
||||
tryAddStructure(source, instanceName, structureId) {
|
||||
system.run(() => {
|
||||
try {
|
||||
this.addStructure(source, instanceName, structureId);
|
||||
} catch (error) {
|
||||
this.handleStructureAdditionErrors(source, error);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
addStructure(source, instanceName, structureId) {
|
||||
structureCollection.add(instanceName, structureId);
|
||||
source.sendMessage({ translate: 'construct.commands.new.success', with: [instanceName, structureId] });
|
||||
}
|
||||
|
||||
handleStructureAdditionErrors(source, error) {
|
||||
if (error instanceof InstanceExistsError || error instanceof StructureNotFoundError)
|
||||
error.sendTo(source);
|
||||
else
|
||||
throw error;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export const newCommand = new NewCommand();
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { CustomCommandParamType, CustomCommandStatus, system } from '@minecraft/server';
|
||||
import { CommandPermissionLevel, 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 { structureCollection } from '../classes/Structure/StructureCollection';
|
||||
|
||||
export class NextLayerCommand extends Command {
|
||||
constructor() {
|
||||
@@ -11,25 +10,16 @@ export class NextLayerCommand extends Command {
|
||||
mandatoryParameters: [
|
||||
{ name: 'instanceName', type: CustomCommandParamType.String }
|
||||
],
|
||||
permissionLevel: CommandPermissionLevel.Any,
|
||||
callback: (source, instanceName) => this.run(source, instanceName)
|
||||
});
|
||||
}
|
||||
|
||||
run(source, instanceName) {
|
||||
try {
|
||||
const instance = findInstance(source, instanceName);
|
||||
if (!instance) return { status: CustomCommandStatus.Failure };
|
||||
system.run(() => {
|
||||
instance.increaseLayer();
|
||||
source.sendMessage({
|
||||
rawtext: [{ translate: 'construct.commands.nextlayer.success',
|
||||
with: [instanceName, String(instance.getLayer())] }]
|
||||
});
|
||||
});
|
||||
return { status: CustomCommandStatus.Success };
|
||||
} catch (err) {
|
||||
return commandError(source, err);
|
||||
}
|
||||
const instance = structureCollection.get(instanceName);
|
||||
instance.increaseLayer();
|
||||
source.sendMessage({ translate: 'construct.commands.nextlayer.success', with: [instanceName, String(instance.getLayer())] });
|
||||
return { status: CustomCommandStatus.Success };
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
import { CustomCommandParamType, CustomCommandStatus, system } from '@minecraft/server';
|
||||
import { CommandPermissionLevel, CustomCommandParamType, CustomCommandStatus, system } from '@minecraft/server';
|
||||
import { Command } from '../classes/Commands/Command';
|
||||
import { PlayerCommandOrigin } from '../classes/Commands/PlayerCommandOrigin';
|
||||
import { BuilderOptions } from '../classes/Builder/BuilderOptions';
|
||||
import { requirePlayer } from '../classes/Commands/lib/requirePlayer';
|
||||
import { commandError } from '../classes/Commands/lib/commandError';
|
||||
|
||||
export class OptionCommand extends Command {
|
||||
constructor() {
|
||||
@@ -18,29 +16,22 @@ export class OptionCommand extends Command {
|
||||
enums: [
|
||||
{ name: 'optionId', values: ['easyPlace', 'fastEasyPlace', 'materialGrabber'] }
|
||||
],
|
||||
permissionLevel: CommandPermissionLevel.Any,
|
||||
callback: (source, optionId, state) => this.run(source, optionId, state)
|
||||
});
|
||||
}
|
||||
|
||||
run(source, optionId, state) {
|
||||
try {
|
||||
const player = requirePlayer(source);
|
||||
if (!BuilderOptions.get(optionId)) {
|
||||
system.run(() => source.sendMessage({
|
||||
rawtext: [{ translate: 'construct.commands.option.unknownOption', with: [optionId] }]
|
||||
}));
|
||||
return { status: CustomCommandStatus.Failure };
|
||||
}
|
||||
system.run(() => {
|
||||
BuilderOptions.setValue(optionId, player.id, state);
|
||||
source.sendMessage({
|
||||
rawtext: [{ translate: 'construct.commands.option.success', with: [optionId, String(state)] }]
|
||||
});
|
||||
});
|
||||
return { status: CustomCommandStatus.Success };
|
||||
} catch (err) {
|
||||
return commandError(source, err);
|
||||
if (!BuilderOptions.get(optionId)) {
|
||||
source.sendMessage({ translate: 'construct.commands.option.unknownOption', with: [optionId] });
|
||||
return void 0;
|
||||
}
|
||||
system.run(() => {
|
||||
const player = source.getSource();
|
||||
BuilderOptions.setValue(optionId, player.id, state);
|
||||
source.sendMessage({ translate: 'construct.commands.option.success', with: [optionId, String(state)] });
|
||||
});
|
||||
return { status: CustomCommandStatus.Success };
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,49 +1,38 @@
|
||||
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';
|
||||
import { Command } from '../classes/Commands/Command';
|
||||
import { CommandPermissionLevel, CustomCommandParamType, CustomCommandStatus, DimensionTypes, system, world } from '@minecraft/server';
|
||||
import { structureCollection } from '../classes/Structure/StructureCollection';
|
||||
import { InstanceExistsError } from '../classes/Errors/InstanceExistsError';
|
||||
import { Vector } from '../lib/Vector';
|
||||
|
||||
export class PlaceCommand extends Command {
|
||||
constructor() {
|
||||
super({
|
||||
name: 'place',
|
||||
description: 'construct.commands.place',
|
||||
enums: [ { name: 'dimensionId', values: Object.values(DimensionTypes.getAll().map(d => d.typeId)) } ],
|
||||
mandatoryParameters: [
|
||||
{ name: 'instanceName', type: CustomCommandParamType.String },
|
||||
{ name: 'pos', type: CustomCommandParamType.Location }
|
||||
{ name: 'dimensionId', type: CustomCommandParamType.Enum },
|
||||
{ name: 'location', type: CustomCommandParamType.Location }
|
||||
],
|
||||
callback: (source, instanceName, pos) => this.run(source, instanceName, pos)
|
||||
permissionLevel: CommandPermissionLevel.Any,
|
||||
callback: (source, instanceName, dimensionId, location) => this.run(source, instanceName, dimensionId, location)
|
||||
});
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
run(source, instanceName, dimensionId, location) {
|
||||
const instance = structureCollection.get(instanceName);
|
||||
const flooredLocation = Vector.from(location).floor();
|
||||
this.assertDimensionExists(dimensionId);
|
||||
system.run(() => {
|
||||
instance.place(dimensionId, flooredLocation);
|
||||
source.sendMessage({ translate: 'construct.commands.place.success', with: [instanceName, flooredLocation.toString(), dimensionId.replace('minecraft:', '')] });
|
||||
});
|
||||
return { status: CustomCommandStatus.Success };
|
||||
}
|
||||
|
||||
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';
|
||||
assertDimensionExists(dimensionId) {
|
||||
return world.getDimension(dimensionId) !== void 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { CustomCommandParamType, CustomCommandStatus, system } from '@minecraft/server';
|
||||
import { CommandPermissionLevel, 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 { structureCollection } from '../classes/Structure/StructureCollection';
|
||||
|
||||
export class PrevLayerCommand extends Command {
|
||||
constructor() {
|
||||
@@ -11,25 +10,16 @@ export class PrevLayerCommand extends Command {
|
||||
mandatoryParameters: [
|
||||
{ name: 'instanceName', type: CustomCommandParamType.String }
|
||||
],
|
||||
permissionLevel: CommandPermissionLevel.Any,
|
||||
callback: (source, instanceName) => this.run(source, instanceName)
|
||||
});
|
||||
}
|
||||
|
||||
run(source, instanceName) {
|
||||
try {
|
||||
const instance = findInstance(source, instanceName);
|
||||
if (!instance) return { status: CustomCommandStatus.Failure };
|
||||
system.run(() => {
|
||||
instance.decreaseLayer();
|
||||
source.sendMessage({
|
||||
rawtext: [{ translate: 'construct.commands.prevlayer.success',
|
||||
with: [instanceName, String(instance.getLayer())] }]
|
||||
});
|
||||
});
|
||||
return { status: CustomCommandStatus.Success };
|
||||
} catch (err) {
|
||||
return commandError(source, err);
|
||||
}
|
||||
const instance = structureCollection.get(instanceName);
|
||||
instance.decreaseLayer();
|
||||
source.sendMessage({ translate: 'construct.commands.prevlayer.success', with: [instanceName, String(instance.getLayer())] });
|
||||
return { status: CustomCommandStatus.Success };
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
import { CustomCommandParamType, CustomCommandStatus, system } from '@minecraft/server';
|
||||
import { Command } from '../classes/Commands/Command';
|
||||
import { CommandPermissionLevel, CustomCommandParamType, CustomCommandStatus, system } from '@minecraft/server';
|
||||
import { structureCollection } from '../classes/Structure/StructureCollection';
|
||||
import { findInstance } from '../classes/Commands/lib/findInstance';
|
||||
import { commandError } from '../classes/Commands/lib/commandError';
|
||||
|
||||
export class RenameCommand extends Command {
|
||||
constructor() {
|
||||
@@ -13,30 +11,20 @@ export class RenameCommand extends Command {
|
||||
{ name: 'instanceName', type: CustomCommandParamType.String },
|
||||
{ name: 'newName', type: CustomCommandParamType.String }
|
||||
],
|
||||
permissionLevel: CommandPermissionLevel.Any,
|
||||
callback: (source, instanceName, newName) => this.run(source, instanceName, newName)
|
||||
});
|
||||
}
|
||||
|
||||
run(source, instanceName, newName) {
|
||||
try {
|
||||
const instance = findInstance(source, instanceName);
|
||||
if (!instance) return { status: CustomCommandStatus.Failure };
|
||||
if (structureCollection.has(newName)) {
|
||||
system.run(() => source.sendMessage({
|
||||
rawtext: [{ translate: 'construct.commands.rename.duplicateName', with: [newName] }]
|
||||
}));
|
||||
return { status: CustomCommandStatus.Failure };
|
||||
}
|
||||
system.run(() => {
|
||||
structureCollection.rename(instanceName, newName);
|
||||
source.sendMessage({
|
||||
rawtext: [{ translate: 'construct.commands.rename.success', with: [instanceName, newName] }]
|
||||
});
|
||||
});
|
||||
return { status: CustomCommandStatus.Success };
|
||||
} catch (err) {
|
||||
return commandError(source, err);
|
||||
const instance = structureCollection.get(instanceName);
|
||||
if (structureCollection.has(newName)) {
|
||||
source.sendMessage({ translate: 'construct.error.instanceExists', with: [newName] });
|
||||
return void 0;
|
||||
}
|
||||
structureCollection.rename(instanceName, newName);
|
||||
source.sendMessage({ translate: 'construct.commands.rename.success', with: [instanceName, newName] });
|
||||
return { status: CustomCommandStatus.Success };
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
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 { CommandPermissionLevel, CustomCommandParamType, CustomCommandStatus, system, TicksPerSecond } from '@minecraft/server';
|
||||
import { InstanceFormBuilder } from '../classes/Instance/InstanceFormBuilder';
|
||||
import { structureCollection } from '../classes/Structure/StructureCollection';
|
||||
import { StructureVerifier } from '../classes/Verifier/StructureVerifier';
|
||||
import { StructureStatistics } from '../classes/Structure/StructureStatistics';
|
||||
|
||||
export class StatsCommand extends Command {
|
||||
constructor() {
|
||||
@@ -12,26 +13,29 @@ export class StatsCommand extends Command {
|
||||
mandatoryParameters: [
|
||||
{ name: 'instanceName', type: CustomCommandParamType.String }
|
||||
],
|
||||
permissionLevel: CommandPermissionLevel.Any,
|
||||
callback: (source, instanceName) => this.run(source, instanceName)
|
||||
});
|
||||
}
|
||||
|
||||
run(source, instanceName) {
|
||||
try {
|
||||
const instance = findInstance(source, instanceName);
|
||||
if (!instance) return { status: CustomCommandStatus.Failure };
|
||||
system.run(async () => {
|
||||
try {
|
||||
const { stats } = await InstanceFormBuilder.buildStatistics(instance);
|
||||
source.sendMessage(stats);
|
||||
} catch (err) {
|
||||
source.sendMessage({ translate: 'construct.commands.stats.alreadyRunning' });
|
||||
}
|
||||
});
|
||||
return { status: CustomCommandStatus.Success };
|
||||
} catch (err) {
|
||||
return commandError(source, err);
|
||||
}
|
||||
const instance = structureCollection.get(instanceName);
|
||||
if (this.structureVerifier)
|
||||
return { status: CustomCommandStatus.Failure, error: 'construct.commands.stats.alreadyRunning' };
|
||||
system.run(async () => {
|
||||
source.sendMessage(await this.getStatsMessage(instance));
|
||||
});
|
||||
return { status: CustomCommandStatus.Success };
|
||||
}
|
||||
|
||||
async getStatsMessage(instance) {
|
||||
const verifierOptions = { isEnabled: true, particleLifetime: 1*TicksPerSecond, isStandalone: true };
|
||||
this.structureVerifier = new StructureVerifier(instance, verifierOptions);
|
||||
const verification = await this.structureVerifier.verifyStructure(true);
|
||||
const statistics = new StructureStatistics(instance, verification);
|
||||
const statsMessage = statistics.getMessage();
|
||||
this.structureVerifier = void 0;
|
||||
return statsMessage;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
import { CustomCommandParamType, CustomCommandStatus, EntityComponentTypes, EquipmentSlot, system } from '@minecraft/server';
|
||||
import { Command } from '../classes/Commands/Command';
|
||||
import { CommandPermissionLevel, CustomCommandParamType, CustomCommandStatus, EntityComponentTypes, EquipmentSlot, system } from '@minecraft/server';
|
||||
import { PlayerCommandOrigin } from '../classes/Commands/PlayerCommandOrigin';
|
||||
import { findInstance } from '../classes/Commands/lib/findInstance';
|
||||
import { requirePlayer } from '../classes/Commands/lib/requirePlayer';
|
||||
import { commandError } from '../classes/Commands/lib/commandError';
|
||||
import { MENU_ITEM } from '../consts';
|
||||
import { structureCollection } from '../classes/Structure/StructureCollection';
|
||||
|
||||
export class TagCommand extends Command {
|
||||
constructor() {
|
||||
@@ -15,32 +13,24 @@ export class TagCommand extends Command {
|
||||
mandatoryParameters: [
|
||||
{ name: 'instanceName', type: CustomCommandParamType.String }
|
||||
],
|
||||
permissionLevel: CommandPermissionLevel.Any,
|
||||
callback: (source, instanceName) => this.run(source, instanceName)
|
||||
});
|
||||
}
|
||||
|
||||
run(source, instanceName) {
|
||||
try {
|
||||
const player = requirePlayer(source);
|
||||
const instance = findInstance(source, instanceName);
|
||||
if (!instance) return { status: CustomCommandStatus.Failure };
|
||||
const equipment = player.getComponent(EntityComponentTypes.Equippable);
|
||||
const itemStack = equipment?.getEquipment(EquipmentSlot.Mainhand);
|
||||
if (itemStack?.typeId !== MENU_ITEM) {
|
||||
system.run(() => source.sendMessage({ translate: 'construct.commands.tag.notHoldingItem' }));
|
||||
return { status: CustomCommandStatus.Failure };
|
||||
}
|
||||
system.run(() => {
|
||||
itemStack.nameTag = instanceName;
|
||||
equipment.setEquipment(EquipmentSlot.Mainhand, itemStack);
|
||||
source.sendMessage({
|
||||
rawtext: [{ translate: 'construct.commands.tag.success', with: [instanceName] }]
|
||||
});
|
||||
});
|
||||
return { status: CustomCommandStatus.Success };
|
||||
} catch (err) {
|
||||
return commandError(source, err);
|
||||
}
|
||||
const instance = structureCollection.get(instanceName);
|
||||
const player = source.getSource();
|
||||
const equipment = player.getComponent(EntityComponentTypes.Equippable);
|
||||
const itemStack = equipment?.getEquipment(EquipmentSlot.Mainhand);
|
||||
if (itemStack?.typeId !== MENU_ITEM)
|
||||
return { status: CustomCommandStatus.Failure, message: 'construct.commands.tag.notHoldingItem' };
|
||||
system.run(() => {
|
||||
itemStack.nameTag = instanceName;
|
||||
equipment.setEquipment(EquipmentSlot.Mainhand, itemStack);
|
||||
source.sendMessage({ translate: 'construct.commands.tag.success', with: [instanceName] });
|
||||
});
|
||||
return { status: CustomCommandStatus.Success };
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { CustomCommandParamType, CustomCommandStatus, system } from '@minecraft/server';
|
||||
import { CommandPermissionLevel, 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 { structureCollection } from '../classes/Structure/StructureCollection';
|
||||
|
||||
export class VerifierCommand extends Command {
|
||||
constructor() {
|
||||
@@ -12,25 +11,23 @@ export class VerifierCommand extends Command {
|
||||
{ name: 'instanceName', type: CustomCommandParamType.String },
|
||||
{ name: 'state', type: CustomCommandParamType.Boolean }
|
||||
],
|
||||
permissionLevel: CommandPermissionLevel.Any,
|
||||
callback: (source, instanceName, state) => this.run(source, instanceName, state)
|
||||
});
|
||||
}
|
||||
|
||||
run(source, instanceName, state) {
|
||||
try {
|
||||
const instance = findInstance(source, instanceName);
|
||||
if (!instance) return { status: CustomCommandStatus.Failure };
|
||||
system.run(() => {
|
||||
instance.setVerifierEnabled(state);
|
||||
source.sendMessage({
|
||||
rawtext: [{ translate: 'construct.commands.verifier.success',
|
||||
with: [instanceName, String(state)] }]
|
||||
});
|
||||
});
|
||||
return { status: CustomCommandStatus.Success };
|
||||
} catch (err) {
|
||||
return commandError(source, err);
|
||||
}
|
||||
const instance = structureCollection.get(instanceName);
|
||||
if (state)
|
||||
instance.setVerifierEnabled(true);
|
||||
else
|
||||
instance.setVerifierEnabled(false);
|
||||
this.sendFeedback(source, instanceName, state);
|
||||
return { status: CustomCommandStatus.Success };
|
||||
}
|
||||
|
||||
sendFeedback(source, instanceName, state) {
|
||||
source.sendMessage({ translate: state ? 'construct.commands.verifier.enabled' : 'construct.commands.verifier.disabled', with: [instanceName] });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user