Fixed EnchantThunder and EnchantElectrifiedArrows item damage

This commit is contained in:
nulli0n 2023-01-26 09:49:58 +06:00
parent d9d2a84805
commit a419c9e147
9 changed files with 51 additions and 19 deletions

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>ExcellentEnchants</artifactId>
<groupId>su.nightexpress.excellentenchants</groupId>
<version>3.3.0.2</version>
<version>3.3.0.3</version>
</parent>
<modelVersion>4.0.0</modelVersion>
@ -45,27 +45,27 @@
<dependency>
<groupId>su.nightexpress.excellentenchants</groupId>
<artifactId>NMS</artifactId>
<version>3.3.0.2</version>
<version>3.3.0.3</version>
</dependency>
<dependency>
<groupId>su.nightexpress.excellentenchants</groupId>
<artifactId>V1_17_R1</artifactId>
<version>3.3.0.2</version>
<version>3.3.0.3</version>
</dependency>
<dependency>
<groupId>su.nightexpress.excellentenchants</groupId>
<artifactId>V1_18_R2</artifactId>
<version>3.3.0.2</version>
<version>3.3.0.3</version>
</dependency>
<dependency>
<groupId>su.nightexpress.excellentenchants</groupId>
<artifactId>V1_19_R1</artifactId>
<version>3.3.0.2</version>
<version>3.3.0.3</version>
</dependency>
<dependency>
<groupId>su.nightexpress.excellentenchants</groupId>
<artifactId>V1_19_R2</artifactId>
<version>3.3.0.2</version>
<version>3.3.0.3</version>
</dependency>
<dependency>
<groupId>fr.neatmonster</groupId>

View File

@ -3,12 +3,16 @@ package su.nightexpress.excellentenchants.enchantment.impl.bow;
import org.bukkit.Particle;
import org.bukkit.block.Block;
import org.bukkit.enchantments.EnchantmentTarget;
import org.bukkit.entity.Item;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Projectile;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityShootBowEvent;
import org.bukkit.event.entity.ProjectileHitEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.metadata.FixedMetadataValue;
import org.jetbrains.annotations.NotNull;
import su.nexmedia.engine.utils.EffectUtil;
import su.nexmedia.engine.utils.LocationUtil;
@ -25,6 +29,8 @@ public class EnchantElectrifiedArrows extends ExcellentEnchant implements Chance
public static final String ID = "electrified_arrows";
private static final String META_NO_ITEM_DAMAGE = "itemNoDamage";
private ArrowImplementation arrowImplementation;
private ChanceImplementation chanceImplementation;
@ -70,7 +76,7 @@ public class EnchantElectrifiedArrows extends ExcellentEnchant implements Chance
if (e.getHitEntity() != null || e.getHitBlock() == null) return false;
Block block = e.getHitBlock();
block.getWorld().strikeLightning(block.getLocation());
block.getWorld().strikeLightning(block.getLocation()).setMetadata(META_NO_ITEM_DAMAGE, new FixedMetadataValue(plugin, true));
if (this.hasVisualEffects()) {
EffectUtil.playEffect(LocationUtil.getCenter(block.getLocation()), Particle.BLOCK_CRACK, block.getType().name(), 1D, 1D, 1D, 0.05, 150);
EffectUtil.playEffect(LocationUtil.getCenter(block.getLocation()), Particle.FIREWORKS_SPARK, "", 1D, 1D, 1D, 0.05, 150);
@ -83,10 +89,20 @@ public class EnchantElectrifiedArrows extends ExcellentEnchant implements Chance
if (!this.isOurProjectile(projectile)) return false;
plugin.getServer().getScheduler().runTask(plugin, () -> {
if (victim.isDead()) return;
victim.setNoDamageTicks(0);
victim.getWorld().strikeLightning(victim.getLocation());
victim.getWorld().strikeLightning(victim.getLocation()).setMetadata(META_NO_ITEM_DAMAGE, new FixedMetadataValue(plugin, true));
});
return true;
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onItemDamage(EntityDamageByEntityEvent e) {
if (!e.getDamager().hasMetadata(META_NO_ITEM_DAMAGE)) return;
if (!(e.getEntity() instanceof Item item)) return;
e.setCancelled(true);
item.setFireTicks(0);
}
}

View File

@ -1,9 +1,13 @@
package su.nightexpress.excellentenchants.enchantment.impl.weapon;
import org.bukkit.enchantments.EnchantmentTarget;
import org.bukkit.entity.Item;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.metadata.FixedMetadataValue;
import org.jetbrains.annotations.NotNull;
import su.nexmedia.engine.api.config.JOption;
import su.nightexpress.excellentenchants.ExcellentEnchants;
@ -17,6 +21,8 @@ public class EnchantThunder extends ExcellentEnchant implements Chanced, CombatE
public static final String ID = "thunder";
private static final String META_NO_ITEM_DAMAGE = "noItemDamage";
private boolean inThunderstormOnly;
private ChanceImplementation chanceImplementation;
@ -56,8 +62,9 @@ public class EnchantThunder extends ExcellentEnchant implements Chanced, CombatE
if (!this.checkTriggerChance(level)) return false;
plugin.getServer().getScheduler().runTask(plugin, () -> {
if (victim.isDead()) return;
victim.setNoDamageTicks(0);
victim.getWorld().strikeLightning(victim.getLocation());
victim.getWorld().strikeLightning(victim.getLocation()).setMetadata(META_NO_ITEM_DAMAGE, new FixedMetadataValue(plugin, true));
});
return true;
@ -67,4 +74,13 @@ public class EnchantThunder extends ExcellentEnchant implements Chanced, CombatE
public boolean onProtect(@NotNull EntityDamageByEntityEvent e, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) {
return false;
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onItemDamage(EntityDamageByEntityEvent e) {
if (!e.getDamager().hasMetadata(META_NO_ITEM_DAMAGE)) return;
if (!(e.getEntity() instanceof Item item)) return;
e.setCancelled(true);
item.setFireTicks(0);
}
}

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>ExcellentEnchants</artifactId>
<groupId>su.nightexpress.excellentenchants</groupId>
<version>3.3.0.2</version>
<version>3.3.0.3</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>ExcellentEnchants</artifactId>
<groupId>su.nightexpress.excellentenchants</groupId>
<version>3.3.0.2</version>
<version>3.3.0.3</version>
</parent>
<modelVersion>4.0.0</modelVersion>
@ -26,7 +26,7 @@
<dependency>
<groupId>su.nightexpress.excellentenchants</groupId>
<artifactId>NMS</artifactId>
<version>3.3.0.2</version>
<version>3.3.0.3</version>
</dependency>
</dependencies>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>ExcellentEnchants</artifactId>
<groupId>su.nightexpress.excellentenchants</groupId>
<version>3.3.0.2</version>
<version>3.3.0.3</version>
</parent>
<modelVersion>4.0.0</modelVersion>
@ -26,7 +26,7 @@
<dependency>
<groupId>su.nightexpress.excellentenchants</groupId>
<artifactId>NMS</artifactId>
<version>3.3.0.2</version>
<version>3.3.0.3</version>
</dependency>
</dependencies>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>ExcellentEnchants</artifactId>
<groupId>su.nightexpress.excellentenchants</groupId>
<version>3.3.0.2</version>
<version>3.3.0.3</version>
</parent>
<modelVersion>4.0.0</modelVersion>
@ -26,7 +26,7 @@
<dependency>
<groupId>su.nightexpress.excellentenchants</groupId>
<artifactId>NMS</artifactId>
<version>3.3.0.2</version>
<version>3.3.0.3</version>
</dependency>
</dependencies>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>ExcellentEnchants</artifactId>
<groupId>su.nightexpress.excellentenchants</groupId>
<version>3.3.0.2</version>
<version>3.3.0.3</version>
</parent>
<modelVersion>4.0.0</modelVersion>
@ -26,7 +26,7 @@
<dependency>
<groupId>su.nightexpress.excellentenchants</groupId>
<artifactId>NMS</artifactId>
<version>3.3.0.2</version>
<version>3.3.0.3</version>
</dependency>
</dependencies>

View File

@ -7,7 +7,7 @@
<groupId>su.nightexpress.excellentenchants</groupId>
<artifactId>ExcellentEnchants</artifactId>
<packaging>pom</packaging>
<version>3.3.0.2</version>
<version>3.3.0.3</version>
<modules>
<module>Core</module>
<module>NMS</module>