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
+30 -32
View File
@@ -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;
}
}