mirror of
https://github.com/Auxilor/EcoEnchants.git
synced 2025-02-16 04:31:22 +01:00
Reworked Thrive and Prosperity to use attribute modifiers
This commit is contained in:
parent
d5d1250540
commit
aec9de30c2
@ -6,52 +6,58 @@ import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
|||||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
|
import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
|
||||||
import com.willfp.ecoenchants.enchantments.util.EnchantChecks;
|
import com.willfp.ecoenchants.enchantments.util.EnchantChecks;
|
||||||
import org.bukkit.attribute.Attribute;
|
import org.bukkit.attribute.Attribute;
|
||||||
|
import org.bukkit.attribute.AttributeInstance;
|
||||||
|
import org.bukkit.attribute.AttributeModifier;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.potion.PotionEffect;
|
import org.bukkit.potion.PotionEffect;
|
||||||
import org.bukkit.potion.PotionEffectType;
|
import org.bukkit.potion.PotionEffectType;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
public class Thrive extends EcoEnchant {
|
public class Thrive extends EcoEnchant {
|
||||||
|
private final AttributeModifier modifier = new AttributeModifier(UUID.nameUUIDFromBytes("thrive".getBytes()), this.getKey().getKey(), 1, AttributeModifier.Operation.ADD_NUMBER);
|
||||||
|
|
||||||
public Thrive() {
|
public Thrive() {
|
||||||
super(
|
super(
|
||||||
"thrive", EnchantmentType.NORMAL
|
"thrive", EnchantmentType.NORMAL
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onArmorEquip(@NotNull final ArmorEquipEvent event) {
|
public void onArmorEquip(@NotNull final ArmorEquipEvent event) {
|
||||||
final Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
|
|
||||||
this.getPlugin().getScheduler().runLater(() -> {
|
this.getPlugin().getScheduler().runLater(() -> {
|
||||||
int totalProsperityPoints = EnchantChecks.getArmorPoints(player, EcoEnchants.PROSPERITY, 0);
|
int points = EnchantChecks.getArmorPoints(player, this);
|
||||||
int totalThrivePoints = EnchantChecks.getArmorPoints(player, EcoEnchants.THRIVE, 0);
|
|
||||||
|
|
||||||
if (totalThrivePoints == 0 && totalProsperityPoints == 0) {
|
AttributeInstance inst = player.getAttribute(Attribute.GENERIC_MAX_HEALTH);
|
||||||
player.getAttribute(Attribute.GENERIC_MAX_HEALTH).setBaseValue(player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getDefaultValue());
|
|
||||||
return;
|
assert inst != null;
|
||||||
|
|
||||||
|
if (this.getDisabledWorlds().contains(player.getWorld())) {
|
||||||
|
points = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (EcoEnchants.THRIVE.getDisabledWorlds().contains(player.getWorld())) {
|
inst.removeModifier(modifier);
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
double thriveBonus = totalThrivePoints * EcoEnchants.THRIVE.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "health-per-point");
|
if (player.getHealth() >= inst.getValue()) {
|
||||||
double prosperityBonus = totalProsperityPoints * EcoEnchants.PROSPERITY.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "health-per-point");
|
this.getPlugin().getScheduler().runLater(() -> {
|
||||||
double bonus = thriveBonus + prosperityBonus;
|
|
||||||
|
|
||||||
boolean onMaxHealth = false;
|
|
||||||
|
|
||||||
if (player.getHealth() == player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()) {
|
|
||||||
onMaxHealth = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
player.getAttribute(Attribute.GENERIC_MAX_HEALTH).setBaseValue(player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getDefaultValue() + bonus);
|
|
||||||
boolean finalOnMaxHealth = onMaxHealth;
|
|
||||||
this.getPlugin().getScheduler().runLater(() -> {
|
|
||||||
if (finalOnMaxHealth) {
|
|
||||||
player.addPotionEffect(new PotionEffect(PotionEffectType.HEAL, 1, 255, false, false, false));
|
player.addPotionEffect(new PotionEffect(PotionEffectType.HEAL, 1, 255, false, false, false));
|
||||||
}
|
}, 1);
|
||||||
}, 1);
|
}
|
||||||
|
|
||||||
|
if (points > 0) {
|
||||||
|
inst.addModifier(
|
||||||
|
new AttributeModifier(
|
||||||
|
UUID.nameUUIDFromBytes("prosperity".getBytes()),
|
||||||
|
this.getKey().getKey(),
|
||||||
|
this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "health-per-point") * points,
|
||||||
|
AttributeModifier.Operation.ADD_NUMBER
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
}, 1);
|
}, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,63 @@
|
|||||||
package com.willfp.ecoenchants.enchantments.ecoenchants.special;
|
package com.willfp.ecoenchants.enchantments.ecoenchants.special;
|
||||||
|
|
||||||
|
import com.willfp.eco.util.events.armorequip.ArmorEquipEvent;
|
||||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||||
|
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
|
import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
|
||||||
|
import com.willfp.ecoenchants.enchantments.util.EnchantChecks;
|
||||||
|
import org.bukkit.attribute.Attribute;
|
||||||
|
import org.bukkit.attribute.AttributeInstance;
|
||||||
|
import org.bukkit.attribute.AttributeModifier;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.potion.PotionEffect;
|
||||||
|
import org.bukkit.potion.PotionEffectType;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
public class Prosperity extends EcoEnchant {
|
public class Prosperity extends EcoEnchant {
|
||||||
|
private final AttributeModifier modifier = new AttributeModifier(UUID.nameUUIDFromBytes("prosperity".getBytes()), this.getKey().getKey(), 1, AttributeModifier.Operation.ADD_NUMBER);
|
||||||
|
|
||||||
public Prosperity() {
|
public Prosperity() {
|
||||||
super(
|
super(
|
||||||
"prosperity", EnchantmentType.SPECIAL
|
"prosperity", EnchantmentType.SPECIAL
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prosperity listeners are located in Thrive
|
@EventHandler
|
||||||
|
public void onArmorEquip(@NotNull final ArmorEquipEvent event) {
|
||||||
|
Player player = event.getPlayer();
|
||||||
|
|
||||||
|
this.getPlugin().getScheduler().runLater(() -> {
|
||||||
|
int points = EnchantChecks.getArmorPoints(player, this);
|
||||||
|
|
||||||
|
AttributeInstance inst = player.getAttribute(Attribute.GENERIC_MAX_HEALTH);
|
||||||
|
|
||||||
|
assert inst != null;
|
||||||
|
|
||||||
|
if (this.getDisabledWorlds().contains(player.getWorld())) {
|
||||||
|
points = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
inst.removeModifier(modifier);
|
||||||
|
|
||||||
|
if (player.getHealth() >= inst.getValue()) {
|
||||||
|
this.getPlugin().getScheduler().runLater(() -> {
|
||||||
|
player.addPotionEffect(new PotionEffect(PotionEffectType.HEAL, 1, 255, false, false, false));
|
||||||
|
}, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (points > 0) {
|
||||||
|
inst.addModifier(
|
||||||
|
new AttributeModifier(
|
||||||
|
UUID.nameUUIDFromBytes("prosperity".getBytes()),
|
||||||
|
this.getKey().getKey(),
|
||||||
|
this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "health-per-point") * points,
|
||||||
|
AttributeModifier.Operation.ADD_NUMBER
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}, 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user