@@ -749,10 +749,10 @@ function toArray( ){
749
749
exports . array = toArray ;
750
750
751
751
function canaryWorlds ( ) {
752
- return toArray ( server . worlds ) ;
752
+ return toArray ( server . worldManager . allWorlds ) ;
753
753
}
754
754
function bukkitWorlds ( ) {
755
- return toArray ( server . worldManager . allWorlds ) ;
755
+ return toArray ( server . worlds ) ;
756
756
}
757
757
exports . worlds = __plugin . canary ? canaryWorlds : bukkitWorlds ;
758
758
@@ -788,13 +788,43 @@ if (__plugin.canary) {
788
788
getPlayers = getPlayersBukkit ;
789
789
}
790
790
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
+
793
801
}
794
- function getStatCanary ( player , stat ) {
802
+ function getStatCanary ( ) {
795
803
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
+ }
797
812
}
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
+
798
828
function getPlayerNames ( ) {
799
829
return getPlayers ( ) . map ( function ( p ) { return p . name ; } ) ;
800
830
}
@@ -808,7 +838,7 @@ This function returns a numeric value for a given player statistic.
808
838
809
839
#### Parameters
810
840
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)
812
842
* Statistic - A string whose value should be one of the following (CanaryMod)
813
843
* ANIMALSBRED
814
844
* BOATONECM
@@ -839,9 +869,25 @@ This function returns a numeric value for a given player statistic.
839
869
* TREASUREFISHED
840
870
* WALKONECM
841
871
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
843
873
844
874
[cmstat]: https://ci.visualillusionsent.net/job/CanaryLib/javadoc/net/canarymod/api/statistics/Statistics.html
845
875
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
846
892
***/
847
893
exports . stat = __plugin . canary ? getStatCanary : getStatBukkit ;
0 commit comments