use of org.bukkit.entity.LivingEntity in project EliteMobs by MagmaGuy.
the class AttackWither method onHit.
@EventHandler
public void onHit(EntityDamageByEntityEvent event) {
Entity damager = event.getDamager();
Entity damagee = event.getEntity();
if (damager.hasMetadata(powerMetadata) && damagee instanceof LivingEntity) {
((LivingEntity) damagee).addPotionEffect(new PotionEffect(PotionEffectType.WITHER, 50, 1));
}
if (damager instanceof Projectile) {
if (ProjectileMetadataDetector.projectileMetadataDetector((Projectile) damager, powerMetadata)) {
((LivingEntity) damagee).addPotionEffect(new PotionEffect(PotionEffectType.WITHER, 50, 1));
}
}
}
use of org.bukkit.entity.LivingEntity in project EliteMobs by MagmaGuy.
the class PowerHandler method powerHandler.
public static void powerHandler(Entity entity) {
int availableMinorPowers = 0;
int availableMajorPowers = 0;
if (entity.hasMetadata(MetadataHandler.ELITE_MOB_MD) && entity.isValid() && ((LivingEntity) entity).getHealth() > 0) {
if (entity.getMetadata(MetadataHandler.ELITE_MOB_MD).get(0).asInt() >= 5) {
int EliteMobLevel = entity.getMetadata(MetadataHandler.ELITE_MOB_MD).get(0).asInt();
availableMinorPowers = (EliteMobLevel - 5) / 10 + 1;
availableMajorPowers = EliteMobLevel / 10;
}
}
if (availableMinorPowers >= 1) {
int currentMinorPowerAmount = 0;
if (entity.hasMetadata(MetadataHandler.CUSTOM_POWERS_MD)) {
return;
}
if (minorPowerArray.isEmpty()) {
minorPowerArrayInitializer();
}
if (entity.hasMetadata(MetadataHandler.MINOR_POWER_AMOUNT_MD)) {
currentMinorPowerAmount = entity.getMetadata(MetadataHandler.MINOR_POWER_AMOUNT_MD).get(0).asInt();
//TODO: this is probably not working as intended
Iterator<MinorPowers> minorPowerIterator = minorPowerArray.iterator();
while (minorPowerIterator.hasNext()) {
MinorPowers minorPower = minorPowerIterator.next();
if (minorPower.existingPowers(entity)) {
minorPowerIterator.remove();
}
}
}
int missingMinorPowerAmount = availableMinorPowers - currentMinorPowerAmount;
if (missingMinorPowerAmount > 0 && minorPowerArray.size() > 0) {
for (int i = 0; i < missingMinorPowerAmount; i++) {
if (minorPowerArray.size() > 0) {
int randomizer = random.nextInt(minorPowerArray.size());
MinorPowers selectedMinorPower = minorPowerArray.get(randomizer);
minorPowerArray.remove(minorPowerArray.get(randomizer));
if (entity.hasMetadata(MetadataHandler.MINOR_POWER_AMOUNT_MD)) {
int oldMinorPowerAmount = entity.getMetadata(MetadataHandler.MINOR_POWER_AMOUNT_MD).get(0).asInt();
int newMinorPowerAmount = oldMinorPowerAmount + 1;
entity.setMetadata(MetadataHandler.MINOR_POWER_AMOUNT_MD, new FixedMetadataValue(plugin, newMinorPowerAmount));
} else {
entity.setMetadata(MetadataHandler.MINOR_POWER_AMOUNT_MD, new FixedMetadataValue(plugin, 1));
}
selectedMinorPower.applyPowers(entity);
}
}
}
}
if (availableMajorPowers >= 1) {
int currentMajorPowerAmount = 0;
if (entity.hasMetadata(MetadataHandler.CUSTOM_POWERS_MD)) {
return;
}
ArrayList<MajorPowers> majorPowersArrayList = new ArrayList();
if (majorPowersArrayList.isEmpty()) {
if (entity instanceof Zombie) {
//These powers can't be intialized like minor powers because the list depends on the mob type
//TODO: Add a mob type sensitive power list
majorPowersArrayList.add(zombieFriends);
majorPowersArrayList.add(zombieNecronomicon);
majorPowersArrayList.add(zombieTeamRocket);
majorPowersArrayList.add(zombieParents);
}
}
if (entity.hasMetadata(MetadataHandler.MAJOR_POWER_AMOUNT_MD)) {
currentMajorPowerAmount = entity.getMetadata(MetadataHandler.MAJOR_POWER_AMOUNT_MD).get(0).asInt();
Iterator<MajorPowers> majorPowerIterator = majorPowersArrayList.iterator();
while (majorPowerIterator.hasNext()) {
MajorPowers majorPowers = majorPowerIterator.next();
if (majorPowers.existingPowers(entity)) {
majorPowerIterator.remove();
}
}
}
//TODO: pretty sure this doesn't check for level 10?
int missingMajorPowerAmount = availableMajorPowers - currentMajorPowerAmount;
if (missingMajorPowerAmount > 0 && majorPowersArrayList.size() > 0) {
for (int i = 0; i < missingMajorPowerAmount; i++) {
if (majorPowersArrayList.size() > 0) {
int randomizer = random.nextInt(majorPowersArrayList.size());
MajorPowers selectedMajorPower = majorPowersArrayList.get(randomizer);
majorPowersArrayList.remove(majorPowersArrayList.get(randomizer));
if (entity.hasMetadata(MetadataHandler.MAJOR_POWER_AMOUNT_MD)) {
int oldMajorPowerAmount = entity.getMetadata(MetadataHandler.MAJOR_POWER_AMOUNT_MD).get(0).asInt();
int newMajorPowerAmount = oldMajorPowerAmount + 1;
entity.setMetadata(MetadataHandler.MAJOR_POWER_AMOUNT_MD, new FixedMetadataValue(plugin, newMajorPowerAmount));
} else {
entity.setMetadata(MetadataHandler.MAJOR_POWER_AMOUNT_MD, new FixedMetadataValue(plugin, 1));
}
selectedMajorPower.applyPowers(entity);
}
}
}
}
}
use of org.bukkit.entity.LivingEntity in project TotalFreedomMod by TotalFreedom.
the class ItemFun method onPlayerInteractEvent.
@EventHandler
public void onPlayerInteractEvent(PlayerInteractEvent event) {
if (event.getAction() == Action.LEFT_CLICK_AIR || event.getAction() == Action.LEFT_CLICK_BLOCK) {
return;
}
final Player player = event.getPlayer();
final FPlayer fPlayer = plugin.pl.getPlayer(player);
switch(event.getMaterial()) {
case RAW_FISH:
{
final int RADIUS_HIT = 5;
final int STRENGTH = 4;
// Clownfish
if (DepreciationAggregator.getData_MaterialData(event.getItem().getData()) != 2) {
break;
}
if (!plugin.al.isSeniorAdmin(player)) {
final StringBuilder msg = new StringBuilder();
final char[] chars = ("You are a clown.").toCharArray();
for (char c : chars) {
msg.append(FUtil.randomChatColor()).append(c);
}
player.sendMessage(msg.toString());
player.getEquipment().getItemInMainHand().setType(Material.POTATO_ITEM);
break;
}
event.setCancelled(true);
boolean didHit = false;
final Location playerLoc = player.getLocation();
final Vector playerLocVec = playerLoc.toVector();
final List<Player> players = player.getWorld().getPlayers();
for (final Player target : players) {
if (target == player) {
continue;
}
final Location targetPos = target.getLocation();
final Vector targetPosVec = targetPos.toVector();
try {
if (targetPosVec.distanceSquared(playerLocVec) < (RADIUS_HIT * RADIUS_HIT)) {
FUtil.setFlying(player, false);
target.setVelocity(targetPosVec.subtract(playerLocVec).normalize().multiply(STRENGTH));
didHit = true;
}
} catch (IllegalArgumentException ex) {
}
}
if (didHit) {
final Sound[] sounds = Sound.values();
for (Sound sound : sounds) {
if (sound.toString().contains("HIT")) {
playerLoc.getWorld().playSound(randomOffset(playerLoc, 5.0), sound, 100.0f, randomDoubleRange(0.5, 2.0).floatValue());
}
}
}
break;
}
case CARROT_ITEM:
{
if (!ConfigEntry.ALLOW_EXPLOSIONS.getBoolean()) {
break;
}
if (!plugin.al.isSeniorAdmin(player)) {
break;
}
Location location = player.getLocation().clone();
Vector playerPostion = location.toVector().add(new Vector(0.0, 1.65, 0.0));
Vector playerDirection = location.getDirection().normalize();
double distance = 150.0;
Block targetBlock = DepreciationAggregator.getTargetBlock(player, null, Math.round((float) distance));
if (targetBlock != null) {
distance = location.distance(targetBlock.getLocation());
}
final List<Block> affected = new ArrayList<>();
Block lastBlock = null;
for (double offset = 0.0; offset <= distance; offset += (distance / 25.0)) {
Block block = playerPostion.clone().add(playerDirection.clone().multiply(offset)).toLocation(player.getWorld()).getBlock();
if (!block.equals(lastBlock)) {
if (block.isEmpty()) {
affected.add(block);
block.setType(Material.TNT);
} else {
break;
}
}
lastBlock = block;
}
new BukkitRunnable() {
@Override
public void run() {
for (Block tntBlock : affected) {
TNTPrimed tnt = tntBlock.getWorld().spawn(tntBlock.getLocation(), TNTPrimed.class);
tnt.setFuseTicks(5);
tntBlock.setType(Material.AIR);
}
}
}.runTaskLater(plugin, 30L);
event.setCancelled(true);
break;
}
case BONE:
{
if (!fPlayer.mobThrowerEnabled()) {
break;
}
Location player_pos = player.getLocation();
Vector direction = player_pos.getDirection().normalize();
LivingEntity rezzed_mob = (LivingEntity) player.getWorld().spawnEntity(player_pos.add(direction.multiply(2.0)), fPlayer.mobThrowerCreature());
rezzed_mob.setVelocity(direction.multiply(fPlayer.mobThrowerSpeed()));
fPlayer.enqueueMob(rezzed_mob);
event.setCancelled(true);
break;
}
case SULPHUR:
{
if (!fPlayer.isMP44Armed()) {
break;
}
event.setCancelled(true);
if (fPlayer.toggleMP44Firing()) {
fPlayer.startArrowShooter(plugin);
} else {
fPlayer.stopArrowShooter();
}
break;
}
case BLAZE_ROD:
{
if (!ConfigEntry.ALLOW_EXPLOSIONS.getBoolean()) {
break;
}
if (!plugin.al.isSeniorAdmin(player)) {
break;
}
event.setCancelled(true);
Block targetBlock;
if (event.getAction().equals(Action.LEFT_CLICK_AIR)) {
targetBlock = DepreciationAggregator.getTargetBlock(player, null, 120);
} else {
targetBlock = event.getClickedBlock();
}
if (targetBlock == null) {
player.sendMessage("Can't resolve target block.");
break;
}
player.getWorld().createExplosion(targetBlock.getLocation(), 4F, true);
player.getWorld().strikeLightning(targetBlock.getLocation());
break;
}
}
}
use of org.bukkit.entity.LivingEntity in project InfernalMobs by NyaaCat.
the class EventListener method onMobSpawn.
@EventHandler(priority = EventPriority.HIGH)
public void onMobSpawn(final CreatureSpawnEvent event) {
LivingEntity e = event.getEntity();
if (e.hasMetadata("NPC"))
return;
if (e.hasMetadata("shopkeeper"))
return;
if (e.getCustomName() != null)
return;
if (!ConfigReader.isEnabledWorld(e.getWorld()))
return;
if (!ConfigReader.isEnabledMobType(e.getType()))
return;
if (e.getLocation().getY() < ConfigReader.getNaturalSpawnMinHeight())
return;
if (!ConfigReader.getEnabledSpawnReasons().contains(event.getSpawnReason()))
return;
new BukkitRunnable() {
@Override
public void run() {
plugin.mobManager.infernalNaturalSpawn(e);
}
}.runTaskLater(plugin, 10L);
}
use of org.bukkit.entity.LivingEntity in project InfernalMobs by NyaaCat.
the class EventListener method onEntityAttack.
@EventHandler(priority = EventPriority.HIGH)
public void onEntityAttack(final EntityDamageByEntityEvent event) {
boolean isDirectAttack = true;
Entity trueVictim = event.getEntity();
Entity trueAttacker = event.getDamager();
if (trueAttacker instanceof Projectile) {
isDirectAttack = false;
ProjectileSource src = ((Projectile) trueAttacker).getShooter();
if (src instanceof Entity) {
trueAttacker = (Entity) src;
} else {
return;
}
}
if (!(trueAttacker instanceof LivingEntity))
return;
if (!(trueVictim instanceof LivingEntity))
return;
if (plugin.mobManager.mobMap.containsKey(trueVictim.getUniqueId())) {
// something attacked infernal mob
if (!(trueAttacker instanceof Player))
return;
if (((Player) trueAttacker).getGameMode() == GameMode.CREATIVE)
return;
Mob mob = plugin.mobManager.mobMap.get(trueVictim.getUniqueId());
for (EnumAbilities ab : mob.abilityList) {
ab.onPlayerAttack((LivingEntity) trueVictim, mob, (Player) trueAttacker, isDirectAttack, event);
}
}
if ((plugin.mobManager.mobMap.containsKey(trueAttacker.getUniqueId()))) {
// infernal mob attacked something
if (!(trueVictim instanceof Player))
return;
if (((Player) trueVictim).getGameMode() == GameMode.CREATIVE)
return;
Mob mob = plugin.mobManager.mobMap.get(trueAttacker.getUniqueId());
for (EnumAbilities ab : mob.abilityList) {
ab.onAttackPlayer((LivingEntity) trueAttacker, mob, (Player) trueVictim, isDirectAttack, event);
}
}
}
Aggregations