Some fixes to prevent null pointer exceptions.

This commit is contained in:
LevelX2 2016-09-24 03:48:48 +02:00
parent 1ccd2a1b04
commit e81f26d539

View file

@ -237,6 +237,9 @@ public class Combat implements Serializable, Copyable<Combat> {
possibleDefenders = new HashSet<>(defenders);
}
Player player = game.getPlayer(attackerId);
if (player == null) {
return false;
}
if (possibleDefenders.size() == 1) {
addAttackerToCombat(creatureId, possibleDefenders.iterator().next(), game);
return true;
@ -866,7 +869,8 @@ public class Combat implements Serializable, Copyable<Combat> {
blockIsValid = true;
break CombatGroups;
} else // check if the blocker blocks a attacker that must be blocked at least by one and is the only blocker, this block is also valid
if (combatGroup.getBlockers().size() == 1) {
{
if (combatGroup.getBlockers().size() == 1) {
if (mustBeBlockedByAtLeastOne.containsKey(forcingAttackerId)) {
if (mustBeBlockedByAtLeastOne.get(forcingAttackerId).contains(creatureForcedToBlock.getId())) {
blockIsValid = true;
@ -874,6 +878,7 @@ public class Combat implements Serializable, Copyable<Combat> {
}
}
}
}
}
}
}
@ -921,8 +926,8 @@ public class Combat implements Serializable, Copyable<Combat> {
if (mustBeBlockedByAtLeastOne.containsKey(blockedAttackerId)) {
// blocks a creature that has to be blocked by at least one
if (combatGroupOfPossibleBlocker.getBlockers().size() == 1) {
Set <UUID> blockedSet = mustBeBlockedByAtLeastOne.get(blockedAttackerId);
Set <UUID> toBlockSet = mustBeBlockedByAtLeastOne.get(toBeBlockedCreatureId);
Set<UUID> blockedSet = mustBeBlockedByAtLeastOne.get(blockedAttackerId);
Set<UUID> toBlockSet = mustBeBlockedByAtLeastOne.get(toBeBlockedCreatureId);
if (toBlockSet == null) {
// This should never happen.
return null;