mirror of
https://gitlab.com/phoenix-dvpmt/mmoitems.git
synced 2025-01-03 06:37:47 +01:00
Merge branch '1015-mana-cost-30-0-not-working-properly-on-consumable' into 'master'
Mana cost stat implemented See merge request phoenix-dvpmt/mmoitems!25
This commit is contained in:
commit
b7ba87b58d
@ -70,7 +70,7 @@ public class ItemStats {
|
||||
PARRY_COOLDOWN_REDUCTION = new DoubleStat("PARRY_COOLDOWN_REDUCTION", Material.BUCKET, "Parry Cooldown Reduction", new String[]{"Reduces the parrying cooldown (%)."}, new String[]{"!miscellaneous", "!block", "all"}),
|
||||
COOLDOWN_REDUCTION = new DoubleStat("COOLDOWN_REDUCTION", Material.BOOK, "Cooldown Reduction", new String[]{"Reduces cooldowns of item and player skills (%)."}),
|
||||
RANGE = new DoubleStat("RANGE", Material.STICK, "Range", new String[]{"The range of your item attacks."}, new String[]{"staff", "whip", "wand", "musket"}),
|
||||
MANA_COST = new DoubleStat("MANA_COST", VersionMaterial.LAPIS_LAZULI.toMaterial(), "Mana Cost", new String[]{"Mana spent by your weapon to be used."}, new String[]{"piercing", "slashing", "blunt", "range"}),
|
||||
MANA_COST = new ManaCost(),
|
||||
STAMINA_COST = new DoubleStat("STAMINA_COST", VersionMaterial.LIGHT_GRAY_DYE.toMaterial(), "Stamina Cost", new String[]{"Stamina spent by your weapon to be used."}, new String[]{"piercing", "slashing", "blunt", "range"}),
|
||||
ARROW_VELOCITY = new DoubleStat("ARROW_VELOCITY", Material.ARROW, "Arrow Velocity", new String[]{"Determines how far your", "weapon can shoot.", "Default: 1.0"}, new String[]{"gem_stone", "bow", "crossbow"}),
|
||||
ARROW_POTION_EFFECTS = new ArrowPotionEffects(),
|
||||
|
@ -0,0 +1,55 @@
|
||||
package net.Indyuce.mmoitems.stat;
|
||||
|
||||
import io.lumine.mythic.lib.api.item.NBTItem;
|
||||
import io.lumine.mythic.lib.version.VersionMaterial;
|
||||
import net.Indyuce.mmoitems.ItemStats;
|
||||
import net.Indyuce.mmoitems.api.item.mmoitem.VolatileMMOItem;
|
||||
import net.Indyuce.mmoitems.api.player.PlayerData;
|
||||
import net.Indyuce.mmoitems.api.player.RPGPlayer;
|
||||
import net.Indyuce.mmoitems.api.util.message.Message;
|
||||
import net.Indyuce.mmoitems.stat.data.DoubleData;
|
||||
import net.Indyuce.mmoitems.stat.type.DoubleStat;
|
||||
import net.Indyuce.mmoitems.stat.type.ItemRestriction;
|
||||
import net.Indyuce.mmoitems.stat.type.PlayerConsumable;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* mmoitems
|
||||
*
|
||||
* @author Roch Blondiaux
|
||||
* @date 24/10/2022
|
||||
*/
|
||||
public class ManaCost extends DoubleStat implements ItemRestriction, PlayerConsumable {
|
||||
|
||||
public ManaCost() {
|
||||
super("MANA_COST", VersionMaterial.LAPIS_LAZULI.toMaterial(), "Mana Cost", new String[]{"Mana spent by your weapon to be used."}, new String[]{"piercing", "slashing", "blunt", "range"});
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean canUse(RPGPlayer player, NBTItem item, boolean message) {
|
||||
// No data no service
|
||||
if (!item.hasTag(ItemStats.MANA_COST.getNBTPath()))
|
||||
return true;
|
||||
double manaCost = item.getDouble(ItemStats.MANA_COST.getNBTPath());
|
||||
boolean hasMana = manaCost > 0 && player.getMana() >= manaCost;
|
||||
if (!hasMana)
|
||||
Message.NOT_ENOUGH_MANA.format(ChatColor.RED).send(player.getPlayer());
|
||||
return hasMana;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConsume(@NotNull VolatileMMOItem mmo, @NotNull Player player, boolean vanillaEating) {
|
||||
// No data no service
|
||||
if (!mmo.hasData(ItemStats.MANA_COST)) return;
|
||||
|
||||
// Get value
|
||||
DoubleData d = (DoubleData) mmo.getData(ItemStats.MANA_COST);
|
||||
if (d.getValue() > 0) {
|
||||
final RPGPlayer rpgPlayer = PlayerData.get(player).getRPG();
|
||||
rpgPlayer.setMana(rpgPlayer.getMana() - d.getValue());
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user