Properly track infinite arrows.

This commit is contained in:
GJ 2013-05-14 22:43:13 -04:00
parent 6c9d1c4953
commit 2e79c8d770
4 changed files with 15 additions and 5 deletions

View File

@ -2,6 +2,7 @@ package com.gmail.nossr50.listeners;
import org.bukkit.OfflinePlayer;
import org.bukkit.block.Block;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.AnimalTamer;
import org.bukkit.entity.Entity;
import org.bukkit.entity.FallingBlock;
@ -21,10 +22,12 @@ import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.entity.EntityShootBowEvent;
import org.bukkit.event.entity.EntityTameEvent;
import org.bukkit.event.entity.EntityTargetEvent;
import org.bukkit.event.entity.ExplosionPrimeEvent;
import org.bukkit.event.entity.FoodLevelChangeEvent;
import org.bukkit.inventory.ItemStack;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
@ -51,6 +54,15 @@ public class EntityListener implements Listener {
this.plugin = plugin;
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onEntityShootBow(EntityShootBowEvent event) {
ItemStack bow = event.getBow();
if (bow != null && bow.containsEnchantment(Enchantment.ARROW_INFINITE)) {
event.getProjectile().setMetadata(mcMMO.infiniteArrowKey, mcMMO.metadataValue);
}
}
/**
* Monitor EntityChangeBlock events.
*

View File

@ -94,6 +94,7 @@ public class mcMMO extends JavaPlugin {
public final static String customNameKey = "mcMMO: Custom Name";
public final static String customVisibleKey = "mcMMO: Name Visibility";
public final static String droppedItemKey = "mcMMO: Tracked Item";
public final static String infiniteArrowKey = "mcMMO: Infinite Arrow";
public static FixedMetadataValue metadataValue;

View File

@ -1,7 +1,6 @@
package com.gmail.nossr50.skills.archery;
import org.bukkit.Location;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffect;
@ -30,9 +29,7 @@ public class ArcheryManager extends SkillManager {
}
public boolean canTrackArrows() {
Player player = getPlayer();
return !(player.getItemInHand().containsEnchantment(Enchantment.ARROW_INFINITE)) && Permissions.arrowRetrieval(player);
return Permissions.arrowRetrieval(getPlayer());
}
/**

View File

@ -245,7 +245,7 @@ public final class CombatUtils {
event.setDamage(archeryManager.dazeCheck((Player) target, event.getDamage()));
}
if (archeryManager.canTrackArrows()) {
if (!damager.hasMetadata(mcMMO.infiniteArrowKey) && archeryManager.canTrackArrows()) {
archeryManager.trackArrows(target);
}