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);

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"

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);