Two small fixes (#4321)

* Fixed armor counting in BleedTimerTask

* Key instead of Name for Piercing
This commit is contained in:
TheBusyBiscuit 2020-11-02 22:57:53 +01:00 committed by GitHub
parent 65fba3e20e
commit 01ebba4443
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 5 deletions

View File

@ -31,6 +31,7 @@ import com.gmail.nossr50.util.skills.SkillActivationType;
import com.gmail.nossr50.worldguard.WorldGuardManager; import com.gmail.nossr50.worldguard.WorldGuardManager;
import com.gmail.nossr50.worldguard.WorldGuardUtils; import com.gmail.nossr50.worldguard.WorldGuardUtils;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.enchantments.Enchantment; import org.bukkit.enchantments.Enchantment;
@ -54,6 +55,12 @@ public class EntityListener implements Listener {
private final mcMMO pluginRef; private final mcMMO pluginRef;
private final @NotNull AbstractPersistentDataLayer persistentDataLayer; private final @NotNull AbstractPersistentDataLayer persistentDataLayer;
/**
* We can use this {@link NamespacedKey} for {@link Enchantment} comparisons to
* check if a {@link Player} has a {@link Trident} enchanted with "Piercing".
*/
private final NamespacedKey piercingEnchantment = NamespacedKey.minecraft("piercing");
public EntityListener(final mcMMO pluginRef) { public EntityListener(final mcMMO pluginRef) {
this.pluginRef = pluginRef; this.pluginRef = pluginRef;
persistentDataLayer = mcMMO.getCompatibilityManager().getPersistentDataLayer(); persistentDataLayer = mcMMO.getCompatibilityManager().getPersistentDataLayer();
@ -161,9 +168,10 @@ public class EntityListener implements Listener {
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())); projectile.setMetadata(mcMMO.arrowDistanceKey, new FixedMetadataValue(pluginRef, projectile.getLocation()));
for(Enchantment enchantment : player.getInventory().getItemInMainHand().getEnchantments().keySet()) { for (Enchantment enchantment : player.getInventory().getItemInMainHand().getEnchantments().keySet()) {
if(enchantment.getName().equalsIgnoreCase("piercing")) if (enchantment.getKey().equals(piercingEnchantment)) {
return; return;
}
} }
if (RandomChanceUtil.isActivationSuccessful(SkillActivationType.RANDOM_LINEAR_100_SCALE_WITH_CAP, SubSkillType.ARCHERY_ARROW_RETRIEVAL, player)) { if (RandomChanceUtil.isActivationSuccessful(SkillActivationType.RANDOM_LINEAR_100_SCALE_WITH_CAP, SubSkillType.ARCHERY_ARROW_RETRIEVAL, player)) {

View File

@ -69,9 +69,11 @@ public class BleedTimerTask extends BukkitRunnable {
} }
//Count Armor //Count Armor
for(ItemStack armorPiece : ((Player) target).getInventory().getArmorContents()) for (ItemStack armorPiece : ((Player) target).getInventory().getArmorContents()) {
{ //We only want to count slots that contain armor.
armorCount++; if (armorPiece != null) {
armorCount++;
}
} }
} else { } else {