Skip to content

Commit 6543bdc

Browse files
authored
Merge branch 'main' into patch-6
2 parents 538f6b7 + fda8df9 commit 6543bdc

10 files changed

Lines changed: 542 additions & 113 deletions

File tree

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,4 @@ Currently, we do not provide support uploading and maintaince for editor extensi
4141

4242
Documentation are no longer being updated as mentioned in README.
4343

44-
Please do not submit any pull requests that changes any content to the docs directory. Instead, please visit [Bedrock Wiki](https://wiki.bedrock.dev/scripting/starting-scripts) and perhaps contribute scripting documentation in Bedrock Wiki GitHub repository: https://github.com/Bedrock-OSS/bedrock-wiki/tree/wiki/docs/scripting
44+
Please do not submit any pull requests that changes any content to the docs directory. Instead, please visit [Bedrock Wiki](https://wiki.bedrock.dev/scripting/scripting-intro.html) and perhaps contribute scripting documentation in Bedrock Wiki GitHub repository: https://github.com/Bedrock-OSS/bedrock-wiki/tree/wiki/docs/scripting

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ Check out the following links for Script API documentation:
4848

4949
- [Official Script API Documentation](https://learn.microsoft.com/en-us/minecraft/creator/scriptapi/) - Microsoft's official documentation of high-level introduction of experimental Script API
5050
- [Jayly's Script API References](https://jaylydev.github.io/scriptapi-docs/) - Jayly's Script API documentation with guides and easy to use and understand API references for programming beginners.
51-
- [Bedrock Wiki](https://wiki.bedrock.dev/scripting/starting-scripts.html) - Learn the basics of the Script API on Bedrock Wiki.
51+
- [Bedrock Wiki](https://wiki.bedrock.dev/scripting/scripting-intro.html) - Learn the basics of the Script API on Bedrock Wiki.
5252
5353
## Contributing
5454

package-lock.json

Lines changed: 95 additions & 95 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,23 @@
1919
},
2020
"homepage": "https://github.com/JaylyDev/ScriptAPI#readme",
2121
"overrides": {
22-
"@minecraft/server": "1.18.0-beta.1.21.60-preview.24",
23-
"@minecraft/vanilla-data": "1.21.60-preview.24"
22+
"@minecraft/server": "2.0.0-beta.1.21.80-preview.22",
23+
"@minecraft/vanilla-data": "1.21.80-preview.22"
2424
},
2525
"dependencies": {
26-
"@minecraft/server-admin": "1.0.0-beta.1.21.60-preview.24",
27-
"@minecraft/server-editor": "0.1.0-beta.1.21.60-preview.24",
28-
"@minecraft/server-gametest": "1.0.0-beta.1.21.60-preview.24",
29-
"@minecraft/server-net": "1.0.0-beta.1.21.60-preview.24",
30-
"@minecraft/server-ui": "1.4.0-beta.1.21.60-preview.24"
26+
"@minecraft/server-admin": "1.0.0-beta.1.21.80-preview.22",
27+
"@minecraft/server-editor": "0.1.0-beta.1.21.80-preview.22",
28+
"@minecraft/server-gametest": "1.0.0-beta.1.21.80-preview.22",
29+
"@minecraft/server-net": "1.0.0-beta.1.21.80-preview.22",
30+
"@minecraft/server-ui": "2.0.0-beta.1.21.80-preview.22"
3131
},
3232
"devDependencies": {
33-
"@minecraft/math": "^1.5.1",
33+
"@minecraft/math": "^2.2.1",
3434
"@npm/types": "^2.0.0",
35-
"@types/node": "^22.10.2",
35+
"@types/node": "^22.14.0",
3636
"@types/parsimmon": "^1.10.9",
37-
"axios": "^1.7.9",
37+
"axios": "^1.8.4",
3838
"parsimmon": "^1.18.1",
39-
"typescript": "^5.7.2"
39+
"typescript": "^5.8.2"
4040
}
4141
}

scripts/fetch-api/README.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Fetch
2+
3+
## Description
4+
5+
The `Fetch` class simplifies HTTP requests in Minecraft Bedrock Edition. It supports common HTTP methods like `GET`, `POST`, `PUT`, and `DELETE`, and automatically handles JSON data.
6+
7+
### Methods
8+
9+
#### `constructor(baseURL: string)`
10+
- Initializes a new `Fetch` instance with the specified base URL.
11+
12+
#### `get(path: string, params?: Object): Promise<Object>`
13+
- Sends an HTTP `GET` request to the specified path with optional query parameters.
14+
15+
#### `post(path: string, data: Object): Promise<Object>`
16+
- Sends an HTTP `POST` request to the specified path with the provided data.
17+
18+
#### `put(path: string, data: Object): Promise<Object>`
19+
- Sends an HTTP `PUT` request to the specified path with the provided data.
20+
21+
#### `delete(path: string): Promise<Object>`
22+
- Sends an HTTP `DELETE` request to the specified path.
23+
24+
### Example
25+
```js
26+
import { Fetch } from './fetch.js';
27+
28+
// Initialize Fetch instance
29+
const api = new Fetch("https://jsonplaceholder.typicode.com");
30+
31+
// GET example
32+
api.get("/posts", { userId: 1 }).then((data) => console.log(data));
33+
34+
// POST example
35+
api.post("/posts", {
36+
title: "foo",
37+
body: "bar",
38+
userId: 1
39+
}).then((data) => console.log(data));
40+
41+
// PUT example
42+
api.put("/posts/1", {
43+
title: "updated title",
44+
body: "updated body",
45+
userId: 1
46+
}).then((data) => console.log(data));
47+
48+
// DELETE example
49+
api.delete("/posts/1").then((data) => console.log(data));
50+
```
51+
52+
## Credits
53+
54+
These scripts were written by [nperma](https://github.com/nperma)

scripts/fetch-api/index.js

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
// Script example for ScriptAPI
2+
// Author: nperma <https://github.com/nperma>
3+
// Project: https://github.com/JaylyDev/ScriptAPI
4+
5+
import {
6+
http,
7+
HttpHeader,
8+
HttpRequest,
9+
HttpRequestMethod,
10+
} from "@minecraft/server-net";
11+
12+
/**
13+
* Class Fetch - Abstraction for HTTP Requests
14+
*/
15+
class Fetch {
16+
/**
17+
* Constructor to initialize the base URL.
18+
* @param {string} baseURL - The base URL for API requests.
19+
*/
20+
constructor(baseURL) {
21+
this.baseURL = baseURL.trim();
22+
}
23+
24+
/**
25+
* Performs an HTTP GET request.
26+
* @param {string} path - The API endpoint path.
27+
* @param {Object} [params={}] - Query parameters.
28+
* @returns {Promise<Object>} - The response body as JSON.
29+
*/
30+
async get(path, params = {}) {
31+
const queryString = this._buildQueryString(params);
32+
const uri = `${this.baseURL}${path}${queryString}`;
33+
const request = new HttpRequest(uri);
34+
request.method = HttpRequestMethod.Get;
35+
request.headers = [new HttpHeader("Content-Type", "application/json")];
36+
37+
const response = await http.request(request);
38+
return this._handleResponse(response);
39+
}
40+
41+
/**
42+
* Performs an HTTP POST request.
43+
* @param {string} path - The API endpoint path.
44+
* @param {Object} data - The data to send in the request body.
45+
* @returns {Promise<Object>} - The response body as JSON.
46+
*/
47+
async post(path, data) {
48+
const uri = `${this.baseURL}${path}`;
49+
const request = new HttpRequest(uri);
50+
request.method = HttpRequestMethod.Post;
51+
request.body = JSON.stringify(data);
52+
request.headers = [new HttpHeader("Content-Type", "application/json")];
53+
54+
const response = await http.request(request);
55+
return this._handleResponse(response);
56+
}
57+
58+
/**
59+
* Performs an HTTP PUT request.
60+
* @param {string} path - The API endpoint path.
61+
* @param {Object} data - The data to send in the request body.
62+
* @returns {Promise<Object>} - The response body as JSON.
63+
*/
64+
async put(path, data) {
65+
const uri = `${this.baseURL}${path}`;
66+
const request = new HttpRequest(uri);
67+
request.method = HttpRequestMethod.Put;
68+
request.body = JSON.stringify(data);
69+
request.headers = [new HttpHeader("Content-Type", "application/json")];
70+
71+
const response = await http.request(request);
72+
return this._handleResponse(response);
73+
}
74+
75+
/**
76+
* Performs an HTTP DELETE request.
77+
* @param {string} path - The API endpoint path.
78+
* @returns {Promise<Object>} - The response body as JSON.
79+
*/
80+
async delete(path) {
81+
const uri = `${this.baseURL}${path}`;
82+
const request = new HttpRequest(uri);
83+
request.method = HttpRequestMethod.Delete;
84+
request.headers = [new HttpHeader("Content-Type", "application/json")];
85+
86+
const response = await http.request(request);
87+
return this._handleResponse(response);
88+
}
89+
90+
/**
91+
* Handles the response from the server.
92+
* @param {Object} response - The HTTP response object.
93+
* @returns {Promise<Object>} - The parsed JSON body.
94+
* @throws {Error} - If the response status is not 200.
95+
*/
96+
async _handleResponse(response) {
97+
if (response.status !== 200) {
98+
throw new Error(
99+
`HTTP Error: ${response.status} - ${response.body}`
100+
);
101+
}
102+
return JSON.parse(response.body);
103+
}
104+
105+
/**
106+
* Builds a query string from an object of parameters.
107+
* @param {Object} params - The query parameters.
108+
* @returns {string} - The query string.
109+
*/
110+
_buildQueryString(params) {
111+
const entries = Object.entries(params);
112+
if (entries.length === 0) return "";
113+
return (
114+
"?" +
115+
entries
116+
.map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(value)}`)
117+
.join("&")
118+
);
119+
}
120+
}
121+
122+
export { Fetch };
123+

scripts/lz-string/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ This package is a fork and a modified version of the original 'lz-string' librar
88
- [Repository](https://github.com/pieroxy/lz-string)
99
- [Homepage](https://github.com/pieroxy/lz-string)
1010

11-
lz-string@1.4.4 is created by Pieroxy, and is licensed under WTFPL and MIT.
11+
lz-string - v1.4.4 is created by Pieroxy, and is licensed under WTFPL and MIT.

scripts/quick-db/index.js

Lines changed: 126 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,23 @@
22
// Author: Nperma <https://github.com/nperma>
33
// Project: https://github.com/JaylyDev/ScriptAPI
44

5+
56
import { world, system, World } from "@minecraft/server";
67

7-
const DATABASE_PREFIX = "\u0235\u0235";
8+
9+
10+
import { world,system, World } from '@minecraft/server';
11+
12+
const DATABASE_PREFIX = '\u0235\u0235';
813

914
const {
10-
getDynamicProperty: GET,
11-
setDynamicProperty: SET,
12-
getDynamicPropertyIds: IDS
15+
getDynamicProperty: GET,
16+
setDynamicProperty: SET,
17+
getDynamicPropertyIds: IDS
1318
} = World.prototype;
1419

1520
class QuickDB {
21+
1622
#identifier;
1723
__cache;
1824

@@ -150,6 +156,122 @@ class QuickDB {
150156
system.run(() => SET.call(world, real_id));
151157
}
152158
}
159+
=======
160+
#identifier;
161+
__cache = {};
162+
163+
/**
164+
* @param {string} id - Unique database identifier.
165+
*/
166+
constructor(id) {
167+
if (typeof id !== 'string' || !id.trim()) {
168+
throw new Error('Invalid database ID');
169+
}
170+
this.#identifier = `${DATABASE_PREFIX}${id}${DATABASE_PREFIX}`;
171+
172+
for (const keyFull of this.getIds()) {
173+
const key = keyFull.replace(this.#identifier, '');
174+
let value;system.run(()=>{value=GET.call(world, keyFull);})
175+
this.__cache[key] = JSON.parse(value);
176+
}
177+
}
178+
179+
/** @returns {number} */
180+
get size() {
181+
return this.keys().length;
182+
}
183+
184+
/** @returns {string[]} */
185+
keys() {
186+
return Object.keys(this.__cache);
187+
}
188+
189+
/** @returns {any[]} */
190+
values() {
191+
return Object.values(this.__cache);
192+
}
193+
194+
/** @returns {[string, any][]} */
195+
entries() {
196+
return Object.entries(this.__cache);
197+
}
198+
199+
/**
200+
* Stores a key-value pair.
201+
* @param {string} keyh
202+
* @param {any} value
203+
* @returns {void}
204+
*/
205+
set(key, value) {
206+
if (typeof key !== 'string' || !key.trim()) throw new Error('Key must be a non-empty string');
207+
system.run(()=>SET.call(world, this.#identifier + key, JSON.stringify(value)));
208+
this.__cache[key] = value;
209+
}
210+
211+
/**
212+
* Deletes a key.
213+
* @param {string} key
214+
* @returns {boolean}
215+
*/
216+
delete(key) {
217+
if (!this.has(key)) return false;
218+
system.run(()=>SET.call(world, this.#identifier + key));
219+
delete this.__cache[key];
220+
return true;
221+
}
222+
223+
/**
224+
* Retrieves a value.
225+
* @param {string} key
226+
* @returns {any}
227+
*/
228+
get(key) {
229+
if (typeof key !== 'string' || !key.trim()) throw new Error('Key must be a non-empty string');
230+
return this.__cache[key];
231+
}
232+
233+
/**
234+
* Checks if a key exists.
235+
* @param {string} key
236+
* @returns {boolean}
237+
*/
238+
has(key) {
239+
return key in this.__cache;
240+
}
241+
242+
/** @returns {string[]} */
243+
static get ids() {
244+
let keys;
245+
system.run(() =>{
246+
keys=IDS.call(world)
247+
.filter((id) => id.startsWith(DATABASE_PREFIX))
248+
.map((k) => k.slice(DATABASE_PREFIX.length).split(DATABASE_PREFIX)[0]);
249+
});
250+
return [...new Set(
251+
keys
252+
)];
253+
}
254+
255+
/** @returns {string[]} */
256+
getIds() {
257+
let result;system.run(()=>{result=IDS.call(world).filter((id) => id.startsWith(this.#identifier));});
258+
return result;
259+
}
260+
261+
/** Clears the database. */
262+
clear() {
263+
for (const key of this.keys()) {
264+
this.delete(key);
265+
}
266+
this.__cache = {}
267+
268+
/** Clears all databases globally. */
269+
static clearAll() {
270+
let keys;system.run(()=>{keys=IDS.call(world).filter((id) => id.startsWith(DATABASE_PREFIX))});
271+
for (const real_id of keys) {
272+
system.run(()=>SET.call(world, real_id));
273+
}
274+
153275
}
154276

155277
export default QuickDB;

scripts/shop-wrapped/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# shop-wrapped
2+
3+
## Description
4+
> This README is auto generated, Edit the README so that users know what this package does.
5+
6+
## Credits
7+
These scripts were written by [Nperma](https://github.com/nperma)

0 commit comments

Comments
 (0)