Skip to content

Commit

Permalink
Catch NPEs in CustomNBT methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
aufdemrand committed Jul 3, 2013
1 parent 3443c82 commit f492c17
Showing 1 changed file with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public static MapOfEnchantments getEnchantments(ItemStack item) {
*/

public static boolean hasCustomNBT(ItemStack item, String key) {
if (item == null) return false;
NBTTagCompound tag;
net.minecraft.server.v1_6_R1.ItemStack cis = CraftItemStack.asNMSCopy(item);
if (!cis.hasTag()) return false;
Expand All @@ -30,6 +31,7 @@ public static boolean hasCustomNBT(ItemStack item, String key) {
}

public static String getCustomNBT(ItemStack item, String key) {
if (item == null) return null;
net.minecraft.server.v1_6_R1.ItemStack cis = CraftItemStack.asNMSCopy(item);
NBTTagCompound tag;
if (!cis.hasTag())
Expand All @@ -42,6 +44,7 @@ public static String getCustomNBT(ItemStack item, String key) {
}

public static ItemStack removeCustomNBT(ItemStack item, String key) {
if (item == null) return null;
net.minecraft.server.v1_6_R1.ItemStack cis = CraftItemStack.asNMSCopy(item);
NBTTagCompound tag;
if (!cis.hasTag())
Expand All @@ -53,6 +56,7 @@ public static ItemStack removeCustomNBT(ItemStack item, String key) {
}

public static ItemStack addCustomNBT(ItemStack item, String key, String value) {
if (item == null) return null;
net.minecraft.server.v1_6_R1.ItemStack cis = CraftItemStack.asNMSCopy(item);
NBTTagCompound tag = null;
// Do stuff with tag
Expand All @@ -64,6 +68,7 @@ public static ItemStack addCustomNBT(ItemStack item, String key, String value) {
}

public static LivingEntity addCustomNBT(LivingEntity entity, String key, String value) {
if (entity == null) return null;
Entity bukkitEntity = entity;
net.minecraft.server.v1_6_R1.Entity nmsEntity = ((CraftEntity) bukkitEntity).getHandle();
NBTTagCompound tag = new NBTTagCompound();
Expand All @@ -80,6 +85,7 @@ public static LivingEntity addCustomNBT(LivingEntity entity, String key, String
}

public static LivingEntity removeCustomNBT(LivingEntity entity, String key) {
if (entity == null) return null;
Entity bukkitEntity = entity;
net.minecraft.server.v1_6_R1.Entity nmsEntity = ((CraftEntity) bukkitEntity).getHandle();
NBTTagCompound tag = new NBTTagCompound();
Expand All @@ -96,6 +102,7 @@ public static LivingEntity removeCustomNBT(LivingEntity entity, String key) {
}

public static boolean hasCustomNBT(LivingEntity entity, String key) {
if (entity == null) return false;
Entity bukkitEntity = entity;
net.minecraft.server.v1_6_R1.Entity nmsEntity = ((CraftEntity) bukkitEntity).getHandle();
NBTTagCompound tag = new NBTTagCompound();
Expand All @@ -108,6 +115,7 @@ public static boolean hasCustomNBT(LivingEntity entity, String key) {
}

public static String getCustomNBT(LivingEntity entity, String key) {
if (entity == null) return null;
Entity bukkitEntity = entity;
net.minecraft.server.v1_6_R1.Entity nmsEntity = ((CraftEntity) bukkitEntity).getHandle();
NBTTagCompound tag = new NBTTagCompound();
Expand Down

0 comments on commit f492c17

Please sign in to comment.