use of org.bukkit.entity.Creature in project solinia3-core by mixxit.
the class EntityManager method doNPCSpellCast.
@Override
public void doNPCSpellCast(Plugin plugin) {
List<Integer> completedNpcsIds = new ArrayList<Integer>();
for (Player player : Bukkit.getOnlinePlayers()) {
for (Entity entityThatWillCast : player.getNearbyEntities(50, 50, 50)) {
if (entityThatWillCast instanceof Player)
continue;
if (!(entityThatWillCast instanceof LivingEntity))
continue;
LivingEntity livingEntityThatWillCast = (LivingEntity) entityThatWillCast;
if (!(entityThatWillCast instanceof Creature))
continue;
if (entityThatWillCast.isDead())
continue;
Creature creatureThatWillCast = (Creature) entityThatWillCast;
if (creatureThatWillCast.getTarget() == null)
continue;
if (!Utils.isLivingEntityNPC(livingEntityThatWillCast))
continue;
try {
ISoliniaLivingEntity solLivingEntityThatWillCast = SoliniaLivingEntityAdapter.Adapt(livingEntityThatWillCast);
if (completedNpcsIds.contains(solLivingEntityThatWillCast.getNpcid()))
continue;
completedNpcsIds.add(solLivingEntityThatWillCast.getNpcid());
if (Utils.isEntityInLineOfSight(livingEntityThatWillCast, creatureThatWillCast.getTarget()))
solLivingEntityThatWillCast.doSpellCast(plugin, creatureThatWillCast.getTarget());
} catch (CoreStateInitException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
use of org.bukkit.entity.Creature in project solinia3-core by mixxit.
the class Solinia3CoreEntityListener method onEntityTargetEvent.
// Needs to occur before anything else
@EventHandler(priority = EventPriority.HIGHEST)
public void onEntityTargetEvent(EntityTargetEvent event) {
if (event.isCancelled())
return;
if (!(event.getEntity() instanceof Creature))
return;
try {
Timestamp mzExpiry = StateManager.getInstance().getEntityManager().getMezzed((LivingEntity) event.getEntity());
if (mzExpiry != null) {
if (event.getEntity() instanceof Player) {
event.getEntity().sendMessage("* You are mezzed!");
}
Utils.CancelEvent(event);
;
return;
}
} catch (CoreStateInitException e) {
}
try {
// Me
ISoliniaLivingEntity solEntity = SoliniaLivingEntityAdapter.Adapt((LivingEntity) event.getEntity());
if (solEntity.isUndead() && !(event.getEntity() instanceof Player) && event.getTarget() instanceof LivingEntity) {
if (StateManager.getInstance().getEntityManager().hasEntityEffectType((LivingEntity) event.getTarget(), SpellEffectType.InvisVsUndead) || StateManager.getInstance().getEntityManager().hasEntityEffectType((LivingEntity) event.getTarget(), SpellEffectType.InvisVsUndead2)) {
((Creature) event.getEntity()).setTarget(null);
Utils.CancelEvent(event);
;
return;
}
}
if (!solEntity.isUndead() && !(event.getEntity() instanceof Player) && !solEntity.isAnimal() && event.getTarget() instanceof LivingEntity) {
if (StateManager.getInstance().getEntityManager().hasEntityEffectType((LivingEntity) event.getTarget(), SpellEffectType.Invisibility) || StateManager.getInstance().getEntityManager().hasEntityEffectType((LivingEntity) event.getTarget(), SpellEffectType.Invisibility2)) {
((Creature) event.getEntity()).setTarget(null);
Utils.CancelEvent(event);
;
return;
}
}
if (solEntity.isAnimal() && !(event.getEntity() instanceof Player) && event.getTarget() instanceof LivingEntity) {
if (StateManager.getInstance().getEntityManager().hasEntityEffectType((LivingEntity) event.getTarget(), SpellEffectType.InvisVsAnimals) || StateManager.getInstance().getEntityManager().hasEntityEffectType((LivingEntity) event.getTarget(), SpellEffectType.ImprovedInvisAnimals)) {
((Creature) event.getEntity()).setTarget(null);
Utils.CancelEvent(event);
;
return;
}
}
// rogue sneak
if (event.getTarget() instanceof Player && !(event.getEntity() instanceof Player)) {
Player targetPlayer = (Player) event.getTarget();
if (targetPlayer.isSneaking()) {
ISoliniaPlayer player = SoliniaPlayerAdapter.Adapt((Player) event.getTarget());
if (player.getClassObj() != null) {
if (player.getClassObj().isSneakFromCrouch()) {
Utils.CancelEvent(event);
;
return;
}
}
}
}
if (event.getEntity() != null && event.getTarget() != null) {
if (!(event.getEntity() instanceof Player)) {
if (event.getEntity() instanceof LivingEntity) {
ISoliniaLivingEntity livingEntity = SoliniaLivingEntityAdapter.Adapt((LivingEntity) event.getEntity());
}
// Mez cancel target
Timestamp mezExpiry = StateManager.getInstance().getEntityManager().getMezzed((LivingEntity) event.getTarget());
if (mezExpiry != null) {
((Creature) event.getEntity()).setTarget(null);
event.getEntity().sendMessage("The target is mezzed, you cannot hit it");
Utils.CancelEvent(event);
;
return;
}
}
}
} catch (CoreStateInitException e) {
return;
}
}
use of org.bukkit.entity.Creature in project solinia3-core by mixxit.
the class SoliniaLivingEntity method doCheckForEnemies.
@Override
public void doCheckForEnemies() {
if (isPlayer())
return;
if (this.getNpcid() < 1)
return;
if (getBukkitLivingEntity().isDead())
return;
if (!(getBukkitLivingEntity() instanceof Creature))
return;
if (((Creature) getBukkitLivingEntity()).getTarget() != null)
return;
try {
ISoliniaNPC npc = StateManager.getInstance().getConfigurationManager().getNPC(this.getNpcid());
if (npc.getFactionid() == 0)
return;
ISoliniaFaction faction = StateManager.getInstance().getConfigurationManager().getFaction(npc.getFactionid());
if (faction.getName().equals("NEUTRAL") || faction.getName().equals("KOS"))
return;
for (Entity entity : getBukkitLivingEntity().getNearbyEntities(10, 10, 10)) {
if (!(entity instanceof Player))
continue;
if (entity.isDead())
continue;
Player player = (Player) entity;
ISoliniaPlayer solPlayer = SoliniaPlayerAdapter.Adapt(player);
PlayerFactionEntry factionEntry = solPlayer.getFactionEntry(npc.getFactionid());
if (factionEntry != null) {
switch(Utils.getFactionStandingType(factionEntry.getFactionId(), factionEntry.getValue())) {
case FACTION_THREATENLY:
case FACTION_SCOWLS:
if (Utils.isEntityInLineOfSight(player, getBukkitLivingEntity())) {
((Creature) getBukkitLivingEntity()).setTarget(player);
return;
} else {
continue;
}
default:
break;
}
}
}
} catch (CoreStateInitException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
use of org.bukkit.entity.Creature in project solinia3-core by mixxit.
the class SoliniaItem method useItemOnEntity.
@Override
public boolean useItemOnEntity(Plugin plugin, Player player, LivingEntity targetentity, boolean isConsumable) throws CoreStateInitException {
if (isPetControlRod()) {
LivingEntity pet = StateManager.getInstance().getEntityManager().getPet(player);
if (pet != null) {
if (pet instanceof Wolf) {
// Mez cancel target
Timestamp mezExpiry = StateManager.getInstance().getEntityManager().getMezzed(targetentity);
if (mezExpiry != null) {
((Creature) pet).setTarget(null);
Wolf wolf = (Wolf) pet;
wolf.setTarget(null);
player.sendMessage("You cannot send your pet to attack a mezzed player");
return false;
}
if (!pet.getUniqueId().equals(targetentity.getUniqueId())) {
Wolf wolf = (Wolf) pet;
wolf.setTarget(targetentity);
player.sendMessage("You send your pet to attack!");
return true;
} else {
Wolf wolf = (Wolf) pet;
wolf.setTarget(null);
player.sendMessage("You cannot send your pet to attack itself");
return false;
}
}
}
}
if (isConsumable == true && isExperienceBonus()) {
SoliniaPlayerAdapter.Adapt(player).grantExperienceBonusFromItem();
System.out.println("Granted " + player.getName() + " experience bonus from item [" + SoliniaPlayerAdapter.Adapt(player).getExperienceBonusExpires().toString() + "]");
return true;
}
ISoliniaSpell spell = StateManager.getInstance().getConfigurationManager().getSpell(getAbilityid());
if (spell == null) {
return false;
}
ISoliniaLivingEntity solentity = SoliniaLivingEntityAdapter.Adapt((LivingEntity) player);
if (solentity == null)
return false;
if (!isConsumable)
if (spell.getActSpellCost(solentity) > SoliniaPlayerAdapter.Adapt(player).getMana()) {
player.sendMessage(ChatColor.GRAY + "Insufficient Mana [E] (Hold crouch or use /trance to meditate)");
return false;
}
try {
if (StateManager.getInstance().getEntityManager().getEntitySpellCooldown(player, spell.getId()) != null) {
LocalDateTime datetime = LocalDateTime.now();
Timestamp nowtimestamp = Timestamp.valueOf(datetime);
Timestamp expiretimestamp = StateManager.getInstance().getEntityManager().getEntitySpellCooldown(player, spell.getId());
if (expiretimestamp != null)
if (!nowtimestamp.after(expiretimestamp)) {
player.sendMessage("You do not have enough willpower to cast " + spell.getName() + " (Wait: " + ((expiretimestamp.getTime() - nowtimestamp.getTime()) / 1000) + "s");
return false;
}
}
} catch (CoreStateInitException e) {
// skip
return false;
}
boolean itemUseSuccess = spell.tryApplyOnEntity(plugin, player, targetentity);
if (itemUseSuccess) {
if (spell.getRecastTime() > 0) {
LocalDateTime datetime = LocalDateTime.now();
Timestamp expiretimestamp = Timestamp.valueOf(datetime.plus(spell.getRecastTime(), ChronoUnit.MILLIS));
StateManager.getInstance().getEntityManager().addEntitySpellCooldown(player, spell.getId(), expiretimestamp);
}
if (!isConsumable)
SoliniaPlayerAdapter.Adapt(player).reducePlayerMana(spell.getActSpellCost(solentity));
}
return itemUseSuccess;
}
use of org.bukkit.entity.Creature in project MagicPlugin by elBukkit.
the class MagicMACreature method spawn.
@Nullable
@Override
public LivingEntity spawn(Arena arena, World world, Location loc) {
loc.setWorld(world);
Entity entity = entityData.spawn(controller, loc);
if (!(entity instanceof LivingEntity))
return null;
if (entity instanceof Creature) {
Creature c = (Creature) entity;
c.setTarget(WaveUtils.getClosestPlayer(arena, entity));
}
return (LivingEntity) entity;
}
Aggregations