servertap-js
Version:
A TypeScript library for working with the ServerTap API
3 lines (2 loc) • 2.9 kB
JavaScript
import e from"isomorphic-unfetch";function r(){return r=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var s in t)Object.prototype.hasOwnProperty.call(t,s)&&(e[s]=t[s])}return e},r.apply(this,arguments)}class t{constructor(e){this.apiKey=void 0,this.baseUrl=void 0,this.apiKey=e.apiKey,this.baseUrl=e.baseUrl||"https://dev.to/api/"}request(t,s,o="application/json"){const a=this.baseUrl+"/v1"+t,i=r({},s,{headers:{"Content-type":o,"api-key":this.apiKey}});return e(a,i).then(e=>{if(e.ok)return e.json();switch(e.status){case 404:throw new Error("Not found");case 400:throw new Error("Bad request")}})}}class s extends t{}var o;o=s,[class extends t{getAllPlayers(){return this.request("/players/all")}getPlayers(){return this.request("/players")}getOps(){return this.request("/server/ops")}addOp(e){return this.request("/server/ops",{method:"POST",body:`playerUuid=${e}`},"application/x-www-form-urlencoded")}removeOp(e){return this.request("/server/ops",{method:"DELETE",body:`playerUuid=${e}`},"application/x-www-form-urlencoded")}getPlayer(e){return this.request(`/players/${e}`)}getPlayerInventory(e,r){return this.request(`/players/${e}/${r}/inventory`)}},class extends t{ping(){return this.request("/ping")}getServer(){return this.request("/server")}execCommand(e){return e.startsWith("/")&&(e=e.substring(1)),this.request("/server/exec",{method:"POST",body:`command=${e}`},"application/x-www-form-urlencoded")}getWhitelist(){return this.request("/server/whitelist")}addWhitelist(e,r){return this.request("/server/whitelist",{method:"POST",body:`uuid=${e}&name=${r}`},"application/x-www-form-urlencoded")}getWorlds(){return this.request("/worlds")}saveWorld(e){return this.request(`/worlds/${e}/save`,{method:"POST"})}getScoreBoards(){return this.request("/scoreboard")}getScoreBoard(e){return this.request(`/scoreboard/${e}`)}},class extends t{broadcast(e){return this.request("/chat/broadcast",{method:"POST",body:`message=${e}`},"application/x-www-form-urlencoded")}tell(e,r){return this.request("/chat/tell",{method:"POST",body:`playerUuid=${e}&message=${r}`},"application/x-www-form-urlencoded")}},class extends t{pay(e,r){return this.request("/economy/pay",{method:"POST",body:`uuid=${e}&amount=${r}`},"application/x-www-form-urlencoded")}debit(e,r){return this.request("/economy/debit",{method:"POST",body:`uuid=${e}&amount=${r}`},"application/x-www-form-urlencoded")}economy(){return this.request("/economy")}},class extends t{replace(e,r){return this.request("/placeholder/replace",{method:"POST",body:`message=${e},uuid=${r}`},"application/x-www-form-urlencoded")}},class extends t{getPlugins(){return this.request("/plugins")}}].forEach(e=>{Object.getOwnPropertyNames(e.prototype).forEach(r=>{Object.defineProperty(o.prototype,r,Object.getOwnPropertyDescriptor(e.prototype,r))})});export{s as default};
//# sourceMappingURL=index.modern.js.map