Fix mob using attack with no diseaseSkill causing errors

This commit is contained in:
P0nk
2022-09-12 20:31:38 +02:00
parent 0c6548a36d
commit d31f4806fc
14 changed files with 71 additions and 45 deletions

View File

@@ -47,20 +47,24 @@ public class MobSkillFactory {
private static final Lock readLock = readWriteLock.readLock();
private static final Lock writeLock = readWriteLock.writeLock();
public static MobSkill getMobSkill(final MobSkillType type, final int level) {
public static MobSkill getMobSkillOrThrow(MobSkillType type, int level) {
return getMobSkill(type, level).orElseThrow(
() -> new IllegalArgumentException("No MobSkill exists for type %s, level %d".formatted(type, level))
);
}
public static Optional<MobSkill> getMobSkill(final MobSkillType type, final int level) {
readLock.lock();
try {
MobSkill ms = mobSkills.get(createKey(type, level));
if (ms != null) {
return ms;
return Optional.of(ms);
}
} finally {
readLock.unlock();
}
return loadMobSkill(type, level).orElseThrow(
() -> new IllegalArgumentException("No MobSkill exists for type %s, level %d".formatted(type, level))
);
return loadMobSkill(type, level);
}
private static Optional<MobSkill> loadMobSkill(final MobSkillType type, final int level) {