diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/gui/skilltree/SkillTreeViewer.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/gui/skilltree/SkillTreeViewer.java index 3454bb3c..a7f9b52a 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/gui/skilltree/SkillTreeViewer.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/gui/skilltree/SkillTreeViewer.java @@ -3,7 +3,9 @@ package net.Indyuce.mmocore.gui.skilltree; import io.lumine.mythic.lib.MythicLib; import io.lumine.mythic.lib.UtilityMethods; import net.Indyuce.mmocore.MMOCore; + import java.util.logging.Level; + import net.Indyuce.mmocore.api.SoundEvent; import net.Indyuce.mmocore.api.player.PlayerData; import net.Indyuce.mmocore.api.util.MMOCoreUtils; @@ -30,6 +32,7 @@ import org.bukkit.persistence.PersistentDataContainer; import org.bukkit.persistence.PersistentDataType; import java.util.*; +import java.util.stream.Collectors; public class SkillTreeViewer extends EditableInventory { protected final Map icons = new HashMap<>(); @@ -200,8 +203,14 @@ public class SkillTreeViewer extends EditableInventory { public class SkillTreeNodeItem extends InventoryItem { + + private final List pathLore = new ArrayList<>(); + + public SkillTreeNodeItem(ConfigurationSection config) { super(Material.AIR, config); + if (config.isList("path-lore")) + pathLore.addAll(config.getStringList("path-lore")); } @Override @@ -222,10 +231,10 @@ public class SkillTreeViewer extends EditableInventory { Icon icon = inv.getIcon(coordinates); ItemStack item = super.display(inv, n, icon.getMaterial(), icon.getCustomModelData()); ItemMeta meta = item.getItemMeta(); + Placeholders holders = getPlaceholders(inv, n); if (inv.getSkillTree().isNode(coordinates)) { SkillTreeNode node = inv.getSkillTree().getNode(coordinates); List lore = new ArrayList<>(); - Placeholders holders = getPlaceholders(inv, n); getLore().forEach(str -> { if (str.contains("{node-lore}")) { node.getLore(inv.getPlayerData()).forEach(s -> lore.add(holders.apply(inv.getPlayer(), s))); @@ -243,7 +252,7 @@ public class SkillTreeViewer extends EditableInventory { } //If it is path we remove the display name and the lore. else { - meta.setLore(new ArrayList<>()); + meta.setLore(pathLore.stream().map(str -> holders.apply(inv.getPlayer(), str)).collect(Collectors.toList())); meta.setDisplayName(" "); } meta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES); @@ -290,6 +299,8 @@ public class SkillTreeViewer extends EditableInventory { holders.register("point-spent", inv.getPlayerData().getPointSpent(inv.getSkillTree())); holders.register("skill-tree-points", inv.getPlayerData().getSkillTreePoint(inv.getSkillTree().getId())); holders.register("global-points", inv.getPlayerData().getSkillTreePoint("global")); + holders.register("display-type", inv.getDisplayType(inv.getCoordinates(n))); + return holders; } } @@ -346,19 +357,26 @@ public class SkillTreeViewer extends EditableInventory { } - public Icon getIcon(IntegerCoordinates coordinates) { + public DisplayType getDisplayType(IntegerCoordinates coordinates) { + Validate.isTrue(skillTree.isNode(coordinates), "The coordinates must be a node"); boolean hasUpPathOrNode = skillTree.isPathOrNode(new IntegerCoordinates(coordinates.getX(), coordinates.getY() - 1)); boolean hasDownPathOrNode = skillTree.isPathOrNode(new IntegerCoordinates(coordinates.getX(), coordinates.getY() + 1)); boolean hasRightPathOrNode = skillTree.isPathOrNode(new IntegerCoordinates(coordinates.getX() + 1, coordinates.getY())); boolean hasLeftPathOrNode = skillTree.isPathOrNode(new IntegerCoordinates(coordinates.getX() - 1, coordinates.getY())); + if (skillTree.isNode(coordinates)) + return NodeType.getNodeType(hasUpPathOrNode, hasRightPathOrNode, hasDownPathOrNode, hasLeftPathOrNode); + return PathType.getPathType(hasUpPathOrNode, hasRightPathOrNode, hasDownPathOrNode, hasLeftPathOrNode); + } + public Icon getIcon(IntegerCoordinates coordinates) { + DisplayType displayType = getDisplayType(coordinates); if (skillTree.isNode(coordinates)) { + NodeType nodeType = (NodeType) displayType; SkillTreeNode node = skillTree.getNode(coordinates); SkillTreeStatus skillTreeStatus = playerData.getNodeStatus(node); //If the node has its own display, it will be shown. if (node.hasIcon(skillTreeStatus)) return node.getIcon(skillTreeStatus); - NodeType nodeType = NodeType.getNodeType(hasUpPathOrNode, hasRightPathOrNode, hasDownPathOrNode, hasLeftPathOrNode); DisplayInfo displayInfo = new NodeDisplayInfo(nodeType, skillTreeStatus); //Takes the display defined in the skill tree config if it exists. if (skillTree.hasIcon(displayInfo)) @@ -368,7 +386,7 @@ public class SkillTreeViewer extends EditableInventory { Validate.notNull(icon, "The node " + node.getFullId() + " has no icon for the type " + nodeType + " and the status " + skillTreeStatus); return icon; } else { - PathType pathType = PathType.getPathType(hasUpPathOrNode, hasRightPathOrNode, hasDownPathOrNode, hasLeftPathOrNode); + PathType pathType = (PathType) displayType; SkillTreePath path = skillTree.getPath(coordinates); DisplayInfo displayInfo = new PathDisplayInfo(pathType, path.getStatus(playerData)); //Takes the display defined in the skill tree config if it exists. diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/gui/skilltree/display/DisplayType.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/gui/skilltree/display/DisplayType.java new file mode 100644 index 00000000..fedf165b --- /dev/null +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/gui/skilltree/display/DisplayType.java @@ -0,0 +1,4 @@ +package net.Indyuce.mmocore.gui.skilltree.display; + +public interface DisplayType { +} diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/gui/skilltree/display/NodeType.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/gui/skilltree/display/NodeType.java index 646feed6..6fd5aafe 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/gui/skilltree/display/NodeType.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/gui/skilltree/display/NodeType.java @@ -1,6 +1,6 @@ package net.Indyuce.mmocore.gui.skilltree.display; -public enum NodeType { +public enum NodeType implements DisplayType { UP_RIGHT_DOWN_LEFT, UP_RIGHT_DOWN, UP_RIGHT_LEFT, diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/gui/skilltree/display/PathType.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/gui/skilltree/display/PathType.java index 10b4f67e..00698cec 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/gui/skilltree/display/PathType.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/gui/skilltree/display/PathType.java @@ -3,7 +3,7 @@ package net.Indyuce.mmocore.gui.skilltree.display; /** * The direction of the path. */ -public enum PathType { +public enum PathType implements DisplayType { UP, /** diff --git a/MMOCore-Dist/src/main/resources/default/gui/skill-tree.yml b/MMOCore-Dist/src/main/resources/default/gui/skill-tree.yml index e7ae88a5..e385a325 100644 --- a/MMOCore-Dist/src/main/resources/default/gui/skill-tree.yml +++ b/MMOCore-Dist/src/main/resources/default/gui/skill-tree.yml @@ -35,7 +35,7 @@ items: skill-tree: name: '{skill-tree-node}' function: skill-tree - slots: [9,18,27] + slots: [ 9,18,27 ] lore: - '' - '&aDescription:' @@ -62,7 +62,7 @@ items: reallocation: function: reallocation item: CAULDRON - slots: [45] + slots: [ 45 ] name: '&aReallocate Skill Tree Points' lore: - '' @@ -76,7 +76,7 @@ items: skill-tree-node: function: 'skill-tree-node' - slots: [1,2,3,4,5,6,7,8,10,11,12,13,14,15,16,17,19,20,21,22,23,24,25,26,28,29,30,31,32,33,34,35,37,38,39,40,41,42,43,44] + slots: [ 1,2,3,4,5,6,7,8,10,11,12,13,14,15,16,17,19,20,21,22,23,24,25,26,28,29,30,31,32,33,34,35,37,38,39,40,41,42,43,44 ] #The lore that will be displayed after the lore of the node. #The {node-lore} placeholder will be replaced by the lore specified in the skill tree node config. #All the placeholders you see here can also be used in the node lore. @@ -101,6 +101,8 @@ items: - '&e◆Points spent for {skill-tree}&e:&6 {point-spent}' - '&e◆Current {skill-tree} &epoints: &6{skill-tree-points}' - '&e◆Current &6global&e points: &6{global-points}' + path-lore: + - '' #This is the name that will be displayed for each status. status-names: