From 943553632bf997e160d68997e745faa4f495cc00 Mon Sep 17 00:00:00 2001 From: Ka0rX Date: Tue, 4 Apr 2023 14:58:14 +0100 Subject: [PATCH] can-manually-bind option for SkillSlots and possibility to bind/unbind a skill to a slot through /mmocore admin slot bind . --- .../api/player/profess/PlayerClass.java | 2 +- .../profess/skillbinding/SkillSlot.java | 10 ++- .../rpg/admin/AdminCommandTreeNode.java | 4 +- .../rpg/admin/SlotCommandTreeNode.java | 80 ++++++++++++++++++- .../net/Indyuce/mmocore/gui/SkillList.java | 13 ++- MMOCore-Dist/src/main/resources/config.yml | 2 +- .../src/main/resources/default/messages.yml | 1 + 7 files changed, 104 insertions(+), 8 deletions(-) diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/profess/PlayerClass.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/profess/PlayerClass.java index 8e0d2688..ad5977ab 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/profess/PlayerClass.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/profess/PlayerClass.java @@ -111,7 +111,7 @@ public class PlayerClass extends PostLoadObject implements ExperienceObject { if (config.contains("skill-slots." + i)) skillSlots.put(i, new SkillSlot(config.getConfigurationSection("skill-slots." + i))); else - skillSlots.put(i, new SkillSlot(i, 0, "true", "&eSkill Slot " + MMOCoreUtils.intToRoman(i), new ArrayList<>(), false, new ArrayList<>())); + skillSlots.put(i, new SkillSlot(i, 0, "true", "&eSkill Slot " + MMOCoreUtils.intToRoman(i), new ArrayList<>(), false, true, new ArrayList<>())); } for (String string : config.getStringList("display.lore")) description.add(ChatColor.GRAY + MythicLib.plugin.parseColors(string)); diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/profess/skillbinding/SkillSlot.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/profess/skillbinding/SkillSlot.java index dd9f7ecc..4fecf2ad 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/profess/skillbinding/SkillSlot.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/profess/skillbinding/SkillSlot.java @@ -20,16 +20,19 @@ public class SkillSlot implements Unlockable { private final boolean isUnlockedByDefault; + private final boolean canManuallyBind; + private final List skillBuffTriggers; private Material item; - public SkillSlot(int slot, int modelData, String formula, String name, List lore, boolean isUnlockedByDefault, List skillBuffTriggers) { + public SkillSlot(int slot, int modelData, String formula, String name, List lore, boolean isUnlockedByDefault, boolean canManuallyBind, List skillBuffTriggers) { this.slot = slot; this.modelData = modelData; this.formula = formula; this.name = name; this.lore = lore; + this.canManuallyBind = canManuallyBind; this.isUnlockedByDefault = isUnlockedByDefault; this.skillBuffTriggers = skillBuffTriggers; } @@ -43,6 +46,7 @@ public class SkillSlot implements Unlockable { this.item = Material.valueOf(section.getString("item")); this.modelData = section.getInt("model-data", 0); isUnlockedByDefault = section.getBoolean("unlocked-by-default", true); + canManuallyBind =section.getBoolean("can-manually-bind",true); skillBuffTriggers = new ArrayList<>(); if (section.contains("skill-buffs")) for (String skillBuff : section.getStringList("skill-buffs")) @@ -83,6 +87,10 @@ public class SkillSlot implements Unlockable { return skillBuffTriggers; } + public boolean canManuallyBind() { + return canManuallyBind; + } + public boolean canPlaceSkill(ClassSkill classSkill) { return classSkill.getSkill().matchesFormula(formula); } diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/command/rpg/admin/AdminCommandTreeNode.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/command/rpg/admin/AdminCommandTreeNode.java index a1cc45dd..18a444b3 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/command/rpg/admin/AdminCommandTreeNode.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/command/rpg/admin/AdminCommandTreeNode.java @@ -22,14 +22,14 @@ public class AdminCommandTreeNode extends CommandTreeNode { addChild(new AttributeCommandTreeNode(this)); addChild(new SkillCommandTreeNode(this)); addChild(new SaveDataTreeNode(this)); - + addChild(new SlotCommandTreeNode(this)); addChild(new PointsCommandTreeNode("skill", this, PlayerData::setSkillPoints, PlayerData::giveSkillPoints, PlayerData::getSkillPoints)); addChild(new PointsCommandTreeNode("class", this, PlayerData::setClassPoints, PlayerData::giveClassPoints, PlayerData::getClassPoints)); addChild(new PointsCommandTreeNode("attribute", this, PlayerData::setAttributePoints, PlayerData::giveAttributePoints, PlayerData::getAttributePoints)); addChild(new PointsCommandTreeNode("attr-realloc", this, PlayerData::setAttributeReallocationPoints, PlayerData::giveAttributeReallocationPoints, PlayerData::getAttributeReallocationPoints)); addChild(new PointsCommandTreeNode("skill-realloc", this, PlayerData::setSkillReallocationPoints, PlayerData::giveSkillReallocationPoints, PlayerData::getSkillReallocationPoints)); addChild(new PointsCommandTreeNode("skill-tree-realloc", this, PlayerData::setSkillTreeReallocationPoints, PlayerData::giveSkillTreeReallocationPoints, PlayerData::getSkillTreeReallocationPoints)); - addChild(new SkillTreePointsCommandTreeNode(this,(playerData, integer, s) -> playerData.setSkillTreePoints(s,integer),(playerData, integer, s) -> playerData.giveSkillTreePoints(s,integer),((playerData, s) -> playerData.getSkillTreePoint(s)))); + addChild(new SkillTreePointsCommandTreeNode(this, (playerData, integer, s) -> playerData.setSkillTreePoints(s, integer), (playerData, integer, s) -> playerData.giveSkillTreePoints(s, integer), ((playerData, s) -> playerData.getSkillTreePoint(s)))); for (PlayerResource res : PlayerResource.values()) addChild(new ResourceCommandTreeNode(res.name().toLowerCase(), this, res)); } diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/command/rpg/admin/SlotCommandTreeNode.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/command/rpg/admin/SlotCommandTreeNode.java index 38c2c852..39bf8d2e 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/command/rpg/admin/SlotCommandTreeNode.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/command/rpg/admin/SlotCommandTreeNode.java @@ -15,9 +15,11 @@ import org.bukkit.entity.Player; public class SlotCommandTreeNode extends CommandTreeNode { public SlotCommandTreeNode(CommandTreeNode parent) { - super(parent, "skill"); + super(parent, "slot"); addChild(new LockSlotCommandTreeNode(this, "lock", true)); addChild(new LockSlotCommandTreeNode(this, "unlock", false)); + addChild(new UnbindSlotCommandTreeNode(this, "unbind")); + addChild(new BindSlotCommandTreeNode(this, "bind")); } public class LockSlotCommandTreeNode extends CommandTreeNode { @@ -51,7 +53,7 @@ public class SlotCommandTreeNode extends CommandTreeNode { sender.sendMessage(ChatColor.RED + "The slot can't be negative."); return CommandResult.FAILURE; } - SkillSlot skillSlot=playerData.getProfess().getSkillSlot(slot); + SkillSlot skillSlot = playerData.getProfess().getSkillSlot(slot); if (lock) { if (!playerData.hasUnlocked(skillSlot)) { CommandVerbose.verbose(sender, CommandVerbose.CommandType.SKILL, ChatColor.RED + "The skill slot " + skillSlot.getName() + " is already locked" + " for " + player.getName()); @@ -72,6 +74,80 @@ public class SlotCommandTreeNode extends CommandTreeNode { } + public class BindSlotCommandTreeNode extends CommandTreeNode { + + public BindSlotCommandTreeNode(CommandTreeNode parent, String id) { + super(parent, id); + addParameter(Parameter.PLAYER); + addParameter(Parameter.AMOUNT); + addParameter(new Parameter("", + (explorer, list) -> MMOCore.plugin.skillManager.getAll().forEach(skill -> list.add(skill.getHandler().getId().toUpperCase())))); + + } + + @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; + } + PlayerData playerData = PlayerData.get(player); + int slot; + try { + slot = Integer.parseInt(args[4]); + } catch (NumberFormatException e) { + sender.sendMessage(ChatColor.RED + args[4] + " is not a valid number."); + return CommandResult.FAILURE; + } + ClassSkill skill = playerData.getProfess().getSkill(args[5]); + if (skill == null) { + sender.sendMessage(ChatColor.RED + "The player's class doesn't have a skill called " + args[5] + "."); + return CommandResult.FAILURE; + } + playerData.bindSkill(slot, skill); + + CommandVerbose.verbose(sender, CommandVerbose.CommandType.SKILL, ChatColor.GOLD + "The skill " + skill.getSkill().getHandler().getId() + " is now bound to the slot " + slot); + return CommandResult.SUCCESS; + } + } + + public class UnbindSlotCommandTreeNode extends CommandTreeNode { + + public UnbindSlotCommandTreeNode(CommandTreeNode parent, String id) { + super(parent, id); + 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[3] + "."); + return CommandResult.FAILURE; + } + PlayerData playerData = PlayerData.get(player); + int slot; + try { + slot = Integer.parseInt(args[4]); + } catch (NumberFormatException e) { + sender.sendMessage(ChatColor.RED + args[4] + " is not a valid number."); + return CommandResult.FAILURE; + } + String skill = playerData.hasSkillBound(slot) ? playerData.getBoundSkill(slot).getSkill().getHandler().getId() : "none"; + if (playerData.hasSkillBound(slot)) + playerData.unbindSkill(slot); + + CommandVerbose.verbose(sender, CommandVerbose.CommandType.SKILL, ChatColor.GOLD + "The skill " + skill + " has been unbounded from the slot " + slot); + return CommandResult.SUCCESS; + } + } + @Override public CommandResult execute(CommandSender sender, String[] args) { return CommandResult.THROW_USAGE; diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/gui/SkillList.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/gui/SkillList.java index b5cbb113..5b527497 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/gui/SkillList.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/gui/SkillList.java @@ -160,7 +160,7 @@ public class SkillList extends EditableInventory { @Override public ItemStack display(SkillViewerInventory inv, int n) { - if (!inv.getPlayerData().hasUnlocked("slot:" + n)) { + if (!inv.getPlayerData().hasUnlocked("slot:" + (n+1))) { return new ItemStack(Material.AIR); } SkillSlot skillSlot = inv.getPlayerData().getProfess().getSkillSlot(n + 1); @@ -403,6 +403,11 @@ public class SkillList extends EditableInventory { player.playSound(player.getLocation(), Sound.ENTITY_VILLAGER_NO, 1, 2); return; } + if(!playerData.getProfess().getSkillSlot(index).canManuallyBind()){ + MMOCore.plugin.configManager.getSimpleMessage("cant-manually-bind").send(player); + player.playSound(player.getLocation(), Sound.ENTITY_VILLAGER_NO, 1, 2); + return; + } player.playSound(player.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1, 2); playerData.unbindSkill(index); open(); @@ -415,6 +420,12 @@ public class SkillList extends EditableInventory { return; } + if(!skillSlot.canManuallyBind()){ + MMOCore.plugin.configManager.getSimpleMessage("cant-manually-bind").send(player); + player.playSound(player.getLocation(), Sound.ENTITY_VILLAGER_NO, 1, 2); + return; + } + if (!skillSlot.canPlaceSkill(selected)) { MMOCore.plugin.configManager.getSimpleMessage("not-compatible-skill").send(player); player.playSound(player.getLocation(), Sound.ENTITY_VILLAGER_NO, 1, 2); diff --git a/MMOCore-Dist/src/main/resources/config.yml b/MMOCore-Dist/src/main/resources/config.yml index d59b2c26..cf27fcae 100644 --- a/MMOCore-Dist/src/main/resources/config.yml +++ b/MMOCore-Dist/src/main/resources/config.yml @@ -198,7 +198,7 @@ death-exp-loss: percent: 30 #Maximum number of slot. This means that you can't unlock a slot greater than max-slots. (The slot count starts at 1 & end at max-slots). -max-slots: 10 +max-slots: 8 #If you want players to bound their passive skills. #If false, all the passive skills unlocked will be active diff --git a/MMOCore-Dist/src/main/resources/default/messages.yml b/MMOCore-Dist/src/main/resources/default/messages.yml index 8b43cf8e..2b98be1c 100644 --- a/MMOCore-Dist/src/main/resources/default/messages.yml +++ b/MMOCore-Dist/src/main/resources/default/messages.yml @@ -203,6 +203,7 @@ upgrade-skill: '&eYour &6{skill} &eis now Level &6{level}&e!' not-unlocked-skill: '&cYou have not unlocked that skill yet.' no-skill-bound: '&cYou don''t have any skill bound to this slot.' not-compatible-skill: '&cThe selected skill is not compatible with this slot.' +cant-manually-bind: "&cYou can't manually bind/unbind a skill to this slot." skill-max-level-hit: '&cYou already hit the max level for that skill.' no-skill-placeholder: 'No Skill Bound' not-skill-reallocation-point: '&cYou do not have 1 skill reallocation point.'