Fixed attributes points spending overflow

This commit is contained in:
Indyuce 2022-07-24 22:36:38 +02:00
parent 55d1a3cf13
commit 1ac652e459
3 changed files with 13 additions and 25 deletions

View File

@ -804,12 +804,10 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc
Validate.isTrue(isCasting(), "Player not in casting mode");
skillCasting.close();
this.skillCasting = null;
setLastActivity(PlayerActivity.ACTION_BAR_MESSAGE, 0); // Reset action bar
}
public void displayActionBar(String message) {
if (!isOnline())
return;
setLastActivity(PlayerActivity.ACTION_BAR_MESSAGE);
getPlayer().spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(message));
}

View File

@ -16,8 +16,6 @@ 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,20 +45,14 @@ public class AttributeView extends EditableInventory {
public static class AttributeItem extends InventoryItem {
private final PlayerAttribute attribute;
private int shiftCost=1;
private final int shiftCost;
public AttributeItem(String function, ConfigurationSection config) {
super(config);
attribute = MMOCore.plugin.attributeManager
.get(function.substring("attribute_".length()).toLowerCase().replace(" ", "-").replace("_", "-"));
if(config.contains("shift-cost")) {
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;
}
}
shiftCost = Math.max(config.getInt("shift-cost"), 1);
}
@Override
@ -124,7 +116,6 @@ 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);
@ -140,16 +131,15 @@ public class AttributeView extends EditableInventory {
}
// Amount of points spent
int pointsSpent = 1;
final boolean shiftClick = event.isShiftClick();
int pointsSpent = shiftClick ? ((AttributeItem) item).shiftCost : 1;
if (attribute.hasMax())
pointsSpent = Math.min(pointsSpent, attribute.getMax() - ins.getBase());
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;
}
pointsSpent = shiftCost;
if (shiftClick && playerData.getAttributePoints() < pointsSpent) {
MMOCore.plugin.configManager.getSimpleMessage("not-attribute-point-shift", "shift_points", String.valueOf(pointsSpent)).send(player);
MMOCore.plugin.soundManager.getSound(SoundEvent.NOT_ENOUGH_POINTS).playTo(getPlayer());
return;
}
ins.addBase(pointsSpent);

View File

@ -156,8 +156,8 @@ cant-choose-new-class:
# Attributes
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.'
not-attribute-point: '&cYou have no attribute point.'
not-attribute-point-shift: '&cYou must 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}