From 2704b0bd4989261eec30ad6a34beb684b38ecbaa Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Wed, 16 Mar 2016 15:28:21 +0100 Subject: [PATCH] TypeItemStack now uses held item. Bugfix for Txt.getItemName --- .../command/type/TypeItemStack.java | 28 +++++++++++-------- .../massivecraft/massivecore/util/Txt.java | 2 +- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/com/massivecraft/massivecore/command/type/TypeItemStack.java b/src/com/massivecraft/massivecore/command/type/TypeItemStack.java index 0495a4f9..9df4e072 100644 --- a/src/com/massivecraft/massivecore/command/type/TypeItemStack.java +++ b/src/com/massivecraft/massivecore/command/type/TypeItemStack.java @@ -1,13 +1,14 @@ package com.massivecraft.massivecore.command.type; import java.util.Collection; -import java.util.Collections; import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import com.massivecraft.massivecore.MassiveException; import com.massivecraft.massivecore.mson.Mson; +import com.massivecraft.massivecore.util.InventoryUtil; import com.massivecraft.massivecore.util.Txt; public class TypeItemStack extends TypeAbstract @@ -32,29 +33,32 @@ public class TypeItemStack extends TypeAbstract @Override public String getNameInner(ItemStack value) { - // TODO: Implement return null; } @Override public String getIdInner(ItemStack value) { - // TODO: Implement return null; } - @Override - public ItemStack read(String arg, CommandSender sender) throws MassiveException - { - // TODO: Implement - throw new MassiveException().addMsg("Not implemented!"); - } - @Override public Collection getTabList(CommandSender sender, String arg) { - // TODO: Implement - return Collections.emptyList(); + return null; + } + + @SuppressWarnings("deprecation") + @Override + public ItemStack read(String arg, CommandSender sender) throws MassiveException + { + if ( ! (sender instanceof Player)) throw new MassiveException().addMsg("You must be a player to hold an item in your hand."); + Player player = (Player)sender; + + ItemStack ret = player.getItemInHand(); + if (InventoryUtil.isNothing(ret)) throw new MassiveException().addMsg("You must hold an item in your hand."); + ret = new ItemStack(ret); + return ret; } } diff --git a/src/com/massivecraft/massivecore/util/Txt.java b/src/com/massivecraft/massivecore/util/Txt.java index 68e01b49..45ff6ec3 100644 --- a/src/com/massivecraft/massivecore/util/Txt.java +++ b/src/com/massivecraft/massivecore/util/Txt.java @@ -433,7 +433,7 @@ public class Txt { if (InventoryUtil.isNothing(itemStack)) return Txt.parse("Nothing"); - ChatColor color = (itemStack.getEnchantments().size() > 0) ? ChatColor.AQUA : ChatColor.RESET; + ChatColor color = (itemStack.getEnchantments().size() > 0) ? ChatColor.AQUA : ChatColor.WHITE; if (itemStack.hasItemMeta()) {