diff --git a/.gradle/buildOutputCleanup/buildOutputCleanup.lock b/.gradle/buildOutputCleanup/buildOutputCleanup.lock index 8f68f9a..49744c3 100644 Binary files a/.gradle/buildOutputCleanup/buildOutputCleanup.lock and b/.gradle/buildOutputCleanup/buildOutputCleanup.lock differ diff --git a/build/libs/GrimmsServer-1.5.6.jar b/build/libs/GrimmsServer-1.5.6.jar index 538048d..637104d 100644 Binary files a/build/libs/GrimmsServer-1.5.6.jar and b/build/libs/GrimmsServer-1.5.6.jar differ diff --git a/src/main/java/org/gsdistance/grimmsServer/Constructable/Entity/EntityAbilities.java b/src/main/java/org/gsdistance/grimmsServer/Constructable/Entity/EntityAbilities.java new file mode 100644 index 0000000..475db95 --- /dev/null +++ b/src/main/java/org/gsdistance/grimmsServer/Constructable/Entity/EntityAbilities.java @@ -0,0 +1,12 @@ +package org.gsdistance.grimmsServer.Constructable.Entity; + +import java.util.Map; + +public class EntityAbilities { + // Key - Ability + // Value - Tier + public static final Map abilities = Map.ofEntries( + Map.entry(new EntityAbility("test", Integer.MAX_VALUE, (entity) -> null), 99) + ); + // Could add abilities such as heal self, reflect damage, summon reinforcements etc. +} diff --git a/src/main/java/org/gsdistance/grimmsServer/Constructable/Entity/EntityAbility.java b/src/main/java/org/gsdistance/grimmsServer/Constructable/Entity/EntityAbility.java new file mode 100644 index 0000000..6fd0d88 --- /dev/null +++ b/src/main/java/org/gsdistance/grimmsServer/Constructable/Entity/EntityAbility.java @@ -0,0 +1,8 @@ +package org.gsdistance.grimmsServer.Constructable.Entity; + +import org.bukkit.entity.LivingEntity; + +import java.util.function.Function; + +public record EntityAbility(String id, int cooldownTicks, Function effect) { +} diff --git a/src/main/java/org/gsdistance/grimmsServer/Constructable/Entity/EntityAffix.java b/src/main/java/org/gsdistance/grimmsServer/Constructable/Entity/EntityAffix.java index 7be4fdd..6caf099 100644 --- a/src/main/java/org/gsdistance/grimmsServer/Constructable/Entity/EntityAffix.java +++ b/src/main/java/org/gsdistance/grimmsServer/Constructable/Entity/EntityAffix.java @@ -4,5 +4,5 @@ import org.bukkit.entity.LivingEntity; import java.util.function.Function; -public record EntityAffix(String id,int cooldown, Function effect) { +public record EntityAffix(String id, Function effect) { } diff --git a/src/main/java/org/gsdistance/grimmsServer/Constructable/Entity/EntityAffixes.java b/src/main/java/org/gsdistance/grimmsServer/Constructable/Entity/EntityAffixes.java index 9f28c88..f6d21cc 100644 --- a/src/main/java/org/gsdistance/grimmsServer/Constructable/Entity/EntityAffixes.java +++ b/src/main/java/org/gsdistance/grimmsServer/Constructable/Entity/EntityAffixes.java @@ -6,6 +6,8 @@ public class EntityAffixes { // Key - Affix // Value - Tier public static final Map affixes = Map.ofEntries( - Map.entry(new EntityAffix("test", 0, (entity) -> null), 99) + Map.entry(new EntityAffix("test", (entity) -> null), 99) ); + + // Could add affixes such as health bonus, armor bonus and damage bonus } diff --git a/src/main/java/org/gsdistance/grimmsServer/Constructable/Entity/EntityMetadata.java b/src/main/java/org/gsdistance/grimmsServer/Constructable/Entity/EntityMetadata.java index 596fe47..79fa3e4 100644 --- a/src/main/java/org/gsdistance/grimmsServer/Constructable/Entity/EntityMetadata.java +++ b/src/main/java/org/gsdistance/grimmsServer/Constructable/Entity/EntityMetadata.java @@ -27,14 +27,13 @@ public class EntityMetadata { public int level = 1; public int prestige = 1; public String originalName; - public boolean levelingApplied = false; - // Store actual attribute values to restore on chunk reload + public List affixes = new ArrayList<>(); + public int championTier = 0; + // Store base values after first leveling to prevent snowballing on chunk reload public double maxHealth = 0; public double armor = 0; public double armorToughness = 0; public double attackDamage = 0; - public List affixes = new ArrayList<>(); - public int championTier = 0; public EntityMetadata(Entity entity) { this.uuid = entity.getUniqueId(); @@ -88,7 +87,6 @@ public class EntityMetadata { // Apply levelling when metadata is first created if (entity instanceof LivingEntity && entity.getType() != EntityType.PLAYER) { applyLevelling((LivingEntity) entity, metadata); - metadata.levelingApplied = true; } metadata.saveToFile(); } else { @@ -96,10 +94,9 @@ public class EntityMetadata { if ("Verbose".equalsIgnoreCase(logLevel)) { GrimmsServer.logger.info("Retrieved EntityMetadata for " + entity.getUniqueId() + " with level " + metadata.level); } - // Restore saved attribute values when loading from disk (chunk reload) - // This prevents releveling by using exact saved values instead of recalculating - if (entity instanceof LivingEntity && entity.getType() != EntityType.PLAYER && (metadata.level > 1 || metadata.prestige > 1)) { - restoreAttributes((LivingEntity) entity, metadata); + // Re-apply levelling based on saved level/prestige when loading from disk (chunk reload) + if (entity instanceof LivingEntity && entity.getType() != EntityType.PLAYER) { + applyAttributeModifiers((LivingEntity) entity, metadata); } } @@ -166,7 +163,7 @@ public class EntityMetadata { } private static void saveAttributeValues(LivingEntity livingEntity, EntityMetadata metadata) { - // Save the actual attribute values after leveling + // Save the base values after leveling to restore on chunk reload if (livingEntity.getAttribute(Attribute.MAX_HEALTH) != null) { metadata.maxHealth = livingEntity.getAttribute(Attribute.MAX_HEALTH).getBaseValue(); } @@ -181,32 +178,6 @@ public class EntityMetadata { } } - private static void restoreAttributes(LivingEntity livingEntity, EntityMetadata metadata) { - // Restore the exact attribute values that were saved - if (livingEntity.getAttribute(Attribute.MAX_HEALTH) != null && metadata.maxHealth > 0) { - livingEntity.getAttribute(Attribute.MAX_HEALTH).setBaseValue(metadata.maxHealth); - livingEntity.setHealth(metadata.maxHealth); - } - if (livingEntity.getAttribute(Attribute.ARMOR) != null && metadata.armor > 0) { - livingEntity.getAttribute(Attribute.ARMOR).setBaseValue(metadata.armor); - } - if (livingEntity.getAttribute(Attribute.ARMOR_TOUGHNESS) != null && metadata.armorToughness > 0) { - livingEntity.getAttribute(Attribute.ARMOR_TOUGHNESS).setBaseValue(metadata.armorToughness); - } - if (livingEntity.getAttribute(Attribute.ATTACK_DAMAGE) != null && metadata.attackDamage > 0) { - livingEntity.getAttribute(Attribute.ATTACK_DAMAGE).setBaseValue(metadata.attackDamage); - } - - // Restore custom name - ChatColor levelColor = getLevelColor(metadata.level); - double maxHealth = livingEntity.getAttribute(Attribute.MAX_HEALTH).getValue(); - String healthBar = Shared.generateHealthBar(livingEntity.getHealth(), maxHealth); - String prestigeDisplay = metadata.prestige > 1 ? ChatColor.DARK_PURPLE + "[" + metadata.prestige + "]" : ""; - String displayName = prestigeDisplay + levelColor + "[" + metadata.level + "] " + ChatColor.WHITE + metadata.originalName + " " + healthBar; - livingEntity.setCustomName(displayName); - livingEntity.setCustomNameVisible(true); - } - private static void applyAttributeModifiers(LivingEntity livingEntity, EntityMetadata metadata) { Boolean enabled = ActiveConfig.getConfigValue(ConfigKey.LEVELLED_MOBS_ENABLED, Boolean.class); if (enabled == null || !enabled) { @@ -222,6 +193,9 @@ public class EntityMetadata { int finalLevel = metadata.level; int totalPrestige = metadata.prestige; + // Check if we have saved base values (chunk reload) or need to calculate from vanilla (new entity) + boolean hasSavedValues = metadata.maxHealth > 0 || metadata.armor > 0 || metadata.armorToughness > 0 || metadata.attackDamage > 0; + // Clear any existing attribute modifiers to prevent stacking if (livingEntity.getAttribute(Attribute.MAX_HEALTH) != null) { livingEntity.getAttribute(Attribute.MAX_HEALTH).getModifiers().clear(); @@ -238,31 +212,55 @@ public class EntityMetadata { // Apply attribute modifiers if (livingEntity.getAttribute(Attribute.MAX_HEALTH) != null) { - double baseHealth = livingEntity.getAttribute(Attribute.MAX_HEALTH).getBaseValue(); - Double healthDivisor = ActiveConfig.getConfigValue(ConfigKey.LEVELLED_MOBS_HEALTH_DIVISOR, Double.class); - if (healthDivisor == null) healthDivisor = 25.0; - double healthBoost = baseHealth * (finalLevel / healthDivisor) * Math.cbrt(totalPrestige); - livingEntity.getAttribute(Attribute.MAX_HEALTH).setBaseValue(baseHealth + healthBoost); - livingEntity.setHealth(livingEntity.getAttribute(Attribute.MAX_HEALTH).getValue()); + if (hasSavedValues && metadata.maxHealth > 0) { + // Restore saved base value (chunk reload) + livingEntity.getAttribute(Attribute.MAX_HEALTH).setBaseValue(metadata.maxHealth); + livingEntity.setHealth(metadata.maxHealth); + } else { + // Calculate from vanilla base value (new entity) + double vanillaHealth = livingEntity.getAttribute(Attribute.MAX_HEALTH).getBaseValue(); + Double healthDivisor = ActiveConfig.getConfigValue(ConfigKey.LEVELLED_MOBS_HEALTH_DIVISOR, Double.class); + if (healthDivisor == null) healthDivisor = 25.0; + double healthBoost = vanillaHealth * (finalLevel / healthDivisor) * Math.cbrt(totalPrestige); + livingEntity.getAttribute(Attribute.MAX_HEALTH).setBaseValue(vanillaHealth + healthBoost); + livingEntity.setHealth(livingEntity.getAttribute(Attribute.MAX_HEALTH).getValue()); + } } if (livingEntity.getAttribute(Attribute.ARMOR) != null) { - Double armorDivisor = ActiveConfig.getConfigValue(ConfigKey.LEVELLED_MOBS_ARMOR_DIVISOR, Double.class); - if (armorDivisor == null) armorDivisor = 2.0; - double armorBoost = Math.sqrt(finalLevel) * Math.sqrt(totalPrestige) / armorDivisor; - livingEntity.getAttribute(Attribute.ARMOR).setBaseValue(armorBoost); + if (hasSavedValues && metadata.armor > 0) { + // Restore saved base value (chunk reload) + livingEntity.getAttribute(Attribute.ARMOR).setBaseValue(metadata.armor); + } else { + // Calculate from scratch (new entity) + Double armorDivisor = ActiveConfig.getConfigValue(ConfigKey.LEVELLED_MOBS_ARMOR_DIVISOR, Double.class); + if (armorDivisor == null) armorDivisor = 2.0; + double armorBoost = Math.sqrt(finalLevel) * Math.sqrt(totalPrestige) / armorDivisor; + livingEntity.getAttribute(Attribute.ARMOR).setBaseValue(armorBoost); + } } if (livingEntity.getAttribute(Attribute.ARMOR_TOUGHNESS) != null) { - double toughnessBoost = Math.cbrt(finalLevel) * Math.cbrt(totalPrestige); - livingEntity.getAttribute(Attribute.ARMOR_TOUGHNESS).setBaseValue(toughnessBoost); + if (hasSavedValues && metadata.armorToughness > 0) { + // Restore saved base value (chunk reload) + livingEntity.getAttribute(Attribute.ARMOR_TOUGHNESS).setBaseValue(metadata.armorToughness); + } else { + // Calculate from scratch (new entity) + double toughnessBoost = Math.cbrt(finalLevel) * Math.cbrt(totalPrestige); + livingEntity.getAttribute(Attribute.ARMOR_TOUGHNESS).setBaseValue(toughnessBoost); + } } if (livingEntity.getAttribute(Attribute.ATTACK_DAMAGE) != null) { - double damageBoost = Math.cbrt(finalLevel) * Math.sqrt(totalPrestige); - livingEntity.getAttribute(Attribute.ATTACK_DAMAGE).setBaseValue( - livingEntity.getAttribute(Attribute.ATTACK_DAMAGE).getBaseValue() + damageBoost - ); + if (hasSavedValues && metadata.attackDamage > 0) { + // Restore saved base value (chunk reload) + livingEntity.getAttribute(Attribute.ATTACK_DAMAGE).setBaseValue(metadata.attackDamage); + } else { + // Calculate from vanilla base value (new entity) + double vanillaDamage = livingEntity.getAttribute(Attribute.ATTACK_DAMAGE).getBaseValue(); + double damageBoost = Math.cbrt(finalLevel) * Math.sqrt(totalPrestige); + livingEntity.getAttribute(Attribute.ATTACK_DAMAGE).setBaseValue(vanillaDamage + damageBoost); + } } // Set custom name with level and health bar diff --git a/src/main/java/org/gsdistance/grimmsServer/Events/Listeners/EntityRemoveEvent.java b/src/main/java/org/gsdistance/grimmsServer/Events/Listeners/EntityRemoveEvent.java index ebecf7a..37dbb77 100644 --- a/src/main/java/org/gsdistance/grimmsServer/Events/Listeners/EntityRemoveEvent.java +++ b/src/main/java/org/gsdistance/grimmsServer/Events/Listeners/EntityRemoveEvent.java @@ -12,11 +12,8 @@ public class EntityRemoveEvent { if (event.getEntity().getType() != EntityType.PLAYER) { CustomEntityManager.unregisterEntity(event.getEntity()); CustomEntityManager.saveToFile(); - // Delete entity metadata file to prevent stale data on despawn - EntityMetadata metadata = EntityMetadata.getEntityMetadata(event.getEntity()); - if (metadata != null) { - metadata.deleteFromFile(); - } + // Do NOT delete metadata here - it should persist across chunk unload/reload + // Metadata is only deleted on actual death in CustomEntityDeathEvent } } }