Compare commits

...

9 Commits
master ... test

Author SHA1 Message Date
Teriuihi 3da2b37aed Fix config string format in MobTypes.java
Replaced concatenation with String.format for clarity and consistency. This change ensures that the configuration strings are constructed correctly, preventing potential runtime errors.
2024-10-18 23:53:59 +02:00
Teriuihi e8b926ab41 Fix config string format in MobTypes.java
Replaced concatenation with String.format for clarity and consistency. This change ensures that the configuration strings are constructed correctly, preventing potential runtime errors.
2024-10-18 23:51:54 +02:00
Teriuihi f36bc6fc7f build commit 2024-10-18 23:49:42 +02:00
Teriuihi f3fa8563e6 build commit 2024-10-18 23:46:29 +02:00
Teriuihi 07b5010f74 build commit 2024-10-18 23:42:30 +02:00
Teriuihi 153543fb1f build commit 2024-10-18 23:37:18 +02:00
Teriuihi d29c3eb3c3 Add debug print statement to config load method
Inserted a temporary debug print statement for diagnostic purposes in the `Config.load` method. This will help in identifying issues during the configuration loading process.
2024-10-18 23:30:21 +02:00
Teriuihi 4937b6e337 Log config data for debugging
Added debug statements to log configuration details including the attribute names and modifier values being processed. This will help in identifying and troubleshooting issues with entity modifiers setup.
2024-10-18 23:27:29 +02:00
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
3 changed files with 32 additions and 3 deletions

View File

@ -24,6 +24,7 @@ public class EntityAttributeModifier implements EntityModifier {
@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());

View File

@ -1,6 +1,7 @@
package com.alttd.custommobs.commands.subcommands;
import com.alttd.custommobs.Main;
import com.alttd.custommobs.abilities.EntityModifier;
import com.alttd.custommobs.abilities.MobType;
import com.alttd.custommobs.abilities.MobTypeApplier;
import com.alttd.custommobs.commands.SubCommand;
@ -17,6 +18,7 @@ import org.bukkit.entity.*;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
@Slf4j
public class Spawn extends SubCommand {
@ -104,16 +106,23 @@ public class Spawn extends SubCommand {
}
private void spawnMob(World world, Location location, EntityType entityType, MobType mobType) {
log.info("one");
log.info(mobType.toString());
log.info(mobType.entityModifiers().stream().map(EntityModifier::getName).collect(Collectors.joining(", ")));
if (entityType.getEntityClass() == null) {
log.warn("Tried to spawn entity with null entity class {}", entityType.name());
return;
}
log.info("two");
Entity entity = world.spawn(location, entityType.getEntityClass());
log.info("three");
if (!(entity instanceof LivingEntity livingEntity)) {
log.warn("Spawned entity is not a living entity? {}", entityType.name());
return;
}
log.info("four");
mobTypeApplier.apply(livingEntity, mobType);
log.info("five");
}
@Override

View File

@ -53,36 +53,55 @@ public class MobTypes extends AbstractConfig {
@SuppressWarnings("unused")
private static void load() {
MOB_TYPES.clear();
log.info("Loading mob types");
ConfigurationSection configurationSection = config.getConfigurationSection(prefix.substring(0, prefix.length() - 1));
if (configurationSection == null) {
log.warn("No config section found for {}", prefix.substring(0, prefix.length() - 1));
return;
}
log.info("1");
Set<String> keys = configurationSection.getKeys(false);
log.info("2");
keys.forEach(key -> {
List<Ability> abilities = config.getStringList(prefix + key, ".abilities", List.of()).stream()
.map(MobTypes.MOB_TYPES::getAbility)
.filter(Optional::isPresent)
.map(Optional::get)
.toList();
log.info("3");
List<EntityModifier> entityModifiers = new ArrayList<>();
log.info("4");
config.getConfigurationSection(prefix + key + ".modifiers").getKeys(false).forEach(modifier -> {
String attribute = config.getString(prefix + key + ".modifiers." + modifier, "attribute", null);
log.info("{}{}.modifiers.{}", prefix, key, modifier);
log.info("5 {}", modifier);
String attribute = config.getString(String.format("%s%s.modifiers.%s.", prefix, key, modifier), "attribute", null);
log.info("6");
if (attribute == null) {
log.info("RETURN (7)");
return;
}
EntityModifier value = getAttribute(attribute, config.getDouble(prefix + key + ".modifiers." + modifier, "value", 1));
if (value == null)
log.info("8");
EntityModifier value = getAttribute(attribute, config.getDouble(String.format("%s%s.modifiers.%s.", prefix, key, modifier), "value", 1));
log.info("9");
if (value == null) {
log.info("RETURN (10)");
return;
}
log.info("11");
entityModifiers.add(value);
});
log.info("12");
MOB_TYPES.put(key, new MobType(abilities, entityModifiers));
log.info("13");
});
}
private static EntityModifier getAttribute(String attributeName, double value) {
try {
Attribute attribute = Attribute.valueOf(attributeName);
log.info("DEBUG in case replacements break");
log.info("DEBUG: {}", attributeName);
log.info("DEBUG: {}", attribute.name());
return new EntityAttributeModifier(config.main, attribute, value);
} catch (IllegalArgumentException e) {
log.error("Invalid attribute {}", attributeName, e);