Compare commits

..
12 Commits
Author SHA1 Message Date
auto 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
auto 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
auto f36bc6fc7f build commit 2024-10-18 23:49:42 +02:00
auto f3fa8563e6 build commit 2024-10-18 23:46:29 +02:00
auto 07b5010f74 build commit 2024-10-18 23:42:30 +02:00
auto 153543fb1f build commit 2024-10-18 23:37:18 +02:00
auto 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
auto 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
auto 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
auto c8cb2309f6 Rename and enhance AttributeModifier
Renamed AttributeModifier to EntityAttributeModifier for clarity. Added Main dependency and improved attribute setting logic with namespaced keys for better error handling and debugging. Updated MobTypes to pass Main instance accordingly.
2024-10-18 22:59:47 +02:00
auto 73cfb772b1 Update debug logs to info level with debug tags
Changed log.debug calls to log.info with "DEBUG" tags for consistency and improved visibility during debugging. This will ensure that debug information appears in the logs without changing log level settings.
2024-10-18 21:49:57 +02:00
auto 941b7d0d8f Adjust spawn location coordinates for target blocks
Modified the spawnable target block location by adding 1 to the Y-coordinate. This change ensures that entities spawn above the target block, preventing them from spawning inside it or in obstructed areas.
2024-10-18 20:18:05 +02:00
8 changed files with 96 additions and 50 deletions
+1 -1
View File
@@ -30,7 +30,7 @@ public class Main extends JavaPlugin {
public void reloadConfigs() {
Config.reload();
Messages.reload();
MobTypes.reload();
MobTypes.reload(this);
}
@Override
@@ -1,34 +0,0 @@
package com.alttd.custommobs.abilities.modifiers;
import com.alttd.custommobs.abilities.EntityModifier;
import lombok.extern.slf4j.Slf4j;
import org.bukkit.attribute.Attribute;
import org.bukkit.attribute.AttributeInstance;
import org.bukkit.entity.LivingEntity;
@Slf4j
public class AttributeModifier implements EntityModifier {
private final double value;
private final Attribute attribute;
public AttributeModifier(Attribute attribute, double value) {
this.value = value;
this.attribute = attribute;
}
@Override
public void apply(LivingEntity entity) {
AttributeInstance attributeInstance = entity.getAttribute(attribute);
if (attributeInstance == null) {
log.warn("Entity {} has no {} attribute", entity.getName(), attribute.name());
return;
}
attributeInstance.setBaseValue(value);
}
@Override
public String getName() {
return attribute.name();
}
}
@@ -0,0 +1,49 @@
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();
}
}
@@ -44,7 +44,7 @@ public class AbilityMob implements Runnable {
if (mob.isDead()) {
cancelTask();
if (Config.SETTINGS.DEBUG) {
log.debug("Entity died, cancelling ability task");
log.info("DEBUG: Entity died, cancelling ability task");
}
return;
}
@@ -43,7 +43,7 @@ public class AbilityThread {
return;
}
if (tasksMap.containsKey(identifier)) {
log.debug("Already scheduled task with identifier {}, skipping", identifier);
log.info("DEBUG: Already scheduled task with identifier {}, skipping", identifier);
return;
}
Future<?> future = executorService.submit(() -> {
@@ -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 {
@@ -30,7 +32,7 @@ public class Spawn extends SubCommand {
@Override
public boolean onCommand(CommandSender commandSender, String[] args) {
if (args.length != 3 && args.length != 7) {
log.debug("Invalid argument length: {} expected 2 or 6", args.length);
log.info("DEBUG: Invalid argument length: {} expected 2 or 6", args.length);
return false;
}
Optional<MobType> optionalMobType = MobTypes.MOB_TYPES.get(args[1]);
@@ -43,7 +45,7 @@ public class Spawn extends SubCommand {
try {
entityType = EntityType.valueOf(args[2]);
} catch (IllegalArgumentException e) {
log.debug("Invalid mob type {}", args[2]);
log.info("DEBUG: Invalid mob type {}", args[2]);
return false;
}
if (!entityType.isSpawnable() || !isMob(entityType)) {
@@ -66,7 +68,7 @@ public class Spawn extends SubCommand {
} else if (args.length == 7) {
return getLocation(args);
} else {
log.debug("Expected player with argument length of 2");
log.info("DEBUG: Expected player with argument length of 2");
return Optional.empty();
}
}
@@ -82,7 +84,7 @@ public class Spawn extends SubCommand {
double z = Double.parseDouble(args[6]);
return Optional.of(new Location(world, x, y, z));
} catch (NumberFormatException e) {
log.debug("Invalid coordinates x: {}, y: {}, z: {}", args[4], args[5], args[6]);
log.info("DEBUG: Invalid coordinates x: {}, y: {}, z: {}", args[4], args[5], args[6]);
return Optional.empty();
}
}
@@ -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
@@ -1,7 +1,8 @@
package com.alttd.custommobs.config;
import com.alttd.custommobs.Main;
import com.alttd.custommobs.abilities.Ability;
import com.alttd.custommobs.abilities.modifiers.AttributeModifier;
import com.alttd.custommobs.abilities.modifiers.EntityAttributeModifier;
import com.alttd.custommobs.abilities.EntityModifier;
import com.alttd.custommobs.abilities.MobType;
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
@@ -16,19 +17,21 @@ import java.util.*;
@Slf4j
public class MobTypes extends AbstractConfig {
static MobTypes config;
private final Main main;
MobTypes() {
MobTypes(Main main) {
super(
new File(File.separator
+ "mnt" + File.separator
+ "configs" + File.separator
+ "custommobs"),
"mob-types.yml");
this.main = main;
}
public static void reload() {
public static void reload(Main main) {
log.info("Reloading mob types");
config = new MobTypes();
config = new MobTypes(main);
config.readConfig(MobTypes.class, null);
}
@@ -50,37 +53,56 @@ 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);
return new AttributeModifier(attribute, value);
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);
return null;
@@ -16,7 +16,7 @@ public class SpawnableTargetBlock {
while (iter.hasNext()) {
Block block = iter.next();
if (isSpawnable(block)) {
return Optional.of(block.getLocation());
return Optional.of(block.getLocation().add(0, 1, 0));
}
}
return Optional.empty();