Added %mmoitems_stat_defense_percent% placeholder

Updated lib.
This commit is contained in:
Ethan 2020-07-26 02:46:47 -04:00
parent f76e93b5bb
commit 81403fe77d
2 changed files with 7 additions and 0 deletions

Binary file not shown.

View File

@ -2,6 +2,8 @@ package net.Indyuce.mmoitems.comp.parse.placeholders;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import net.mmogroup.mmolib.api.player.MMOPlayerData;
import net.mmogroup.mmolib.listener.DamageReduction;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@ -33,12 +35,17 @@ public class MMOItemsPlaceholders extends PlaceholderExpansion {
} }
public String onPlaceholderRequest(Player player, String identifier) { public String onPlaceholderRequest(Player player, String identifier) {
// registering before identifier.startsWith("stat_") to prevent issues
// i don't register it in the starts with condition because it will mess with substring
if (identifier.equals("stat_defense_percent"))
return twoDigits.format(new DamageReduction.DefenseCalculator(MMOPlayerData.get(player)).getReductionPercent()) + "%";
if (identifier.startsWith("stat_")) { if (identifier.startsWith("stat_")) {
ItemStat stat = MMOItems.plugin.getStats().get(identifier.substring(5).toUpperCase()); ItemStat stat = MMOItems.plugin.getStats().get(identifier.substring(5).toUpperCase());
if (stat != null) if (stat != null)
return twoDigits.format(PlayerData.get(player).getStats().getStat(stat)); return twoDigits.format(PlayerData.get(player).getStats().getStat(stat));
} }
if (identifier.startsWith("ability_cd_")) { if (identifier.startsWith("ability_cd_")) {
PlayerData data = PlayerData.get(player); PlayerData data = PlayerData.get(player);
return data.hasCooldownInfo(identifier.substring(11)) ? oneDigit.format(data.getCooldownInfo(identifier.substring(11)).getRemaining()) return data.hasCooldownInfo(identifier.substring(11)) ? oneDigit.format(data.getCooldownInfo(identifier.substring(11)).getRemaining())