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();
}
}
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()));
}
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);
});
}
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;
}
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));
}
}
Aggregations