use of com.jacob_vejvoda.infernal_mobs.ability.EnumAbilities in project InfernalMobs by NyaaCat.
the class MobManager method spawnMob.
public Mob spawnMob(EntityType type, Location loc, List<EnumAbilities> abilities, UUID parentId, InfernalSpawnReason reason) {
if (!type.isAlive())
throw new IllegalArgumentException(type.name() + " is not a living entity");
Entity spawnedEntity = loc.getWorld().spawnEntity(loc, type);
UUID id = spawnedEntity.getUniqueId();
int lives = abilities.contains(EnumAbilities.ONEUP) ? 2 : 1;
Mob mob = new Mob(id, lives, ConfigReader.getRandomParticleEffect(), abilities);
mobMap.put(id, mob);
unnaturallySpawned.put(id, true);
InfernalMobSpawnEvent spwanEvent = new InfernalMobSpawnEvent((LivingEntity) spawnedEntity, mob, parentId, reason);
for (EnumAbilities ability : abilities) ability.onMobSpawn(spwanEvent);
setInfernalHealth(spwanEvent);
setInfernalMobName(spwanEvent);
Bukkit.getServer().getPluginManager().callEvent(spwanEvent);
return mob;
}
use of com.jacob_vejvoda.infernal_mobs.ability.EnumAbilities in project InfernalMobs by NyaaCat.
the class MobManager method infernalNaturalSpawn.
/**
* Change the given entity into infernal mob
* may need to be called delayed
*
* @param mobEntity the entity
*/
public void infernalNaturalSpawn(LivingEntity mobEntity) {
if (mobEntity.isDead() || !mobEntity.isValid() || mobEntity.getCustomName() != null)
return;
if (mobEntity.hasMetadata("NPC") || mobEntity.hasMetadata("shopkeeper"))
return;
if (!isAcceptableBaby(mobEntity))
return;
final UUID id = mobEntity.getUniqueId();
UUID parentId = mamaSpawned.getIfPresent(id);
if (unnaturallySpawned.getIfPresent(id) != null)
return;
if (!Helper.possibility(ConfigReader.getInfernalNaturalSpawningPercentage()))
return;
List<EnumAbilities> abilities = Helper.randomNItems(ConfigReader.getEnabledAbilities(), getInfernalLevelForLocation(mobEntity.getLocation()));
if (abilities == null || abilities.size() <= 0)
return;
if (parentId != null) {
if (!mobMap.containsKey(parentId) || mobMap.get(parentId).maxMamaInfernal <= 0) {
return;
}
mobMap.get(parentId).maxMamaInfernal--;
if (abilities.contains(EnumAbilities.MAMA)) {
abilities.remove(EnumAbilities.MAMA);
if (abilities.size() <= 0) {
return;
}
}
}
// setup infernal mob
int lives = abilities.contains(EnumAbilities.ONEUP) ? 2 : 1;
Mob mob = new Mob(id, lives, ConfigReader.getRandomParticleEffect(), abilities);
InfernalMobSpawnEvent spwanEvent;
if (parentId != null) {
spwanEvent = new InfernalMobSpawnEvent(mobEntity, mob, parentId, InfernalSpawnReason.MAMA);
} else {
spwanEvent = new InfernalMobSpawnEvent(mobEntity, mob, null, InfernalSpawnReason.NATURAL);
}
for (EnumAbilities ability : abilities) ability.onMobSpawn(spwanEvent);
setInfernalHealth(spwanEvent);
setInfernalMobName(spwanEvent);
mobMap.put(id, mob);
Bukkit.getPluginManager().callEvent(spwanEvent);
// Show message
if (ConfigReader.isSpwanMessageEnabled()) {
String msg = Helper.randomItem(ConfigReader.getSpwanMessages());
msg = msg.replace("{mob}", mobEntity.getCustomName() == null ? mobEntity.getType().name().toLowerCase() : mobEntity.getCustomName());
msg = ChatColor.translateAlternateColorCodes('&', msg);
if (ConfigReader.isBroadcastSpawnMessageServer()) {
Bukkit.broadcastMessage(msg);
} else if (ConfigReader.isBroadcastSpawnMessageWorld()) {
for (Player p : mobEntity.getWorld().getPlayers()) {
p.sendMessage(msg);
}
} else {
int r = ConfigReader.getSpawnMessageBroadcaseRadius();
for (Entity e : mobEntity.getNearbyEntities(r, r, r)) {
if (e instanceof Player) {
e.sendMessage(msg);
}
}
}
}
}
use of com.jacob_vejvoda.infernal_mobs.ability.EnumAbilities in project InfernalMobs by NyaaCat.
the class CommandHandler method printAbilities.
public static void printAbilities(CommandSender sender) {
sender.sendMessage("--Infernal Mobs Abilities--");
List<String> l = new ArrayList<>();
for (EnumAbilities a : EnumAbilities.values()) {
l.add(a.name().toLowerCase());
}
l.sort(Comparator.naturalOrder());
for (String str : l) {
sender.sendMessage(" - " + str);
}
}
use of com.jacob_vejvoda.infernal_mobs.ability.EnumAbilities 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);
}
}
}
use of com.jacob_vejvoda.infernal_mobs.ability.EnumAbilities in project InfernalMobs by NyaaCat.
the class GUI method updateMobScoreboard.
private static void updateMobScoreboard(Mob mob, LivingEntity mobEntity) {
Scoreboard sb = mobScoreboard.get(mob.entityId);
if (sb == null) {
// init scoreboard
sb = Bukkit.getScoreboardManager().getNewScoreboard();
mobScoreboard.put(mob.entityId, sb);
Objective obj = sb.registerNewObjective(OBJECTIVE_NAME_INFO, "dummy");
obj.setDisplaySlot(DisplaySlot.SIDEBAR);
obj.setDisplayName(mobEntity.getType().name());
// this is the actual "score"
int index = 1;
for (EnumAbilities ab : mob.abilityList) {
obj.getScore(ab.name().toLowerCase()).setScore(index++);
}
obj.getScore(ChatColor.YELLOW.toString() + ChatColor.BOLD + "Abilities:").setScore(index++);
double maxHealth = mobEntity.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue();
double health = mobEntity.getHealth();
obj.getScore(String.format("Health: %.0f/%.0f", health, maxHealth)).setScore(index);
} else {
// update scoreboard
Objective obj = sb.getObjective(OBJECTIVE_NAME_INFO);
int index = -1;
for (String str : sb.getEntries()) {
if (str.startsWith("Health:")) {
index = obj.getScore(str).getScore();
sb.resetScores(str);
}
}
double maxHealth = mobEntity.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue();
double health = mobEntity.getHealth();
obj.getScore(String.format("Health: %.0f/%.0f", health, maxHealth)).setScore(index);
}
}
Aggregations