-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
90 lines (78 loc) · 2.77 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import { world, system } from "@minecraft/server";
let properties = []
/*
made by: pokecosimo123
*/
export class Database {
constructor(name) {
this.name = name;
const getDatabases = world.getDynamicPropertyIds()
if (getDatabases) {
getDatabases.forEach(p => {
const split = p.split(":")
if (split[0] === this.name) {
if (!properties[this.name]) {
properties[this.name] = {
properties: [p]
}
} else {
properties[this.name].properties.push(p)
}
}
})
}
if (!properties[this.name]) {
properties[this.name] = {
properties: []
}
}
if (!properties[this.name].properties) {
properties[this.name] = {
properties: []
}
}
}
set(property, value) {
world.setDynamicProperty(this.name + ":" + property, JSON.stringify(value))
if (properties[this.name].properties.find((c) => c.split(":")[1] == property)) return
properties[this.name].properties.push(this.name + ":" + property)
}
get(property) {
if (world.getDynamicProperty(this.name + ":" + property) === undefined) return undefined
return JSON.parse(world.getDynamicProperty(this.name + ":" + property))
}
getAll(property) {
if (world.getDynamicProperty(this.name + ":" + property) === undefined) return undefined
return properties[this.name]
}
delete(property) {
if (properties[this.name].properties.find((c) => c.split(":")[1] == property)) {
const find = properties[this.name].properties.find((c) => c.split(":")[1] == property)
const index = properties[this.name].properties.indexOf(find)
world.setDynamicProperty(properties[this.name].properties.find((c) => c.split(":")[1] == property))
properties[this.name].properties.splice(index, 1)
} else {
return console.warn('Propriety not found')
}
}
clearAll() {
const properties1 = properties[this.name].properties
properties1.forEach(p => {
world.getDynamicPropertyIds().forEach(d => {
if (p === d) {
world.setDynamicProperty(d)
}
})
})
properties[this.name].properties = []
}
clearAllProprieties() {
properties = []
world.getDynamicPropertyIds().forEach(d => {
world.setDynamicProperty(d)
})
}
}
/*
made by: pokecosimo123
*/