Fixed bug in creating signs in canarymod and updated minigames/scoreboard to work with example code from book.

This commit is contained in:
walterhiggins 2014-10-12 18:34:40 +01:00
parent 70282e278d
commit 0866097411
4 changed files with 64 additions and 50 deletions

View file

@ -46,6 +46,7 @@
</target>
<target name="generate-api-ref-entries" depends="copy-js,compile-docs,init">
<java classname="jscript" failonerror="true" fork="true" output="${dist}/apiref.md">
<classpath>
<pathelement path="${build}"/>
@ -53,6 +54,7 @@
<arg value="src/docs/js/generateApiDocs.js"/>
<arg value="${dist}/js"/>
</java>
<java classname="jscript" failonerror="true" fork="true" output="${dist}/items.md" error="${dist}/genitemserror.log">
<classpath>
<pathelement path="${build}"/>
@ -60,10 +62,12 @@
</classpath>
<arg value="src/docs/js/generateItemsDoc.js"/>
</java>
<concat destfile="${dist}/apiref-con.md">
<fileset file="${dist}/apiref.md" />
<fileset file="${dist}/items.md" />
</concat>
</target>

View file

@ -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.

View file

@ -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;

View file

@ -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){