Skip to content

Commit

Permalink
Fixes issue #1. XP now calculated correctly.
Browse files Browse the repository at this point in the history
Removed use of method getTotalExperience(), which gives amount used
for score.
  • Loading branch information
501st-alpha1 committed Jan 13, 2013
1 parent fb22c20 commit f839c4f
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
Binary file modified com/scott_weldon/xp_to_emerald/XPtoEmerald.class
Binary file not shown.
30 changes: 27 additions & 3 deletions com/scott_weldon/xp_to_emerald/XPtoEmerald.java
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ private boolean xpToEmerald(Player player, int xp) {
.get(world.getName()) : this.scale;
Material material = (worldMaterials.containsKey(world.getName())) ? worldMaterials
.get(world.getName()) : this.material;
int exp = player.getTotalExperience();
int exp = getTotalXP(player);
if (xp == 0) {
xp = exp;
}
Expand Down Expand Up @@ -547,7 +547,7 @@ private boolean emeraldToXP(Player player, int emeralds) {
return true;
}

int exp = player.getTotalExperience() + (emeralds * scale);
int exp = getTotalXP(player) + (emeralds * scale);
setTotalXP(player, exp);
if ((numOfEmeralds - emeralds) > 0) {
inventory.addItem(new ItemStack(material, numOfEmeralds - emeralds));
Expand All @@ -556,6 +556,31 @@ private boolean emeraldToXP(Player player, int emeralds) {
return true;
}

private int getTotalXP(Player player) {
int xp = 0;
int level = player.getLevel();
float xpPct = player.getExp();
int xpToNext;

if (level < 16) {
xp = 17 * level;
xpToNext = 17;
}
else if (level < 31) {
xp = (int) (1.5 * level * level - 29.5 * level + 360);
xpToNext = 3 * level - 28;
}
else {
xp = (int) (3.5 * level * level - 151.5 * level + 2220);
xpToNext = 7 * level - 148;
}

xp += (int) (xpToNext * xpPct);

player.sendMessage("You had " + xp + " XP!");
return xp;
}

private void setTotalXP(Player player, int xp) {
int level = 0;
int currXP = xp;
Expand Down Expand Up @@ -595,7 +620,6 @@ private void setTotalXP(Player player, int xp) {

player.setLevel(level);
player.setExp(xpPct);
player.setTotalExperience(xp);
return;
}
}
Binary file added jars/XPtoEmerald-1.0.1.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion plugin.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: XP to Emerald
main: com.scott_weldon.xp_to_emerald.XPtoEmerald
version: 1.0.0
version: 1.0.1
commands:
xptoemerald:
description: Convert some XP to Emeralds.
Expand Down

0 comments on commit f839c4f

Please sign in to comment.