Java Code Examples for org.bukkit.entity.Player#getNearbyEntities()
The following examples show how to use
org.bukkit.entity.Player#getNearbyEntities() .
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: Pyro.java From AnnihilationPro with MIT License | 8 votes |
@Override protected boolean performSpecialAction(Player player, AnniPlayer p) { if(p.getTeam() != null) { for(Entity e : player.getNearbyEntities(5, 5, 5)) { if(e.getType() == EntityType.PLAYER) { AnniPlayer d = AnniPlayer.getPlayer(e.getUniqueId()); if(d != null && d.getTeam() != null && !d.getTeam().equals(p.getTeam())) e.setFireTicks(40); } } player.sendMessage(ChatColor.DARK_RED+ChatColor.stripColor(getSpecialItemName()).toUpperCase()+"!"); return true; } else return false; }
Example 2
Source File: SlimefunBootsListener.java From Slimefun4 with GNU General Public License v3.0 | 6 votes |
private void stomp(EntityDamageEvent e) { Player p = (Player) e.getEntity(); p.getWorld().playSound(p.getLocation(), Sound.ENTITY_ZOMBIE_BREAK_WOODEN_DOOR, 1F, 2F); p.setVelocity(new Vector(0.0, 0.7, 0.0)); for (Entity n : p.getNearbyEntities(4, 4, 4)) { if (n instanceof LivingEntity && !n.getUniqueId().equals(p.getUniqueId())) { Vector velocity = n.getLocation().toVector().subtract(p.getLocation().toVector()).normalize().multiply(1.4); n.setVelocity(velocity); if (!(n instanceof Player) || (p.getWorld().getPVP() && SlimefunPlugin.getProtectionManager().hasPermission(p, n.getLocation(), ProtectableAction.PVP))) { EntityDamageByEntityEvent event = new EntityDamageByEntityEvent(p, n, DamageCause.ENTITY_ATTACK, e.getDamage() / 2); Bukkit.getPluginManager().callEvent(event); if (!event.isCancelled()) ((LivingEntity) n).damage(e.getDamage() / 2); } } } for (BlockFace face : BlockFace.values()) { Block b = p.getLocation().getBlock().getRelative(BlockFace.DOWN).getRelative(face); p.getWorld().playEffect(b.getLocation(), Effect.STEP_SOUND, b.getType()); } }
Example 3
Source File: PushbackCharger.java From QualityArmory with GNU General Public License v3.0 | 5 votes |
@SuppressWarnings("deprecation") @Override public boolean shoot(Gun g, Player p, ItemStack i) { Location start = p.getEyeLocation().clone(); Vector go = p.getLocation().getDirection().normalize(); //go.add(new Vector((Math.random() * 2 * sway) - sway, (Math.random() * 2 * sway) - sway, // (Math.random() * 2 * sway) - sway)); GunUtil.playShoot(g, p); boolean lookup = (go.getY() > go.getX() && go.getY() > go.getZ()); boolean lookdown = (-go.getY() > go.getX() && -go.getY() > go.getZ()); double degreeVector = Math.atan2(go.getX(), go.getZ()); if (degreeVector > Math.PI) degreeVector = 2 * Math.PI - degreeVector; for (Entity e : p.getNearbyEntities(g.getMaxDistance(), g.getMaxDistance(), g.getMaxDistance())) { double dis = e.getLocation().distance(start); if (e instanceof Damageable) if (e != p && e != p.getVehicle() && e != p.getPassenger()) { double degreeEntity = Math.atan2(e.getLocation().getX() - start.getX(), e.getLocation().getZ() - start.getZ()); if (degreeEntity > Math.PI) degreeEntity = 2 * Math.PI - degreeEntity; if ((lookup && e.getLocation().getY() > start.getY()) || (lookdown && e.getLocation().getY() < start.getY()) || (!lookdown&&!lookup&&Math.max(degreeEntity, degreeVector) - Math.min(degreeEntity, degreeVector) < (dis > 10 ? Math.PI / 4 : Math.PI / 2))) { Vector pushback = new Vector(e.getLocation().getX() - start.getX(),e.getLocation().getY() - start.getY(), e.getLocation().getZ() - start.getZ()); pushback.normalize().multiply(g.getMaxDistance()/(dis)); e.setVelocity(pushback); } } } return false; }
Example 4
Source File: QuadCrate.java From Crazy-Crates with MIT License | 5 votes |
@EventHandler public void onPlayerMove(PlayerMoveEvent e) { Player player = e.getPlayer(); if (QuadCrateSession.inSession(player)) {//Player tries to walk away from the crate area Location from = e.getFrom(); Location to = e.getTo(); if (from.getBlockX() != to.getBlockX() || from.getBlockZ() != to.getBlockZ()) { e.setCancelled(true); player.teleport(from); return; } } for (Entity en : player.getNearbyEntities(2, 2, 2)) {//Someone tries to enter the crate area if (en instanceof Player) { Player p = (Player) en; if (QuadCrateSession.inSession(p)) { Vector v = player.getLocation().toVector().subtract(p.getLocation().toVector()).normalize().setY(1); if (player.isInsideVehicle()) { player.getVehicle().setVelocity(v); } else { player.setVelocity(v); } break; } } } }
Example 5
Source File: McMMOHook.java From RedProtect with GNU General Public License v3.0 | 5 votes |
@EventHandler public void onPlayerActivateAbility(McMMOPlayerAbilityActivateEvent e) { if (e.isCancelled()) { return; } RedProtect.get().logger.debug(LogLevel.DEFAULT, "McMMO McMMOPlayerAbilityActivateEvent event."); Player p = e.getPlayer(); //try to fix invisibility on bersek if (RedProtect.get().config.configRoot().hooks.mcmmo.fix_berserk_invisibility && e.getAbility().equals(SuperAbilityType.BERSERK)) { p.damage(0); for (Entity ent : p.getNearbyEntities(10, 10, 10)) { if (ent instanceof LivingEntity) { ((LivingEntity) ent).damage(0); } } } Region r = RedProtect.get().rm.getTopRegion(p.getLocation()); if (r == null) { return; } if (!r.canSkill(p)) { p.sendMessage(RedProtect.get().lang.get("mcmmolistener.notallowed")); e.setCancelled(true); } if (!r.canPVP(p, null) && (e.getSkill().equals(PrimarySkillType.SWORDS) || e.getSkill().equals(PrimarySkillType.UNARMED))) { e.setCancelled(true); } }
Example 6
Source File: ItemsCollector.java From Minepacks with GNU General Public License v3.0 | 5 votes |
@Override public void run() { for(Player player : Bukkit.getServer().getOnlinePlayers()) { if(plugin.isDisabled(player) != WorldBlacklistMode.None) return; if(player.getInventory().firstEmpty() == -1 && player.hasPermission(Permissions.USE) && player.hasPermission(Permissions.FULL_PICKUP)) { // Only check loaded backpacks (loading them would take to much time for a repeating task, the backpack will be loaded async soon enough) Backpack backpack = (Backpack) plugin.getBackpackCachedOnly(player); if(backpack == null) { continue; } List<Entity> entities = player.getNearbyEntities(radius, radius, radius); for(Entity entity : entities) { if(entity instanceof Item) { Item item = (Item) entity; if(!item.isDead() && item.getPickupDelay() <= 0) { if(itemFilter != null && itemFilter.isItemBlocked(item.getItemStack())) continue; Map<Integer, ItemStack> full = backpack.addItems(item.getItemStack()); backpack.setChanged(); if(!full.isEmpty()) { item.setItemStack(full.get(0)); } else { item.remove(); } } } } } } }