diff --git a/Construct[BP]/scripts/classes/Instance/InstanceForm.js b/Construct[BP]/scripts/classes/Instance/InstanceForm.js index 03a8597..e55d7b4 100644 --- a/Construct[BP]/scripts/classes/Instance/InstanceForm.js +++ b/Construct[BP]/scripts/classes/Instance/InstanceForm.js @@ -136,7 +136,15 @@ export class InstanceForm { } async statisticsForm() { - const statsForm = await InstanceFormBuilder.buildStatistics(this.instance) + let statsForm; + try { + statsForm = await InstanceFormBuilder.buildStatistics(this.instance); + } catch (e) { + if (e.message === 'StructureVerifier is already running.') { + this.player.sendMessage('§cA verification is already in progress. Please wait until it finishes.'); + return; + } + } statsForm.form.show(this.player).then((response) => { if (response.canceled && response.cancelationReason === FormCancelationReason.UserBusy) this.player.sendMessage(statsForm.stats); diff --git a/Construct[BP]/scripts/classes/Instance/InstanceFormBuilder.js b/Construct[BP]/scripts/classes/Instance/InstanceFormBuilder.js index 4ff722e..7659577 100644 --- a/Construct[BP]/scripts/classes/Instance/InstanceFormBuilder.js +++ b/Construct[BP]/scripts/classes/Instance/InstanceFormBuilder.js @@ -5,6 +5,8 @@ import { StructureStatistics } from '../Structure/StructureStatistics'; import { TicksPerSecond } from '@minecraft/server'; export class InstanceFormBuilder { + static structureVerifier; + static buildInstance(instance, options) { const location = instance.getLocation(); const form = new ActionFormData() @@ -29,9 +31,12 @@ export class InstanceFormBuilder { static async buildStatistics(instance) { const buildStatisticsForm = new ActionFormData() .title(MenuFormBuilder.menuTitle) - const structureVerifier = new StructureVerifier(instance, { isEnabled: true, trackPlayerDistance: 0, intervalOrLifetime: 30 * TicksPerSecond, isStandalone: true }); - const verification = await structureVerifier.verifyStructure(); + if (this.structureVerifier) + throw new Error('StructureVerifier is already running.'); + this.structureVerifier = new StructureVerifier(instance, { isEnabled: true, trackPlayerDistance: 0, intervalOrLifetime: 30 * TicksPerSecond, isStandalone: true }); + const verification = await this.structureVerifier.verifyStructure(); const statistics = new StructureStatistics(instance, verification); + this.structureVerifier = void 0; const statsMessage = statistics.getMessage(); buildStatisticsForm.body(statsMessage); return { form: buildStatisticsForm, stats: statsMessage }; @@ -41,7 +46,7 @@ export class InstanceFormBuilder { return new ModalFormData() .title(MenuFormBuilder.menuTitle) .toggle('Block Validation', { defaultValue: instance.options.verifier.isEnabled, tooltip: 'Shows missing and incorrect block overlay.' }) - .toggle('Distance-Based Block Validation', { defaultValue: instance.verifier.getTrackPlayerDistance() !== 0, tooltip: 'If enabled, the verifier will only check blocks within a certain distance from the player.' }) + .toggle('Distance-Based Block Validation', { defaultValue: instance.verifier.getTrackPlayerDistance() !== 0, tooltip: `If enabled, the verifier will only check within ${instance.verifier.getTrackPlayerDistance()} blocks of the player. This should stay enabled unless your structure is very small.` }) .label('Use the slider to select the layer. Use 0 for all layers.') .slider("Layer", 0, instance.getMaxLayer(), { defaultValue: instance.getLayer(), valueStep: 1 }) .submitButton('§2Apply'); diff --git a/Construct[BP]/scripts/classes/Instance/StructureInstance.js b/Construct[BP]/scripts/classes/Instance/StructureInstance.js index c5fd573..8d62d4b 100644 --- a/Construct[BP]/scripts/classes/Instance/StructureInstance.js +++ b/Construct[BP]/scripts/classes/Instance/StructureInstance.js @@ -149,7 +149,7 @@ export class StructureInstance { } hasLocation() { - return this.options.dimensionId && this.options.worldLocation.x !== 0 && this.options.worldLocation.y !== 0 && this.options.worldLocation.z !== 0; + return this.options.dimensionId && (this.options.worldLocation.x !== 0 || this.options.worldLocation.y !== 0 || this.options.worldLocation.z !== 0); } hasLayers() { diff --git a/Construct[BP]/scripts/classes/MenuForm.js b/Construct[BP]/scripts/classes/MenuForm.js index 161807e..554c71c 100644 --- a/Construct[BP]/scripts/classes/MenuForm.js +++ b/Construct[BP]/scripts/classes/MenuForm.js @@ -91,7 +91,7 @@ export class MenuForm { const structureId = response.formValues[0]; if (structureId === '') return void 0; - if (!structureCollection.getWorldStructureIds().includes(structureId)) { + if (!structureCollection.getWorldStructureIds().some(id => id.replace('mystructure:', '') === structureId)) { this.player.sendMessage(`§cStructure ID '${structureId}' not found. If you're looking for a structure that you put in the structures folder, please restart your world and try again.`); return void 0; }