Skip to content
This repository was archived by the owner on May 1, 2021. It is now read-only.

Commit dae1092

Browse files
committed
[scoreboard] Add custom tags for ranks and level
1 parent 8b395d8 commit dae1092

File tree

1 file changed

+33
-17
lines changed

1 file changed

+33
-17
lines changed

scripts/info/scoreboard.js

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ Custom scoreboard script.
44
Note: the "⭕" character is invisible, and makes each line unique.
55
It also changes the font, making it slightly smaller.
66
7-
Made by Weissnix4711
7+
Tags work on the list menu, although the code to grab the tags is really ugly.
8+
Currently, the rank will be any rank beginning with "rank", and "level" for the mine level. It displays the entire tag name, although you could crop out the beginning if you wish.
89
9-
Todo: tags still broken. Comment out for now
10+
Made by Weissnix4711
1011
11-
v1.1
12+
v1.2
1213
*/
1314

1415
import {
@@ -48,15 +49,26 @@ onPlayerInitialized(player => {
4849
let money = getBalance(playerData);
4950
let playerCount = getPlayerList().length;
5051

51-
//tags - broken. need to fix
52-
//let tagsArray = system.getComponent(player, "minecraft:tag");
53-
//console.log(tagsArray);
54-
//let levelRegex= /level(.+)/;
55-
//let mineLevel = tagsArray.find(value => levelRegex.search(value));
56-
57-
//static testing variables for now
58-
let rank = "testrank";
59-
let mineLevel = "1";
52+
//tags - oh god oh god oh god
53+
//this is really ugly
54+
function mineLevel(callback) {
55+
system.executeCommand(`tag "${player.name}" list`, (result) => {
56+
let message = result.data.statusMessage;
57+
let levelRegex= /.*level.+/;
58+
let tags = message.substring(message.indexOf(":")+1,message.length).trim().split(", ");
59+
let level = tags.find(function (value) {if (levelRegex.test(value)) {return value}});
60+
callback(level)
61+
});
62+
}
63+
function rank(callback) {
64+
system.executeCommand(`tag "${player.name}" list`, (result) => {
65+
let message = result.data.statusMessage;
66+
let rankRegex= /.*rank.+/;
67+
let tags = message.substring(message.indexOf(":")+1,message.length).trim().split(", ");
68+
let rank = tags.find(function (value) {if (rankRegex.test(value)) {return value}});
69+
callback(rank)
70+
});
71+
}
6072

6173
//count and deinit
6274
if (i >= 11) {i = 0;}
@@ -128,8 +140,12 @@ onPlayerInitialized(player => {
128140
list.set(playerData, 25, `⭕§b${player.name}`, 25)
129141
list.set(playerData, 24, " ", 24)
130142

131-
list.set(playerData, 23, `⭕§l§4Level: §r§c${mineLevel}`, 23);
132-
list.set(playerData, 22, `⭕§l§2Rank: §r${rank}`, 22);
143+
mineLevel(function(result) {
144+
list.set(playerData, 23, `⭕§l§4Level: §r§c${result}`, 23);
145+
})
146+
rank(function(result) {
147+
list.set(playerData, 22, `⭕§l§2Rank: §r${result}`, 22);
148+
})
133149
list.set(playerData, 21, `⭕§l§6Jems: §r§e${money}`, 21)
134150
list.set(playerData, 20, " ", 20)
135151

@@ -143,7 +159,7 @@ onPlayerInitialized(player => {
143159
i++;
144160
}, 15)
145161
} catch(err) {
146-
console.log(err);
162+
console.error(err);
147163
}
148164
})
149165

@@ -155,6 +171,6 @@ onPlayerLeft(player => {
155171
sidebar.deinit(getPlayerByNAME(player.name));
156172
list.deinit(getPlayerByNAME(player.name));
157173
} catch(err) {
158-
console.log(err);
174+
console.error(err);
159175
}
160-
})
176+
})

0 commit comments

Comments
 (0)