summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKHobbits <rob@khobbits.co.uk>2012-08-08 02:06:45 +0100
committerKHobbits <rob@khobbits.co.uk>2012-08-08 02:07:47 +0100
commitba6cc5a9ee7175edb4986a732c96adaef7d09dd9 (patch)
treee2fa542b8148c5f9de0017a16d3e0263a97a8668
parent101ae201d65852cc7aee8b0edf16e21d81f2cdc0 (diff)
downloadEssentials-ba6cc5a9ee7175edb4986a732c96adaef7d09dd9.tar
Essentials-ba6cc5a9ee7175edb4986a732c96adaef7d09dd9.tar.gz
Essentials-ba6cc5a9ee7175edb4986a732c96adaef7d09dd9.tar.lz
Essentials-ba6cc5a9ee7175edb4986a732c96adaef7d09dd9.tar.xz
Essentials-ba6cc5a9ee7175edb4986a732c96adaef7d09dd9.zip
Fix minor Exp discrepancy
Add 'l<level>' syntax to /exp command EG: /exp set l20
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandexp.java23
-rw-r--r--Essentials/src/com/earth2me/essentials/craftbukkit/SetExpFix.java35
2 files changed, 44 insertions, 14 deletions
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandexp.java b/Essentials/src/com/earth2me/essentials/commands/Commandexp.java
index 0f1fe4ea6..f3dac79e2 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commandexp.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandexp.java
@@ -3,6 +3,7 @@ package com.earth2me.essentials.commands;
import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.User;
import com.earth2me.essentials.craftbukkit.SetExpFix;
+import java.util.Locale;
import org.bukkit.Server;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@@ -103,7 +104,7 @@ public class Commandexp extends EssentialsCommand
}
}
- private void expMatch(final Server server, final CommandSender sender, final String match, final String amount, final boolean toggle) throws NotEnoughArgumentsException
+ private void expMatch(final Server server, final CommandSender sender, final String match, String amount, final boolean toggle) throws NotEnoughArgumentsException
{
boolean foundUser = false;
for (Player matchPlayer : server.matchPlayer(match))
@@ -124,9 +125,25 @@ public class Commandexp extends EssentialsCommand
sender.sendMessage(_("exp", target.getDisplayName(), SetExpFix.getTotalExperience(target), target.getLevel(), SetExpFix.getExpUntilNextLevel(target)));
}
- private void setExp(final CommandSender sender, final User target, final String strAmount, final boolean give)
+ private void setExp(final CommandSender sender, final User target, String strAmount, final boolean give)
{
- Long amount = Long.parseLong(strAmount);
+ Long amount;
+ strAmount = strAmount.toLowerCase(Locale.ENGLISH);
+ if (strAmount.startsWith("l"))
+ {
+ strAmount = strAmount.substring(1);
+ int neededLevel = Integer.parseInt(strAmount);
+ if (give)
+ {
+ neededLevel += target.getLevel();
+ }
+ amount = (long)SetExpFix.getExpToLevel(neededLevel);
+ SetExpFix.setTotalExperience(target, 0);
+ }
+ else {
+ amount = Long.parseLong(strAmount);
+ }
+
if (give)
{
amount += SetExpFix.getTotalExperience(target);
diff --git a/Essentials/src/com/earth2me/essentials/craftbukkit/SetExpFix.java b/Essentials/src/com/earth2me/essentials/craftbukkit/SetExpFix.java
index e4a226da0..7ed3034c3 100644
--- a/Essentials/src/com/earth2me/essentials/craftbukkit/SetExpFix.java
+++ b/Essentials/src/com/earth2me/essentials/craftbukkit/SetExpFix.java
@@ -22,7 +22,7 @@ public class SetExpFix
int amount = exp;
while (amount > 0)
{
- final int expToLevel = getExpToLevel(player);
+ final int expToLevel = getExpAtLevel(player);
amount -= expToLevel;
if (amount >= 0)
{
@@ -39,43 +39,56 @@ public class SetExpFix
}
}
- private static int getExpToLevel(final Player player)
+ private static int getExpAtLevel(final Player player)
{
- return getExpToLevel(player.getLevel());
+ return getExpAtLevel(player.getLevel());
}
- private static int getExpToLevel(final int level)
+ public static int getExpAtLevel(final int level)
{
- if (level >= 30)
+ if (level > 29)
{
return 62 + (level - 30) * 7;
}
- if (level >= 15)
+ if (level > 15)
{
return 17 + (level - 15) * 3;
}
return 17;
}
+
+ public static int getExpToLevel(final int level)
+ {
+ int currentLevel = 0;
+ int exp = 0;
+
+ while (currentLevel < level)
+ {
+ exp += getExpAtLevel(currentLevel);
+ currentLevel++;
+ }
+ return exp;
+ }
//This method is required because the bukkit player.getTotalExperience() method, shows exp that has been 'spent'.
//Without this people would be able to use exp and then still sell it.
public static int getTotalExperience(final Player player)
{
- int exp = (int)Math.round(getExpToLevel(player) * player.getExp());
+ int exp = (int)Math.round(getExpAtLevel(player) * player.getExp());
int currentLevel = player.getLevel();
while (currentLevel > 0)
{
currentLevel--;
- exp += getExpToLevel(currentLevel);
+ exp += getExpAtLevel(currentLevel);
}
return exp;
}
public static int getExpUntilNextLevel(final Player player)
{
- int exp = (int)Math.round(getExpToLevel(player) * player.getExp());
- int nextLevel = player.getLevel() + 1;
- return getExpToLevel(nextLevel) - exp;
+ int exp = (int)Math.round(getExpAtLevel(player) * player.getExp());
+ int nextLevel = player.getLevel();
+ return getExpAtLevel(nextLevel) - exp;
}
}