From 2013b3b07cfb4e537724d45541abd40c362b2b27 Mon Sep 17 00:00:00 2001 From: MiaoWoo Date: Sat, 9 Mar 2019 10:29:47 +0800 Subject: [PATCH] style: code format Signed-off-by: MiaoWoo --- src/main/resources/plugins/ItemTag.js | 4 ++ src/main/resources/plugins/MiaoBoard.js | 25 ++++++++--- src/main/resources/plugins/MiaoChat.js | 10 ++--- src/main/resources/plugins/bukkit/Lottery.js | 45 ++++++++++++-------- 4 files changed, 54 insertions(+), 30 deletions(-) diff --git a/src/main/resources/plugins/ItemTag.js b/src/main/resources/plugins/ItemTag.js index 80b2657..b825644 100644 --- a/src/main/resources/plugins/ItemTag.js +++ b/src/main/resources/plugins/ItemTag.js @@ -74,6 +74,10 @@ function getItemCount(amount) { return amount === 1 ? "" : "*" + amount; } +function disable() { + console.log('卸载', description.name, '插件!'); +} + module.exports = { description: description, load: load, diff --git a/src/main/resources/plugins/MiaoBoard.js b/src/main/resources/plugins/MiaoBoard.js index 241f816..01789ee 100644 --- a/src/main/resources/plugins/MiaoBoard.js +++ b/src/main/resources/plugins/MiaoBoard.js @@ -84,9 +84,7 @@ function enable() { registerCommand(); registerEvent(); registerTask(); - server.players(function (player) { - boards[player.name] = new MiaoBoard(player); - }) + updatePlayers() } function registerCommand() { @@ -110,7 +108,7 @@ function mainCommand(sender, command, args) { function registerEvent() { switch (DetectServerType) { case ServerType.Bukkit: - event.on(self, 'PlayerLoginEvent', handlerPlayerJoin); + //event.on(self, 'PlayerLoginEvent', handlerPlayerJoin); break; case ServerType.Sponge: Player = org.spongepowered.api.entity.living.player.Player; @@ -120,6 +118,19 @@ function registerEvent() { } } +function updatePlayers() { + switch (DetectServerType) { + case ServerType.Bukkit: + //event.on(self, 'PlayerLoginEvent', handlerPlayerJoin); + break; + case ServerType.Sponge: + server.players(function(player) { + boards[player.name] = new MiaoBoard(player); + }) + break; + } +} + function handlerPlayerJoin(event) { var player = event.player || event.targetEntity; boards[player.name] = new MiaoBoard(player); @@ -180,11 +191,11 @@ function MiaoBoard(player) { scoreboard.addObjective(sidebar); player.setScoreboard(scoreboard); - this.update = function (title, lines) { + this.update = function(title, lines) { this.updateBuffer(title, lines); } - this.updateBuffer = function (title, lines) { + this.updateBuffer = function(title, lines) { sidebar.scores.values().forEach(function removeScore(score) { sidebar.removeScore(score); }) @@ -196,7 +207,7 @@ function MiaoBoard(player) { scoreboard.updateDisplaySlot(sidebar, DisplaySlots.SIDEBAR); } - this.clear = function () { + this.clear = function() { player.setScoreboard(Scoreboard.builder().build()); } } diff --git a/src/main/resources/plugins/MiaoChat.js b/src/main/resources/plugins/MiaoChat.js index 1eea30c..3048d87 100644 --- a/src/main/resources/plugins/MiaoChat.js +++ b/src/main/resources/plugins/MiaoChat.js @@ -41,14 +41,14 @@ var description = { "index": 50, "permission": "MiaoChat.default", "range": 0, - "format": "[world][player]: ", + "format": "[world][player]&7: ", "item": true, "itemformat": "&6[&b%s&6]&r" }, "admin": { "index": 49, "permission": "MiaoChat.admin", - "format": "[admin][world][player][help]: ", + "format": "[admin][world][player][help]&7: ", "range": 0, "item": true, "itemformat": "&6[&b%s&6]&r" @@ -116,7 +116,7 @@ function load() { var FORMAT_PATTERN = /[\[]([^\[\]]+)[\]]/ig; function initFormat(chat_formats) { - chat_formats.forEach(function (chat_format) { + chat_formats.forEach(function(chat_format) { var chat_format_str = chat_format.format; var temp = []; var r; @@ -168,7 +168,7 @@ function registerEvent() { } function handlerBukkitChat(event) { - sendChat(event.player, event.message, function () { + sendChat(event.player, event.message, function() { event.setCancelled(true); }); } @@ -182,7 +182,7 @@ function handlerSpongeChat(event) { if (plain.startsWith(tellraw.duplicateChar)) { return; } - sendChat(player, plain, function () { + sendChat(player, plain, function() { event.setMessageCancelled(true) }); } diff --git a/src/main/resources/plugins/bukkit/Lottery.js b/src/main/resources/plugins/bukkit/Lottery.js index 389dd10..37731fb 100644 --- a/src/main/resources/plugins/bukkit/Lottery.js +++ b/src/main/resources/plugins/bukkit/Lottery.js @@ -10,11 +10,13 @@ var bukkit = require('api/server'); var item = require('api/item'); var Arrays = Java.type('java.util.Arrays'); +var Material = Java.type('org.bukkit.Material'); var ItemStackArray = Java.type('org.bukkit.inventory.ItemStack[]'); var description = { name: 'Lottery', version: '1.0', + author: 'MiaoWoo', commands: { 'lottery': { description: 'Lottery主命令' @@ -22,11 +24,15 @@ var description = { }, config: { title: '§m§s§a幸运抽奖', - panel: '160:13', + control: { + panel: 'GLASS_PANE:13', + ok: 'GLASS_PANE:14', + no: 'GLASS_PANE:15', + }, list: [ { box: { - id: 160, + id: 'GLASS_PANE', damage: 1, name: '§a箱子', lore: [ @@ -34,7 +40,7 @@ var description = { ] }, key: { - id: 160, + id: 'GLASS_PANE', damage: 2, name: '§b钥匙', lore: [ @@ -46,7 +52,7 @@ var description = { percent: 10, command: 'money give %player% 100', item: { - id: 160, + id: 'GLASS_PANE', damage: 3, name: '§c奖品1', lore: [ @@ -58,7 +64,7 @@ var description = { percent: 20, command: 'money give %player% 200', item: { - id: 160, + id: 'GLASS_PANE', damage: 4, name: '§c奖品2', lore: [ @@ -72,25 +78,19 @@ var description = { } }; -var panel = item.create(160, 1, 13); +var panel; var config; var items; function load() { + panel = item.create('GLASS_PANE', 1, 13); config = this.config; - if (config.panel) { - var arr = config.panel.split(':'); - if (arr.length === 2) { - panel = newItem(arr[0], arr[1]); - } else { - panel = newItem(arr[0]); - } - } + panel = newItemFromString(config.control.panel || 'GLASS_PANE:13') items = new ItemStackArray(54); item.setName(panel, ''); - var ok = newItem(160, 14); + var ok = newItemFromString(config.control.ok || 'GLASS_PANE:14') item.setName(ok, '§a确定抽奖'); - var no = newItem(160, 15); + var no = newItemFromString(config.control.no || 'GLASS_PANE:15') item.setName(no, '§c取消抽奖'); Arrays.fill(items, 0, 10, panel); Arrays.fill(items, 11, 16, panel); @@ -113,6 +113,15 @@ function newItem(name, sub) { return item.create(name, 1, sub || 0); } +function newItemFromString(str) { + var arr = str.split(':'); + if (arr.length === 2) { + return newItem(arr[0], arr[1]); + } else { + return newItem(arr[0]); + } +} + function newItemFromConfig(config) { var i = newItem(config.id, config.damage); if (config.name) item.setName(i, config.name); @@ -123,7 +132,7 @@ function newItemFromConfig(config) { function enable() { // noinspection JSUnusedLocalSymbols command.on(this, 'l', { - cmd: function (sender, command, args) { + cmd: function(sender, command, args) { if (!sender.openInventory) { console.sender(sender, "§4当前用户无法使用该命令!"); } @@ -180,7 +189,7 @@ function enable() { return; } var resultList = []; - litem.result.forEach(function (t) { + litem.result.forEach(function(t) { for (var i = 0; i < t.percent; i++) { resultList.push(t); }