51 lines
1.9 KiB
JavaScript
51 lines
1.9 KiB
JavaScript
var textcolors = require('textcolors');
|
|
var Canary = Packages.net.canarymod.Canary;
|
|
var sb = Canary.scoreboards().getScoreboard();
|
|
function execCommand( command ){
|
|
server.executeVanillaCommand(server, command);
|
|
}
|
|
function getTeamByName( teamName ){
|
|
var allTeams = sb.getTeams().toArray();
|
|
for (var i = 0;i < allTeams.length; i++){
|
|
if (allTeams[i].displayName == teamName){
|
|
return allTeams[i];
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
function createScoreboard( objectiveName, displayName ){
|
|
execCommand('scoreboard objectives add ' + objectiveName + ' dummy ' + displayName);
|
|
execCommand('scoreboard objectives setdisplay sidebar ' + objectiveName);
|
|
}
|
|
function addTeamToScoreboard( teamName, color){
|
|
execCommand('scoreboard teams add ' + teamName);
|
|
var team = getTeamByName( teamName );
|
|
team.prefix = textcolors.colorize(color, '');
|
|
//execCommand('scoreboard teams option ' + teamName + ' color ' + color);
|
|
}
|
|
function removeScoreboard( name ){
|
|
//execCommand('scoreboard objectives remove ' + name );
|
|
sb['removeScoreObjective(String)'](name);
|
|
}
|
|
function addPlayerToTeam( objectiveName, teamName, playerName ){
|
|
execCommand('scoreboard teams join ' + teamName + ' ' + playerName);
|
|
execCommand('scoreboard players set ' + playerName + ' ' + objectiveName + ' -1');
|
|
updatePlayerScore( objectiveName, playerName, 0);
|
|
}
|
|
|
|
function updatePlayerScore( objectiveName, playerName, score ){
|
|
var sc = sb['getScore(String, ScoreObjective)']( playerName, sb.getScoreObjective( objectiveName) );
|
|
sc.score = score;
|
|
}
|
|
|
|
function removeTeamFromScoreboard( teamName ){
|
|
execCommand('scoreboard teams remove ' + teamName);
|
|
//sb['removeTeam(String)'](teamName);
|
|
}
|
|
exports.create = createScoreboard;
|
|
exports.addTeam = addTeamToScoreboard;
|
|
exports.removeTeam = removeTeamFromScoreboard;
|
|
exports.addPlayerToTeam = addPlayerToTeam;
|
|
exports.updateScore = updatePlayerScore;
|
|
exports.remove = removeScoreboard;
|