Skip to content

Commit

Permalink
fix: set
Browse files Browse the repository at this point in the history
  • Loading branch information
leaftail1880 committed Oct 30, 2024
1 parent 8093009 commit 06f5f15
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/lib/database/persistent-set.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { system } from '@minecraft/server'
import { LongDynamicProperty } from './properties'

export class LimitedSet<T> extends Set<T> {
Expand All @@ -24,12 +23,11 @@ export class PersistentSet<T extends Json> extends LimitedSet<T> {
private load() {
const id = `PersistentSet<${this.id}>:`
try {
LongDynamicProperty.getJob(this.id, '[]', values => {
if (typeof values === 'undefined') return // Set was not saved
if (!Array.isArray(values)) return console.warn(`${id} Dynamic property is not array, it is:`, values)
const values = LongDynamicProperty.get(this.id, '[]')
if (typeof values === 'undefined') return // Set was not saved
if (!Array.isArray(values)) return console.warn(`${id} Dynamic property is not array, it is:`, values)

system.runJobForEach(values as T[], value => this.add(value))
})
values.forEach(e => this.add(e as T))
} catch (error) {
console.error(`${id} Failed to load:`, error)
}
Expand Down

0 comments on commit 06f5f15

Please sign in to comment.