Fix for Bukkit NPE in /enchant.

This commit is contained in:
Steven Lawson 2013-07-20 19:38:27 -04:00
parent aad8f17455
commit c3fc085adc
3 changed files with 22 additions and 7 deletions

View File

@ -1,6 +1,6 @@
#Fri, 19 Jul 2013 19:19:28 -0400 #Sat, 20 Jul 2013 19:28:30 -0400
program.VERSION=2.21 program.VERSION=2.21
program.BUILDNUM=318 program.BUILDNUM=320
program.BUILDDATE=07/19/2013 07\:19 PM program.BUILDDATE=07/20/2013 07\:28 PM

View File

@ -1,3 +1,3 @@
#Build Number for ANT. Do not edit! #Build Number for ANT. Do not edit!
#Fri Jul 19 19:19:28 EDT 2013 #Sat Jul 20 19:28:30 EDT 2013
build.number=319 build.number=321

View File

@ -1,5 +1,6 @@
package me.StevenLawson.TotalFreedomMod.Commands; package me.StevenLawson.TotalFreedomMod.Commands;
import me.StevenLawson.TotalFreedomMod.TFM_Log;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.enchantments.Enchantment; import org.bukkit.enchantments.Enchantment;
@ -53,9 +54,23 @@ public class Command_enchant extends TFM_Command
{ {
for (Enchantment ench : Enchantment.values()) for (Enchantment ench : Enchantment.values())
{ {
if (ench.canEnchantItem(itemInHand)) /*
2013-07-20 23:17:13 [INFO] [TotalFreedomMod]: Command Error: enchant
java.lang.NullPointerException
at net.minecraft.server.v1_6_R2.EnchantmentDurability.canEnchant(SourceFile:33)
at org.bukkit.craftbukkit.v1_6_R2.enchantments.CraftEnchantment.canEnchantItem(CraftEnchantment.java:55)
at me.StevenLawson.TotalFreedomMod.Commands.Command_enchant.run(Command_enchant.java:56)
*/
try
{ {
itemInHand.addEnchantment(ench, ench.getMaxLevel()); if (ench.canEnchantItem(itemInHand))
{
itemInHand.addEnchantment(ench, ench.getMaxLevel());
}
}
catch (Exception ex)
{
TFM_Log.info("Error using " + ench.getName() + " on " + itemInHand.getType().name() + " held by " + sender_p.getName() + ".");
} }
} }