Java Code Examples for org.bukkit.entity.Player#launchProjectile()
The following examples show how to use
org.bukkit.entity.Player#launchProjectile() .
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: ThrowableFireballListener.java From BedWars with GNU Lesser General Public License v3.0 | 5 votes |
@EventHandler public void onFireballThrow(PlayerInteractEvent event) { Player player = event.getPlayer(); if (!Main.isPlayerInGame(player)) { return; } if (event.getItem() != null) { ItemStack stack = event.getItem(); String unhash = APIUtils.unhashFromInvisibleStringStartsWith(stack, THROWABLE_FIREBALL_PREFIX); if (unhash != null && (event.getAction() == Action.RIGHT_CLICK_BLOCK || event.getAction() == Action.RIGHT_CLICK_AIR)) { String[] properties = unhash.split(":"); double damage = Double.parseDouble(properties[2]); float explosion = (float) Double.parseDouble(properties[2]); Fireball fireball = player.launchProjectile(Fireball.class); fireball.setIsIncendiary(false); fireball.setYield(explosion); Main.registerGameEntity(fireball, Main.getPlayerGameProfile(player).getGame()); event.setCancelled(true); if (stack.getAmount() > 1) { stack.setAmount(stack.getAmount() - 1); } else { player.getInventory().remove(stack); } player.updateInventory(); } } }
Example 2
Source File: ThrowableFireballListener.java From BedWars with GNU Lesser General Public License v3.0 | 5 votes |
@EventHandler public void onFireballThrow(PlayerInteractEvent event) { Player player = event.getPlayer(); if (!Main.isPlayerInGame(player)) { return; } if (event.getItem() != null) { ItemStack stack = event.getItem(); String unhash = APIUtils.unhashFromInvisibleStringStartsWith(stack, THROWABLE_FIREBALL_PREFIX); if (unhash != null && (event.getAction() == Action.RIGHT_CLICK_BLOCK || event.getAction() == Action.RIGHT_CLICK_AIR)) { String[] properties = unhash.split(":"); double damage = Double.parseDouble(properties[2]); float explosion = (float) Double.parseDouble(properties[2]); Fireball fireball = player.launchProjectile(Fireball.class); fireball.setIsIncendiary(false); fireball.setYield(explosion); Main.registerGameEntity(fireball, Main.getPlayerGameProfile(player).getGame()); event.setCancelled(true); if (stack.getAmount() > 1) { stack.setAmount(stack.getAmount() - 1); } else { player.getInventory().remove(stack); } player.updateInventory(); } } }
Example 3
Source File: MagicEyeOfEnder.java From Slimefun4 with GNU General Public License v3.0 | 5 votes |
@Override public ItemUseHandler getItemHandler() { return e -> { e.cancel(); Player p = e.getPlayer(); if (hasArmor(p.getInventory())) { p.launchProjectile(EnderPearl.class); p.getWorld().playSound(p.getLocation(), Sound.ENTITY_ENDERMAN_TELEPORT, 1, 1); } }; }
Example 4
Source File: PotionLauncher.java From ce with GNU Lesser General Public License v3.0 | 5 votes |
@Override public boolean effect(Event event, Player player) { int slot = player.getInventory().getHeldItemSlot(); ItemStack potion = player.getInventory().getItem(slot + 1); Location loc = player.getLocation(); if (potion != null && potion.getType().toString().contains("POTION")) { ThrownPotion tp = player.launchProjectile(ThrownPotion.class); EffectManager.playSound(loc, "ENTITY_GENERIC_EXPLODE", 0.5f, 2f); try { tp.setItem(potion); } catch (IllegalArgumentException ex) { ItemStack pt = potion.clone(); if (potion.getType().equals(Material.POTION) || potion.getType().equals(Material.LINGERING_POTION)) pt.setType(Material.SPLASH_POTION); tp.setItem(pt); } tp.setBounce(false); tp.setVelocity(loc.getDirection().multiply(ProjectileSpeedMultiplier)); if (!player.getGameMode().equals(GameMode.CREATIVE)) { potion.setAmount(potion.getAmount() - 1); player.getInventory().setItem(slot + 1, potion); player.updateInventory(); } return true; } else { player.sendMessage(ChatColor.RED + "You need a Potion in the slot to the right of the Potion Launcher!"); player.getWorld().playEffect(loc, Effect.CLICK1, 5); } return false; }
Example 5
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 6
Source File: NecromancersStaff.java From ce with GNU Lesser General Public License v3.0 | 4 votes |
@Override public boolean effect(Event event, Player player) { PlayerInteractEvent e = (PlayerInteractEvent) event; ItemMeta im = e.getPlayer().getItemInHand().getItemMeta(); List<String> lore = new ArrayList<String>(); if (!im.hasLore()) { lore.add(spells.get(0)); im.setLore(lore); e.getPlayer().getItemInHand().setItemMeta(im); } lore = im.getLore(); int lastElement = lore.size() - 1; if (e.getAction().toString().startsWith("LEFT")) { int nextSpellIndex = spells.indexOf(lore.get(lastElement)) + 1; if (nextSpellIndex == 3) nextSpellIndex = 0; String nextSpell = spells.get(nextSpellIndex); lore.set(lastElement, nextSpell); im.setLore(lore); e.getPlayer().getItemInHand().setItemMeta(im); player.sendMessage(ChatColor.GRAY + "Changed Spell to " + nextSpell.split(": ")[1] + ChatColor.GRAY + "."); player.getWorld().playEffect(player.getLocation(), Effect.CLICK1, 10); } else if (e.getAction().toString().startsWith("RIGHT")) { int spell = -1; int cost = -1; int cooldown = -1; // Get all values if (lore.get(lastElement).equals(spells.get(0))) { spell = 0; cost = WitherCost; cooldown = WitherCooldown; } else if (lore.get(lastElement).equals(spells.get(1))) { spell = 1; cost = FireballCost; cooldown = FireballCooldown; } else if (lore.get(lastElement).equals(spells.get(2))) { spell = 2; cost = LightningCost; cooldown = LightningCooldown; } // Apply costs if (player.getInventory().contains(Fuel, cost) || player.getGameMode().equals(GameMode.CREATIVE)) { if (!player.getGameMode().equals(GameMode.CREATIVE)) { ItemStack mana = new ItemStack(Fuel, cost); player.getInventory().removeItem(mana); player.updateInventory(); } Location l = player.getLocation(); // Apply effect if (spell == 0) { if (Tools.checkWorldGuard(l, player, "PVP", true)) { WitherSkull ws = player.launchProjectile(WitherSkull.class); ws.setVelocity(l.getDirection().multiply(2)); if (!Main.createExplosions) ws.setMetadata("ce.explosive", new FixedMetadataValue(getPlugin(), null)); EffectManager.playSound(l, "ENTITY_WITHER_IDLE", 0.5f, 10f); } else { EffectManager.playSound(l, "ENTITY_CAT_HISS", 0.3f, 5f); } } else if (spell == 1) { player.launchProjectile(SmallFireball.class).setVelocity(l.getDirection().multiply(1.5)); EffectManager.playSound(l, "ENTITY_BLAZE_HIT", 0.2f, 0f); } else if (spell == 2) { Location target = player.getTargetBlock((Set<Material>) null, 20).getLocation(); player.getWorld().strikeLightning(target); if (Tools.checkWorldGuard(l, player, "TNT", true)) player.getWorld().createExplosion(target, 1); EffectManager.playSound(target, "ENTITY_ENDERDRAGON_GROWL", 0.5f, 2f); } // Generate the cooldown based on the cooldown value generateCooldown(player, cooldown); } else { player.sendMessage(ChatColor.RED + "You need " + cost + " " + Fuel.toString().toLowerCase().replace("_", " ") + " to cast this spell."); } } return false; // The Staff generates it's own cooldowns, so it always // returns false }