diff --git a/src/main/java/com/azuredoom/levelingcore/compat/party/PartyPluginCompat.java b/src/main/java/com/azuredoom/levelingcore/compat/party/PartyPluginCompat.java index f67014b..6ed630b 100644 --- a/src/main/java/com/azuredoom/levelingcore/compat/party/PartyPluginCompat.java +++ b/src/main/java/com/azuredoom/levelingcore/compat/party/PartyPluginCompat.java @@ -30,7 +30,7 @@ public static void onXPGain( var cfg = config.get(); var party = PartyManager.getInstance().getPartyDataById(playerUuid); if (party == null || !cfg.isEnablePartyPluginXPShareCompat()) { - if (!cfg.isDisableXPGainNotification()) { + if (!cfg.isDisableXPGainNotification() && !levelService.isMaxLevel(playerUuid)) { NotificationsUtil.sendXPGainNotification(playerRef, xp); } levelService.addXp(playerUuid, xp); @@ -100,7 +100,7 @@ public static void onXPGain( var player = Universe.get().getPlayer(uuid); - if (!cfg.isDisableXPGainNotification()) { + if (!cfg.isDisableXPGainNotification() && !levelService.isMaxLevel(uuid)) { if (player != null) { NotificationsUtil.sendXPGainNotification( player, diff --git a/src/main/java/com/azuredoom/levelingcore/compat/party/PartyProCompat.java b/src/main/java/com/azuredoom/levelingcore/compat/party/PartyProCompat.java index d81916f..fdf143e 100644 --- a/src/main/java/com/azuredoom/levelingcore/compat/party/PartyProCompat.java +++ b/src/main/java/com/azuredoom/levelingcore/compat/party/PartyProCompat.java @@ -30,7 +30,7 @@ public static void onXPGain( var cfg = config.get(); var party = PartyProAPI.getInstance().getPartyByPlayer(playerUuid); if (party == null || !cfg.isEnablePartyPluginXPShareCompat()) { - if (!cfg.isDisableXPGainNotification()) { + if (!cfg.isDisableXPGainNotification() && !levelService.isMaxLevel(playerUuid)) { NotificationsUtil.sendXPGainNotification(playerRef, xp); } levelService.addXp(playerUuid, xp); @@ -100,7 +100,7 @@ public static void onXPGain( var player = Universe.get().getPlayer(uuid); - if (!cfg.isDisableXPGainNotification()) { + if (!cfg.isDisableXPGainNotification() && !levelService.isMaxLevel(uuid)) { if (player != null) { NotificationsUtil.sendXPGainNotification( player, diff --git a/src/main/java/com/azuredoom/levelingcore/level/LevelServiceImpl.java b/src/main/java/com/azuredoom/levelingcore/level/LevelServiceImpl.java index b415976..1b2fe1f 100644 --- a/src/main/java/com/azuredoom/levelingcore/level/LevelServiceImpl.java +++ b/src/main/java/com/azuredoom/levelingcore/level/LevelServiceImpl.java @@ -7,6 +7,7 @@ import com.azuredoom.levelingcore.level.formulas.LevelFormula; import com.azuredoom.levelingcore.listeners.*; import com.azuredoom.levelingcore.playerdata.PlayerLevelData; +import com.azuredoom.levelingcore.utils.LevelingUtil; /** * Used for managing player levels and experience points (XP). This class provides methods to retrieve, modify, and @@ -83,6 +84,16 @@ public int getLevel(UUID id) { return formula.getLevelForXp(get(id).getXp()); } + /** + * Checks if a player has reached the maximum level based on their current experience points (XP). + * + * @param id The unique identifier (UUID) of the player whose level is being checked. + * @return {@code true} if the player is at the maximum level, {@code false} otherwise. + */ + public boolean isMaxLevel(UUID id) { + return getLevel(id) >= LevelingUtil.computeMaxLevel(); + } + public void addLevel(UUID id, int level) { if (level == 0) { return; @@ -186,6 +197,11 @@ public void addXp(UUID id, long amount) { var data = get(id); var oldLevel = getLevel(id); + if (isMaxLevel(id)) { + setDataXP(data, formula.getXpForLevel(oldLevel)); + return; + } + setDataXP(data, data.getXp() + amount); xpGainListeners.forEach(l -> l.onXpGain(id, amount)); diff --git a/src/main/java/com/azuredoom/levelingcore/systems/xp/GainXPEventSystem.java b/src/main/java/com/azuredoom/levelingcore/systems/xp/GainXPEventSystem.java index cee0f4f..7cea020 100644 --- a/src/main/java/com/azuredoom/levelingcore/systems/xp/GainXPEventSystem.java +++ b/src/main/java/com/azuredoom/levelingcore/systems/xp/GainXPEventSystem.java @@ -138,7 +138,11 @@ public void onComponentAdded( ); } else { // Fallback to default XP gain if supported Party mods are not installed - if (!config.get().isDisableXPGainNotification()) + if ( + !config.get().isDisableXPGainNotification() && !levelService.isMaxLevel( + player.getUuid() + ) + ) NotificationsUtil.sendXPGainNotification( playerRef, xpAmount diff --git a/src/main/java/com/azuredoom/levelingcore/utils/MobLevelingUtil.java b/src/main/java/com/azuredoom/levelingcore/utils/MobLevelingUtil.java index 3e609a2..4de532e 100644 --- a/src/main/java/com/azuredoom/levelingcore/utils/MobLevelingUtil.java +++ b/src/main/java/com/azuredoom/levelingcore/utils/MobLevelingUtil.java @@ -71,7 +71,7 @@ public static boolean applyMobScaling( return false; store.getExternalData().getWorld().execute(() -> { - var healthMult = 1F + ((float) level - 1F) * config.get().getMobHealthMultiplier(); + var healthMult = Math.max(1f, (float) level * config.get().getMobHealthMultiplier()); var stats = store.getComponent(npc.getReference(), EntityStatMap.getComponentType()); var healthIndex = DefaultEntityStatTypes.getHealth(); var modifier = new StaticModifier( @@ -138,18 +138,25 @@ public static int computeBiomeLevel(Store store, NPCEntity npc) { public static int computeEnvironmentLevel(TransformComponent transform, Store store, NPCEntity npc) { var world = store.getExternalData().getWorld(); var mobPos = transform.getPosition(); - var chunk = world.getChunk(ChunkUtil.indexChunkFromBlock((int) mobPos.x, (int) mobPos.z)); + var chunk = world.getChunkIfInMemory(ChunkUtil.indexChunkFromBlock((int) mobPos.x, (int) mobPos.z)); if (chunk == null) { LevelingCore.LOGGER.at(Level.WARNING) .log( - "Chunk does not exist; defaulting to 1" + "Chunk not in memory; defaulting to 1" ); return 1; } int envID = chunk.getBlockChunk().getEnvironment(mobPos); var envAsset = Environment.getAssetMap().getAsset(envID); + if (envAsset == null) { + LevelingCore.LOGGER.at(Level.WARNING) + .log( + "Environment id " + envID + " does not exist in asset registry; defaulting to 1" + ); + return 1; + } var envName = envAsset.getId(); if (envName == null) {