Null check mania!

This commit is contained in:
Garbage Mule 2011-09-23 17:45:37 +02:00
parent 080bb69927
commit 03a1212e6b
6 changed files with 22 additions and 8 deletions

Binary file not shown.

View File

@ -300,7 +300,7 @@ public class Arena
playerLeave(p);
for (Entity e : monsters)
e.remove();
if (e != null) e.remove();
if (bossWave != null)
bossWave.clear();
@ -465,6 +465,8 @@ public class Arena
for (LivingEntity e : new LinkedList<LivingEntity>(explodingSheep))
{
if (e == null) continue;
Creature c = (Creature) e;
if (c.getTarget() != null && e.getLocation().distanceSquared(c.getTarget().getLocation()) < 8)
{
@ -777,13 +779,13 @@ public class Arena
if (bossWave != null)
bossWave.clear();
for (LivingEntity e : monsters)
e.remove();
if (e != null) e.remove();
for (LivingEntity e : explodingSheep)
e.remove();
if (e != null) e.remove();
for (LivingEntity e : plaguedPigs)
e.remove();
if (e != null) e.remove();
for (LivingEntity e : madCows)
e.remove();
if (e != null) e.remove();
}
private void removeBlocks()
@ -796,6 +798,8 @@ public class Arena
{
for (Wolf w : pets)
{
if (w == null) continue;
w.setOwner(null);
w.remove();
}
@ -805,7 +809,7 @@ public class Arena
{
for (Wolf w : pets)
{
if (!((Player) w.getOwner()).getName().equals(p.getName()))
if (w == null || !((Player) w.getOwner()).getName().equals(p.getName()))
continue;
w.setOwner(null);
@ -824,7 +828,7 @@ public class Arena
for (int j = c1.getZ(); j <= c2.getZ(); j++)
for (Entity e : world.getChunkAt(i,j).getEntities())
if ((e instanceof Item || e instanceof Slime) && inRegion(e.getLocation()))
e.remove();
if (e != null) e.remove();
}

View File

@ -87,6 +87,8 @@ public class MASpawnThread implements Runnable
List<Entity> tmp = new LinkedList<Entity>(arena.monsters);
for (Entity e : tmp)
{
if (e == null) continue;
if (e.isDead() || !arena.inRegion(e.getLocation()))
{
arena.monsters.remove(e);
@ -230,6 +232,8 @@ public class MASpawnThread implements Runnable
Location loc;
for (Entity e : tmp)
{
if (e == null) continue;
arena.monsters.remove(e);
loc = e.getLocation().getBlock().getRelative(0,2,0).getLocation();
arena.world.createExplosion(loc, 2);

View File

@ -84,8 +84,11 @@ public abstract class AbstractWave implements Wave
*/
public LivingEntity spawnMonster(MACreature creature, Location loc)
{
// Spawn and add to collection
// Spawn
LivingEntity e = creature.spawn(getArena(), getWorld(), loc);
if (e == null) return null;
// Add to collection
getArena().addMonster(e);
// Boost health

View File

@ -135,6 +135,8 @@ public class BossWave extends AbstractWave
cancelAbilityTask();
getArena().setBossWave(null);
if (bossCreature == null) return;
CraftEntity ce = (CraftEntity) bossCreature;
CraftWorld cw = (CraftWorld) getWorld();
WorldServer ws = cw.getHandle();

View File

@ -65,6 +65,7 @@ public class SwarmWave extends AbstractWave
for (int i = 0; i < amount; i++)
{
LivingEntity e = spawnMonster(monster, spawnpoints.get(i % spawnpointCount));
if (e == null) continue;
// Boost health
int health = (int) Math.min(150D, 1 * getHealthMultiplier());