mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2024-08-25 04:37:44 +00:00
Fix minor Exp discrepancy
Add 'l<level>' syntax to /exp command EG: /exp set l20
This commit is contained in:
parent
101ae201d6
commit
ba6cc5a9ee
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue