use of com.solinia.solinia.Models.SoliniaActiveSpell in project solinia3-core by mixxit.
the class Solinia3CoreEntityListener method onEntityDamage.
@EventHandler
public void onEntityDamage(EntityDamageEvent event) {
if (event.isCancelled())
return;
if (!(event instanceof EntityDamageByEntityEvent)) {
return;
}
EntityDamageByEntityEvent damagecause = (EntityDamageByEntityEvent) event;
// If the event is being blocked by a shield negate 85% of it unless its thorns then always allow it through
if (damagecause.getDamage(DamageModifier.BLOCKING) < 0) {
if (event.getCause().equals(DamageCause.THORNS)) {
damagecause.setDamage(DamageModifier.BLOCKING, 0);
} else {
// Only give them 15% blocking
double newarmour = (damagecause.getDamage(DamageModifier.BLOCKING) / 100) * 15;
damagecause.setDamage(DamageModifier.BLOCKING, newarmour);
}
}
// and check they are not mezzed
try {
if (damagecause.getDamager() instanceof LivingEntity) {
LivingEntity attacker = (LivingEntity) damagecause.getDamager();
// Change attacker to archer
if (damagecause.getDamager() instanceof Arrow) {
Arrow arr = (Arrow) attacker;
if (arr.getShooter() instanceof LivingEntity) {
attacker = (LivingEntity) arr.getShooter();
} else {
}
}
// cancel attacks on mobs mezzed
if (attacker instanceof Creature && attacker instanceof LivingEntity && event.getEntity() instanceof LivingEntity) {
ISoliniaLivingEntity solCreatureEntity = SoliniaLivingEntityAdapter.Adapt(attacker);
if (solCreatureEntity.isPet() || !solCreatureEntity.isPlayer()) {
Timestamp mezExpiry = StateManager.getInstance().getEntityManager().getMezzed((LivingEntity) event.getEntity());
if (mezExpiry != null) {
((Creature) attacker).setTarget(null);
if (solCreatureEntity.isPet()) {
Wolf wolf = (Wolf) attacker;
wolf.setTarget(null);
solCreatureEntity.say("Stopping attacking master, the target is mesmerized");
}
event.setCancelled(true);
return;
}
}
}
try {
Timestamp mzExpiry = StateManager.getInstance().getEntityManager().getMezzed((LivingEntity) attacker);
if (mzExpiry != null) {
if (attacker instanceof Player) {
attacker.sendMessage("* You are mezzed!");
}
Utils.CancelEvent(event);
;
return;
}
} catch (CoreStateInitException e) {
}
List<Integer> removeSpells = new ArrayList<Integer>();
for (SoliniaActiveSpell spell : StateManager.getInstance().getEntityManager().getActiveEntitySpells((LivingEntity) attacker).getActiveSpells()) {
if (spell.getSpell().getSpellEffectTypes().contains(SpellEffectType.InvisVsUndead) || spell.getSpell().getSpellEffectTypes().contains(SpellEffectType.Mez) || spell.getSpell().getSpellEffectTypes().contains(SpellEffectType.InvisVsUndead2) || spell.getSpell().getSpellEffectTypes().contains(SpellEffectType.Invisibility) || spell.getSpell().getSpellEffectTypes().contains(SpellEffectType.Invisibility2) || spell.getSpell().getSpellEffectTypes().contains(SpellEffectType.InvisVsAnimals) || spell.getSpell().getSpellEffectTypes().contains(SpellEffectType.ImprovedInvisAnimals)) {
if (!removeSpells.contains(spell.getSpell().getId()))
removeSpells.add(spell.getSpell().getId());
}
}
for (Integer spellId : removeSpells) {
StateManager.getInstance().getEntityManager().removeSpellEffectsOfSpellId(plugin, ((LivingEntity) attacker).getUniqueId(), spellId);
}
}
} catch (CoreStateInitException e) {
// skip
}
// Remove buffs on recipient (invis should drop)
try {
if (event.getEntity() instanceof LivingEntity) {
List<Integer> removeSpells = new ArrayList<Integer>();
for (SoliniaActiveSpell spell : StateManager.getInstance().getEntityManager().getActiveEntitySpells((LivingEntity) event.getEntity()).getActiveSpells()) {
if (spell.getSpell().getSpellEffectTypes().contains(SpellEffectType.Mez) || spell.getSpell().getSpellEffectTypes().contains(SpellEffectType.InvisVsUndead) || spell.getSpell().getSpellEffectTypes().contains(SpellEffectType.InvisVsUndead) || spell.getSpell().getSpellEffectTypes().contains(SpellEffectType.InvisVsUndead2) || spell.getSpell().getSpellEffectTypes().contains(SpellEffectType.Invisibility) || spell.getSpell().getSpellEffectTypes().contains(SpellEffectType.Invisibility2) || spell.getSpell().getSpellEffectTypes().contains(SpellEffectType.InvisVsAnimals) || spell.getSpell().getSpellEffectTypes().contains(SpellEffectType.ImprovedInvisAnimals)) {
if (!removeSpells.contains(spell.getSpell().getId()))
removeSpells.add(spell.getSpell().getId());
}
}
for (Integer spellId : removeSpells) {
StateManager.getInstance().getEntityManager().removeSpellEffectsOfSpellId(plugin, ((LivingEntity) event.getEntity()).getUniqueId(), spellId);
}
}
// Check for rune damage
if (event.getEntity() instanceof LivingEntity) {
ISoliniaLivingEntity soldefender = SoliniaLivingEntityAdapter.Adapt((LivingEntity) event.getEntity());
if (soldefender.isInvulnerable()) {
event.setDamage(0);
Utils.CancelEvent(event);
;
if (damagecause.getDamager() instanceof Player) {
((Player) damagecause.getDamager()).sendMessage("* Your attack was prevented as the target is Invulnerable!");
}
if (event.getEntity() instanceof Player) {
((Player) event.getEntity()).sendMessage("* Your invulnerability prevented the targets attack!");
}
}
}
// see if any runes want to reduce this damage
if (event.getEntity() instanceof LivingEntity) {
if (!event.getCause().equals(DamageCause.THORNS)) {
ISoliniaLivingEntity soldefender = SoliniaLivingEntityAdapter.Adapt((LivingEntity) event.getEntity());
event.setDamage(Utils.reduceDamage(soldefender, event.getDamage()));
}
}
// Check for rune damage
if (event.getEntity() instanceof LivingEntity) {
ISoliniaLivingEntity soldefender = SoliniaLivingEntityAdapter.Adapt((LivingEntity) event.getEntity());
if (soldefender.getRune() > 0) {
event.setDamage(soldefender.reduceAndRemoveRunesAndReturnLeftover(plugin, (int) event.getDamage()));
if (event.getDamage() <= 0) {
Utils.CancelEvent(event);
;
if (damagecause.getDamager() instanceof Player) {
((Player) damagecause.getDamager()).sendMessage("* Your attack was absorbed by the targets Rune");
}
if (event.getEntity() instanceof Player) {
((Player) event.getEntity()).sendMessage("* Your rune spell absorbed the targets attack!");
}
return;
}
}
}
} catch (CoreStateInitException e) {
// skip
}
if ((damagecause.getDamager() instanceof LivingEntity || damagecause.getDamager() instanceof Arrow) && event.getEntity() instanceof LivingEntity) {
// code
if (event.getCause().equals(DamageCause.THORNS)) {
if (damagecause.getDamager() instanceof Player) {
LivingEntity recipient = (LivingEntity) event.getEntity();
DecimalFormat df = new DecimalFormat();
df.setMaximumFractionDigits(2);
String name = recipient.getName();
if (recipient.getCustomName() != null)
name = recipient.getCustomName();
((Player) damagecause.getDamager()).spigot().sendMessage(ChatMessageType.ACTION_BAR, new TextComponent("You SPELLDMG'd " + name + " for " + df.format(event.getDamage()) + " [" + df.format(recipient.getHealth() - event.getDamage()) + "/" + df.format(recipient.getMaxHealth()) + "]"));
}
if (event.getEntity() instanceof LivingEntity) {
ISoliniaLivingEntity solentity;
try {
solentity = SoliniaLivingEntityAdapter.Adapt((LivingEntity) event.getEntity());
if (event.getDamage() > solentity.getBukkitLivingEntity().getHealth() && solentity.hasDeathSave() > 0) {
Utils.CancelEvent(event);
solentity.removeDeathSaves(plugin);
solentity.getBukkitLivingEntity().sendMessage("* Your death/divine save boon has saved you from death!");
return;
}
solentity.damageHook(event.getDamage(), damagecause.getDamager());
} catch (CoreStateInitException e) {
// skip
}
}
return;
}
try {
Entity damager = damagecause.getDamager();
// Change attacker to archer
if (damagecause.getDamager() instanceof Arrow) {
Arrow arr = (Arrow) damagecause.getDamager();
if (arr.getShooter() instanceof LivingEntity) {
damager = (LivingEntity) arr.getShooter();
// Modify Player Bow Damage
if (arr.getShooter() instanceof Player) {
Player shooter = (Player) arr.getShooter();
ItemStack mainitem = shooter.getInventory().getItemInMainHand();
if (mainitem != null) {
if (mainitem.getType() == Material.BOW) {
int dmgmodifier = 0;
if (Utils.IsSoliniaItem(mainitem)) {
try {
ISoliniaItem item = SoliniaItemAdapter.Adapt(mainitem);
if (item.getDamage() > 0 && item.getBasename().equals("BOW")) {
dmgmodifier = item.getDamage();
}
} catch (SoliniaItemException e) {
// sok just skip
}
}
event.setDamage(event.getDamage() + dmgmodifier);
}
}
}
} else {
}
}
if (!(damager instanceof LivingEntity))
return;
LivingEntity attacker = (LivingEntity) damager;
// Change attacker to archer
if (damagecause.getDamager() instanceof Arrow) {
Arrow arr = (Arrow) damagecause.getDamager();
if (arr.getShooter() instanceof LivingEntity) {
attacker = (LivingEntity) arr.getShooter();
} else {
}
}
if (attacker == null)
return;
ISoliniaLivingEntity soldefender = SoliniaLivingEntityAdapter.Adapt((LivingEntity) event.getEntity());
ISoliniaLivingEntity solattacker = SoliniaLivingEntityAdapter.Adapt((LivingEntity) attacker);
if (attacker instanceof Player && event.getEntity() instanceof Wolf) {
if (soldefender.isPet()) {
Wolf wolf = (Wolf) event.getEntity();
if (wolf != null) {
if (wolf.getTarget() == null || !wolf.getTarget().equals(attacker)) {
Utils.CancelEvent(event);
;
return;
}
} else {
Utils.CancelEvent(event);
;
return;
}
}
}
if (!(event instanceof EntityDamageByEntityEvent)) {
soldefender.damageHook(event.getDamage(), damagecause.getDamager());
return;
}
solattacker.Attack(soldefender, event, damagecause.getDamager() instanceof Arrow, plugin);
} catch (CoreStateInitException e) {
}
}
}
use of com.solinia.solinia.Models.SoliniaActiveSpell in project solinia3-core by mixxit.
the class CommandPet method onCommand.
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
// TODO Auto-generated method stub
if (sender instanceof Player) {
try {
Player player = (Player) sender;
LivingEntity pet = StateManager.getInstance().getEntityManager().getPet(player);
if (pet == null) {
player.sendMessage("You don't have a pet");
return true;
}
if (args.length > 0) {
String petcommand = args[0];
if (petcommand.equals("back")) {
Wolf c = (Wolf) pet;
player.setLastDamageCause(null);
player.sendMessage("* As you wish my master");
c.setTarget(null);
}
}
player.sendMessage("Pet Name: " + pet.getName());
player.sendMessage("Pet HP: " + pet.getHealth() + "/" + pet.getMaxHealth());
ISoliniaLivingEntity petLivingEntity = SoliniaLivingEntityAdapter.Adapt(pet);
EntityInsentient entityhandle = (EntityInsentient) ((org.bukkit.craftbukkit.v1_12_R1.entity.CraftLivingEntity) pet).getHandle();
double dmg = entityhandle.getAttributeInstance(GenericAttributes.ATTACK_DAMAGE).getValue();
player.sendMessage("Pet DMG: " + dmg);
player.sendMessage("STR: " + petLivingEntity.getStrength() + " STA: " + petLivingEntity.getStamina() + " AGI: " + petLivingEntity.getAgility() + " DEX: " + petLivingEntity.getDexterity() + " INT: " + petLivingEntity.getIntelligence() + " WIS: " + petLivingEntity.getWisdom() + " CHA: " + petLivingEntity.getCharisma());
player.sendMessage("Pet Armour Class Mitigation : " + petLivingEntity.getMitigationAC());
player.sendMessage("Pet Attack Value: " + petLivingEntity.getAttk());
player.sendMessage("Pet Total Rune of: " + petLivingEntity.getRune());
player.sendMessage("Active Effects:");
SoliniaEntitySpells spells = StateManager.getInstance().getEntityManager().getActiveEntitySpells(pet);
for (SoliniaActiveSpell activeSpell : spells.getActiveSpells()) {
ISoliniaSpell spell = StateManager.getInstance().getConfigurationManager().getSpell(activeSpell.getSpellId());
String removetext = "";
ChatColor spellcolor = ChatColor.GREEN;
if (spell.isBeneficial()) {
removetext = "Removable spell";
} else {
removetext = "Unremovable spell";
spellcolor = ChatColor.RED;
}
TextComponent tc = new TextComponent();
tc.setText("- " + spellcolor + spell.getName() + ChatColor.RESET + " " + activeSpell.getTicksLeft() + " ticks left - ");
TextComponent tc2 = new TextComponent();
tc2.setText(removetext);
tc.addExtra(tc2);
sender.spigot().sendMessage(tc);
}
return true;
} catch (CoreStateInitException e) {
}
}
return true;
}
use of com.solinia.solinia.Models.SoliniaActiveSpell in project solinia3-core by mixxit.
the class CommandEffects method onCommand.
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (sender instanceof Player) {
Player player = (Player) sender;
try {
SoliniaEntitySpells spells = StateManager.getInstance().getEntityManager().getActiveEntitySpells(player);
if (spells == null)
return true;
if (args.length == 0) {
player.sendMessage(ChatColor.GOLD + "Active Spell Effects on you:" + ChatColor.WHITE);
ISoliniaPlayer solplayer = SoliniaPlayerAdapter.Adapt(player);
if (solplayer.getExperienceBonusExpires() != null) {
System.out.println("Experience Bonus was not null: " + solplayer.getExperienceBonusExpires().toString());
LocalDateTime datetime = LocalDateTime.now();
Timestamp nowtimestamp = Timestamp.valueOf(datetime);
Timestamp expiretimestamp = solplayer.getExperienceBonusExpires();
if (expiretimestamp != null) {
System.out.println("Experience Bonus expire timestamp " + solplayer.getExperienceBonusExpires() + " vs Now: " + nowtimestamp.toString());
if (!nowtimestamp.after(expiretimestamp)) {
System.out.println("Experience bonus was after, displaying in effects");
int secondsleft = (int) Math.floor(Utils.compareTwoTimeStamps(expiretimestamp, nowtimestamp));
TextComponent tc = new TextComponent();
tc.setText("- " + ChatColor.GREEN + "100% Experience Potion" + ChatColor.RESET + " " + secondsleft + " seconds");
sender.spigot().sendMessage(tc);
}
}
} else {
System.out.println("Experience Bonus was null");
}
for (SoliniaActiveSpell activeSpell : spells.getActiveSpells()) {
ISoliniaSpell spell = StateManager.getInstance().getConfigurationManager().getSpell(activeSpell.getSpellId());
String removetext = "";
ChatColor spellcolor = ChatColor.GREEN;
if (spell.isBeneficial()) {
removetext = "/effects remove " + spell.getId();
} else {
removetext = "Unremovable spell";
spellcolor = ChatColor.RED;
}
TextComponent tc = new TextComponent();
tc.setText("- " + spellcolor + spell.getName() + ChatColor.RESET + " " + activeSpell.getTicksLeft() + " ticks left - ");
TextComponent tc2 = new TextComponent();
tc2.setText(removetext);
if (spell.isBeneficial()) {
tc2.setText(ChatColor.GRAY + "Click here to remove" + ChatColor.RESET);
tc2.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, removetext));
}
tc.addExtra(tc2);
sender.spigot().sendMessage(tc);
}
} else {
if (args.length < 2)
return true;
int spellid = Integer.parseInt(args[1]);
ISoliniaSpell spell = StateManager.getInstance().getConfigurationManager().getSpell(spellid);
if (spell == null) {
player.sendMessage("That spell does not exist");
return true;
}
StateManager.getInstance().getEntityManager().removeSpellEffectsOfSpellId(plugin, player.getUniqueId(), spell.getId());
if (!spell.isBeneficial()) {
player.sendMessage("Can only remove beneficial spells");
return true;
}
player.sendMessage("Spell Effect removed");
}
} catch (CoreStateInitException e) {
player.sendMessage(e.getMessage());
}
}
return true;
}
use of com.solinia.solinia.Models.SoliniaActiveSpell in project solinia3-core by mixxit.
the class Utils method getActiveSpellEffectsRemainingValue.
public static int getActiveSpellEffectsRemainingValue(LivingEntity livingEntity, SpellEffectType effectType) {
int totalRemaining = 0;
SoliniaEntitySpells effects;
try {
effects = StateManager.getInstance().getEntityManager().getActiveEntitySpells(livingEntity);
for (SoliniaActiveSpell activeSpell : effects.getActiveSpells()) {
for (ActiveSpellEffect effect : activeSpell.getActiveSpellEffects()) {
if (!(effect.getSpellEffectType().equals(effectType)))
continue;
totalRemaining += effect.getRemainingValue();
}
}
} catch (CoreStateInitException e) {
// skip
}
return totalRemaining;
}
use of com.solinia.solinia.Models.SoliniaActiveSpell in project solinia3-core by mixxit.
the class Utils method getActiveSpellEffects.
public static List<ActiveSpellEffect> getActiveSpellEffects(LivingEntity livingEntity, SpellEffectType effectType) {
List<ActiveSpellEffect> returnEffects = new ArrayList<ActiveSpellEffect>();
SoliniaEntitySpells effects;
try {
effects = StateManager.getInstance().getEntityManager().getActiveEntitySpells(livingEntity);
for (SoliniaActiveSpell activeSpell : effects.getActiveSpells()) {
for (ActiveSpellEffect effect : activeSpell.getActiveSpellEffects()) {
if (!(effect.getSpellEffectType().equals(effectType)))
continue;
returnEffects.add(effect);
}
}
} catch (CoreStateInitException e) {
// skip
}
return returnEffects;
}
Aggregations