@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()); } } } }
/** * Launch 2 more arrows when one is launched * * @param event Event */ @EventHandler public void onProjectileLaunch(ProjectileLaunchEvent event) { if (event.getEntity().getType() != EntityType.ARROW || !(event.getEntity().getShooter() instanceof Player) || event.getEntity().hasMetadata("TAM")) return; final Vector velocity = event.getEntity().getVelocity(); for(int i = 0; i < 2; i++) { this.plugin.getServer().getScheduler().runTaskLater(this.plugin, () -> { EntityArrow entityArrow = new EntityArrow(((CraftWorld)event.getEntity().getWorld()).getHandle(), ((CraftLivingEntity)event.getEntity().getShooter()).getHandle(), 1F); entityArrow.shoot(((CraftLivingEntity)event.getEntity().getShooter()).getHandle().pitch, ((CraftLivingEntity)event.getEntity().getShooter()).getHandle().yaw, 0.0F, 3.0F, 1.0F); entityArrow.getBukkitEntity().setMetadata("TAM", new FixedMetadataValue(this.plugin, true)); entityArrow.getBukkitEntity().setVelocity(velocity); ((CraftWorld)event.getEntity().getWorld()).getHandle().addEntity(entityArrow); }, 5L * (i + 1)); } }
public void checkProjectile(Player player, ProjectileLaunchEvent e) { incrementOld(player, projectilesShot, 10); if(!projectileTime.containsKey(player)) { projectileTime.put(player,System.currentTimeMillis()); } else if(projectilesShot.get(player) == 10) { long time = System.currentTimeMillis() - projectileTime.get(player); projectileTime.remove(player); projectilesShot.remove(player); if(time < 1500) { for(Player pla : DynamicAC.instance.onlinestaff) { pla.sendMessage(DynamicAC.prefix + player.getName() + " failed Fast Bow!"); } e.setCancelled(true); DACManager.getUserManager().incrementUser(DACManager.getUserManager().getUser(player.getName()), "Fast Bow"); } } }
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR) public void onProjectileLaunch(ProjectileLaunchEvent event) { Projectile projectile = event.getEntity(); if (projectile instanceof EnderPearl) { EnderPearl enderPearl = (EnderPearl) projectile; ProjectileSource source = enderPearl.getShooter(); if (source instanceof Player) { Player shooter = (Player) source; long remaining = getRemaining(shooter); if (remaining > 0L) { shooter.sendMessage(ChatColor.RED + "You are still on " + ChatColor.LIGHT_PURPLE + getName() + ChatColor.RED + " cooldown for another " + ChatColor.BOLD + DurationFormatter.getRemaining(remaining, true, false) + ChatColor.RED + '.'); event.setCancelled(true); return; } if (setCooldown(shooter, shooter.getUniqueId(), defaultCooldown, true)) { startDisplaying(shooter); } } } }
@EventHandler (priority = EventPriority.HIGHEST) public void on(ProjectileLaunchEvent event) { if (event.isCancelled() || !(event.getEntity().getShooter() instanceof Player) || !config.isCountdownBlockProjectile()) { return; } Player player = (Player) event.getEntity().getShooter(); Arena arena = getArena(player); if (arena == null) { return; } if (arena.isCounting()) { Helper.pm(player, "Errors.blocked-countdown-action", true); event.setCancelled(true); } }
@EventHandler(ignoreCancelled=1, priority=EventPriority.MONITOR) public void onShoot(ProjectileLaunchEvent e) { Player player; Arrow arrow; if (e.getEntity() instanceof Arrow && (arrow = (Arrow)e.getEntity()).getShooter() != null && arrow.getShooter() instanceof Player && this.bowPull.containsKey((player = (Player)arrow.getShooter()).getUniqueId())) { Long time = System.currentTimeMillis() - this.bowPull.get(player.getUniqueId()); double power = arrow.getVelocity().length(); Long timeLimit = 300; int ping = this.getJanitor().lag.getPing(player); if (ping > 400) { timeLimit = 150; } if (power > 2.5 && time < timeLimit) { this.getJanitor().logCheat(this, player, null, new String[0]); } } }
@EventHandler public void on(ProjectileLaunchEvent event) { Entity entity = event.getEntity(); if (!(entity instanceof Egg)) return; Egg egg = (Egg) entity; // skip our own eggs if (((CraftEgg) entity).getHandle() instanceof CustomChickenEgg) return; // cancel the launch event.setCancelled(true); EntityEgg original = ((CraftEgg) egg).getHandle(); // create our own egg from the original and spawn that CustomChickenEgg newEgg = new CustomChickenEgg(original.getWorld(), original.getShooter()); original.getWorld().addEntity(newEgg, CreatureSpawnEvent.SpawnReason.EGG); }
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onProjectileLaunch(ProjectileLaunchEvent event) { if (!(event.getEntity().getShooter() instanceof Player)) { return; } Player player = (Player) event.getEntity().getShooter(); NormalAchievements category; if (event.getEntity() instanceof Snowball) { category = NormalAchievements.SNOWBALLS; } else if (event.getEntity() instanceof Egg) { category = NormalAchievements.EGGS; } else { return; } if (plugin.getDisabledCategorySet().contains(category.toString())) { return; } if (!shouldIncreaseBeTakenIntoAccount(player, category)) { return; } updateStatisticAndAwardAchievementsIfAvailable(player, category, 1); }
@EventHandler public void PlayerTrownArrow(ProjectileLaunchEvent e){ if (!(e.getEntity().getShooter() instanceof Player)){ return; } RedProtect.get().logger.debug("Is ProjectileLaunchEvent event."); Location l = e.getEntity().getLocation(); Player p = (Player) e.getEntity().getShooter(); Region r = RedProtect.get().rm.getTopRegion(l); if (r != null && !r.canProtectiles(p)){ e.setCancelled(true); RPLang.sendMessage(p, "playerlistener.region.cantuse"); } }
public void disable() { // Unregister your events on plugin disable. // PlayerJoinEvent.getHandlerList().unregister(plugin); PlayerBucketFillEvent.getHandlerList().unregister(this); PlayerBucketEmptyEvent.getHandlerList().unregister(this); ProjectileLaunchEvent.getHandlerList().unregister(this); PlayerMoveEvent.getHandlerList().unregister(this); EntityDamageEvent.getHandlerList().unregister(this); PlayerJoinEvent.getHandlerList().unregister(this); PlayerLoginEvent.getHandlerList().unregister(this); PlayerQuitEvent.getHandlerList().unregister(this); PlayerKickEvent.getHandlerList().unregister(this); PlayerChangedWorldEvent.getHandlerList().unregister(this); PlayerPickupItemEvent.getHandlerList().unregister(this); PlayerDropItemEvent.getHandlerList().unregister(this); InventoryClickEvent.getHandlerList().unregister(this); PlayerInteractEvent.getHandlerList().unregister(this); PlayerAnimationEvent.getHandlerList().unregister(this); PlayerRespawnEvent.getHandlerList().unregister(this); AsyncPlayerChatEvent.getHandlerList().unregister(this); }
@EventHandler(priority = EventPriority.NORMAL) public void onProjectileLaunch(ProjectileLaunchEvent ev) { LivingEntity shooter = (LivingEntity) ev.getEntity().getShooter(); if ((shooter instanceof Player)) { Player p = (Player) shooter; if ((plugin.getGameManager().isSpectator(p) || plugin.getGameManager().getState() == SGGameState.LOBBY || plugin.getGameManager().getState() == SGGameState.STARTING || plugin.getGameManager().getState() == SGGameState.PRE_DEATHMATCH) && !plugin.getGameManager().isAdmin(p)) { ev.setCancelled(true); } } }
@EventHandler public void onGhastShoot(ProjectileLaunchEvent event) { if (event.getEntity() instanceof LargeFireball) { // ghast fireball LargeFireball frb = (LargeFireball) event.getEntity(); if (frb.getShooter() instanceof Ghast) { Ghast g = (Ghast) frb.getShooter(); DroneFighter f = getFighter(g); if (f == null) { g.remove(); //System.out.println("f for ghast is null, removing!"); event.setCancelled(true); } else { event.setCancelled(true); //System.out.println("Dud fire!"); } } } }
@EventHandler public void onProjectileLaunch(ProjectileLaunchEvent event) { Projectile entity = event.getEntity(); if (!(entity instanceof ThrownPotion)) { return; } ProjectileSource shooter = entity.getShooter(); if (!(shooter instanceof Player)) { return; } Location l = BukkitUtil.getLocation(entity); if (!PS.get().hasPlotArea(l.getWorld())) { return; } PlotPlayer pp = BukkitUtil.getPlayer((Player) shooter); Plot plot = l.getOwnedPlot(); if (plot != null && !plot.isAdded(pp.getUUID())) { entity.remove(); event.setCancelled(true); } }
@EventHandler public void onProjectileThrow(ProjectileLaunchEvent event){ if(Minigame.getCurrentMinigame()!=null){ switch(Minigame.getCurrentMinigame().getMap().getType()){ case CIRCLE_OF_BOOM: if(event.getEntity().getShooter() instanceof Player){ if(Team.getTeam((Player)event.getEntity().getShooter()).equals(Minigame.getObservers())){ event.setCancelled(true); } else { if(!Minigame.getCurrentMinigame().getState().equals(MatchState.STARTED)){ event.setCancelled(true); } } } break; case KEY_QUEST: break; case WATER_THE_MONUMENT: break; default: break; } } }
@EventHandler(priority = EventPriority.MONITOR) public void onProjectileLaunch (ProjectileLaunchEvent event) { if ( ! (event.getEntity() instanceof Arrow) || ! (event.getEntity().getShooter() instanceof Player)) return; if ( ((Player) event.getEntity().getShooter()) .hasPermission("headshot")) { event.getEntity() .setMetadata( "spawn-location", new FixedMetadataValue(plugin, event.getEntity() .getLocation())); } }
@SuppressWarnings("deprecation") @EventHandler public void onProjectileFire(ProjectileLaunchEvent e) { LivingEntity shooter = e.getEntity().getShooter(); if (shooter instanceof Player) { Player player = (Player) shooter; ItemStack item = player.getItemInHand(); RPGItem rItem = ItemManager.toRPGItem(item); if (rItem == null) return; if (!WorldGuard.canPvP(player.getLocation()) && !rItem.ignoreWorldGuard) return; RPGMetadata meta = RPGItem.getMetadata(item); if (rItem.getMaxDurability() != -1) { int durability = meta.containsKey(RPGMetadata.DURABILITY) ? ((Number) meta.get(RPGMetadata.DURABILITY)).intValue() : rItem.getMaxDurability(); durability--; if (durability <= 0) { player.setItemInHand(null); } meta.put(RPGMetadata.DURABILITY, Integer.valueOf(durability)); } RPGItem.updateItem(item, Locale.getPlayerLocale(player), meta); player.updateInventory(); rpgProjectiles.put(e.getEntity().getEntityId(), rItem.getID()); } }
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST) public void onProjectileLaunch(ProjectileLaunchEvent event) { if (event.getEntity() == null) { return; } Projectile projectile = event.getEntity(); // In the Bukkit API prior to 1.7, getShooter() returns a LivingEntity instead of a ProjectileSource Object shooterRaw = null; if (shooterIsLivingEntity) { try { if (getShooter == null) { getShooter = Projectile.class.getMethod("getShooter"); } shooterRaw = getShooter.invoke(projectile); } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) { ConsoleLogger.logException("Error getting shooter", e); } } else { shooterRaw = projectile.getShooter(); } if (shooterRaw instanceof Player && listenerService.shouldCancelEvent((Player) shooterRaw)) { event.setCancelled(true); } }
@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 verifyZeroInteractions(listenerService); verify(event, never()).setCancelled(anyBoolean()); }
@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()); }
@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); }
@Test public void shouldHandleOldShooterMethod() { // given ReflectionTestUtils.setField(listener, "shooterIsLivingEntity", true); ReflectionTestUtils.setField(listener, "getShooter", null); 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)); }
@EventHandler(priority = EventPriority.NORMAL) public void onProjectileLaunch (ProjectileLaunchEvent event) { Projectile projectile = event.getEntity(); if (projectile.getType() != EntityType.THROWN_EXP_BOTTLE || ! (projectile.getShooter() instanceof Player)) return; Player player = (Player) projectile.getShooter(); ItemStack item = player.getInventory().getItemInHand(); if (item.getType() != Material.EXP_BOTTLE) return; ItemMeta meta = item.getItemMeta(); if ( !meta.hasLore()) return; for (String s : meta.getLore()) { if (s == null) return; if (s.startsWith("Level ")) { projectile.setMetadata("expbottlelevel", new LevelMetadata( Integer.parseInt(s.substring(s.indexOf(' ') + 1)))); } } }
@EventHandler public void onLaunch(ProjectileLaunchEvent e){ Player p; if (e.getEntity().getShooter() instanceof Player) { p = (Player) e.getEntity().getShooter(); if (p.getInventory().getItemInMainHand() == null) return; if (!p.getInventory().getItemInMainHand().hasItemMeta() || !p.getInventory().getItemInMainHand().getItemMeta().hasDisplayName()) return; if (p.getInventory().getItemInMainHand().getItemMeta().getDisplayName().equalsIgnoreCase(pe.getPokeEgg().getItemMeta().getDisplayName())) { canWork = true; } } }
void onEvent(ProjectileLaunchEvent event) { for(StaminaSymptom symptom : getActiveSymptoms()) { symptom.onShoot(event); } mutateStamina(options.mutators.archery); }
@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))); } }
@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); } }
@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); } }); }
@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) { GamePlayer shooter = SkyWarsReloaded.getPC().getPlayer(((Player) projectile.getShooter()).getUniqueId()); String effect = shooter.getProjEffect(); if (effect != null) { if (!effect.equalsIgnoreCase("normal") && shooter.inGame()) { SkyWarsReloaded.getProjC().addProjectile(projectile, shooter.getProjEffect()); } } } } }
@EventHandler(priority = EventPriority.HIGHEST) public void on(ProjectileLaunchEvent event){ Projectile projectile = event.getEntity(); if(projectile instanceof Arrow && projectile.getShooter() instanceof Player){ final Arrow arrow = (Arrow) projectile; final int task = server.getScheduler().scheduleSyncRepeatingTask(plugin, ()-> { arrow.getLocation().getWorld().spawnParticle(Particle.LAVA, arrow.getLocation(), 1); }, 0L, 1L); particleTasks.put(arrow, task); } }
@EventHandler public void onProjectileLaunch(ProjectileLaunchEvent e) { if(e.getEntity().getShooter() instanceof Player) { Player player = (Player) e.getEntity().getShooter(); if(e.getEntity() instanceof Arrow) { return; } DynamicAC.getManager().getBackend().checkProjectile(player, e); } }
@EventHandler(priority=EventPriority.HIGHEST) public void onProjectileLaunch(final ProjectileLaunchEvent event) { final Projectile projectile = event.getEntity(); if (event.getEntityType() == EntityType.SPLASH_POTION && projectile.getType().equals((Object)PotionEffectType.HEAL)) { if (projectile.getShooter() instanceof Player && ((Player) projectile.getShooter()).isSprinting()) { final Vector velocity = projectile.getVelocity(); velocity.setY(velocity.getY() - 0.4); } } }
@EventHandler public void onProjectileLaunch(final ProjectileLaunchEvent event) { if (event.getEntityType() == EntityType.SPLASH_POTION) { final Projectile projectile = event.getEntity(); if (projectile.getShooter() instanceof Player && ((Player) projectile.getShooter()).isSprinting()) { final Vector velocity = projectile.getVelocity(); velocity.setY(velocity.getY() - 0.8); projectile.setVelocity(velocity); } } }
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR) public void onThrow(ProjectileLaunchEvent event) { if (event.getEntity().getShooter() instanceof Player) { Player player = (Player) event.getEntity().getShooter(); if (this.editKits.containsKey(player.getUniqueId())) { event.setCancelled(true); } } }
@EventHandler public void onProjectileLaunch(ProjectileLaunchEvent e){ Projectile projectile = e.getEntity(); //Getting the projectile ProjectileSource shooter = projectile.getShooter(); //Getting the shooter if(shooter instanceof Player){ //If the shooter was a player Player player = (Player) shooter; if(!isEnabled(player.getWorld())) return; //If this module is enabled in this world debug("Making projectile go straight", player); //Here we get a unit vector of the direction the player is looking in and multiply it by the projectile's vector's magnitude //We then assign this to the projectile as its new velocity projectile.setVelocity(player.getLocation().getDirection().normalize().multiply(projectile.getVelocity().length())); } }
@EventHandler public void OnGhastProjectileLaunch(ProjectileLaunchEvent event) { if(maze != null) { ProjectileSource e = event.getEntity().getShooter(); if (e instanceof Ghast && maze.checkIfInMaze(((Ghast) e).getLocation())) { Fireball ball = (Fireball) event.getEntity(); float roll = 1 + 3 * random.nextFloat(); ball.setYield(roll); } } }
@EventHandler public void arrowFireEvent(ProjectileLaunchEvent event){ if(event.getEntity() instanceof Arrow){ Arrow arrow = (Arrow) event.getEntity(); if(arrow.getShooter() instanceof Player){ Player player = (Player) arrow.getShooter(); ItemStack item = player.getInventory().getItemInMainHand(); if(new ItemType(item).getType().equals(ItemTypes.BOW)){ Bow detailItem = new Bow(item); if(detailItem.getEnchantsAndLevel() != null){ HashMap<Enchantments, Integer> enchantments = detailItem.getEnchantsAndLevel(); if(enchantments.containsKey(Enchantments.VOLLEY)){ for(int i = 0; i < 10; i++){ Arrow newArrow = player.getWorld().spawnArrow( player.getLocation().add(player.getLocation().getDirection()).add(0, 2, 0), player.getLocation().getDirection().normalize().multiply(2), (float) 2, 12); if(arrow.isCritical()){ newArrow.setCritical(true); } } } return; } } } } }