mirror of
https://gitlab.com/phoenix-dvpmt/mmocore.git
synced 2024-12-11 03:03:25 +01:00
Small code factorization
This commit is contained in:
parent
c788a88a82
commit
23f6854f79
@ -129,20 +129,8 @@ public class PlayerAttributes {
|
||||
update();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds X points to the base of the player attribute AND applies
|
||||
* the attribute experience table.
|
||||
*
|
||||
* @param value Amount of attribute points spent in the attribute
|
||||
*/
|
||||
public void addBase(int value) {
|
||||
setBase(spent + value);
|
||||
|
||||
// Apply exp table as many times as required
|
||||
final PlayerAttribute attribute = MMOCore.plugin.attributeManager.get(id);
|
||||
if (attribute.hasExperienceTable())
|
||||
while (value-- > 0)
|
||||
attribute.getExperienceTable().claim(data, spent, attribute);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -1,16 +1,16 @@
|
||||
package net.Indyuce.mmocore.gui;
|
||||
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.api.SoundEvent;
|
||||
import net.Indyuce.mmocore.api.event.PlayerAttributeUseEvent;
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
import net.Indyuce.mmocore.api.player.attribute.PlayerAttribute;
|
||||
import net.Indyuce.mmocore.api.player.attribute.PlayerAttributes;
|
||||
import net.Indyuce.mmocore.gui.api.EditableInventory;
|
||||
import net.Indyuce.mmocore.gui.api.GeneratedInventory;
|
||||
import net.Indyuce.mmocore.gui.api.item.InventoryItem;
|
||||
import net.Indyuce.mmocore.gui.api.item.SimplePlaceholderItem;
|
||||
import net.Indyuce.mmocore.api.SoundEvent;
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
import net.Indyuce.mmocore.gui.api.EditableInventory;
|
||||
import net.Indyuce.mmocore.gui.api.item.Placeholders;
|
||||
import net.Indyuce.mmocore.gui.api.item.SimplePlaceholderItem;
|
||||
import net.Indyuce.mmocore.player.stats.StatInfo;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
@ -139,6 +139,9 @@ public class AttributeView extends EditableInventory {
|
||||
return;
|
||||
}
|
||||
|
||||
// Amount of points spent
|
||||
int pointsSpent = 1;
|
||||
|
||||
if (event.isShiftClick()) {
|
||||
if (playerData.getAttributePoints() < shiftCost) {
|
||||
MMOCore.plugin.configManager.getSimpleMessage("not-attribute-point-shift", "shift_points", "" + shiftCost).send(player);
|
||||
@ -146,14 +149,18 @@ public class AttributeView extends EditableInventory {
|
||||
return;
|
||||
}
|
||||
|
||||
ins.addBase(shiftCost);
|
||||
playerData.giveAttributePoints(-shiftCost);
|
||||
} else {
|
||||
ins.addBase(1);
|
||||
playerData.giveAttributePoints(-1);
|
||||
pointsSpent = shiftCost;
|
||||
}
|
||||
|
||||
MMOCore.plugin.configManager.getSimpleMessage("attribute-level-up", "attribute", attribute.getName(), "level", "" + ins.getBase()).send(player);
|
||||
ins.addBase(pointsSpent);
|
||||
playerData.giveAttributePoints(-pointsSpent);
|
||||
|
||||
// Apply exp table as many times as required
|
||||
if (attribute.hasExperienceTable())
|
||||
while (pointsSpent-- > 0)
|
||||
attribute.getExperienceTable().claim(playerData, ins.getBase(), attribute);
|
||||
|
||||
MMOCore.plugin.configManager.getSimpleMessage("attribute-level-up", "attribute", attribute.getName(), "level", String.valueOf(ins.getBase())).send(player);
|
||||
MMOCore.plugin.soundManager.getSound(SoundEvent.LEVEL_ATTRIBUTE).playTo(getPlayer());
|
||||
|
||||
PlayerAttributeUseEvent playerAttributeUseEvent = new PlayerAttributeUseEvent(playerData, attribute);
|
||||
|
Loading…
Reference in New Issue
Block a user