Skip to content

Commit

Permalink
Add level and change stat methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Spencer committed Oct 17, 2016
1 parent c713b56 commit ba3f4fa
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 9 deletions.
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
module.exports = require(`./lib/MineplexAPIWrapper`);
var MineplexAPIWrapper = require(`./lib/MineplexAPIWrapper`);
module.exports = MineplexAPIWrapper;
3 changes: 3 additions & 0 deletions lib/Errors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
NOT_FOUND: `Not found`
};
10 changes: 10 additions & 0 deletions lib/MineplexAPIWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ var ServerStatus = require('./ServerStatus');
var Player = require('./Player');
var Amplifiers = require('./Amplifier');

var log = require('frozor-logger');

class MineplexAPIWrapper{
constructor(apikey){
this.api = new MineplexAPI(apikey);
Expand Down Expand Up @@ -41,6 +43,14 @@ class MineplexAPIWrapper{

callback(true, new Player.Player(res));
});
};

getPlayerStats(player, callback){
this.getPlayerInfo(player, (success, res)=>{
if(!success) return callback(false, res);

callback(true, res.getStats());
});
}

getPlayerFriends(player, callback){
Expand Down
24 changes: 16 additions & 8 deletions lib/Player/Components/PlayerStats.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,39 @@ class PlayerStats{
for(var item in data){
var info = item.split('.');
var game = info[0];
var stat = info[1];
var stat = info.splice(1).join(' ');
var value = data[item];

this.addStat(game, stat, value);
}
}

getStats(game){
addStat(game, stat, value){
if(!this._stats[game]) this._stats[game] = {};
return this._stats[game];
this._stats[game][stat] = value;
}

getStat(game, stat){
var gameStats = this.getStats(game);
return (gameStats[stat]) ? gameStats[stat] : 0;
getStats(){
return this._stats;
}

addStat(game, stat, value){
getStatsForGame(game){
if(!this._stats[game]) this._stats[game] = {};
this._stats[game][stat] = value;
return this._stats[game];
}

getStatForGame(game, stat){
var gameStats = this.getStatsForGame(game);
return (gameStats[stat]) ? gameStats[stat] : 0;
}

toString(){
return JSON.stringify(this._stats);
}

toJSON(){
return this._stats;
}
}

module.exports = PlayerStats;
10 changes: 10 additions & 0 deletions lib/Player/Player.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ class Player extends PlayerComponents.Data{
this._accountId = data.accountId;
this._rank = data.rank;
this._lastLogin = new Date(data.lastLogin);
this._level = data.level;
this._levColor = data.levelColor;
this.status = new PlayerComponents.Status(data.playerStatus);
this.friends = new PlayerComponents.Friends(data.friends);
this.stats = new PlayerComponents.Stats(data.playerStats);
Expand Down Expand Up @@ -34,6 +36,14 @@ class Player extends PlayerComponents.Data{
getStats(){
return this.stats;
}

getLevel(){
return this._level;
}

getLevelColor(){
return this._levColor;
}
}

module.exports = Player;
11 changes: 11 additions & 0 deletions mineplex-api-wrapper.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$" />
<content url="file://$MODULE_DIR$/../mineplex-stats" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="jquery" level="application" />
</component>
</module>

0 comments on commit ba3f4fa

Please sign in to comment.