summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKHobbits <rob@khobbits.co.uk>2013-12-07 20:25:23 +0000
committerKHobbits <rob@khobbits.co.uk>2013-12-07 20:25:23 +0000
commit946051de7124ac0344df98b6c823b94613fe69ff (patch)
treeb98ccddcb4c4e2f8608e802433c695699725809d
parent427b97433e14079fc9466457b19cc70ac49e6670 (diff)
downloadEssentials-946051de7124ac0344df98b6c823b94613fe69ff.tar
Essentials-946051de7124ac0344df98b6c823b94613fe69ff.tar.gz
Essentials-946051de7124ac0344df98b6c823b94613fe69ff.tar.lz
Essentials-946051de7124ac0344df98b6c823b94613fe69ff.tar.xz
Essentials-946051de7124ac0344df98b6c823b94613fe69ff.zip
Add support for adding item meta to [free] signs.
Fix NPE on [sign] creation.
-rw-r--r--Essentials/src/com/earth2me/essentials/MetaItemStack.java2
-rw-r--r--Essentials/src/com/earth2me/essentials/signs/EssentialsSign.java22
-rw-r--r--Essentials/src/com/earth2me/essentials/signs/SignFree.java20
3 files changed, 38 insertions, 6 deletions
diff --git a/Essentials/src/com/earth2me/essentials/MetaItemStack.java b/Essentials/src/com/earth2me/essentials/MetaItemStack.java
index f0f965f1f..90b761249 100644
--- a/Essentials/src/com/earth2me/essentials/MetaItemStack.java
+++ b/Essentials/src/com/earth2me/essentials/MetaItemStack.java
@@ -117,7 +117,7 @@ public class MetaItemStack
}
}
- private void addStringMeta(final CommandSource sender, final boolean allowUnsafe, final String string, final IEssentials ess) throws Exception
+ public void addStringMeta(final CommandSource sender, final boolean allowUnsafe, final String string, final IEssentials ess) throws Exception
{
final String[] split = splitPattern.split(string, 2);
if (split.length < 1)
diff --git a/Essentials/src/com/earth2me/essentials/signs/EssentialsSign.java b/Essentials/src/com/earth2me/essentials/signs/EssentialsSign.java
index 5d688a467..bb74a316e 100644
--- a/Essentials/src/com/earth2me/essentials/signs/EssentialsSign.java
+++ b/Essentials/src/com/earth2me/essentials/signs/EssentialsSign.java
@@ -100,7 +100,7 @@ public class EssentialsSign
showError(ess, user.getSource(), ex, signName);
return false;
}
- catch (SignException ex)
+ catch (Exception ex)
{
showError(ess, user.getSource(), ex, signName);
return false;
@@ -385,6 +385,26 @@ public class EssentialsSign
}
}
+ protected final ItemStack getItemMeta(final ItemStack item, final String meta, final IEssentials ess) throws SignException
+ {
+ ItemStack stack = item;
+ try
+ {
+ if (!meta.isEmpty())
+ {
+ MetaItemStack metaStack = new MetaItemStack(stack);
+ final boolean allowUnsafe = ess.getSettings().allowUnsafeEnchantments();
+ metaStack.addStringMeta(null, allowUnsafe, meta, ess);
+ stack = metaStack.getItemStack();
+ }
+ }
+ catch (Exception ex)
+ {
+ throw new SignException(ex.getMessage(), ex);
+ }
+ return stack;
+ }
+
protected final BigDecimal getMoney(final String line) throws SignException
{
final boolean isMoney = line.matches("^[^0-9-\\.][\\.0-9]+$");
diff --git a/Essentials/src/com/earth2me/essentials/signs/SignFree.java b/Essentials/src/com/earth2me/essentials/signs/SignFree.java
index aff951bcb..e16a4846f 100644
--- a/Essentials/src/com/earth2me/essentials/signs/SignFree.java
+++ b/Essentials/src/com/earth2me/essentials/signs/SignFree.java
@@ -4,9 +4,11 @@ import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.Trade;
import com.earth2me.essentials.User;
import net.ess3.api.IEssentials;
+import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
+import org.bukkit.inventory.meta.ItemMeta;
public class SignFree extends EssentialsSign
@@ -20,7 +22,9 @@ public class SignFree extends EssentialsSign
protected boolean onSignCreate(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException
{
try {
- getItemStack(sign.getLine(1), 1, ess);
+ ItemStack item = getItemStack(sign.getLine(1), 1, ess);
+ item = getItemMeta(item, sign.getLine(2), ess);
+ item = getItemMeta(item, sign.getLine(3), ess);
}
catch (SignException ex)
{
@@ -32,15 +36,23 @@ public class SignFree extends EssentialsSign
@Override
protected boolean onSignInteract(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException
- {
- final ItemStack item = getItemStack(sign.getLine(1), 1, ess);
+ {
+ ItemStack itemStack = getItemStack(sign.getLine(1), 1, ess);
+ itemStack = getItemMeta(itemStack, sign.getLine(2), ess);
+ final ItemStack item = getItemMeta(itemStack, sign.getLine(3), ess);
+
if (item.getType() == Material.AIR)
{
throw new SignException(_("cantSpawnItem", "Air"));
}
item.setAmount(item.getType().getMaxStackSize());
- Inventory invent = ess.getServer().createInventory(player.getBase(), 36, item.getItemMeta().getDisplayName());
+
+ ItemMeta meta = item.getItemMeta();
+
+ final String displayName = meta.hasDisplayName() ? meta.getDisplayName() : item.getType().toString();
+
+ Inventory invent = ess.getServer().createInventory(player.getBase(), 36, displayName);
for (int i = 0; i < 36; i++) {
invent.addItem(item);
}