Spell permission now accepts any percentage

This commit is contained in:
Auxilor 2021-04-14 12:28:52 +01:00
parent 64ae9f3de2
commit acb91725fe

View File

@ -21,6 +21,7 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.BlockInventoryHolder;
import org.bukkit.permissions.PermissionAttachmentInfo;
import org.bukkit.util.NumberConversions;
import org.jetbrains.annotations.NotNull;
@ -90,10 +91,10 @@ public abstract class Spell extends EcoEnchant {
/**
* Get a multiplier for a spell cooldown.
* <p>
* Used for perks - this should be reworked as it has hardcoded permission references.
* Used for perks..
*
* @param player The player to query.
* @return The multipiler.
* @return The multiplier.
*/
public static double getCooldownMultiplier(@NotNull final Player player) {
if (player.hasPermission("ecoenchants.cooldowntime.quarter")) {
@ -112,6 +113,18 @@ public abstract class Spell extends EcoEnchant {
return 0.75;
}
String prefix = "ecoenchants.cooldowntime.";
for (PermissionAttachmentInfo permissionAttachmentInfo : player.getEffectivePermissions()) {
String permission = permissionAttachmentInfo.getPermission();
if (permission.startsWith(prefix)) {
try {
return Double.parseDouble(permission.substring(permission.lastIndexOf(".") + 1)) / 100;
} catch (NumberFormatException e) {
return 1;
}
}
}
return 1;
}