From 755d4b005d89e20391c6b54916c92209b850e98e Mon Sep 17 00:00:00 2001 From: coding Date: Sun, 18 Mar 2018 12:04:56 +0000 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E6=8F=92=E4=BB=B6?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/plugins/ItemTag.js | 30 ++++++++++++++++----------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/src/main/resources/plugins/ItemTag.js b/src/main/resources/plugins/ItemTag.js index cc1f657..d976cfd 100644 --- a/src/main/resources/plugins/ItemTag.js +++ b/src/main/resources/plugins/ItemTag.js @@ -7,6 +7,8 @@ var task = require('api/task'); var http = require('http'); var fs = require('fs'); +var Keys; + var description = { name: 'ItemTag', version: '1.0', @@ -38,10 +40,11 @@ function enable() { }) break; case ServerType.Sponge: - event.on(self, 'itemmergeitemevent', function (event) { + Keys = Java.type('org.spongepowered.api.data.key.Keys'); + event.on(self, 'ItemMergeItemEvent', function (event) { // Sponge 暂未实现当前事件 }) - event.on(self, 'spawnentityevent', function (event) { + event.on(self, 'SpawnEntityEvent', function (event) { event.entities.forEach(function (entity) { if (entity.type.name === "item") sponge(entity); }) @@ -50,26 +53,29 @@ function enable() { } } -function getItemName(name) { - return itemConfig[(name + '').toUpperCase()] || name; -} - function bukkit(item , amount) { - var amounts = amount == 1 ? "" : "*" + amount; - item.setCustomName('§b' + getItemName(item.itemStack.type) + amounts); + item.setCustomName('§b' + getItemName(item.itemStack.type) + getItemCount(amount)); item.setCustomNameVisible(true); } function sponge(entity) { - var itemOptional = entity.get(org.spongepowered.api.data.key.Keys.REPRESENTED_ITEM); + var itemOptional = entity.get(Keys.REPRESENTED_ITEM); if (itemOptional.isPresent()) { var item = itemOptional.get(); - var amounts = item.count == 1 ? "" : "*" + item.count; - entity.offer(org.spongepowered.api.data.key.Keys.DISPLAY_NAME, org.spongepowered.api.text.Text.of('§b' + getItemName(item.type.name.split(':')[1]) + amounts)); - entity.offer(org.spongepowered.api.data.key.Keys.CUSTOM_NAME_VISIBLE, true); + var itemName = '§b' + getItemName(item.type.name.split(':')[1]) + getItemCount(item.count); + entity.offer(Keys.DISPLAY_NAME, org.spongepowered.api.text.Text.of(itemName)); + entity.offer(Keys.CUSTOM_NAME_VISIBLE, true); } } +function getItemName(name) { + return itemConfig[(name + '').toUpperCase()] || name; +} + +function getItemCount(amount){ + return amount == 1 ? "" : "*" + amount; +} + module.exports = { description: description, load: load,