diff --git a/src/main/java/net/Indyuce/mmocore/command/rpg/admin/AdminCommandTreeNode.java b/src/main/java/net/Indyuce/mmocore/command/rpg/admin/AdminCommandTreeNode.java index 3310229a..8dd104a0 100644 --- a/src/main/java/net/Indyuce/mmocore/command/rpg/admin/AdminCommandTreeNode.java +++ b/src/main/java/net/Indyuce/mmocore/command/rpg/admin/AdminCommandTreeNode.java @@ -16,6 +16,7 @@ public class AdminCommandTreeNode extends CommandTreeNode { addChild(new ExperienceCommandTreeNode(this)); addChild(new LevelCommandTreeNode(this)); + addChild(new AttributeCommandTreeNode(this)); addChild(new PointsCommandTreeNode("skill", this, (data, points) -> data.setSkillPoints(points), (data, points) -> data.giveSkillPoints(points), (data) -> data.getSkillPoints())); addChild(new PointsCommandTreeNode("class", this, (data, points) -> data.setClassPoints(points), (data, points) -> data.giveClassPoints(points), (data) -> data.getClassPoints())); diff --git a/src/main/java/net/Indyuce/mmocore/command/rpg/admin/AttributeCommandTreeNode.java b/src/main/java/net/Indyuce/mmocore/command/rpg/admin/AttributeCommandTreeNode.java new file mode 100644 index 00000000..fcdfbb92 --- /dev/null +++ b/src/main/java/net/Indyuce/mmocore/command/rpg/admin/AttributeCommandTreeNode.java @@ -0,0 +1,75 @@ +package net.Indyuce.mmocore.command.rpg.admin; + +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.api.player.PlayerData; +import net.Indyuce.mmocore.api.player.attribute.PlayerAttribute; +import net.Indyuce.mmocore.api.player.attribute.PlayerAttributes.AttributeInstance; +import net.mmogroup.mmolib.command.api.CommandTreeNode; +import net.mmogroup.mmolib.command.api.Parameter; + +public class AttributeCommandTreeNode extends CommandTreeNode { + public AttributeCommandTreeNode(CommandTreeNode parent) { + super(parent, "attribute"); + + addChild(new ActionCommandTreeNode(this, "give", false)); + addChild(new ActionCommandTreeNode(this, "take", true)); + } + + public class ActionCommandTreeNode extends CommandTreeNode { + private final int c; + + public ActionCommandTreeNode(CommandTreeNode parent, String type, boolean take) { + super(parent, type); + + this.c = take ? -1 : 1; + + addParameter(Parameter.PLAYER); + addParameter(new Parameter("", + (explorer, list) -> MMOCore.plugin.attributeManager.getAll().forEach(attribute -> list.add(attribute.getId())))); + addParameter(Parameter.AMOUNT); + } + + @Override + public CommandResult execute(CommandSender sender, String[] args) { + if (args.length < 6) + return CommandResult.THROW_USAGE; + + Player player = Bukkit.getPlayer(args[3]); + if (player == null) { + sender.sendMessage(ChatColor.RED + "Could not find the player called " + args[3] + "."); + return CommandResult.FAILURE; + } + + String format = args[4].toLowerCase().replace("_", "-"); + if (!MMOCore.plugin.attributeManager.has(format)) { + sender.sendMessage(ChatColor.RED + "Could not find the attribute called " + args[4] + "."); + return CommandResult.FAILURE; + } + PlayerAttribute attribute = MMOCore.plugin.attributeManager.get(format); + + int amount = 0; + try { + amount = Integer.parseInt(args[5]); + } catch (Exception e) { + sender.sendMessage(ChatColor.RED + args[5] + " is not a valid number."); + return CommandResult.FAILURE; + } + + AttributeInstance instance = PlayerData.get(player).getAttributes().getInstance(attribute); + instance.setBase(Math.min(attribute.getMax(), instance.getBase() + c * amount)); + sender.sendMessage(ChatColor.GOLD + player.getName() + ChatColor.YELLOW + " now has " + ChatColor.GOLD + instance.getBase() + + ChatColor.YELLOW + " " + attribute.getName() + "."); + return CommandResult.SUCCESS; + } + } + + @Override + public CommandResult execute(CommandSender sender, String[] args) { + return CommandResult.THROW_USAGE; + } +} diff --git a/src/main/java/net/Indyuce/mmocore/command/rpg/admin/PointsCommandTreeNode.java b/src/main/java/net/Indyuce/mmocore/command/rpg/admin/PointsCommandTreeNode.java index acaea6da..f23e3e17 100644 --- a/src/main/java/net/Indyuce/mmocore/command/rpg/admin/PointsCommandTreeNode.java +++ b/src/main/java/net/Indyuce/mmocore/command/rpg/admin/PointsCommandTreeNode.java @@ -46,7 +46,7 @@ public class PointsCommandTreeNode extends CommandTreeNode { Player player = Bukkit.getPlayer(args[3]); if (player == null) { - sender.sendMessage(ChatColor.RED + "Could not find the player called " + args[2] + "."); + sender.sendMessage(ChatColor.RED + "Could not find the player called " + args[3] + "."); return CommandResult.FAILURE; } diff --git a/src/main/java/net/Indyuce/mmocore/manager/AttributeManager.java b/src/main/java/net/Indyuce/mmocore/manager/AttributeManager.java index a8327f3c..38920e3f 100644 --- a/src/main/java/net/Indyuce/mmocore/manager/AttributeManager.java +++ b/src/main/java/net/Indyuce/mmocore/manager/AttributeManager.java @@ -41,5 +41,4 @@ public class AttributeManager extends MMOManager { public void clear() { map.clear(); } - }