Skip to content

Commit eb8b78c

Browse files
committed
Added utils.worlds() and utils.stat. enums
1 parent 9b10d51 commit eb8b78c

File tree

3 files changed

+75
-11
lines changed

3 files changed

+75
-11
lines changed

docs/API-Reference.md

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2619,7 +2619,7 @@ This function returns a numeric value for a given player statistic.
26192619
26202620
#### Parameters
26212621
2622-
* Player - The player object
2622+
* Player - The player object (optional - if only the statistic name parameter is provided then the statistic object is returned)
26232623
* Statistic - A string whose value should be one of the following (CanaryMod)
26242624
* ANIMALSBRED
26252625
* BOATONECM
@@ -2650,10 +2650,26 @@ This function returns a numeric value for a given player statistic.
26502650
* TREASUREFISHED
26512651
* WALKONECM
26522652
2653-
See [CanaryMod's Statistic][cmstat] class for a list of possible stat values
2653+
See [CanaryMod's Statistic][cmstat] class for an up-to-date list of possible stat values
26542654
26552655
[cmstat]: https://ci.visualillusionsent.net/job/CanaryLib/javadoc/net/canarymod/api/statistics/Statistics.html
26562656
2657+
#### Example 1 Getting stats for a player
2658+
2659+
var utils = require('utils');
2660+
var jumpCount = utils.stat( player, 'jump');
2661+
2662+
#### Example 2 Getting the JUMP statistic object (which can be used elsewhere)
2663+
2664+
var utils = require('utils');
2665+
var JUMPSTAT = utils.stat('jump');
2666+
var jumpCount = player.getStat( JUMPSTAT ); // canary-specific code
2667+
2668+
This function also contains values for each possible stat so you can get at stats like this...
2669+
2670+
var utils = require('utils');
2671+
var JUMPSTAT = utils.stat.JUMP; // Accessing the value
2672+
var jumpCount = player.getStat ( JUMPSTAT ); // canary-specific code
26572673
## Drone Plugin
26582674
26592675
The Drone is a convenience class for building. It can be used for...

src/main/java/bukkit/org/scriptcraftjs/bukkit/ScriptCraftPlugin.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package net.walterhiggins.scriptcraft;
1+
package org.scriptcraftjs.bukkit;
22

33
import org.bukkit.command.Command;
44
import org.bukkit.command.CommandSender;
@@ -14,6 +14,8 @@
1414

1515
public class ScriptCraftPlugin extends JavaPlugin implements Listener
1616
{
17+
public boolean canary = false;
18+
public boolean bukkit = true;
1719
// right now all ops share the same JS context/scope
1820
// need to look at possibly having context/scope per operator
1921
//protected Map<CommandSender,ScriptCraftEvaluator> playerContexts = new HashMap<CommandSender,ScriptCraftEvaluator>();

src/main/js/modules/utils/utils.js

Lines changed: 54 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -749,10 +749,10 @@ function toArray( ){
749749
exports.array = toArray;
750750

751751
function canaryWorlds(){
752-
return toArray( server.worlds );
752+
return toArray( server.worldManager.allWorlds );
753753
}
754754
function bukkitWorlds(){
755-
return toArray( server.worldManager.allWorlds );
755+
return toArray( server.worlds );
756756
}
757757
exports.worlds = __plugin.canary ? canaryWorlds : bukkitWorlds;
758758

@@ -788,13 +788,43 @@ if (__plugin.canary) {
788788
getPlayers = getPlayersBukkit;
789789
}
790790

791-
function getStatBukkit(player, stat){
792-
return player.getStatistic(org.bukkit.Statistic[stat.toUpperCase()]);
791+
function getStatBukkit(){
792+
if (arguments.length == 1){
793+
var stat = arguments[1];
794+
return org.bukkit.Statistic[stat.toUpperCase()];
795+
} else {
796+
var player = arguments[0];
797+
var stat = arguments[1];
798+
return player.getStatistic(org.bukkit.Statistic[stat.toUpperCase()]);
799+
}
800+
793801
}
794-
function getStatCanary(player, stat){
802+
function getStatCanary(){
795803
var cmStatistics = Packages.net.canarymod.api.statistics.Statistics;
796-
return player.getStat(cmStatistics[stat.toUpperCase()].instance);
804+
if (arguments.length == 1){
805+
var stat = arguments[0];
806+
return cmStatistics[stat.toUpperCase()].instance;
807+
} else {
808+
var player = arguments[0];
809+
var stat = arguments[1];
810+
return player.getStat(cmStatistics[stat.toUpperCase()].instance);
811+
}
797812
}
813+
if (__plugin.canary){
814+
var cmStatistics = Packages.net.canarymod.api.statistics.Statistics;
815+
var values = cmStatistics.values();
816+
for (var i = 0;i < values.length; i++){
817+
var value = values[i];
818+
try {
819+
var stat = value.instance;
820+
getStatCanary[value.name()] = stat;
821+
}catch (e){
822+
// as of 20141018 some calls to getInstance() will generate an NPE
823+
// see https://github.com/CanaryModTeam/CanaryMod/issues/84
824+
}
825+
}
826+
}
827+
798828
function getPlayerNames(){
799829
return getPlayers().map(function(p){ return p.name; });
800830
}
@@ -808,7 +838,7 @@ This function returns a numeric value for a given player statistic.
808838
809839
#### Parameters
810840
811-
* Player - The player object
841+
* Player - The player object (optional - if only the statistic name parameter is provided then the statistic object is returned)
812842
* Statistic - A string whose value should be one of the following (CanaryMod)
813843
* ANIMALSBRED
814844
* BOATONECM
@@ -839,9 +869,25 @@ This function returns a numeric value for a given player statistic.
839869
* TREASUREFISHED
840870
* WALKONECM
841871
842-
See [CanaryMod's Statistic][cmstat] class for a list of possible stat values
872+
See [CanaryMod's Statistic][cmstat] class for an up-to-date list of possible stat values
843873
844874
[cmstat]: https://ci.visualillusionsent.net/job/CanaryLib/javadoc/net/canarymod/api/statistics/Statistics.html
845875
876+
#### Example 1 Getting stats for a player
877+
878+
var utils = require('utils');
879+
var jumpCount = utils.stat( player, 'jump');
880+
881+
#### Example 2 Getting the JUMP statistic object (which can be used elsewhere)
882+
883+
var utils = require('utils');
884+
var JUMPSTAT = utils.stat('jump');
885+
var jumpCount = player.getStat( JUMPSTAT ); // canary-specific code
886+
887+
This function also contains values for each possible stat so you can get at stats like this...
888+
889+
var utils = require('utils');
890+
var JUMPSTAT = utils.stat.JUMP; // Accessing the value
891+
var jumpCount = player.getStat ( JUMPSTAT ); // canary-specific code
846892
***/
847893
exports.stat = __plugin.canary ? getStatCanary: getStatBukkit;

0 commit comments

Comments
 (0)