Java Code Examples for org.bukkit.event.entity.EntityShootBowEvent#getProjectile()
The following examples show how to use
org.bukkit.event.entity.EntityShootBowEvent#getProjectile() .
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: SlimefunBowListener.java From Slimefun4 with GNU General Public License v3.0 | 5 votes |
@EventHandler public void onBowUse(EntityShootBowEvent e) { if (e.getEntity() instanceof Player && e.getProjectile() instanceof Arrow) { SlimefunItem bow = SlimefunItem.getByItem(e.getBow()); if (bow instanceof SlimefunBow) { projectiles.put(e.getProjectile().getUniqueId(), (SlimefunBow) bow); } } }
Example 2
Source File: Volley.java From ce with GNU Lesser General Public License v3.0 | 5 votes |
private void volley(EntityShootBowEvent e, ItemStack item, int lvl) { Player p = (Player) e.getEntity(); int amount = 1 + 2 * lvl; // Keep amount of arrows uneven, 2 extra arrows in a volley per level. Arrow oldArrow = (Arrow) e.getProjectile(); int fireTicks = oldArrow.getFireTicks(); int knockbackStrength = oldArrow.getKnockbackStrength(); boolean critical = oldArrow.isCritical(); String metadata = oldArrow.getMetadata("ce.bow.enchantment").get(0).asString(); double angleBetweenArrows = (CONE_DEGREES / (amount - 1)) * Math.PI / 180; double pitch = (p.getLocation().getPitch() + 90) * Math.PI / 180; double yaw = (p.getLocation().getYaw() + 90 - CONE_DEGREES / 2) * Math.PI / 180; // Starting direction values for the cone, each arrow increments it's direction on these values. double sZ = Math.cos(pitch); for (int i = 0; i < amount; i++) { // spawn all arrows in a cone of 90 degrees (equally distributed).; double nX = Math.sin(pitch) * Math.cos(yaw + angleBetweenArrows * i); double nY = Math.sin(pitch) * Math.sin(yaw + angleBetweenArrows * i); Vector newDir = new Vector(nX, sZ, nY); Arrow arrow = p.launchProjectile(Arrow.class); arrow.setShooter(p); arrow.setVelocity(newDir.normalize().multiply(oldArrow.getVelocity().length())); // Need to make sure arrow has same speed as original arrow. arrow.setFireTicks(fireTicks); // Set the new arrows on fire if the original one was arrow.setKnockbackStrength(knockbackStrength); arrow.setCritical(critical); if (i == 0) { if (p.getGameMode().equals(GameMode.CREATIVE)) arrow.setMetadata("ce.Volley", new FixedMetadataValue(getPlugin(), null)); //Control metadata to prevent players from duplicating arrows } else { arrow.setMetadata("ce.Volley", new FixedMetadataValue(getPlugin(), null)); //Control metadata to prevent players from duplicating arrows } arrow.setMetadata("ce.bow.enchantment", new FixedMetadataValue(getPlugin(), metadata)); } oldArrow.remove(); // Remove original arrow. }
Example 3
Source File: CustomItemListener.java From NBTEditor with GNU General Public License v3.0 | 5 votes |
@EventHandler private void entityShootBow(EntityShootBowEvent event) { if (event.getEntity() instanceof Player) { Player player = (Player) event.getEntity(); CustomItem customItem = CustomItemManager.getCustomItem(event.getBow()); if (verifyCustomItem(customItem, player, false)) { DelayedPlayerDetails details = new DelayedPlayerDetails(event.getBow(), player); ((CustomBow) customItem).onShootBow(event, details); if (!event.isCancelled() && event.getProjectile() instanceof Projectile) { details.lock(); event.getProjectile().setMetadata("CustomItem-bow", new FixedMetadataValue(CustomItemManager._plugin, new Object[] { customItem, details })); } } } }
Example 4
Source File: ModifyBowProjectileMatchModule.java From PGM with GNU Affero General Public License v3.0 | 4 votes |
@EventHandler(ignoreCancelled = true) public void changeBowProjectile(EntityShootBowEvent event) { Plugin plugin = PGM.get(); Entity newProjectile; if (this.cls == Arrow.class && event.getProjectile() instanceof Arrow) { // Don't change the projectile if it's an Arrow and the custom entity type is also Arrow newProjectile = event.getProjectile(); } else { // Replace the projectile Projectile oldEntity = (Projectile) event.getProjectile(); if (Projectile.class.isAssignableFrom(this.cls)) { newProjectile = event.getEntity().launchProjectile((Class<? extends Projectile>) this.cls); } else { World world = event.getEntity().getWorld(); newProjectile = world.spawn(oldEntity.getLocation(), this.cls); } event.setProjectile(newProjectile); // Copy some things from the old projectile newProjectile.setVelocity(oldEntity.getVelocity()); newProjectile.setFallDistance(oldEntity.getFallDistance()); newProjectile.setFireTicks(oldEntity.getFireTicks()); if (newProjectile instanceof Projectile) { ((Projectile) newProjectile).setShooter(oldEntity.getShooter()); ((Projectile) newProjectile).setBounce(oldEntity.doesBounce()); } // Save some special properties of Arrows if (oldEntity instanceof Arrow) { Arrow arrow = (Arrow) oldEntity; newProjectile.setMetadata("critical", new FixedMetadataValue(plugin, arrow.isCritical())); newProjectile.setMetadata( "knockback", new FixedMetadataValue(plugin, arrow.getKnockbackStrength())); newProjectile.setMetadata( "damage", new FixedMetadataValue(plugin, arrow.spigot().getDamage())); } } // Tag the projectile as custom newProjectile.setMetadata("customProjectile", new FixedMetadataValue(plugin, true)); match.callEvent(new EntityLaunchEvent(newProjectile, event.getEntity())); }
Example 5
Source File: ModifyBowProjectileMatchModule.java From ProjectAres with GNU Affero General Public License v3.0 | 4 votes |
@EventHandler(ignoreCancelled = true) public void changeBowProjectile(EntityShootBowEvent event) { Plugin plugin = this.getMatch().getPlugin(); Entity newProjectile; if(this.projectile == Arrow.class && event.getProjectile() instanceof Arrow) { // Don't change the projectile if it's an Arrow and the custom entity type is also Arrow newProjectile = event.getProjectile(); } else { // Replace the projectile World world = event.getEntity().getWorld(); Projectile oldEntity = (Projectile) event.getProjectile(); if(Projectile.class.isAssignableFrom(projectile)) { // Ender Pearls need to be soawned this way, otherwise they will hit the shooter sometimes newProjectile = event.getEntity().launchProjectile(projectile.asSubclass(Projectile.class), oldEntity.getVelocity()); } else { newProjectile = world.spawn(oldEntity.getLocation(), projectile); newProjectile.setVelocity(oldEntity.getVelocity()); } event.setProjectile(newProjectile); // Copy some things from the old projectile newProjectile.setFallDistance(oldEntity.getFallDistance()); newProjectile.setFireTicks(oldEntity.getFireTicks()); if(newProjectile instanceof Projectile) { ((Projectile) newProjectile).setShooter(oldEntity.getShooter()); ((Projectile) newProjectile).setBounce(oldEntity.doesBounce()); } // Save some special properties of Arrows if(oldEntity instanceof Arrow) { Arrow arrow = (Arrow) oldEntity; newProjectile.setMetadata("critical", new FixedMetadataValue(plugin, arrow.isCritical())); newProjectile.setMetadata("knockback", new FixedMetadataValue(plugin, arrow.getKnockbackStrength())); newProjectile.setMetadata("damage", new FixedMetadataValue(plugin, arrow.getDamage())); } } // Tag the projectile as custom newProjectile.setMetadata("customProjectile", new FixedMetadataValue(plugin, true)); getMatch().callEvent(new EntityLaunchEvent(newProjectile, event.getEntity())); }
Example 6
Source File: ItemNewBow.java From Carbon-2 with GNU Lesser General Public License v3.0 | 4 votes |
@Override public void a(ItemStack itemstack, World world, EntityHuman player, int usedFor) { final boolean flag = player.abilities.canInstantlyBuild || EnchantmentManager.getEnchantmentLevel(Enchantment.ARROW_INFINITE.id, itemstack) > 0; int arrowSlot = this.findArrowSlot(player.inventory); if (flag || arrowSlot != -1) { ItemStack arrowItemStack = arrowSlot != -1 ? player.inventory.getItem(arrowSlot) : new ItemStack(Items.ARROW); final int j = this.d(itemstack) - usedFor; float ready = j / 20.0f; ready = (ready * ready + ready * 2.0f) / 3.0f; if (ready < 0.1) { return; } if (ready > 1.0f) { ready = 1.0f; } EntityArrow entityarrow = null; if (arrowItemStack.getItem() instanceof ItemNewArrow) { entityarrow = ((ItemNewArrow) arrowItemStack.getItem()).createArrowEntity(world, arrowItemStack, player, ready); } else { entityarrow = new EntityArrow(world, player, ready * 2.0f); } if (ready == 1.0f) { entityarrow.setCritical(true); } final int k = EnchantmentManager.getEnchantmentLevel(Enchantment.ARROW_DAMAGE.id, itemstack); if (k > 0) { entityarrow.b(entityarrow.j() + k * 0.5 + 0.5); } final int l = EnchantmentManager.getEnchantmentLevel(Enchantment.ARROW_KNOCKBACK.id, itemstack); if (l > 0) { entityarrow.setKnockbackStrength(l); } if (EnchantmentManager.getEnchantmentLevel(Enchantment.ARROW_FIRE.id, itemstack) > 0) { final EntityCombustEvent event = new EntityCombustEvent(entityarrow.getBukkitEntity(), 100); entityarrow.world.getServer().getPluginManager().callEvent(event); if (!event.isCancelled()) { entityarrow.setOnFire(event.getDuration()); } } final EntityShootBowEvent event2 = CraftEventFactory.callEntityShootBowEvent(player, itemstack, entityarrow, ready); if (event2.isCancelled()) { event2.getProjectile().remove(); return; } if (event2.getProjectile() == entityarrow.getBukkitEntity()) { world.addEntity(entityarrow); } itemstack.damage(1, player); world.makeSound(player, "random.bow", 1.0f, 1.0f / (ItemNewBow.g.nextFloat() * 0.4f + 1.2f) + ready * 0.5f); if (flag) { entityarrow.fromPlayer = 2; } else { player.inventory.a(Items.ARROW); } player.b(StatisticList.USE_ITEM_COUNT[Item.getId(this)]); } }
Example 7
Source File: ItemNewBow.java From Carbon-2 with GNU Lesser General Public License v3.0 | 4 votes |
@Override public void a(ItemStack itemstack, World world, EntityHuman player, int usedFor) { final boolean flag = player.abilities.canInstantlyBuild || EnchantmentManager.getEnchantmentLevel(Enchantment.ARROW_INFINITE.id, itemstack) > 0; int arrowSlot = this.findArrowSlot(player.inventory); if (flag || arrowSlot != -1) { ItemStack arrowItemStack = arrowSlot != -1 ? player.inventory.getItem(arrowSlot) : new ItemStack(Items.ARROW); final int j = this.d(itemstack) - usedFor; float ready = j / 20.0f; ready = (ready * ready + ready * 2.0f) / 3.0f; if (ready < 0.1) { return; } if (ready > 1.0f) { ready = 1.0f; } EntityArrow entityarrow = null; if (arrowItemStack.getItem() instanceof ItemNewArrow) { entityarrow = ((ItemNewArrow) arrowItemStack.getItem()).createArrowEntity(world, arrowItemStack, player, ready); } else { entityarrow = new EntityArrow(world, player, ready * 2.0f); } if (ready == 1.0f) { entityarrow.setCritical(true); } final int k = EnchantmentManager.getEnchantmentLevel(Enchantment.ARROW_DAMAGE.id, itemstack); if (k > 0) { entityarrow.b(entityarrow.j() + k * 0.5 + 0.5); } final int l = EnchantmentManager.getEnchantmentLevel(Enchantment.ARROW_KNOCKBACK.id, itemstack); if (l > 0) { entityarrow.setKnockbackStrength(l); } if (EnchantmentManager.getEnchantmentLevel(Enchantment.ARROW_FIRE.id, itemstack) > 0) { final EntityCombustEvent event = new EntityCombustEvent(entityarrow.getBukkitEntity(), 100); entityarrow.world.getServer().getPluginManager().callEvent(event); if (!event.isCancelled()) { entityarrow.setOnFire(event.getDuration()); } } final EntityShootBowEvent event2 = CraftEventFactory.callEntityShootBowEvent(player, itemstack, entityarrow, ready); if (event2.isCancelled()) { event2.getProjectile().remove(); return; } if (event2.getProjectile() == entityarrow.getBukkitEntity()) { world.addEntity(entityarrow); } itemstack.damage(1, player); world.makeSound(player, "random.bow", 1.0f, 1.0f / (ItemNewBow.g.nextFloat() * 0.4f + 1.2f) + ready * 0.5f); if (flag) { entityarrow.fromPlayer = 2; } else { player.inventory.a(Items.ARROW); } player.b(StatisticList.USE_ITEM_COUNT[Item.getId(this)]); } }
Example 8
Source File: Minigun.java From ce with GNU Lesser General Public License v3.0 | 4 votes |
@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; }