浏览代码

Fixed a bug where Spectral arrow awarded too much XP

nossr50 4 年之前
父节点
当前提交
da06d5c075

+ 13 - 10
src/main/java/com/gmail/nossr50/listeners/EntityListener.java

@@ -161,21 +161,24 @@ public class EntityListener implements Listener {
             }
 
             Projectile projectile = event.getEntity();
+            EntityType entityType = projectile.getType();
 
-            if(!(projectile instanceof Arrow))
-                return;
+            if(entityType == EntityType.ARROW || entityType == EntityType.SPECTRAL_ARROW) {
+                if(!projectile.hasMetadata(mcMMO.bowForceKey))
+                    projectile.setMetadata(mcMMO.bowForceKey, new FixedMetadataValue(pluginRef, 1.0));
 
-            projectile.setMetadata(mcMMO.bowForceKey, new FixedMetadataValue(pluginRef, 1.0));
-            projectile.setMetadata(mcMMO.arrowDistanceKey, new FixedMetadataValue(pluginRef, projectile.getLocation()));
+                if(!projectile.hasMetadata(mcMMO.arrowDistanceKey))
+                    projectile.setMetadata(mcMMO.arrowDistanceKey, new FixedMetadataValue(pluginRef, projectile.getLocation()));
 
-            for (Enchantment enchantment : player.getInventory().getItemInMainHand().getEnchantments().keySet()) {
-                if (enchantment.getKey().equals(piercingEnchantment)) {
-                    return;
+                for (Enchantment enchantment : player.getInventory().getItemInMainHand().getEnchantments().keySet()) {
+                    if (enchantment.getKey().equals(piercingEnchantment)) {
+                        return;
+                    }
                 }
-            }
 
-            if (RandomChanceUtil.isActivationSuccessful(SkillActivationType.RANDOM_LINEAR_100_SCALE_WITH_CAP, SubSkillType.ARCHERY_ARROW_RETRIEVAL, player)) {
-                projectile.setMetadata(mcMMO.trackedArrow, mcMMO.metadataValue);
+                if (RandomChanceUtil.isActivationSuccessful(SkillActivationType.RANDOM_LINEAR_100_SCALE_WITH_CAP, SubSkillType.ARCHERY_ARROW_RETRIEVAL, player)) {
+                    projectile.setMetadata(mcMMO.trackedArrow, mcMMO.metadataValue);
+                }
             }
         }
     }

+ 14 - 2
src/main/java/com/gmail/nossr50/util/skills/CombatUtils.java

@@ -36,6 +36,8 @@ import org.bukkit.inventory.ItemStack;
 import org.bukkit.metadata.MetadataValue;
 import org.bukkit.potion.PotionEffectType;
 import org.bukkit.projectiles.ProjectileSource;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
 
 import java.util.EnumMap;
 import java.util.HashMap;
@@ -117,9 +119,14 @@ public final class CombatUtils {
         printFinalDamageDebug(player, event, mcMMOPlayer);
     }
 
-    private static void printFinalDamageDebug(Player player, EntityDamageByEntityEvent event, McMMOPlayer mcMMOPlayer) {
+    private static void printFinalDamageDebug(@NotNull Player player, @NotNull EntityDamageByEntityEvent event, @NotNull McMMOPlayer mcMMOPlayer, @Nullable String... extraInfoLines) {
         if(mcMMOPlayer.isDebugMode()) {
             player.sendMessage("Final Damage value after mcMMO modifiers: "+ event.getFinalDamage());
+            if(extraInfoLines != null) {
+                for(String str : extraInfoLines) {
+                    player.sendMessage(str);
+                }
+            }
         }
     }
 
@@ -317,9 +324,14 @@ public final class CombatUtils {
             forceMultiplier = arrow.getMetadata(mcMMO.bowForceKey).get(0).asDouble();
 
         applyScaledModifiers(initialDamage, finalDamage, event);
+
         processCombatXP(mcMMOPlayer, target, PrimarySkillType.ARCHERY, forceMultiplier * distanceMultiplier);
 
-        printFinalDamageDebug(player, event, mcMMOPlayer);
+        printFinalDamageDebug(player, event, mcMMOPlayer,
+                "Distance Multiplier: "+distanceMultiplier,
+                "Force Multiplier: "+forceMultiplier,
+                "Initial Damage: "+initialDamage,
+                "Final Damage: "+finalDamage);
     }
 
     /**