26
26
27
27
import { ScoreboardIdentity , ScoreboardIdentityType , ScoreboardObjective , system , world } from "@minecraft/server" ;
28
28
29
- const version = "1.1.1 " ;
29
+ const version = "1.1.2 " ;
30
30
const str = ( ) => ( '00000000000000000' + ( Math . random ( ) * 0xffffffffffffffff ) . toString ( 16 ) ) . slice ( - 16 ) ;
31
31
/**
32
32
* A rough mechanism for create a random uuid. Not as secure as uuid without as much of a guarantee of uniqueness,
@@ -74,14 +74,24 @@ const CreateCrashReport = (action: "save" | "load", data: string, error: Error,
74
74
* @beta
75
75
*/
76
76
const DisplayName = {
77
- parse ( text : string , salt ?: string ) : Record < string , string | number | boolean > {
77
+ parse ( text : string , objective : ScoreboardObjective , salt ?: string ) : Record < string , string | number | boolean > {
78
78
try {
79
79
const a = salt ? decrypt ( text , salt ) : text ;
80
80
return JSON . parse ( `{${ a } }` ) ;
81
81
} catch ( error ) {
82
82
if ( ! ( error instanceof Error ) ) throw error ;
83
- CreateCrashReport ( "load" , text , error , salt ) ;
84
- throw new Error ( `Failed to load data. Please check content log file for more info.\n` ) ;
83
+ // fallback to 1.0
84
+ try {
85
+ const a = JSON . parse ( `"${ salt ? decrypt ( text , salt ) : text } "` ) ;
86
+ const b = JSON . parse ( `{${ a } }` ) ;
87
+ // upgrade format
88
+ objective . removeParticipant ( text ) ;
89
+ objective . setScore ( DisplayName . stringify ( b , salt ) , 0 ) ;
90
+ return b ;
91
+ } catch {
92
+ CreateCrashReport ( "load" , text , error , salt ) ;
93
+ throw new Error ( `Failed to load data. Please check content log file for more info.\n` ) ;
94
+ }
85
95
}
86
96
} ,
87
97
stringify ( value : Record < string , string | number | boolean > , salt ?: string ) : string {
@@ -124,7 +134,7 @@ class JaylyDB implements Map<string, string | number | boolean> {
124
134
this . localState . clear ( ) ;
125
135
for ( const participant of this . objective . getParticipants ( ) ) {
126
136
if ( participant . type !== ScoreboardIdentityType . FakePlayer ) continue ;
127
- const data = DisplayName . parse ( participant . displayName , this . salt ) ;
137
+ const data = DisplayName . parse ( participant . displayName , this . objective , this . salt ) ;
128
138
const key = Object . keys ( data ) [ 0 ] ;
129
139
const value = data [ key ] ;
130
140
this . localState . set ( key , {
@@ -204,6 +214,9 @@ class JaylyDB implements Map<string, string | number | boolean> {
204
214
if ( ! this . localState . has ( key ) ) this . updateParticipants ( ) ;
205
215
return this . localState . get ( key ) ?. decoded_value
206
216
}
217
+ /**
218
+ * @returns boolean indicating whether an element with the specified key exists or not in jaylydb.
219
+ */
207
220
has ( key : string ) : boolean {
208
221
return this . localState . has ( key ) ;
209
222
}
@@ -228,6 +241,9 @@ class JaylyDB implements Map<string, string | number | boolean> {
228
241
229
242
return this ;
230
243
}
244
+ /**
245
+ * Returns an iterable of key, value pairs for every entry in the database.
246
+ */
231
247
* entries ( ) : IterableIterator < [ string , string | number | boolean ] > {
232
248
for ( const [ key , data ] of this . localState . entries ( ) ) yield [ key , data . decoded_value ] ;
233
249
}
0 commit comments