Search in sources :

Example 51 with LivingEntity

use of org.bukkit.entity.LivingEntity in project InfernalMobs by NyaaCat.

the class AbilityFlying method onMobSpawn.

@Override
public void onMobSpawn(InfernalMobSpawnEvent ev) {
    LivingEntity infernal = ev.mobEntity;
    LivingEntity bat = (LivingEntity) infernal.getWorld().spawnEntity(infernal.getLocation(), EntityType.BAT);
    InfernalMobs.instance.mobManager.unnaturallySpawned.put(bat.getUniqueId(), true);
    if (bat.addPassenger(infernal)) {
        // success
        bat.setVelocity(new Vector(0, 1, 0));
        bat.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 999999, 1), true);
    } else {
        // failed
        bat.remove();
    }
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) PotionEffect(org.bukkit.potion.PotionEffect) Vector(org.bukkit.util.Vector)

Example 52 with LivingEntity

use of org.bukkit.entity.LivingEntity in project InfernalMobs by NyaaCat.

the class AbilityGravity method perCycleEffect.

@Override
public void perCycleEffect(LivingEntity mobEntity, Mob mob) {
    if (!Helper.possibility(0.2))
        return;
    Location mobLocation = mobEntity.getLocation();
    mobLocation.getWorld().getPlayers().stream().filter(p -> p.getLocation().distanceSquared(mobLocation) <= EFFECTIVE_RANGE_SQUARED).filter(p -> p.getGameMode() != GameMode.CREATIVE).filter(p -> {
        Location t = p.getLocation().clone();
        t.add(0, -2, 0);
        Block b = p.getWorld().getBlockAt(t);
        return b != null && b.getType() != AIR;
    }).filter(p -> Helper.possibility(0.2)).forEach(p -> levitate(p, ConfigReader.getGravityLevitateLength()));
}
Also used : Helper(com.jacob_vejvoda.infernal_mobs.Helper) Entity(org.bukkit.entity.Entity) Mob(com.jacob_vejvoda.infernal_mobs.persist.Mob) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) Player(org.bukkit.entity.Player) LivingEntity(org.bukkit.entity.LivingEntity) ConfigReader(com.jacob_vejvoda.infernal_mobs.ConfigReader) PotionEffect(org.bukkit.potion.PotionEffect) Vector(org.bukkit.util.Vector) GameMode(org.bukkit.GameMode) Block(org.bukkit.block.Block) Location(org.bukkit.Location) InfernalMobs(com.jacob_vejvoda.infernal_mobs.InfernalMobs) AIR(org.bukkit.Material.AIR) PotionEffectType(org.bukkit.potion.PotionEffectType) Block(org.bukkit.block.Block) Location(org.bukkit.Location)

Example 53 with LivingEntity

use of org.bukkit.entity.LivingEntity in project InfernalMobs by NyaaCat.

the class AbilityTosser method perCycleEffect.

@Override
public void perCycleEffect(LivingEntity mobEntity, Mob mob) {
    if (Helper.possibility(0.9))
        return;
    Location mobLocation = mobEntity.getLocation();
    mobEntity.getWorld().getPlayers().stream().filter(p -> p.getLocation().distanceSquared(mobLocation) < EFFECTIVE_RANGE_SQUARED).filter(p -> p.getLocation().distanceSquared(mobLocation) > 4).filter(p -> !p.isSneaking()).filter(p -> p.getGameMode() != GameMode.CREATIVE).forEach(p -> {
        Vector v = mobEntity.getEyeLocation().toVector().clone().subtract(p.getLocation().toVector());
        double len = v.length();
        if (len > 6 || len < 1)
            return;
        v.normalize().multiply(Math.min(2D, len / 2D));
        p.setVelocity(v);
    });
}
Also used : Vector(org.bukkit.util.Vector) Helper(com.jacob_vejvoda.infernal_mobs.Helper) GameMode(org.bukkit.GameMode) Location(org.bukkit.Location) Mob(com.jacob_vejvoda.infernal_mobs.persist.Mob) LivingEntity(org.bukkit.entity.LivingEntity) Vector(org.bukkit.util.Vector) Location(org.bukkit.Location)

Example 54 with LivingEntity

use of org.bukkit.entity.LivingEntity in project MyPet by xXKeyleXx.

the class CommandRelease method onCommand.

public boolean onCommand(final CommandSender sender, Command command, String label, String[] args) {
    if (sender instanceof Player) {
        Player petOwner = (Player) sender;
        if (MyPetApi.getMyPetManager().hasActiveMyPet(petOwner)) {
            MyPet myPet = MyPetApi.getMyPetManager().getMyPet(petOwner);
            if (!Permissions.hasLegacy(petOwner, "MyPet.command.release")) {
                return true;
            }
            if (myPet.getStatus() == PetState.Despawned) {
                sender.sendMessage(Util.formatText(Translation.getString("Message.Call.First", petOwner), myPet.getPetName()));
                return true;
            } else if (myPet.getStatus() == PetState.Dead) {
                sender.sendMessage(Util.formatText(Translation.getString("Message.Spawn.Respawn.In", petOwner), myPet.getPetName(), myPet.getRespawnTime()));
                return true;
            }
            String name = "";
            if (args.length > 0) {
                for (String arg : args) {
                    if (!name.equals("")) {
                        name += " ";
                    }
                    name += arg;
                }
            }
            if (ChatColor.stripColor(myPet.getPetName()).trim().equalsIgnoreCase(name.trim())) {
                MyPetRemoveEvent removeEvent = new MyPetRemoveEvent(myPet, MyPetRemoveEvent.Source.Release);
                Bukkit.getServer().getPluginManager().callEvent(removeEvent);
                if (myPet.getSkills().isSkillActive(Inventory.class)) {
                    myPet.getSkills().getSkill(Inventory.class).get().getInventory().dropContentAt(myPet.getLocation().get());
                }
                if (myPet instanceof MyPetEquipment) {
                    ((MyPetEquipment) myPet).dropEquipment();
                }
                if (!Configuration.Misc.REMOVE_PETS_AFTER_RELEASE) {
                    LivingEntity normalEntity = (LivingEntity) myPet.getLocation().get().getWorld().spawnEntity(myPet.getLocation().get(), EntityType.valueOf(myPet.getPetType().getBukkitName()));
                    Optional<EntityConverterService> converter = MyPetApi.getServiceManager().getService(EntityConverterService.class);
                    if (converter.isPresent()) {
                        converter.get().convertEntity(myPet, normalEntity);
                    }
                }
                myPet.removePet();
                myPet.getOwner().setMyPetForWorldGroup(WorldGroup.getGroupByWorld(petOwner.getWorld().getName()), null);
                sender.sendMessage(Util.formatText(Translation.getString("Message.Command.Release.Success", petOwner), myPet.getPetName()));
                MyPetApi.getMyPetManager().deactivateMyPet(myPet.getOwner(), false);
                MyPetApi.getRepository().removeMyPet(myPet.getUUID(), null);
                return true;
            } else {
                FancyMessage message = new FancyMessage(Translation.getString("Message.Command.Release.Confirm", petOwner) + " ");
                List<String> lore = new ArrayList<>();
                lore.add(RESET + Translation.getString("Name.Hunger", petOwner) + ": " + GOLD + Math.round(myPet.getSaturation()));
                if (myPet.getRespawnTime() > 0) {
                    lore.add(RESET + Translation.getString("Name.Respawntime", petOwner) + ": " + GOLD + myPet.getRespawnTime() + "sec");
                } else {
                    lore.add(RESET + Translation.getString("Name.HP", petOwner) + ": " + GOLD + String.format("%1.2f", myPet.getHealth()));
                }
                lore.add(RESET + Translation.getString("Name.Exp", petOwner) + ": " + GOLD + String.format("%1.2f", myPet.getExp()));
                lore.add(RESET + Translation.getString("Name.Type", petOwner) + ": " + GOLD + Translation.getString("Name." + myPet.getPetType().name(), petOwner));
                lore.add(RESET + Translation.getString("Name.Skilltree", petOwner) + ": " + GOLD + (myPet.getSkilltree() != null ? myPet.getSkilltree().getDisplayName() : "-"));
                message.then(myPet.getPetName()).color(ChatColor.AQUA).command("/petrelease " + ChatColor.stripColor(myPet.getPetName())).itemTooltip(new ItemTooltip().setMaterial(Material.MONSTER_EGG).addLore(lore).setTitle(myPet.getPetName()));
                MyPetApi.getPlatformHelper().sendMessageRaw((Player) sender, message.toJSONString());
                return true;
            }
        } else {
            sender.sendMessage(Translation.getString("Message.No.HasPet", petOwner));
        }
        return true;
    }
    sender.sendMessage("You can't use this command from server console!");
    return false;
}
Also used : EntityConverterService(de.Keyle.MyPet.api.util.service.types.EntityConverterService) Player(org.bukkit.entity.Player) MyPet(de.Keyle.MyPet.api.entity.MyPet) ArrayList(java.util.ArrayList) FancyMessage(de.keyle.fanciful.FancyMessage) LivingEntity(org.bukkit.entity.LivingEntity) MyPetRemoveEvent(de.Keyle.MyPet.api.event.MyPetRemoveEvent) ItemTooltip(de.keyle.fanciful.ItemTooltip) MyPetEquipment(de.Keyle.MyPet.api.entity.MyPetEquipment) Inventory(de.Keyle.MyPet.skill.skills.Inventory)

Example 55 with LivingEntity

use of org.bukkit.entity.LivingEntity in project MyPet by xXKeyleXx.

the class MyPetExperience method addDamageToEntity.

@SuppressWarnings("unchecked")
public static void addDamageToEntity(LivingEntity damager, LivingEntity victim, double damage) {
    Map<Entity, Double> damageMap;
    if (victim.hasMetadata("DamageCount")) {
        for (MetadataValue value : victim.getMetadata("DamageCount")) {
            if (value.getOwningPlugin().getName().equals("MyPet")) {
                damageMap = (Map<Entity, Double>) value.value();
                if (damageMap.containsKey(damager)) {
                    double oldDamage = damageMap.get(damager);
                    damageMap.put(damager, victim.getHealth() < damage ? victim.getHealth() + oldDamage : damage + oldDamage);
                } else {
                    damageMap.put(damager, victim.getHealth() < damage ? victim.getHealth() : damage);
                }
                break;
            }
        }
    } else {
        damageMap = new WeakHashMap<>();
        damageMap.put(damager, victim.getHealth() < damage ? victim.getHealth() : damage);
        victim.setMetadata("DamageCount", new FixedMetadataValue(MyPetApi.getPlugin(), damageMap));
    }
}
Also used : Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) FixedMetadataValue(org.bukkit.metadata.FixedMetadataValue) MetadataValue(org.bukkit.metadata.MetadataValue) FixedMetadataValue(org.bukkit.metadata.FixedMetadataValue)

Aggregations

LivingEntity (org.bukkit.entity.LivingEntity)57 Entity (org.bukkit.entity.Entity)27 Player (org.bukkit.entity.Player)23 EventHandler (org.bukkit.event.EventHandler)22 Location (org.bukkit.Location)12 ArrayList (java.util.ArrayList)11 Vector (org.bukkit.util.Vector)10 Projectile (org.bukkit.entity.Projectile)9 PotionEffect (org.bukkit.potion.PotionEffect)9 FixedMetadataValue (org.bukkit.metadata.FixedMetadataValue)8 Mob (com.jacob_vejvoda.infernal_mobs.persist.Mob)7 net.aufdemrand.denizen.objects.dEntity (net.aufdemrand.denizen.objects.dEntity)7 ItemStack (org.bukkit.inventory.ItemStack)7 List (java.util.List)5 Element (net.aufdemrand.denizencore.objects.Element)5 Island (com.wasteofplastic.acidisland.Island)4 HashMap (java.util.HashMap)4 World (org.bukkit.World)4 EntityDamageByEntityEvent (org.bukkit.event.entity.EntityDamageByEntityEvent)4 Helper (com.jacob_vejvoda.infernal_mobs.Helper)3