Skip to content

Commit

Permalink
fix(affix): fix potential crash caused by null attribute
Browse files Browse the repository at this point in the history
fix #13
  • Loading branch information
WakelessSloth56 committed May 19, 2022
1 parent 6f9fc70 commit 3e04721
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
package org.auioc.mcmod.extrachampions.api.affix;

import static org.auioc.mcmod.extrachampions.ExtraChampions.LOGGER;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.function.Supplier;
import com.electronwill.nightconfig.core.UnmodifiableConfig;
import com.electronwill.nightconfig.core.conversion.ObjectConverter;
import org.apache.logging.log4j.Marker;
import org.auioc.mcmod.arnicalib.utils.LogUtil;
import org.auioc.mcmod.extrachampions.api.exception.AutoConfigBuildingException;
import net.minecraftforge.common.ForgeConfigSpec;
import net.minecraftforge.registries.ForgeRegistries;
import top.theillusivec4.champions.api.AffixCategory;
import top.theillusivec4.champions.api.IChampion;
import top.theillusivec4.champions.common.affix.core.BasicAffix;

public abstract class ExtraAffix<C> extends BasicAffix {

private static final Marker MARKER = LogUtil.getMarker(ExtraAffix.class);

protected C config;
private final AffixBasicConfig basicConfig;

Expand Down Expand Up @@ -71,4 +78,8 @@ protected void buildExtraConfig(ForgeConfigSpec.Builder builder) {
}
}

protected void warn(IChampion champion) {
LOGGER.warn(MARKER, "Affix '" + this.getIdentifier() + "' should not be applied to entity '" + ForgeRegistries.ENTITIES.getKey(champion.getLivingEntity().getType()) + "', please add it to the blacklist");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,15 @@ public AcupunctureAffix() {
@Override
public void onSpawn(IChampion champion) {
var attr = champion.getLivingEntity().getAttribute(Attributes.ATTACK_DAMAGE);
if (attr == null) {
this.warn(champion);
return;
}

var modifier = getModifier();
if (!attr.hasModifier(modifier)) {
attr.addPermanentModifier(modifier);
}

}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,13 @@ public FuryAffix() {
@Override
public void onServerUpdate(IChampion champion) {
var living = champion.getLivingEntity();

var attr = living.getAttribute(Attributes.ATTACK_DAMAGE);
if (attr == null) {
this.warn(champion);
return;
}

var modifier = getModifier();
if (isHealthLow(living)) {
if (!attr.hasModifier(modifier)) {
Expand Down

0 comments on commit 3e04721

Please sign in to comment.