UNPKG

@ccms/api

Version:

MiaoScript api package

196 lines 8.74 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.proxy = void 0; var tslib_1 = require("tslib"); var container_1 = require("@ccms/container"); var channel_1 = require("./channel"); var proxy; (function (proxy) { var ByteArrayOutputStream = Java.type('java.io.ByteArrayOutputStream'); var DataOutputStream = Java.type('java.io.DataOutputStream'); var bungeecord; (function (bungeecord) { var CHANNEL_NAME = "BungeeCord"; var SubChannelBuilder = /** @class */ (function () { function SubChannelBuilder(channel, player) { this.channel = channel; this.player = player; this.params = []; } SubChannelBuilder.prototype.connect = function (server) { this.params.push("Connect"); this.params.push(server); return this.finalSend(); }; SubChannelBuilder.prototype.connectOther = function (player, server) { this.params.push("ConnectOther"); this.params.push(player); this.params.push(server); return this.finalSend(); }; SubChannelBuilder.prototype.ip = function () { this.params.push("IP"); return this.finalSend(); }; SubChannelBuilder.prototype.ipOther = function (player) { this.params.push("IPOther"); this.params.push(player); return this.finalSend(); }; SubChannelBuilder.prototype.playerCount = function (server) { this.params.push("PlayerCount"); this.params.push(server); return this.finalSend(); }; /** * Get a list of players connected on a certain server, or on ALL the servers. * @param server count server * Response: * String server = in.readUTF(); // The name of the server you got the player list of, as given in args. * String[] playerList = in.readUTF().split(", "); */ SubChannelBuilder.prototype.playerList = function (server) { this.params.push("PlayerList"); this.params.push(server); return this.finalSend(); }; /** * Get a list of server name strings, as defined in BungeeCord's config.yml * Response: * String[] serverList = in.readUTF().split(", "); */ SubChannelBuilder.prototype.getServers = function () { this.params.push("GetServers"); return this.finalSend(); }; /** * Get this server's name, as defined in BungeeCord's config.yml */ SubChannelBuilder.prototype.getServer = function () { this.params.push("GetServer"); return this.finalSend(); }; SubChannelBuilder.prototype.broadcast = function (message) { this.message("ALL", message); return this.finalSend(); }; /** * Send a message (as in, a chat message) to the specified player. * @param player who reciver message * @param message message content */ SubChannelBuilder.prototype.message = function (player, message) { this.params.push("Message"); this.params.push(player); this.params.push(message); return this.finalSend(); }; /** * Send a raw message (as in, a chat message) to the specified player. The advantage of this method over Message is that you can include click events and hover events. * @param player who reciver message * @param message message content */ SubChannelBuilder.prototype.messageRaw = function (player, json) { this.params.push("MessageRaw"); this.params.push(player); this.params.push(json); return this.finalSend(); }; SubChannelBuilder.prototype.forwardAll = function (channel, data) { return this.forward("ALL", channel, data); }; /** * Send a custom plugin message to said server. This is one of the most useful channels ever. * Remember, the sending and receiving server(s) need to have a player online. * @param server reciver * @param channel channelName * @param data data */ SubChannelBuilder.prototype.forward = function (server, channel, data) { this.params.push("Forward"); this.params.push(server); this.params.push(channel); this.params.push(typeof data === "string" ? data : JSON.stringify(data)); return this.finalSend(); }; /** * Send a custom plugin message to said server. This is one of the most useful channels ever. * Remember, the sending and receiving server(s) need to have a player online. * @param server reciver * @param channel channelName * @param data data */ SubChannelBuilder.prototype.forwardToPlayer = function (server, channel, data) { this.params.push("Forward"); this.params.push(server); this.params.push(channel); this.params.push(typeof data === "string" ? data : JSON.stringify(data)); return this.finalSend(); }; SubChannelBuilder.prototype.generic = function () { var _a; var args = []; for (var _i = 0; _i < arguments.length; _i++) { args[_i] = arguments[_i]; } args && (_a = this.params).concat.apply(_a, tslib_1.__spreadArray([], tslib_1.__read(args), false)); return this.finalSend(); }; SubChannelBuilder.prototype.send = function () { var e_1, _a; var middlewares = []; for (var _i = 0; _i < arguments.length; _i++) { middlewares[_i] = arguments[_i]; } var byteArray = new ByteArrayOutputStream(); var out = new DataOutputStream(byteArray); this.params.forEach(function (utf) { return out.writeUTF(utf); }); try { for (var middlewares_1 = tslib_1.__values(middlewares), middlewares_1_1 = middlewares_1.next(); !middlewares_1_1.done; middlewares_1_1 = middlewares_1.next()) { var middleware = middlewares_1_1.value; middleware(out); } } catch (e_1_1) { e_1 = { error: e_1_1 }; } finally { try { if (middlewares_1_1 && !middlewares_1_1.done && (_a = middlewares_1.return)) _a.call(middlewares_1); } finally { if (e_1) throw e_1.error; } } return this.channel.send(this.player, CHANNEL_NAME, byteArray.toByteArray()); }; SubChannelBuilder.prototype.finalSend = function () { return { send: this.send.bind(this) }; }; return SubChannelBuilder; }()); bungeecord.SubChannelBuilder = SubChannelBuilder; })(bungeecord || (bungeecord = {})); var BungeeCord = /** @class */ (function () { function BungeeCord() { } BungeeCord_1 = BungeeCord; /** * 获得代理 * @param player 玩家 */ BungeeCord.prototype.for = function (player) { return new bungeecord.SubChannelBuilder(this.channel, player); }; var BungeeCord_1; tslib_1.__decorate([ (0, container_1.optional)(), (0, container_1.Autowired)(), tslib_1.__metadata("design:type", channel_1.channel.Channel) ], BungeeCord.prototype, "channel", void 0); BungeeCord = BungeeCord_1 = tslib_1.__decorate([ (0, container_1.provideSingleton)(BungeeCord_1) ], BungeeCord); return BungeeCord; }()); proxy.BungeeCord = BungeeCord; })(proxy = exports.proxy || (exports.proxy = {})); //# sourceMappingURL=proxy.js.map