@starktma/minecraft-utils 1.3.24 → 1.3.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/database/database.d.ts +14 -31
- package/dist/database/database.d.ts.map +1 -1
- package/dist/database/database.js +47 -81
- package/dist/database/database.js.map +1 -1
- package/dist/minecraft/effectsAPI.d.ts +82 -0
- package/dist/minecraft/effectsAPI.d.ts.map +1 -0
- package/dist/minecraft/effectsAPI.js +438 -0
- package/dist/minecraft/effectsAPI.js.map +1 -0
- package/dist/minecraft/index.d.ts +4 -0
- package/dist/minecraft/index.d.ts.map +1 -1
- package/dist/minecraft/index.js +4 -0
- package/dist/minecraft/index.js.map +1 -1
- package/dist/minecraft/potionAPI.d.ts +74 -0
- package/dist/minecraft/potionAPI.d.ts.map +1 -0
- package/dist/minecraft/potionAPI.js +228 -0
- package/dist/minecraft/potionAPI.js.map +1 -0
- package/dist/minecraft/projectileAPI.d.ts +61 -0
- package/dist/minecraft/projectileAPI.d.ts.map +1 -0
- package/dist/minecraft/projectileAPI.js +146 -0
- package/dist/minecraft/projectileAPI.js.map +1 -0
- package/package.json +2 -2
|
@@ -18,36 +18,19 @@ import { SimpleObject } from "./interfaces";
|
|
|
18
18
|
* }
|
|
19
19
|
* return MyDatabase.instance;
|
|
20
20
|
* }
|
|
21
|
-
* }
|
|
22
|
-
*
|
|
23
|
-
* @example
|
|
24
|
-
* // Using a custom namespace
|
|
25
|
-
* class MyCustomDatabase extends SimpleDatabase<PlayerObject> {
|
|
26
|
-
* protected static instance: MyCustomDatabase;
|
|
27
|
-
* constructor() {
|
|
28
|
-
* super("myDatabase", undefined, "customnamespace");
|
|
29
|
-
* }
|
|
30
|
-
*
|
|
31
|
-
* static getInstance(): MyCustomDatabase {
|
|
32
|
-
* if (!MyCustomDatabase.instance) {
|
|
33
|
-
* MyCustomDatabase.instance = new MyCustomDatabase();
|
|
34
|
-
* }
|
|
35
|
-
* return MyCustomDatabase.instance;
|
|
36
|
-
* }
|
|
37
|
-
* }
|
|
38
21
|
*/
|
|
39
22
|
declare class SimpleDatabase<T extends SimpleObject> {
|
|
40
23
|
private mainDB;
|
|
24
|
+
private localDB;
|
|
41
25
|
protected databaseName: string;
|
|
42
26
|
/**
|
|
43
|
-
* The constructor initializes the database
|
|
27
|
+
* The constructor initializes the local database and syncs it with the main database.
|
|
44
28
|
* @param databaseName The name of the database.
|
|
45
29
|
* @param target The target entity to store the database in. If undefined, the database is stored in the world.
|
|
46
|
-
* @param namespace The namespace to use for the database. If undefined, the global namespace is used.
|
|
47
30
|
*/
|
|
48
|
-
protected constructor(databaseName: string, target?: Entity | undefined
|
|
31
|
+
protected constructor(databaseName: string, target?: Entity | undefined);
|
|
49
32
|
/**
|
|
50
|
-
* Updates the main database with the
|
|
33
|
+
* Updates the main database with the local database.
|
|
51
34
|
* This method is called automatically when an object is added, updated or removed.
|
|
52
35
|
* @private
|
|
53
36
|
*/
|
|
@@ -59,47 +42,47 @@ declare class SimpleDatabase<T extends SimpleObject> {
|
|
|
59
42
|
*/
|
|
60
43
|
private getMainDB;
|
|
61
44
|
/**
|
|
62
|
-
* Adds an object to the database.
|
|
45
|
+
* Adds an object to the local database and updates the main database.
|
|
63
46
|
* @param object The object to be added.
|
|
64
47
|
*/
|
|
65
48
|
addObject(object: T): void;
|
|
66
49
|
/**
|
|
67
|
-
* Updates an object in the database.
|
|
50
|
+
* Updates an object in the local database and the main database.
|
|
68
51
|
* If the object does not exist, it is added.
|
|
69
52
|
* @param object The object to be updated.
|
|
70
53
|
*/
|
|
71
54
|
updateObject(object: T): void;
|
|
72
55
|
/**
|
|
73
|
-
* Checks if an object with the given id exists in the database.
|
|
56
|
+
* Checks if an object with the given id exists in the local database.
|
|
74
57
|
* @param id The id of the object.
|
|
75
58
|
* @returns True if the object exists, false otherwise.
|
|
76
59
|
*/
|
|
77
60
|
hasObject(id: string): boolean;
|
|
78
61
|
/**
|
|
79
|
-
* Retrieves an object with the given id from the database.
|
|
62
|
+
* Retrieves an object with the given id from the local database.
|
|
80
63
|
* @param id The id of the object.
|
|
81
64
|
* @returns The object if it exists, undefined otherwise.
|
|
82
65
|
*/
|
|
83
66
|
getObject(id: string): T | undefined;
|
|
84
67
|
/**
|
|
85
|
-
* Removes an object with the given id from the database.
|
|
68
|
+
* Removes an object with the given id from the local database and updates the main database.
|
|
86
69
|
* @param id The id of the object.
|
|
87
70
|
*/
|
|
88
71
|
removeObject(id: string): void;
|
|
89
72
|
/**
|
|
90
|
-
* Retrieves all objects from the database.
|
|
91
|
-
* @returns An array of all objects in the database.
|
|
73
|
+
* Retrieves all objects from the local database.
|
|
74
|
+
* @returns An array of all objects in the local database.
|
|
92
75
|
*/
|
|
93
76
|
getAllObjects(): T[];
|
|
94
77
|
/**
|
|
95
|
-
* Removes all objects from the database.
|
|
78
|
+
* Removes all objects from the local database and updates the main database.
|
|
96
79
|
*/
|
|
97
80
|
eraseAllObjects(): void;
|
|
98
81
|
/**
|
|
99
|
-
* Iterates over all objects in the database.
|
|
82
|
+
* Iterates over all objects in the local database.
|
|
100
83
|
* @param callback The function to be called for each object.
|
|
101
84
|
*/
|
|
102
|
-
forEach(callback: (object:
|
|
85
|
+
forEach(callback: (object: SimpleObject, index: number) => void): void;
|
|
103
86
|
}
|
|
104
87
|
export { SimpleDatabase, SimpleObject };
|
|
105
88
|
//# sourceMappingURL=database.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"database.d.ts","sourceRoot":"","sources":["../../src/database/database.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAgB,MAAM,mBAAmB,CAAC;AACzD,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"database.d.ts","sourceRoot":"","sources":["../../src/database/database.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAgB,MAAM,mBAAmB,CAAC;AACzD,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAqI5C;;;;;;;;;;;;;;;;;;GAkBG;AACH,cAAM,cAAc,CAAC,CAAC,SAAS,YAAY;IAC1C,OAAO,CAAC,MAAM,CAAkB;IAChC,OAAO,CAAC,OAAO,CAAM;IAErB,SAAS,CAAC,YAAY,EAAE,MAAM,CAAC;IAE/B;;;;OAIG;IACH,SAAS,aAAa,YAAY,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS;IAYvE;;;;OAIG;IACH,OAAO,CAAC,YAAY;IAIpB;;;;OAIG;IACH,OAAO,CAAC,SAAS;IAIjB;;;OAGG;IACH,SAAS,CAAC,MAAM,EAAE,CAAC,GAAG,IAAI;IAK1B;;;;OAIG;IACH,YAAY,CAAC,MAAM,EAAE,CAAC,GAAG,IAAI;IAO7B;;;;OAIG;IACH,SAAS,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO;IAI9B;;;;OAIG;IACH,SAAS,CAAC,EAAE,EAAE,MAAM,GAAG,CAAC,GAAG,SAAS;IAIpC;;;OAGG;IACH,YAAY,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI;IAK9B;;;OAGG;IACH,aAAa,IAAI,CAAC,EAAE;IAIpB;;OAEG;IACH,eAAe,IAAI,IAAI;IAKvB;;;OAGG;IACH,OAAO,CAAC,QAAQ,EAAE,CAAC,MAAM,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,GAAG,IAAI;CAGtE;AAED,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,CAAC"}
|
|
@@ -8,20 +8,13 @@ class DatabaseManager {
|
|
|
8
8
|
static DYNAMIC_PROP_MAX_LENGTH = 32767;
|
|
9
9
|
static CHUNK_KEY = "__SPLIT__";
|
|
10
10
|
target;
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Creates a new DatabaseManager instance.
|
|
14
|
-
* @param target The target entity to store the database in. If undefined, the database is stored in the world.
|
|
15
|
-
* @param namespace The namespace to use for the database. If undefined, the global namespace is used.
|
|
16
|
-
*/
|
|
17
|
-
constructor(target, namespace) {
|
|
11
|
+
constructor(target) {
|
|
18
12
|
if (target instanceof Entity) {
|
|
19
13
|
this.target = target;
|
|
20
14
|
}
|
|
21
15
|
else {
|
|
22
16
|
this.target = world;
|
|
23
17
|
}
|
|
24
|
-
this.namespace = namespace || getNamespace();
|
|
25
18
|
}
|
|
26
19
|
/**
|
|
27
20
|
* Checks if a JSON database with the given name exists.
|
|
@@ -29,7 +22,7 @@ class DatabaseManager {
|
|
|
29
22
|
* @returns True if the database exists, false otherwise.
|
|
30
23
|
*/
|
|
31
24
|
hasJSONDatabase(databaseName) {
|
|
32
|
-
return this.target.getDynamicProperty(
|
|
25
|
+
return this.target.getDynamicProperty(databaseName) !== undefined;
|
|
33
26
|
}
|
|
34
27
|
/**
|
|
35
28
|
* Adds a new JSON database with the given name and data.
|
|
@@ -37,9 +30,8 @@ class DatabaseManager {
|
|
|
37
30
|
* @param database The data to be stored in the database.
|
|
38
31
|
*/
|
|
39
32
|
addJSONDatabase(databaseName, database) {
|
|
40
|
-
const propertyName = `${this.namespace}:${databaseName}`;
|
|
41
33
|
const jsonString = JSON.stringify(database);
|
|
42
|
-
const existingProp = this.target.getDynamicProperty(
|
|
34
|
+
const existingProp = this.target.getDynamicProperty(databaseName);
|
|
43
35
|
let existingChunks = 0;
|
|
44
36
|
if (existingProp) {
|
|
45
37
|
try {
|
|
@@ -53,18 +45,18 @@ class DatabaseManager {
|
|
|
53
45
|
if (jsonString.length <= DatabaseManager.DYNAMIC_PROP_MAX_LENGTH || jsonString.length === 0) {
|
|
54
46
|
if (existingChunks > 0) {
|
|
55
47
|
for (let i = 0; i < existingChunks; i++) {
|
|
56
|
-
const partName = `${
|
|
48
|
+
const partName = `${databaseName}_${i}`;
|
|
57
49
|
this.target.setDynamicProperty(partName, undefined);
|
|
58
50
|
}
|
|
59
51
|
}
|
|
60
|
-
this.target.setDynamicProperty(
|
|
52
|
+
this.target.setDynamicProperty(databaseName, jsonString);
|
|
61
53
|
}
|
|
62
54
|
else {
|
|
63
55
|
const chunkSize = DatabaseManager.DYNAMIC_PROP_MAX_LENGTH;
|
|
64
56
|
const chunkCount = Math.ceil(jsonString.length / chunkSize);
|
|
65
57
|
if (existingChunks > 0) {
|
|
66
58
|
for (let i = 0; i < existingChunks; i++) {
|
|
67
|
-
const oldPartName = `${
|
|
59
|
+
const oldPartName = `${databaseName}_${i}`;
|
|
68
60
|
this.target.setDynamicProperty(oldPartName, undefined);
|
|
69
61
|
}
|
|
70
62
|
}
|
|
@@ -72,11 +64,11 @@ class DatabaseManager {
|
|
|
72
64
|
const start = i * chunkSize;
|
|
73
65
|
const end = start + chunkSize;
|
|
74
66
|
const chunk = jsonString.slice(start, end);
|
|
75
|
-
const partName = `${
|
|
67
|
+
const partName = `${databaseName}_${i}`;
|
|
76
68
|
this.target.setDynamicProperty(partName, chunk);
|
|
77
69
|
}
|
|
78
70
|
const meta = { [DatabaseManager.CHUNK_KEY]: chunkCount };
|
|
79
|
-
this.target.setDynamicProperty(
|
|
71
|
+
this.target.setDynamicProperty(databaseName, JSON.stringify(meta));
|
|
80
72
|
}
|
|
81
73
|
}
|
|
82
74
|
/**
|
|
@@ -84,21 +76,20 @@ class DatabaseManager {
|
|
|
84
76
|
* @param databaseName The name of the database.
|
|
85
77
|
*/
|
|
86
78
|
removeJSONDatabase(databaseName) {
|
|
87
|
-
const
|
|
88
|
-
const propString = this.target.getDynamicProperty(propertyName);
|
|
79
|
+
const propString = this.target.getDynamicProperty(databaseName);
|
|
89
80
|
if (propString !== undefined) {
|
|
90
81
|
try {
|
|
91
82
|
const propObj = JSON.parse(propString);
|
|
92
83
|
if (propObj && typeof propObj === "object" && DatabaseManager.CHUNK_KEY in propObj) {
|
|
93
84
|
const chunkCount = propObj[DatabaseManager.CHUNK_KEY];
|
|
94
85
|
for (let i = 0; i < chunkCount; i++) {
|
|
95
|
-
const partName = `${
|
|
86
|
+
const partName = `${databaseName}_${i}`;
|
|
96
87
|
this.target.setDynamicProperty(partName, undefined);
|
|
97
88
|
}
|
|
98
89
|
}
|
|
99
90
|
}
|
|
100
91
|
catch { }
|
|
101
|
-
this.target.setDynamicProperty(
|
|
92
|
+
this.target.setDynamicProperty(databaseName, undefined);
|
|
102
93
|
}
|
|
103
94
|
}
|
|
104
95
|
/**
|
|
@@ -108,8 +99,7 @@ class DatabaseManager {
|
|
|
108
99
|
* @throws An error if the database does not exist.
|
|
109
100
|
*/
|
|
110
101
|
getJSONDatabase(databaseName) {
|
|
111
|
-
const
|
|
112
|
-
const propString = this.target.getDynamicProperty(propertyName);
|
|
102
|
+
const propString = this.target.getDynamicProperty(databaseName);
|
|
113
103
|
if (propString === undefined) {
|
|
114
104
|
throw new Error("Database does not exist");
|
|
115
105
|
}
|
|
@@ -119,7 +109,7 @@ class DatabaseManager {
|
|
|
119
109
|
const chunkCount = propObj[DatabaseManager.CHUNK_KEY];
|
|
120
110
|
let combined = "";
|
|
121
111
|
for (let i = 0; i < chunkCount; i++) {
|
|
122
|
-
const partName = `${
|
|
112
|
+
const partName = `${databaseName}_${i}`;
|
|
123
113
|
const part = this.target.getDynamicProperty(partName);
|
|
124
114
|
if (typeof part === "string") {
|
|
125
115
|
combined += part;
|
|
@@ -157,48 +147,34 @@ class DatabaseManager {
|
|
|
157
147
|
* }
|
|
158
148
|
* return MyDatabase.instance;
|
|
159
149
|
* }
|
|
160
|
-
* }
|
|
161
|
-
*
|
|
162
|
-
* @example
|
|
163
|
-
* // Using a custom namespace
|
|
164
|
-
* class MyCustomDatabase extends SimpleDatabase<PlayerObject> {
|
|
165
|
-
* protected static instance: MyCustomDatabase;
|
|
166
|
-
* constructor() {
|
|
167
|
-
* super("myDatabase", undefined, "customnamespace");
|
|
168
|
-
* }
|
|
169
|
-
*
|
|
170
|
-
* static getInstance(): MyCustomDatabase {
|
|
171
|
-
* if (!MyCustomDatabase.instance) {
|
|
172
|
-
* MyCustomDatabase.instance = new MyCustomDatabase();
|
|
173
|
-
* }
|
|
174
|
-
* return MyCustomDatabase.instance;
|
|
175
|
-
* }
|
|
176
|
-
* }
|
|
177
150
|
*/
|
|
178
151
|
class SimpleDatabase {
|
|
179
152
|
mainDB;
|
|
153
|
+
localDB;
|
|
180
154
|
databaseName;
|
|
181
155
|
/**
|
|
182
|
-
* The constructor initializes the database
|
|
156
|
+
* The constructor initializes the local database and syncs it with the main database.
|
|
183
157
|
* @param databaseName The name of the database.
|
|
184
158
|
* @param target The target entity to store the database in. If undefined, the database is stored in the world.
|
|
185
|
-
* @param namespace The namespace to use for the database. If undefined, the global namespace is used.
|
|
186
159
|
*/
|
|
187
|
-
constructor(databaseName, target
|
|
188
|
-
this.
|
|
189
|
-
this.
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
160
|
+
constructor(databaseName, target) {
|
|
161
|
+
this.databaseName = `${getNamespace()}:${databaseName}`;
|
|
162
|
+
this.mainDB = new DatabaseManager(target);
|
|
163
|
+
if (this.mainDB.hasJSONDatabase(this.databaseName)) {
|
|
164
|
+
this.localDB = this.getMainDB();
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
this.localDB = [];
|
|
168
|
+
this.updateMainDB();
|
|
193
169
|
}
|
|
194
170
|
}
|
|
195
171
|
/**
|
|
196
|
-
* Updates the main database with the
|
|
172
|
+
* Updates the main database with the local database.
|
|
197
173
|
* This method is called automatically when an object is added, updated or removed.
|
|
198
174
|
* @private
|
|
199
175
|
*/
|
|
200
|
-
updateMainDB(
|
|
201
|
-
this.mainDB.addJSONDatabase(this.databaseName,
|
|
176
|
+
updateMainDB() {
|
|
177
|
+
this.mainDB.addJSONDatabase(this.databaseName, this.localDB);
|
|
202
178
|
}
|
|
203
179
|
/**
|
|
204
180
|
* Retrieves the main database.
|
|
@@ -206,25 +182,18 @@ class SimpleDatabase {
|
|
|
206
182
|
* @returns The main database.
|
|
207
183
|
*/
|
|
208
184
|
getMainDB() {
|
|
209
|
-
|
|
210
|
-
return this.mainDB.getJSONDatabase(this.databaseName);
|
|
211
|
-
}
|
|
212
|
-
catch {
|
|
213
|
-
// If database doesn't exist or is corrupted, return empty array
|
|
214
|
-
return [];
|
|
215
|
-
}
|
|
185
|
+
return this.mainDB.getJSONDatabase(this.databaseName);
|
|
216
186
|
}
|
|
217
187
|
/**
|
|
218
|
-
* Adds an object to the database.
|
|
188
|
+
* Adds an object to the local database and updates the main database.
|
|
219
189
|
* @param object The object to be added.
|
|
220
190
|
*/
|
|
221
191
|
addObject(object) {
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
this.updateMainDB(currentData);
|
|
192
|
+
this.localDB.push(object);
|
|
193
|
+
this.updateMainDB();
|
|
225
194
|
}
|
|
226
195
|
/**
|
|
227
|
-
* Updates an object in the database.
|
|
196
|
+
* Updates an object in the local database and the main database.
|
|
228
197
|
* If the object does not exist, it is added.
|
|
229
198
|
* @param object The object to be updated.
|
|
230
199
|
*/
|
|
@@ -235,52 +204,49 @@ class SimpleDatabase {
|
|
|
235
204
|
this.addObject(object);
|
|
236
205
|
}
|
|
237
206
|
/**
|
|
238
|
-
* Checks if an object with the given id exists in the database.
|
|
207
|
+
* Checks if an object with the given id exists in the local database.
|
|
239
208
|
* @param id The id of the object.
|
|
240
209
|
* @returns True if the object exists, false otherwise.
|
|
241
210
|
*/
|
|
242
211
|
hasObject(id) {
|
|
243
|
-
|
|
244
|
-
return currentData.map((object) => object.id).includes(id);
|
|
212
|
+
return this.localDB.map((object) => object.id).includes(id);
|
|
245
213
|
}
|
|
246
214
|
/**
|
|
247
|
-
* Retrieves an object with the given id from the database.
|
|
215
|
+
* Retrieves an object with the given id from the local database.
|
|
248
216
|
* @param id The id of the object.
|
|
249
217
|
* @returns The object if it exists, undefined otherwise.
|
|
250
218
|
*/
|
|
251
219
|
getObject(id) {
|
|
252
|
-
|
|
253
|
-
return currentData.filter((object) => object.id === id)[0];
|
|
220
|
+
return this.localDB.filter((object) => object.id === id)[0];
|
|
254
221
|
}
|
|
255
222
|
/**
|
|
256
|
-
* Removes an object with the given id from the database.
|
|
223
|
+
* Removes an object with the given id from the local database and updates the main database.
|
|
257
224
|
* @param id The id of the object.
|
|
258
225
|
*/
|
|
259
226
|
removeObject(id) {
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
this.updateMainDB(updatedData);
|
|
227
|
+
this.localDB = this.localDB.filter((object) => object.id !== id);
|
|
228
|
+
this.updateMainDB();
|
|
263
229
|
}
|
|
264
230
|
/**
|
|
265
|
-
* Retrieves all objects from the database.
|
|
266
|
-
* @returns An array of all objects in the database.
|
|
231
|
+
* Retrieves all objects from the local database.
|
|
232
|
+
* @returns An array of all objects in the local database.
|
|
267
233
|
*/
|
|
268
234
|
getAllObjects() {
|
|
269
|
-
return this.
|
|
235
|
+
return this.localDB;
|
|
270
236
|
}
|
|
271
237
|
/**
|
|
272
|
-
* Removes all objects from the database.
|
|
238
|
+
* Removes all objects from the local database and updates the main database.
|
|
273
239
|
*/
|
|
274
240
|
eraseAllObjects() {
|
|
275
|
-
this.
|
|
241
|
+
this.localDB = [];
|
|
242
|
+
this.updateMainDB();
|
|
276
243
|
}
|
|
277
244
|
/**
|
|
278
|
-
* Iterates over all objects in the database.
|
|
245
|
+
* Iterates over all objects in the local database.
|
|
279
246
|
* @param callback The function to be called for each object.
|
|
280
247
|
*/
|
|
281
248
|
forEach(callback) {
|
|
282
|
-
|
|
283
|
-
currentData.forEach((object, index) => callback(object, index));
|
|
249
|
+
this.localDB.forEach((object, index) => callback(object, index));
|
|
284
250
|
}
|
|
285
251
|
}
|
|
286
252
|
export { SimpleDatabase };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"database.js","sourceRoot":"","sources":["../../src/database/database.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,KAAK,EAAS,MAAM,mBAAmB,CAAC;AAEzD,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE5C;;;GAGG;AACH,MAAM,eAAe;IACZ,MAAM,CAAU,uBAAuB,GA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AAE,EAAE,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;IAC7D,CAAC;IAED;;;;OAIG;IACH,SAAS,CAAC,EAAU;QACnB,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;IAC7D,CAAC;IAED;;;OAGG;IACH,YAAY,CAAC,EAAU;QACtB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;QACjE,IAAI,CAAC,YAAY,EAAE,CAAC;IACrB,CAAC;IAED;;;OAGG;IACH,aAAa;QACZ,OAAO,IAAI,CAAC,OAAO,CAAC;IACrB,CAAC;IAED;;OAEG;IACH,eAAe;QACd,IAAI,CAAC,OAAO,GAAG,EAAE,CAAC;QAClB,IAAI,CAAC,YAAY,EAAE,CAAC;IACrB,CAAC;IAED;;;OAGG;IACH,OAAO,CAAC,QAAuD;QAC9D,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC,QAAQ,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC;IAClE,CAAC;CACD;AAED,OAAO,EAAE,cAAc,EAAgB,CAAC"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { Entity, RGBA } from "@minecraft/server";
|
|
2
|
+
interface EffectObject {
|
|
3
|
+
id: string;
|
|
4
|
+
entityId: string;
|
|
5
|
+
effectType: string;
|
|
6
|
+
amplifier: number;
|
|
7
|
+
duration: number;
|
|
8
|
+
color: RGBA;
|
|
9
|
+
}
|
|
10
|
+
interface EffectSounds {
|
|
11
|
+
ambient?: string;
|
|
12
|
+
start?: string;
|
|
13
|
+
end?: string;
|
|
14
|
+
}
|
|
15
|
+
interface EffectConfig {
|
|
16
|
+
effectType: string;
|
|
17
|
+
color: RGBA;
|
|
18
|
+
sounds?: EffectSounds;
|
|
19
|
+
particleType?: string;
|
|
20
|
+
handler: EffectHandler;
|
|
21
|
+
}
|
|
22
|
+
type EffectHandler = (entity: Entity, effect: EffectObject) => void;
|
|
23
|
+
declare class EffectManager {
|
|
24
|
+
private configs;
|
|
25
|
+
private entityDB;
|
|
26
|
+
static instance: EffectManager;
|
|
27
|
+
static getInstance(): EffectManager;
|
|
28
|
+
private constructor();
|
|
29
|
+
private getEntityDatabase;
|
|
30
|
+
/**
|
|
31
|
+
* Track an entity as having effects
|
|
32
|
+
* @param entity - The entity to track
|
|
33
|
+
*/
|
|
34
|
+
private trackEntity;
|
|
35
|
+
/**
|
|
36
|
+
* Stop tracking an entity (when it has no more effects)
|
|
37
|
+
* @param entity - The entity to stop tracking
|
|
38
|
+
*/
|
|
39
|
+
private untrackEntity;
|
|
40
|
+
/**
|
|
41
|
+
* Check if an entity has any effect tags
|
|
42
|
+
* @param entity - The entity to check
|
|
43
|
+
* @returns True if entity has any effect tags
|
|
44
|
+
*/
|
|
45
|
+
private entityHasEffectTags;
|
|
46
|
+
/**
|
|
47
|
+
* Parse effect data from entity tags regardless of namespace
|
|
48
|
+
* @param entity - The entity to get effects from
|
|
49
|
+
* @returns Array of effect objects parsed from all effect tags
|
|
50
|
+
*/
|
|
51
|
+
private getEffectsFromTags;
|
|
52
|
+
/**
|
|
53
|
+
* Parse ALL effect data from entity tags regardless of namespace
|
|
54
|
+
* @param entity - The entity to get effects from
|
|
55
|
+
* @returns Array of effect objects parsed from all effect tags
|
|
56
|
+
*/
|
|
57
|
+
private getAllEffectsFromTags;
|
|
58
|
+
/**
|
|
59
|
+
* Register a effect effect with full configuration
|
|
60
|
+
* @param config - Complete effect configuration including effect type, color, sounds, particle type, and handler
|
|
61
|
+
* @returns Helper functions for adding, removing, and applying the effect
|
|
62
|
+
*/
|
|
63
|
+
registerEffect(config: EffectConfig): {
|
|
64
|
+
addEffect: (entity: Entity, amplifier: number, duration: number) => void;
|
|
65
|
+
removeEffect: (entity: Entity) => void;
|
|
66
|
+
applyEffect: EffectHandler;
|
|
67
|
+
};
|
|
68
|
+
addEffect(entity: Entity, effectType: string, amplifier: number, duration: number): void;
|
|
69
|
+
removeEffect(entity: Entity, effectType: string): void;
|
|
70
|
+
removeAllEffects(entity: Entity): void;
|
|
71
|
+
extendEffect(entity: Entity, effectType: string, additionalDuration: number): boolean;
|
|
72
|
+
hasEffect(entity: Entity, effectType: string): boolean;
|
|
73
|
+
getEffects(entity: Entity): EffectObject[];
|
|
74
|
+
/**
|
|
75
|
+
* Debug function to display all active effects for an entity in the action bar
|
|
76
|
+
* @param entity - The entity to display effects for (must be a Player)
|
|
77
|
+
*/
|
|
78
|
+
debugShowEffects(entity: Entity): void;
|
|
79
|
+
start(): void;
|
|
80
|
+
}
|
|
81
|
+
export { EffectManager, EffectObject, EffectConfig, EffectSounds };
|
|
82
|
+
//# sourceMappingURL=effectsAPI.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"effectsAPI.d.ts","sourceRoot":"","sources":["../../src/minecraft/effectsAPI.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAA6B,IAAI,EAAiB,MAAM,mBAAmB,CAAC;AAK3F,UAAU,YAAY;IACrB,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,IAAI,CAAC;CACZ;AAqBD,UAAU,YAAY;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,GAAG,CAAC,EAAE,MAAM,CAAC;CACb;AAED,UAAU,YAAY;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,KAA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