Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * This handler listens to ALL bow shootings, including both
- * custom bows from MMOItems AND vanilla bows, since MMOItems needs to
- * apply on-hit effects like crits, elemental damage... even if the
- * player is using a vanilla bow.
- * <p>
- * Fixing commit 4aec1433
- */
- @EventHandler
- public void handleCustomBows(EntityShootBowEvent event) {
- if (!(event.getProjectile() instanceof Arrow) || !(event.getEntity() instanceof Player))
- return;
- NBTItem item = NBTItem.get(event.getBow());
- Type type = Type.get(item.getType());
- PlayerData playerData = PlayerData.get((Player) event.getEntity());
- if (type != null) {
- Weapon weapon = new Weapon(playerData, item);
- if (!weapon.checkItemRequirements() || !weapon.checkAndApplyWeaponCosts()) {
- event.setCancelled(true);
- return;
- }
- /*if (!checkDualWield((Player) event.getEntity(), item, bowSlot)) {
- event.setCancelled(true);
- return;
- }*/
- }
- // Have to get hand manually because 1.15 and below does not have event.getHand()
- ItemStack itemInMainHand = playerData.getPlayer().getInventory().getItemInMainHand();
- EquipmentSlot bowSlot = itemInMainHand.isSimilar(event.getBow()) ? EquipmentSlot.MAIN_HAND : EquipmentSlot.OFF_HAND;
- Arrow arrow = (Arrow) event.getProjectile();
- if (item.getStat("ARROW_VELOCITY") > 0)
- arrow.setVelocity(arrow.getVelocity().multiply(item.getStat("ARROW_VELOCITY")));
- MMOItems.plugin.getEntities().registerCustomProjectile(item, playerData.getStats().newTemporary(bowSlot), event.getProjectile(), type != null, event.getForce());
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement