22
33import static com .gmail .nossr50 .datatypes .experience .XPGainReason .PVP ;
44import static com .gmail .nossr50 .util .AttributeMapper .MAPPED_MOVEMENT_SPEED ;
5- import static com .gmail .nossr50 .util .ItemUtils .isSpear ;
65import static com .gmail .nossr50 .util .MobMetadataUtils .hasMobFlag ;
76import static com .gmail .nossr50 .util .Permissions .canUseSubSkill ;
87import static com .gmail .nossr50 .util .skills .ProjectileUtils .isCrossbowProjectile ;
@@ -132,11 +131,6 @@ private static void processSwordCombat(@NotNull LivingEntity target, @NotNull Pl
132131 return ;
133132 }
134133
135- // Hack to avoid other combat abilities applying to off-hand spear attacks
136- if (isSpear (player .getInventory ().getItemInOffHand ()) && isNotSwinging (mmoPlayer )) {
137- return ;
138- }
139-
140134 SwordsManager swordsManager = mmoPlayer .getSwordsManager ();
141135 double boostedDamage = event .getDamage ();
142136
@@ -203,11 +197,6 @@ private static void processTridentCombatMelee(@NotNull LivingEntity target,
203197 return ;
204198 }
205199
206- // Hack to avoid other combat abilities applying to off-hand spear attacks
207- if (isSpear (player .getInventory ().getItemInOffHand ()) && isNotSwinging (mmoPlayer )) {
208- return ;
209- }
210-
211200 final TridentsManager tridentsManager = mmoPlayer .getTridentsManager ();
212201
213202// if (tridentsManager.canActivateAbility()) {
@@ -321,11 +310,6 @@ private static void processMacesCombat(@NotNull LivingEntity target,
321310 return ;
322311 }
323312
324- // Hack to avoid other combat abilities applying to off-hand spear attacks
325- if (isSpear (player .getInventory ().getItemInOffHand ()) && isNotSwinging (mmoPlayer )) {
326- return ;
327- }
328-
329313 final MacesManager macesManager = mmoPlayer .getMacesManager ();
330314
331315 // Apply Limit Break DMG
@@ -404,11 +388,6 @@ private static void processAxeCombat(@NotNull LivingEntity target, @NotNull Play
404388 return ;
405389 }
406390
407- // Hack to avoid other combat abilities applying to off-hand spear attacks
408- if (isSpear (player .getInventory ().getItemInOffHand ()) && isNotSwinging (mmoPlayer )) {
409- return ;
410- }
411-
412391 final AxesManager axesManager = mmoPlayer .getAxesManager ();
413392
414393 if (axesManager .canActivateAbility ()) {
@@ -461,11 +440,6 @@ private static void processUnarmedCombat(@NotNull LivingEntity target, @NotNull
461440 return ;
462441 }
463442
464- // Hack to avoid other combat abilities applying to off-hand spear attacks
465- if (isSpear (player .getInventory ().getItemInOffHand ()) && isNotSwinging (mmoPlayer )) {
466- return ;
467- }
468-
469443 final UnarmedManager unarmedManager = mmoPlayer .getUnarmedManager ();
470444
471445 if (unarmedManager .canActivateAbility ()) {
@@ -598,8 +572,12 @@ private static void processArcheryCombat(@NotNull LivingEntity target, @NotNull
598572 public static void processCombatAttack (@ NotNull EntityDamageByEntityEvent event ,
599573 @ NotNull Entity painSourceRoot ,
600574 @ NotNull LivingEntity target ) {
601- Entity painSource = event .getDamager ();
602- EntityType entityType = painSource .getType ();
575+ final Entity painSource = event .getDamager ();
576+ final EntityType entityType = painSource .getType ();
577+ final String damageType = event .getDamageSource ().getDamageType ().getKey ().getKey ();
578+
579+ boolean isDamageTypeSpear =
580+ damageType .equalsIgnoreCase ("SPEAR" );
603581
604582 if (target instanceof ArmorStand ) {
605583 return ;
@@ -642,7 +620,7 @@ public static void processCombatAttack(@NotNull EntityDamageByEntityEvent event,
642620 return ;
643621 }
644622
645- ItemStack heldItem = player .getInventory ().getItemInMainHand ();
623+ final ItemStack heldItem = player .getInventory ().getItemInMainHand ();
646624
647625 if (target instanceof Tameable ) {
648626 if (heldItem .getType () == Material .BONE ) {
@@ -660,7 +638,16 @@ public static void processCombatAttack(@NotNull EntityDamageByEntityEvent event,
660638 }
661639 }
662640
663- if (ItemUtils .isSword (heldItem )) {
641+ if (isDamageTypeSpear ) {
642+ if (!mcMMO .p .getSkillTools ()
643+ .canCombatSkillsTrigger (PrimarySkillType .SPEARS , target )) {
644+ return ;
645+ }
646+ if (mcMMO .p .getSkillTools ()
647+ .doesPlayerHaveSkillPermission (player , PrimarySkillType .SPEARS )) {
648+ processSpearsCombat (target , player , event );
649+ }
650+ } if (ItemUtils .isSword (heldItem )) {
664651 if (!mcMMO .p .getSkillTools ()
665652 .canCombatSkillsTrigger (PrimarySkillType .SWORDS , target )) {
666653 return ;
@@ -710,15 +697,6 @@ public static void processCombatAttack(@NotNull EntityDamageByEntityEvent event,
710697 .doesPlayerHaveSkillPermission (player , PrimarySkillType .MACES )) {
711698 processMacesCombat (target , player , event );
712699 }
713- } else if (isSpear (heldItem )) {
714- if (!mcMMO .p .getSkillTools ()
715- .canCombatSkillsTrigger (PrimarySkillType .SPEARS , target )) {
716- return ;
717- }
718- if (mcMMO .p .getSkillTools ()
719- .doesPlayerHaveSkillPermission (player , PrimarySkillType .SPEARS )) {
720- processSpearsCombat (target , player , event );
721- }
722700 }
723701 } else if (entityType == EntityType .WOLF ) {
724702 Wolf wolf = (Wolf ) painSource ;
@@ -1225,10 +1203,4 @@ public static void delayArrowMetaCleanup(@NotNull AbstractArrow arrow) {
12251203 mcMMO .p .getFoliaLib ().getScheduler ()
12261204 .runLater (() -> ProjectileUtils .cleanupProjectileMetadata (arrow ), 20 * 120 );
12271205 }
1228-
1229- public static boolean isNotSwinging (McMMOPlayer mmoPlayer ) {
1230- // If player has swung in the last second, it's extremely unlikely the damage originates
1231- // from an off-hand spear charge attack
1232- return mmoPlayer .getLastSwingTimestamp () + 500L < System .currentTimeMillis ();
1233- }
12341206}
0 commit comments