Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3da2b37aed | ||
|
|
e8b926ab41 | ||
|
|
f36bc6fc7f | ||
|
|
f3fa8563e6 | ||
|
|
07b5010f74 | ||
|
|
153543fb1f | ||
|
|
d29c3eb3c3 | ||
|
|
4937b6e337 | ||
|
|
77f9cfe0a6 |
|
|
@ -24,6 +24,7 @@ public class EntityAttributeModifier implements EntityModifier {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void apply(LivingEntity entity) {
|
public void apply(LivingEntity entity) {
|
||||||
|
log.info("DEBUG: Setting attribute {} to {}", attribute.name(), value);
|
||||||
AttributeInstance attributeInstance = entity.getAttribute(attribute);
|
AttributeInstance attributeInstance = entity.getAttribute(attribute);
|
||||||
if (attributeInstance == null) {
|
if (attributeInstance == null) {
|
||||||
log.warn("Entity {} has no {} attribute", entity.getName(), attribute.name());
|
log.warn("Entity {} has no {} attribute", entity.getName(), attribute.name());
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package com.alttd.custommobs.commands.subcommands;
|
package com.alttd.custommobs.commands.subcommands;
|
||||||
|
|
||||||
import com.alttd.custommobs.Main;
|
import com.alttd.custommobs.Main;
|
||||||
|
import com.alttd.custommobs.abilities.EntityModifier;
|
||||||
import com.alttd.custommobs.abilities.MobType;
|
import com.alttd.custommobs.abilities.MobType;
|
||||||
import com.alttd.custommobs.abilities.MobTypeApplier;
|
import com.alttd.custommobs.abilities.MobTypeApplier;
|
||||||
import com.alttd.custommobs.commands.SubCommand;
|
import com.alttd.custommobs.commands.SubCommand;
|
||||||
|
|
@ -17,6 +18,7 @@ import org.bukkit.entity.*;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class Spawn extends SubCommand {
|
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) {
|
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) {
|
if (entityType.getEntityClass() == null) {
|
||||||
log.warn("Tried to spawn entity with null entity class {}", entityType.name());
|
log.warn("Tried to spawn entity with null entity class {}", entityType.name());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
log.info("two");
|
||||||
Entity entity = world.spawn(location, entityType.getEntityClass());
|
Entity entity = world.spawn(location, entityType.getEntityClass());
|
||||||
|
log.info("three");
|
||||||
if (!(entity instanceof LivingEntity livingEntity)) {
|
if (!(entity instanceof LivingEntity livingEntity)) {
|
||||||
log.warn("Spawned entity is not a living entity? {}", entityType.name());
|
log.warn("Spawned entity is not a living entity? {}", entityType.name());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
log.info("four");
|
||||||
mobTypeApplier.apply(livingEntity, mobType);
|
mobTypeApplier.apply(livingEntity, mobType);
|
||||||
|
log.info("five");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -53,36 +53,55 @@ public class MobTypes extends AbstractConfig {
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
private static void load() {
|
private static void load() {
|
||||||
MOB_TYPES.clear();
|
MOB_TYPES.clear();
|
||||||
|
log.info("Loading mob types");
|
||||||
ConfigurationSection configurationSection = config.getConfigurationSection(prefix.substring(0, prefix.length() - 1));
|
ConfigurationSection configurationSection = config.getConfigurationSection(prefix.substring(0, prefix.length() - 1));
|
||||||
if (configurationSection == null) {
|
if (configurationSection == null) {
|
||||||
log.warn("No config section found for {}", prefix.substring(0, prefix.length() - 1));
|
log.warn("No config section found for {}", prefix.substring(0, prefix.length() - 1));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
log.info("1");
|
||||||
Set<String> keys = configurationSection.getKeys(false);
|
Set<String> keys = configurationSection.getKeys(false);
|
||||||
|
log.info("2");
|
||||||
keys.forEach(key -> {
|
keys.forEach(key -> {
|
||||||
List<Ability> abilities = config.getStringList(prefix + key, ".abilities", List.of()).stream()
|
List<Ability> abilities = config.getStringList(prefix + key, ".abilities", List.of()).stream()
|
||||||
.map(MobTypes.MOB_TYPES::getAbility)
|
.map(MobTypes.MOB_TYPES::getAbility)
|
||||||
.filter(Optional::isPresent)
|
.filter(Optional::isPresent)
|
||||||
.map(Optional::get)
|
.map(Optional::get)
|
||||||
.toList();
|
.toList();
|
||||||
|
log.info("3");
|
||||||
List<EntityModifier> entityModifiers = new ArrayList<>();
|
List<EntityModifier> entityModifiers = new ArrayList<>();
|
||||||
|
log.info("4");
|
||||||
config.getConfigurationSection(prefix + key + ".modifiers").getKeys(false).forEach(modifier -> {
|
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) {
|
if (attribute == null) {
|
||||||
|
log.info("RETURN (7)");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
EntityModifier value = getAttribute(attribute, config.getDouble(prefix + key + ".modifiers." + modifier, "value", 1));
|
log.info("8");
|
||||||
if (value == null)
|
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;
|
return;
|
||||||
|
}
|
||||||
|
log.info("11");
|
||||||
entityModifiers.add(value);
|
entityModifiers.add(value);
|
||||||
});
|
});
|
||||||
|
log.info("12");
|
||||||
MOB_TYPES.put(key, new MobType(abilities, entityModifiers));
|
MOB_TYPES.put(key, new MobType(abilities, entityModifiers));
|
||||||
|
log.info("13");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private static EntityModifier getAttribute(String attributeName, double value) {
|
private static EntityModifier getAttribute(String attributeName, double value) {
|
||||||
try {
|
try {
|
||||||
Attribute attribute = Attribute.valueOf(attributeName);
|
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);
|
return new EntityAttributeModifier(config.main, attribute, value);
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
log.error("Invalid attribute {}", attributeName, e);
|
log.error("Invalid attribute {}", attributeName, e);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user