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'] }
],
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)) {
source.sendMessage({ translate: 'construct.commands.builder.unknownOption', with: [builderOption] });
origin.sendMessage({ translate: 'construct.commands.builder.unknownOption', with: [builderOption] });
return void 0;
}
system.run(() => {
const player = source.getSource();
const player = origin.getSource();
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 };
}
@@ -11,12 +11,12 @@ export class ConstructCommand extends Command {
cheatsRequired: false,
allowedSources: [PlayerCommandOrigin],
permissionLevel: CommandPermissionLevel.Any,
callback: (source) => this.run(source)
callback: (origin) => this.run(origin)
});
}
run(source) {
const player = source.getSource();
run(origin) {
const player = origin.getSource();
system.run(() => {
this.giveMenuItem(player);
});
+10 -10
View File
@@ -14,33 +14,33 @@ export class CreateCommand extends Command {
{ name: 'structureId', type: CustomCommandParamType.String }
],
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) {
this.tryAddStructure(source, instanceName, structureId);
run(origin, instanceName, structureId) {
this.tryAddStructure(origin, instanceName, structureId);
return { status: CustomCommandStatus.Success };
}
tryAddStructure(source, instanceName, structureId) {
tryAddStructure(origin, instanceName, structureId) {
system.run(() => {
try {
this.addStructure(source, instanceName, structureId);
this.addStructure(origin, instanceName, structureId);
} catch (error) {
this.handleStructureAdditionErrors(source, error);
this.handleStructureAdditionErrors(origin, error);
}
});
}
addStructure(source, instanceName, structureId) {
addStructure(origin, 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)
error.sendTo(source);
error.sendTo(origin);
else
throw error;
}
+3 -3
View File
@@ -11,15 +11,15 @@ export class DeleteCommand extends Command {
{ name: 'instanceName', type: CustomCommandParamType.String }
],
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);
system.run(() => {
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 };
}
+6 -6
View File
@@ -12,14 +12,14 @@ export class EnableCommand extends Command {
{ name: 'state', type: CustomCommandParamType.Boolean }
],
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);
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;
}
system.run(() => {
@@ -27,13 +27,13 @@ export class EnableCommand extends Command {
instance.enable();
else
instance.disable();
this.sendFeedback(source, instanceName, state);
this.sendFeedback(origin, instanceName, state);
});
return { status: CustomCommandStatus.Success };
}
sendFeedback(source, instanceName, state) {
source.sendMessage({ translate: state ? 'construct.commands.enable.true' : 'construct.commands.enable.false', with: [instanceName] });
sendFeedback(origin, instanceName, state) {
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 }
],
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 message = { rawtext: [
this.getHeaderText(instance),
@@ -33,7 +33,7 @@ export class InstanceInfoCommand extends Command {
{ text: '\n' },
this.getSizeText(instance)
]};
source.sendMessage(message);
origin.sendMessage(message);
return { status: CustomCommandStatus.Success };
}
@@ -8,11 +8,11 @@ export class InstancesCommand extends Command {
name: 'instances',
description: 'construct.commands.instances',
permissionLevel: CommandPermissionLevel.Any,
callback: (source) => this.run(source)
callback: (origin) => this.run(origin)
});
}
run(source) {
run(origin) {
const names = structureCollection.getInstanceNames();
if (names.length === 0)
return { status: CustomCommandStatus.Success, message: 'construct.commands.instances.empty' };
@@ -29,7 +29,7 @@ export class InstancesCommand extends Command {
});
rawtext.push({ text: '\n' });
}
source.sendMessage({ rawtext });
origin.sendMessage({ rawtext });
return { status: CustomCommandStatus.Success };
}
+4 -4
View File
@@ -12,19 +12,19 @@ export class LayerCommand extends Command {
{ name: 'layer', type: CustomCommandParamType.Integer }
],
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 max = instance.getMaxLayer();
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;
}
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 };
}
}
@@ -16,39 +16,39 @@ export class MaterialsCommand extends Command {
{ name: 'missing', type: CustomCommandParamType.Boolean }
],
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 onlyMissing = missing === true;
if (onlyMissing)
this.assertIsPlayer(source);
this.assertIsPlayer(origin);
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);
const list = this.getMaterialList(origin, instance, onlyMissing);
if (!list.rawtext || list.rawtext.length === 0)
rawtext.push({ translate: 'construct.commands.materials.empty' });
else
rawtext.push(list);
source.sendMessage({ rawtext });
origin.sendMessage({ rawtext });
return { status: CustomCommandStatus.Success };
}
assertIsPlayer(source) {
if (!(source instanceof PlayerCommandOrigin))
assertIsPlayer(origin) {
if (!(origin instanceof PlayerCommandOrigin))
throw new NotAPlayerError();
}
getMaterialList(source, instance, onlyMissing) {
getMaterialList(origin, instance, onlyMissing) {
const materials = instance.getActiveMaterials();
let container;
if (onlyMissing) {
const player = source.getSource();
const player = origin.getSource();
const inventoryComponent = player?.getComponent(EntityComponentTypes.Inventory);
container = inventoryComponent?.container;
}
+5 -5
View File
@@ -17,16 +17,16 @@ export class MoveCommand extends Command {
{ name: 'location', type: CustomCommandParamType.Location }
],
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);
if (dimensionId === void 0 || location === void 0) {
if (!(source instanceof PlayerCommandOrigin))
if (!(origin instanceof PlayerCommandOrigin))
return { status: CustomCommandStatus.Failure, message: 'construct.commands.move.locationRequired' };
const player = source.getSource();
const player = origin.getSource();
location = player.location;
dimensionId = player.dimension.id;
}
@@ -34,7 +34,7 @@ export class MoveCommand extends Command {
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:', '')] });
origin.sendMessage({ translate: 'construct.commands.move.success', with: [instanceName, flooredLocation.toString(), dimensionId.replace('minecraft:', '')] });
});
return { status: CustomCommandStatus.Success };
}
@@ -11,14 +11,14 @@ export class NextLayerCommand extends Command {
{ name: 'instanceName', type: CustomCommandParamType.String }
],
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);
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 };
}
}
+3 -3
View File
@@ -16,17 +16,17 @@ export class PlaceCommand extends Command {
{ name: 'location', type: CustomCommandParamType.Location }
],
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 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:', '')] });
origin.sendMessage({ translate: 'construct.commands.place.success', with: [instanceName, flooredLocation.toString(), dimensionId.replace('minecraft:', '')] });
});
return { status: CustomCommandStatus.Success };
}
@@ -11,14 +11,14 @@ export class PrevLayerCommand extends Command {
{ name: 'instanceName', type: CustomCommandParamType.String }
],
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);
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 };
}
}
+4 -4
View File
@@ -12,18 +12,18 @@ export class RenameCommand extends Command {
{ name: 'newName', type: CustomCommandParamType.String }
],
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);
if (structureCollection.has(newName)) {
source.sendMessage({ translate: 'construct.error.instanceExists', with: [newName] });
origin.sendMessage({ translate: 'construct.error.instanceExists', with: [newName] });
return void 0;
}
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 };
}
}
+3 -3
View File
@@ -14,16 +14,16 @@ export class StatsCommand extends Command {
{ name: 'instanceName', type: CustomCommandParamType.String }
],
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);
if (this.structureVerifier)
return { status: CustomCommandStatus.Failure, error: 'construct.commands.stats.alreadyRunning' };
system.run(async () => {
source.sendMessage(await this.getStatsMessage(instance));
origin.sendMessage(await this.getStatsMessage(instance));
});
return { status: CustomCommandStatus.Success };
}
+4 -4
View File
@@ -14,13 +14,13 @@ export class TagCommand extends Command {
{ name: 'instanceName', type: CustomCommandParamType.String }
],
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 player = source.getSource();
const player = origin.getSource();
const equipment = player.getComponent(EntityComponentTypes.Equippable);
const itemStack = equipment?.getEquipment(EquipmentSlot.Mainhand);
if (itemStack?.typeId !== MENU_ITEM)
@@ -28,7 +28,7 @@ export class TagCommand extends Command {
system.run(() => {
itemStack.nameTag = instanceName;
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 };
}
+5 -5
View File
@@ -12,22 +12,22 @@ export class VerifierCommand extends Command {
{ name: 'state', type: CustomCommandParamType.Boolean }
],
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);
if (state)
instance.setVerifierEnabled(true);
else
instance.setVerifierEnabled(false);
this.sendFeedback(source, instanceName, state);
this.sendFeedback(origin, instanceName, state);
return { status: CustomCommandStatus.Success };
}
sendFeedback(source, instanceName, state) {
source.sendMessage({ translate: state ? 'construct.commands.verifier.enabled' : 'construct.commands.verifier.disabled', with: [instanceName] });
sendFeedback(origin, instanceName, state) {
origin.sendMessage({ translate: state ? 'construct.commands.verifier.enabled' : 'construct.commands.verifier.disabled', with: [instanceName] });
}
}