style: code format

Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
MiaoWoo 2019-03-09 10:29:47 +08:00
parent 2dff086a01
commit 2013b3b07c
4 changed files with 54 additions and 30 deletions

View File

@ -74,6 +74,10 @@ function getItemCount(amount) {
return amount === 1 ? "" : "*" + amount; return amount === 1 ? "" : "*" + amount;
} }
function disable() {
console.log('卸载', description.name, '插件!');
}
module.exports = { module.exports = {
description: description, description: description,
load: load, load: load,

View File

@ -84,9 +84,7 @@ function enable() {
registerCommand(); registerCommand();
registerEvent(); registerEvent();
registerTask(); registerTask();
server.players(function (player) { updatePlayers()
boards[player.name] = new MiaoBoard(player);
})
} }
function registerCommand() { function registerCommand() {
@ -110,7 +108,7 @@ function mainCommand(sender, command, args) {
function registerEvent() { function registerEvent() {
switch (DetectServerType) { switch (DetectServerType) {
case ServerType.Bukkit: case ServerType.Bukkit:
event.on(self, 'PlayerLoginEvent', handlerPlayerJoin); //event.on(self, 'PlayerLoginEvent', handlerPlayerJoin);
break; break;
case ServerType.Sponge: case ServerType.Sponge:
Player = org.spongepowered.api.entity.living.player.Player; 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) { function handlerPlayerJoin(event) {
var player = event.player || event.targetEntity; var player = event.player || event.targetEntity;
boards[player.name] = new MiaoBoard(player); boards[player.name] = new MiaoBoard(player);
@ -180,11 +191,11 @@ function MiaoBoard(player) {
scoreboard.addObjective(sidebar); scoreboard.addObjective(sidebar);
player.setScoreboard(scoreboard); player.setScoreboard(scoreboard);
this.update = function (title, lines) { this.update = function(title, lines) {
this.updateBuffer(title, lines); this.updateBuffer(title, lines);
} }
this.updateBuffer = function (title, lines) { this.updateBuffer = function(title, lines) {
sidebar.scores.values().forEach(function removeScore(score) { sidebar.scores.values().forEach(function removeScore(score) {
sidebar.removeScore(score); sidebar.removeScore(score);
}) })
@ -196,7 +207,7 @@ function MiaoBoard(player) {
scoreboard.updateDisplaySlot(sidebar, DisplaySlots.SIDEBAR); scoreboard.updateDisplaySlot(sidebar, DisplaySlots.SIDEBAR);
} }
this.clear = function () { this.clear = function() {
player.setScoreboard(Scoreboard.builder().build()); player.setScoreboard(Scoreboard.builder().build());
} }
} }

View File

@ -41,14 +41,14 @@ var description = {
"index": 50, "index": 50,
"permission": "MiaoChat.default", "permission": "MiaoChat.default",
"range": 0, "range": 0,
"format": "[world][player]: ", "format": "[world][player]&7: ",
"item": true, "item": true,
"itemformat": "&6[&b%s&6]&r" "itemformat": "&6[&b%s&6]&r"
}, },
"admin": { "admin": {
"index": 49, "index": 49,
"permission": "MiaoChat.admin", "permission": "MiaoChat.admin",
"format": "[admin][world][player][help]: ", "format": "[admin][world][player][help]&7: ",
"range": 0, "range": 0,
"item": true, "item": true,
"itemformat": "&6[&b%s&6]&r" "itemformat": "&6[&b%s&6]&r"
@ -116,7 +116,7 @@ function load() {
var FORMAT_PATTERN = /[\[]([^\[\]]+)[\]]/ig; var FORMAT_PATTERN = /[\[]([^\[\]]+)[\]]/ig;
function initFormat(chat_formats) { function initFormat(chat_formats) {
chat_formats.forEach(function (chat_format) { chat_formats.forEach(function(chat_format) {
var chat_format_str = chat_format.format; var chat_format_str = chat_format.format;
var temp = []; var temp = [];
var r; var r;
@ -168,7 +168,7 @@ function registerEvent() {
} }
function handlerBukkitChat(event) { function handlerBukkitChat(event) {
sendChat(event.player, event.message, function () { sendChat(event.player, event.message, function() {
event.setCancelled(true); event.setCancelled(true);
}); });
} }
@ -182,7 +182,7 @@ function handlerSpongeChat(event) {
if (plain.startsWith(tellraw.duplicateChar)) { if (plain.startsWith(tellraw.duplicateChar)) {
return; return;
} }
sendChat(player, plain, function () { sendChat(player, plain, function() {
event.setMessageCancelled(true) event.setMessageCancelled(true)
}); });
} }

View File

@ -10,11 +10,13 @@ var bukkit = require('api/server');
var item = require('api/item'); var item = require('api/item');
var Arrays = Java.type('java.util.Arrays'); var Arrays = Java.type('java.util.Arrays');
var Material = Java.type('org.bukkit.Material');
var ItemStackArray = Java.type('org.bukkit.inventory.ItemStack[]'); var ItemStackArray = Java.type('org.bukkit.inventory.ItemStack[]');
var description = { var description = {
name: 'Lottery', name: 'Lottery',
version: '1.0', version: '1.0',
author: 'MiaoWoo',
commands: { commands: {
'lottery': { 'lottery': {
description: 'Lottery主命令' description: 'Lottery主命令'
@ -22,11 +24,15 @@ var description = {
}, },
config: { config: {
title: '§m§s§a幸运抽奖', title: '§m§s§a幸运抽奖',
panel: '160:13', control: {
panel: 'GLASS_PANE:13',
ok: 'GLASS_PANE:14',
no: 'GLASS_PANE:15',
},
list: [ list: [
{ {
box: { box: {
id: 160, id: 'GLASS_PANE',
damage: 1, damage: 1,
name: '§a箱子', name: '§a箱子',
lore: [ lore: [
@ -34,7 +40,7 @@ var description = {
] ]
}, },
key: { key: {
id: 160, id: 'GLASS_PANE',
damage: 2, damage: 2,
name: '§b钥匙', name: '§b钥匙',
lore: [ lore: [
@ -46,7 +52,7 @@ var description = {
percent: 10, percent: 10,
command: 'money give %player% 100', command: 'money give %player% 100',
item: { item: {
id: 160, id: 'GLASS_PANE',
damage: 3, damage: 3,
name: '§c奖品1', name: '§c奖品1',
lore: [ lore: [
@ -58,7 +64,7 @@ var description = {
percent: 20, percent: 20,
command: 'money give %player% 200', command: 'money give %player% 200',
item: { item: {
id: 160, id: 'GLASS_PANE',
damage: 4, damage: 4,
name: '§c奖品2', name: '§c奖品2',
lore: [ lore: [
@ -72,25 +78,19 @@ var description = {
} }
}; };
var panel = item.create(160, 1, 13); var panel;
var config; var config;
var items; var items;
function load() { function load() {
panel = item.create('GLASS_PANE', 1, 13);
config = this.config; config = this.config;
if (config.panel) { panel = newItemFromString(config.control.panel || 'GLASS_PANE:13')
var arr = config.panel.split(':');
if (arr.length === 2) {
panel = newItem(arr[0], arr[1]);
} else {
panel = newItem(arr[0]);
}
}
items = new ItemStackArray(54); items = new ItemStackArray(54);
item.setName(panel, ''); item.setName(panel, '');
var ok = newItem(160, 14); var ok = newItemFromString(config.control.ok || 'GLASS_PANE:14')
item.setName(ok, '§a确定抽奖'); item.setName(ok, '§a确定抽奖');
var no = newItem(160, 15); var no = newItemFromString(config.control.no || 'GLASS_PANE:15')
item.setName(no, '§c取消抽奖'); item.setName(no, '§c取消抽奖');
Arrays.fill(items, 0, 10, panel); Arrays.fill(items, 0, 10, panel);
Arrays.fill(items, 11, 16, panel); Arrays.fill(items, 11, 16, panel);
@ -113,6 +113,15 @@ function newItem(name, sub) {
return item.create(name, 1, sub || 0); 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) { function newItemFromConfig(config) {
var i = newItem(config.id, config.damage); var i = newItem(config.id, config.damage);
if (config.name) item.setName(i, config.name); if (config.name) item.setName(i, config.name);
@ -123,7 +132,7 @@ function newItemFromConfig(config) {
function enable() { function enable() {
// noinspection JSUnusedLocalSymbols // noinspection JSUnusedLocalSymbols
command.on(this, 'l', { command.on(this, 'l', {
cmd: function (sender, command, args) { cmd: function(sender, command, args) {
if (!sender.openInventory) { if (!sender.openInventory) {
console.sender(sender, "§4当前用户无法使用该命令!"); console.sender(sender, "§4当前用户无法使用该命令!");
} }
@ -180,7 +189,7 @@ function enable() {
return; return;
} }
var resultList = []; var resultList = [];
litem.result.forEach(function (t) { litem.result.forEach(function(t) {
for (var i = 0; i < t.percent; i++) { for (var i = 0; i < t.percent; i++) {
resultList.push(t); resultList.push(t);
} }