Skip to content

Commit

Permalink
Added utils.worlds() and utils.stat. enums
Browse files Browse the repository at this point in the history
  • Loading branch information
walterhiggins committed Oct 18, 2014
1 parent 9b10d51 commit eb8b78c
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 11 deletions.
20 changes: 18 additions & 2 deletions docs/API-Reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -2619,7 +2619,7 @@ This function returns a numeric value for a given player statistic.
#### Parameters
* Player - The player object
* Player - The player object (optional - if only the statistic name parameter is provided then the statistic object is returned)
* Statistic - A string whose value should be one of the following (CanaryMod)
* ANIMALSBRED
* BOATONECM
Expand Down Expand Up @@ -2650,10 +2650,26 @@ This function returns a numeric value for a given player statistic.
* TREASUREFISHED
* WALKONECM
See [CanaryMod's Statistic][cmstat] class for a list of possible stat values
See [CanaryMod's Statistic][cmstat] class for an up-to-date list of possible stat values
[cmstat]: https://ci.visualillusionsent.net/job/CanaryLib/javadoc/net/canarymod/api/statistics/Statistics.html
#### Example 1 Getting stats for a player
var utils = require('utils');
var jumpCount = utils.stat( player, 'jump');
#### Example 2 Getting the JUMP statistic object (which can be used elsewhere)
var utils = require('utils');
var JUMPSTAT = utils.stat('jump');
var jumpCount = player.getStat( JUMPSTAT ); // canary-specific code
This function also contains values for each possible stat so you can get at stats like this...
var utils = require('utils');
var JUMPSTAT = utils.stat.JUMP; // Accessing the value
var jumpCount = player.getStat ( JUMPSTAT ); // canary-specific code
## Drone Plugin
The Drone is a convenience class for building. It can be used for...
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.walterhiggins.scriptcraft;
package org.scriptcraftjs.bukkit;

import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
Expand All @@ -14,6 +14,8 @@

public class ScriptCraftPlugin extends JavaPlugin implements Listener
{
public boolean canary = false;
public boolean bukkit = true;
// right now all ops share the same JS context/scope
// need to look at possibly having context/scope per operator
//protected Map<CommandSender,ScriptCraftEvaluator> playerContexts = new HashMap<CommandSender,ScriptCraftEvaluator>();
Expand Down
62 changes: 54 additions & 8 deletions src/main/js/modules/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -749,10 +749,10 @@ function toArray( ){
exports.array = toArray;

function canaryWorlds(){
return toArray( server.worlds );
return toArray( server.worldManager.allWorlds );
}
function bukkitWorlds(){
return toArray( server.worldManager.allWorlds );
return toArray( server.worlds );
}
exports.worlds = __plugin.canary ? canaryWorlds : bukkitWorlds;

Expand Down Expand Up @@ -788,13 +788,43 @@ if (__plugin.canary) {
getPlayers = getPlayersBukkit;
}

function getStatBukkit(player, stat){
return player.getStatistic(org.bukkit.Statistic[stat.toUpperCase()]);
function getStatBukkit(){
if (arguments.length == 1){
var stat = arguments[1];
return org.bukkit.Statistic[stat.toUpperCase()];
} else {
var player = arguments[0];
var stat = arguments[1];
return player.getStatistic(org.bukkit.Statistic[stat.toUpperCase()]);
}

}
function getStatCanary(player, stat){
function getStatCanary(){
var cmStatistics = Packages.net.canarymod.api.statistics.Statistics;
return player.getStat(cmStatistics[stat.toUpperCase()].instance);
if (arguments.length == 1){
var stat = arguments[0];
return cmStatistics[stat.toUpperCase()].instance;
} else {
var player = arguments[0];
var stat = arguments[1];
return player.getStat(cmStatistics[stat.toUpperCase()].instance);
}
}
if (__plugin.canary){
var cmStatistics = Packages.net.canarymod.api.statistics.Statistics;
var values = cmStatistics.values();
for (var i = 0;i < values.length; i++){
var value = values[i];
try {
var stat = value.instance;
getStatCanary[value.name()] = stat;
}catch (e){
// as of 20141018 some calls to getInstance() will generate an NPE
// see https://github.com/CanaryModTeam/CanaryMod/issues/84
}
}
}

function getPlayerNames(){
return getPlayers().map(function(p){ return p.name; });
}
Expand All @@ -808,7 +838,7 @@ This function returns a numeric value for a given player statistic.
#### Parameters
* Player - The player object
* Player - The player object (optional - if only the statistic name parameter is provided then the statistic object is returned)
* Statistic - A string whose value should be one of the following (CanaryMod)
* ANIMALSBRED
* BOATONECM
Expand Down Expand Up @@ -839,9 +869,25 @@ This function returns a numeric value for a given player statistic.
* TREASUREFISHED
* WALKONECM
See [CanaryMod's Statistic][cmstat] class for a list of possible stat values
See [CanaryMod's Statistic][cmstat] class for an up-to-date list of possible stat values
[cmstat]: https://ci.visualillusionsent.net/job/CanaryLib/javadoc/net/canarymod/api/statistics/Statistics.html
#### Example 1 Getting stats for a player
var utils = require('utils');
var jumpCount = utils.stat( player, 'jump');
#### Example 2 Getting the JUMP statistic object (which can be used elsewhere)
var utils = require('utils');
var JUMPSTAT = utils.stat('jump');
var jumpCount = player.getStat( JUMPSTAT ); // canary-specific code
This function also contains values for each possible stat so you can get at stats like this...
var utils = require('utils');
var JUMPSTAT = utils.stat.JUMP; // Accessing the value
var jumpCount = player.getStat ( JUMPSTAT ); // canary-specific code
***/
exports.stat = __plugin.canary ? getStatCanary: getStatBukkit;

0 comments on commit eb8b78c

Please sign in to comment.