diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java index b751072e..ba882e67 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java @@ -80,7 +80,6 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc private double mana, stamina, stellium; private Guild guild; private SkillCastingHandler skillCasting; - private SkillTree cachedSkillTree; private final PlayerQuests questData; private final PlayerStats playerStats; private final List friends = new ArrayList<>(); @@ -406,18 +405,9 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc return Math.max(1, level); } - public void setCachedSkillTree(SkillTree cachedSkillTree) { - this.cachedSkillTree = cachedSkillTree; - } - @NotNull - public SkillTree getOpenedSkillTree() { - if (cachedSkillTree == null) { - Optional optionnal = MMOCore.plugin.skillTreeManager.getAll().stream().findFirst(); - return optionnal.isPresent() ? optionnal.get() : null; - } - return cachedSkillTree; - } + + @Nullable public AbstractParty getParty() { diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/profess/SavedClassInformation.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/profess/SavedClassInformation.java index 5a807ebf..db1cd3f2 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/profess/SavedClassInformation.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/profess/SavedClassInformation.java @@ -186,7 +186,7 @@ public class SavedClassInformation { } public int getAttributeLevel(String id) { - return attributes.get(id); + return attributes.getOrDefault(id,0); } public void registerAttributeLevel(PlayerAttribute attribute, int level) { @@ -239,6 +239,8 @@ public class SavedClassInformation { attributes.forEach((id, pts) -> player.getAttributes().setBaseAttribute(id, pts)); skillTreePoints.forEach((skillTree, point) -> player.setSkillTreePoints(skillTree, point)); nodeLevels.forEach((node, level) -> player.setNodeLevel(node, level)); + for(SkillTree skillTree: profess.getSkillTrees()) + skillTree.setupNodeState(player); //Add the values to the times claimed table and claims the corresponding stat triggers. nodeTimesClaimed.forEach((str,val)->player.setClaims(str,val)); nodeLevels.keySet().forEach(node -> node.getExperienceTable().claimStatTriggers(player, node)); diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/gui/SkillTreeViewer.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/gui/SkillTreeViewer.java index 8cce0c02..47b2432c 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/gui/SkillTreeViewer.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/gui/SkillTreeViewer.java @@ -60,9 +60,9 @@ public class SkillTreeViewer extends EditableInventory { holders.register("skill-tree-points", inv.getPlayerData().getSkillTreePoint(inv.getSkillTree().getId())); holders.register("global-points", inv.getPlayerData().getSkillTreePoint("global")); holders.register("realloc-points", inv.getPlayerData().getSkillTreeReallocationPoints()); - int maxPointSpent=inv.getSkillTree().getMaxPointSpent(); - holders.register("max-point-spent",maxPointSpent==Integer.MAX_VALUE?"∞":maxPointSpent); - holders.register("point-spent",inv.getPlayerData().getPointSpent(inv.getSkillTree())); + int maxPointSpent = inv.getSkillTree().getMaxPointSpent(); + holders.register("max-point-spent", maxPointSpent == Integer.MAX_VALUE ? "∞" : maxPointSpent); + holders.register("point-spent", inv.getPlayerData().getPointSpent(inv.getSkillTree())); return holders; } @@ -102,7 +102,7 @@ public class SkillTreeViewer extends EditableInventory { @Override public ItemStack display(SkillTreeInventory inv, int n) { int index = inv.getEditable().getByFunction("skill-tree").getSlots().size() * inv.treeListPage + n; - if (inv.skillTrees.size()>=index) { + if (inv.skillTrees.size() <= index) { return new ItemStack(Material.AIR); } SkillTree skillTree = inv.skillTrees.get(index); @@ -134,9 +134,9 @@ public class SkillTreeViewer extends EditableInventory { Placeholders holders = new Placeholders(); holders.register("name", skillTree.getName()); holders.register("id", skillTree.getId()); - int maxPointSpent=inv.getSkillTree().getMaxPointSpent(); - holders.register("max-point-spent",maxPointSpent==Integer.MAX_VALUE?"∞":maxPointSpent); - holders.register("point-spent",inv.getPlayerData().getPointSpent(inv.getSkillTree())); + int maxPointSpent = inv.getSkillTree().getMaxPointSpent(); + holders.register("max-point-spent", maxPointSpent == Integer.MAX_VALUE ? "∞" : maxPointSpent); + 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")); return holders; @@ -250,9 +250,9 @@ public class SkillTreeViewer extends EditableInventory { holders.register("max-children", node.getMaxChildren()); holders.register("size", node.getSize()); } - int maxPointSpent=inv.getSkillTree().getMaxPointSpent(); - holders.register("max-point-spent",maxPointSpent==Integer.MAX_VALUE?"∞":maxPointSpent); - holders.register("point-spent",inv.getPlayerData().getPointSpent(inv.getSkillTree())); + int maxPointSpent = inv.getSkillTree().getMaxPointSpent(); + holders.register("max-point-spent", maxPointSpent == Integer.MAX_VALUE ? "∞" : maxPointSpent); + 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")); return holders; @@ -268,14 +268,14 @@ public class SkillTreeViewer extends EditableInventory { private int treeListPage; private final int maxTreeListPage; private final List skillTrees; - private final SkillTree skillTree; + private SkillTree skillTree; private final List slots; public SkillTreeInventory(PlayerData playerData, EditableInventory editable) { super(playerData, editable); - skillTree = playerData.getOpenedSkillTree(); - skillTrees=playerData.getProfess().getSkillTrees(); + skillTrees = playerData.getProfess().getSkillTrees(); + skillTree = skillTrees.get(0); maxTreeListPage = (skillTrees.size() - 1) / editable.getByFunction("skill-tree").getSlots().size(); //We get the width and height of the GUI(corresponding to the slots given) slots = editable.getByFunction("skill-tree-node").getSlots(); @@ -398,10 +398,9 @@ public class SkillTreeViewer extends EditableInventory { if (item.getFunction().equals("skill-tree")) { String id = event.getItemStack().getItemMeta().getPersistentDataContainer().get( new NamespacedKey(MMOCore.plugin, "skill-tree-id"), PersistentDataType.STRING); - playerData.setCachedSkillTree(MMOCore.plugin.skillTreeManager.get(id)); MMOCore.plugin.soundManager.getSound(SoundEvent.CHANGE_SKILL_TREE).playTo(player); - - newInventory(playerData).open(); + skillTree=MMOCore.plugin.skillTreeManager.get(id); + open(); event.setCancelled(true); return; } @@ -416,7 +415,7 @@ public class SkillTreeViewer extends EditableInventory { return; } SkillTreeNode node = skillTree.getNode(new IntegerCoordinates(x, y)); - if(playerData.getPointSpent(skillTree)>= skillTree.getMaxPointSpent()) { + if (playerData.getPointSpent(skillTree) >= skillTree.getMaxPointSpent()) { MMOCore.plugin.configManager.getSimpleMessage("max-points-reached").send(player); MMOCore.plugin.soundManager.getSound(SoundEvent.NOT_ENOUGH_POINTS).playTo(getPlayer()); event.setCancelled(true);