From ff3b1e810fcb6b1f09847f2e104df2f0ef112a66 Mon Sep 17 00:00:00 2001 From: vemacs Date: Thu, 4 Jun 2015 11:18:47 -0600 Subject: [PATCH] Fix MetaItemStack canSpawn() method to try it on a clone, readd check to /give and /i --- Essentials/src/com/earth2me/essentials/MetaItemStack.java | 2 +- .../src/com/earth2me/essentials/commands/Commandgive.java | 6 +++++- .../src/com/earth2me/essentials/commands/Commanditem.java | 7 ++++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/MetaItemStack.java b/Essentials/src/com/earth2me/essentials/MetaItemStack.java index ac0b08553..afdb84240 100644 --- a/Essentials/src/com/earth2me/essentials/MetaItemStack.java +++ b/Essentials/src/com/earth2me/essentials/MetaItemStack.java @@ -90,7 +90,7 @@ public class MetaItemStack { public boolean canSpawn(final IEssentials ess) { try { - ess.getServer().getUnsafe().modifyItemStack(stack, "{}"); + ess.getServer().getUnsafe().modifyItemStack(stack.clone(), "{}"); return true; } catch (NullPointerException npe) { if (ess.getSettings().isDebug()) { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandgive.java b/Essentials/src/com/earth2me/essentials/commands/Commandgive.java index 4d5952c01..8411103f1 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandgive.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandgive.java @@ -50,8 +50,12 @@ public class Commandgive extends EssentialsCommand { throw new NotEnoughArgumentsException(); } + MetaItemStack metaStack = new MetaItemStack(stack); + if (!metaStack.canSpawn(ess)) { + throw new Exception(tl("unableToSpawnItem", itemname)); + } + if (args.length > 3) { - MetaItemStack metaStack = new MetaItemStack(stack); boolean allowUnsafe = ess.getSettings().allowUnsafeEnchantments(); if (allowUnsafe && sender.isPlayer() && !ess.getUser(sender.getPlayer()).isAuthorized("essentials.enchantments.allowunsafe")) { allowUnsafe = false; diff --git a/Essentials/src/com/earth2me/essentials/commands/Commanditem.java b/Essentials/src/com/earth2me/essentials/commands/Commanditem.java index 9f5461316..d822a9ce3 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commanditem.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commanditem.java @@ -39,8 +39,13 @@ public class Commanditem extends EssentialsCommand { } catch (NumberFormatException e) { throw new NotEnoughArgumentsException(); } + + MetaItemStack metaStack = new MetaItemStack(stack); + if (!metaStack.canSpawn(ess)) { + throw new Exception(tl("unableToSpawnItem", itemname)); + } + if (args.length > 2) { - MetaItemStack metaStack = new MetaItemStack(stack); final boolean allowUnsafe = ess.getSettings().allowUnsafeEnchantments() && user.isAuthorized("essentials.enchantments.allowunsafe"); metaStack.parseStringMeta(user.getSource(), allowUnsafe, args, 2, ess);