Skip to content

Commit 880a0da

Browse files
authored
Merge pull request #1049 from SjnExe/fix-commands-and-ui-14846249216144152681
Fix commands and UI 14846249216144152681
2 parents 49375c0 + b94f01f commit 880a0da

11 files changed

Lines changed: 62 additions & 221 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
/staging/
1616
/packs/behavior/pack_icon.png
1717
/packs/resource/pack_icon.png
18+
/out
1819

1920
# misc
2021
.DS_Store

eslint.config.js

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import importPlugin from 'eslint-plugin-import';
66
import jsonc from 'eslint-plugin-jsonc';
77
import minecraftLinting from 'eslint-plugin-minecraft-linting';
88
import promisePlugin from 'eslint-plugin-promise';
9-
import sonarjs from 'eslint-plugin-sonarjs';
109
import eslintPluginUnicorn from 'eslint-plugin-unicorn';
1110
import unusedImports from 'eslint-plugin-unused-imports';
1211
import globals from 'globals';
@@ -37,20 +36,6 @@ export default tseslint.config(
3736
// Base JS configuration
3837
eslint.configs.recommended,
3938

40-
// SonarJS Configuration
41-
sonarjs.configs.recommended,
42-
{
43-
rules: {
44-
// Disable rules that conflict with strict TS or are too noisy for this project
45-
'sonarjs/no-duplicate-string': 'off', // Common in Minecraft commands/IDs
46-
'sonarjs/cognitive-complexity': ['warn', 60], // Increased limit for complex UI handlers
47-
'sonarjs/no-nested-template-literals': 'off',
48-
'sonarjs/todo-tag': 'warn',
49-
'sonarjs/fixme-tag': 'warn',
50-
'sonarjs/pseudo-random': 'off' // Safe for Minecraft game mechanics
51-
}
52-
},
53-
5439
// Unicorn Configuration
5540
eslintPluginUnicorn.configs['flat/recommended'],
5641
{
@@ -230,9 +215,7 @@ export default tseslint.config(
230215
...jsonc.configs['flat/recommended-with-jsonc'],
231216
{
232217
files: ['**/*.json'],
233-
rules: {
234-
'sonarjs/no-empty-test-file': 'off'
235-
}
218+
rules: {}
236219
},
237220

238221
// Prettier

package.json

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
"description": "<p align=\"center\"> <!-- TODO: Add a cool project logo/banner here. Example: <img src=\"link_to_your_logo.png\" alt=\"AddonExe Logo\" width=\"200\"/> --> <h1 align=\"center\">AddonExe for Minecraft BE</h1> </p>",
55
"main": "index.js",
66
"scripts": {
7-
"preinstall": "node scripts/update-mc-deps.js",
87
"clean": "rimraf packs/behavior/scripts",
98
"reinstall": "rm -rf node_modules package-lock.json && npm install",
109
"check-types": "tsc --noEmit",
@@ -47,11 +46,11 @@
4746
"@minecraft/common": "latest",
4847
"@minecraft/core-build-tasks": "latest",
4948
"@minecraft/creator-tools": "latest",
50-
"@minecraft/debug-utilities": "1.0.0-beta.1.26.1-stable",
49+
"@minecraft/debug-utilities": "beta",
5150
"@minecraft/math": "latest",
52-
"@minecraft/server": "2.6.0-beta.1.26.1-stable",
53-
"@minecraft/server-gametest": "1.0.0-beta.1.26.1-stable",
54-
"@minecraft/server-ui": "2.1.0-beta.1.26.1-stable",
51+
"@minecraft/server": "beta",
52+
"@minecraft/server-gametest": "beta",
53+
"@minecraft/server-ui": "beta",
5554
"@minecraft/vanilla-data": "latest",
5655
"@types/jest": "latest",
5756
"@types/node": "latest",
@@ -68,7 +67,6 @@
6867
"eslint-plugin-jsonc": "latest",
6968
"eslint-plugin-minecraft-linting": "latest",
7069
"eslint-plugin-promise": "latest",
71-
"eslint-plugin-sonarjs": "^3.0.6",
7270
"eslint-plugin-unicorn": "latest",
7371
"eslint-plugin-unused-imports": "latest",
7472
"glob": "latest",
@@ -78,7 +76,7 @@
7876
"prettier": "latest",
7977
"prettier-plugin-organize-imports": "latest",
8078
"rimraf": "latest",
81-
"simple-git-hooks": "^2.13.1",
79+
"simple-git-hooks": "latest",
8280
"ts-jest": "latest",
8381
"ts-node": "latest",
8482
"tsc-alias": "latest",
@@ -129,10 +127,10 @@
129127
},
130128
"overrides": {
131129
"@minecraft/common": "latest",
132-
"@minecraft/debug-utilities": "1.0.0-beta.1.26.1-stable",
133-
"@minecraft/server": "2.6.0-beta.1.26.1-stable",
134-
"@minecraft/server-gametest": "1.0.0-beta.1.26.1-stable",
135-
"@minecraft/server-ui": "2.1.0-beta.1.26.1-stable",
130+
"@minecraft/debug-utilities": "beta",
131+
"@minecraft/server": "beta",
132+
"@minecraft/server-gametest": "beta",
133+
"@minecraft/server-ui": "beta",
136134
"@minecraft/vanilla-data": "latest"
137135
}
138136
}

packs/resource/ui/_ui_defs.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"ui_defs": [
3+
"ui/hud_screen.json",
4+
"ui/loading_messages.json",
5+
"ui/pause_screen.json",
6+
"ui/scoreboards.json",
7+
"ui/server_form.json",
8+
"ui/tic_tac_toe.json"
9+
]
10+
}

packs/resource/ui/pause_screen.json

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,5 @@
1616
}
1717
}
1818
]
19-
},
20-
"store_button_panel@pause.pause_button_template": {
21-
"$pressed_button_name": "button.menu_settings",
22-
"$button_text": "menu.settings"
23-
},
24-
"marketplace_icon": {
25-
"type": "panel",
26-
"size": [16, 16],
27-
"controls": [
28-
{
29-
"icon": {
30-
"type": "image",
31-
"texture": "textures/ui/sidebar_icons/marketplace",
32-
"size": [16, 16]
33-
}
34-
}
35-
]
36-
},
37-
"settings_button_small@common_buttons.light_content_button": {
38-
"$pressed_button_name": "button.menu_store",
39-
"$button_tts_header": "menu.store",
40-
"$button_content": "pause.marketplace_icon"
4119
}
4220
}

scripts/generate-manifests.js

Lines changed: 40 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
import { exec } from 'node:child_process';
12
import fs from 'node:fs/promises';
23
import path from 'node:path';
34
import { fileURLToPath } from 'node:url';
5+
import { promisify } from 'node:util';
46

7+
const execAsync = promisify(exec);
58
const __filename = fileURLToPath(import.meta.url);
69
const __dirname = path.dirname(__filename);
710

@@ -51,23 +54,36 @@ function parseVersion(versionString) {
5154
}
5255

5356
/**
54-
* Extracts the module version from the NPM version string.
55-
* e.g., "2.5.0-beta.1.21.132-stable" -> "2.5.0-beta"
56-
* "1.0.0" -> "1.0.0"
57+
* Fetches the latest stable version of a package from npm.
58+
* @param {string} pkgName The name of the package.
59+
* @returns {Promise<string>} The latest version.
5760
*/
58-
function extractModuleVersion(npmVersion) {
61+
async function fetchLatestVersion(pkgName) {
62+
try {
63+
console.log(`Fetching latest version for ${pkgName}...`);
64+
const { stdout } = await execAsync(`npm view ${pkgName} version`);
65+
return stdout.trim();
66+
} catch (error) {
67+
console.warn(`Failed to fetch version for ${pkgName}, defaulting to 1.0.0. Error: ${error.message}`);
68+
return '1.0.0';
69+
}
70+
}
71+
72+
/**
73+
* Resolves the module version from the NPM version string.
74+
*/
75+
async function resolveModuleVersion(pkgName, npmVersion) {
5976
if (!npmVersion) return '1.0.0';
60-
if (npmVersion === 'latest') return 'beta';
6177

62-
// Strip range characters like ^, ~, >=
63-
const cleanVersion = npmVersion.replace(/^[^\d]*/, '');
78+
if (npmVersion === 'beta') return 'beta';
6479

65-
// Regex to capture x.y.z(-tag)?
66-
const match = cleanVersion.match(/^(\d+\.\d+\.\d+(?:-(?:beta|rc|preview))?)/);
67-
if (match) {
68-
return match[1];
80+
if (npmVersion === 'latest') {
81+
const version = await fetchLatestVersion(pkgName);
82+
return version;
6983
}
70-
return cleanVersion;
84+
85+
// Strip range characters like ^, ~, >= if explicit version provided
86+
return npmVersion.replace(/^[^\d]*/, '');
7187
}
7288

7389
async function generateManifests() {
@@ -116,14 +132,19 @@ async function generateManifests() {
116132

117133
const dependencies = [];
118134

119-
for (const mod of modulesToInclude) {
120-
if (devDeps[mod]) {
121-
dependencies.push({
135+
// Process modules in parallel to speed up npm fetches
136+
const modulePromises = modulesToInclude
137+
.filter((mod) => devDeps[mod])
138+
.map(async (mod) => {
139+
const version = await resolveModuleVersion(mod, devDeps[mod]);
140+
return {
122141
module_name: mod,
123-
version: extractModuleVersion(devDeps[mod])
124-
});
125-
}
126-
}
142+
version: version
143+
};
144+
});
145+
146+
const resolvedModules = await Promise.all(modulePromises);
147+
dependencies.push(...resolvedModules);
127148

128149
// Always add RP dependency
129150
dependencies.push({

scripts/update-mc-deps.js

Lines changed: 0 additions & 142 deletions
This file was deleted.

src/core/__tests__/__mocks__/minecraftMock.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,6 @@ export class ModalFormData {
170170

171171
show = jest.fn().mockImplementation(async () => {
172172
return {
173-
// eslint-disable-next-line sonarjs/function-return-type
174173
formValues: this._controls.map((c): string | number | boolean | undefined => {
175174
if (c.type === 'toggle') return c.defaultValue ?? false;
176175
if (c.type === 'textField') return c.defaultValue ?? '';

src/core/playerDataManager.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,6 @@ function saveShardedMap(map: Map<string, string>, prefix: string) {
173173
// Cleanup stale shards if the map shrank
174174
let nextIndex = totalShards;
175175
while (mc.world.getDynamicProperty(`${prefix}${nextIndex}`) !== undefined) {
176-
// eslint-disable-next-line sonarjs/no-undefined-argument
177176
mc.world.setDynamicProperty(`${prefix}${nextIndex}`, undefined);
178177
nextIndex++;
179178
}
@@ -193,7 +192,6 @@ function loadShardedMap(map: Map<string, string>, legacyKey: string, shardPrefix
193192
const entries = JSON.parse(legacyData) as [string, string][];
194193
for (const [k, v] of entries) map.set(k, v);
195194
// Delete legacy key immediately to mark migration complete
196-
// eslint-disable-next-line sonarjs/no-undefined-argument
197195
mc.world.setDynamicProperty(legacyKey, undefined);
198196
migrated = true;
199197
} catch (error) {

0 commit comments

Comments
 (0)