You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Aug 24, 2024. It is now read-only.
Copy file name to clipboardExpand all lines: database.js
+79-49Lines changed: 79 additions & 49 deletions
Original file line number
Diff line number
Diff line change
@@ -5,43 +5,11 @@ function initDatabase() {
5
5
6
6
session.exec("CREATE TABLE IF NOT EXISTS co_art_map (id INTEGER PRIMARY KEY AUTOINCREMENT, block TEXT UNIQUE)");
7
7
session.exec("CREATE TABLE IF NOT EXISTS co_user (id INTEGER PRIMARY KEY AUTOINCREMENT, nickname TEXT UNIQUE, inspector INT DEFAULT 0, wid INT DEFAULT -1, x INT DEFAULT 0, y INT DEFAULT -256, z INT DEFAULT 0)");
8
-
session.exec("CREATE TABLE IF NOT EXISTS co_item (id INTEGER PRIMARY KEY AUTOINCREMENT, item TEXT UNIQUE)");
9
-
session.exec("CREATE TABLE IF NOT EXISTS co_block (time TIMESTAMP DEFAULT (CAST (((julianday('now') - 2440587.5) * 86400.0 * 1000) AS INT)), block INT, user INT, action INT, wid INT, x INT, y INT, z INT)");
8
+
session.exec("CREATE TABLE IF NOT EXISTS co_block (time TIMESTAMP DEFAULT (CAST (((julianday('now') - 2440587.5) * 86400.0 * 1000) AS INT)), block INT, user INT, action INT, wid INT, x INT, y INT, z INT, data INT, count INT, slot INT, rollback INT DEFAULT 0)");
10
9
}
11
10
12
-
functiongetUserId(playerName){
13
-
letuserId=session.query(`SELECT id FROM co_user WHERE nickname = "${playerName}"`);
14
-
15
-
if(userId===undefined){
16
-
session.exec(`INSERT INTO co_user (nickname) VALUES ("${playerName}")`);
17
-
returnsession.query(`SELECT id FROM co_user WHERE nickname = "${playerName}"`)[1][0];
18
-
}
19
-
20
-
returnuserId[1][0];
21
-
}
22
-
23
-
functiongetUserName(userId){
24
-
returnsession.query(`SELECT nickname FROM co_user WHERE id = ${userId}`)[1][0];
25
-
}
26
-
27
-
functiongetBlockId(blockName){
28
-
blockName=blockName.replace("minecraft:","");
29
-
letblockId=session.query(`SELECT id FROM co_art_map WHERE block = "${blockName}"`);
30
-
31
-
if(blockId===undefined){
32
-
session.exec(`INSERT INTO co_art_map (block) VALUES ("${blockName}")`);
33
-
returnsession.query(`SELECT id FROM co_art_map WHERE block = "${blockName}"`)[1][0];
34
-
}
35
-
36
-
returnblockId[1][0];
37
-
}
38
-
39
-
functiongetBlockName(blockId){
40
-
returnsession.query(`SELECT block FROM co_art_map WHERE id = ${blockId}`)[1][0];
41
-
}
42
-
43
-
functionlogBlock(pl,blockName,wid,x,y,z,action){
44
-
if(!isInspector(pl.realName))session.exec(`INSERT INTO co_block (block, user, action, wid, x, y, z) VALUES (${getBlockId(blockName)}, ${getUserId(pl.realName)}, ${action}, ${wid}, ${x}, ${y}, ${z})`);
if(pageCount>1)output+=`-----\nPage 1/${pageCount}. View older data by typing "§3/co l <page>§r".`;
58
27
pl.tell(output);
59
28
}
60
-
elsepl.tell(action ? `§3CoreProtect §r- No data found at this location.` : `§3CoreProtect §r- No data found at §o${blockName.replace("minecraft:","")}§r.`);
29
+
elsepl.tell(action ? "§3CoreProtect §r- No data found at this location." : `§3CoreProtect §r- No data found at §o${blockName.replace("minecraft:","")}§r.`);
61
30
62
31
session.exec(`UPDATE co_user SET x = ${x}, y = ${y}, z = ${z}, wid = ${wid} WHERE id = ${getUserId(pl.realName)}`);
63
32
@@ -80,27 +49,44 @@ function lookupPage(pl, page, out) {
returnsession.query(`SELECT time, user, block, action FROM co_block WHERE wid = ${wid} AND x = ${x} AND y = ${y} AND z = ${z} ORDER BY time DESC LIMIT ${offset}, 7`);
89
+
returnsession.query(`SELECT time, user, block, action, count, rollback FROM co_block WHERE wid = ${wid} AND x = ${x} AND y = ${y} AND z = ${z} ORDER BY time DESC LIMIT ${offset}, 7`);
0 commit comments