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