mirror of
https://gitlab.com/phoenix-dvpmt/mmocore.git
synced 2024-11-24 00:15:16 +01:00
Option to spend multiple attribute/skill points at once by shift clicking (#423)
This commit is contained in:
parent
9996211296
commit
09ef313642
@ -18,6 +18,8 @@ import org.bukkit.Bukkit;
|
|||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||||
|
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
public class AttributeView extends EditableInventory {
|
public class AttributeView extends EditableInventory {
|
||||||
public AttributeView() {
|
public AttributeView() {
|
||||||
super("attribute-view");
|
super("attribute-view");
|
||||||
@ -47,12 +49,18 @@ public class AttributeView extends EditableInventory {
|
|||||||
|
|
||||||
public static class AttributeItem extends InventoryItem {
|
public static class AttributeItem extends InventoryItem {
|
||||||
private final PlayerAttribute attribute;
|
private final PlayerAttribute attribute;
|
||||||
|
private int shiftCost;
|
||||||
|
|
||||||
public AttributeItem(String function, ConfigurationSection config) {
|
public AttributeItem(String function, ConfigurationSection config) {
|
||||||
super(config);
|
super(config);
|
||||||
|
|
||||||
attribute = MMOCore.plugin.attributeManager
|
attribute = MMOCore.plugin.attributeManager
|
||||||
.get(function.substring("attribute_".length()).toLowerCase().replace(" ", "-").replace("_", "-"));
|
.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
|
@Override
|
||||||
@ -66,6 +74,7 @@ public class AttributeView extends EditableInventory {
|
|||||||
holders.register("max", attribute.getMax());
|
holders.register("max", attribute.getMax());
|
||||||
holders.register("current", total);
|
holders.register("current", total);
|
||||||
holders.register("attribute_points", inv.getPlayerData().getAttributePoints());
|
holders.register("attribute_points", inv.getPlayerData().getAttributePoints());
|
||||||
|
holders.register("shift_points", shiftCost);
|
||||||
attribute.getBuffs().forEach(buff -> {
|
attribute.getBuffs().forEach(buff -> {
|
||||||
StatInfo info = StatInfo.valueOf(buff.getStat());
|
StatInfo info = StatInfo.valueOf(buff.getStat());
|
||||||
holders.register("buff_" + buff.getStat().toLowerCase(), info.format(buff.getValue()));
|
holders.register("buff_" + buff.getStat().toLowerCase(), info.format(buff.getValue()));
|
||||||
@ -112,6 +121,7 @@ public class AttributeView extends EditableInventory {
|
|||||||
|
|
||||||
if (item.getFunction().startsWith("attribute_")) {
|
if (item.getFunction().startsWith("attribute_")) {
|
||||||
PlayerAttribute attribute = ((AttributeItem) item).attribute;
|
PlayerAttribute attribute = ((AttributeItem) item).attribute;
|
||||||
|
int shiftCost = ((AttributeItem) item).shiftCost;
|
||||||
|
|
||||||
if (playerData.getAttributePoints() < 1) {
|
if (playerData.getAttributePoints() < 1) {
|
||||||
MMOCore.plugin.configManager.getSimpleMessage("not-attribute-point").send(player);
|
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());
|
MMOCore.plugin.soundManager.getSound(SoundEvent.NOT_ENOUGH_POINTS).playTo(getPlayer());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ins.addBase(1);
|
if (event.isShiftClick()) {
|
||||||
playerData.giveAttributePoints(-1);
|
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.configManager.getSimpleMessage("attribute-level-up", "attribute", attribute.getName(), "level", "" + ins.getBase()).send(player);
|
||||||
MMOCore.plugin.soundManager.getSound(SoundEvent.LEVEL_ATTRIBUTE).playTo(getPlayer());
|
MMOCore.plugin.soundManager.getSound(SoundEvent.LEVEL_ATTRIBUTE).playTo(getPlayer());
|
||||||
|
|
||||||
|
@ -25,6 +25,7 @@ import org.bukkit.inventory.meta.ItemMeta;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
public class SkillList extends EditableInventory {
|
public class SkillList extends EditableInventory {
|
||||||
public SkillList() {
|
public SkillList() {
|
||||||
@ -41,20 +42,7 @@ public class SkillList extends EditableInventory {
|
|||||||
return new LevelItem(config);
|
return new LevelItem(config);
|
||||||
|
|
||||||
if (function.equals("upgrade"))
|
if (function.equals("upgrade"))
|
||||||
return new InventoryItem<SkillViewerInventory>(config) {
|
return new UpgradeItem(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;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
if (function.equals("slot"))
|
if (function.equals("slot"))
|
||||||
return new InventoryItem<SkillViewerInventory>(config) {
|
return new InventoryItem<SkillViewerInventory>(config) {
|
||||||
@ -235,7 +223,34 @@ public class SkillList extends EditableInventory {
|
|||||||
return new Placeholders();
|
return new Placeholders();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class UpgradeItem extends InventoryItem<SkillViewerInventory> {
|
||||||
|
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 {
|
public class SkillViewerInventory extends GeneratedInventory {
|
||||||
|
|
||||||
// Cached information
|
// Cached information
|
||||||
@ -348,6 +363,8 @@ public class SkillList extends EditableInventory {
|
|||||||
* upgrading a player skill
|
* upgrading a player skill
|
||||||
*/
|
*/
|
||||||
if (item.getFunction().equals("upgrade")) {
|
if (item.getFunction().equals("upgrade")) {
|
||||||
|
int shiftCost = ((UpgradeItem) item).shiftCost;
|
||||||
|
|
||||||
if (!playerData.hasSkillUnlocked(selected)) {
|
if (!playerData.hasSkillUnlocked(selected)) {
|
||||||
MMOCore.plugin.configManager.getSimpleMessage("not-unlocked-skill").send(player);
|
MMOCore.plugin.configManager.getSimpleMessage("not-unlocked-skill").send(player);
|
||||||
player.playSound(player.getLocation(), Sound.ENTITY_VILLAGER_NO, 1, 2);
|
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);
|
player.playSound(player.getLocation(), Sound.ENTITY_VILLAGER_NO, 1, 2);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
playerData.giveSkillPoints(-1);
|
if (event.isShiftClick()) {
|
||||||
playerData.setSkillLevel(selected.getSkill(), playerData.getSkillLevel(selected.getSkill()) + 1);
|
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",
|
MMOCore.plugin.configManager.getSimpleMessage("upgrade-skill", "skill", selected.getSkill().getName(), "level",
|
||||||
"" + playerData.getSkillLevel(selected.getSkill())).send(player);
|
"" + playerData.getSkillLevel(selected.getSkill())).send(player);
|
||||||
player.playSound(player.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1, 2);
|
player.playSound(player.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1, 2);
|
||||||
|
@ -22,6 +22,7 @@ items:
|
|||||||
str:
|
str:
|
||||||
slots: [11]
|
slots: [11]
|
||||||
function: attribute_strength
|
function: attribute_strength
|
||||||
|
shift-cost: 10
|
||||||
name: '&a{name}'
|
name: '&a{name}'
|
||||||
item: GOLDEN_APPLE
|
item: GOLDEN_APPLE
|
||||||
lore: # {buffs} returns amount of buffs
|
lore: # {buffs} returns amount of buffs
|
||||||
@ -34,10 +35,13 @@ items:
|
|||||||
- '&7 +{buff_max_health}% Max Health (&a+{total_max_health}&7)'
|
- '&7 +{buff_max_health}% Max Health (&a+{total_max_health}&7)'
|
||||||
- ''
|
- ''
|
||||||
- '&eClick to level up for 1 attribute point.'
|
- '&eClick to level up for 1 attribute point.'
|
||||||
|
- '&eShift-Click to level up for {shift_points} attribute points.'
|
||||||
|
- ''
|
||||||
- '&e◆ Current Attribute Points: {attribute_points}'
|
- '&e◆ Current Attribute Points: {attribute_points}'
|
||||||
dex:
|
dex:
|
||||||
slots: [13]
|
slots: [13]
|
||||||
function: attribute_dexterity
|
function: attribute_dexterity
|
||||||
|
shift-cost: 10
|
||||||
name: '&a{name}'
|
name: '&a{name}'
|
||||||
item: LEATHER_BOOTS
|
item: LEATHER_BOOTS
|
||||||
hide-flags: true
|
hide-flags: true
|
||||||
@ -52,10 +56,13 @@ items:
|
|||||||
- '&7 +{buff_attack_speed}% Attack Speed (&a+{total_attack_speed}&7)'
|
- '&7 +{buff_attack_speed}% Attack Speed (&a+{total_attack_speed}&7)'
|
||||||
- ''
|
- ''
|
||||||
- '&eClick to level up for 1 attribute point.'
|
- '&eClick to level up for 1 attribute point.'
|
||||||
|
- '&eShift-Click to level up for {shift_points} attribute points.'
|
||||||
|
- ''
|
||||||
- '&e◆ Current Attribute Points: {attribute_points}'
|
- '&e◆ Current Attribute Points: {attribute_points}'
|
||||||
int:
|
int:
|
||||||
slots: [15]
|
slots: [15]
|
||||||
function: attribute_intelligence
|
function: attribute_intelligence
|
||||||
|
shift-cost: 10
|
||||||
name: '&a{name}'
|
name: '&a{name}'
|
||||||
item: BOOK
|
item: BOOK
|
||||||
lore:
|
lore:
|
||||||
@ -68,4 +75,6 @@ items:
|
|||||||
- '&7 +{buff_cooldown_reduction}% Cooldown Reduction (&a+{total_cooldown_reduction}%&7)'
|
- '&7 +{buff_cooldown_reduction}% Cooldown Reduction (&a+{total_cooldown_reduction}%&7)'
|
||||||
- ''
|
- ''
|
||||||
- '&eClick to level up for 1 attribute point.'
|
- '&eClick to level up for 1 attribute point.'
|
||||||
|
- '&eShift-Click to level up for {shift_points} attribute points.'
|
||||||
|
- ''
|
||||||
- '&e◆ Current Attribute Points: {attribute_points}'
|
- '&e◆ Current Attribute Points: {attribute_points}'
|
||||||
|
@ -87,9 +87,11 @@ items:
|
|||||||
upgrade:
|
upgrade:
|
||||||
slots: [ 15 ]
|
slots: [ 15 ]
|
||||||
function: upgrade
|
function: upgrade
|
||||||
|
shift-cost: 10
|
||||||
item: GREEN_STAINED_GLASS_PANE
|
item: GREEN_STAINED_GLASS_PANE
|
||||||
name: '&a&lUPGRADE {skill_caps}'
|
name: '&a&lUPGRADE {skill_caps}'
|
||||||
lore:
|
lore:
|
||||||
- '&7Costs 1 skill point.'
|
- '&7Costs 1 skill point.'
|
||||||
|
- '&7Shift-Click to spend {shift_points} points'
|
||||||
- ''
|
- ''
|
||||||
- '&eCurrent Skill Points: {skill_points}'
|
- '&eCurrent Skill Points: {skill_points}'
|
||||||
|
@ -157,6 +157,7 @@ cant-choose-new-class:
|
|||||||
no-attribute-points-spent: '&cYou have not spent any attribute points.'
|
no-attribute-points-spent: '&cYou have not spent any attribute points.'
|
||||||
not-attribute-reallocation-point: '&cYou do not have 1 reallocation point.'
|
not-attribute-reallocation-point: '&cYou do not have 1 reallocation point.'
|
||||||
not-attribute-point: '&cYou do not have 1 attribute 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-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-max-points-hit: '&cYou cannot level up this attribute anymore.'
|
||||||
attribute-level-up: '&eYou successfully leveled up your &6{attribute}&e.' # {level}
|
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
|
# Skills
|
||||||
no-class-skill: '&cYour class has no skill.'
|
no-class-skill: '&cYour class has no skill.'
|
||||||
not-enough-skill-points: '&cYou need one skill point.'
|
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!'
|
upgrade-skill: '&eYour &6{skill} &eis now Level &6{level}&e!'
|
||||||
not-unlocked-skill: '&cYou have not unlocked that skill yet.'
|
not-unlocked-skill: '&cYou have not unlocked that skill yet.'
|
||||||
no-skill-bound: '&cYou don''t have any skill bound to this slot.'
|
no-skill-bound: '&cYou don''t have any skill bound to this slot.'
|
||||||
|
Loading…
Reference in New Issue
Block a user