diff --git a/src/main/java/com/gmail/nossr50/listeners/EntityListener.java b/src/main/java/com/gmail/nossr50/listeners/EntityListener.java index f68fe1cb2..2453115ba 100644 --- a/src/main/java/com/gmail/nossr50/listeners/EntityListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/EntityListener.java @@ -6,6 +6,7 @@ import com.gmail.nossr50.config.WorldBlacklist; import com.gmail.nossr50.config.experience.ExperienceConfig; import com.gmail.nossr50.datatypes.meta.ProjectileOriginMeta; import com.gmail.nossr50.datatypes.player.McMMOPlayer; +import com.gmail.nossr50.datatypes.skills.PrimarySkillType; import com.gmail.nossr50.datatypes.skills.SubSkillType; import com.gmail.nossr50.datatypes.skills.subskills.interfaces.InteractType; import com.gmail.nossr50.events.fake.FakeEntityDamageByEntityEvent; @@ -148,15 +149,32 @@ public class EntityListener implements Listener { projectile.setMetadata(mcMMO.arrowDistanceKey, new FixedMetadataValue(plugin, projectile.getLocation())); + boolean isCrossbow = false; + //Track origin of projectile if(ItemUtils.hasItemInMainHand(player, "bow")) { markProjectileOriginAsBow(projectile); } else if(ItemUtils.hasItemInMainHand(player, "crossbow")) { markProjectileOriginAsCrossbow(projectile); + isCrossbow = true; } else if(ItemUtils.hasItemInOffHand(player, "bow")) { markProjectileOriginAsBow(projectile); } else if(ItemUtils.hasItemInOffHand(player, "crossbow")) { markProjectileOriginAsCrossbow(projectile); + isCrossbow = true; + } + + //Crossbow only + if(isCrossbow) { + McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player); + + //Process launch event + if(Permissions.skillEnabled(player, PrimarySkillType.CROSSBOWS)) { + if(mcMMOPlayer != null) { + mcMMOPlayer.getCrossbowManager().processProjectileLaunchEvent(event); + } + } + } for(Enchantment enchantment : player.getInventory().getItemInMainHand().getEnchantments().keySet()) { @@ -164,8 +182,11 @@ public class EntityListener implements Listener { return; } - if (RandomChanceUtil.isActivationSuccessful(SkillActivationType.RANDOM_LINEAR_100_SCALE_WITH_CAP, SubSkillType.ARCHERY_ARROW_RETRIEVAL, player)) { - projectile.setMetadata(mcMMO.trackedArrow, mcMMO.metadataValue); + //Bow only + if(!isCrossbow) { + if (RandomChanceUtil.isActivationSuccessful(SkillActivationType.RANDOM_LINEAR_100_SCALE_WITH_CAP, SubSkillType.ARCHERY_ARROW_RETRIEVAL, player)) { + projectile.setMetadata(mcMMO.trackedArrow, mcMMO.metadataValue); + } } } } diff --git a/src/main/java/com/gmail/nossr50/skills/crossbows/CrossbowManager.java b/src/main/java/com/gmail/nossr50/skills/crossbows/CrossbowManager.java index fbfbcef4c..e55e5fe8e 100644 --- a/src/main/java/com/gmail/nossr50/skills/crossbows/CrossbowManager.java +++ b/src/main/java/com/gmail/nossr50/skills/crossbows/CrossbowManager.java @@ -8,6 +8,7 @@ import com.gmail.nossr50.skills.archery.Archery; import org.bukkit.Location; import org.bukkit.entity.Entity; import org.bukkit.entity.LivingEntity; +import org.bukkit.event.entity.ProjectileLaunchEvent; public class CrossbowManager extends SkillManager { public CrossbowManager(McMMOPlayer mcMMOPlayer) { @@ -36,4 +37,13 @@ public class CrossbowManager extends SkillManager { return 1 + Math.min(firedLocation.distance(targetLocation), 50) * Archery.DISTANCE_XP_MULTIPLIER; } + /** + * Used for sub-skills that activate on projectile launch + * @param projectileLaunchEvent target event + */ + public void processProjectileLaunchEvent(ProjectileLaunchEvent projectileLaunchEvent) { + mcMMOPlayer.getPlayer().sendMessage("Pew pew!"); + } + + }