diff --git a/build.xml b/build.xml index bb4a2be..a213127 100644 --- a/build.xml +++ b/build.xml @@ -46,6 +46,7 @@ + @@ -53,6 +54,7 @@ + @@ -60,10 +62,12 @@ + + diff --git a/docs/API-Reference.md b/docs/API-Reference.md index fdd2a25..02af2b1 100644 --- a/docs/API-Reference.md +++ b/docs/API-Reference.md @@ -198,6 +198,8 @@ Walter Higgins * [utils.unwatchFile() function](#utilsunwatchfile-function) * [utils.unwatchDir() function](#utilsunwatchdir-function) * [utils.array() function](#utilsarray-function) + * [utils.players() function](#utilsplayers-function) + * [utils.playerNames() function](#utilsplayernames-function) * [utils.stat() function](#utilsstat-function) * [Drone Plugin](#drone-plugin) * [Constructing a Drone Object](#constructing-a-drone-object) @@ -2603,6 +2605,14 @@ all of Javascript's Array goodness. var utils = require('utils'); var worlds = utils.array(server.worlds); +### utils.players() function + +This function returns a javascript array of all online players on the server. + +### utils.playerNames() function + +This function returns a javascript array of player names (as javascript strings) + ### utils.stat() function This function returns a numeric value for a given player statistic. diff --git a/src/main/js/modules/minigames/scoreboard.js b/src/main/js/modules/minigames/scoreboard.js index 7fc4cae..493099d 100644 --- a/src/main/js/modules/minigames/scoreboard.js +++ b/src/main/js/modules/minigames/scoreboard.js @@ -1,50 +1,50 @@ -var bkDisplaySlot = org.bukkit.scoreboard.DisplaySlot; -/* - The scoreboard is a simple wrapper around the Bukkit Scoreboard API. - It's only concerned with display of scores, not maintaining them - that's the game's job. -*/ -module.exports = function( options ) { - var temp = {}; - var ccScoreboard; - - return { - start: function( ) { - var objective, - slot, - ccObj; - ccScoreboard = server.scoreboardManager.getNewScoreboard(); - for ( objective in options ) { - ccObj = ccScoreboard.registerNewObjective( objective, 'dummy' ); - for ( slot in options[ objective ] ) { - ccObj.displaySlot = bkDisplaySlot[ slot ]; - ccObj.displayName = options[ objective ][ slot ]; - } - } - }, - stop: function(){ - var objective, slot; - for ( objective in options ) { - ccScoreboard.getObjective(objective).unregister(); - for ( slot in options[ objective ] ) { - ccScoreboard.clearSlot( bkDisplaySlot[ slot ] ); - } - } - }, - update: function( objective, player, score ) { - if ( player.scoreboard && player.scoreboard != ccScoreboard ) { - temp[player.name] = player.scoreboard; - player.scoreboard = ccScoreboard; - } - ccScoreboard - .getObjective( objective ) - .getScore( player ) - .score = score; - }, - restore: function( player ) { - // offlineplayers don't have a scoreboard - if ( player.scoreboard ) { - player.scoreboard = temp[ player.name ]; - } +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; diff --git a/src/main/js/plugins/drone/drone.js b/src/main/js/plugins/drone/drone.js index afe07ed..05744b6 100644 --- a/src/main/js/plugins/drone/drone.js +++ b/src/main/js/plugins/drone/drone.js @@ -611,7 +611,7 @@ var putSign = function( drone, x, y, z, world, texts, blockId, meta, immediate ) setLine = function( block, i, text) { var sign = block.getTileEntity(); sign.setTextOnLine( text, i ); - sign.upate(true); + sign.upate(); }; } if (__plugin.bukkit){