Fixed bug in creating signs in canarymod and updated minigames/scoreboard to work with example code from book.
This commit is contained in:
parent
70282e278d
commit
0866097411
4 changed files with 64 additions and 50 deletions
|
@ -46,6 +46,7 @@
|
||||||
</target>
|
</target>
|
||||||
|
|
||||||
<target name="generate-api-ref-entries" depends="copy-js,compile-docs,init">
|
<target name="generate-api-ref-entries" depends="copy-js,compile-docs,init">
|
||||||
|
|
||||||
<java classname="jscript" failonerror="true" fork="true" output="${dist}/apiref.md">
|
<java classname="jscript" failonerror="true" fork="true" output="${dist}/apiref.md">
|
||||||
<classpath>
|
<classpath>
|
||||||
<pathelement path="${build}"/>
|
<pathelement path="${build}"/>
|
||||||
|
@ -53,6 +54,7 @@
|
||||||
<arg value="src/docs/js/generateApiDocs.js"/>
|
<arg value="src/docs/js/generateApiDocs.js"/>
|
||||||
<arg value="${dist}/js"/>
|
<arg value="${dist}/js"/>
|
||||||
</java>
|
</java>
|
||||||
|
|
||||||
<java classname="jscript" failonerror="true" fork="true" output="${dist}/items.md" error="${dist}/genitemserror.log">
|
<java classname="jscript" failonerror="true" fork="true" output="${dist}/items.md" error="${dist}/genitemserror.log">
|
||||||
<classpath>
|
<classpath>
|
||||||
<pathelement path="${build}"/>
|
<pathelement path="${build}"/>
|
||||||
|
@ -60,10 +62,12 @@
|
||||||
</classpath>
|
</classpath>
|
||||||
<arg value="src/docs/js/generateItemsDoc.js"/>
|
<arg value="src/docs/js/generateItemsDoc.js"/>
|
||||||
</java>
|
</java>
|
||||||
|
|
||||||
<concat destfile="${dist}/apiref-con.md">
|
<concat destfile="${dist}/apiref-con.md">
|
||||||
<fileset file="${dist}/apiref.md" />
|
<fileset file="${dist}/apiref.md" />
|
||||||
<fileset file="${dist}/items.md" />
|
<fileset file="${dist}/items.md" />
|
||||||
</concat>
|
</concat>
|
||||||
|
|
||||||
</target>
|
</target>
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -198,6 +198,8 @@ Walter Higgins
|
||||||
* [utils.unwatchFile() function](#utilsunwatchfile-function)
|
* [utils.unwatchFile() function](#utilsunwatchfile-function)
|
||||||
* [utils.unwatchDir() function](#utilsunwatchdir-function)
|
* [utils.unwatchDir() function](#utilsunwatchdir-function)
|
||||||
* [utils.array() function](#utilsarray-function)
|
* [utils.array() function](#utilsarray-function)
|
||||||
|
* [utils.players() function](#utilsplayers-function)
|
||||||
|
* [utils.playerNames() function](#utilsplayernames-function)
|
||||||
* [utils.stat() function](#utilsstat-function)
|
* [utils.stat() function](#utilsstat-function)
|
||||||
* [Drone Plugin](#drone-plugin)
|
* [Drone Plugin](#drone-plugin)
|
||||||
* [Constructing a Drone Object](#constructing-a-drone-object)
|
* [Constructing a Drone Object](#constructing-a-drone-object)
|
||||||
|
@ -2603,6 +2605,14 @@ all of Javascript's Array goodness.
|
||||||
var utils = require('utils');
|
var utils = require('utils');
|
||||||
var worlds = utils.array(server.worlds);
|
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
|
### utils.stat() function
|
||||||
|
|
||||||
This function returns a numeric value for a given player statistic.
|
This function returns a numeric value for a given player statistic.
|
||||||
|
|
|
@ -1,50 +1,50 @@
|
||||||
var bkDisplaySlot = org.bukkit.scoreboard.DisplaySlot;
|
var textcolors = require('textcolors');
|
||||||
/*
|
var Canary = Packages.net.canarymod.Canary;
|
||||||
The scoreboard is a simple wrapper around the Bukkit Scoreboard API.
|
var sb = Canary.scoreboards().getScoreboard();
|
||||||
It's only concerned with display of scores, not maintaining them - that's the game's job.
|
function execCommand( command ){
|
||||||
*/
|
server.executeVanillaCommand(server, command);
|
||||||
module.exports = function( options ) {
|
}
|
||||||
var temp = {};
|
function getTeamByName( teamName ){
|
||||||
var ccScoreboard;
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
function updatePlayerScore( objectiveName, playerName, score ){
|
||||||
start: function( ) {
|
var sc = sb['getScore(String, ScoreObjective)']( playerName, sb.getScoreObjective( objectiveName) );
|
||||||
var objective,
|
sc.score = score;
|
||||||
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 ];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function removeTeamFromScoreboard( teamName ){
|
||||||
|
execCommand('scoreboard teams remove ' + teamName);
|
||||||
|
//sb['removeTeam(String)'](teamName);
|
||||||
}
|
}
|
||||||
},
|
exports.create = createScoreboard;
|
||||||
stop: function(){
|
exports.addTeam = addTeamToScoreboard;
|
||||||
var objective, slot;
|
exports.removeTeam = removeTeamFromScoreboard;
|
||||||
for ( objective in options ) {
|
exports.addPlayerToTeam = addPlayerToTeam;
|
||||||
ccScoreboard.getObjective(objective).unregister();
|
exports.updateScore = updatePlayerScore;
|
||||||
for ( slot in options[ objective ] ) {
|
exports.remove = removeScoreboard;
|
||||||
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 ];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
|
@ -611,7 +611,7 @@ var putSign = function( drone, x, y, z, world, texts, blockId, meta, immediate )
|
||||||
setLine = function( block, i, text) {
|
setLine = function( block, i, text) {
|
||||||
var sign = block.getTileEntity();
|
var sign = block.getTileEntity();
|
||||||
sign.setTextOnLine( text, i );
|
sign.setTextOnLine( text, i );
|
||||||
sign.upate(true);
|
sign.upate();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
if (__plugin.bukkit){
|
if (__plugin.bukkit){
|
||||||
|
|
Reference in a new issue