Skip to content

Commit

Permalink
Fix leaderboard updates and display - 1.5.1
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikSzabo committed Jul 29, 2024
1 parent 8c61b4f commit e547c00
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 19 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ You can view the full documentation [here](https://docs.auroramc.gg/auroralevels
<dependency>
<groupId>gg.auroramc</groupId>
<artifactId>AuroraLevels</artifactId>
<version>1.5.0</version>
<version>1.5.1</version>
<scope>provided</scope>
</dependency>
```
Expand All @@ -51,7 +51,7 @@ repositories {
}
dependencies {
compileOnly 'gg.auroramc:AuroraLevels:1.5.0'
compileOnly 'gg.auroramc:AuroraLevels:1.5.1'
}
```

Expand All @@ -62,6 +62,6 @@ repositories {
}
dependencies {
compileOnly("gg.auroramc:AuroraLevels:1.5.0")
compileOnly("gg.auroramc:AuroraLevels:1.5.1")
}
```
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ plugins {
}

group = "gg.auroramc"
version = "1.5.0"
version = "1.5.1"

java.sourceCompatibility = JavaVersion.VERSION_21
java.targetCompatibility = JavaVersion.VERSION_21
Expand All @@ -37,7 +37,7 @@ repositories {

dependencies {
compileOnly("io.papermc.paper:paper-api:1.21-R0.1-SNAPSHOT")
compileOnly("gg.auroramc:Aurora:1.5.0")
compileOnly("gg.auroramc:Aurora:1.5.7")
compileOnly("net.luckperms:api:5.4")
compileOnly("dev.aurelium:auraskills-api-bukkit:2.0.7")
compileOnly("io.lumine:Mythic-Dist:5.6.1")
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/gg/auroramc/levels/leveler/PlayerLeveler.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ public double addXpToPlayer(Player player, double xp) {

if (newXP < requiredXpToLevelUp) {
data.setCurrentXP(newXP);
AuroraAPI.getLeaderboards().updateUser(AuroraAPI.getUserManager().getUser(player), "levels");
return xp;
}

Expand All @@ -116,6 +117,8 @@ public double addXpToPlayer(Player player, double xp) {
Bukkit.getPluginManager().callEvent(new PlayerLevelUpEvent(player, data.getLevel()));
}

AuroraAPI.getLeaderboards().updateUser(AuroraAPI.getUserManager().getUser(player), "levels");

return xp;
}

Expand Down Expand Up @@ -205,6 +208,7 @@ public void setPlayerLevel(Player player, int level) {
if (data.getLevel() > level) {
data.setLevel(level);
Bukkit.getPluginManager().callEvent(new PlayerLevelUpEvent(player, level));
AuroraAPI.getLeaderboards().updateUser(AuroraAPI.getUserManager().getUser(player), "levels");
return;
}

Expand All @@ -213,12 +217,15 @@ public void setPlayerLevel(Player player, int level) {
rewardPlayer(player, l);
Bukkit.getPluginManager().callEvent(new PlayerLevelUpEvent(player, level));
}

AuroraAPI.getLeaderboards().updateUser(AuroraAPI.getUserManager().getUser(player), "levels");
}

public void setPlayerLevelRaw(Player player, int level) {
var data = getUserData(player);
data.setCurrentXP(0);
data.setLevel(level);
AuroraAPI.getLeaderboards().updateUser(AuroraAPI.getUserManager().getUser(player), "levels");
}

public double getXpForLevel(int level) {
Expand All @@ -245,11 +252,4 @@ public void onUserLoaded(AuroraUserLoadedEvent event) {
if (player == null) return;
rewardAutoCorrector.correctRewards(player);
}

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerXPGain(PlayerXpGainEvent event) {
var user = AuroraAPI.getUser(event.getPlayer().getUniqueId());
if (!user.isLoaded()) return;
AuroraAPI.getLeaderboards().updateUser(user, "levels");
}
}
6 changes: 3 additions & 3 deletions src/main/java/gg/auroramc/levels/menu/LevelMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ private AuroraMenu createMenu() {
var lbm = AuroraAPI.getLeaderboards();

var lb = AuroraAPI.getUser(player.getUniqueId()).getLeaderboardEntries().get("levels");
var lbPositionPlaceholder = Placeholder.of("{lb_position}", lb == null ? lbm.getEmptyPlaceholder() : AuroraAPI.formatNumber(lb.getPosition()));
var lbPositionPlaceholder = Placeholder.of("{lb_position}", lb == null || lb.getPosition() == 0 ? lbm.getEmptyPlaceholder() : AuroraAPI.formatNumber(lb.getPosition()));
var lbPositionPercentPlaceholder = Placeholder.of("{lb_position_percent}",
lb == null ? lbm.getEmptyPlaceholder() : AuroraAPI.formatNumber(
lb == null || lb.getPosition() == 0 ? lbm.getEmptyPlaceholder() : AuroraAPI.formatNumber(
Math.min(((double) lb.getPosition() / Math.max(1, AuroraAPI.getLeaderboards().getBoardSize("levels"))) * 100, 100)
)
);
var lbBoardSizePlaceholder = Placeholder.of("{lb_size}", AuroraAPI.formatNumber(Math.max(AuroraAPI.getLeaderboards().getBoardSize("levels"), lb == null ? Bukkit.getOnlinePlayers().size() : Math.max(lb.getPosition(), Bukkit.getOnlinePlayers().size()))));
var lbBoardSizePlaceholder = Placeholder.of("{lb_size}", AuroraAPI.formatNumber(Math.max(AuroraAPI.getLeaderboards().getBoardSize("levels"), lb == null || lb.getPosition() == 0 ? Bukkit.getOnlinePlayers().size() : Math.max(lb.getPosition(), Bukkit.getOnlinePlayers().size()))));
var totalCurrentXP = leveler.getXpForLevel(leveler.getUserData(player).getLevel()) + leveler.getUserData(player).getCurrentXP();

for (var customItem : menuConfig.getCustomItems().values()) {
Expand Down
21 changes: 17 additions & 4 deletions src/main/resources/menus/levels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ title: "Player levels"

# First is always the current completed level
# Then the next level and the locked levels
level-track: [20, 21, 22, 23, 24]
level-track: [ 20, 21, 22, 23, 24 ]

progress-bar:
length: 10
filled-character: "&a&l■"
unfilled-character: "&7&l■"
length: 10
filled-character: "&a&l■"
unfilled-character: "&7&l■"

display-components:
rewards:
Expand Down Expand Up @@ -51,6 +51,19 @@ items:

# Just set it to {} if you don't want to use custom menu items
custom-items:
info:
name: "&aYour level ranking"
material: self_head
slot: 4
lore:
- "&8Global ranking"
- ""
- "&7Your level: &f{level}"
- "&7Total XP: &f{current_short}"
- ""
- "&7Rank: &8#&a{lb_position}"
- "&8You are in the top &a{lb_position_percent}%&8 of &7{lb_size}"
- "&8players!"
milestones:
name: "&aMilestones"
material: NETHER_STAR
Expand Down

0 comments on commit e547c00

Please sign in to comment.