Merge pull request #123
Added AntigriefManager support to Instability and Corrosive enchantments
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.normal;
|
||||
|
||||
import com.willfp.eco.core.integrations.antigrief.AntigriefManager;
|
||||
import com.willfp.eco.util.DurabilityUtils;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
|
||||
@@ -30,6 +31,12 @@ public class Corrosive extends EcoEnchant {
|
||||
return;
|
||||
}
|
||||
|
||||
if (attacker instanceof Player player) {
|
||||
if (!AntigriefManager.canInjure(player, uncastVictim)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
ArrayList<ItemStack> armor = new ArrayList<>(Arrays.asList(victim.getInventory().getArmorContents()));
|
||||
if (armor.isEmpty()) {
|
||||
return;
|
||||
|
||||
@@ -5,20 +5,40 @@ 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.EnchantChecks;
|
||||
import org.bukkit.entity.Arrow;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.*;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.bukkit.event.entity.ProjectileHitEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Instability extends EcoEnchant {
|
||||
|
||||
private static final List<Entity> toProtect = new ArrayList<>();
|
||||
|
||||
public Instability() {
|
||||
super(
|
||||
"instability", EnchantmentType.SPECIAL
|
||||
);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onInstabilityExplode(@NotNull final EntityDamageEvent event) {
|
||||
if (!toProtect.contains(event.getEntity())) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.getCause() != EntityDamageEvent.DamageCause.ENTITY_EXPLOSION && event.getCause()
|
||||
!= EntityDamageEvent.DamageCause.BLOCK_EXPLOSION) {
|
||||
return;
|
||||
}
|
||||
|
||||
event.setCancelled(true);
|
||||
toProtect.remove(event.getEntity());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onInstabilityLand(@NotNull final ProjectileHitEvent event) {
|
||||
if (event.getEntityType() != EntityType.ARROW) {
|
||||
@@ -60,6 +80,16 @@ public class Instability extends EcoEnchant {
|
||||
breakblocks = AntigriefManager.canBreakBlock(player, event.getEntity().getLocation().getWorld().getBlockAt(event.getEntity().getLocation()));
|
||||
}
|
||||
|
||||
List<Entity> toAdd = event.getEntity().getNearbyEntities(power, power, power)
|
||||
.stream().filter(entity -> entity instanceof LivingEntity && !AntigriefManager.canInjure(player, (LivingEntity) entity))
|
||||
.toList();
|
||||
|
||||
toProtect.addAll(
|
||||
toAdd
|
||||
);
|
||||
|
||||
this.getPlugin().getScheduler().runLater(() -> toProtect.removeAll(toAdd), 20);
|
||||
|
||||
event.getEntity().getWorld().createExplosion(event.getEntity().getLocation().getX(), event.getEntity().getLocation().getY(), event.getEntity().getLocation().getZ(), power, fire, breakblocks);
|
||||
|
||||
event.getEntity().remove();
|
||||
|
||||
Reference in New Issue
Block a user