Added custom XP multipliers (kp.xpmultiplier.<value>)
This commit is contained in:
1 parent
34616b773a
commit
fbc62cd426
2 files changed
+25
-1
No files matched your search
@@ -53,7 +53,8 @@ public class Stats {
|
||||
public void addExperience(Player p, int experienceToAdd) {
|
||||
if (levels.getBoolean("Levels.Levels.Enabled")) {
|
||||
int currentExperience = getStat("experience", p.getName());
|
||||
setStat("experience", p.getName(), currentExperience + experienceToAdd);
|
||||
int newExperience = applyPossibleXPMultiplier(p, currentExperience + experienceToAdd);
|
||||
setStat("experience", p.getName(), newExperience);
|
||||
if (getStat("experience", p.getName()) >= getRegularOrRelativeNeededExperience(p.getName())) {
|
||||
levelUp(p);
|
||||
Bukkit.getPluginManager().callEvent(new PlayerLevelUpEvent(p, getStat("level", p.getName())));
|
||||
@@ -61,6 +62,11 @@ public class Stats {
|
||||
}
|
||||
}
|
||||
|
||||
private int applyPossibleXPMultiplier(Player p, int experience) {
|
||||
double xpMultiplier = Toolkit.getPermissionAmountDouble(p, "kp.xpmultiplier.", 1.0);
|
||||
return (int) (experience * xpMultiplier);
|
||||
}
|
||||
|
||||
public void levelUp(Player p) {
|
||||
|
||||
String username = p.getName();
|
||||
|
||||
@@ -297,6 +297,24 @@ public class Toolkit {
|
||||
|
||||
}
|
||||
|
||||
// TODO: eventually merge the below two methods into one
|
||||
public static double getPermissionAmountDouble(Player player, String permissionPrefix, double defaultValue) {
|
||||
double highestPermissionValue = 0.0;
|
||||
for (PermissionAttachmentInfo attachmentInfo : player.getEffectivePermissions()) {
|
||||
String permission = attachmentInfo.getPermission();
|
||||
if (permission.startsWith(permissionPrefix)) {
|
||||
// strips from some.permission.49 to just 49
|
||||
double permissionValue = Double.parseDouble(permission.substring(permissionPrefix.length()));
|
||||
if (permissionValue > highestPermissionValue) {
|
||||
highestPermissionValue = permissionValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return highestPermissionValue == 0.0 ? defaultValue : highestPermissionValue;
|
||||
|
||||
}
|
||||
|
||||
public static int getPermissionAmount(Player player, String permissionPrefix, int defaultValue) {
|
||||
// String permissionPrefix = "some.permission.here.";
|
||||
if (!player.isOp()) {
|
||||
|
||||
Reference in new issue
Block a user