9
0
mirror of https://github.com/Auxilor/EcoMobs.git synced 2025-12-21 16:09:24 +00:00

Fixed 2 effects with same name not being registered

This commit is contained in:
Auxilor
2021-08-28 15:53:10 +01:00
parent d135922dc1
commit 04eff9d3f3
2 changed files with 20 additions and 11 deletions

View File

@@ -13,6 +13,7 @@ import com.willfp.ecobosses.bosses.effects.Effect;
import com.willfp.ecobosses.bosses.effects.Effects; import com.willfp.ecobosses.bosses.effects.Effects;
import com.willfp.ecobosses.bosses.util.bosstype.BossEntityUtils; import com.willfp.ecobosses.bosses.util.bosstype.BossEntityUtils;
import com.willfp.ecobosses.bosses.util.bosstype.BossType; import com.willfp.ecobosses.bosses.util.bosstype.BossType;
import com.willfp.ecobosses.bosses.util.obj.ArgumentedEffectName;
import com.willfp.ecobosses.bosses.util.obj.BossbarProperties; import com.willfp.ecobosses.bosses.util.obj.BossbarProperties;
import com.willfp.ecobosses.bosses.util.obj.ExperienceOptions; import com.willfp.ecobosses.bosses.util.obj.ExperienceOptions;
import com.willfp.ecobosses.bosses.util.obj.ImmunityOptions; import com.willfp.ecobosses.bosses.util.obj.ImmunityOptions;
@@ -231,7 +232,7 @@ public class EcoBoss extends PluginDependent<EcoPlugin> {
/** /**
* The effect names and arguments. * The effect names and arguments.
*/ */
private final Map<String, List<String>> effectNames; private final List<ArgumentedEffectName> effectNames;
/** /**
* The target distance. * The target distance.
@@ -460,19 +461,19 @@ public class EcoBoss extends PluginDependent<EcoPlugin> {
} }
// Effects // Effects
this.effectNames = new HashMap<>(); this.effectNames = new ArrayList<>();
for (String string : this.getConfig().getStrings("effects")) { for (String string : this.getConfig().getStrings("effects")) {
String effectName = string.split(":")[0]; String effectName = string.split(":")[0];
List<String> args = Arrays.asList(string.replace(effectName + ":", "").split(":")); List<String> args = Arrays.asList(string.replace(effectName + ":", "").split(":"));
this.effectNames.put(effectName, args); this.effectNames.add(new ArgumentedEffectName(effectName, args));
} }
new HashMap<>(this.effectNames).forEach((string, args) -> { for (ArgumentedEffectName effectName : new ArrayList<>(this.effectNames)) {
if (Effects.getEffect(string, args) == null) { if (Effects.getEffect(effectName.name(), effectName.args()) == null) {
this.effectNames.remove(string); this.effectNames.remove(effectName);
Bukkit.getLogger().warning("Invalid effect specified in " + this.name); Bukkit.getLogger().warning("Invalid effect " + effectName.name() + " specified in " + this.name);
} }
}); }
// Targeting // Targeting
this.targetDistance = this.getConfig().getDouble("attacks.target.range"); this.targetDistance = this.getConfig().getDouble("attacks.target.range");
@@ -533,9 +534,9 @@ public class EcoBoss extends PluginDependent<EcoPlugin> {
*/ */
public List<Effect> createEffects() { public List<Effect> createEffects() {
List<Effect> effects = new ArrayList<>(); List<Effect> effects = new ArrayList<>();
this.effectNames.forEach((string, args) -> { for (ArgumentedEffectName effectName : this.effectNames) {
effects.add(Effects.getEffect(string, args)); effects.add(Effects.getEffect(effectName.name(), effectName.args()));
}); }
return effects; return effects;
} }

View File

@@ -0,0 +1,8 @@
package com.willfp.ecobosses.bosses.util.obj;
import org.jetbrains.annotations.NotNull;
import java.util.List;
public record ArgumentedEffectName(@NotNull String name, @NotNull List<String> args) {
}