From 77d4f8e4e49dfe3e9b40738973fe34f6deab148e Mon Sep 17 00:00:00 2001 From: Ka0rX Date: Tue, 21 Mar 2023 21:20:14 +0100 Subject: [PATCH] Command to lock/unlock skill manually. It is better to use triggers as it enables the unlocking.. to go to its initial state after a reallocation. --- .../rpg/admin/SkillCommandTreeNode.java | 51 ++++++++++++++++--- 1 file changed, 43 insertions(+), 8 deletions(-) diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/command/rpg/admin/SkillCommandTreeNode.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/command/rpg/admin/SkillCommandTreeNode.java index 869c44e5..38fdd94c 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/command/rpg/admin/SkillCommandTreeNode.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/command/rpg/admin/SkillCommandTreeNode.java @@ -18,7 +18,8 @@ import java.util.function.BiFunction; public class SkillCommandTreeNode extends CommandTreeNode { public SkillCommandTreeNode(CommandTreeNode parent) { super(parent, "skill"); - + addChild(new LockSkillCommandTreeNode(this, "lock", true)); + addChild(new LockSkillCommandTreeNode(this, "unlock", false)); addChild(new ActionCommandTreeNode(this, "give", (old, amount) -> old + amount)); addChild(new ActionCommandTreeNode(this, "set", (old, amount) -> amount)); } @@ -55,15 +56,14 @@ public class SkillCommandTreeNode extends CommandTreeNode { } - - ClassSkill classSkill=null; - for(ClassSkill var:playerData.getProfess().getSkills()) { - if(var.getSkill().equals(skill)) - classSkill=var; + ClassSkill classSkill = null; + for (ClassSkill var : playerData.getProfess().getSkills()) { + if (var.getSkill().equals(skill)) + classSkill = var; } - if(classSkill==null||classSkill.getUnlockLevel() > playerData.getLevel()) { - sender.sendMessage(ChatColor.RED+ skill.getName()+" is not unlockable for "+player.getName()+"."); + if (classSkill == null || classSkill.getUnlockLevel() > playerData.getLevel()) { + sender.sendMessage(ChatColor.RED + skill.getName() + " is not unlockable for " + player.getName() + "."); return CommandResult.FAILURE; } @@ -83,6 +83,41 @@ public class SkillCommandTreeNode extends CommandTreeNode { } } + public class LockSkillCommandTreeNode extends CommandTreeNode { + private final boolean lock; + + public LockSkillCommandTreeNode(CommandTreeNode parent, String id, boolean lock) { + super(parent, id); + this.lock = lock; + addParameter(Parameter.PLAYER); + } + + @Override + public CommandResult execute(CommandSender sender, String[] args) { + if (args.length < 4) + 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; + } + PlayerData playerData = PlayerData.get(player); + + RegisteredSkill skill = MMOCore.plugin.skillManager.getSkill(args[4]); + if (skill == null) { + sender.sendMessage(ChatColor.RED + "Could not find the skill called " + args[4] + "."); + return CommandResult.FAILURE; + } + if (lock) + playerData.lock(skill); + else + playerData.unlock(skill); + CommandVerbose.verbose(sender, CommandVerbose.CommandType.SKILL, "The skill " + skill.getName() + " is now " + (lock ? "locked" : "unlocked" + " for " + player.getName())); + return CommandResult.SUCCESS; + } + } + + @Override public CommandResult execute(CommandSender sender, String[] args) { return CommandResult.THROW_USAGE;