refactor: rename source -> origin in all commands

This commit is contained in:
ForestOfLight
2026-05-29 23:26:49 +02:00
Unverified
parent e0e12f5dd0
commit f750710732
17 changed files with 76 additions and 76 deletions
+5 -5
View File
@@ -17,19 +17,19 @@ export class BuilderCommand extends Command {
{ name: 'builderOption', values: ['easyPlace', 'fastEasyPlace', 'materialGrabber'] } { name: 'builderOption', values: ['easyPlace', 'fastEasyPlace', 'materialGrabber'] }
], ],
permissionLevel: CommandPermissionLevel.Any, permissionLevel: CommandPermissionLevel.Any,
callback: (source, builderOption, state) => this.run(source, builderOption, state) callback: (origin, builderOption, state) => this.run(origin, builderOption, state)
}); });
} }
run(source, builderOption, state) { run(origin, builderOption, state) {
if (!BuilderOptions.get(builderOption)) { if (!BuilderOptions.get(builderOption)) {
source.sendMessage({ translate: 'construct.commands.builder.unknownOption', with: [builderOption] }); origin.sendMessage({ translate: 'construct.commands.builder.unknownOption', with: [builderOption] });
return void 0; return void 0;
} }
system.run(() => { system.run(() => {
const player = source.getSource(); const player = origin.getSource();
BuilderOptions.setValue(builderOption, player.id, state); BuilderOptions.setValue(builderOption, player.id, state);
source.sendMessage({ translate: 'construct.commands.builder.success', with: [builderOption, String(state)] }); origin.sendMessage({ translate: 'construct.commands.builder.success', with: [builderOption, String(state)] });
}); });
return { status: CustomCommandStatus.Success }; return { status: CustomCommandStatus.Success };
} }
@@ -11,12 +11,12 @@ export class ConstructCommand extends Command {
cheatsRequired: false, cheatsRequired: false,
allowedSources: [PlayerCommandOrigin], allowedSources: [PlayerCommandOrigin],
permissionLevel: CommandPermissionLevel.Any, permissionLevel: CommandPermissionLevel.Any,
callback: (source) => this.run(source) callback: (origin) => this.run(origin)
}); });
} }
run(source) { run(origin) {
const player = source.getSource(); const player = origin.getSource();
system.run(() => { system.run(() => {
this.giveMenuItem(player); this.giveMenuItem(player);
}); });
+10 -10
View File
@@ -14,33 +14,33 @@ export class CreateCommand extends Command {
{ name: 'structureId', type: CustomCommandParamType.String } { name: 'structureId', type: CustomCommandParamType.String }
], ],
permissionLevel: CommandPermissionLevel.Any, permissionLevel: CommandPermissionLevel.Any,
callback: (source, instanceName, structureId) => this.run(source, instanceName, structureId) callback: (origin, instanceName, structureId) => this.run(origin, instanceName, structureId)
}); });
} }
run(source, instanceName, structureId) { run(origin, instanceName, structureId) {
this.tryAddStructure(source, instanceName, structureId); this.tryAddStructure(origin, instanceName, structureId);
return { status: CustomCommandStatus.Success }; return { status: CustomCommandStatus.Success };
} }
tryAddStructure(source, instanceName, structureId) { tryAddStructure(origin, instanceName, structureId) {
system.run(() => { system.run(() => {
try { try {
this.addStructure(source, instanceName, structureId); this.addStructure(origin, instanceName, structureId);
} catch (error) { } catch (error) {
this.handleStructureAdditionErrors(source, error); this.handleStructureAdditionErrors(origin, error);
} }
}); });
} }
addStructure(source, instanceName, structureId) { addStructure(origin, instanceName, structureId) {
structureCollection.add(instanceName, structureId); structureCollection.add(instanceName, structureId);
source.sendMessage({ translate: 'construct.commands.create.success', with: [instanceName, structureId] }); origin.sendMessage({ translate: 'construct.commands.create.success', with: [instanceName, structureId] });
} }
handleStructureAdditionErrors(source, error) { handleStructureAdditionErrors(origin, error) {
if (error instanceof InstanceExistsError || error instanceof StructureNotFoundError) if (error instanceof InstanceExistsError || error instanceof StructureNotFoundError)
error.sendTo(source); error.sendTo(origin);
else else
throw error; throw error;
} }
+3 -3
View File
@@ -11,15 +11,15 @@ export class DeleteCommand extends Command {
{ name: 'instanceName', type: CustomCommandParamType.String } { name: 'instanceName', type: CustomCommandParamType.String }
], ],
permissionLevel: CommandPermissionLevel.Any, permissionLevel: CommandPermissionLevel.Any,
callback: (source, instanceName) => this.run(source, instanceName) callback: (origin, instanceName) => this.run(origin, instanceName)
}); });
} }
run(source, instanceName) { run(origin, instanceName) {
const instance = structureCollection.get(instanceName); const instance = structureCollection.get(instanceName);
system.run(() => { system.run(() => {
structureCollection.delete(instanceName); structureCollection.delete(instanceName);
source.sendMessage({ translate: 'construct.commands.delete.success', with: [instanceName] }); origin.sendMessage({ translate: 'construct.commands.delete.success', with: [instanceName] });
}); });
return { status: CustomCommandStatus.Success }; return { status: CustomCommandStatus.Success };
} }
+6 -6
View File
@@ -12,14 +12,14 @@ export class EnableCommand extends Command {
{ name: 'state', type: CustomCommandParamType.Boolean } { name: 'state', type: CustomCommandParamType.Boolean }
], ],
permissionLevel: CommandPermissionLevel.Any, permissionLevel: CommandPermissionLevel.Any,
callback: (source, instanceName, state) => this.run(source, instanceName, state) callback: (origin, instanceName, state) => this.run(origin, instanceName, state)
}); });
} }
run(source, instanceName, state) { run(origin, instanceName, state) {
const instance = structureCollection.get(instanceName); const instance = structureCollection.get(instanceName);
if (state && !instance.hasLocation()) { if (state && !instance.hasLocation()) {
source.sendMessage({ translate: 'construct.commands.error.noLocation', with: [instanceName] }); origin.sendMessage({ translate: 'construct.commands.error.noLocation', with: [instanceName] });
return void 0; return void 0;
} }
system.run(() => { system.run(() => {
@@ -27,13 +27,13 @@ export class EnableCommand extends Command {
instance.enable(); instance.enable();
else else
instance.disable(); instance.disable();
this.sendFeedback(source, instanceName, state); this.sendFeedback(origin, instanceName, state);
}); });
return { status: CustomCommandStatus.Success }; return { status: CustomCommandStatus.Success };
} }
sendFeedback(source, instanceName, state) { sendFeedback(origin, instanceName, state) {
source.sendMessage({ translate: state ? 'construct.commands.enable.true' : 'construct.commands.enable.false', with: [instanceName] }); origin.sendMessage({ translate: state ? 'construct.commands.enable.true' : 'construct.commands.enable.false', with: [instanceName] });
} }
} }
@@ -12,11 +12,11 @@ export class InstanceInfoCommand extends Command {
{ name: 'instanceName', type: CustomCommandParamType.String } { name: 'instanceName', type: CustomCommandParamType.String }
], ],
permissionLevel: CommandPermissionLevel.Any, permissionLevel: CommandPermissionLevel.Any,
callback: (source, instanceName) => this.run(source, instanceName) callback: (origin, instanceName) => this.run(origin, instanceName)
}); });
} }
run(source, instanceName) { run(origin, instanceName) {
const instance = structureCollection.get(instanceName); const instance = structureCollection.get(instanceName);
const message = { rawtext: [ const message = { rawtext: [
this.getHeaderText(instance), this.getHeaderText(instance),
@@ -33,7 +33,7 @@ export class InstanceInfoCommand extends Command {
{ text: '\n' }, { text: '\n' },
this.getSizeText(instance) this.getSizeText(instance)
]}; ]};
source.sendMessage(message); origin.sendMessage(message);
return { status: CustomCommandStatus.Success }; return { status: CustomCommandStatus.Success };
} }
@@ -8,11 +8,11 @@ export class InstancesCommand extends Command {
name: 'instances', name: 'instances',
description: 'construct.commands.instances', description: 'construct.commands.instances',
permissionLevel: CommandPermissionLevel.Any, permissionLevel: CommandPermissionLevel.Any,
callback: (source) => this.run(source) callback: (origin) => this.run(origin)
}); });
} }
run(source) { run(origin) {
const names = structureCollection.getInstanceNames(); const names = structureCollection.getInstanceNames();
if (names.length === 0) if (names.length === 0)
return { status: CustomCommandStatus.Success, message: 'construct.commands.instances.empty' }; return { status: CustomCommandStatus.Success, message: 'construct.commands.instances.empty' };
@@ -29,7 +29,7 @@ export class InstancesCommand extends Command {
}); });
rawtext.push({ text: '\n' }); rawtext.push({ text: '\n' });
} }
source.sendMessage({ rawtext }); origin.sendMessage({ rawtext });
return { status: CustomCommandStatus.Success }; return { status: CustomCommandStatus.Success };
} }
+4 -4
View File
@@ -12,19 +12,19 @@ export class LayerCommand extends Command {
{ name: 'layer', type: CustomCommandParamType.Integer } { name: 'layer', type: CustomCommandParamType.Integer }
], ],
permissionLevel: CommandPermissionLevel.Any, permissionLevel: CommandPermissionLevel.Any,
callback: (source, instanceName, layer) => this.run(source, instanceName, layer) callback: (origin, instanceName, layer) => this.run(origin, instanceName, layer)
}); });
} }
run(source, instanceName, layer) { run(origin, instanceName, layer) {
const instance = structureCollection.get(instanceName); const instance = structureCollection.get(instanceName);
const max = instance.getMaxLayer(); const max = instance.getMaxLayer();
if (layer < 0 || layer > max) { if (layer < 0 || layer > max) {
source.sendMessage({ translate: 'construct.commands.layer.outOfBounds', with: [String(layer), instanceName, String(max)] }); origin.sendMessage({ translate: 'construct.commands.layer.outOfBounds', with: [String(layer), instanceName, String(max)] });
return void 0; return void 0;
} }
instance.setLayer(layer); instance.setLayer(layer);
source.sendMessage({ translate: 'construct.commands.layer.success', with: [instanceName, String(layer)] }); origin.sendMessage({ translate: 'construct.commands.layer.success', with: [instanceName, String(layer)] });
return { status: CustomCommandStatus.Success }; return { status: CustomCommandStatus.Success };
} }
} }
@@ -16,39 +16,39 @@ export class MaterialsCommand extends Command {
{ name: 'missing', type: CustomCommandParamType.Boolean } { name: 'missing', type: CustomCommandParamType.Boolean }
], ],
permissionLevel: CommandPermissionLevel.Any, permissionLevel: CommandPermissionLevel.Any,
callback: (source, instanceName, missing) => this.run(source, instanceName, missing) callback: (origin, instanceName, missing) => this.run(origin, instanceName, missing)
}); });
} }
run(source, instanceName, missing) { run(origin, instanceName, missing) {
const instance = structureCollection.get(instanceName); const instance = structureCollection.get(instanceName);
const onlyMissing = missing === true; const onlyMissing = missing === true;
if (onlyMissing) if (onlyMissing)
this.assertIsPlayer(source); this.assertIsPlayer(origin);
const headerKey = onlyMissing ? 'construct.commands.materials.headerMissing' : 'construct.commands.materials.headerAll'; const headerKey = onlyMissing ? 'construct.commands.materials.headerMissing' : 'construct.commands.materials.headerAll';
const rawtext = [ const rawtext = [
{ translate: headerKey, with: [instanceName] }, { translate: headerKey, with: [instanceName] },
{ text: '\n' } { text: '\n' }
]; ];
const list = this.getMaterialList(source, instance, onlyMissing); const list = this.getMaterialList(origin, instance, onlyMissing);
if (!list.rawtext || list.rawtext.length === 0) if (!list.rawtext || list.rawtext.length === 0)
rawtext.push({ translate: 'construct.commands.materials.empty' }); rawtext.push({ translate: 'construct.commands.materials.empty' });
else else
rawtext.push(list); rawtext.push(list);
source.sendMessage({ rawtext }); origin.sendMessage({ rawtext });
return { status: CustomCommandStatus.Success }; return { status: CustomCommandStatus.Success };
} }
assertIsPlayer(source) { assertIsPlayer(origin) {
if (!(source instanceof PlayerCommandOrigin)) if (!(origin instanceof PlayerCommandOrigin))
throw new NotAPlayerError(); throw new NotAPlayerError();
} }
getMaterialList(source, instance, onlyMissing) { getMaterialList(origin, instance, onlyMissing) {
const materials = instance.getActiveMaterials(); const materials = instance.getActiveMaterials();
let container; let container;
if (onlyMissing) { if (onlyMissing) {
const player = source.getSource(); const player = origin.getSource();
const inventoryComponent = player?.getComponent(EntityComponentTypes.Inventory); const inventoryComponent = player?.getComponent(EntityComponentTypes.Inventory);
container = inventoryComponent?.container; container = inventoryComponent?.container;
} }
+5 -5
View File
@@ -17,16 +17,16 @@ export class MoveCommand extends Command {
{ name: 'location', type: CustomCommandParamType.Location } { name: 'location', type: CustomCommandParamType.Location }
], ],
permissionLevel: CommandPermissionLevel.Any, permissionLevel: CommandPermissionLevel.Any,
callback: (source, instanceName, dimensionId, location) => this.run(source, instanceName, dimensionId, location) callback: (origin, instanceName, dimensionId, location) => this.run(origin, instanceName, dimensionId, location)
}); });
} }
run(source, instanceName, dimensionId, location) { run(origin, instanceName, dimensionId, location) {
const instance = structureCollection.get(instanceName); const instance = structureCollection.get(instanceName);
if (dimensionId === void 0 || location === void 0) { if (dimensionId === void 0 || location === void 0) {
if (!(source instanceof PlayerCommandOrigin)) if (!(origin instanceof PlayerCommandOrigin))
return { status: CustomCommandStatus.Failure, message: 'construct.commands.move.locationRequired' }; return { status: CustomCommandStatus.Failure, message: 'construct.commands.move.locationRequired' };
const player = source.getSource(); const player = origin.getSource();
location = player.location; location = player.location;
dimensionId = player.dimension.id; dimensionId = player.dimension.id;
} }
@@ -34,7 +34,7 @@ export class MoveCommand extends Command {
const flooredLocation = Vector.from(location).floor(); const flooredLocation = Vector.from(location).floor();
system.run(() => { system.run(() => {
instance.move(dimensionId, flooredLocation); instance.move(dimensionId, flooredLocation);
source.sendMessage({ translate: 'construct.commands.move.success', with: [instanceName, flooredLocation.toString(), dimensionId.replace('minecraft:', '')] }); origin.sendMessage({ translate: 'construct.commands.move.success', with: [instanceName, flooredLocation.toString(), dimensionId.replace('minecraft:', '')] });
}); });
return { status: CustomCommandStatus.Success }; return { status: CustomCommandStatus.Success };
} }
@@ -11,14 +11,14 @@ export class NextLayerCommand extends Command {
{ name: 'instanceName', type: CustomCommandParamType.String } { name: 'instanceName', type: CustomCommandParamType.String }
], ],
permissionLevel: CommandPermissionLevel.Any, permissionLevel: CommandPermissionLevel.Any,
callback: (source, instanceName) => this.run(source, instanceName) callback: (origin, instanceName) => this.run(origin, instanceName)
}); });
} }
run(source, instanceName) { run(origin, instanceName) {
const instance = structureCollection.get(instanceName); const instance = structureCollection.get(instanceName);
instance.increaseLayer(); instance.increaseLayer();
source.sendMessage({ translate: 'construct.commands.nextlayer.success', with: [instanceName, String(instance.getLayer())] }); origin.sendMessage({ translate: 'construct.commands.nextlayer.success', with: [instanceName, String(instance.getLayer())] });
return { status: CustomCommandStatus.Success }; return { status: CustomCommandStatus.Success };
} }
} }
+3 -3
View File
@@ -16,17 +16,17 @@ export class PlaceCommand extends Command {
{ name: 'location', type: CustomCommandParamType.Location } { name: 'location', type: CustomCommandParamType.Location }
], ],
permissionLevel: CommandPermissionLevel.Any, permissionLevel: CommandPermissionLevel.Any,
callback: (source, instanceName, dimensionId, location) => this.run(source, instanceName, dimensionId, location) callback: (origin, instanceName, dimensionId, location) => this.run(origin, instanceName, dimensionId, location)
}); });
} }
run(source, instanceName, dimensionId, location) { run(origin, instanceName, dimensionId, location) {
const instance = structureCollection.get(instanceName); const instance = structureCollection.get(instanceName);
const flooredLocation = Vector.from(location).floor(); const flooredLocation = Vector.from(location).floor();
this.assertDimensionExists(dimensionId); this.assertDimensionExists(dimensionId);
system.run(() => { system.run(() => {
instance.place(dimensionId, flooredLocation); instance.place(dimensionId, flooredLocation);
source.sendMessage({ translate: 'construct.commands.place.success', with: [instanceName, flooredLocation.toString(), dimensionId.replace('minecraft:', '')] }); origin.sendMessage({ translate: 'construct.commands.place.success', with: [instanceName, flooredLocation.toString(), dimensionId.replace('minecraft:', '')] });
}); });
return { status: CustomCommandStatus.Success }; return { status: CustomCommandStatus.Success };
} }
@@ -11,14 +11,14 @@ export class PrevLayerCommand extends Command {
{ name: 'instanceName', type: CustomCommandParamType.String } { name: 'instanceName', type: CustomCommandParamType.String }
], ],
permissionLevel: CommandPermissionLevel.Any, permissionLevel: CommandPermissionLevel.Any,
callback: (source, instanceName) => this.run(source, instanceName) callback: (origin, instanceName) => this.run(origin, instanceName)
}); });
} }
run(source, instanceName) { run(origin, instanceName) {
const instance = structureCollection.get(instanceName); const instance = structureCollection.get(instanceName);
instance.decreaseLayer(); instance.decreaseLayer();
source.sendMessage({ translate: 'construct.commands.prevlayer.success', with: [instanceName, String(instance.getLayer())] }); origin.sendMessage({ translate: 'construct.commands.prevlayer.success', with: [instanceName, String(instance.getLayer())] });
return { status: CustomCommandStatus.Success }; return { status: CustomCommandStatus.Success };
} }
} }
+4 -4
View File
@@ -12,18 +12,18 @@ export class RenameCommand extends Command {
{ name: 'newName', type: CustomCommandParamType.String } { name: 'newName', type: CustomCommandParamType.String }
], ],
permissionLevel: CommandPermissionLevel.Any, permissionLevel: CommandPermissionLevel.Any,
callback: (source, instanceName, newName) => this.run(source, instanceName, newName) callback: (origin, instanceName, newName) => this.run(origin, instanceName, newName)
}); });
} }
run(source, instanceName, newName) { run(origin, instanceName, newName) {
const instance = structureCollection.get(instanceName); const instance = structureCollection.get(instanceName);
if (structureCollection.has(newName)) { if (structureCollection.has(newName)) {
source.sendMessage({ translate: 'construct.error.instanceExists', with: [newName] }); origin.sendMessage({ translate: 'construct.error.instanceExists', with: [newName] });
return void 0; return void 0;
} }
structureCollection.rename(instanceName, newName); structureCollection.rename(instanceName, newName);
source.sendMessage({ translate: 'construct.commands.rename.success', with: [instanceName, newName] }); origin.sendMessage({ translate: 'construct.commands.rename.success', with: [instanceName, newName] });
return { status: CustomCommandStatus.Success }; return { status: CustomCommandStatus.Success };
} }
} }
+3 -3
View File
@@ -14,16 +14,16 @@ export class StatsCommand extends Command {
{ name: 'instanceName', type: CustomCommandParamType.String } { name: 'instanceName', type: CustomCommandParamType.String }
], ],
permissionLevel: CommandPermissionLevel.Any, permissionLevel: CommandPermissionLevel.Any,
callback: (source, instanceName) => this.run(source, instanceName) callback: (origin, instanceName) => this.run(origin, instanceName)
}); });
} }
run(source, instanceName) { run(origin, instanceName) {
const instance = structureCollection.get(instanceName); const instance = structureCollection.get(instanceName);
if (this.structureVerifier) if (this.structureVerifier)
return { status: CustomCommandStatus.Failure, error: 'construct.commands.stats.alreadyRunning' }; return { status: CustomCommandStatus.Failure, error: 'construct.commands.stats.alreadyRunning' };
system.run(async () => { system.run(async () => {
source.sendMessage(await this.getStatsMessage(instance)); origin.sendMessage(await this.getStatsMessage(instance));
}); });
return { status: CustomCommandStatus.Success }; return { status: CustomCommandStatus.Success };
} }
+4 -4
View File
@@ -14,13 +14,13 @@ export class TagCommand extends Command {
{ name: 'instanceName', type: CustomCommandParamType.String } { name: 'instanceName', type: CustomCommandParamType.String }
], ],
permissionLevel: CommandPermissionLevel.Any, permissionLevel: CommandPermissionLevel.Any,
callback: (source, instanceName) => this.run(source, instanceName) callback: (origin, instanceName) => this.run(origin, instanceName)
}); });
} }
run(source, instanceName) { run(origin, instanceName) {
const instance = structureCollection.get(instanceName); const instance = structureCollection.get(instanceName);
const player = source.getSource(); const player = origin.getSource();
const equipment = player.getComponent(EntityComponentTypes.Equippable); const equipment = player.getComponent(EntityComponentTypes.Equippable);
const itemStack = equipment?.getEquipment(EquipmentSlot.Mainhand); const itemStack = equipment?.getEquipment(EquipmentSlot.Mainhand);
if (itemStack?.typeId !== MENU_ITEM) if (itemStack?.typeId !== MENU_ITEM)
@@ -28,7 +28,7 @@ export class TagCommand extends Command {
system.run(() => { system.run(() => {
itemStack.nameTag = instanceName; itemStack.nameTag = instanceName;
equipment.setEquipment(EquipmentSlot.Mainhand, itemStack); equipment.setEquipment(EquipmentSlot.Mainhand, itemStack);
source.sendMessage({ translate: 'construct.commands.tag.success', with: [instanceName] }); origin.sendMessage({ translate: 'construct.commands.tag.success', with: [instanceName] });
}); });
return { status: CustomCommandStatus.Success }; return { status: CustomCommandStatus.Success };
} }
+5 -5
View File
@@ -12,22 +12,22 @@ export class VerifierCommand extends Command {
{ name: 'state', type: CustomCommandParamType.Boolean } { name: 'state', type: CustomCommandParamType.Boolean }
], ],
permissionLevel: CommandPermissionLevel.Any, permissionLevel: CommandPermissionLevel.Any,
callback: (source, instanceName, state) => this.run(source, instanceName, state) callback: (origin, instanceName, state) => this.run(origin, instanceName, state)
}); });
} }
run(source, instanceName, state) { run(origin, instanceName, state) {
const instance = structureCollection.get(instanceName); const instance = structureCollection.get(instanceName);
if (state) if (state)
instance.setVerifierEnabled(true); instance.setVerifierEnabled(true);
else else
instance.setVerifierEnabled(false); instance.setVerifierEnabled(false);
this.sendFeedback(source, instanceName, state); this.sendFeedback(origin, instanceName, state);
return { status: CustomCommandStatus.Success }; return { status: CustomCommandStatus.Success };
} }
sendFeedback(source, instanceName, state) { sendFeedback(origin, instanceName, state) {
source.sendMessage({ translate: state ? 'construct.commands.verifier.enabled' : 'construct.commands.verifier.disabled', with: [instanceName] }); origin.sendMessage({ translate: state ? 'construct.commands.verifier.enabled' : 'construct.commands.verifier.disabled', with: [instanceName] });
} }
} }