Skip to content

Commit

Permalink
1.4.1
Browse files Browse the repository at this point in the history
  • Loading branch information
BenceX100 committed Dec 23, 2023
1 parent cdaadfd commit 7e0a1c0
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 6 deletions.
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.artillexstudios</groupId>
<artifactId>AxGraves</artifactId>
<version>1.4.0</version>
<version>1.4.1</version>
<packaging>jar</packaging>

<name>AxGraves</name>
Expand Down Expand Up @@ -106,7 +106,7 @@
<dependency>
<groupId>com.artillexstudios.axapi</groupId>
<artifactId>axapi</artifactId>
<version>1.3.4</version>
<version>1.4.10</version>
<scope>compile</scope>
</dependency>
<dependency>
Expand All @@ -118,7 +118,7 @@
<dependency>
<groupId>dev.triumphteam</groupId>
<artifactId>triumph-gui</artifactId>
<version>3.1.2</version>
<version>3.1.7</version>
<scope>compile</scope>
</dependency>
<dependency>
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/artillexstudios/axgraves/grave/Grave.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.artillexstudios.axgraves.api.events.GraveInteractEvent;
import com.artillexstudios.axgraves.api.events.GraveOpenEvent;
import com.artillexstudios.axgraves.utils.BlacklistUtils;
import com.artillexstudios.axgraves.utils.ExperienceUtils;
import com.artillexstudios.axgraves.utils.LocationUtils;
import com.artillexstudios.axgraves.utils.Utils;
import dev.triumphteam.gui.guis.Gui;
Expand Down Expand Up @@ -135,7 +136,7 @@ public void interact(@NotNull Player player, org.bukkit.inventory.EquipmentSlot
if (deathChestInteractEvent.isCancelled()) return;

if (this.storedXP != 0) {
player.giveExp(this.storedXP);
ExperienceUtils.changeExp(player, this.storedXP);
this.storedXP = 0;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.artillexstudios.axgraves.api.events.GraveSpawnEvent;
import com.artillexstudios.axgraves.grave.Grave;
import com.artillexstudios.axgraves.grave.SpawnedGrave;
import com.artillexstudios.axgraves.utils.ExperienceUtils;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
Expand All @@ -29,11 +30,11 @@ public void onDeath(@NotNull PlayerDeathEvent event) {
Grave grave = null;

if (!event.getKeepInventory()) {
grave = new Grave(player.getLocation(), player, event.getDrops().toArray(new ItemStack[0]), player.getTotalExperience());
grave = new Grave(player.getLocation(), player, event.getDrops().toArray(new ItemStack[0]), ExperienceUtils.getExp(player));
} else if (CONFIG.getBoolean("override-keep-inventory", true)) {
grave = new Grave(player.getLocation(), player, player.getInventory().getContents(), ExperienceUtils.getExp(player));
player.setLevel(0);
player.setTotalExperience(0);
grave = new Grave(player.getLocation(), player, player.getInventory().getContents(), player.getTotalExperience());
player.getInventory().clear();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package com.artillexstudios.axgraves.utils;

import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;

public final class ExperienceUtils {
// credit: https://gist.githubusercontent.com/Jikoo/30ec040443a4701b8980/raw/0745ca25a8aaaf749ba2f2164a809e998f6a37c4/Experience.java

public static int getExp(@NotNull Player player) {
return getExpFromLevel(player.getLevel()) + Math.round(getExpToNext(player.getLevel()) * player.getExp());
}

public static int getExpFromLevel(int level) {
if (level > 30) {
return (int) (4.5 * level * level - 162.5 * level + 2220);
}
if (level > 15) {
return (int) (2.5 * level * level - 40.5 * level + 360);
}
return level * level + 6 * level;
}

public static double getLevelFromExp(long exp) {
int level = getIntLevelFromExp(exp);

// Get remaining exp progressing towards next level. Cast to float for next bit of math.
float remainder = exp - (float) getExpFromLevel(level);

// Get level progress with float precision.
float progress = remainder / getExpToNext(level);

// Slap both numbers together and call it a day. While it shouldn't be possible for progress
// to be an invalid value (value < 0 || 1 <= value)
return ((double) level) + progress;
}

public static int getIntLevelFromExp(long exp) {
if (exp > 1395) {
return (int) ((Math.sqrt(72 * exp - 54215D) + 325) / 18);
}
if (exp > 315) {
return (int) (Math.sqrt(40 * exp - 7839D) / 10 + 8.1);
}
if (exp > 0) {
return (int) (Math.sqrt(exp + 9D) - 3);
}
return 0;
}

private static int getExpToNext(int level) {
if (level >= 30) {
// Simplified formula. Internal: 112 + (level - 30) * 9
return level * 9 - 158;
}
if (level >= 15) {
// Simplified formula. Internal: 37 + (level - 15) * 5
return level * 5 - 38;
}
// Internal: 7 + level * 2
return level * 2 + 7;
}

public static void changeExp(Player player, int exp) {
exp += getExp(player);

if (exp < 0) {
exp = 0;
}

double levelAndExp = getLevelFromExp(exp);
int level = (int) levelAndExp;
player.setLevel(level);
player.setExp((float) (levelAndExp - level));
}
}

0 comments on commit 7e0a1c0

Please sign in to comment.