Java Code Examples for org.bukkit.entity.Entity

The following are top voted examples for showing how to use org.bukkit.entity.Entity. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: Crescent   File: KillauraB.java   Source Code and License 6 votes vote down vote up
/**
 * @param check
 *            The entity to check whether
 * @param distance
 *            The difference in distance to allow for.
 * @return
 */
private boolean isInLineOfSight(Entity check, double distance) {
	final Location entityLocation = check.getLocation();
	final BlockIterator iterator = new BlockIterator(profile.getPlayer().getEyeLocation(), 0.0, 7);

	while (iterator.hasNext()) {
		final Location current = iterator.next().getLocation();

		if (getLocationDifference(current, entityLocation, "X") < distance
				&& getLocationDifference(current, entityLocation, "Y") < distance
				&& getLocationDifference(current, entityLocation, "Z") < distance) {
			return true;
		}
	}

	// The entity has not been found in the player's line of sight.
	return false;
}
 
Example 2
Project: FactionsXL   File: EntityProtectionListener.java   Source Code and License 6 votes vote down vote up
@EventHandler
public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
    Player attacker = getDamageSource(event.getDamager());
    Entity eDefender = event.getEntity();
    if (!(eDefender instanceof Player)) {
        forbidIfInProtectedTerritory(attacker, eDefender, event, ATTACK);
        return;
    }
    Player defender = (Player) eDefender;
    Faction aFaction = plugin.getFactionCache().getByMember(attacker);
    Faction dFaction = plugin.getFactionCache().getByMember(defender);
    Faction rFaction = plugin.getFactionCache().getByLocation(defender.getLocation());
    if (aFaction.getRelation(dFaction).isProtected()) {
        ParsingUtil.sendMessage(attacker, FMessage.PROTECTION_CANNOT_ATTACK_PLAYER.getMessage(), dFaction);
        event.setCancelled(true);
    } else if (rFaction != null && rFaction.getRelation(dFaction).isProtected()) {
        if (plugin.getFConfig().isTerritoryProtectionEnabled() && (!plugin.getFConfig().isCapitalProtectionEnabled()
                || rFaction.getCapital().equals(plugin.getBoard().getByLocation(eDefender.getLocation())))) {
            ParsingUtil.sendMessage(attacker, FMessage.PROTECTION_CANNOT_ATTACK_FACTION.getMessage(), rFaction);
            event.setCancelled(true);
        } else if (plugin.getFConfig().getTerritoryShield() != 0) {
            event.setDamage(event.getDamage() * plugin.getFConfig().getTerritoryShield());
        }
    }
}
 
Example 3
Project: Mob-AI   File: CommandHandler.java   Source Code and License 6 votes vote down vote up
public static List<Entity> getEntities(Location location, double radius) {
    List<Entity> entities = new ArrayList<Entity>();
    World world = location.getWorld();

    // Find chunck by coordinates
    int smallX = MathHelper.floor((location.getX() - radius) / 16.0D);
    int bigX = MathHelper.floor((location.getX() + radius) / 16.0D);
    int smallZ = MathHelper.floor((location.getZ() - radius) / 16.0D);
    int bigZ = MathHelper.floor((location.getZ() + radius) / 16.0D);

    for (int x = smallX; x <= bigX; x++) 
    	for (int z = smallZ; z <= bigZ; z++) 
    		if (world.isChunkLoaded(x, z)) entities.addAll(Arrays.asList(world.getChunkAt(x, z).getEntities()));

    Iterator<Entity> entityIterator = entities.iterator();
    while (entityIterator.hasNext()) 
    	if (entityIterator.next().getLocation().distanceSquared(location) > radius * radius) entityIterator.remove(); 
    
    return entities;
}
 
Example 4
Project: HCFCore   File: TeleportTimer.java   Source Code and License 6 votes vote down vote up
/**
 * Gets the amount of enemies nearby a {@link Player}.
 *
 * @param player
 *            the {@link Player} to get for
 * @param distance
 *            the radius to get within
 * @return the amount of players within enemy distance
 */
public int getNearbyEnemies(Player player, int distance) {
    FactionManager factionManager = plugin.getFactionManager();
    Faction playerFaction = factionManager.getPlayerFaction(player.getUniqueId());
    int count = 0;

    Collection<Entity> nearby = player.getNearbyEntities(distance, distance, distance);
    for (Entity entity : nearby) {
        if (entity instanceof Player) {
            Player target = (Player) entity;

            // If the nearby player or sender cannot see each-other, continue.
            if (!target.canSee(player) || !player.canSee(target)) {
                continue;
            }

            if (playerFaction == null || factionManager.getPlayerFaction(target) != playerFaction) {
                count++;
            }
        }
    }

    return count;
}
 
Example 5
Project: ProjectAres   File: ProjectileDefinition.java   Source Code and License 6 votes vote down vote up
public ProjectileDefinitionImpl(@Nullable String name,
                                @Nullable Double damage,
                                double velocity,
                                ClickAction clickAction,
                                Class<? extends Entity> entity,
                                List<PotionEffect> potion,
                                Filter destroyFilter,
                                Duration coolDown,
                                boolean throwable) {
    this.name = name;
    this.damage = damage;
    this.velocity = velocity;
    this.clickAction = clickAction;
    this.projectile = entity;
    this.potion = potion;
    this.destroyFilter = destroyFilter;
    this.coolDown = coolDown;
    this.throwable = throwable;
}
 
Example 6
Project: BlockBall   File: CustomArmorstand.java   Source Code and License 6 votes vote down vote up
/**
 * Passes the ball with the given strength parameters
 *
 * @param entity             entity
 * @param horizontalStrength horizontalStrength
 * @param verticalStrength   verticalStrength
 */
@Override
public void pass(Entity entity, double horizontalStrength, double verticalStrength) {
    BallKickEvent event = null;
    if (entity instanceof Player) {
        event = new BallKickEvent((Player) entity, this);
        Bukkit.getPluginManager().callEvent(new BallKickEvent((Player) entity, this));
    }
    if (event == null || !event.isCancelled()) {
        this.startVector = this.slime.getSpigotEntity().getLocation().toVector().subtract(entity.getLocation().toVector()).normalize().multiply(horizontalStrength * 0.8);
        this.startVector.setY(verticalStrength * 0.5);
        try {
            this.slime.getSpigotEntity().setVelocity(this.startVector.clone());
        } catch (final IllegalArgumentException ex) {

        }
        if (this.isRotating)
            this.getSpigotEntity().setHeadPose(new EulerAngle(1, this.getSpigotEntity().getHeadPose().getY(), this.getSpigotEntity().getHeadPose().getZ()));
        this.rvalue = this.random.nextInt(5) + 9;
        this.jumps = this.random.nextInt(5) + 5;
    }
}
 
Example 7
Project: mczone   File: Control.java   Source Code and License 6 votes vote down vote up
public static void walkToPlayer(Entity e, Player p) {
    // Tamed animals already handle their own following
    if (e instanceof Tameable) {
        if (((Tameable) e).isTamed()) {
            return;
        }
    }
    if (e.getPassenger() instanceof Player) {
        return;
    }

    // Moving the dragon is too buggy
    if (e instanceof EnderDragon) {
        return;
    }
    // Once this is set we can't unset it.
    //((Creature)e).setTarget(p);

    // If the pet is too far just teleport instead of attempt navigation
    if (e.getLocation().distance(p.getLocation()) > 20) {
        e.teleport(p);
    } else {
        Navigation n = ((CraftLivingEntity) e).getHandle().getNavigation();
        n.a(p.getLocation().getX(), p.getLocation().getY(), p.getLocation().getZ(), 0.30f);
    }
}
 
Example 8
Project: SuperiorCraft   File: CustomBlock.java   Source Code and License 6 votes vote down vote up
public void removeBlock(BlockBreakEvent e) {
		for (Entity en : e.getBlock().getWorld().getEntities()) {
			if (en.getCustomName() != null && en.getCustomName().equals(getName()) && en.getLocation().add(-0.5, 0, -0.5).equals(e.getBlock().getLocation())) {
				en.remove();
				en.getWorld().getBlockAt(en.getLocation().add(-0.5, 0, -0.5)).setType(Material.AIR);
				
				ItemStack block = new ItemStack(Material.MONSTER_EGG, 1);
				
				ItemMeta bmeta = block.getItemMeta();
				
				bmeta.setDisplayName(name);
				
				block.setItemMeta(bmeta);
				
				if (e.getPlayer() != null && e.getPlayer().getGameMode().equals(GameMode.CREATIVE)) {
					e.getPlayer().getInventory().addItem(block);
				} else {
					e.getBlock().getWorld().dropItemNaturally(en.getLocation().add(-0.5, 0, -0.5), block);
				}
			}
		}
	//}
}
 
Example 9
Project: ProjectAres   File: MatchEntityState.java   Source Code and License 6 votes vote down vote up
protected MatchEntityState(Match match, Class<? extends Entity> entityClass, UUID uuid, EntityLocation location, @Nullable String customName) {
    this.uuid = checkNotNull(uuid);
    this.match = checkNotNull(match);
    this.entityClass = checkNotNull(entityClass);
    this.location = checkNotNull(location);
    this.customName = customName;

    EntityType type = null;
    for(EntityType t : EntityType.values()) {
        if(t.getEntityClass().isAssignableFrom(entityClass)) {
            type = t;
            break;
        }
    }
    checkArgument(type != null, "Unknown entity class " + entityClass);
    this.entityType = type;
}
 
Example 10
Project: Uranium   File: CraftWorld.java   Source Code and License 6 votes vote down vote up
public List<Player> getPlayers() {
    List<Player> list = new ArrayList<Player>();

    for (Object o : world.loadedEntityList) {
        if (o instanceof net.minecraft.entity.Entity) {
            net.minecraft.entity.Entity mcEnt = (net.minecraft.entity.Entity) o;
            Entity bukkitEntity = mcEnt.getBukkitEntity();

            if ((bukkitEntity != null) && (bukkitEntity instanceof Player)) {
                list.add((Player) bukkitEntity);
            }
        }
    }

    return list;
}
 
Example 11
Project: Debuggery   File: InputFormatter.java   Source Code and License 6 votes vote down vote up
@Nullable
private static Entity getEntity(String input, @Nullable CommandSender sender) throws InputException {
    Entity target;
    if (sender instanceof Player) {
        if (input.equalsIgnoreCase("that")) {
            target = PlatformUtil.getEntityPlayerLookingAt((Player) sender, 25, 1.5D);

            if (target != null) {
                return target;
            }
        } else if (input.equalsIgnoreCase("me")) {
            return ((Player) sender);
        }
    }

    Location loc = getLocation(input, sender);
    return PlatformUtil.getEntityNearestTo(loc, 25, 1.5D);
}
 
Example 12
Project: helper   File: Metadata.java   Source Code and License 6 votes vote down vote up
/**
 * Gets a {@link MetadataMap} for the given object, if one already exists and has
 * been cached in this registry.
 *
 * A map will only be returned if the object is an instance of
 * {@link Player}, {@link UUID}, {@link Entity}, {@link Block} or {@link World}.
 *
 * @param obj the object
 * @return a metadata map
 */
@Nonnull
public static Optional<MetadataMap> get(@Nonnull Object obj) {
    Preconditions.checkNotNull(obj, "obj");
    if (obj instanceof Player) {
        return getForPlayer(((Player) obj));
    } else if (obj instanceof UUID) {
        return getForPlayer(((UUID) obj));
    } else if (obj instanceof Entity) {
        return getForEntity(((Entity) obj));
    } else if (obj instanceof Block) {
        return getForBlock(((Block) obj));
    } else if (obj instanceof World) {
        return getForWorld(((World) obj));
    } else {
        throw new IllegalArgumentException("Unknown object type: " + obj.getClass());
    }
}
 
Example 13
Project: SuperiorCraft   File: GhostBlock.java   Source Code and License 6 votes vote down vote up
@EventHandler
public void onPlayerMoveEvent(PlayerMoveEvent e) {
	for (Entity en : e.getPlayer().getWorld().getEntities()) {
		if (en.getCustomName() != null && en.getCustomName().equals(getName()) && en.getLocation().distance(e.getTo()) <= 1) {
			Location l = en.getLocation();
			//e.getPlayer().sendMessage(getPlayerDirection(e.getPlayer()));
			if (getPlayerDirection(e.getPlayer()).equals("north")) {
				l.add(-1.2, 0, 0);	
			}
			else if (getPlayerDirection(e.getPlayer()).equals("south")) {
				l.add(1.2, 0, 0);	
			}
			else if (getPlayerDirection(e.getPlayer()).equals("east")) {
				l.add(0, 0, -1.2);	
			}
			else if (getPlayerDirection(e.getPlayer()).equals("west")) {
				l.add(0, 0, 1.2);	
			}
			else {
				l = e.getPlayer().getLocation();
			}
			l.setDirection(e.getPlayer().getLocation().getDirection());
			e.setTo(l);
		}
	}
}
 
Example 14
Project: OpenUHC   File: GoldenFleece.java   Source Code and License 6 votes vote down vote up
/**
 * Utilizes a random chance to either spawn a skeleton with gold armor or resources.
 *
 * @param event The event
 */
@EventHandler
public void onEntityDeath(EntityDeathEvent event) {
  Entity entity = event.getEntity();
  if (entity instanceof Sheep) {
    double chance = Math.random();
    if (0.25 > chance) {
      Skeleton skeleton = entity.getWorld().spawn(entity.getLocation(), Skeleton.class);
      skeleton.getEquipment().setArmorContents(
          new ItemStack[]{
              new ItemStack(Material.GOLD_HELMET),
              new ItemStack(Material.GOLD_CHESTPLATE),
              new ItemStack(Material.GOLD_LEGGINGS),
              new ItemStack(Material.GOLD_BOOTS)
          }
      );
    } else if (0.5 > chance) {
      event.getDrops().add(new ItemStack(Material.IRON_INGOT));
    } else if (0.75 > chance) {
      event.getDrops().add(new ItemStack(Material.GOLD_INGOT));
    } else {
      event.getDrops().add(new ItemStack(Material.DIAMOND));
    }
  }
}
 
Example 15
Project: AsgardAscension   File: RuneManager.java   Source Code and License 6 votes vote down vote up
private void handleSlowdown(Player player, Rune rune) {
	new BukkitRunnable() {
		int iterations = 0;
		public void run() {
			if(!player.isOnline() || iterations / 2 >= rune.getDuration()) {
				finish(player, true);
				this.cancel();
				return;
			}
			
			for(Entity entity : player.getNearbyEntities(3D, 3D, 3D)) {
				if(!(entity instanceof Player)) {
					continue;
				}
				Player target = (Player) entity;
				
				if(Utility.canAttack(player, target)) {
					target.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 40, 0));
				}
			}
			iterations++;
		}
	}.runTaskTimer(plugin, 0L, 10L);
}
 
Example 16
Project: ZentrelaRPG   File: MobData.java   Source Code and License 6 votes vote down vote up
public void knockback(Entity attacker, double knockbackMultiplier) {
    return;
    //        if (dead || noKnockback || entity == null || frozen)
    //            return;
    //        if (attributes.contains(MobAttribute.LOWKNOCKBACK)) {
    //            knockbackMultiplier = 0.25;
    //        }
    //        if (System.currentTimeMillis() - lastKnockback > 600) {
    //            lastKnockback = System.currentTimeMillis();
    //            Vector newVelocity = entity.getLocation().toVector().subtract(attacker.getLocation().toVector()).normalize().multiply(knockbackMultiplier);
    //            // cap Y knockback
    //            if (Math.abs(newVelocity.getY()) > 0.01)
    //                newVelocity.setY(0.01 * Math.signum(newVelocity.getY()));
    //            // cap X knockback
    //            if (Math.abs(newVelocity.getX()) > 1)
    //                newVelocity.setX(1 * Math.signum(newVelocity.getX()));
    //            // cap Z knockback
    //            if (Math.abs(newVelocity.getZ()) > 1)
    //                newVelocity.setZ(1 * Math.signum(newVelocity.getZ()));
    //            if (newVelocity.getY() < 0.2)
    //                newVelocity.setY(0.2);
    //            if (entity != null && entity.isValid())
    //                entity.setVelocity(newVelocity);
    //        }
}
 
Example 17
Project: SuperiorCraft   File: HoverBike.java   Source Code and License 6 votes vote down vote up
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
	if (command.getName().equalsIgnoreCase("hbike")) {
		Player player = (Player) sender;
		if (args[0].equals("create")) {
			create(player.getLocation()).setPassenger(player);
		}
		else if (args[0].equals("destroy")) {
			for (Entity ent : player.getNearbyEntities(0.2, 0.2, 0.2)) {
				if (ent.getCustomName() != null && ent.getCustomName().equals("HoverBike")) {
					ent.remove();
					return true;
				}
			}
		}
			
		return true;
	}
	
	return false;
}
 
Example 18
Project: ZentrelaRPG   File: BuffManager.java   Source Code and License 6 votes vote down vote up
public static void handleBuff(Entity player, Entity e) {
    if (!(player instanceof Player))
        return;
    Player p = (Player) player;
    PlayerDataRPG pd = plugin.getPD(p);
    if (pd != null && buffMap.containsKey(e.getUniqueId())) {
        try {
            Buff buff = buffMap.remove(e.getUniqueId());
            buff.apply(p, pd);
        } catch (Exception e2) {
            e2.printStackTrace();
        }
        Location loc = e.getLocation();
        RParticles.showWithOffsetPositiveY(ParticleEffect.EXPLOSION_LARGE, loc, 1.0, 10);
        e.remove();
    }
}
 
Example 19
Project: CloudNet   File: ArmorStandListener.java   Source Code and License 5 votes vote down vote up
@EventHandler
public void handle(ItemDespawnEvent e)
{
    MobSelector.MobImpl mob = CollectionWrapper.filter(MobSelector.getInstance().getMobs().values(), new Acceptable<MobSelector.MobImpl>() {
        @Override
        public boolean isAccepted(MobSelector.MobImpl value)
        {
            return ((Entity) value.getDisplayMessage()).getPassenger() != null && e.getEntity().getEntityId() == ((Entity) value.getDisplayMessage()).getPassenger().getEntityId();
        }
    });
    if (mob != null)
    {
        e.setCancelled(true);
    }
}
 
Example 20
Project: ProjectAres   File: SequentialPointProvider.java   Source Code and License 5 votes vote down vote up
@Override
public Location getPoint(Match match, @Nullable Entity entity) {
    for(PointProvider child : children) {
        Location loc = child.getPoint(match, entity);
        if(loc != null) return loc;
    }
    return null;
}
 
Example 21
Project: uppercore   File: EntityNms.java   Source Code and License 5 votes vote down vote up
public static Object getHandle(Entity entity) {
    try {
        return getHandle.invoke(entity);
    } catch (Exception e) {
        handleException(e);
        return null;
    }
}
 
Example 22
Project: HCFCore   File: CombatTimer.java   Source Code and License 5 votes vote down vote up
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
    Player attacker = BukkitUtils.getFinalAttacker(event, true);
    Entity entity;
    if (attacker != null && (entity = event.getEntity()) instanceof Player) {
        Player attacked = (Player) entity;
        setCooldown(attacker, attacker.getUniqueId(), defaultCooldown, false);
        setCooldown(attacked, attacked.getUniqueId(), defaultCooldown, false);
    }
}
 
Example 23
Project: PetBlocks   File: PetBlockCommandExecutor.java   Source Code and License 5 votes vote down vote up
private void killNextCommand(Player sender) {
    double distance = 100;
    Entity nearest = null;
    for (final Entity entity : sender.getLocation().getChunk().getEntities()) {
        if (!(entity instanceof Player) && sender.getLocation().distance(entity.getLocation()) < distance) {
            distance = sender.getLocation().distance(entity.getLocation());
            nearest = entity;
        }
    }
    if (nearest != null) {
        nearest.remove();
        sender.sendMessage(Config.getInstance().getPrefix() + "" + ChatColor.GREEN + "You removed entity " + nearest.getType() + '.');
    }
}
 
Example 24
Project: PetBlocks   File: PetBlockListener.java   Source Code and License 5 votes vote down vote up
private PetBlock getPet(Entity entity) {
    try {
        for (final PetBlock block : this.manager.getPetBlockController().getAll()) {
            if (block != null && entity != null && block.getArmorStand() != null && block.getEngineEntity() != null && (block.getArmorStand().equals(entity) || block.getEngineEntity().equals(entity)))
                return block;
        }
    } catch (final Exception ignored) {
    }
    return null;
}
 
Example 25
Project: ProjectAres   File: GenericDamageResolver.java   Source Code and License 5 votes vote down vote up
@Override
public @Nullable DamageInfo resolveDamage(EntityDamageEvent.DamageCause damageType, Entity victim, @Nullable PhysicalInfo damager) {
    if(damager instanceof DamageInfo) {
        // If the damager block/entity resolved to a DamageInfo directly, return that
        return (DamageInfo) damager;
    } else {
        return new GenericDamageInfo(damageType, damager);
    }
}
 
Example 26
Project: CaulCrafting   File: ItemDropListener.java   Source Code and License 5 votes vote down vote up
Entity[] getNearbyEntities(Location l, int radius){
	int chunkRadius = radius < 16 ? 1 : (radius - (radius % 16))/16;
	HashSet<Entity> radiusEntities = new HashSet<Entity>();
     	for (int chX = 0 -chunkRadius; chX <= chunkRadius; chX ++){
     		for (int chZ = 0 -chunkRadius; chZ <= chunkRadius; chZ++){
     			int x=(int) l.getX(),y=(int) l.getY(),z=(int) l.getZ();
     			for (Entity e : new Location(l.getWorld(),x+(chX*16),y,z+(chZ*16)).getChunk().getEntities()){
     				if (e.getLocation().distance(l) <= radius && e.getLocation().getBlock() != l.getBlock()) radiusEntities.add(e);
     			}
     		}
     	}
     return radiusEntities.toArray(new Entity[radiusEntities.size()]);
}
 
Example 27
Project: Slimefun4-Chinese-Version   File: AutoBreeder.java   Source Code and License 5 votes vote down vote up
protected void tick(Block b)
    throws Exception
{
    for(Iterator iterator = me.mrCookieSlime.Slimefun.holograms.AutoBreeder.getArmorStand(b).getNearbyEntities(4D, 2D, 4D).iterator(); iterator.hasNext();)
    {
        Entity n = (Entity)iterator.next();
        if(Animals.isFeedable(n))
        {
            int ai[];
            int j = (ai = getInputSlots()).length;
            for(int i = 0; i < j; i++)
            {
                int slot = ai[i];
                if(SlimefunManager.isItemSimiliar(BlockStorage.getInventory(b).getItemInSlot(slot), SlimefunItems.ORGANIC_FOOD, false))
                    if(ChargableBlock.getCharge(b) < getEnergyConsumption())
                    {
                        return;
                    } else
                    {
                        ChargableBlock.addCharge(b, -getEnergyConsumption());
                        BlockStorage.getInventory(b).replaceExistingItem(slot, InvUtils.decreaseItem(BlockStorage.getInventory(b).getItemInSlot(slot), 1));
                        Animals.feed(n);
                        ParticleEffect.HEART.display(((LivingEntity)n).getEyeLocation(), 0.2F, 0.2F, 0.2F, 0.0F, 8);
                        return;
                    }
            }

        }
    }

}
 
Example 28
Project: Warzone   File: SimpleDispenserTracker.java   Source Code and License 5 votes vote down vote up
public @Nullable
OfflinePlayer setOwner(@Nonnull Entity entity, @Nullable Player player) {
    Preconditions.checkNotNull(entity, "tnt entity");

    if(player != null) {
        return this.ownedEntitys.put(entity, player);
    } else {
        return this.ownedEntitys.remove(entity);
    }
}
 
Example 29
Project: mczone   File: GameEvents.java   Source Code and License 5 votes vote down vote up
@EventHandler
public void onCompassUse(PlayerInteractEvent event) {
	Player p = event.getPlayer();
	if (event.getItem() != null && event.getItem().getType() == Material.COMPASS) {
		Boolean found = false;
		for (int i = 0; i < 5000; i += 25) {
			List<Entity> entities = p.getNearbyEntities(i, 256, i);
			for (Entity e : entities) {
				if (!(e instanceof Player))
					continue;
				Player t = (Player) e;
				if (Gamer.get(t.getName()).isInvisible())
					continue;
				p.setCompassTarget(e.getLocation());
				Chat.player(p, "&2[SG] &aCompass points to &7" + ((Player) e).getDisplayName() + "&a!");
				found = true;
				break;
			}

			if (found)
				break;
		}
		if (!found) {
			Chat.player(p, "&cNo players in range. Compass points to spawn location.");
			Gamer g = Gamer.get(p.getName());
			p.setCompassTarget(g.getLocation("spawn-block"));
		}
	}
}
 
Example 30
Project: ProjectAres   File: PGMListener.java   Source Code and License 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void clearActiveEnderPearls(final PlayerDeathEvent event) {
    for(Entity entity : event.getEntity().getWorld().getEntitiesByClass(EnderPearl.class)) {
        if(((EnderPearl) entity).getShooter() == event.getEntity()) {
            entity.remove();
        }
    }
}
 
Example 31
Project: BlockBall   File: CustomArmorstand.java   Source Code and License 5 votes vote down vote up
@Override
public boolean isSameEntity(Entity entity) {
    if (!this.getSpigotEntity().isDead()) {
        if (this.getBukkitEntity().getEntityId() == entity.getEntityId() || this.slime.getSpigotEntity().getEntityId() == entity.getEntityId())
            return true;
    }
    return false;
}
 
Example 32
Project: EchoPet   File: PetEntityListener.java   Source Code and License 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) // Highest because we don't want to trust other plugins modifying it.
public void onEntityDamage(EntityDamageEvent event) {
    Entity e = event.getEntity();
    if (ReflectionUtil.getEntityHandle(e) instanceof IEntityPet) {
        IEntityPet entityPet = (IEntityPet) ReflectionUtil.getEntityHandle(e);
        PetDamageEvent damageEvent = new PetDamageEvent(entityPet.getPet(), event.getCause(), event.getDamage());
        EchoPet.getPlugin().getServer().getPluginManager().callEvent(damageEvent);
        event.setDamage(damageEvent.getDamage());
        event.setCancelled(damageEvent.isCancelled());
    }
}
 
Example 33
Project: ZentrelaRPG   File: ShadowWarp.java   Source Code and License 5 votes vote down vote up
@Override
public boolean cast(final Player p, PlayerDataRPG pd, int level) {
    if(!pd.isStealthed()) {
        p.sendMessage(ChatColor.RED + "Shadow Warp can only be used while in stealth.");
        return false;
    }
    Vector dir = p.getLocation().getDirection().normalize().multiply(0.3);
    Location start = p.getLocation().add(0, p.getEyeHeight() * 0.75, 0).clone();
    Location curr = start.clone();
    Entity target = null;
    for (int k = 0; k < 30; k++) {
        for (Entity e : RMath.getNearbyEntities(curr, 1.5)) {
            if (e != p) {
                if (Spell.canDamage(e, true)) {
                    target = e;
                    break;
                }
            }
        }
        if(target != null)
            break;
        curr.add(dir);
        if(!RParticles.isAirlike(curr.getBlock()))
            break;
    }
    if (target == null) {
        p.sendMessage(ChatColor.RED + "Failed to find a Shadow Warp target.");
        return false;
    }
    Location loc = target.getLocation();
    loc = loc.add(0, 0.3, 0);
    loc.add(target.getLocation().getDirection().normalize().multiply(-2));
    p.teleport(loc);
    Spell.notify(p, "You teleport behind your target.");
    return true;
}
 
Example 34
Project: ArchersBattle   File: ProjectileListener.java   Source Code and License 5 votes vote down vote up
@EventHandler
public void onHit(final ProjectileHitEvent e) {
    if (!Utils.isArenaWorld(e.getEntity().getWorld())) {
        return;
    }
    if (!e.getEntityType().equals(EntityType.ARROW)) {
        return;
    }
    new BukkitRunnable() {
        public void run() {
            Entity arrow = e.getEntity();
            arrow.remove();
        }
    }.runTaskLater(Main.getInstance(), 100L);
}
 
Example 35
Project: ZentrelaRPG   File: DropManager.java   Source Code and License 5 votes vote down vote up
public static void removeLabel(Item item) {
    if (itemLabels.containsKey(item.getUniqueId())) {
        Entity e = itemLabels.remove(item.getUniqueId());
        if (e != null)
            e.remove();
        e = null;
    }
}
 
Example 36
Project: Uranium   File: CraftTNTPrimed.java   Source Code and License 5 votes vote down vote up
public Entity getSource() {
    net.minecraft.entity.EntityLivingBase source = getHandle().getTntPlacedBy();

    if (source != null) {
        Entity bukkitEntity = source.getBukkitEntity();

        if (bukkitEntity.isValid()) {
            return bukkitEntity;
        }
    }

    return null;
}
 
Example 37
Project: ProjectAres   File: MasterResolver.java   Source Code and License 5 votes vote down vote up
@Override
public @Nullable PhysicalInfo resolveShooter(ProjectileSource source) {
    if(source instanceof Entity) {
        return entityTracker.resolveEntity((Entity) source);
    } else if(source instanceof BlockProjectileSource) {
        return blockTracker.resolveBlock(((BlockProjectileSource) source).getBlock());
    }
    return null;
}
 
Example 38
Project: NavyCraft2-Lite   File: MoveCraft_EntityListener.java   Source Code and License 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGH)
public void onEntityExplode(EntityExplodeEvent event) 
{
	Entity ent = event.getEntity();
	if( (ent != null && ent instanceof TNTPrimed) )
	{
		if( event.getLocation() != null )
		{
			if( NavyCraft.shotTNTList.containsKey(ent.getUniqueId()) )
			{
				Craft checkCraft;
				checkCraft = structureUpdate(event.getLocation(), NavyCraft.shotTNTList.get(ent.getUniqueId()));
				if( checkCraft == null ) {
					checkCraft = structureUpdate(event.getLocation().getBlock().getRelative(4,4,4).getLocation(), NavyCraft.shotTNTList.get(ent.getUniqueId()));
					if( checkCraft == null ) {
						checkCraft = structureUpdate(event.getLocation().getBlock().getRelative(-4,-4,-4).getLocation(), NavyCraft.shotTNTList.get(ent.getUniqueId()));
						if( checkCraft == null ) {
							checkCraft = structureUpdate(event.getLocation().getBlock().getRelative(2,-2,-2).getLocation(), NavyCraft.shotTNTList.get(ent.getUniqueId()));
							if( checkCraft == null ) {
								checkCraft = structureUpdate(event.getLocation().getBlock().getRelative(-2,2,2).getLocation(), NavyCraft.shotTNTList.get(ent.getUniqueId()));
							}
						}
					}
				}
				NavyCraft.shotTNTList.remove(ent.getUniqueId());
			}
			else
				structureUpdate(event.getLocation(), null);
		}
	}
 
}
 
Example 39
Project: WC   File: KillAllCMD.java   Source Code and License 5 votes vote down vote up
private List<Entity> worldClassEntities(World w, EntityType entityType){
    List<Entity> entities = new ArrayList<>();

    w.getEntitiesByClass(entityType.getEntityClass()).forEach(e -> {
        if (e.getType() == entityType){
            entities.add(e);
        }
    });
    return entities;
}
 
Example 40
Project: KingdomFactions   File: KingdomFactionsPlugin.java   Source Code and License 5 votes vote down vote up
@Override
public void onDisable() {

	ShopLogger.getInstance().disable();

	for (Entity e : Utils.getInstance().getOverWorld().getEntities()) {
		if (e instanceof LivingEntity) {
			if (MonsterModule.getInstance().getGuard((LivingEntity) e) != null) {
				MonsterModule.getInstance().getGuard((LivingEntity) e).kill();
			}
		}
	}
	MySQLModule.getInstance().closeConnection();
}
 
Example 41
Project: HCFCore   File: InfinityArrowFixListener.java   Source Code and License 5 votes vote down vote up
@EventHandler(priority = EventPriority.NORMAL)
public void onProjectileHit(ProjectileHitEvent event) {
    Entity entity = event.getEntity();
    if (entity instanceof Arrow) {
        Arrow arrow = (Arrow) entity;
        if (!(arrow.getShooter() instanceof Player) || ((CraftArrow) arrow).getHandle().fromPlayer == 2) {
            arrow.remove();
        }
    }
}
 
Example 42
Project: AsgardAscension   File: RuneManager.java   Source Code and License 5 votes vote down vote up
private void handleLightning(Player player, Rune rune) {
	@SuppressWarnings("deprecation")
	Block block = player.getTargetBlock((HashSet<Byte>) null, 15);
	if(!Utility.isPVPEnabled(block.getLocation())) {
		return;
	}
	
	block.getWorld().strikeLightning(block.getLocation());
	for(Entity e : block.getWorld().getEntities()) {
		if(!(e instanceof Player)) {
			continue;
		}
		Player target = (Player) e;
		if(!Utility.canAttack(player, target)) {
			continue;
		}
		double distance = target.getLocation().distance(block.getLocation());
		double damage = 0;
		if(distance < 1) {
			damage = 16;
		}
		else if(distance <= 3) {
			damage = 10;
		}
		
		if(damage < 1)
			continue;
		
		if(target.getHealth() > damage)
			target.setHealth(target.getHealth() - damage);
		else
			target.damage(1000000, player);
		target.sendMessage(Lang.HEADERS_TOKENS.toString() + Lang.TOKENS_LIGHTNING.toString()
			.replaceAll("%s", player.getName()));
	}
	finish(player, false);
}
 
Example 43
Project: HCFCore   File: EnchantLimitListener.java   Source Code and License 5 votes vote down vote up
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH)
public void onPlayerFishEvent(PlayerFishEvent event) {
    Entity caught = event.getCaught();
    if (caught instanceof Item) {
        validateIllegalEnchants(((Item) caught).getItemStack());
    }
}
 
Example 44
Project: ZentrelaRPG   File: EnvironmentManager.java   Source Code and License 5 votes vote down vote up
public static void despawnEntities(Entity[] list) {
    for (Entity e : list) {
        if (e == null || e.getUniqueId() == null)
            continue;
        if (e instanceof Player)
            continue;
        try {
            if (MobManager.spawnedMobs != null && MobManager.spawnedMobs.containsKey(e.getUniqueId())) {
                MobManager.spawnedMobs.get(e.getUniqueId()).despawn();
            }
            if (NPCManager.npcs != null && NPCManager.npcs.containsKey(e.getUniqueId())) {
                NPCManager.npcs.remove(e.getUniqueId()).despawn();
            }
            if (e instanceof Item || e instanceof LivingEntity || e instanceof ArmorStand || e instanceof Projectile || e instanceof EnderCrystal) {
                if (e instanceof LivingEntity)
                    ((LivingEntity) e).setHealth(0.0);
                DropManager dm = plugin.getInstance(DropManager.class);
                if (dm != null) {
                    Entity label = dm.removeLabel(e.getUniqueId());
                    if (label != null)
                        label.remove();
                    e.remove();
                }
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

}
 
Example 45
Project: ZentrelaRPG   File: ClearNearbyCommand.java   Source Code and License 5 votes vote down vote up
@Override
public void executePlayer(Player p, PlayerDataRPG pd, String[] args) {
    for (Entity e : p.getNearbyEntities(5, 5, 5)) {
        if (e instanceof Item) {
            DropManager.removeLabel((Item) e);
            e.remove();
        }
    }
    p.sendMessage("cleared nearby items");
}
 
Example 46
Project: ZentrelaRPG   File: DungeonManager.java   Source Code and License 5 votes vote down vote up
public void handleBossSpawn(Entity player, Entity e) {
    if (!(player instanceof Player))
        return;
    Player p = (Player) player;
    PlayerDataRPG pd = plugin.getPD(p);
    if (pd != null && spawners.containsKey(e.getUniqueId())) {
        try {
            DungeonBoss db = spawners.remove(e.getUniqueId());
            db.spawnBoss();
        } catch (Exception e2) {
            e2.printStackTrace();
        }
    }
}
 
Example 47
Project: Arcadia-Spigot   File: BombardmentGame.java   Source Code and License 5 votes vote down vote up
private void moveToward(Entity entity, Location to, double speed) {
    Location loc = entity.getLocation();
    double x = loc.getX() - to.getX();
    double y = loc.getY() - to.getY();
    double z = loc.getZ() - to.getZ();
    Vector velocity = new Vector(x, y, z).normalize().multiply(-speed);
    entity.setVelocity(velocity);
}
 
Example 48
Project: BlockBall   File: CustomArmorstand.java   Source Code and License 5 votes vote down vote up
@Override
public boolean isSameEntity(Entity entity) {
    if (!this.getSpigotEntity().isDead()) {
        if (this.getBukkitEntity().getEntityId() == entity.getEntityId() || this.slime.getSpigotEntity().getEntityId() == entity.getEntityId())
            return true;
    }
    return false;
}
 
Example 49
Project: MultiLineAPI   File: EntityUtil.java   Source Code and License 5 votes vote down vote up
public static boolean isInRange(Entity e, Player p, double distanceMultiplier) {
    if (!e.getWorld().getUID().equals(p.getWorld().getUID())) return false;
    double highest = entityDistances.containsKey(e.getWorld().getName()) ?
            entityDistances.get(p.getWorld().getName()) : entityDistances.get("default");
    highest *= distanceMultiplier;
    return Math.abs(e.getLocation().getX() - p.getLocation().getX()) < highest
            && Math.abs(e.getLocation().getZ() - p.getLocation().getZ()) < highest;
}
 
Example 50
Project: ProjectAres   File: FireTracker.java   Source Code and License 5 votes vote down vote up
@Override
public @Nullable FireInfo resolveDamage(EntityDamageEvent.DamageCause damageType, Entity victim, @Nullable PhysicalInfo damager) {
    switch(damageType) {
        case FIRE_TICK:
            FireInfo info = resolveBurning(victim);
            if(info != null) return info;
            // fall through

        case FIRE:
        case LAVA:
            return new FireInfo(damager);
    }
    return null;
}
 
Example 51
Project: HCFCore   File: StuckTimer.java   Source Code and License 5 votes vote down vote up
@EventHandler(ignoreCancelled=true, priority=EventPriority.MONITOR)
public void onPlayerDamage(EntityDamageEvent event)
{
    Entity entity = event.getEntity();
    if ((entity instanceof Player))
    {
        Player player = (Player)entity;
        if (getRemaining(player) > 0L)
        {
            player.sendMessage(ChatColor.RED + "You were damaged, " + getDisplayName() + ChatColor.RED + " timer ended.");
            clearCooldown(player);
        }
    }
}
 
Example 52
Project: PA   File: MobUtils.java   Source Code and License 4 votes vote down vote up
public boolean isMule(Entity e){
    return e.getType() == EntityType.MULE;
}
 
Example 53
Project: MockBukkit   File: PlayerMock.java   Source Code and License 4 votes vote down vote up
@Override
public void setShoulderEntityLeft(Entity entity)
{
	// TODO Auto-generated method stub
	throw new UnimplementedOperationException();
}
 
Example 54
Project: ProjectAres   File: MasterResolver.java   Source Code and License 4 votes vote down vote up
@Override
public DamageInfo resolveDamage(EntityDamageEvent.DamageCause damageType, Entity victim, @Nullable Block damager) {
    if(damager == null) return resolveDamage(damageType, victim);
    return resolveDamage(damageType, victim, blockTracker.resolveBlock(damager));

}
 
Example 55
Project: MockBukkit   File: WorldMock.java   Source Code and License 4 votes vote down vote up
@Override
public Collection<Entity> getEntitiesByClasses(Class<?>... classes)
{
	// TODO Auto-generated method stub
	throw new UnimplementedOperationException();
}
 
Example 56
Project: ProjectAres   File: NMSHacks.java   Source Code and License 4 votes vote down vote up
public static Packet entityMetadataPacket(int entityId, Entity entity, boolean complete) {
    return entityMetadataPacket(entityId, ((CraftEntity) entity).getHandle(), complete);
}
 
Example 57
Project: ProjectAres   File: Projectiles.java   Source Code and License 4 votes vote down vote up
static @Nullable ProjectileDefinition launchingProjectileDefinition(Entity entity) {
    final ProjectileDefinition definition = getProjectileDefinition(entity);
    return definition != null ? definition : launchingDefinition.get();
}
 
Example 58
Project: uppercore   File: Hologram.java   Source Code and License 4 votes vote down vote up
public void remove() {
    entities.forEach(Entity::remove);
    entities.clear();
}
 
Example 59
Project: ZentrelaRPG   File: FlameWave.java   Source Code and License 4 votes vote down vote up
@Override
public boolean cast(final Player p, final PlayerDataRPG pd, final int level) {
    final ArrayList<Entity> hit = new ArrayList<Entity>();
    final Location start = p.getLocation().add(0, p.getEyeHeight() * 0.75, 0);
    for (Vector v : getVectors(p, level)) {
        ArrayList<Location> locs = RMath.calculateVectorPath(start.clone(), v, 12, 3);
        int count = 0;
        for (int k = 0; k < locs.size(); k++) {
            final Location loc = locs.get(k);
            RScheduler.schedule(Spell.plugin, new Runnable() {
                public void run() {
                    RParticles.showWithOffset(ParticleEffect.FLAME, loc, 0.2, 1);
                    int damage = pd.getDamage(true);
                    switch (level) {
                        case 1:
                            damage *= 2.0;
                            break;
                        case 2:
                            damage *= 2.2;
                            break;
                        case 3:
                            damage *= 2.4;
                            break;
                        case 4:
                            damage *= 2.6;
                            break;
                        case 5:
                            damage *= 2.8;
                            break;
                        case 6:
                            damage *= 3.0;
                            break;
                        case 7:
                            damage *= 3.2;
                            break;
                        case 8:
                            damage *= 3.4;
                            break;
                        case 9:
                            damage *= 3.6;
                            break;
                        case 10:
                            damage *= 3.8;
                            break;
                    }
                    ArrayList<Entity> damaged = Spell.damageNearby(damage, p, loc, 1.0, hit);
                    hit.addAll(damaged);
                }
            }, 1 * count);
            if (k % 2 == 0)
                count++;
        }
    }
    Spell.notify(p, "A wave of hot flame spreads out from your wand.");
    return true;
}
 
Example 60
Project: MockBukkit   File: PlayerMock.java   Source Code and License 4 votes vote down vote up
@Override
public boolean addPassenger(Entity passenger)
{
	// TODO Auto-generated method stub
	throw new UnimplementedOperationException();
}