Added isFullyChargedIfRequired to enchantments

This commit is contained in:
Auxilor 2021-03-04 18:33:32 +00:00
parent fe5e243b86
commit d5d1250540
23 changed files with 55 additions and 87 deletions

View File

@ -1,10 +1,9 @@
package com.willfp.ecoenchants.enchantments.ecoenchants.normal;
import com.willfp.eco.util.DurabilityUtils;
import com.willfp.eco.util.PlayerUtils;
import com.willfp.ecoenchants.enchantments.EcoEnchant;
import com.willfp.ecoenchants.enchantments.EcoEnchants;
import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
@ -30,8 +29,7 @@ public class Abrasion extends EcoEnchant {
}
Player victim = (Player) uncastVictim;
boolean notcharged = this.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "allow-not-fully-charged");
if (attacker instanceof Player && PlayerUtils.getAttackCooldown((Player) attacker) != 1.0f && !notcharged) {
if (!EnchantmentUtils.isFullyChargeIfRequired(this, attacker)) {
return;
}

View File

@ -24,9 +24,7 @@ public class Bleed extends EcoEnchant {
@NotNull final LivingEntity victim,
final int level,
@NotNull final EntityDamageByEntityEvent event) {
if (attacker instanceof Player
&& PlayerUtils.getAttackCooldown((Player) attacker) != 1.0f
&& !this.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "allow-not-fully-charged")) {
if (!EnchantmentUtils.isFullyChargeIfRequired(this, attacker)) {
return;
}

View File

@ -1,11 +1,10 @@
package com.willfp.ecoenchants.enchantments.ecoenchants.normal;
import com.willfp.eco.util.PlayerUtils;
import com.willfp.ecoenchants.enchantments.EcoEnchant;
import com.willfp.ecoenchants.enchantments.EcoEnchants;
import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.jetbrains.annotations.NotNull;
@ -24,9 +23,7 @@ public class Cleave extends EcoEnchant {
return;
}
if (attacker instanceof Player
&& PlayerUtils.getAttackCooldown((Player) attacker) != 1.0f
&& !this.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "allow-not-fully-charged")) {
if (!EnchantmentUtils.isFullyChargeIfRequired(this, attacker)) {
return;
}

View File

@ -24,9 +24,7 @@ public class Disable extends EcoEnchant {
@NotNull final LivingEntity victim,
final int level,
@NotNull final EntityDamageByEntityEvent event) {
if (attacker instanceof Player
&& PlayerUtils.getAttackCooldown((Player) attacker) != 1.0f
&& !this.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "allow-not-fully-charged")) {
if (!EnchantmentUtils.isFullyChargeIfRequired(this, attacker)) {
return;
}

View File

@ -1,12 +1,10 @@
package com.willfp.ecoenchants.enchantments.ecoenchants.normal;
import com.willfp.eco.util.PlayerUtils;
import com.willfp.ecoenchants.enchantments.EcoEnchant;
import com.willfp.ecoenchants.enchantments.EcoEnchants;
import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
@ -23,9 +21,7 @@ public class Dullness extends EcoEnchant {
@NotNull final LivingEntity victim,
final int level,
@NotNull final EntityDamageByEntityEvent event) {
if (attacker instanceof Player
&& PlayerUtils.getAttackCooldown((Player) attacker) != 1.0f
&& !this.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "allow-not-fully-charged")) {
if (!EnchantmentUtils.isFullyChargeIfRequired(this, attacker)) {
return;
}

View File

@ -1,12 +1,9 @@
package com.willfp.ecoenchants.enchantments.ecoenchants.normal;
import com.willfp.eco.util.PlayerUtils;
import com.willfp.ecoenchants.enchantments.EcoEnchant;
import com.willfp.ecoenchants.enchantments.EcoEnchants;
import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
@ -24,9 +21,7 @@ public class Famine extends EcoEnchant {
@NotNull final LivingEntity victim,
final int level,
@NotNull final EntityDamageByEntityEvent event) {
if (attacker instanceof Player
&& PlayerUtils.getAttackCooldown((Player) attacker) != 1.0f
&& !this.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "allow-not-fully-charged")) {
if (!EnchantmentUtils.isFullyChargeIfRequired(this, attacker)) {
return;
}

View File

@ -26,9 +26,7 @@ public class Fury extends EcoEnchant {
@NotNull final LivingEntity victim,
final int level,
@NotNull final EntityDamageByEntityEvent event) {
if (attacker instanceof Player
&& PlayerUtils.getAttackCooldown((Player) attacker) != 1.0f
&& !this.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "allow-not-fully-charged")) {
if (!EnchantmentUtils.isFullyChargeIfRequired(this, attacker)) {
return;
}

View File

@ -24,9 +24,7 @@ public class IllusionAspect extends EcoEnchant {
@NotNull final LivingEntity victim,
final int level,
@NotNull final EntityDamageByEntityEvent event) {
if (attacker instanceof Player
&& PlayerUtils.getAttackCooldown((Player) attacker) != 1.0f
&& !this.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "allow-not-fully-charged")) {
if (!EnchantmentUtils.isFullyChargeIfRequired(this, attacker)) {
return;
}

View File

@ -1,12 +1,11 @@
package com.willfp.ecoenchants.enchantments.ecoenchants.normal;
import com.willfp.eco.util.PlayerUtils;
import com.willfp.ecoenchants.enchantments.EcoEnchant;
import com.willfp.ecoenchants.enchantments.EcoEnchants;
import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils;
import org.bukkit.attribute.Attribute;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.jetbrains.annotations.NotNull;
@ -22,9 +21,7 @@ public class Leeching extends EcoEnchant {
@NotNull final LivingEntity victim,
final int level,
@NotNull final EntityDamageByEntityEvent event) {
if (attacker instanceof Player
&& PlayerUtils.getAttackCooldown((Player) attacker) != 1.0f
&& !this.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "allow-not-fully-charged")) {
if (!EnchantmentUtils.isFullyChargeIfRequired(this, attacker)) {
return;
}

View File

@ -24,9 +24,7 @@ public class StrayAspect extends EcoEnchant {
@NotNull final LivingEntity victim,
final int level,
@NotNull final EntityDamageByEntityEvent event) {
if (attacker instanceof Player
&& PlayerUtils.getAttackCooldown((Player) attacker) != 1.0f
&& !this.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "allow-not-fully-charged")) {
if (!EnchantmentUtils.isFullyChargeIfRequired(this, attacker)) {
return;
}

View File

@ -22,9 +22,7 @@ public class Supercritical extends EcoEnchant {
@NotNull final LivingEntity victim,
final int level,
@NotNull final EntityDamageByEntityEvent event) {
if (attacker instanceof Player
&& PlayerUtils.getAttackCooldown((Player) attacker) != 1.0f
&& !this.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "allow-not-fully-charged")) {
if (!EnchantmentUtils.isFullyChargeIfRequired(this, attacker)) {
return;
}

View File

@ -23,9 +23,7 @@ public class Thor extends EcoEnchant {
@NotNull final LivingEntity victim,
final int level,
@NotNull final EntityDamageByEntityEvent event) {
if (attacker instanceof Player
&& PlayerUtils.getAttackCooldown((Player) attacker) != 1.0f
&& !this.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "allow-not-fully-charged")) {
if (!EnchantmentUtils.isFullyChargeIfRequired(this, attacker)) {
return;
}

View File

@ -24,9 +24,7 @@ public class Toxic extends EcoEnchant {
@NotNull final LivingEntity victim,
final int level,
@NotNull final EntityDamageByEntityEvent event) {
if (attacker instanceof Player
&& PlayerUtils.getAttackCooldown((Player) attacker) != 1.0f
&& !this.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "allow-not-fully-charged")) {
if (!EnchantmentUtils.isFullyChargeIfRequired(this, attacker)) {
return;
}

View File

@ -1,12 +1,9 @@
package com.willfp.ecoenchants.enchantments.ecoenchants.normal;
import com.willfp.eco.util.PlayerUtils;
import com.willfp.ecoenchants.enchantments.EcoEnchant;
import com.willfp.ecoenchants.enchantments.EcoEnchants;
import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
@ -24,9 +21,7 @@ public class VampireAspect extends EcoEnchant {
@NotNull final LivingEntity victim,
final int level,
@NotNull final EntityDamageByEntityEvent event) {
if (attacker instanceof Player
&& PlayerUtils.getAttackCooldown((Player) attacker) != 1.0f
&& !this.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "allow-not-fully-charged")) {
if (!EnchantmentUtils.isFullyChargeIfRequired(this, attacker)) {
return;
}

View File

@ -23,9 +23,7 @@ public class Bolt extends EcoEnchant {
@NotNull final LivingEntity victim,
final int level,
@NotNull final EntityDamageByEntityEvent event) {
if (attacker instanceof Player
&& PlayerUtils.getAttackCooldown((Player) attacker) != 1.0f
&& !this.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "allow-not-fully-charged")) {
if (!EnchantmentUtils.isFullyChargeIfRequired(this, attacker)) {
return;
}
if (!EnchantmentUtils.passedChance(this, level)) {

View File

@ -1,11 +1,10 @@
package com.willfp.ecoenchants.enchantments.ecoenchants.special;
import com.willfp.eco.util.PlayerUtils;
import com.willfp.ecoenchants.enchantments.EcoEnchant;
import com.willfp.ecoenchants.enchantments.EcoEnchants;
import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.jetbrains.annotations.NotNull;
@ -30,9 +29,7 @@ public class Carve extends EcoEnchant {
final double damage = damagePerLevel * level * event.getDamage();
final double radius = radiusPerLevel * level;
if (attacker instanceof Player
&& PlayerUtils.getAttackCooldown((Player) attacker) != 1.0
&& !this.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "allow-not-fully-charged")) {
if (!EnchantmentUtils.isFullyChargeIfRequired(this, attacker)) {
return;
}

View File

@ -31,9 +31,7 @@ public class Confusion extends EcoEnchant {
}
Player victim = (Player) uncastVictim;
if (attacker instanceof Player
&& PlayerUtils.getAttackCooldown((Player) attacker) != 1.0f
&& !this.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "allow-not-fully-charged")) {
if (!EnchantmentUtils.isFullyChargeIfRequired(this, attacker)) {
return;
}

View File

@ -1,12 +1,11 @@
package com.willfp.ecoenchants.enchantments.ecoenchants.special;
import com.willfp.eco.util.PlayerUtils;
import com.willfp.ecoenchants.enchantments.EcoEnchant;
import com.willfp.ecoenchants.enchantments.EcoEnchants;
import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils;
import org.bukkit.attribute.Attribute;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.jetbrains.annotations.NotNull;
@ -22,9 +21,7 @@ public class LifeSteal extends EcoEnchant {
@NotNull final LivingEntity victim,
final int level,
@NotNull final EntityDamageByEntityEvent event) {
if (attacker instanceof Player
&& PlayerUtils.getAttackCooldown((Player) attacker) != 1.0f
&& !this.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "allow-not-fully-charged")) {
if (!EnchantmentUtils.isFullyChargeIfRequired(this, attacker)) {
return;
}

View File

@ -1,6 +1,5 @@
package com.willfp.ecoenchants.enchantments.ecoenchants.special;
import com.willfp.eco.util.PlayerUtils;
import com.willfp.eco.util.integrations.antigrief.AntigriefManager;
import com.willfp.ecoenchants.enchantments.EcoEnchant;
import com.willfp.ecoenchants.enchantments.EcoEnchants;
@ -30,8 +29,7 @@ public class Volatile extends EcoEnchant {
Player attacker = (Player) uncastAttacker;
if (PlayerUtils.getAttackCooldown(attacker) != 1.0f
&& !this.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "allow-not-fully-charged")) {
if (!EnchantmentUtils.isFullyChargeIfRequired(this, attacker)) {
return;
}

View File

@ -2,6 +2,7 @@ package com.willfp.ecoenchants.enchantments.util;
import com.willfp.eco.util.NumberUtils;
import com.willfp.eco.util.PlayerUtils;
import com.willfp.eco.util.StringUtils;
import com.willfp.eco.util.integrations.placeholder.PlaceholderEntry;
import com.willfp.eco.util.integrations.placeholder.PlaceholderManager;
@ -9,6 +10,8 @@ import com.willfp.ecoenchants.enchantments.EcoEnchant;
import com.willfp.ecoenchants.enchantments.EcoEnchants;
import com.willfp.ecoenchants.enchantments.itemtypes.Spell;
import lombok.experimental.UtilityClass;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
@UtilityClass
@ -25,6 +28,24 @@ public class EnchantmentUtils {
return NumberUtils.randFloat(0, 1) < ((enchantment.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "chance-per-level") * level) / 100);
}
/**
* If attack was fully charged if required.
*
* @param enchantment The enchantment.
* @param entity The attacker.
* @return If was fully charged.
*/
public static boolean isFullyChargeIfRequired(@NotNull final EcoEnchant enchantment,
@NotNull final LivingEntity entity) {
if (entity instanceof Player) {
if (PlayerUtils.getAttackCooldown((Player) enchantment) != 1.0f) {
return enchantment.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "allow-not-fully-charged");
}
}
return true;
}
/**
* Register the placeholders for an enchantment.
*

View File

@ -1,8 +1,8 @@
package com.willfp.ecoenchants.mmo.enchants.mana;
import com.willfp.eco.util.PlayerUtils;
import com.willfp.ecoenchants.enchantments.EcoEnchants;
import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils;
import com.willfp.ecoenchants.mmo.integrations.mmo.MMOManager;
import com.willfp.ecoenchants.mmo.structure.MMOEnchantment;
import org.bukkit.entity.LivingEntity;
@ -22,9 +22,9 @@ public class Elixir extends MMOEnchantment {
Player pAttacker = (Player) attacker;
Player pVictim = (Player) victim;
boolean notcharged = this.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "allow-not-fully-charged");
if (PlayerUtils.getAttackCooldown(pAttacker) != 1.0f && !notcharged)
if (!EnchantmentUtils.isFullyChargeIfRequired(this, attacker)) {
return;
}
double victimMana = MMOManager.getMana(pVictim);

View File

@ -1,8 +1,8 @@
package com.willfp.ecoenchants.mmo.enchants.stamina;
import com.willfp.eco.util.PlayerUtils;
import com.willfp.ecoenchants.enchantments.EcoEnchants;
import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils;
import com.willfp.ecoenchants.mmo.integrations.mmo.MMOManager;
import com.willfp.ecoenchants.mmo.structure.MMOEnchantment;
import org.bukkit.entity.LivingEntity;
@ -22,9 +22,9 @@ public class Motivate extends MMOEnchantment {
Player pAttacker = (Player) attacker;
Player pVictim = (Player) victim;
boolean notcharged = this.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "allow-not-fully-charged");
if (PlayerUtils.getAttackCooldown(pVictim) != 1.0f && !notcharged)
if (!EnchantmentUtils.isFullyChargeIfRequired(this, attacker)) {
return;
}
double victimStamina = MMOManager.getStamina(pVictim);

View File

@ -1,7 +1,6 @@
package com.willfp.ecoenchants.summoning;
import com.willfp.eco.util.NumberUtils;
import com.willfp.eco.util.PlayerUtils;
import com.willfp.eco.util.optional.Prerequisite;
import com.willfp.ecoenchants.enchantments.EcoEnchant;
import com.willfp.ecoenchants.enchantments.EcoEnchants;
@ -14,7 +13,6 @@ import org.bukkit.entity.Arrow;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Mob;
import org.bukkit.entity.Player;
import org.bukkit.entity.Trident;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
@ -78,11 +76,10 @@ public abstract class SummoningEnchantment extends EcoEnchant {
private void doSpawn(@NotNull final LivingEntity attacker,
@NotNull final LivingEntity victim,
final int level) {
if (summoningType.equals(SummoningType.MELEE)
&& attacker instanceof Player && PlayerUtils.getAttackCooldown((Player) attacker) != 1.0f
&& !this.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "allow-not-fully-charged")) {
return;
if (summoningType.equals(SummoningType.MELEE)) {
if (EnchantmentUtils.isFullyChargeIfRequired(this, attacker)) {
return;
}
}
if (!EnchantmentUtils.passedChance(this, level)) {