Null checks are important!

This commit is contained in:
Ellpeck 2015-09-27 15:34:22 +02:00
parent d4e425fbd7
commit b9fe715244
2 changed files with 6 additions and 2 deletions

View file

@ -32,7 +32,7 @@ public class CraftEvent{
if(ConfigBoolValues.GIVE_BOOKLET_ON_FIRST_CRAFT.isEnabled()){ if(ConfigBoolValues.GIVE_BOOKLET_ON_FIRST_CRAFT.isEnabled()){
if(!event.player.worldObj.isRemote && event.crafting.getItem() != InitItems.itemLexicon && (event.crafting.getItem() instanceof INameableItem || Block.getBlockFromItem(event.crafting.getItem()) instanceof INameableItem)){ if(!event.player.worldObj.isRemote && event.crafting.getItem() != InitItems.itemLexicon && (event.crafting.getItem() instanceof INameableItem || Block.getBlockFromItem(event.crafting.getItem()) instanceof INameableItem)){
PersistantServerData data = PersistantServerData.get(event.player); PersistantServerData data = PersistantServerData.get(event.player);
if(!data.bookGottenAlready){ if(data != null && !data.bookGottenAlready){
data.bookGottenAlready = true; data.bookGottenAlready = true;
EntityItem entityItem = new EntityItem(event.player.worldObj, event.player.posX, event.player.posY, event.player.posZ, new ItemStack(InitItems.itemLexicon)); EntityItem entityItem = new EntityItem(event.player.worldObj, event.player.posX, event.player.posY, event.player.posZ, new ItemStack(InitItems.itemLexicon));

View file

@ -47,6 +47,10 @@ public class PersistantServerData implements IExtendedEntityProperties{
} }
public static PersistantServerData get(EntityPlayer player){ public static PersistantServerData get(EntityPlayer player){
return (PersistantServerData)player.getExtendedProperties(ModUtil.MOD_ID); IExtendedEntityProperties properties = player.getExtendedProperties(ModUtil.MOD_ID);
if(properties != null && properties instanceof PersistantServerData){
return (PersistantServerData)properties;
}
return null;
} }
} }