CustomMobs/src/main/java/com/alttd/custommobs/abilities/modifiers/EntityAttributeModifier.java
Teriuihi 77f9cfe0a6 Add logging to debug entity attributes
Inserted debug logs to track attribute setting and entity modifiers. This will aid in troubleshooting issues related to entity spawning and attribute application.
2024-10-18 23:21:49 +02:00

50 lines
1.7 KiB
Java

package com.alttd.custommobs.abilities.modifiers;
import com.alttd.custommobs.Main;
import com.alttd.custommobs.abilities.EntityModifier;
import lombok.extern.slf4j.Slf4j;
import org.bukkit.NamespacedKey;
import org.bukkit.attribute.Attribute;
import org.bukkit.attribute.AttributeInstance;
import org.bukkit.attribute.AttributeModifier;
import org.bukkit.entity.LivingEntity;
@Slf4j
public class EntityAttributeModifier implements EntityModifier {
private final double value;
private final Attribute attribute;
private final Main main;
public EntityAttributeModifier(Main main, Attribute attribute, double value) {
this.main = main;
this.value = value;
this.attribute = attribute;
}
@Override
public void apply(LivingEntity entity) {
log.info("DEBUG: Setting attribute {} to {}", attribute.name(), value);
AttributeInstance attributeInstance = entity.getAttribute(attribute);
if (attributeInstance == null) {
log.warn("Entity {} has no {} attribute", entity.getName(), attribute.name());
return;
}
log.info("DEBUG: Setting attribute {} to {}", attribute.name(), value);
NamespacedKey namespacedKey = NamespacedKey.fromString("cm", main);
if (namespacedKey == null) {
log.error("Namespaced key was null when applying attribute modifier");
return;
}
AttributeModifier attributeModifier = new AttributeModifier(namespacedKey,
attributeInstance.getValue() - value,
AttributeModifier.Operation.ADD_NUMBER);
attributeInstance.addModifier(attributeModifier);
}
@Override
public String getName() {
return attribute.name();
}
}