diff --git a/src/main/java/net/Indyuce/mmocore/command/rpg/admin/AdminCommandMap.java b/src/main/java/net/Indyuce/mmocore/command/rpg/admin/AdminCommandMap.java index f8657d6d..8b2021b9 100644 --- a/src/main/java/net/Indyuce/mmocore/command/rpg/admin/AdminCommandMap.java +++ b/src/main/java/net/Indyuce/mmocore/command/rpg/admin/AdminCommandMap.java @@ -21,6 +21,10 @@ public class AdminCommandMap extends CommandMap { addFloor(new PointsCommandMap("class", this, (data, points) -> data.setClassPoints(points), (data, points) -> data.giveClassPoints(points), (data) -> data.getClassPoints())); addFloor(new PointsCommandMap("attribute", this, (data, points) -> data.setAttributePoints(points), (data, points) -> data.giveAttributePoints(points), (data) -> data.getAttributePoints())); addFloor(new PointsCommandMap("attr-realloc", this, (data, points) -> data.setAttributeReallocationPoints(points), (data, points) -> data.giveAttributeReallocationPoints(points), (data) -> data.getAttributeReallocationPoints())); + + addFloor(new ResourcesCommandMap("mana", this, (data, value) -> data.setMana(value), (data, value) -> data.giveMana(value), (data, value) -> data.giveMana(-value), (data) -> data.getMana())); + addFloor(new ResourcesCommandMap("stamina", this, (data, value) -> data.setStamina(value), (data, value) -> data.giveStamina(value), (data, value) -> data.giveStamina(-value), (data) -> data.getStamina())); + addFloor(new ResourcesCommandMap("stellium", this, (data, value) -> data.setStellium(value), (data, value) -> data.giveStellium(value), (data, value) -> data.giveStellium(-value), (data) -> data.getStellium())); } @Override diff --git a/src/main/java/net/Indyuce/mmocore/command/rpg/admin/ResourcesCommandMap.java b/src/main/java/net/Indyuce/mmocore/command/rpg/admin/ResourcesCommandMap.java new file mode 100644 index 00000000..842e05b1 --- /dev/null +++ b/src/main/java/net/Indyuce/mmocore/command/rpg/admin/ResourcesCommandMap.java @@ -0,0 +1,73 @@ +package net.Indyuce.mmocore.command.rpg.admin; + +import java.util.function.BiConsumer; +import java.util.function.Function; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import net.Indyuce.mmocore.api.player.PlayerData; +import net.Indyuce.mmocore.command.api.CommandEnd; +import net.Indyuce.mmocore.command.api.CommandMap; +import net.Indyuce.mmocore.command.api.Parameter; + +public class ResourcesCommandMap extends CommandMap { + private final String type; + private final Function get; + + public ResourcesCommandMap(String type, CommandMap parent, BiConsumer set, BiConsumer give, BiConsumer take, Function get) { + super(parent, "resource-" + type); + + this.type = type; + this.get = get; + + addFloor(new ActionCommandMap(this, "set", set)); + addFloor(new ActionCommandMap(this, "give", give)); + addFloor(new ActionCommandMap(this, "take", take)); + } + + public class ActionCommandMap extends CommandEnd { + private final BiConsumer action; + + public ActionCommandMap(CommandMap parent, String type, BiConsumer action) { + super(parent, type); + + this.action = action; + + addParameter(Parameter.PLAYER); + addParameter(Parameter.AMOUNT); + } + + @Override + public CommandResult execute(CommandSender sender, String[] args) { + if (args.length < 5) + return CommandResult.THROW_USAGE; + + Player player = Bukkit.getPlayer(args[3]); + if (player == null) { + sender.sendMessage(ChatColor.RED + "Could not find the player called " + args[2] + "."); + return CommandResult.FAILURE; + } + + double amount = 0; + try { + amount = Double.parseDouble(args[4]); + } catch (Exception e) { + sender.sendMessage(ChatColor.RED + args[4] + " is not a valid number."); + return CommandResult.FAILURE; + } + + PlayerData data = PlayerData.get(player); + action.accept(data, amount); + sender.sendMessage(ChatColor.GOLD + player.getName() + ChatColor.YELLOW + " now has " + ChatColor.GOLD + get.apply(data) + ChatColor.YELLOW + " " + type + " points."); + return CommandResult.SUCCESS; + } + } + + @Override + public CommandResult execute(CommandSender sender, String[] args) { + return CommandResult.THROW_USAGE; + } +}