More null checks for less possible crashes

This commit is contained in:
Ellpeck 2016-06-03 23:34:01 +02:00
parent bec7252405
commit 7892a788be
6 changed files with 14 additions and 7 deletions

View file

@ -87,7 +87,7 @@ public class EntityLivingEvents{
data.setTag("Deaths", deaths);
//player.addChatComponentMessage(new TextComponentTranslation("info."+ModUtil.MOD_ID+".deathRecorded"));
WorldData.get(((EntityPlayer)event.getEntityLiving()).worldObj).markDirty();
WorldData.markDirty(event.getEntityLiving().getEntityWorld());
}
}

View file

@ -52,7 +52,7 @@ public class PlayerObtainEvents{
NBTTagCompound compound = PlayerServerData.getDataFromPlayer(event.player);
if(compound != null && !compound.getBoolean("BookGottenAlready")){
compound.setBoolean("BookGottenAlready", true);
WorldData.get(event.player.worldObj).markDirty();
WorldData.markDirty(event.player.worldObj);
EntityItem entityItem = new EntityItem(event.player.worldObj, event.player.posX, event.player.posY, event.player.posZ, new ItemStack(InitItems.itemBooklet));
entityItem.setPickupDelay(0);

View file

@ -20,14 +20,14 @@ public class WorldLoadingEvents{
@SubscribeEvent
public void onLoad(WorldEvent.Load event){
if(!event.getWorld().isRemote){
WorldData.get(event.getWorld());
WorldData.loadOrGet(event.getWorld());
}
}
@SubscribeEvent
public void onUnload(WorldEvent.Unload event){
if(!event.getWorld().isRemote){
WorldData.get(event.getWorld()).markDirty();
WorldData.markDirty(event.getWorld());
FakePlayerUtil.unloadFakePlayer();
}
}

View file

@ -60,7 +60,7 @@ public class ItemLaserWrench extends ItemBase{
((TileEntityLaserRelay)world.getTileEntity(savedPos)).sendUpdate();
((TileEntityLaserRelay)world.getTileEntity(pos)).sendUpdate();
WorldData.get(world).markDirty();
WorldData.markDirty(world);
player.addChatComponentMessage(new TextComponentTranslation("tooltip."+ModUtil.MOD_ID+".laser.connected.desc"));
}

View file

@ -25,7 +25,7 @@ public class WorldData extends WorldSavedData{
super(tag);
}
public static WorldData get(World world){
public static WorldData loadOrGet(World world){
if(world.getMapStorage() != null){
WorldData data = (WorldData)world.getMapStorage().getOrLoadData(WorldData.class, DATA_TAG);
if(data == null){
@ -41,6 +41,13 @@ public class WorldData extends WorldSavedData{
}
}
public static void markDirty(World world){
WorldData data = loadOrGet(world);
if(data != null){
data.markDirty();
}
}
@Override
public void readFromNBT(NBTTagCompound compound){
//Laser World Data

View file

@ -100,7 +100,7 @@ public abstract class TileEntityLaserRelay extends TileEntityBase{
public void invalidate(){
super.invalidate();
LaserRelayConnectionHandler.getInstance().removeRelayFromNetwork(this.pos);
WorldData.get(this.worldObj).markDirty();
WorldData.markDirty(this.worldObj);
}
}