Java Code Examples for org.bukkit.entity.Arrow#hasMetadata()

The following examples show how to use org.bukkit.entity.Arrow#hasMetadata() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CEListener.java    From ce with GNU Lesser General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void antiArrowSpam(ProjectileHitEvent event) {

    // Destroys the Arrows of the Minigun
    if (event.getEntityType().equals(EntityType.ARROW)) {
        Arrow arrow = (Arrow) event.getEntity();
        ProjectileSource shooter = arrow.getShooter();
        if (shooter instanceof Player)
            if (arrow.hasMetadata("ce.minigunarrow"))
                if (((Player) shooter).getGameMode().equals(GameMode.CREATIVE))
                    arrow.remove();
    }

}
 
Example 2
Source File: Minigun.java    From ce with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public boolean effect(Event event, final Player player) {
	final EntityShootBowEvent e = (EntityShootBowEvent) event;
	Arrow oldArrow = (Arrow) e.getProjectile();
	e.setCancelled(true);
	addLock(player);
	
	
	String meta = null;
	if(oldArrow.hasMetadata("ce.bow.enchantment"))
		meta = oldArrow.getMetadata("ce.bow.enchantment").get(0).asString();
	
	
	final int fireTicks = oldArrow.getFireTicks();
	final int knockbackStrength = oldArrow.getKnockbackStrength();
	final boolean critical = oldArrow.isCritical();
	final String metadata = meta;
	
		new BukkitRunnable() {
			
			
			int lArrows = ArrowCountPerVolley;
			ItemStack last = player.getItemInHand();
			
			@Override
			public void run() {
				if (lArrows > 0) {
					if(player.getItemInHand().hasItemMeta() && player.getItemInHand().getItemMeta().equals(last.getItemMeta())) {
						if (player.getGameMode().equals(GameMode.CREATIVE) || player.getInventory().contains(Material.ARROW, 1)) {
							if (!player.getGameMode().equals(GameMode.CREATIVE)) {
								if(last.getDurability() < 380) {
									
									last.setDurability((short) (last.getDurability() + 1));
									last = player.getItemInHand();
									
								} else {
									
									ItemStack brokenItem = new ItemStack(Material.AIR);
									player.setItemInHand(brokenItem);
									player.getWorld().playEffect(player.getLocation(), Effect.ZOMBIE_DESTROY_DOOR, 10);
									EffectManager.playSound(player.getLocation(), "ENTITY_ITEM_BREAK", 0.4f, 0f);
									removeLock(player);
									this.cancel();
									
								}
							
							
								ItemStack arrows = new ItemStack(
									Material.ARROW, 1);
								player.getInventory().removeItem(
									arrows);
							}

							Arrow arrow = player.launchProjectile(Arrow.class);
							arrow.setBounce(false);
							arrow.setVelocity(player.getLocation().getDirection().multiply(5));
							arrow.setShooter(player);
							arrow.setFireTicks(fireTicks); // Set the new arrows on fire if the original one was 
							arrow.setKnockbackStrength(knockbackStrength);
							arrow.setCritical(critical);
							if(metadata != null)
								arrow.setMetadata("ce.bow.enchantment", new FixedMetadataValue(getPlugin(), metadata));
							arrow.setMetadata("ce.minigunarrow", new FixedMetadataValue(main, null));
							player.getWorld().playEffect(player.getLocation(),Effect.BOW_FIRE, 20);
							lArrows--;
							return;
							
						} else {
							
						player.sendMessage(ChatColor.RED + "Out of ammo!");
						player.getWorld().playEffect(player.getLocation(), Effect.CLICK2, 80);
						
						}
					}
				}
				
				removeLock(player);
				this.cancel();
				
			}
		}.runTaskTimer(main, 0l, 20/ShotsPerSecond);
		
		return true;
	
}