From 4653bbc0912321b7472decae2b480212397fe737 Mon Sep 17 00:00:00 2001 From: MiaoWoo Date: Sun, 28 Apr 2019 19:32:24 +0800 Subject: [PATCH] fix: item lib error Signed-off-by: MiaoWoo --- .../node_modules/internal/bukkit/item.js | 47 +++++++++++-------- 1 file changed, 28 insertions(+), 19 deletions(-) diff --git a/src/main/resources/node_modules/internal/bukkit/item.js b/src/main/resources/node_modules/internal/bukkit/item.js index 5394c62..e810741 100644 --- a/src/main/resources/node_modules/internal/bukkit/item.js +++ b/src/main/resources/node_modules/internal/bukkit/item.js @@ -5,7 +5,6 @@ */ /*global Java, base, module, exports, require, __FILE__*/ var Bukkit = MServer; -var item = {}; var ItemStack = Java.type("org.bukkit.inventory.ItemStack"); var Material = Java.type('org.bukkit.Material'); var ItemIDMaterial = require('./item-id-material.json') @@ -17,8 +16,8 @@ var ItemIDRegex = /^[0-9]*$/ * @constructor (ID,数量) * @constructor (ID,数量,子ID) */ -item.create = function() { - var idOrType = item.type(arguments[0]); +function create() { + var idOrType = type(arguments[0]); if (!idOrType) { throw Error('无效的物品ID或枚举 ' + arguments[0] + ' => ' + idOrType) } @@ -35,7 +34,7 @@ item.create = function() { /** * 获得物品枚举(兼容的方式) */ -item.type = function(idOrType) { +function type(idOrType) { if (arguments.length > 1) { idOrType = Array.prototype.slice.apply(arguments); } @@ -74,8 +73,8 @@ item.type = function(idOrType) { * 创建一个头颅 * @constructor (玩家名称) */ -item.head = function(name) { - var head = item.create(397, 1, 3); +function head(name) { + var head = create(397, 1, 3); var skullMeta = head.itemMeta; skullMeta.setOwner(name); head.setItemMeta(skullMeta); @@ -88,11 +87,11 @@ item.head = function(name) { * @param items 物品数组 * @param drop 满背包是否掉落 */ -item.add = function(player, items, drop) { +function add(player, items, drop) { var drops = player.inventory.addItem(items).values(); if (drops.size() !== 0 && drop) { drops.forEach(function(itemStack) { - item.drop(player.location, itemStack); + drop(player.location, itemStack); }); } }; @@ -102,7 +101,7 @@ item.add = function(player, items, drop) { * @param loc 地点 * @param item 物品 */ -item.drop = function(loc, item) { +function drop(loc, item) { setTimeout(function() { loc.world.dropItem(loc, item); }, 1); @@ -114,11 +113,11 @@ item.drop = function(loc, item) { * @param name * @returns {*} */ -item.setName = function(item, name) { +function setName(item, name) { if (item.type && item.type.name() !== "AIR") { - var meta = item.meta(item); - meta.setDisplayName(name); - item.setItemMeta(meta); + var itemMeta = meta(item); + itemMeta.setDisplayName(name); + item.setItemMeta(itemMeta); } return item; }; @@ -129,7 +128,7 @@ item.setName = function(item, name) { * @param lores Lore * @returns {*} 物品 */ -item.setLore = item.setLores = function(item, lores) { +function setLore(item, lores) { var argType = toString.call(lores); switch (argType) { case "[object String]": @@ -145,15 +144,25 @@ item.setLore = item.setLores = function(item, lores) { throw Error("Unsupport argument type " + argType + " value " + lores) } if (item.type && item.type.name() !== "AIR") { - var meta = item.meta(item); - meta.setLore(lores); - item.setItemMeta(meta); + var itemMeta = meta(item); + itemMeta.setLore(lores); + item.setItemMeta(itemMeta); } return item; }; -item.meta = function(item) { +function meta(item) { return item.hasItemMeta() ? item.itemMeta : Bukkit.itemFactory.getItemMeta(item.type); } -module.exports = item; \ No newline at end of file +module.exports = { + create: create, + type: type, + head: head, + add: add, + drop: drop, + meta: meta, + setName: setName, + setLore: setLore, + setLores: setLore +};