Fixed a problem with skill tree open command feedback message

This commit is contained in:
Jules 2025-10-13 16:29:29 +02:00
parent 47fd207ba8
commit bba10a93cd
5 changed files with 21 additions and 10 deletions

View File

@ -15,6 +15,7 @@ import org.bukkit.command.CommandSender;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class SkillTreesCommand extends CommandTreeRoot { public class SkillTreesCommand extends CommandTreeRoot {
private final Argument<SkillTree> argType; private final Argument<SkillTree> argType;
@ -35,7 +36,7 @@ public class SkillTreesCommand extends CommandTreeRoot {
return CommandResult.FAILURE; return CommandResult.FAILURE;
} }
final var opened = explorer.parse(argType); // null == global final @Nullable var opened = explorer.parse(argType); // null == global
if (MMOCoreUtils.callLegacyCommandEvent(data, this)) return CommandResult.FAILURE; if (MMOCoreUtils.callLegacyCommandEvent(data, this)) return CommandResult.FAILURE;
// Global skill tree view // Global skill tree view

View File

@ -7,7 +7,7 @@ import net.Indyuce.mmocore.command.builtin.mmocore.clazz.ClassCommandTreeNode;
import net.Indyuce.mmocore.command.builtin.mmocore.debug.DebugCommandTreeNode; import net.Indyuce.mmocore.command.builtin.mmocore.debug.DebugCommandTreeNode;
import net.Indyuce.mmocore.command.builtin.mmocore.quest.QuestCommandTreeNode; import net.Indyuce.mmocore.command.builtin.mmocore.quest.QuestCommandTreeNode;
import net.Indyuce.mmocore.command.builtin.mmocore.skill.SkillCommandTreeNode; import net.Indyuce.mmocore.command.builtin.mmocore.skill.SkillCommandTreeNode;
import net.Indyuce.mmocore.command.builtin.mmocore.tree.SkillTreeCommandNode; import net.Indyuce.mmocore.command.builtin.mmocore.skilltree.SkillTreeCommandNode;
import net.Indyuce.mmocore.command.builtin.mmocore.waypoint.WaypointsCommandTreeNode; import net.Indyuce.mmocore.command.builtin.mmocore.waypoint.WaypointsCommandTreeNode;
public class MMOCoreCommandTreeRoot extends CommandTreeRoot { public class MMOCoreCommandTreeRoot extends CommandTreeRoot {

View File

@ -11,6 +11,7 @@ import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.function.BiFunction; import java.util.function.BiFunction;
@ -49,7 +50,7 @@ public class SkillTreePointsCommandTreeNode extends CommandTreeNode {
public @NotNull CommandResult execute(CommandTreeExplorer explorer, CommandSender sender, String[] args) { public @NotNull CommandResult execute(CommandTreeExplorer explorer, CommandSender sender, String[] args) {
final var player = explorer.parse(argPlayer); final var player = explorer.parse(argPlayer);
final var amount = explorer.parse(argAmount); final var amount = explorer.parse(argAmount);
final var skillTree = explorer.parse(argType); final @Nullable var skillTree = explorer.parse(argType);
final var skillTreeName = skillTree == null ? "global" : skillTree.getId(); final var skillTreeName = skillTree == null ? "global" : skillTree.getId();
final var data = PlayerData.get(player); final var data = PlayerData.get(player);

View File

@ -1,4 +1,4 @@
package net.Indyuce.mmocore.command.builtin.mmocore.tree; package net.Indyuce.mmocore.command.builtin.mmocore.skilltree;
import io.lumine.mythic.lib.UtilityMethods; import io.lumine.mythic.lib.UtilityMethods;
import io.lumine.mythic.lib.command.CommandTreeExplorer; import io.lumine.mythic.lib.command.CommandTreeExplorer;
@ -11,22 +11,23 @@ import net.Indyuce.mmocore.skilltree.tree.SkillTree;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class OpenCommandNode extends CommandTreeNode { public class OpenCommandNode extends CommandTreeNode {
private final Argument<SkillTree> argTree;
private final Argument<Player> argPlayer; private final Argument<Player> argPlayer;
private final Argument<SkillTree> argTree;
public OpenCommandNode(CommandTreeNode parent) { public OpenCommandNode(CommandTreeNode parent) {
super(parent, "open"); super(parent, "open");
argPlayer = addArgument(Argument.PLAYER); argPlayer = addArgument(Argument.PLAYER);
argTree = addArgument(Arguments.SKILL_TREE_OR_GLOBAL); argTree = addArgument(Arguments.SKILL_TREE_OR_GLOBAL).withFallback(explorer -> null);
} }
@Override @Override
public @NotNull CommandResult execute(CommandTreeExplorer explorer, CommandSender sender, String[] args) { public @NotNull CommandResult execute(CommandTreeExplorer explorer, CommandSender sender, String[] args) {
final var player = explorer.parse(argPlayer); final var player = explorer.parse(argPlayer);
final var skillTree = explorer.parse(argTree); final @Nullable var skillTree = explorer.parse(argTree);
final var playerData = PlayerData.get(player); final var playerData = PlayerData.get(player);
final var skillTrees = playerData.getProfess().getSkillTrees(); final var skillTrees = playerData.getProfess().getSkillTrees();
@ -34,12 +35,20 @@ public class OpenCommandNode extends CommandTreeNode {
return explorer.fail("Player class " + playerData.getProfess().getName() + " of " + player.getName() + " has no skill tree"); return explorer.fail("Player class " + playerData.getProfess().getName() + " of " + player.getName() + " has no skill tree");
} }
final var skillTreeName = skillTree == null ? "Global" : skillTree.getName();
// Global skill tree view
if (skillTree == null) {
InventoryManager.TREE_VIEW.newInventory(playerData).open();
return explorer.success("Skill tree &6" + skillTreeName + "&e opened for player &6" + player.getName());
}
// Specific skill tree view // Specific skill tree view
if (skillTrees.stream().noneMatch(candidate -> skillTree.getId().equals(candidate.getId()))) { if (skillTrees.stream().noneMatch(candidate -> skillTree.getId().equals(candidate.getId()))) {
return explorer.fail("Player class " + playerData.getProfess().getName() + " of " + player.getName() + " has no skill tree " + skillTree.getId()); return explorer.fail("Player class " + playerData.getProfess().getName() + " of " + player.getName() + " has no skill tree " + skillTree.getId());
} }
InventoryManager.SPECIFIC_TREE_VIEW.get(UtilityMethods.kebabCase(skillTree.getId())).newInventory(playerData).open(); InventoryManager.SPECIFIC_TREE_VIEW.get(UtilityMethods.kebabCase(skillTree.getId())).newInventory(playerData).open();
return explorer.success("Skill tree &6" + skillTree.getName() + "&e opened for player &6" + player.getName()); return explorer.success("Skill tree &6" + skillTreeName + "&e opened for player &6" + player.getName());
} }
} }

View File

@ -1,10 +1,10 @@
package net.Indyuce.mmocore.command.builtin.mmocore.tree; package net.Indyuce.mmocore.command.builtin.mmocore.skilltree;
import io.lumine.mythic.lib.command.CommandTreeNode; import io.lumine.mythic.lib.command.CommandTreeNode;
public class SkillTreeCommandNode extends CommandTreeNode { public class SkillTreeCommandNode extends CommandTreeNode {
public SkillTreeCommandNode(CommandTreeNode parent) { public SkillTreeCommandNode(CommandTreeNode parent) {
super(parent, "tree"); super(parent, "skill-tree");
addChild(new OpenCommandNode(this)); addChild(new OpenCommandNode(this));
} }