org.bukkit.event.entity.ProjectileLaunchEvent Java Examples
The following examples show how to use
org.bukkit.event.entity.ProjectileLaunchEvent.
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: KitMatchModule.java From PGM with GNU Affero General Public License v3.0 | 6 votes |
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onGrenadeLaunch(final ProjectileLaunchEvent event) { if (event.getEntity().getShooter() instanceof Player) { Player player = (Player) event.getEntity().getShooter(); ItemStack stack = player.getItemInHand(); if (stack != null) { // special case for grenade arrows if (stack.getType() == Material.BOW) { int arrows = player.getInventory().first(Material.ARROW); if (arrows == -1) return; stack = player.getInventory().getItem(arrows); } Grenade grenade = Grenade.ITEM_TAG.get(stack); if (grenade != null) { grenade.set(PGM.get(), event.getEntity()); } } } }
Example #2
Source File: EntityListenerTest.java From AuthMeReloaded with GNU General Public License v3.0 | 6 votes |
@Test public void shouldHandleOldShooterMethod() { // given Projectile projectile = mock(Projectile.class); Player shooter = mock(Player.class); given(projectile.getShooter()).willReturn(shooter); ProjectileLaunchEvent event = new ProjectileLaunchEvent(projectile); given(listenerService.shouldCancelEvent(shooter)).willReturn(true); // when listener.onProjectileLaunch(event); // then verify(listenerService).shouldCancelEvent(shooter); assertThat(event.isCancelled(), equalTo(true)); }
Example #3
Source File: TridentListener.java From MineTinker with GNU General Public License v3.0 | 6 votes |
@EventHandler(ignoreCancelled = true) public void onTridentLaunch(ProjectileLaunchEvent event) { if (!(event.getEntity().getShooter() instanceof Player)) { return; } if (!(event.getEntity() instanceof Trident)) { return; } Player player = (Player) event.getEntity().getShooter(); ItemStack trident = player.getInventory().getItemInMainHand().clone(); if (!ModManager.instance().isToolViable(trident)) { return; } ModManager.instance().addExp(player, trident, -20000); //trident is a item clone and only for triggering modifier effects //this makes sure that the item duplicate does not get any level ups TridentToItemStack.put((Trident) event.getEntity(), trident); }
Example #4
Source File: EntityListenerTest.java From AuthMeReloaded with GNU General Public License v3.0 | 6 votes |
@Test public void shouldRejectProjectileLaunchFromUnauthed() { // given Projectile projectile = mock(Projectile.class); Player player = mock(Player.class); given(projectile.getShooter()).willReturn(player); ProjectileLaunchEvent event = mock(ProjectileLaunchEvent.class); given(event.getEntity()).willReturn(projectile); given(listenerService.shouldCancelEvent(player)).willReturn(true); // when listener.onProjectileLaunch(event); // then verify(listenerService).shouldCancelEvent(player); verify(event).setCancelled(true); }
Example #5
Source File: EntityListenerTest.java From AuthMeReloaded with GNU General Public License v3.0 | 6 votes |
@Test public void shouldAllowProjectileLaunchFromAuthedHuman() { // given Projectile projectile = mock(Projectile.class); Player player = mock(Player.class); given(projectile.getShooter()).willReturn(player); ProjectileLaunchEvent event = mock(ProjectileLaunchEvent.class); given(event.getEntity()).willReturn(projectile); given(listenerService.shouldCancelEvent(player)).willReturn(false); // when listener.onProjectileLaunch(event); // then verify(listenerService).shouldCancelEvent(player); verify(event, never()).setCancelled(anyBoolean()); }
Example #6
Source File: EntityListenerTest.java From AuthMeReloaded with GNU General Public License v3.0 | 6 votes |
@Test public void shouldAllowProjectileLaunchFromNonHuman() { // given Projectile projectile = mock(Projectile.class); ProjectileSource source = mock(ProjectileSource.class); given(projectile.getShooter()).willReturn(source); ProjectileLaunchEvent event = mock(ProjectileLaunchEvent.class); given(event.getEntity()).willReturn(projectile); // when listener.onProjectileLaunch(event); // then verifyNoInteractions(listenerService); verify(event, never()).setCancelled(anyBoolean()); }
Example #7
Source File: GrenadeListener.java From ProjectAres with GNU Affero General Public License v3.0 | 6 votes |
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onGrenadeLaunch(final ProjectileLaunchEvent event) { if (event.getEntity().getShooter() instanceof Player) { Player player = (Player) event.getEntity().getShooter(); ItemStack stack = player.getItemInHand(); if(stack != null) { // special case for grenade arrows if (stack.getType() == Material.BOW) { int arrows = player.getInventory().first(Material.ARROW); if (arrows == -1) return; stack = player.getInventory().getItem(arrows); } Grenade grenade = Grenade.ITEM_TAG.get(stack); if(grenade != null) { grenade.set(plugin, event.getEntity()); } } } }
Example #8
Source File: ParticleEffectListener.java From SkyWarsReloaded with GNU General Public License v3.0 | 6 votes |
@EventHandler public void projectileLaunch(ProjectileLaunchEvent e) { Projectile projectile = e.getEntity(); if (projectile instanceof Snowball || projectile instanceof Egg || projectile instanceof Arrow) { if (projectile.getShooter() instanceof Player) { Player player = (Player) projectile.getShooter(); GameMap gMap = MatchManager.get().getPlayerMap(player); if (gMap != null) { PlayerStat ps = PlayerStat.getPlayerStats(player.getUniqueId()); if (ps != null) { String key = ps.getProjectileEffect(); ProjectileEffectOption peo = (ProjectileEffectOption) ProjectileEffectOption.getPlayerOptionByKey(key); if (peo != null) { List<ParticleEffect> effects = peo.getEffects(); if (key != null && effects != null) { if (!key.equalsIgnoreCase("none")) { SkyWarsReloaded.getOM().addProjectile(projectile, effects); } } } } } } } }
Example #9
Source File: LivingEntityShopListener.java From Shopkeepers with GNU General Public License v3.0 | 5 votes |
@EventHandler(ignoreCancelled = true) void onEntityLaunchProjectile(ProjectileLaunchEvent event) { ProjectileSource source = event.getEntity().getShooter(); if (source instanceof LivingEntity && plugin.isShopkeeper((LivingEntity) source)) { event.setCancelled(true); } }
Example #10
Source File: EntityListener.java From AuthMeReloaded with GNU General Public License v3.0 | 5 votes |
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST) public void onProjectileLaunch(ProjectileLaunchEvent event) { final Projectile projectile = event.getEntity(); ProjectileSource shooter = projectile.getShooter(); if (shooter instanceof Player && listenerService.shouldCancelEvent((Player) shooter)) { event.setCancelled(true); } }
Example #11
Source File: ProjectileParticlesModule.java From CardinalPGM with MIT License | 5 votes |
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onArrowLaunch(ProjectileLaunchEvent event) { if (event.getEntity() instanceof Arrow) ((Arrow) event.getEntity()).setCritical(false); if (event.getActor() instanceof Player) createParticlesFor(event.getEntity(), (Player) event.getActor()); }
Example #12
Source File: MainListener.java From HolographicDisplays with GNU General Public License v3.0 | 5 votes |
@EventHandler (priority = EventPriority.MONITOR, ignoreCancelled = false) public void onProjectileLaunch(ProjectileLaunchEvent event) { if (nmsManager.isNMSEntityBase(event.getEntity())) { if (event.isCancelled()) { event.setCancelled(false); } } }
Example #13
Source File: BukkitPlotListener.java From PlotMe-Core with GNU General Public License v3.0 | 5 votes |
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public void onProjectileLaunchEvent(ProjectileLaunchEvent event) { if (event.getEntity() instanceof Player) { PlotMapInfo pmi = manager.getMap(BukkitUtil.adapt(event.getEntity().getWorld())); if (pmi != null && !pmi.canUseProjectiles()) { event.getEntity().sendMessage(api.C("ErrCannotUseEggs")); event.setCancelled(true); } } }
Example #14
Source File: ServerListener.java From ZombieEscape with GNU General Public License v2.0 | 5 votes |
@EventHandler public void onThrow(ProjectileLaunchEvent event) { Projectile projectile = event.getEntity(); if (projectile instanceof Snowball && projectile.getShooter() instanceof Player) { Player player = (Player) projectile.getShooter(); if (player.getItemInHand().getType() == Material.SNOW_BALL && player.getItemInHand().getAmount() == 0) { // ran out of snowballs new ReloadTask(player).runTaskLater(plugin, 20 * 3); Messages.RELOADING.send(player); } } }
Example #15
Source File: ExpCapListener.java From NyaaUtils with MIT License | 5 votes |
@EventHandler public void onExpCapThrown(ProjectileLaunchEvent event) { if (!cfg.expcap_thron_enabled) return; if (event.getEntity() instanceof ThrownExpBottle) { ProjectileSource shooter = event.getEntity().getShooter(); if (shooter instanceof Player) { event.getEntity().setMetadata("nu_expcap_exp", new FixedMetadataValue(plugin, thrownExpMap.computeIfAbsent(((Player) shooter).getUniqueId(), uuid -> 0) ) ); } } }
Example #16
Source File: ParticleListener.java From NyaaUtils with MIT License | 5 votes |
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onProjectileLaunch(ProjectileLaunchEvent event) { if (plugin.cfg.particles_type_other && event.getEntity() != null && event.getEntity().getShooter() instanceof Player) { if (!plugin.particleTask.bypassPlayers.contains(((Player) event.getEntity().getShooter()).getUniqueId())) { projectiles.add(event.getEntity().getUniqueId()); } } }
Example #17
Source File: Pyro.java From AnnihilationPro with MIT License | 5 votes |
@EventHandler(priority = EventPriority.HIGHEST,ignoreCancelled = true) public void arrowLaunch(final ProjectileLaunchEvent event) { if(event.getEntityType() == EntityType.ARROW) { ProjectileSource shooter = event.getEntity().getShooter(); if(shooter instanceof Player) { AnniPlayer p = AnniPlayer.getPlayer(((Player) shooter).getUniqueId()); if(p != null && p.getKit().equals(this)) event.getEntity().setFireTicks(999999); } } }
Example #18
Source File: ProjectileTrailMatchModule.java From ProjectAres with GNU Affero General Public License v3.0 | 5 votes |
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onProjectileLaunch(ProjectileLaunchEvent event) { match.player(event.getActor()).ifPresent(shooter -> { final Projectile projectile = event.getEntity(); projectile.setMetadata(TRAIL_META, new FixedMetadataValue(PGM.get(), shooter.getParty().getFullColor())); // Set critical metadata to false in order to remove default particle trail. // The metadata will be restored just before the arrow hits something. if(projectile instanceof Arrow) { final Arrow arrow = (Arrow) projectile; arrow.setMetadata(CRITICAL_META, new FixedMetadataValue(PGM.get(), arrow.isCritical())); arrow.setCritical(false); } }); }
Example #19
Source File: StaminaMatchModule.java From ProjectAres with GNU Affero General Public License v3.0 | 5 votes |
@EventHandler(ignoreCancelled = true) public void onPlayerShoot(ProjectileLaunchEvent event) { if(event.getEntity().getShooter() instanceof Player) { PlayerStaminaState state = states.get(event.getEntity().getShooter()); if(state != null) state.onEvent(event); } }
Example #20
Source File: ArcherySymptom.java From ProjectAres with GNU Affero General Public License v3.0 | 5 votes |
@Override public void onShoot(ProjectileLaunchEvent event) { super.onShoot(event); if(event.getEntity() instanceof Arrow) { Arrow arrow = (Arrow) event.getEntity(); arrow.setDamage(modifier.apply(arrow.getDamage())); arrow.setVelocity(arrow.getVelocity().multiply(modifier.apply(1d))); } }
Example #21
Source File: PlayerStaminaState.java From ProjectAres with GNU Affero General Public License v3.0 | 5 votes |
void onEvent(ProjectileLaunchEvent event) { for(StaminaSymptom symptom : getActiveSymptoms()) { symptom.onShoot(event); } mutateStamina(options.mutators.archery); }
Example #22
Source File: Infinity.java From MineTinker with GNU General Public License v3.0 | 5 votes |
@EventHandler public void onShoot(ProjectileLaunchEvent event) { if (!this.isAllowed()) return; Projectile arrow = event.getEntity(); if (!(arrow instanceof Arrow)) return; if (!(arrow.getShooter() instanceof Player)) return; Player player = (Player) arrow.getShooter(); if (!player.hasPermission("minetinker.modifiers.infinity.use")) return; ItemStack tool = player.getInventory().getItemInMainHand(); if (!ToolType.CROSSBOW.contains(tool.getType())) return; if (!modManager.isToolViable(tool)) return; if (!modManager.hasMod(tool, this)) return; if(!((Arrow) arrow).hasCustomEffects()) { if (player.getInventory().addItem(new ItemStack(Material.ARROW, 1)).size() != 0) { //adds items to (full) inventory player.getWorld().dropItem(player.getLocation(), new ItemStack(Material.ARROW, 1)); //drops item when inventory is full } // no else as it gets added in if ((Arrow) arrow).setPickupStatus(AbstractArrow.PickupStatus.CREATIVE_ONLY); ChatWriter.logModifier(player, event, this, tool); } }
Example #23
Source File: ProjectileTracker.java From ProjectAres with GNU Affero General Public License v3.0 | 4 votes |
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onProjectileLaunch(ProjectileLaunchEvent event) { handleLaunch(event.getEntity(), event.getEntity().getShooter()); }
Example #24
Source File: MultiShot.java From MineTinker with GNU General Public License v3.0 | 4 votes |
@EventHandler public void onShoot(ProjectileLaunchEvent event) { if (!this.isAllowed()) { return; } Projectile arrow = event.getEntity(); if (!(arrow instanceof Arrow)) { return; } if (!(arrow.getShooter() instanceof Player)) { return; } Player player = (Player) arrow.getShooter(); if (!player.hasPermission("minetinker.modifiers.multishot.use")) { return; } ItemStack tool = player.getInventory().getItemInMainHand(); if (ToolType.CROSSBOW.contains(tool.getType()) && getConfig().getBoolean("UseEnchantOnCrossbow")) { return; } if (!modManager.isToolViable(tool)) { return; } int modLevel = modManager.getModLevel(tool, this); if (modLevel <= 0) { return; } Vector vel = arrow.getVelocity().clone(); Location loc = arrow.getLocation().clone(); boolean hasInfinity = modManager.hasMod(tool, Infinity.instance()); boolean hasFiery = modManager.hasMod(tool, Fiery.instance()) && player.hasPermission("minetinker.modifiers.fiery.use"); ChatWriter.logModifier(player, event, this, tool, Fiery.instance().getKey() + "(" + hasFiery + ")", Infinity.instance().getKey() + "(" + hasInfinity + ")"); for (int i = 1; i <= modLevel; i++) { if (!player.getGameMode().equals(GameMode.CREATIVE)) { if (!hasInfinity && needsArrows) { if (!player.getInventory().contains(Material.ARROW)) { break; } for (ItemStack item : player.getInventory().getContents()) { if (item == null) { continue; } if (item.getType() == Material.ARROW) { item.setAmount(item.getAmount() - 1); break; } } } } Bukkit.getScheduler().runTaskLater(MineTinker.getPlugin(), () -> { Arrow arr = loc.getWorld().spawnArrow(loc, vel, (float) vel.length(), (float) spread); if(hasFiery) arr.setFireTicks(2000); arr.setShooter(player); if (hasInfinity || player.getGameMode().equals(GameMode.CREATIVE)) { arr.setPickupStatus(AbstractArrow.PickupStatus.CREATIVE_ONLY); } arr.setCritical(((Arrow) arrow).isCritical()); arr.setDamage(((Arrow) arrow).getDamage()); }, i); } }
Example #25
Source File: Magical.java From MineTinker with GNU General Public License v3.0 | 4 votes |
@EventHandler public void onShoot(ProjectileLaunchEvent event) { if (!this.isAllowed()) return; Projectile arrow = event.getEntity(); if (!(arrow instanceof Arrow)) return; if (!(arrow.getShooter() instanceof Player)) return; Player player = (Player) arrow.getShooter(); if (!player.hasPermission("minetinker.modifiers.magical.use")) return; ItemStack tool = player.getInventory().getItemInMainHand(); if (!modManager.isToolViable(tool)) return; int modLevel = modManager.getModLevel(tool, this); if (modLevel <= 0) return; if (PlayerInfo.getPlayerExp(player) < this.experienceCost) { event.setCancelled(true); return; } player.giveExp(- this.experienceCost); arrow.setBounce(true); ((Arrow) arrow).setColor(Color.PURPLE); ((Arrow) arrow).setPickupStatus(AbstractArrow.PickupStatus.CREATIVE_ONLY); arrow.setGravity(false); //arrow.setGlowing(true); Entity entity = player.getLocation().getWorld().spawnEntity(arrow.getLocation().add(arrow.getVelocity().normalize().multiply(-0.5)), EntityType.ENDERMITE); if (entity instanceof LivingEntity) { ((LivingEntity) entity).setRemoveWhenFarAway(true); //((LivingEntity) entity).setAI(false); can not move entity.setGravity(false); entity.setVelocity(arrow.getVelocity().multiply(this.multiplierArrowSpeed)); //does not work entity.setInvulnerable(true); entity.setSilent(true); ((LivingEntity) entity).setCollidable(false); for (int i = 5; i < 10 * 20; i = i + 5) { Bukkit.getScheduler().runTaskLater(MineTinker.getPlugin(), () -> { entity.teleport(arrow.getLocation().add(arrow.getVelocity().normalize().multiply(-0.4))); entity.setVelocity(arrow.getVelocity()); //does not work }, i); } } arrow.setCustomName(this.getKey() + ":" + modLevel + ":" + entity.getUniqueId()); arrow.addAttachment(MineTinker.getPlugin(), this.getKey() + ":" + modLevel, true); arrow.setVelocity(arrow.getVelocity().multiply(this.multiplierArrowSpeed)); ((Arrow) arrow).setDamage(((Arrow) arrow).getDamage() * Math.pow(this.multiplierDamagePerLevel, modLevel)); ChatWriter.logModifier(player, event, this, tool, "Cost(" + this.experienceCost + ")"); Bukkit.getScheduler().runTaskLater(MineTinker.getPlugin(), () -> { entity.remove(); arrow.remove(); }, 10 * 20L); //TODO: Find a way to hide the arrow from clients }
Example #26
Source File: Fiery.java From MineTinker with GNU General Public License v3.0 | 4 votes |
@EventHandler public void onShoot(ProjectileLaunchEvent event) { if (!this.isAllowed()) return; Projectile arrow = event.getEntity(); if (!(arrow instanceof Arrow)) return; if (!(arrow.getShooter() instanceof Player)) return; Player player = (Player) arrow.getShooter(); if(!player.hasPermission("minetinker.modifiers.fiery.use")) return; ItemStack tool = player.getInventory().getItemInMainHand(); if (!ToolType.CROSSBOW.contains(tool.getType())) return; if (!modManager.isToolViable(tool)) return; if (!modManager.hasMod(tool, this)) return; arrow.setFireTicks(2000); }
Example #27
Source File: ProjectileTracker.java From PGM with GNU Affero General Public License v3.0 | 4 votes |
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onProjectileLaunch(ProjectileLaunchEvent event) { handleLaunch(event.getEntity(), event.getEntity().getShooter()); }
Example #28
Source File: EntityEventHandler.java From GriefDefender with MIT License | 4 votes |
@EventHandler(priority = EventPriority.LOWEST) public void onProjectileSpawn(ProjectileLaunchEvent event) { handleEntitySpawn(event, null, event.getEntity()); }
Example #29
Source File: CEListener.java From ce with GNU Lesser General Public License v3.0 | 3 votes |
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void ProjectileLaunchEvent(ProjectileLaunchEvent e) { ProjectileSource shooter = e.getEntity().getShooter(); if (shooter instanceof Player) CEventHandler.handleEvent((Player) shooter, e, projectileThrow); }
Example #30
Source File: StaminaSymptom.java From ProjectAres with GNU Affero General Public License v3.0 | votes |
public void onShoot(ProjectileLaunchEvent event) {}