Permission requirement for skill tree node according to ticket #801.

Check the wiki for further info. Make sure to reload messages.yml.
This commit is contained in:
Ka0rX 2023-05-04 11:21:11 +01:00
parent 528606628d
commit 5523e875cf
4 changed files with 12 additions and 12 deletions

View File

@ -278,7 +278,7 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc
NodeStatus nodeStatus = nodeStates.get(node);
//Check the State of the node
if (nodeStatus != NodeStatus.UNLOCKED && nodeStatus != NodeStatus.UNLOCKABLE) return false;
return getNodeLevel(node) < node.getMaxLevel() && (skillTreePoints.getOrDefault(node.getTree().getId(), 0) + skillTreePoints.getOrDefault("global", 0) >= node.getSkillTreePointsConsumed());
return node.hasPermissionRequirement(this)&&getNodeLevel(node) < node.getMaxLevel() && (skillTreePoints.getOrDefault(node.getTree().getId(), 0) + skillTreePoints.getOrDefault("global", 0) >= node.getSkillTreePointsConsumed());
}
/**

View File

@ -421,14 +421,12 @@ public class SkillTreeViewer extends EditableInventory {
if (spent < 1) {
MMOCore.plugin.configManager.getSimpleMessage("no-skill-tree-points-spent").send(player);
MMOCore.plugin.soundManager.getSound(SoundEvent.NOT_ENOUGH_POINTS).playTo(getPlayer());
event.setCancelled(true);
return;
}
if (getPlayerData().getSkillTreeReallocationPoints() <= 0) {
MMOCore.plugin.configManager.getSimpleMessage("not-skill-tree-reallocation-point").send(player);
MMOCore.plugin.soundManager.getSound(SoundEvent.NOT_ENOUGH_POINTS).playTo(getPlayer());
event.setCancelled(true);
return;
} else {
int reallocated = playerData.getPointSpent(skillTree);
@ -439,7 +437,6 @@ public class SkillTreeViewer extends EditableInventory {
skillTree.setupNodeStates(playerData);
MMOCore.plugin.configManager.getSimpleMessage("reallocated-points", "points", "" + playerData.getSkillTreePoint(skillTree.getId()), "skill-tree", skillTree.getName()).send(player);
MMOCore.plugin.soundManager.getSound(SoundEvent.RESET_SKILL_TREE).playTo(player);
event.setCancelled(true);
open();
return;
@ -452,7 +449,6 @@ public class SkillTreeViewer extends EditableInventory {
MMOCore.plugin.soundManager.getSound(SoundEvent.CHANGE_SKILL_TREE).playTo(player);
skillTree = MMOCore.plugin.skillTreeManager.get(id);
open();
event.setCancelled(true);
return;
}
@ -462,16 +458,13 @@ public class SkillTreeViewer extends EditableInventory {
int x = container.get(new NamespacedKey(MMOCore.plugin, "coordinates.x"), PersistentDataType.INTEGER);
int y = container.get(new NamespacedKey(MMOCore.plugin, "coordinates.y"), PersistentDataType.INTEGER);
if (!skillTree.isNode(new IntegerCoordinates(x, y))) {
event.setCancelled(true);
return;
}
SkillTreeNode node = skillTree.getNode(new IntegerCoordinates(x, y));
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);
return;
}
if (playerData.canIncrementNodeLevel(node)) {
@ -479,23 +472,22 @@ public class SkillTreeViewer extends EditableInventory {
MMOCore.plugin.configManager.getSimpleMessage("upgrade-skill-node", "skill-node", node.getName(), "level", "" + playerData.getNodeLevel(node)).send(player);
MMOCore.plugin.soundManager.getSound(SoundEvent.LEVEL_UP).playTo(getPlayer());
open();
event.setCancelled(true);
} else if (playerData.getNodeStatus(node) == NodeStatus.LOCKED || playerData.getNodeStatus(node) == NodeStatus.FULLY_LOCKED) {
MMOCore.plugin.configManager.getSimpleMessage("locked-node").send(player);
MMOCore.plugin.soundManager.getSound(SoundEvent.NOT_ENOUGH_POINTS).playTo(getPlayer());
event.setCancelled(true);
} else if (playerData.getNodeLevel(node) >= node.getMaxLevel()) {
MMOCore.plugin.configManager.getSimpleMessage("skill-node-max-level-hit").send(player);
MMOCore.plugin.soundManager.getSound(SoundEvent.NOT_ENOUGH_POINTS).playTo(getPlayer());
event.setCancelled(true);
}else if(!node.hasPermissionRequirement(playerData)){
MMOCore.plugin.configManager.getSimpleMessage("missing-skill-node-permission").send(player);
MMOCore.plugin.soundManager.getSound(SoundEvent.NOT_ENOUGH_POINTS).playTo(getPlayer());
}
//Else the player doesn't doesn't have the skill tree points
else {
MMOCore.plugin.configManager.getSimpleMessage("not-enough-skill-tree-points", "point", "" + node.getSkillTreePointsConsumed()).send(player);
MMOCore.plugin.soundManager.getSound(SoundEvent.NOT_ENOUGH_POINTS).playTo(getPlayer());
event.setCancelled(true);
}
}

View File

@ -24,6 +24,8 @@ public class SkillTreeNode implements ExperienceObject {
private final SkillTree tree;
private final String name, id;
private String permissionRequired;
private final Map<NodeStatus, Icon> icons = new HashMap<>();
private IntegerCoordinates coordinates;
@ -76,6 +78,7 @@ public class SkillTreeNode implements ExperienceObject {
size = Objects.requireNonNull(config.getInt("size"));
isRoot = config.getBoolean("is-root", false);
skillTreePointsConsumed = config.getInt("point-consumed", 1);
permissionRequired = config.getString("permission-required");
Validate.isTrue(skillTreePointsConsumed > 0, "The skill tree points consumed by a node must be greater than 0.");
if (config.contains("lores"))
for (String key : config.getConfigurationSection("lores").getKeys(false))
@ -151,6 +154,10 @@ public class SkillTreeNode implements ExperienceObject {
return maxChildren;
}
public boolean hasPermissionRequirement(PlayerData playerData){
return permissionRequired == null || playerData.getPlayer().hasPermission(permissionRequired);
}
public Set<SkillTreeNode> getSoftParents() {
return softParents.keySet();
}

View File

@ -216,6 +216,7 @@ no-skill-tree-points-spent: '&cYou have not spent any skill tree points.'
locked-node: '&cThis skill is locked!'
upgrade-skill-node: '&eYour skill node &6{skill-node} &eis now Level &6{level}&e!'
skill-node-max-level-hit: '&cYou already hit the max level for that skill node.'
missing-skill-node-permission: '&cYou do not have the permission to unlock this skill node.'
not-enough-skill-tree-points: '&cYou need {point} skill tree point.'
reallocated-points: '&eYou successfully reset the skill tree {skill-tree}. &eYou now have &6{points} &eskill tree points.'
not-skill-tree-reallocation-point: '&cYou do not have 1 skill tree reallocation point.'