Fix attempting to spawn invalid items.

This commit is contained in:
KHobbits 2014-04-30 05:41:42 +01:00
parent e66ad88451
commit 1bb569fff2
26 changed files with 68 additions and 1 deletions

View file

@ -10,6 +10,7 @@ import java.util.*;
import java.util.regex.Pattern;
import com.google.common.base.Joiner;
import java.util.logging.Level;
import net.ess3.api.IEssentials;
import org.bukkit.Color;
import org.bukkit.DyeColor;
@ -26,6 +27,7 @@ public class MetaItemStack
{
private static final Map<String, DyeColor> colorMap = new HashMap<String, DyeColor>();
private static final Map<String, FireworkEffect.Type> fireworkShape = new HashMap<String, FireworkEffect.Type>();
static
{
for (DyeColor color : DyeColor.values())
@ -95,6 +97,35 @@ public class MetaItemStack
completePotion = true;
}
public boolean canSpawn(final IEssentials ess)
{
try
{
ess.getServer().getUnsafe().modifyItemStack(stack, "{}");
return true;
}
catch (NullPointerException npe)
{
if (ess.getSettings().isDebug())
{
ess.getLogger().log(Level.INFO, "Itemstack is invalid", npe);
}
return false;
}
catch (NoSuchMethodError nsme)
{
return true;
}
catch (Throwable throwable)
{
if (ess.getSettings().isDebug())
{
ess.getLogger().log(Level.INFO, "Itemstack is invalid", throwable);
}
return false;
}
}
public void parseStringMeta(final CommandSource sender, final boolean allowUnsafe, String[] string, int fromArg, final IEssentials ess) throws Exception
{
if (string[fromArg].startsWith("{"))
@ -103,6 +134,13 @@ public class MetaItemStack
{
stack = ess.getServer().getUnsafe().modifyItemStack(stack, Joiner.on(' ').join(Arrays.asList(string).subList(fromArg, string.length)));
}
catch (NullPointerException npe)
{
if (ess.getSettings().isDebug())
{
ess.getLogger().log(Level.INFO, "Itemstack is invalid", npe);
}
}
catch (NoSuchMethodError nsme)
{
throw new Exception(tl("noMetaJson"), nsme);