forked from Upstream/mmocore
Added /mmocore admin exp take
This commit is contained in:
parent
18b2e032f3
commit
3b09398ebc
@ -555,7 +555,7 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc
|
||||
if (event.isCancelled())
|
||||
return;
|
||||
|
||||
experience += event.getExperience();
|
||||
experience = Math.max(0, experience + event.getExperience());
|
||||
|
||||
// Calculate the player's next level
|
||||
int oldLevel = level, needed;
|
||||
|
@ -1,21 +1,21 @@
|
||||
package net.Indyuce.mmocore.command.rpg.admin;
|
||||
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
import io.lumine.mythic.lib.commands.mmolib.api.CommandTreeNode;
|
||||
import io.lumine.mythic.lib.commands.mmolib.api.Parameter;
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
import net.Indyuce.mmocore.command.CommandVerbose;
|
||||
import net.Indyuce.mmocore.command.MMOCoreCommandTreeRoot;
|
||||
import net.Indyuce.mmocore.experience.EXPSource;
|
||||
import net.Indyuce.mmocore.experience.PlayerProfessions;
|
||||
import net.Indyuce.mmocore.experience.Profession;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.experience.EXPSource;
|
||||
import net.Indyuce.mmocore.experience.PlayerProfessions;
|
||||
import net.Indyuce.mmocore.experience.Profession;
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
import net.Indyuce.mmocore.command.CommandVerbose;
|
||||
import net.Indyuce.mmocore.command.MMOCoreCommandTreeRoot;
|
||||
import io.lumine.mythic.lib.commands.mmolib.api.CommandTreeNode;
|
||||
import io.lumine.mythic.lib.commands.mmolib.api.Parameter;
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
public class ExperienceCommandTreeNode extends CommandTreeNode {
|
||||
public ExperienceCommandTreeNode(CommandTreeNode parent) {
|
||||
@ -24,6 +24,8 @@ public class ExperienceCommandTreeNode extends CommandTreeNode {
|
||||
addChild(new ActionCommandTreeNode(this, "set", PlayerData::setExperience, PlayerProfessions::setExperience));
|
||||
addChild(new ActionCommandTreeNode(this, "give", (data, value) -> data.giveExperience(value, EXPSource.COMMAND), (professions, profession,
|
||||
value) -> professions.giveExperience(profession, value, EXPSource.COMMAND, professions.getPlayerData().getPlayer().getLocation())));
|
||||
addChild(new ActionCommandTreeNode(this, "take", (data, value) -> data.giveExperience(-value, EXPSource.COMMAND), (professions, profession,
|
||||
value) -> professions.giveExperience(profession, -value, EXPSource.COMMAND, professions.getPlayerData().getPlayer().getLocation())));
|
||||
}
|
||||
|
||||
public static class ActionCommandTreeNode extends CommandTreeNode {
|
||||
@ -56,6 +58,7 @@ public class ExperienceCommandTreeNode extends CommandTreeNode {
|
||||
int amount;
|
||||
try {
|
||||
amount = Integer.parseInt(args[5]);
|
||||
Validate.isTrue(amount > 0);
|
||||
} catch (NumberFormatException exception) {
|
||||
sender.sendMessage(ChatColor.RED + args[5] + " is not a valid number.");
|
||||
return CommandResult.FAILURE;
|
||||
|
@ -177,7 +177,7 @@ public class PlayerProfessions {
|
||||
if (event.isCancelled())
|
||||
return;
|
||||
|
||||
exp.put(profession.getId(), exp.containsKey(profession.getId()) ? exp.get(profession.getId()) + event.getExperience() : event.getExperience());
|
||||
exp.put(profession.getId(), Math.max(0, exp.getOrDefault(profession.getId(), 0) + event.getExperience()));
|
||||
int needed, exp, level, oldLevel = getLevel(profession);
|
||||
|
||||
/*
|
||||
|
Loading…
Reference in New Issue
Block a user