Fix Exceptions

This commit is contained in:
MistPhizzle 2014-08-25 16:47:56 -04:00
parent 6453cc9897
commit a11eb336e6

View file

@ -1,7 +1,9 @@
package com.projectkorra.ProjectKorra.airbending; package com.projectkorra.ProjectKorra.airbending;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.ConcurrentModificationException;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
@ -31,7 +33,7 @@ public class Suffocate {
private Player player; private Player player;
private long time; private long time;
private long warmup = 2000; private long warmup = 2000;
private PotionEffect slow = new PotionEffect(PotionEffectType.SLOW, 60, 1); private PotionEffect slow = new PotionEffect(PotionEffectType.SLOW, 60, 1);
private PotionEffect nausea = new PotionEffect(PotionEffectType.SLOW, 60, 1); private PotionEffect nausea = new PotionEffect(PotionEffectType.SLOW, 60, 1);
@ -40,7 +42,7 @@ public class Suffocate {
remove(player); remove(player);
return; return;
} }
if (AvatarState.isAvatarState(player)) { if (AvatarState.isAvatarState(player)) {
range = AvatarState.getValue(range); range = AvatarState.getValue(range);
for (Entity entity: Methods.getEntitiesAroundPoint(player.getLocation(), range)) { for (Entity entity: Methods.getEntitiesAroundPoint(player.getLocation(), range)) {
@ -54,7 +56,7 @@ public class Suffocate {
targets.put(en, en.getLocation()); targets.put(en, en.getLocation());
} }
} }
this.player = player; this.player = player;
instances.put(player, this); instances.put(player, this);
time = System.currentTimeMillis(); time = System.currentTimeMillis();
@ -65,78 +67,86 @@ public class Suffocate {
remove(player); remove(player);
return; return;
} }
if (player.isDead()) { if (player.isDead()) {
remove(player); remove(player);
return; return;
} }
if (!Methods.canBend(player.getName(), "Suffocate")) { if (!Methods.canBend(player.getName(), "Suffocate")) {
remove(player); remove(player);
return; return;
} }
if (Methods.getBoundAbility(player) == null || !Methods.getBoundAbility(player).equalsIgnoreCase("Suffocate")) { if (Methods.getBoundAbility(player) == null || !Methods.getBoundAbility(player).equalsIgnoreCase("Suffocate")) {
remove(player); remove(player);
return; return;
} }
for (Entity entity: targets.keySet()) { try {
if (targets.isEmpty()) { for (Entity entity: targets.keySet()) {
remove(player); if (!targets.keySet().iterator().hasNext()) {
return; remove(player);
} return;
if (isUndead(entity) && !canBeUsedOnUndead) { }
breakSuffocate(entity); if (targets.isEmpty()) {
continue; remove(player);
} return;
}
if (entity.getLocation().getBlock() != null && Methods.isWater(entity.getLocation().getBlock())) { if (isUndead(entity) && !canBeUsedOnUndead) {
breakSuffocate(entity);
continue;
}
if (Methods.isRegionProtectedFromBuild(player, "Suffocate", entity.getLocation())) {
remove(player);
continue;
}
if (entity.getLocation().distance(player.getLocation()) >= range) {
breakSuffocate(entity);
continue;
}
if (Methods.isObstructed(player.getLocation(), entity.getLocation())) {
breakSuffocate(entity);
continue;
}
if (entity instanceof Player) {
if (AvatarState.isAvatarState((Player) entity)) {
breakSuffocate(entity); breakSuffocate(entity);
continue; continue;
} }
}
if (entity.isDead()) {
breakSuffocate(entity);
continue;
}
if (entity instanceof Creature) {
((Creature) entity).setTarget(player);
}
for(Location airsphere : Methods.getCircle(entity.getLocation(), 3, 3, false, true, 0)) { if (entity.getLocation().getBlock() != null && Methods.isWater(entity.getLocation().getBlock())) {
Methods.playAirbendingParticles(airsphere, 1); breakSuffocate(entity);
} continue;
entity.setFallDistance(0); }
new TempPotionEffect((LivingEntity) entity, slow);
new TempPotionEffect((LivingEntity) entity, nausea); if (Methods.isRegionProtectedFromBuild(player, "Suffocate", entity.getLocation())) {
if (System.currentTimeMillis() >= time + warmup) { remove(player);
Methods.damageEntity(player, entity, damage); continue;
entity.teleport(entity); }
if (entity.getLocation().distance(player.getLocation()) >= range) {
breakSuffocate(entity);
continue;
}
if (Methods.isObstructed(player.getLocation(), entity.getLocation())) {
breakSuffocate(entity);
continue;
}
if (entity instanceof Player) {
if (AvatarState.isAvatarState((Player) entity)) {
breakSuffocate(entity);
continue;
}
}
if (entity.isDead()) {
breakSuffocate(entity);
continue;
}
if (entity instanceof Creature) {
((Creature) entity).setTarget(player);
}
for(Location airsphere : Methods.getCircle(entity.getLocation(), 3, 3, false, true, 0)) {
Methods.playAirbendingParticles(airsphere, 1);
}
entity.setFallDistance(0);
new TempPotionEffect((LivingEntity) entity, slow);
new TempPotionEffect((LivingEntity) entity, nausea);
if (System.currentTimeMillis() >= time + warmup) {
Methods.damageEntity(player, entity, damage);
entity.teleport(entity);
}
} }
} catch (ConcurrentModificationException e) {
} }
} }