This commit is contained in:
tyuXX 2026-07-26 01:07:57 +03:00
parent 5b937e8ac0
commit afed85f857
6 changed files with 71 additions and 8 deletions

Binary file not shown.

View file

@ -650,7 +650,7 @@ code + .copy-button {
<script type="text/javascript"> <script type="text/javascript">
function configurationCacheProblems() { return ( function configurationCacheProblems() { return (
// begin-report-data // begin-report-data
{"diagnostics":[{"locations":[{}],"problem":[{"text":"Properties should be assigned using the 'propName = value' syntax. Setting a property via the Gradle-generated 'propName value' or 'propName(value)' syntax in Groovy DSL has been deprecated."}],"severity":"WARNING","problemDetails":[{"text":"This is scheduled to be removed in Gradle 10.0."}],"contextualLabel":"Properties should be assigned using the 'propName = value' syntax. Setting a property via the Gradle-generated 'propName value' or 'propName(value)' syntax in Groovy DSL has been deprecated.","documentationLink":"https://docs.gradle.org/8.14.5/userguide/upgrading_version_8.html#groovy_space_assignment_syntax","problemId":[{"name":"deprecation","displayName":"Deprecation"},{"name":"properties-should-be-assigned-using-the-propname-value-syntax-setting-a-property-via-the-gradle-generated-propname-value-or-propname-value-syntax-in-groovy-dsl","displayName":"Properties should be assigned using the 'propName = value' syntax. Setting a property via the Gradle-generated 'propName value' or 'propName(value)' syntax in Groovy DSL has been deprecated."}],"solutions":[[{"text":"Use assignment ('filteringCharset = <value>') instead."}]]}],"problemsReport":{"totalProblemCount":1,"buildName":"GrimmsServer","requestedTasks":"build","documentationLink":"https://docs.gradle.org/8.14.5/userguide/reporting_problems.html","documentationLinkCaption":"Problem report","summaries":[]}} {"diagnostics":[{"locations":[{}],"problem":[{"text":"Properties should be assigned using the 'propName = value' syntax. Setting a property via the Gradle-generated 'propName value' or 'propName(value)' syntax in Groovy DSL has been deprecated."}],"severity":"WARNING","problemDetails":[{"text":"This is scheduled to be removed in Gradle 10.0."}],"contextualLabel":"Properties should be assigned using the 'propName = value' syntax. Setting a property via the Gradle-generated 'propName value' or 'propName(value)' syntax in Groovy DSL has been deprecated.","documentationLink":"https://docs.gradle.org/8.14.5/userguide/upgrading_version_8.html#groovy_space_assignment_syntax","problemId":[{"name":"deprecation","displayName":"Deprecation"},{"name":"properties-should-be-assigned-using-the-propname-value-syntax-setting-a-property-via-the-gradle-generated-propname-value-or-propname-value-syntax-in-groovy-dsl","displayName":"Properties should be assigned using the 'propName = value' syntax. Setting a property via the Gradle-generated 'propName value' or 'propName(value)' syntax in Groovy DSL has been deprecated."}],"solutions":[[{"text":"Use assignment ('filteringCharset = <value>') instead."}]]},{"locations":[{"path":"/home/tyuxx/IdeaProjects/GrimmsServer/src/main/java/org/gsdistance/grimmsServer/Constructable/Entity/EntityMetadata.java"},{"taskPath":":compileJava"}],"problem":[{"text":"/home/tyuxx/IdeaProjects/GrimmsServer/src/main/java/org/gsdistance/grimmsServer/Constructable/Entity/EntityMetadata.java uses unchecked or unsafe operations."}],"severity":"ADVICE","problemDetails":[{"text":"Note: /home/tyuxx/IdeaProjects/GrimmsServer/src/main/java/org/gsdistance/grimmsServer/Constructable/Entity/EntityMetadata.java uses unchecked or unsafe operations."}],"contextualLabel":"/home/tyuxx/IdeaProjects/GrimmsServer/src/main/java/org/gsdistance/grimmsServer/Constructable/Entity/EntityMetadata.java uses unchecked or unsafe operations.","problemId":[{"name":"java","displayName":"Java compilation"},{"name":"compilation","displayName":"Compilation"},{"name":"compiler.note.unchecked.filename","displayName":"/home/tyuxx/IdeaProjects/GrimmsServer/src/main/java/org/gsdistance/grimmsServer/Constructable/Entity/EntityMetadata.java uses unchecked or unsafe operations."}]},{"locations":[{"path":"/home/tyuxx/IdeaProjects/GrimmsServer/src/main/java/org/gsdistance/grimmsServer/Constructable/Entity/EntityMetadata.java"},{"taskPath":":compileJava"}],"problem":[{"text":"Recompile with -Xlint:unchecked for details."}],"severity":"ADVICE","problemDetails":[{"text":"Note: Recompile with -Xlint:unchecked for details."}],"contextualLabel":"Recompile with -Xlint:unchecked for details.","problemId":[{"name":"java","displayName":"Java compilation"},{"name":"compilation","displayName":"Compilation"},{"name":"compiler.note.unchecked.recompile","displayName":"Recompile with -Xlint:unchecked for details."}]}],"problemsReport":{"totalProblemCount":3,"buildName":"GrimmsServer","requestedTasks":"build","documentationLink":"https://docs.gradle.org/8.14.5/userguide/reporting_problems.html","documentationLinkCaption":"Problem report","summaries":[]}}
// end-report-data // end-report-data
);} );}
</script> </script>

View file

@ -3,6 +3,8 @@ package org.gsdistance.grimmsServer.Constructable.Entity;
import java.util.Map; import java.util.Map;
public class EntityAffixes { public class EntityAffixes {
// Key - Affix
// Value - Tier
public static final Map<EntityAffix, Integer> affixes = Map.ofEntries( public static final Map<EntityAffix, Integer> affixes = Map.ofEntries(
Map.entry(new EntityAffix("test", 0, (entity) -> null), 99) Map.entry(new EntityAffix("test", 0, (entity) -> null), 99)
); );

View file

@ -28,6 +28,11 @@ public class EntityMetadata {
public int prestige = 1; public int prestige = 1;
public String originalName; public String originalName;
public boolean levelingApplied = false; public boolean levelingApplied = false;
// Store actual attribute values to restore on chunk reload
public double maxHealth = 0;
public double armor = 0;
public double armorToughness = 0;
public double attackDamage = 0;
public List<EntityAffix> affixes = new ArrayList<>(); public List<EntityAffix> affixes = new ArrayList<>();
public int championTier = 0; public int championTier = 0;
@ -40,7 +45,7 @@ public class EntityMetadata {
} }
if(championTier > 0){ if(championTier > 0){
while(Math.random() < 0.5){ while(Math.random() < 0.5){
// Add a random affix with tier equal to or less than the champion tier // TODO - Add a random affix with tier equal to or less than the champion tier
} }
} }
@ -89,13 +94,12 @@ public class EntityMetadata {
} else { } else {
String logLevel = ActiveConfig.getConfigValue(ConfigKey.LOG_LEVEL, String.class); String logLevel = ActiveConfig.getConfigValue(ConfigKey.LOG_LEVEL, String.class);
if ("Verbose".equalsIgnoreCase(logLevel)) { if ("Verbose".equalsIgnoreCase(logLevel)) {
GrimmsServer.logger.info("Retrieved EntityMetadata for " + entity.getUniqueId()); GrimmsServer.logger.info("Retrieved EntityMetadata for " + entity.getUniqueId() + " with level " + metadata.level);
} }
// Re-apply attribute modifiers when metadata is loaded from disk (e.g., after chunk reload) // Restore saved attribute values when loading from disk (chunk reload)
// This is necessary because chunk reloads reset entity attributes to vanilla values // This prevents releveling by using exact saved values instead of recalculating
// Use the saved level/prestige instead of recalculating to prevent releveling
if (entity instanceof LivingEntity && entity.getType() != EntityType.PLAYER && (metadata.level > 1 || metadata.prestige > 1)) { if (entity instanceof LivingEntity && entity.getType() != EntityType.PLAYER && (metadata.level > 1 || metadata.prestige > 1)) {
applyAttributeModifiers((LivingEntity) entity, metadata); restoreAttributes((LivingEntity) entity, metadata);
} }
} }
@ -158,6 +162,49 @@ public class EntityMetadata {
metadata.prestige = totalPrestige; metadata.prestige = totalPrestige;
applyAttributeModifiers(livingEntity, metadata); applyAttributeModifiers(livingEntity, metadata);
saveAttributeValues(livingEntity, metadata);
}
private static void saveAttributeValues(LivingEntity livingEntity, EntityMetadata metadata) {
// Save the actual attribute values after leveling
if (livingEntity.getAttribute(Attribute.MAX_HEALTH) != null) {
metadata.maxHealth = livingEntity.getAttribute(Attribute.MAX_HEALTH).getBaseValue();
}
if (livingEntity.getAttribute(Attribute.ARMOR) != null) {
metadata.armor = livingEntity.getAttribute(Attribute.ARMOR).getBaseValue();
}
if (livingEntity.getAttribute(Attribute.ARMOR_TOUGHNESS) != null) {
metadata.armorToughness = livingEntity.getAttribute(Attribute.ARMOR_TOUGHNESS).getBaseValue();
}
if (livingEntity.getAttribute(Attribute.ATTACK_DAMAGE) != null) {
metadata.attackDamage = livingEntity.getAttribute(Attribute.ATTACK_DAMAGE).getBaseValue();
}
}
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) { private static void applyAttributeModifiers(LivingEntity livingEntity, EntityMetadata metadata) {
@ -175,6 +222,20 @@ public class EntityMetadata {
int finalLevel = metadata.level; int finalLevel = metadata.level;
int totalPrestige = metadata.prestige; int totalPrestige = metadata.prestige;
// Clear any existing attribute modifiers to prevent stacking
if (livingEntity.getAttribute(Attribute.MAX_HEALTH) != null) {
livingEntity.getAttribute(Attribute.MAX_HEALTH).getModifiers().clear();
}
if (livingEntity.getAttribute(Attribute.ARMOR) != null) {
livingEntity.getAttribute(Attribute.ARMOR).getModifiers().clear();
}
if (livingEntity.getAttribute(Attribute.ARMOR_TOUGHNESS) != null) {
livingEntity.getAttribute(Attribute.ARMOR_TOUGHNESS).getModifiers().clear();
}
if (livingEntity.getAttribute(Attribute.ATTACK_DAMAGE) != null) {
livingEntity.getAttribute(Attribute.ATTACK_DAMAGE).getModifiers().clear();
}
// Apply attribute modifiers // Apply attribute modifiers
if (livingEntity.getAttribute(Attribute.MAX_HEALTH) != null) { if (livingEntity.getAttribute(Attribute.MAX_HEALTH) != null) {
double baseHealth = livingEntity.getAttribute(Attribute.MAX_HEALTH).getBaseValue(); double baseHealth = livingEntity.getAttribute(Attribute.MAX_HEALTH).getBaseValue();

View file

@ -11,7 +11,7 @@ public class EntitySpawnEvent {
public static void Event(org.bukkit.event.entity.EntitySpawnEvent event) { public static void Event(org.bukkit.event.entity.EntitySpawnEvent event) {
if (event.getEntity().getType() != EntityType.PLAYER) { if (event.getEntity().getType() != EntityType.PLAYER) {
CustomEntityManager.registerEntity(event.getEntity()); CustomEntityManager.registerEntity(event.getEntity());
// Leveling is now applied in EntityMetadata.getEntityMetadata() // getEntityMetadata handles both new entities (creates & levels) and chunk reloads (loads from disk without releveling)
EntityMetadata.getEntityMetadata(event.getEntity()); EntityMetadata.getEntityMetadata(event.getEntity());
} }
} }