Rework some of the wave parsing logic.
This commit is a full sweep across the WaveParser. It introduces the ConfigError exception to the WaveParser and throws it whenever something isn't right. There's quite a lot of stuff going on, but in overall: - Errors are thrown rather than null values being returned - Defaults are picked in lieu of explicit values when they "make sense" - Most list-type values can now be either the default comma-separated string or a string list Common nodes: - Spawnpoints can now be a string list Default waves: - Missing or empty monsters map throws an error - Missing wave growth defaults to medium - Invalid wave growth throws an error Special waves: - Missing or empty monsters map throws an error Swarm waves: - Missing or empty monster node throws an error - Missing swarm amount defaults to low - Invalid swarm amount throws an error Supply waves: - Missing or empty monsters map throws an error - Missing or empty drops node throws an error - Invalid drop throws an error - Drops can now be a string list Upgrade waves: - Missing or empty upgrades map throws an error Boss waves: - Missing or empty monster node throws an error - Missing or empty boss health defaults to medium - Invalid boss health throws an error - Invalid ability throws an error - Invalid drop throws an error - Abilities and drops can now be string lists
This commit is contained in:
@@ -2,7 +2,6 @@ package com.garbagemule.MobArena.waves;
|
|||||||
|
|
||||||
import com.garbagemule.MobArena.framework.Arena;
|
import com.garbagemule.MobArena.framework.Arena;
|
||||||
import com.garbagemule.MobArena.waves.enums.WaveBranch;
|
import com.garbagemule.MobArena.waves.enums.WaveBranch;
|
||||||
import com.garbagemule.MobArena.waves.enums.WaveError;
|
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
|
||||||
import java.util.SortedSet;
|
import java.util.SortedSet;
|
||||||
@@ -48,13 +47,18 @@ public class WaveManager
|
|||||||
finalWave = section.getParent().getInt("settings.final-wave", 0);
|
finalWave = section.getParent().getInt("settings.final-wave", 0);
|
||||||
|
|
||||||
if (recurrentWaves.isEmpty()) {
|
if (recurrentWaves.isEmpty()) {
|
||||||
arena.getPlugin().getLogger().warning(WaveError.NO_RECURRENT_WAVES.format(arena.configName()));
|
if (singleWaves.isEmpty()) {
|
||||||
|
arena.getPlugin().getLogger().warning("Found no waves for arena " + arena.configName() + ", using default wave.");
|
||||||
Wave def = WaveParser.createDefaultWave();
|
} else {
|
||||||
recurrentWaves.add(def);
|
arena.getPlugin().getLogger().info("Found no 'recurrent' waves for arena " + arena.configName() + ", using default wave.");
|
||||||
|
}
|
||||||
|
defaultWave = WaveParser.createDefaultWave();
|
||||||
|
} else {
|
||||||
|
if (singleWaves.isEmpty()) {
|
||||||
|
arena.getPlugin().getLogger().info("Found no 'single' waves for arena " + arena.configName());
|
||||||
|
}
|
||||||
|
defaultWave = recurrentWaves.first();
|
||||||
}
|
}
|
||||||
|
|
||||||
defaultWave = recurrentWaves.first();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ import com.garbagemule.MobArena.waves.ability.AbilityManager;
|
|||||||
import com.garbagemule.MobArena.waves.enums.BossHealth;
|
import com.garbagemule.MobArena.waves.enums.BossHealth;
|
||||||
import com.garbagemule.MobArena.waves.enums.SwarmAmount;
|
import com.garbagemule.MobArena.waves.enums.SwarmAmount;
|
||||||
import com.garbagemule.MobArena.waves.enums.WaveBranch;
|
import com.garbagemule.MobArena.waves.enums.WaveBranch;
|
||||||
import com.garbagemule.MobArena.waves.enums.WaveError;
|
|
||||||
import com.garbagemule.MobArena.waves.enums.WaveGrowth;
|
import com.garbagemule.MobArena.waves.enums.WaveGrowth;
|
||||||
import com.garbagemule.MobArena.waves.enums.WaveType;
|
import com.garbagemule.MobArena.waves.enums.WaveType;
|
||||||
import com.garbagemule.MobArena.waves.types.BossWave;
|
import com.garbagemule.MobArena.waves.types.BossWave;
|
||||||
@@ -33,7 +32,6 @@ import java.util.Collections;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.SortedMap;
|
import java.util.SortedMap;
|
||||||
import java.util.TreeMap;
|
import java.util.TreeMap;
|
||||||
@@ -48,14 +46,12 @@ public class WaveParser
|
|||||||
|
|
||||||
// If the config is null, return the empty set.
|
// If the config is null, return the empty set.
|
||||||
if (config == null) {
|
if (config == null) {
|
||||||
arena.getPlugin().getLogger().warning(WaveError.BRANCH_MISSING.format(branch.toString().toLowerCase(), arena.configName()));
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If no waves were found, return the empty set.
|
// If no waves were found, return the empty set.
|
||||||
Set<String> waves = config.getKeys(false);
|
Set<String> waves = config.getKeys(false);
|
||||||
if (waves == null) {
|
if (waves == null) {
|
||||||
arena.getPlugin().getLogger().warning(WaveError.BRANCH_MISSING.format(branch.toString().toLowerCase(), arena.configName()));
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,12 +59,6 @@ public class WaveParser
|
|||||||
for (String wave : waves) {
|
for (String wave : waves) {
|
||||||
ConfigurationSection waveSection = config.getConfigurationSection(wave);
|
ConfigurationSection waveSection = config.getConfigurationSection(wave);
|
||||||
Wave w = parseWave(arena, wave, waveSection, branch);
|
Wave w = parseWave(arena, wave, waveSection, branch);
|
||||||
|
|
||||||
// Only add properly parsed waves.
|
|
||||||
if (w == null) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
result.add(w);
|
result.add(w);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,8 +71,7 @@ public class WaveParser
|
|||||||
WaveType type = WaveType.fromString(t);
|
WaveType type = WaveType.fromString(t);
|
||||||
|
|
||||||
if (type == null) {
|
if (type == null) {
|
||||||
arena.getPlugin().getLogger().warning(WaveError.INVALID_TYPE.format(t, name, arena.configName()));
|
throw new ConfigError("Invalid wave type for wave " + name + " of arena " + arena.configName() + ": " + t);
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prepare the result
|
// Prepare the result
|
||||||
@@ -110,12 +99,6 @@ public class WaveParser
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check that the result isn't null
|
|
||||||
if (result == null) {
|
|
||||||
arena.getPlugin().getLogger().warning(WaveError.INVALID_WAVE.format(name, arena.configName()));
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Grab the branch-specific nodes.
|
// Grab the branch-specific nodes.
|
||||||
int priority = config.getInt("priority", -1);
|
int priority = config.getInt("priority", -1);
|
||||||
int frequency = config.getInt("frequency", -1);
|
int frequency = config.getInt("frequency", -1);
|
||||||
@@ -139,12 +122,15 @@ public class WaveParser
|
|||||||
List<PotionEffect> effects = getPotionEffects(arena, name, config);
|
List<PotionEffect> effects = getPotionEffects(arena, name, config);
|
||||||
|
|
||||||
// Recurrent must have priority + frequency, single must have firstWave
|
// Recurrent must have priority + frequency, single must have firstWave
|
||||||
if (branch == WaveBranch.RECURRENT && (priority == -1 || frequency <= 0)) {
|
if (branch == WaveBranch.RECURRENT) {
|
||||||
arena.getPlugin().getLogger().warning(WaveError.RECURRENT_NODES.format(name, arena.configName()));
|
if (priority <= 0) {
|
||||||
return null;
|
throw new ConfigError("Missing or invalid 'priority' node for recurrent wave " + name + " of arena " + arena.configName());
|
||||||
|
}
|
||||||
|
if (frequency <= 0) {
|
||||||
|
throw new ConfigError("Missing or invalid 'frequency' node for recurrent wave " + name + " of arena " + arena.configName());
|
||||||
|
}
|
||||||
} else if (branch == WaveBranch.SINGLE && firstWave <= 0) {
|
} else if (branch == WaveBranch.SINGLE && firstWave <= 0) {
|
||||||
arena.getPlugin().getLogger().warning(WaveError.SINGLE_NODES.format(name, arena.configName()));
|
throw new ConfigError("Missing or invalid 'wave' node for single wave " + name + " of arena " + arena.configName());
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the important required values.
|
// Set the important required values.
|
||||||
@@ -169,11 +155,7 @@ public class WaveParser
|
|||||||
|
|
||||||
private static Wave parseDefaultWave(Arena arena, String name, ConfigurationSection config) {
|
private static Wave parseDefaultWave(Arena arena, String name, ConfigurationSection config) {
|
||||||
// Grab the monster map.
|
// Grab the monster map.
|
||||||
SortedMap<Integer,MACreature> monsters = getMonsterMap(config);
|
SortedMap<Integer,MACreature> monsters = getMonsterMap(arena, name, config);
|
||||||
if (monsters == null || monsters.isEmpty()) {
|
|
||||||
arena.getPlugin().getLogger().warning(WaveError.MONSTER_MAP_MISSING.format(name, arena.configName()));
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create the wave.
|
// Create the wave.
|
||||||
DefaultWave result = new DefaultWave(monsters);
|
DefaultWave result = new DefaultWave(monsters);
|
||||||
@@ -186,53 +168,72 @@ public class WaveParser
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Grab the WaveGrowth
|
// Grab the WaveGrowth
|
||||||
String grw = config.getString("growth");
|
String grw = config.getString("growth", null);
|
||||||
WaveGrowth growth = WaveGrowth.fromString(grw);
|
if (grw != null && !grw.isEmpty()) {
|
||||||
result.setGrowth(growth);
|
try {
|
||||||
|
WaveGrowth growth = WaveGrowth.valueOf(grw.toUpperCase());
|
||||||
|
result.setGrowth(growth);
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
throw new ConfigError("Failed to parse wave growth for wave " + name + " of arena " + arena.configName() + ": " + grw);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
result.setGrowth(WaveGrowth.MEDIUM);
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Wave parseSpecialWave(Arena arena, String name, ConfigurationSection config) {
|
private static Wave parseSpecialWave(Arena arena, String name, ConfigurationSection config) {
|
||||||
SortedMap<Integer,MACreature> monsters = getMonsterMap(config);
|
SortedMap<Integer,MACreature> monsters = getMonsterMap(arena, name, config);
|
||||||
if (monsters == null || monsters.isEmpty()) {
|
|
||||||
arena.getPlugin().getLogger().warning(WaveError.MONSTER_MAP_MISSING.format(name, arena.configName()));
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
SpecialWave result = new SpecialWave(monsters);
|
return new SpecialWave(monsters);
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Wave parseSwarmWave(Arena arena, String name, ConfigurationSection config) {
|
private static Wave parseSwarmWave(Arena arena, String name, ConfigurationSection config) {
|
||||||
MACreature monster = getSingleMonster(config);
|
MACreature monster = getSingleMonster(arena, name, config);
|
||||||
if (monster == null) {
|
|
||||||
arena.getPlugin().getLogger().warning(WaveError.SINGLE_MONSTER_MISSING.format(name, arena.configName()));
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
SwarmWave result = new SwarmWave(monster);
|
SwarmWave result = new SwarmWave(monster);
|
||||||
|
|
||||||
// Grab SwarmAmount
|
// Grab SwarmAmount
|
||||||
String amnt = config.getString("amount");
|
String amnt = config.getString("amount", null);
|
||||||
SwarmAmount amount = SwarmAmount.fromString(amnt);
|
if (amnt != null && !amnt.isEmpty()) {
|
||||||
result.setAmount(amount);
|
try {
|
||||||
|
SwarmAmount amount = SwarmAmount.valueOf(amnt.toUpperCase());
|
||||||
|
result.setAmount(amount);
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
throw new ConfigError("Failed to parse wave amount for wave " + name + " of arena " + arena.configName() + ": " + amnt);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
result.setAmount(SwarmAmount.LOW);
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Wave parseSupplyWave(Arena arena, String name, ConfigurationSection config) {
|
private static Wave parseSupplyWave(Arena arena, String name, ConfigurationSection config) {
|
||||||
SortedMap<Integer,MACreature> monsters = getMonsterMap(config);
|
SortedMap<Integer,MACreature> monsters = getMonsterMap(arena, name, config);
|
||||||
if (monsters == null || monsters.isEmpty()) {
|
|
||||||
arena.getPlugin().getLogger().warning(WaveError.MONSTER_MAP_MISSING.format(name, arena.configName()));
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
SupplyWave result = new SupplyWave(monsters);
|
SupplyWave result = new SupplyWave(monsters);
|
||||||
|
|
||||||
// Grab the loot.
|
// Grab the loot.
|
||||||
String loot = config.getString("drops");
|
List<String> loot = config.getStringList("drops");
|
||||||
List<ItemStack> stacks = ItemParser.parseItems(loot);
|
if (loot == null || loot.isEmpty()) {
|
||||||
|
String value = config.getString("drops", null);
|
||||||
|
if (value == null) {
|
||||||
|
throw new ConfigError("Missing 'drops' node for wave " + name + " of arena " + arena.configName());
|
||||||
|
}
|
||||||
|
loot = Arrays.asList(value.split(","));
|
||||||
|
}
|
||||||
|
List<ItemStack> stacks = loot.stream()
|
||||||
|
.map(String::trim)
|
||||||
|
.map(value -> {
|
||||||
|
ItemStack stack = ItemParser.parseItem(value, false);
|
||||||
|
if (stack == null) {
|
||||||
|
throw new ConfigError("Failed to parse loot for wave " + name + " of arena " + arena.configName() + ": " + value);
|
||||||
|
}
|
||||||
|
return stack;
|
||||||
|
})
|
||||||
|
.collect(Collectors.toList());
|
||||||
result.setDropList(stacks);
|
result.setDropList(stacks);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
@@ -241,72 +242,69 @@ public class WaveParser
|
|||||||
private static Wave parseUpgradeWave(Arena arena, String name, ConfigurationSection config) {
|
private static Wave parseUpgradeWave(Arena arena, String name, ConfigurationSection config) {
|
||||||
ThingManager thingman = arena.getPlugin().getThingManager();
|
ThingManager thingman = arena.getPlugin().getThingManager();
|
||||||
Map<String,List<Thing>> upgrades = getUpgradeMap(config, name, arena, thingman);
|
Map<String,List<Thing>> upgrades = getUpgradeMap(config, name, arena, thingman);
|
||||||
if (upgrades == null || upgrades.isEmpty()) {
|
|
||||||
arena.getPlugin().getLogger().warning(WaveError.UPGRADE_MAP_MISSING.format(name, arena.configName()));
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return new UpgradeWave(upgrades);
|
return new UpgradeWave(upgrades);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Wave parseBossWave(Arena arena, String name, ConfigurationSection config) {
|
private static Wave parseBossWave(Arena arena, String name, ConfigurationSection config) {
|
||||||
MACreature monster = getSingleMonster(config);
|
MACreature monster = getSingleMonster(arena, name, config);
|
||||||
if (monster == null) {
|
|
||||||
arena.getPlugin().getLogger().warning(WaveError.SINGLE_MONSTER_MISSING.format(name, arena.configName()));
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
BossWave result = new BossWave(monster);
|
BossWave result = new BossWave(monster);
|
||||||
|
|
||||||
// Check if there's a specific boss name
|
// Check if there's a specific boss name
|
||||||
String bossName = config.getString("name");
|
String bossName = config.getString("name", null);
|
||||||
if (bossName != null && !bossName.equals("")) {
|
if (bossName != null && !bossName.isEmpty()) {
|
||||||
result.setBossName(bossName);
|
result.setBossName(bossName);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Grab the boss health
|
// Grab the boss health
|
||||||
String healthString = config.getString("health");
|
String healthString = config.getString("health", null);
|
||||||
if (healthString == null) {
|
if (healthString != null && !healthString.isEmpty()) {
|
||||||
String warning = "No health value found for boss '%s' in arena '%s'. Defaulting to medium.";
|
try {
|
||||||
arena.getPlugin().getLogger().warning(String.format(warning, name, arena.configName()));
|
BossHealth health = BossHealth.valueOf(healthString.toUpperCase());
|
||||||
result.setHealth(BossHealth.MEDIUM);
|
|
||||||
} else {
|
|
||||||
BossHealth health = BossHealth.fromString(healthString);
|
|
||||||
if (health != null) {
|
|
||||||
result.setHealth(health);
|
result.setHealth(health);
|
||||||
} else {
|
} catch (IllegalArgumentException e) {
|
||||||
int flatHealth = config.getInt("health", 0);
|
int flatHealth = config.getInt("health", -1);
|
||||||
if (flatHealth <= 0) {
|
if (flatHealth < 0) {
|
||||||
String warning = "Unable to parse health of boss '%s' in arena '%s'. Defaulting to medium. Value was '%s'";
|
throw new ConfigError("Failed to parse boss health for wave " + name + " of arena " + arena.configName() + ": " + healthString);
|
||||||
arena.getPlugin().getLogger().warning(String.format(warning, name, arena.configName(), healthString));
|
|
||||||
result.setHealth(BossHealth.MEDIUM);
|
|
||||||
} else {
|
|
||||||
result.setFlatHealth(flatHealth);
|
|
||||||
}
|
}
|
||||||
|
result.setFlatHealth(flatHealth);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
result.setHealth(BossHealth.MEDIUM);
|
||||||
}
|
}
|
||||||
|
|
||||||
// And the abilities.
|
// And the abilities.
|
||||||
String ablts = config.getString("abilities");
|
List<String> abilities = config.getStringList("abilities");
|
||||||
if (ablts != null) {
|
if (abilities == null || abilities.isEmpty()) {
|
||||||
String[] parts = ablts.split(",");
|
String value = config.getString("abilities", null);
|
||||||
for (String ability : parts) {
|
if (value == null) {
|
||||||
Ability a = AbilityManager.getAbility(ability.trim());
|
abilities = Collections.emptyList();
|
||||||
if (a == null) {
|
} else {
|
||||||
arena.getPlugin().getLogger().warning(WaveError.BOSS_ABILITY.format(ability.trim(), name, arena.configName()));
|
abilities = Arrays.asList(value.split(","));
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
result.addBossAbility(a);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (abilities.isEmpty()) {
|
||||||
|
arena.getPlugin().getLogger().warning("No boss abilities for boss wave " + name + " of arena " + arena.configName());
|
||||||
|
}
|
||||||
|
abilities.stream()
|
||||||
|
.map(String::trim)
|
||||||
|
.map(value -> {
|
||||||
|
Ability ability = AbilityManager.getAbility(value);
|
||||||
|
if (ability == null) {
|
||||||
|
throw new ConfigError("Failed to parse boss ability for boss wave " + name + " of arena " + arena.configName() + ": " + value);
|
||||||
|
}
|
||||||
|
return ability;
|
||||||
|
})
|
||||||
|
.forEach(result::addBossAbility);
|
||||||
|
|
||||||
// As well as the ability interval and ability announce.
|
// As well as the ability interval and ability announce.
|
||||||
result.setAbilityInterval(config.getInt("ability-interval", 3) * 20);
|
result.setAbilityInterval(config.getInt("ability-interval", 3) * 20);
|
||||||
result.setAbilityAnnounce(config.getBoolean("ability-announce", true));
|
result.setAbilityAnnounce(config.getBoolean("ability-announce", true));
|
||||||
|
|
||||||
// Rewards!
|
// Rewards!
|
||||||
String rew = config.getString("reward");
|
String rew = config.getString("reward", null);
|
||||||
if (rew != null) {
|
if (rew != null && !rew.isEmpty()) {
|
||||||
try {
|
try {
|
||||||
Thing thing = arena.getPlugin().getThingManager().parse(rew.trim());
|
Thing thing = arena.getPlugin().getThingManager().parse(rew.trim());
|
||||||
result.setReward(thing);
|
result.setReward(thing);
|
||||||
@@ -316,9 +314,26 @@ public class WaveParser
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Drops!
|
// Drops!
|
||||||
String drp = config.getString("drops");
|
List<String> drops = config.getStringList("drops");
|
||||||
List<ItemStack> drops = ItemParser.parseItems(drp);
|
if (drops == null || drops.isEmpty()) {
|
||||||
result.setDrops(drops);
|
String value = config.getString("drops", null);
|
||||||
|
if (value == null) {
|
||||||
|
drops = Collections.emptyList();
|
||||||
|
} else {
|
||||||
|
drops = Arrays.asList(value.split(","));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
List<ItemStack> stacks = drops.stream()
|
||||||
|
.map(String::trim)
|
||||||
|
.map(value -> {
|
||||||
|
ItemStack stack = ItemParser.parseItem(value, false);
|
||||||
|
if (stack == null) {
|
||||||
|
throw new ConfigError("Failed to parse boss drop in wave " + name + " of arena " + arena.configName() + ": " + value);
|
||||||
|
}
|
||||||
|
return stack;
|
||||||
|
})
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
result.setDrops(stacks);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -329,13 +344,16 @@ public class WaveParser
|
|||||||
* @param config a ConfigSection
|
* @param config a ConfigSection
|
||||||
* @return an MACreature, if the monster node contains one that is valid
|
* @return an MACreature, if the monster node contains one that is valid
|
||||||
*/
|
*/
|
||||||
private static MACreature getSingleMonster(ConfigurationSection config) {
|
private static MACreature getSingleMonster(Arena arena, String name, ConfigurationSection config) {
|
||||||
String monster = config.getString("monster");
|
String monster = config.getString("monster", null);
|
||||||
if (monster == null) {
|
if (monster == null || monster.isEmpty()) {
|
||||||
return null;
|
throw new ConfigError("Missing 'monster' node for wave " + name + " of arena " + arena.configName());
|
||||||
}
|
}
|
||||||
|
|
||||||
MACreature result = MACreature.fromString(monster);
|
MACreature result = MACreature.fromString(monster);
|
||||||
|
if (result == null) {
|
||||||
|
throw new ConfigError("Failed to parse monster for wave " + name + " of arena " + arena.configName() + ": " + monster);
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -345,15 +363,15 @@ public class WaveParser
|
|||||||
* @param config
|
* @param config
|
||||||
* @return a "reverse" map of monsters and numbers
|
* @return a "reverse" map of monsters and numbers
|
||||||
*/
|
*/
|
||||||
private static SortedMap<Integer,MACreature> getMonsterMap(ConfigurationSection config) {
|
private static SortedMap<Integer,MACreature> getMonsterMap(Arena arena, String name, ConfigurationSection config) {
|
||||||
ConfigurationSection section = config.getConfigurationSection("monsters");
|
ConfigurationSection section = config.getConfigurationSection("monsters");
|
||||||
if (section == null) {
|
if (section == null) {
|
||||||
return null;
|
throw new ConfigError("Missing 'monsters' node for wave " + name + " of arena " + arena.configName());
|
||||||
}
|
}
|
||||||
|
|
||||||
Set<String> monsters = section.getKeys(false);
|
Set<String> monsters = section.getKeys(false);
|
||||||
if (monsters == null || monsters.isEmpty()) {
|
if (monsters == null || monsters.isEmpty()) {
|
||||||
return null;
|
throw new ConfigError("Empty 'monsters' node for wave " + name + " of arena " + arena.configName());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prepare the map.
|
// Prepare the map.
|
||||||
@@ -364,10 +382,14 @@ public class WaveParser
|
|||||||
// Check all the monsters.
|
// Check all the monsters.
|
||||||
for (String monster : monsters) {
|
for (String monster : monsters) {
|
||||||
MACreature creature = MACreature.fromString(monster);
|
MACreature creature = MACreature.fromString(monster);
|
||||||
if (creature == null) continue;
|
if (creature == null) {
|
||||||
|
throw new ConfigError("Failed to parse monster for wave " + name + " of arena " + arena.configName() + ": " + monster);
|
||||||
|
}
|
||||||
|
|
||||||
int prob = config.getInt(path + monster, 0);
|
int prob = config.getInt(path + monster, -1);
|
||||||
if (prob == 0) continue;
|
if (prob < 0) {
|
||||||
|
throw new ConfigError("Failed to parse probability for monster " + monster + " in wave " + name + " of arena " + arena.configName());
|
||||||
|
}
|
||||||
|
|
||||||
sum += prob;
|
sum += prob;
|
||||||
monsterMap.put(sum, creature);
|
monsterMap.put(sum, creature);
|
||||||
@@ -377,29 +399,26 @@ public class WaveParser
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static List<Location> getSpawnpoints(Arena arena, String name, ConfigurationSection config) {
|
private static List<Location> getSpawnpoints(Arena arena, String name, ConfigurationSection config) {
|
||||||
List<Location> result = new ArrayList<>();
|
List<String> spawnpoints = config.getStringList("spawnpoints");
|
||||||
|
if (spawnpoints == null || spawnpoints.isEmpty()) {
|
||||||
String spawnString = config.getString("spawnpoints");
|
String value = config.getString("spawnpoints", null);
|
||||||
if (spawnString == null) {
|
if (value == null || value.isEmpty()) {
|
||||||
return result;
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
spawnpoints = Arrays.asList(value.split(";"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Split the string by semicolons
|
|
||||||
String[] spawns = spawnString.split(";");
|
|
||||||
|
|
||||||
ArenaRegion region = arena.getRegion();
|
ArenaRegion region = arena.getRegion();
|
||||||
for (String spawn : spawns) {
|
return spawnpoints.stream()
|
||||||
Location spawnpoint = region.getSpawnpoint(spawn.trim());
|
.map(String::trim)
|
||||||
|
.map(value -> {
|
||||||
if (spawnpoint == null) {
|
Location spawnpoint = region.getSpawnpoint(value);
|
||||||
arena.getPlugin().getLogger().warning("Spawnpoint '" + spawn + "' in wave '" + name + "' for arena '" + arena.configName() + "' could not be parsed!");
|
if (spawnpoint == null) {
|
||||||
continue;
|
throw new ConfigError("Spawnpoint '" + value + "' in wave '" + name + "' for arena '" + arena.configName() + "' could not be parsed!");
|
||||||
}
|
}
|
||||||
|
return spawnpoint;
|
||||||
result.add(spawnpoint);
|
})
|
||||||
}
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<PotionEffect> getPotionEffects(Arena arena, String name, ConfigurationSection config) {
|
private static List<PotionEffect> getPotionEffects(Arena arena, String name, ConfigurationSection config) {
|
||||||
@@ -439,12 +458,12 @@ public class WaveParser
|
|||||||
private static Map<String,List<Thing>> getUpgradeMap(ConfigurationSection config, String name, Arena arena, ThingManager thingman) {
|
private static Map<String,List<Thing>> getUpgradeMap(ConfigurationSection config, String name, Arena arena, ThingManager thingman) {
|
||||||
ConfigurationSection section = config.getConfigurationSection("upgrades");
|
ConfigurationSection section = config.getConfigurationSection("upgrades");
|
||||||
if (section == null) {
|
if (section == null) {
|
||||||
return null;
|
throw new ConfigError("Missing 'upgrades' node for wave " + name + " of arena " + arena.configName());
|
||||||
}
|
}
|
||||||
|
|
||||||
Set<String> classes = section.getKeys(false);
|
Set<String> classes = section.getKeys(false);
|
||||||
if (classes == null || classes.isEmpty()) {
|
if (classes == null || classes.isEmpty()) {
|
||||||
return null;
|
throw new ConfigError("Empty 'upgrades' node for wave " + name + " of arena " + arena.configName());
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String,List<Thing>> upgrades = new HashMap<>();
|
Map<String,List<Thing>> upgrades = new HashMap<>();
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
package com.garbagemule.MobArena.waves.enums;
|
package com.garbagemule.MobArena.waves.enums;
|
||||||
|
|
||||||
import com.garbagemule.MobArena.waves.WaveUtils;
|
|
||||||
|
|
||||||
public enum BossHealth
|
public enum BossHealth
|
||||||
{
|
{
|
||||||
VERYLOW(4), LOW(8), MEDIUM(15), HIGH(25), VERYHIGH(40), PSYCHO(60);
|
VERYLOW(4), LOW(8), MEDIUM(15), HIGH(25), VERYHIGH(40), PSYCHO(60);
|
||||||
@@ -18,8 +16,4 @@ public enum BossHealth
|
|||||||
public int getMultiplier() {
|
public int getMultiplier() {
|
||||||
return multiplier;
|
return multiplier;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static BossHealth fromString(String string) {
|
|
||||||
return WaveUtils.getEnumFromString(BossHealth.class, string, null);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,5 @@
|
|||||||
package com.garbagemule.MobArena.waves.enums;
|
package com.garbagemule.MobArena.waves.enums;
|
||||||
|
|
||||||
import com.garbagemule.MobArena.waves.WaveUtils;
|
|
||||||
|
|
||||||
public enum SwarmAmount
|
public enum SwarmAmount
|
||||||
{
|
{
|
||||||
LOW(10), MEDIUM(20), HIGH(30), PSYCHO(60);
|
LOW(10), MEDIUM(20), HIGH(30), PSYCHO(60);
|
||||||
@@ -14,8 +12,4 @@ public enum SwarmAmount
|
|||||||
public int getAmount(int playerCount) {
|
public int getAmount(int playerCount) {
|
||||||
return Math.max(1, playerCount / 2) * multiplier;
|
return Math.max(1, playerCount / 2) * multiplier;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SwarmAmount fromString(String string) {
|
|
||||||
return WaveUtils.getEnumFromString(SwarmAmount.class, string, LOW);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
package com.garbagemule.MobArena.waves.enums;
|
|
||||||
|
|
||||||
public enum WaveError
|
|
||||||
{
|
|
||||||
INVALID_WAVE("Wave '%s' for arena '%s' could not be parsed."),
|
|
||||||
NO_RECURRENT_WAVES("No valid recurrent waves found for arena '%s'. Check the config-file. Using implicit default wave."),
|
|
||||||
|
|
||||||
BRANCH_MISSING("The '%s' branch for arena '%s' is empty. Check the config-file."),
|
|
||||||
INVALID_TYPE("Invalid type '%s' for wave '%s' in arena '%s'. Skipping..."),
|
|
||||||
|
|
||||||
RECURRENT_NODES("Recurrent wave '%s' in arena '%s' is missing either the 'frequency' or the 'priority' node. Skipping..."),
|
|
||||||
SINGLE_NODES("Single wave '%s' in arena '%s' is missing the 'wave' node. Skipping..."),
|
|
||||||
|
|
||||||
MONSTER_MAP_MISSING("Missing 'monsters' node for wave '%s' in arena '%s'."),
|
|
||||||
SINGLE_MONSTER_MISSING("Missing 'monster' node for wave '%s' in arena '%s'."),
|
|
||||||
|
|
||||||
BOSS_ABILITY("Invalid boss ability '%s' for wave '%s' in arena '%s'."),
|
|
||||||
|
|
||||||
SUPPLY_DROPS("Missing 'drops' node for wave '%s' in arena '%s'."),
|
|
||||||
|
|
||||||
UPGRADE_MAP_MISSING("Missing 'upgrades' node for wave '%s' in arena '%s'.");
|
|
||||||
|
|
||||||
private String msg;
|
|
||||||
|
|
||||||
WaveError(String msg) {
|
|
||||||
this.msg = msg;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String format(Object... args) {
|
|
||||||
return String.format(msg, args);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,7 +1,5 @@
|
|||||||
package com.garbagemule.MobArena.waves.enums;
|
package com.garbagemule.MobArena.waves.enums;
|
||||||
|
|
||||||
import com.garbagemule.MobArena.waves.WaveUtils;
|
|
||||||
|
|
||||||
public enum WaveGrowth
|
public enum WaveGrowth
|
||||||
{
|
{
|
||||||
OLD(0), SLOW(0.5), MEDIUM(0.65), FAST(0.8), PSYCHO(1.2);
|
OLD(0), SLOW(0.5), MEDIUM(0.65), FAST(0.8), PSYCHO(1.2);
|
||||||
@@ -11,10 +9,6 @@ public enum WaveGrowth
|
|||||||
this.exp = exp;
|
this.exp = exp;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static WaveGrowth fromString(String string) {
|
|
||||||
return WaveUtils.getEnumFromString(WaveGrowth.class, string, OLD);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getAmount(int wave, int playerCount) {
|
public int getAmount(int wave, int playerCount) {
|
||||||
if (this == OLD) return wave + playerCount;
|
if (this == OLD) return wave + playerCount;
|
||||||
|
|
||||||
|
|||||||
@@ -51,6 +51,10 @@ public enum WaveType
|
|||||||
public abstract void announce(Arena arena, int wave);
|
public abstract void announce(Arena arena, int wave);
|
||||||
|
|
||||||
public static WaveType fromString(String string) {
|
public static WaveType fromString(String string) {
|
||||||
return WaveUtils.getEnumFromString(WaveType.class, string);
|
try {
|
||||||
|
return WaveType.valueOf(string.toUpperCase());
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user