-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Spencer
committed
Oct 13, 2016
0 parents
commit c713b56
Showing
18 changed files
with
432 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# Created by .ignore support plugin (hsz.mobi) | ||
### Windows template | ||
# Windows image file caches | ||
Thumbs.db | ||
ehthumbs.db | ||
|
||
# Folder config file | ||
Desktop.ini | ||
|
||
# Recycle Bin used on file shares | ||
$RECYCLE.BIN/ | ||
|
||
# Windows Installer files | ||
*.cab | ||
*.msi | ||
*.msm | ||
*.msp | ||
|
||
# Windows shortcuts | ||
*.lnk | ||
### Node template | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
|
||
# nyc test coverage | ||
.nyc_output | ||
|
||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
# Compiled binary addons (http://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directories | ||
node_modules | ||
jspm_packages | ||
|
||
# Optional npm cache directory | ||
.npm | ||
|
||
# Optional REPL history | ||
.node_repl_history | ||
|
||
.idea/ | ||
api-test.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
module.exports = { | ||
base_url: 'http://api.mineplex.com:8081/', | ||
routes: { | ||
server: { | ||
url: 'server', | ||
token: false | ||
}, | ||
player: { | ||
url: 'player/', | ||
token: true | ||
}, | ||
'player.status': { | ||
url: 'player/', | ||
token: true | ||
}, | ||
'player.friends': { | ||
url: 'player/', | ||
token: true | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = require(`./lib/MineplexAPIWrapper`); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
var Player = require('../Player/'); | ||
|
||
class Amplifier extends Player.Components.Data{ | ||
constructor(data, group){ | ||
super(data, 'playerName'); | ||
this._group = group; | ||
this._duration = data.duration; | ||
this._activationTime = new Date(data.activationTime); | ||
this._startTime = new Date(data.startTime); | ||
this._endTime = new Date(data.endTime); | ||
this._multiplier = data.multiplier; | ||
} | ||
|
||
getGroup(){ | ||
return this._group; | ||
} | ||
|
||
getDuration(){ | ||
return this._duration; | ||
} | ||
|
||
getActivationTime(){ | ||
return this._activationTime; | ||
} | ||
|
||
getStartTime(){ | ||
return this._startTime; | ||
} | ||
|
||
getEndTime(){ | ||
return this._endTime; | ||
} | ||
|
||
isActive(){ | ||
var now = Date.now(); | ||
return (now >= this.getStartTime().getTime() && now <= this.getEndTime().getTime()); | ||
} | ||
|
||
getMultiplier(){ | ||
return this._multiplier; | ||
} | ||
} | ||
|
||
module.exports = Amplifier; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
var Amplifier = require('./Amplifier'); | ||
|
||
class AmplifierGroup{ | ||
constructor(data, group){ | ||
this._group = group; | ||
this._amplifiers = []; | ||
data.forEach((amplifier)=>{ | ||
this._amplifiers.push(new Amplifier(amplifier)); | ||
}); | ||
} | ||
|
||
getGroup(){ | ||
return this._group; | ||
} | ||
|
||
getAmplifiers(){ | ||
return this._amplifiers; | ||
} | ||
} | ||
|
||
module.exports = AmplifierGroup; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
var AmplifierGroup = require('./AmplifierGroup'); | ||
|
||
class AmplifierGroups{ | ||
constructor(data){ | ||
this._groups = {}; | ||
for(var group in data){ | ||
groups[group] = new AmplifierGroup(data[group], group); | ||
} | ||
} | ||
|
||
getGroups(){ | ||
return this._groups; | ||
} | ||
|
||
getGroup(group){ | ||
return this._groups[group]; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
exports.Amplifier = require('./Amplifier'); | ||
|
||
exports.AmplifierGroup = require('./AmplifierGroup'); | ||
|
||
exports.AmplifierGroups = require('./AmplifierGroups'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
var MineplexAPI = require('../../mineplex-api'); | ||
var ServerStatus = require('./ServerStatus'); | ||
var Player = require('./Player'); | ||
var Amplifiers = require('./Amplifier'); | ||
|
||
class MineplexAPIWrapper{ | ||
constructor(apikey){ | ||
this.api = new MineplexAPI(apikey); | ||
} | ||
|
||
getServerStatus(callback){ | ||
this.api.get.server((success, res)=>{ | ||
if(!success) return callback(false, res); | ||
|
||
var status = new ServerStatus(res); | ||
callback(true, status); | ||
}); | ||
} | ||
|
||
getServerTotal(callback){ | ||
this.api.get.server((success, res)=>{ | ||
if(!success) return callback(false, res); | ||
|
||
var status = new ServerStatus(res); | ||
callback(true, status.getTotal()); | ||
}); | ||
} | ||
|
||
getServerGroups(callback){ | ||
this.api.get.server((success, res)=>{ | ||
if(!success) return callback(false, res); | ||
|
||
var status = new ServerStatus(res); | ||
callback(true, status.getGroups()); | ||
}); | ||
} | ||
|
||
getPlayerInfo(player, callback){ | ||
this.api.get.player.info(player, (success, res)=>{ | ||
if(!success) return callback(false, res); | ||
|
||
callback(true, new Player.Player(res)); | ||
}); | ||
} | ||
|
||
getPlayerFriends(player, callback){ | ||
this.api.get.player.friends(player, (success, res)=>{ | ||
if(!success) return callback(false, res); | ||
|
||
callback(true, new Player.Components.Friends(res)); | ||
}); | ||
} | ||
|
||
getPlayerStatus(player, callback){ | ||
this.api.get.player.status(player, (success, res)=>{ | ||
if(!success) return callback(false, res); | ||
|
||
callback(true, new Player.Components.Status(res)); | ||
}); | ||
} | ||
|
||
getAmplifierGroups(callback){ | ||
this.api.get.amplifierGroup((success, res)=>{ | ||
if(!success) return callback(false, res); | ||
|
||
callback(true, res); | ||
}); | ||
} | ||
|
||
getAmplifiers(callback){ | ||
this.api.get.amplifier.all((success, res)=>{ | ||
if(!success) return callback(false, res); | ||
|
||
callback(true, new Amplifiers.AmplifierGroups(res)); | ||
}); | ||
} | ||
|
||
getAmplifiersForGroup(group, callback){ | ||
this.api.get.amplifier.specific(group, (success, res)=>{ | ||
if(!success) return callback(false, res); | ||
|
||
callback(true, new Amplifiers.AmplifierGroup(res)); | ||
}); | ||
} | ||
} | ||
|
||
module.exports = MineplexAPIWrapper; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
class PlayerData{ | ||
constructor(data, nameKey){ | ||
this._uuid = data.uuid; | ||
this._name = (nameKey) ? data[nameKey] : data.name; | ||
} | ||
|
||
getUUID(){ | ||
return this._uuid; | ||
} | ||
|
||
getName(){ | ||
return this._name; | ||
} | ||
} | ||
|
||
module.exports = PlayerData; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
class PlayerFriends{ | ||
constructor(data){ | ||
this._friends = data; | ||
} | ||
|
||
getFriends(){ | ||
return this._friends; | ||
} | ||
|
||
isFriend(player){ | ||
return (this._friends.indexOf(player) > -1); | ||
} | ||
|
||
getAmount(){ | ||
return this._friends.length; | ||
} | ||
} | ||
|
||
module.exports = PlayerFriends; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
class PlayerStats{ | ||
constructor(data){ | ||
this._stats = {}; | ||
|
||
for(var item in data){ | ||
var info = item.split('.'); | ||
var game = info[0]; | ||
var stat = info[1]; | ||
var value = data[item]; | ||
|
||
this.addStat(game, stat, value); | ||
} | ||
} | ||
|
||
getStats(game){ | ||
if(!this._stats[game]) this._stats[game] = {}; | ||
return this._stats[game]; | ||
} | ||
|
||
getStat(game, stat){ | ||
var gameStats = this.getStats(game); | ||
return (gameStats[stat]) ? gameStats[stat] : 0; | ||
} | ||
|
||
addStat(game, stat, value){ | ||
if(!this._stats[game]) this._stats[game] = {}; | ||
this._stats[game][stat] = value; | ||
} | ||
|
||
toString(){ | ||
return JSON.stringify(this._stats); | ||
} | ||
} | ||
|
||
module.exports = PlayerStats; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/** | ||
* Created by Spencer on 10/12/2016. | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
class PlayerStatus{ | ||
constructor(data){ | ||
this._online = data.online; | ||
this._server = data.server; | ||
} | ||
|
||
isOnline(){ | ||
return this._online; | ||
} | ||
|
||
getServer(){ | ||
return this._server; | ||
} | ||
|
||
toString(){ | ||
return (this._online) ? `online` : `offline`; | ||
} | ||
} | ||
|
||
module.exports = PlayerStatus; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
exports.Friends = require('./PlayerFriends'); | ||
exports.Stats = require('./PlayerStats'); | ||
exports.Status = require('./PlayerStatus'); | ||
exports.Data = require('./PlayerData'); |
Oops, something went wrong.