mirror of
https://github.com/Auxilor/EcoEnchants.git
synced 2024-12-23 19:57:36 +01:00
Switched out ArmorEquipEvent for ArmorChangeEvent
This commit is contained in:
parent
a531b736b0
commit
26795ce9b8
@ -1,6 +1,6 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.curse;
|
||||
|
||||
import com.willfp.eco.core.events.ArmorEquipEvent;
|
||||
import com.willfp.eco.core.events.ArmorChangeEvent;
|
||||
import com.willfp.eco.util.NumberUtils;
|
||||
import com.willfp.eco.util.VectorUtils;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
@ -37,7 +37,7 @@ public class CallingCurse extends EcoEnchant implements TimedRunnable {
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onArmorEquip(@NotNull final ArmorEquipEvent event) {
|
||||
public void onArmorEquip(@NotNull final ArmorChangeEvent event) {
|
||||
refresh();
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.normal;
|
||||
|
||||
import com.willfp.eco.core.events.ArmorEquipEvent;
|
||||
import com.willfp.eco.core.events.ArmorChangeEvent;
|
||||
import com.willfp.eco.util.NumberUtils;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
@ -31,7 +31,7 @@ public class Forcefield extends EcoEnchant implements TimedRunnable {
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onArmorEquip(@NotNull final ArmorEquipEvent event) {
|
||||
public void onArmorEquip(@NotNull final ArmorChangeEvent event) {
|
||||
refresh();
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.normal;
|
||||
|
||||
import com.willfp.eco.core.events.ArmorEquipEvent;
|
||||
import com.willfp.eco.core.events.ArmorChangeEvent;
|
||||
import com.willfp.eco.util.VectorUtils;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
@ -32,7 +32,7 @@ public class Magnetic extends EcoEnchant implements TimedRunnable {
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onArmorEquip(@NotNull final ArmorEquipEvent event) {
|
||||
public void onArmorEquip(@NotNull final ArmorChangeEvent event) {
|
||||
refresh();
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.normal;
|
||||
|
||||
import com.willfp.eco.core.events.ArmorEquipEvent;
|
||||
import com.willfp.eco.core.events.ArmorChangeEvent;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
|
||||
@ -10,7 +10,6 @@ import org.bukkit.attribute.AttributeInstance;
|
||||
import org.bukkit.attribute.AttributeModifier;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.UUID;
|
||||
@ -25,40 +24,38 @@ public class Thrive extends EcoEnchant {
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onArmorEquip(@NotNull final ArmorEquipEvent event) {
|
||||
public void onArmorEquip(@NotNull final ArmorChangeEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
|
||||
this.getPlugin().getScheduler().runLater(() -> {
|
||||
int points = EnchantChecks.getArmorPoints(player, this);
|
||||
int points = EnchantChecks.getArmorPoints(player, this);
|
||||
|
||||
AttributeInstance inst = player.getAttribute(Attribute.GENERIC_MAX_HEALTH);
|
||||
AttributeInstance inst = player.getAttribute(Attribute.GENERIC_MAX_HEALTH);
|
||||
|
||||
assert inst != null;
|
||||
assert inst != null;
|
||||
|
||||
inst.setBaseValue(inst.getDefaultValue());
|
||||
inst.setBaseValue(inst.getDefaultValue());
|
||||
|
||||
if (this.getDisabledWorlds().contains(player.getWorld())) {
|
||||
points = 0;
|
||||
}
|
||||
if (this.getDisabledWorlds().contains(player.getWorld())) {
|
||||
points = 0;
|
||||
}
|
||||
|
||||
inst.removeModifier(modifier);
|
||||
inst.removeModifier(modifier);
|
||||
|
||||
if (player.getHealth() >= inst.getValue()) {
|
||||
this.getPlugin().getScheduler().runLater(() -> {
|
||||
player.setHealth(player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue());
|
||||
}, 1);
|
||||
}
|
||||
if (player.getHealth() >= inst.getValue()) {
|
||||
this.getPlugin().getScheduler().runLater(() -> {
|
||||
player.setHealth(player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue());
|
||||
}, 1);
|
||||
}
|
||||
|
||||
if (points > 0) {
|
||||
inst.addModifier(
|
||||
new AttributeModifier(
|
||||
UUID.nameUUIDFromBytes("thrive".getBytes()),
|
||||
this.getKey().getKey(),
|
||||
this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "health-per-point") * points,
|
||||
AttributeModifier.Operation.ADD_NUMBER
|
||||
)
|
||||
);
|
||||
}
|
||||
}, 1);
|
||||
if (points > 0) {
|
||||
inst.addModifier(
|
||||
new AttributeModifier(
|
||||
UUID.nameUUIDFromBytes("thrive".getBytes()),
|
||||
this.getKey().getKey(),
|
||||
this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "health-per-point") * points,
|
||||
AttributeModifier.Operation.ADD_NUMBER
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.special;
|
||||
|
||||
import com.willfp.eco.core.events.ArmorEquipEvent;
|
||||
import com.willfp.eco.core.events.ArmorChangeEvent;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
|
||||
@ -24,7 +24,7 @@ public class Prosperity extends EcoEnchant {
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onArmorEquip(@NotNull final ArmorEquipEvent event) {
|
||||
public void onArmorEquip(@NotNull final ArmorChangeEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
|
||||
this.getPlugin().getScheduler().runLater(() -> {
|
||||
|
@ -1,6 +1,6 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.special;
|
||||
|
||||
import com.willfp.eco.core.events.ArmorEquipEvent;
|
||||
import com.willfp.eco.core.events.ArmorChangeEvent;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
|
||||
@ -17,7 +17,7 @@ public class Streamlining extends EcoEnchant {
|
||||
@Override
|
||||
public void onArmorEquip(@NotNull final Player player,
|
||||
final int level,
|
||||
@NotNull final ArmorEquipEvent event) {
|
||||
@NotNull final ArmorChangeEvent event) {
|
||||
if (level == 0) {
|
||||
player.setWalkSpeed(0.2f);
|
||||
return;
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.willfp.ecoenchants.enchantments.util;
|
||||
|
||||
import com.willfp.eco.core.events.ArmorChangeEvent;
|
||||
import com.willfp.eco.core.events.ArmorEquipEvent;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Arrow;
|
||||
@ -185,12 +186,26 @@ public interface Watcher {
|
||||
* @param level The level of the enchantment found on the player's armor.
|
||||
* @param event The event that called this watcher.
|
||||
*/
|
||||
@Deprecated
|
||||
default void onArmorEquip(@NotNull final Player player,
|
||||
final int level,
|
||||
@NotNull final ArmorEquipEvent event) {
|
||||
// Empty default as enchantments only override required watchers.
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when an entity puts on or takes off armor with an enchantment.
|
||||
*
|
||||
* @param player The player that equipped the armor.
|
||||
* @param level The level of the enchantment found on the player's armor.
|
||||
* @param event The event that called this watcher.
|
||||
*/
|
||||
default void onArmorEquip(@NotNull final Player player,
|
||||
final int level,
|
||||
@NotNull final ArmorChangeEvent event) {
|
||||
// Empty default as enchantments only override required watchers.
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a player damages a block.
|
||||
*
|
||||
|
@ -3,6 +3,7 @@ package com.willfp.ecoenchants.enchantments.util;
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import com.willfp.eco.core.PluginDependent;
|
||||
import com.willfp.eco.core.config.updating.ConfigUpdater;
|
||||
import com.willfp.eco.core.events.ArmorChangeEvent;
|
||||
import com.willfp.eco.core.events.ArmorEquipEvent;
|
||||
import com.willfp.eco.core.events.PlayerJumpEvent;
|
||||
import com.willfp.eco.core.integrations.antigrief.AntigriefManager;
|
||||
@ -532,6 +533,7 @@ public class WatcherTriggers extends PluginDependent<EcoPlugin> implements Liste
|
||||
* @param event The event to listen for.
|
||||
*/
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
@Deprecated
|
||||
public void onArmorEquip(@NotNull final ArmorEquipEvent event) {
|
||||
if (McmmoManager.isFake(event)) {
|
||||
return;
|
||||
@ -553,6 +555,34 @@ public class WatcherTriggers extends PluginDependent<EcoPlugin> implements Liste
|
||||
}), 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when an entity puts on or takes off armor with an enchantment.
|
||||
*
|
||||
* @param event The event to listen for.
|
||||
*/
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
@Deprecated
|
||||
public void onArmorChange(@NotNull final ArmorChangeEvent event) {
|
||||
if (McmmoManager.isFake(event)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = event.getPlayer();
|
||||
|
||||
EcoEnchants.values().forEach(enchant -> {
|
||||
if (!enchant.isEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (enchant.getDisabledWorlds().contains(player.getWorld())) {
|
||||
return;
|
||||
}
|
||||
|
||||
int level = EnchantChecks.getArmorPoints(player, enchant);
|
||||
enchant.onArmorEquip(player, level, event);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a player damages a block.
|
||||
*
|
||||
|
@ -1,7 +1,7 @@
|
||||
package com.willfp.ecoenchants.effects;
|
||||
|
||||
import com.willfp.eco.core.Prerequisite;
|
||||
import com.willfp.eco.core.events.ArmorEquipEvent;
|
||||
import com.willfp.eco.core.events.ArmorChangeEvent;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
|
||||
import com.willfp.ecoenchants.enchantments.util.EnchantChecks;
|
||||
@ -21,21 +21,19 @@ public abstract class EffectsEnchantment extends EcoEnchant {
|
||||
public abstract PotionEffectType getPotionEffect();
|
||||
|
||||
@EventHandler
|
||||
public void onEquip(@NotNull final ArmorEquipEvent event) {
|
||||
public void onEquip(@NotNull final ArmorChangeEvent event) {
|
||||
final Player player = event.getPlayer();
|
||||
|
||||
this.getPlugin().getScheduler().runLater(() -> {
|
||||
if (player.hasPotionEffect(this.getPotionEffect()) && player.getPotionEffect(this.getPotionEffect()).getDuration() >= 1639) {
|
||||
player.removePotionEffect(this.getPotionEffect());
|
||||
}
|
||||
if (player.hasPotionEffect(this.getPotionEffect()) && player.getPotionEffect(this.getPotionEffect()).getDuration() >= 1639) {
|
||||
player.removePotionEffect(this.getPotionEffect());
|
||||
}
|
||||
|
||||
int level = EnchantChecks.getArmorPoints(player, this);
|
||||
if (this.getDisabledWorlds().contains(player.getWorld())) {
|
||||
return;
|
||||
}
|
||||
if (level > 0) {
|
||||
player.addPotionEffect(new PotionEffect(this.getPotionEffect(), 0x6fffffff, level - 1, false, false, true));
|
||||
}
|
||||
}, 1);
|
||||
int level = EnchantChecks.getArmorPoints(player, this);
|
||||
if (this.getDisabledWorlds().contains(player.getWorld())) {
|
||||
return;
|
||||
}
|
||||
if (level > 0) {
|
||||
player.addPotionEffect(new PotionEffect(this.getPotionEffect(), 0x6fffffff, level - 1, false, false, true));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user