Advertisement
williambriggs

Untitled

Jul 28th, 2022
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. /**
  2. * This handler listens to ALL bow shootings, including both
  3. * custom bows from MMOItems AND vanilla bows, since MMOItems needs to
  4. * apply on-hit effects like crits, elemental damage... even if the
  5. * player is using a vanilla bow.
  6. * <p>
  7. * Fixing commit 4aec1433
  8. */
  9. @EventHandler
  10. public void handleCustomBows(EntityShootBowEvent event) {
  11. if (!(event.getProjectile() instanceof Arrow) || !(event.getEntity() instanceof Player))
  12. return;
  13.  
  14. NBTItem item = NBTItem.get(event.getBow());
  15. Type type = Type.get(item.getType());
  16.  
  17. PlayerData playerData = PlayerData.get((Player) event.getEntity());
  18. if (type != null) {
  19. Weapon weapon = new Weapon(playerData, item);
  20. if (!weapon.checkItemRequirements() || !weapon.checkAndApplyWeaponCosts()) {
  21. event.setCancelled(true);
  22. return;
  23. }
  24.  
  25. /*if (!checkDualWield((Player) event.getEntity(), item, bowSlot)) {
  26. event.setCancelled(true);
  27. return;
  28. }*/
  29. }
  30.  
  31. // Have to get hand manually because 1.15 and below does not have event.getHand()
  32. ItemStack itemInMainHand = playerData.getPlayer().getInventory().getItemInMainHand();
  33. EquipmentSlot bowSlot = itemInMainHand.isSimilar(event.getBow()) ? EquipmentSlot.MAIN_HAND : EquipmentSlot.OFF_HAND;
  34.  
  35. Arrow arrow = (Arrow) event.getProjectile();
  36. if (item.getStat("ARROW_VELOCITY") > 0)
  37. arrow.setVelocity(arrow.getVelocity().multiply(item.getStat("ARROW_VELOCITY")));
  38. MMOItems.plugin.getEntities().registerCustomProjectile(item, playerData.getStats().newTemporary(bowSlot), event.getProjectile(), type != null, event.getForce());
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement