Skip to content

Commit

Permalink
Fix MultiShot-Arrows reflect from entities
Browse files Browse the repository at this point in the history
  • Loading branch information
Flo56958 committed Oct 6, 2023
1 parent 893815d commit d78833f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,6 @@ public boolean applyMod(Player player, ItemStack tool, boolean isCommand) {

@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH)
public void onShoot(final MTProjectileLaunchEvent event) {
if (!this.isAllowed()) return;

Projectile projectile = event.getEvent().getEntity();
if (!(projectile instanceof Arrow arrow)) return;

Expand All @@ -110,8 +108,6 @@ public void onShoot(final MTProjectileLaunchEvent event) {

final ItemStack tool = event.getTool();

if (!modManager.isToolViable(tool)) return;

if (!modManager.hasMod(tool, this)) return;

if(!(arrow.hasCustomEffects())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@
import org.bukkit.Material;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.AbstractArrow;
import org.bukkit.entity.Arrow;
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
import org.bukkit.entity.*;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityShootBowEvent;
import org.bukkit.event.entity.ProjectileLaunchEvent;
import org.bukkit.inventory.EquipmentSlot;
Expand Down Expand Up @@ -121,17 +120,30 @@ public boolean applyMod(Player player, ItemStack tool, boolean isCommand) {
return true;
}

@EventHandler(priority = EventPriority.LOW)
public void onHit(final EntityDamageByEntityEvent event) {
if (!this.isAllowed()) return;
if (!(event.getDamager() instanceof Arrow arrow)) return;
if (!arrow.hasMetadata(this.getKey())) return;
if (!(event.getEntity() instanceof LivingEntity entity)) return;

// Fix Arrows reflecting of entity
entity.setNoDamageTicks(0);
entity.setMaximumNoDamageTicks(0);
event.setCancelled(false);
}

@EventHandler(ignoreCancelled = true)
public void onShoot(final MTProjectileLaunchEvent event) {
if (!this.isAllowed()) {
return;
}

Projectile arrow = event.getEvent().getEntity();
Projectile projectile = event.getEvent().getEntity();

if (arrow.hasMetadata(this.getKey())) return;
if (projectile.hasMetadata(this.getKey())) return;

if (!(arrow instanceof Arrow)) {
if (!(projectile instanceof Arrow arrow)) {
return;
}

Expand Down Expand Up @@ -208,8 +220,8 @@ public void onShoot(final MTProjectileLaunchEvent event) {
arr.setPickupStatus(AbstractArrow.PickupStatus.CREATIVE_ONLY);
}

arr.setCritical(((Arrow) arrow).isCritical());
arr.setDamage(((Arrow) arrow).getDamage());
arr.setCritical(arrow.isCritical());
arr.setDamage(arrow.getDamage());
// no recursive actions
arr.setMetadata(this.getKey(), new FixedMetadataValue(this.getSource(), null));

Expand All @@ -230,6 +242,8 @@ public void onShoot(final MTProjectileLaunchEvent event) {
}
}, 0);
}

arrow.setMetadata(this.getKey(), new FixedMetadataValue(this.getSource(), null));
}

private void returnArrow(Player player, Arrow arr) {
Expand Down

0 comments on commit d78833f

Please sign in to comment.