diff --git a/src/main/java/net/Indyuce/mmocore/gui/AttributeView.java b/src/main/java/net/Indyuce/mmocore/gui/AttributeView.java index 058694a8..5ad00e3b 100644 --- a/src/main/java/net/Indyuce/mmocore/gui/AttributeView.java +++ b/src/main/java/net/Indyuce/mmocore/gui/AttributeView.java @@ -18,6 +18,8 @@ import org.bukkit.Bukkit; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.event.inventory.InventoryClickEvent; +import java.util.logging.Level; + public class AttributeView extends EditableInventory { public AttributeView() { super("attribute-view"); @@ -47,12 +49,18 @@ public class AttributeView extends EditableInventory { public static class AttributeItem extends InventoryItem { private final PlayerAttribute attribute; + private int shiftCost; public AttributeItem(String function, ConfigurationSection config) { super(config); attribute = MMOCore.plugin.attributeManager .get(function.substring("attribute_".length()).toLowerCase().replace(" ", "-").replace("_", "-")); + shiftCost = config.getInt("shift-cost"); + if (shiftCost < 1) { + MMOCore.log(Level.WARNING, "Level up points cost must not be less than 1. Using default value: 1"); + shiftCost = 1; + } } @Override @@ -66,6 +74,7 @@ public class AttributeView extends EditableInventory { holders.register("max", attribute.getMax()); holders.register("current", total); holders.register("attribute_points", inv.getPlayerData().getAttributePoints()); + holders.register("shift_points", shiftCost); attribute.getBuffs().forEach(buff -> { StatInfo info = StatInfo.valueOf(buff.getStat()); holders.register("buff_" + buff.getStat().toLowerCase(), info.format(buff.getValue())); @@ -112,6 +121,7 @@ public class AttributeView extends EditableInventory { if (item.getFunction().startsWith("attribute_")) { PlayerAttribute attribute = ((AttributeItem) item).attribute; + int shiftCost = ((AttributeItem) item).shiftCost; if (playerData.getAttributePoints() < 1) { MMOCore.plugin.configManager.getSimpleMessage("not-attribute-point").send(player); @@ -125,9 +135,21 @@ public class AttributeView extends EditableInventory { MMOCore.plugin.soundManager.getSound(SoundEvent.NOT_ENOUGH_POINTS).playTo(getPlayer()); return; } - - ins.addBase(1); - playerData.giveAttributePoints(-1); + + if (event.isShiftClick()) { + if (playerData.getAttributePoints() < shiftCost) { + MMOCore.plugin.configManager.getSimpleMessage("not-attribute-point-shift", "shift_points", "" + shiftCost).send(player); + MMOCore.plugin.soundManager.getSound(SoundEvent.NOT_ENOUGH_POINTS).playTo(getPlayer()); + return; + } + + ins.addBase(shiftCost); + playerData.giveAttributePoints(-shiftCost); + } else { + ins.addBase(1); + playerData.giveAttributePoints(-1); + } + MMOCore.plugin.configManager.getSimpleMessage("attribute-level-up", "attribute", attribute.getName(), "level", "" + ins.getBase()).send(player); MMOCore.plugin.soundManager.getSound(SoundEvent.LEVEL_ATTRIBUTE).playTo(getPlayer()); diff --git a/src/main/java/net/Indyuce/mmocore/gui/SkillList.java b/src/main/java/net/Indyuce/mmocore/gui/SkillList.java index 1699f0ef..5c611a8f 100644 --- a/src/main/java/net/Indyuce/mmocore/gui/SkillList.java +++ b/src/main/java/net/Indyuce/mmocore/gui/SkillList.java @@ -25,6 +25,7 @@ import org.bukkit.inventory.meta.ItemMeta; import java.util.ArrayList; import java.util.List; +import java.util.logging.Level; public class SkillList extends EditableInventory { public SkillList() { @@ -41,20 +42,7 @@ public class SkillList extends EditableInventory { return new LevelItem(config); if (function.equals("upgrade")) - return new InventoryItem(config) { - - @Override - public Placeholders getPlaceholders(SkillViewerInventory inv, int n) { - RegisteredSkill selected = inv.selected == null ? null : inv.selected.getSkill(); - Placeholders holders = new Placeholders(); - - holders.register("skill_caps", selected.getName().toUpperCase()); - holders.register("skill", selected.getName()); - holders.register("skill_points", "" + inv.getPlayerData().getSkillPoints()); - - return holders; - } - }; + return new UpgradeItem(config); if (function.equals("slot")) return new InventoryItem(config) { @@ -235,7 +223,34 @@ public class SkillList extends EditableInventory { return new Placeholders(); } } - + + public class UpgradeItem extends InventoryItem { + private int shiftCost; + + public UpgradeItem(ConfigurationSection config) { + super(config); + + this.shiftCost = config.getInt("shift-cost"); + if (shiftCost < 1) { + MMOCore.log(Level.WARNING, "Upgrade shift-cost cannot be less than 1. Using default value: 1"); + shiftCost = 1; + } + + } + + @Override + public Placeholders getPlaceholders(SkillViewerInventory inv, int n) { + RegisteredSkill selected = inv.selected == null ? null : inv.selected.getSkill(); + Placeholders holders = new Placeholders(); + + holders.register("skill_caps", selected.getName().toUpperCase()); + holders.register("skill", selected.getName()); + holders.register("skill_points", "" + inv.getPlayerData().getSkillPoints()); + holders.register("shift_points", shiftCost); + return holders; + } + } + public class SkillViewerInventory extends GeneratedInventory { // Cached information @@ -348,6 +363,8 @@ public class SkillList extends EditableInventory { * upgrading a player skill */ if (item.getFunction().equals("upgrade")) { + int shiftCost = ((UpgradeItem) item).shiftCost; + if (!playerData.hasSkillUnlocked(selected)) { MMOCore.plugin.configManager.getSimpleMessage("not-unlocked-skill").send(player); player.playSound(player.getLocation(), Sound.ENTITY_VILLAGER_NO, 1, 2); @@ -365,9 +382,21 @@ public class SkillList extends EditableInventory { player.playSound(player.getLocation(), Sound.ENTITY_VILLAGER_NO, 1, 2); return; } - - playerData.giveSkillPoints(-1); - playerData.setSkillLevel(selected.getSkill(), playerData.getSkillLevel(selected.getSkill()) + 1); + + if (event.isShiftClick()) { + if (playerData.getSkillPoints() < shiftCost) { + MMOCore.plugin.configManager.getSimpleMessage("not-enough-skill-points-shift", "shift_points", "" + shiftCost).send(player); + player.playSound(player.getLocation(), Sound.ENTITY_VILLAGER_NO, 1, 2); + return; + } + + playerData.giveSkillPoints(-shiftCost); + playerData.setSkillLevel(selected.getSkill(), playerData.getSkillLevel(selected.getSkill()) + shiftCost); + } else { + playerData.giveSkillPoints(-1); + playerData.setSkillLevel(selected.getSkill(), playerData.getSkillLevel(selected.getSkill()) + 1); + } + MMOCore.plugin.configManager.getSimpleMessage("upgrade-skill", "skill", selected.getSkill().getName(), "level", "" + playerData.getSkillLevel(selected.getSkill())).send(player); player.playSound(player.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1, 2); diff --git a/src/main/resources/default/gui/attribute-view.yml b/src/main/resources/default/gui/attribute-view.yml index 304eeda4..a93b8d6b 100644 --- a/src/main/resources/default/gui/attribute-view.yml +++ b/src/main/resources/default/gui/attribute-view.yml @@ -22,6 +22,7 @@ items: str: slots: [11] function: attribute_strength + shift-cost: 10 name: '&a{name}' item: GOLDEN_APPLE lore: # {buffs} returns amount of buffs @@ -34,10 +35,13 @@ items: - '&7 +{buff_max_health}% Max Health (&a+{total_max_health}&7)' - '' - '&eClick to level up for 1 attribute point.' + - '&eShift-Click to level up for {shift_points} attribute points.' + - '' - '&e◆ Current Attribute Points: {attribute_points}' dex: slots: [13] function: attribute_dexterity + shift-cost: 10 name: '&a{name}' item: LEATHER_BOOTS hide-flags: true @@ -52,10 +56,13 @@ items: - '&7 +{buff_attack_speed}% Attack Speed (&a+{total_attack_speed}&7)' - '' - '&eClick to level up for 1 attribute point.' + - '&eShift-Click to level up for {shift_points} attribute points.' + - '' - '&e◆ Current Attribute Points: {attribute_points}' int: slots: [15] function: attribute_intelligence + shift-cost: 10 name: '&a{name}' item: BOOK lore: @@ -68,4 +75,6 @@ items: - '&7 +{buff_cooldown_reduction}% Cooldown Reduction (&a+{total_cooldown_reduction}%&7)' - '' - '&eClick to level up for 1 attribute point.' + - '&eShift-Click to level up for {shift_points} attribute points.' + - '' - '&e◆ Current Attribute Points: {attribute_points}' diff --git a/src/main/resources/default/gui/skill-list.yml b/src/main/resources/default/gui/skill-list.yml index 04dc88a6..f3c5598c 100644 --- a/src/main/resources/default/gui/skill-list.yml +++ b/src/main/resources/default/gui/skill-list.yml @@ -87,9 +87,11 @@ items: upgrade: slots: [ 15 ] function: upgrade + shift-cost: 10 item: GREEN_STAINED_GLASS_PANE name: '&a&lUPGRADE {skill_caps}' lore: - '&7Costs 1 skill point.' + - '&7Shift-Click to spend {shift_points} points' - '' - '&eCurrent Skill Points: {skill_points}' diff --git a/src/main/resources/default/messages.yml b/src/main/resources/default/messages.yml index 8d1f7fb0..5ff5d69a 100644 --- a/src/main/resources/default/messages.yml +++ b/src/main/resources/default/messages.yml @@ -157,6 +157,7 @@ cant-choose-new-class: no-attribute-points-spent: '&cYou have not spent any attribute points.' not-attribute-reallocation-point: '&cYou do not have 1 reallocation point.' not-attribute-point: '&cYou do not have 1 attribute point.' +not-attribute-point-shift: '&cYou do not have &4{shift_points} &cattribute points.' attribute-points-reallocated: '&eYou successfully reset your attributes. You now have &6{points} &eattribute points.' attribute-max-points-hit: '&cYou cannot level up this attribute anymore.' attribute-level-up: '&eYou successfully leveled up your &6{attribute}&e.' # {level} @@ -164,6 +165,7 @@ attribute-level-up: '&eYou successfully leveled up your &6{attribute}&e.' # {lev # Skills no-class-skill: '&cYour class has no skill.' not-enough-skill-points: '&cYou need one skill point.' +not-enough-skill-points-shift: '&cYou need {shift_points} skill points.' 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.'