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);

View File

@ -69,9 +69,14 @@ 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"))
{

View File

@ -6661,6 +6661,7 @@ goldencarrot,396,0
goldcarrot,396,0
gcarrot,396,0
head,397,0
skull,397,0
skeletonhead,397,0
headskeleton,397,0
skeletonskull,397,0

1 #version: TeamCity
6661 goldcarrot,396,0
6662 gcarrot,396,0
6663 head,397,0
6664 skull,397,0
6665 skeletonhead,397,0
6666 headskeleton,397,0
6667 skeletonskull,397,0

View File

@ -546,3 +546,4 @@ gameModeInvalid=\u00a74You need to specify a valid player/mode.
mailTooLong=\u00a74Mail message too long. Try to keep it below 1000 characters.
mailDelay=Too many mails have been sent within the last minute. Maximum\: {0}
seenAccounts=\u00a76Player has also been known as:\u00a7c {0}
unableToSpawnItem=\u00a74Cannot spawn \u00a7c{0}\u00a74, this is not a spawnable item.

View File

@ -546,3 +546,4 @@ gameModeInvalid=\u00a74You need to specify a valid player/mode.
mailTooLong=\u00a74Mail message too long. Try to keep it below 1000
mailDelay=Too many mails have been sent within the last minute. Maximum\: {0}
seenAccounts=\u00a76Player has also been known as:\u00a7c {0}
unableToSpawnItem=\u00a74Cannot spawn \u00a7c{0}\u00a74, this is not a spawnable item.

View File

@ -546,3 +546,4 @@ gameModeInvalid=\u00a74You need to specify a valid player/mode.
mailTooLong=\u00a74Mail message too long. Try to keep it below 1000
mailDelay=Too many mails have been sent within the last minute. Maximum\: {0}
seenAccounts=\u00a76Player has also been known as:\u00a7c {0}
unableToSpawnItem=\u00a74Cannot spawn \u00a7c{0}\u00a74, this is not a spawnable item.

View File

@ -546,3 +546,4 @@ gameModeInvalid=\u00a74You need to specify a valid player/mode.
mailTooLong=\u00a74Mail message too long. Try to keep it below 1000
mailDelay=Too many mails have been sent within the last minute. Maximum\: {0}
seenAccounts=\u00a76Player has also been known as:\u00a7c {0}
unableToSpawnItem=\u00a74Cannot spawn \u00a7c{0}\u00a74, this is not a spawnable item.

View File

@ -546,3 +546,4 @@ gameModeInvalid=\u00a74You need to specify a valid player/mode.
mailTooLong=\u00a74Mail message too long. Try to keep it below 1000 characters.
mailDelay=Too many mails have been sent within the last minute. Maximum\: {0}
seenAccounts=\u00a76Player has also been known as:\u00a7c {0}
unableToSpawnItem=\u00a74Cannot spawn \u00a7c{0}\u00a74, this is not a spawnable item.

View File

@ -546,3 +546,4 @@ gameModeInvalid=\u00a74You need to specify a valid player/mode.
mailTooLong=\u00a74Mail message too long. Try to keep it below 1000
mailDelay=Too many mails have been sent within the last minute. Maximum\: {0}
seenAccounts=\u00a76Player has also been known as:\u00a7c {0}
unableToSpawnItem=\u00a74Cannot spawn \u00a7c{0}\u00a74, this is not a spawnable item.

View File

@ -546,3 +546,4 @@ gameModeInvalid=\u00a74You need to specify a valid player/mode.
mailTooLong=\u00a74Mail message too long. Try to keep it below 1000
mailDelay=Too many mails have been sent within the last minute. Maximum\: {0}
seenAccounts=\u00a76Player has also been known as:\u00a7c {0}
unableToSpawnItem=\u00a74Cannot spawn \u00a7c{0}\u00a74, this is not a spawnable item.

View File

@ -546,3 +546,4 @@ gameModeInvalid=\u00a74You need to specify a valid player/mode.
mailTooLong=\u00a74Mail message too long. Try to keep it below 1000
mailDelay=Too many mails have been sent within the last minute. Maximum\: {0}
seenAccounts=\u00a76Player has also been known as:\u00a7c {0}
unableToSpawnItem=\u00a74Cannot spawn \u00a7c{0}\u00a74, this is not a spawnable item.

View File

@ -546,3 +546,4 @@ gameModeInvalid=\u00a74You need to specify a valid player/mode.
mailTooLong=\u00a74Mail message too long. Try to keep it below 1000
mailDelay=Too many mails have been sent within the last minute. Maximum\: {0}
seenAccounts=\u00a76Player has also been known as:\u00a7c {0}
unableToSpawnItem=\u00a74Cannot spawn \u00a7c{0}\u00a74, this is not a spawnable item.

View File

@ -546,3 +546,4 @@ gameModeInvalid=\u00a74You need to specify a valid player/mode.
mailTooLong=\u00a74Mail message too long. Try to keep it below 1000
mailDelay=Too many mails have been sent within the last minute. Maximum\: {0}
seenAccounts=\u00a76Player has also been known as:\u00a7c {0}
unableToSpawnItem=\u00a74Cannot spawn \u00a7c{0}\u00a74, this is not a spawnable item.

View File

@ -546,3 +546,4 @@ gameModeInvalid=\u00a74You need to specify a valid player/mode.
mailTooLong=\u00a74Mail message too long. Try to keep it below 1000
mailDelay=Too many mails have been sent within the last minute. Maximum\: {0}
seenAccounts=\u00a76Player has also been known as:\u00a7c {0}
unableToSpawnItem=\u00a74Cannot spawn \u00a7c{0}\u00a74, this is not a spawnable item.

View File

@ -546,3 +546,4 @@ gameModeInvalid=\u00a74You need to specify a valid player/mode.
mailTooLong=\u00a74Mail message too long. Try to keep it below 1000
mailDelay=Too many mails have been sent within the last minute. Maximum\: {0}
seenAccounts=\u00a76Player has also been known as:\u00a7c {0}
unableToSpawnItem=\u00a74Cannot spawn \u00a7c{0}\u00a74, this is not a spawnable item.

View File

@ -546,3 +546,4 @@ gameModeInvalid=\u00a74You need to specify a valid player/mode.
mailTooLong=\u00a74Mail message too long. Try to keep it below 1000
mailDelay=Too many mails have been sent within the last minute. Maximum\: {0}
seenAccounts=\u00a76Player has also been known as:\u00a7c {0}
unableToSpawnItem=\u00a74Cannot spawn \u00a7c{0}\u00a74, this is not a spawnable item.

View File

@ -546,3 +546,4 @@ gameModeInvalid=\u00a74You need to specify a valid player/mode.
mailTooLong=\u00a74Mail message too long. Try to keep it below 1000
mailDelay=Too many mails have been sent within the last minute. Maximum\: {0}
seenAccounts=\u00a76Player has also been known as:\u00a7c {0}
unableToSpawnItem=\u00a74Cannot spawn \u00a7c{0}\u00a74, this is not a spawnable item.

View File

@ -546,3 +546,4 @@ gameModeInvalid=\u00a74You need to specify a valid player/mode.
mailTooLong=\u00a74Mail message too long. Try to keep it below 1000
mailDelay=Too many mails have been sent within the last minute. Maximum\: {0}
seenAccounts=\u00a76Player has also been known as:\u00a7c {0}
unableToSpawnItem=\u00a74Cannot spawn \u00a7c{0}\u00a74, this is not a spawnable item.

View File

@ -546,3 +546,4 @@ gameModeInvalid=\u00a74You need to specify a valid player/mode.
mailTooLong=\u00a74Mail message too long. Try to keep it below 1000
mailDelay=Too many mails have been sent within the last minute. Maximum\: {0}
seenAccounts=\u00a76Player has also been known as:\u00a7c {0}
unableToSpawnItem=\u00a74Cannot spawn \u00a7c{0}\u00a74, this is not a spawnable item.

View File

@ -546,3 +546,4 @@ gameModeInvalid=\u00a74You need to specify a valid player/mode.
mailTooLong=\u00a74Mail message too long. Try to keep it below 1000
mailDelay=Too many mails have been sent within the last minute. Maximum\: {0}
seenAccounts=\u00a76Player has also been known as:\u00a7c {0}
unableToSpawnItem=\u00a74Cannot spawn \u00a7c{0}\u00a74, this is not a spawnable item.

View File

@ -546,3 +546,4 @@ gameModeInvalid=\u00a74You need to specify a valid player/mode.
mailTooLong=\u00a74Mail message too long. Try to keep it below 1000
mailDelay=Too many mails have been sent within the last minute. Maximum\: {0}
seenAccounts=\u00a76Player has also been known as:\u00a7c {0}
unableToSpawnItem=\u00a74Cannot spawn \u00a7c{0}\u00a74, this is not a spawnable item.

View File

@ -546,3 +546,4 @@ gameModeInvalid=\u00a74You need to specify a valid player/mode.
mailTooLong=\u00a74Mail message too long. Try to keep it below 1000
mailDelay=Too many mails have been sent within the last minute. Maximum\: {0}
seenAccounts=\u00a76Player has also been known as:\u00a7c {0}
unableToSpawnItem=\u00a74Cannot spawn \u00a7c{0}\u00a74, this is not a spawnable item.

View File

@ -546,3 +546,4 @@ gameModeInvalid=\u00a74You need to specify a valid player/mode.
mailTooLong=\u00a74Mail message too long. Try to keep it below 1000
mailDelay=Too many mails have been sent within the last minute. Maximum\: {0}
seenAccounts=\u00a76Player has also been known as:\u00a7c {0}
unableToSpawnItem=\u00a74Cannot spawn \u00a7c{0}\u00a74, this is not a spawnable item.

View File

@ -546,3 +546,4 @@ gameModeInvalid=\u00a74You need to specify a valid player/mode.
mailTooLong=\u00a74Mail message too long. Try to keep it below 1000
mailDelay=Too many mails have been sent within the last minute. Maximum\: {0}
seenAccounts=\u00a76Player has also been known as:\u00a7c {0}
unableToSpawnItem=\u00a74Cannot spawn \u00a7c{0}\u00a74, this is not a spawnable item.

View File

@ -546,3 +546,4 @@ gameModeInvalid=\u00a74You need to specify a valid player/mode.
mailTooLong=\u00a74Mail message too long. Try to keep it below 1000
mailDelay=Too many mails have been sent within the last minute. Maximum\: {0}
seenAccounts=\u00a76Player has also been known as:\u00a7c {0}
unableToSpawnItem=\u00a74Cannot spawn \u00a7c{0}\u00a74, this is not a spawnable item.

View File

@ -546,3 +546,4 @@ gameModeInvalid=\u00a74You need to specify a valid player/mode.
mailTooLong=\u00a74Mail message too long. Try to keep it below 1000
mailDelay=Too many mails have been sent within the last minute. Maximum\: {0}
seenAccounts=\u00a76Player has also been known as:\u00a7c {0}
unableToSpawnItem=\u00a74Cannot spawn \u00a7c{0}\u00a74, this is not a spawnable item.