org.bukkit.entity.LivingEntity Java Examples

The following examples show how to use org.bukkit.entity.LivingEntity. 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: SimpleChunkManager.java    From EntityAPI with GNU Lesser General Public License v3.0 7 votes vote down vote up
@EventHandler
public void onUnload(ChunkUnloadEvent event) {
    Chunk unloadedChunk = event.getChunk();
    for (Entity entity : unloadedChunk.getEntities()) {
        if (entity instanceof LivingEntity) {
            Object handle = BukkitUnwrapper.getInstance().unwrap(entity);
            if (handle instanceof ControllableEntityHandle) {
                ControllableEntity controllableEntity = ((ControllableEntityHandle) handle).getControllableEntity();
                if (controllableEntity != null && controllableEntity.isSpawned()) {
                    this.SPAWN_QUEUE.add(new EntityChunkData(controllableEntity, entity.getLocation()));
                    controllableEntity.despawn(DespawnReason.CHUNK_UNLOAD);
                }
            }
        }
    }
}
 
Example #2
Source File: PreventEndermanHeightExploit.java    From EliteMobs with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler (priority = EventPriority.HIGHEST)
public void onDamage(EntityDamageByEntityEvent event){

    if (event.isCancelled()) return;
    if (!event.getEntity().getType().equals(EntityType.ENDERMAN)) return;
    EntityType entityType = EntityFinder.getRealDamager(event).getType();
    if (entityType == null) return;
    if (!entityType.equals(EntityType.PLAYER)) return;

    EliteMobEntity eliteMobEntity = EntityTracker.getEliteMobEntity(event.getEntity());
    if (eliteMobEntity == null) return;

    Block block = EntityFinder.getRealDamager(event).getLocation().getBlock().getLocation().add(new Vector(0, 2, 0)).getBlock();
    if (block.getType().equals(Material.AIR) || block.getType().equals(Material.WATER)) return;

    eliteMobEntity.setHasSpecialLoot(false);
    AntiExploitMessage.sendWarning((LivingEntity) event.getEntity());

}
 
Example #3
Source File: ParticleEffect.java    From Civs with GNU General Public License v3.0 6 votes vote down vote up
public void apply() {
    Object target = getTarget();

    if (!(target instanceof LivingEntity)) {
        return;
    }
    LivingEntity livingEntity = (LivingEntity) target;
    final BukkitRunnable runnable = new BukkitRunnable() {
        @Override
        public void run() {
            onUpdate();
        }
    };
    runnable.runTaskAsynchronously(Civs.getInstance());
    if (duration > 0) {
        BukkitRunnable runnable1 = new BukkitRunnable() {
            @Override
            public void run() {
                runnable.cancel();
            }
        };
    }
}
 
Example #4
Source File: SentinelWar.java    From Sentinel with MIT License 6 votes vote down vote up
@Override
public boolean isTarget(LivingEntity ent, String prefix, String value) {
    try {
        if (prefix.equals("war_team") && ent instanceof Player) {
            Team team = Team.getTeamByPlayerName(ent.getName());
            if (team.getName().equalsIgnoreCase(value)) {
                return true;
            }
            else {
                return false;
            }
        }
    }
    catch (Exception ex) {
        ex.printStackTrace();
    }
    return false;
}
 
Example #5
Source File: CraftBeacon.java    From Kettle with GNU General Public License v3.0 6 votes vote down vote up
@Override
public Collection<LivingEntity> getEntitiesInRange() {
    TileEntity tileEntity = this.getTileEntityFromWorld();
    if (tileEntity instanceof TileEntityBeacon) {
        TileEntityBeacon beacon = (TileEntityBeacon) tileEntity;

        Collection<EntityPlayer> nms = beacon.getHumansInRange();
        Collection<LivingEntity> bukkit = new ArrayList<LivingEntity>(nms.size());

        for (EntityPlayer human : nms) {
            bukkit.add(human.getBukkitEntity());
        }

        return bukkit;
    }

    // block is no longer a beacon
    return new ArrayList<LivingEntity>();
}
 
Example #6
Source File: Listener_V7_0.java    From CombatLogX with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(priority=EventPriority.HIGHEST)
public void onPreventPVP(DisallowedPVPEvent e) {
    NoEntryHandler handler = this.expansion.getNoEntryHandler();
    NoEntryMode mode = handler.getNoEntryMode();
    if(mode != NoEntryMode.VULNERABLE) return;

    ICombatLogX plugin = this.expansion.getPlugin();
    ICombatManager manager = plugin.getCombatManager();

    Player player = e.getDefender();
    if(!manager.isInCombat(player)) return;

    LivingEntity enemy = manager.getEnemy(player);
    if(enemy == null) return;

    e.setCancelled(true);
    this.expansion.sendNoEntryMessage(player, enemy);
}
 
Example #7
Source File: NoEntryListener.java    From CombatLogX with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(priority=EventPriority.HIGHEST)
public void onCancelPVP(EntityDamageByEntityEvent e) {
    if(!e.isCancelled()) return;
    if(this.expansion.getNoEntryHandler().getNoEntryMode() != NoEntryMode.VULNERABLE) return;

    Entity entity = e.getEntity();
    if(!(entity instanceof Player)) return;

    ICombatLogX plugin = this.expansion.getPlugin();
    ICombatManager manager = plugin.getCombatManager();

    Player player = (Player) entity;
    if(!manager.isInCombat(player)) return;

    LivingEntity enemy = manager.getEnemy(player);
    if(enemy == null) return;

    e.setCancelled(false);
    this.expansion.sendNoEntryMessage(player, enemy);
}
 
Example #8
Source File: EffExplodeCreeper.java    From Skript with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void execute(final Event e) {
	for (final LivingEntity le : entities.getArray(e)) {
		if (le instanceof Creeper) {
			if (instant) {
				((Creeper) le).explode();
			} else if (stop) {
				((Creeper) le).setIgnited(false);
			} else {
				if (paper) {
					((Creeper) le).setIgnited(true);
				} else {
					((Creeper) le).ignite();
				}
			}
		}
	}
}
 
Example #9
Source File: LimitLogic.java    From uSkyBlock with GNU General Public License v3.0 6 votes vote down vote up
public Map<CreatureType, Integer> getCreatureCount(us.talabrek.ultimateskyblock.api.IslandInfo islandInfo) {
    Map<CreatureType, Integer> mapCount = new HashMap<>();
    for (CreatureType type : CreatureType.values()) {
        mapCount.put(type, 0);
    }
    Location islandLocation = islandInfo.getIslandLocation();
    ProtectedRegion islandRegionAt = WorldGuardHandler.getIslandRegionAt(islandLocation);
    if (islandRegionAt != null) {
        // Nether and Overworld regions are more or less equal (same x,z coords)
        List<LivingEntity> creatures = WorldGuardHandler.getCreaturesInRegion(plugin.getWorldManager().getWorld(),
                islandRegionAt);
        World nether = plugin.getWorldManager().getNetherWorld();
        if (nether != null) {
            creatures.addAll(WorldGuardHandler.getCreaturesInRegion(nether, islandRegionAt));
        }
        for (LivingEntity creature : creatures) {
            CreatureType key = getCreatureType(creature);
            if (!mapCount.containsKey(key)) {
                mapCount.put(key, 0);
            }
            mapCount.put(key, mapCount.get(key) + 1);
        }
    }
    return mapCount;
}
 
Example #10
Source File: EntityUtils.java    From BedWars with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static EntityLivingNMS makeMobAttackTarget(LivingEntity mob, double speed, double follow,
	double attackDamage) {
	try {
		Object handler = getHandle(mob);
		if (!EntityInsentient.isInstance(handler)) {
			throw new IllegalArgumentException("Entity must be instance of EntityInsentient!!");
		}
		
		EntityLivingNMS entityLiving = new EntityLivingNMS(handler);
		
		GoalSelector selector = entityLiving.getGoalSelector();
		selector.clearSelector();
		selector.registerPathfinder(0, PathfinderGoalMeleeAttack
			.getConstructor(EntityCreature, double.class, boolean.class).newInstance(handler, 1.0D, false));
		
		entityLiving.setAttribute(Attribute.MOVEMENT_SPEED, speed);
		entityLiving.setAttribute(Attribute.FOLLOW_RANGE, follow);
		entityLiving.setAttribute(Attribute.ATTACK_DAMAGE, attackDamage);
		
		entityLiving.getTargetSelector().clearSelector();
		
		return entityLiving;
	} catch (Throwable ignored) {
	}
	return null;
}
 
Example #11
Source File: ExprShooter.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@Override
@Nullable
public Class<?>[] acceptChange(final ChangeMode mode) {
	if (mode == ChangeMode.SET)
		return new Class[] {LivingEntity.class};
	return super.acceptChange(mode);
}
 
Example #12
Source File: Hardened.java    From ce with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void effect(Event e, ItemStack item, int level) {
	EntityDamageByEntityEvent event = (EntityDamageByEntityEvent) e;
	LivingEntity target = (LivingEntity) event.getDamager();
		target.addPotionEffect(
				new PotionEffect(
						PotionEffectType.WEAKNESS, 
						duration * level,
						strength + level));

}
 
Example #13
Source File: CraftProjectile.java    From Thermos with GNU General Public License v3.0 5 votes vote down vote up
@Deprecated
public LivingEntity _INVALID_getShooter() {
    if (getHandle().thrower == null) {
        return null;
    }
    return (LivingEntity) getHandle().thrower.getBukkitEntity();
}
 
Example #14
Source File: LimitLogic.java    From uSkyBlock with GNU General Public License v3.0 5 votes vote down vote up
public CreatureType getCreatureType(LivingEntity creature) {
    if (creature instanceof Monster
            || creature instanceof WaterMob
            || creature instanceof Slime
            || creature instanceof Ghast) {
        return CreatureType.MONSTER;
    } else if (creature instanceof Animals) {
        return CreatureType.ANIMAL;
    } else if (creature instanceof Villager) {
        return CreatureType.VILLAGER;
    } else if (creature instanceof Golem) {
        return CreatureType.GOLEM;
    }
    return CreatureType.UNKNOWN;
}
 
Example #15
Source File: CraftEventFactory.java    From Thermos with GNU General Public License v3.0 5 votes vote down vote up
public static EntityBreakDoorEvent callEntityBreakDoorEvent(net.minecraft.entity.Entity entity, int x, int y, int z) {
    org.bukkit.entity.Entity entity1 = entity.getBukkitEntity();
    Block block = entity1.getWorld().getBlockAt(x, y, z);

    EntityBreakDoorEvent event = new EntityBreakDoorEvent((LivingEntity) entity1, block);
    entity1.getServer().getPluginManager().callEvent(event);

    return event;
}
 
Example #16
Source File: Blind.java    From ce with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void effect(Event e, ItemStack item, int level) {
    EntityDamageByEntityEvent event = (EntityDamageByEntityEvent) e;
    LivingEntity target = (LivingEntity) event.getEntity();
    EffectManager.playSound(target.getLocation(), "ENTITY_PLAYER_HURT", 1f, 0.4f);
    target.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, duration + 20 * level, 0));

}
 
Example #17
Source File: EffChargeCreeper.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings({"unchecked", "null"})
@Override
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
	entities = (Expression<LivingEntity>) exprs[0];
	charge = parseResult.mark != 1;
	return true;
}
 
Example #18
Source File: EffLeash.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
	leash = matchedPattern != 2;
	if (leash) {
		holder = (Expression<Entity>) exprs[1 - matchedPattern];
		targets = (Expression<LivingEntity>) exprs[matchedPattern];
	} else {
		targets = (Expression<LivingEntity>) exprs[0];
	}
	return true;
}
 
Example #19
Source File: DisguiseManager.java    From iDisguise with Creative Commons Attribution Share Alike 4.0 International 5 votes vote down vote up
public static synchronized void hideEntityFromAll(LivingEntity livingEntity) {
	// do nothing if entity is invalid (dead or despawned)
	if(!(livingEntity instanceof Player) && !livingEntity.isValid()) {
		return;
	}
	
	try {
		Object playerInfoPacket = null;
		boolean isPlayer = livingEntity instanceof Player, disguisedAsPlayer = getDisguise(livingEntity) instanceof PlayerDisguise;
		
		if(isPlayer || disguisedAsPlayer) {
			// construct the packet
			playerInfoPacket = PacketPlayOutPlayerInfo_new.newInstance();
			PacketPlayOutPlayerInfo_action.set(playerInfoPacket, EnumPlayerInfoAction_REMOVE_PLAYER.get(null));
			List playerInfoList = (List)PacketPlayOutPlayerInfo_playerInfoList.get(playerInfoPacket);
			playerInfoList.add(PlayerInfoData_new.newInstance(playerInfoPacket, ProfileHelper.getInstance().getGameProfile(livingEntity.getUniqueId(), "", ""), 35, EnumGamemode_SURVIVAL.get(null), null));
		}
		
		Object entityTrackerEntry = IntHashMap_get.invoke(EntityTracker_trackedEntities.get(WorldServer_entityTracker.get(Entity_world.get(CraftLivingEntity_getHandle.invoke(livingEntity)))), livingEntity.getEntityId());
		
		for(Player observer : Bukkit.getOnlinePlayers()) {
			
			if(livingEntity != observer) {
				// hide the entity
				EntityTrackerEntry_clear.invoke(entityTrackerEntry, CraftPlayer_getHandle.invoke(observer));
			}
			
			// send the player info removal if needed
			if(isPlayer ? disguiseViewSelf || livingEntity != observer : disguisedAsPlayer && isDisguisedTo(livingEntity, observer)) {
				ChannelInjector.sendPacketUnaltered(observer, playerInfoPacket);
			}
			
		}
	} catch(Exception e) {
		iDisguise.getInstance().getLogger().log(Level.SEVERE, "An unexpected exception occured.", e);
	}
}
 
Example #20
Source File: NMSImpl.java    From SonarPet with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean spawnEntity(NMSInsentientEntity wrapper, Location l) {
    EntityLiving entity = ((NMSEntityInsentientImpl) wrapper).getHandle();
    entity.spawnIn(((CraftWorld) l.getWorld()).getHandle());
    ((LivingEntity) entity.getBukkitEntity()).setCollidable(false);
    entity.setLocation(l.getX(), l.getY(), l.getZ(), l.getYaw(), l.getPitch());
    if (!l.getChunk().isLoaded()) {
        l.getChunk().load();
    }
    return entity.world.addEntity(entity, CreatureSpawnEvent.SpawnReason.CUSTOM);
}
 
Example #21
Source File: SlimefunBowListener.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onArrowSuccessfulHit(EntityDamageByEntityEvent e) {
    if (e.getDamager() instanceof Arrow && e.getEntity() instanceof LivingEntity && e.getCause() != EntityDamageEvent.DamageCause.ENTITY_EXPLOSION) {
        SlimefunBow bow = projectiles.get(e.getDamager().getUniqueId());

        if (bow != null) {
            bow.callItemHandler(BowShootHandler.class, handler -> handler.onHit(e, (LivingEntity) e.getEntity()));
        }

        projectiles.remove(e.getDamager().getUniqueId());
    }
}
 
Example #22
Source File: KnockbackPlayerFacet.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
@TargetedEventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onKnockback(PlayerKnockbackEvent event) {
    if(knockback.isPresent() &&
       victim.equals(event.getPlayer()) &&
       event.getDamager() instanceof LivingEntity) {

        event.setCancelled(true);
    }
}
 
Example #23
Source File: Drunk.java    From ce with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void effect(Event e, ItemStack item, int level) {
    EntityDamageByEntityEvent event = (EntityDamageByEntityEvent) e;
    LivingEntity target = (LivingEntity) event.getDamager();
    target.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, duration * level, strength + level));
    target.addPotionEffect(new PotionEffect(PotionEffectType.SLOW_DIGGING, duration * level, strength + level));
    target.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, duration * level, 0));
}
 
Example #24
Source File: NMSImpl.java    From SonarPet with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean spawnEntity(NMSInsentientEntity wrapper, Location l) {
    EntityLiving entity = ((NMSEntityInsentientImpl) wrapper).getHandle();
    entity.spawnIn(((CraftWorld) l.getWorld()).getHandle());
    ((LivingEntity) entity.getBukkitEntity()).setCollidable(false);
    entity.setLocation(l.getX(), l.getY(), l.getZ(), l.getYaw(), l.getPitch());
    if (!l.getChunk().isLoaded()) {
        l.getChunk().load();
    }
    return entity.world.addEntity(entity, CreatureSpawnEvent.SpawnReason.CUSTOM);
}
 
Example #25
Source File: McMMOHook.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
@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 #26
Source File: AreaTarget.java    From Civs with GNU General Public License v3.0 5 votes vote down vote up
public Set<?> getTargets() {
    int level = getLevel();
    Spell spell = getSpell();
    Set<LivingEntity> returnSet = new HashSet<>();
    if (!(getOrigin() instanceof LivingEntity)) {
        return returnSet;
    }
    LivingEntity player = (LivingEntity) getOrigin();
    ConfigurationSection config = getConfig();
    int range = (int) Math.round(Spell.getLevelAdjustedValue(getConfig().getString("range","15"), level, null, spell));
    int radius = (int) Math.round(Spell.getLevelAdjustedValue(getConfig().getString("radius", "5"), level, null, spell));
    int maxTargets = (int) Math.round(Spell.getLevelAdjustedValue(getConfig().getString("max-targets", "-1"), level, null, spell));
    Collection<Entity> nearbyEntities;
    if (range < 1) {
        nearbyEntities = player.getNearbyEntities(radius, radius, radius);
    } else {
        HashSet<Material> materialHashSet = new HashSet<>();
        Location center = player.getTargetBlock(materialHashSet, range).getLocation();
        center = applyTargetSettings(center);
        ArmorStand removeMe = (ArmorStand) center.getWorld().spawnEntity(center, EntityType.ARMOR_STAND);
        removeMe.setVisible(false);
        nearbyEntities = removeMe.getNearbyEntities(radius, radius, radius);
        removeMe.remove();
    }

    for (Entity target : nearbyEntities) {
        if (maxTargets > 0 && returnSet.size() >= maxTargets) {
            break;
        }

        if (target != player &&
                target instanceof LivingEntity) {

            returnSet.add((LivingEntity) target);
        }
    }
    return returnSet;
}
 
Example #27
Source File: EchoPetAPI.java    From EchoPet with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Set a target for the {@link com.dsh105.echopet.api.pet.Pet} to attack
 *
 * @param pet    the attacker
 * @param target the {@link org.bukkit.entity.LivingEntity} for the {@link com.dsh105.echopet.api.pet.Pet} to
 *               attack
 */
public void setAttackTarget(IPet pet, LivingEntity target) {
    if (pet == null) {
        EchoPet.LOG.severe("Failed to set attack target for Pet through the EchoPetAPI. Pet cannot be null.");
        return;
    }
    if (target == null) {
        EchoPet.LOG.severe("Failed to set attack target for Pet through the EchoPetAPI. Target cannot be null.");
        return;
    }
    if (pet.getEntityPet().getPetGoalSelector().getGoal("Attack") != null) {
        pet.getCraftPet().setTarget(target);
    }
}
 
Example #28
Source File: SeismicAxe.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public ItemUseHandler getItemHandler() {
    return e -> {
        Player p = e.getPlayer();
        List<Block> blocks = p.getLineOfSight(null, RANGE);

        for (int i = 2; i < blocks.size(); i++) {
            Block ground = findGround(blocks.get(i));
            Location groundLocation = ground.getLocation();

            ground.getWorld().playEffect(groundLocation, Effect.STEP_SOUND, ground.getType());

            if (ground.getRelative(BlockFace.UP).getType() == Material.AIR) {
                Location loc = ground.getRelative(BlockFace.UP).getLocation().add(0.5, 0.0, 0.5);
                FallingBlock block = ground.getWorld().spawnFallingBlock(loc, ground.getBlockData());
                block.setDropItem(false);
                block.setVelocity(new Vector(0, 0.4 + i * 0.01, 0));
                block.setMetadata("seismic_axe", new FixedMetadataValue(SlimefunPlugin.instance, "fake_block"));
            }

            for (Entity n : ground.getChunk().getEntities()) {
                if (n instanceof LivingEntity && n.getType() != EntityType.ARMOR_STAND && n.getLocation().distance(groundLocation) <= 2.0D && !n.getUniqueId().equals(p.getUniqueId())) {
                    pushEntity(p, n);
                }
            }
        }

        for (int i = 0; i < 4; i++) {
            damageItem(p, e.getItem());
        }
    };
}
 
Example #29
Source File: EffShear.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void execute(final Event e) {
	for (final LivingEntity en : sheep.getArray(e)) {
		if (en instanceof Sheep) {
			((Sheep) en).setSheared(shear);
		}
	}
}
 
Example #30
Source File: InternalPathfinderExecutor.java    From TabooLib with MIT License 5 votes vote down vote up
@Override
public void setTargetAi(LivingEntity entity, Iterable ai) {
    try {
        Ref.putField(((EntityInsentient) getEntityInsentient(entity)).targetSelector, this.pathfinderGoalSelectorSet, ai);
    } catch (Throwable t) {
        t.printStackTrace();
    }
}