Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -138,18 +138,25 @@ public static int computeBiomeLevel(Store<EntityStore> store, NPCEntity npc) {
public static int computeEnvironmentLevel(TransformComponent transform, Store<EntityStore> 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) {
Expand Down
Loading