Search in sources :

Example 1 with ISoliniaLivingEntity

use of com.solinia.solinia.Interfaces.ISoliniaLivingEntity 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) {
        }
    }
}
Also used : Arrow(org.bukkit.entity.Arrow) TextComponent(net.md_5.bungee.api.chat.TextComponent) ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) Player(org.bukkit.entity.Player) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) Creature(org.bukkit.entity.Creature) ISoliniaItem(com.solinia.solinia.Interfaces.ISoliniaItem) DecimalFormat(java.text.DecimalFormat) ArrayList(java.util.ArrayList) SoliniaItemException(com.solinia.solinia.Exceptions.SoliniaItemException) Timestamp(java.sql.Timestamp) ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) LivingEntity(org.bukkit.entity.LivingEntity) ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) EntityDamageByEntityEvent(org.bukkit.event.entity.EntityDamageByEntityEvent) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) Wolf(org.bukkit.entity.Wolf) ItemStack(org.bukkit.inventory.ItemStack) SoliniaActiveSpell(com.solinia.solinia.Models.SoliniaActiveSpell) EventHandler(org.bukkit.event.EventHandler)

Example 2 with ISoliniaLivingEntity

use of com.solinia.solinia.Interfaces.ISoliniaLivingEntity in project solinia3-core by mixxit.

the class Solinia3CoreEntityListener method onEntityDeath.

@EventHandler
public void onEntityDeath(EntityDeathEvent event) {
    if ((event.getEntity() instanceof ArmorStand)) {
        return;
    }
    if (!(event.getEntity() instanceof LivingEntity))
        return;
    if (event.getEntity() instanceof Player)
        return;
    if (!(event.getEntity().getLastDamageCause() instanceof EntityDamageByEntityEvent))
        return;
    if (event.getEntity() instanceof Animals && !Utils.isLivingEntityNPC((LivingEntity) event.getEntity()))
        return;
    EntityDamageByEntityEvent entitykiller = (EntityDamageByEntityEvent) event.getEntity().getLastDamageCause();
    Entity damager = entitykiller.getDamager();
    if (damager instanceof Projectile) {
        Projectile projectile = (Projectile) damager;
        damager = (Entity) projectile.getShooter();
    }
    if (!(damager instanceof LivingEntity))
        return;
    ISoliniaLivingEntity soldamagerentity = null;
    try {
        soldamagerentity = SoliniaLivingEntityAdapter.Adapt((LivingEntity) damager);
    } catch (CoreStateInitException e) {
    }
    // something
    if ((!(damager instanceof Player)) && Utils.isLivingEntityNPC((LivingEntity) damager)) {
        soldamagerentity.doSlayChat();
    }
    if (!(damager instanceof Player) && !soldamagerentity.isPet())
        return;
    try {
        ISoliniaLivingEntity livingEntity = SoliniaLivingEntityAdapter.Adapt(event.getEntity());
        ISoliniaPlayer player = null;
        if (damager instanceof Player) {
            player = SoliniaPlayerAdapter.Adapt((Player) damager);
        }
        if (soldamagerentity.isPet()) {
            if (damager instanceof Wolf) {
                Wolf w = (Wolf) damager;
                player = SoliniaPlayerAdapter.Adapt((Player) w.getOwner());
            }
        }
        if (player == null) {
            return;
        }
        Double experience = Utils.getExperienceRewardAverageForLevel(livingEntity.getLevel());
        // try to share with group
        ISoliniaGroup group = StateManager.getInstance().getGroupByMember(player.getUUID());
        if (group != null) {
            Integer dhighestlevel = 0;
            List<Integer> levelranges = new ArrayList<Integer>();
            for (UUID member : group.getMembers()) {
                ISoliniaPlayer playerchecked = SoliniaPlayerAdapter.Adapt(Bukkit.getPlayer(member));
                int checkedlevel = playerchecked.getLevel();
                levelranges.add(checkedlevel);
            }
            Collections.sort(levelranges);
            // get the highest person in the group
            dhighestlevel = levelranges.get(levelranges.size() - 1);
            int ihighlvl = (int) Math.floor(dhighestlevel);
            int ilowlvl = ihighlvl - 7;
            if (ilowlvl < 1) {
                ilowlvl = 1;
            }
            if (player.getLevel() < ilowlvl) {
                // as they are out of range of the group
                if (livingEntity.getLevel() >= player.getLevel() - 7) {
                    player.increasePlayerExperience(experience);
                    // Grant title for killing mob
                    if (livingEntity.getNpcid() > 0) {
                        ISoliniaNPC npc = StateManager.getInstance().getConfigurationManager().getNPC(livingEntity.getNpcid());
                        if (npc != null && !npc.getDeathGrantsTitle().equals("")) {
                            player.grantTitle(npc.getDeathGrantsTitle());
                        }
                        if (npc.isBoss() || npc.isRaidboss()) {
                            player.grantTitle("the Vanquisher");
                        }
                    }
                } else {
                    player.getBukkitPlayer().sendMessage(ChatColor.GRAY + "* The npc was too low level to gain experience from");
                }
            } else {
                for (UUID member : group.getMembers()) {
                    Player tgtplayer = Bukkit.getPlayer(member);
                    if (tgtplayer != null) {
                        ISoliniaPlayer tgtsolplayer = SoliniaPlayerAdapter.Adapt(tgtplayer);
                        int tgtlevel = tgtsolplayer.getLevel();
                        if (tgtlevel < ilowlvl) {
                            tgtplayer.sendMessage("You were out of level range to gain experience in this group (Min: " + ilowlvl + " Max: " + ihighlvl + ")");
                            continue;
                        }
                        if (!tgtplayer.getWorld().equals(player.getBukkitPlayer().getWorld())) {
                            tgtplayer.sendMessage("You were out of range for shared group xp (world)");
                            continue;
                        }
                        if (tgtplayer.getLocation().distance(player.getBukkitPlayer().getLocation()) <= 100) {
                            if (livingEntity.getLevel() >= (tgtsolplayer.getLevel() - 7)) {
                                tgtsolplayer.increasePlayerExperience(experience);
                                // Grant title for killing mob
                                if (livingEntity.getNpcid() > 0) {
                                    ISoliniaNPC npc = StateManager.getInstance().getConfigurationManager().getNPC(livingEntity.getNpcid());
                                    if (npc != null && !npc.getDeathGrantsTitle().equals("")) {
                                        tgtsolplayer.grantTitle(npc.getDeathGrantsTitle());
                                    }
                                    if (npc.isBoss() || npc.isRaidboss()) {
                                        tgtsolplayer.grantTitle("the Vanquisher");
                                    }
                                }
                            } else {
                                tgtplayer.sendMessage(ChatColor.GRAY + "* The npc was too low level to gain experience from");
                            }
                        } else {
                            tgtplayer.sendMessage("You were out of range for shared group xp (distance)");
                            continue;
                        }
                    }
                }
            }
        } else {
            if (livingEntity.getLevel() >= (player.getLevel() - 7)) {
                player.increasePlayerExperience(experience);
                // Grant title for killing mob
                if (livingEntity.getNpcid() > 0) {
                    ISoliniaNPC npc = StateManager.getInstance().getConfigurationManager().getNPC(livingEntity.getNpcid());
                    if (npc != null && !npc.getDeathGrantsTitle().equals("")) {
                        player.grantTitle(npc.getDeathGrantsTitle());
                    }
                    if (npc.isBoss() || npc.isRaidboss()) {
                        player.grantTitle("the Vanquisher");
                    }
                }
            } else {
                player.getBukkitPlayer().sendMessage(ChatColor.GRAY + "* The npc was too low level to gain experience from");
            }
        }
        if (livingEntity.getNpcid() > 0) {
            ISoliniaNPC npc = StateManager.getInstance().getConfigurationManager().getNPC(livingEntity.getNpcid());
            if (npc.getFactionid() > 0) {
                ISoliniaFaction faction = StateManager.getInstance().getConfigurationManager().getFaction(npc.getFactionid());
                player.decreaseFactionStanding(npc.getFactionid(), 50);
                for (FactionStandingEntry factionEntry : faction.getFactionEntries()) {
                    if (factionEntry.getValue() >= 1500) {
                        // If this is an ally of the faction, grant negative faction
                        player.decreaseFactionStanding(factionEntry.getFactionId(), 10);
                    }
                    if (factionEntry.getValue() <= -1500) {
                        // If this is an enemy of the faction, grant positive faction
                        player.increaseFactionStanding(factionEntry.getFactionId(), 1);
                    }
                }
            }
        }
        if (livingEntity.getNpcid() > 0) {
            ISoliniaNPC npc = StateManager.getInstance().getConfigurationManager().getNPC(livingEntity.getNpcid());
            if (npc != null && !npc.getDeathGrantsTitle().equals("")) {
                player.grantTitle(npc.getDeathGrantsTitle());
            }
            if (npc.isBoss() || npc.isRaidboss()) {
                player.grantTitle("the Vanquisher");
            }
            if (npc.isBoss() || npc.isRaidboss()) {
                Bukkit.broadcastMessage(ChatColor.RED + "[VICTORY] The foundations of the earth shake following the destruction of " + npc.getName() + " at the hands of " + player.getFullNameWithTitle() + "!" + ChatColor.RESET);
            }
        }
        player.giveMoney(1);
        livingEntity.dropLoot();
    } catch (CoreStateInitException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) Player(org.bukkit.entity.Player) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) ISoliniaGroup(com.solinia.solinia.Interfaces.ISoliniaGroup) FactionStandingEntry(com.solinia.solinia.Models.FactionStandingEntry) ISoliniaFaction(com.solinia.solinia.Interfaces.ISoliniaFaction) ArrayList(java.util.ArrayList) Projectile(org.bukkit.entity.Projectile) ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) LivingEntity(org.bukkit.entity.LivingEntity) Animals(org.bukkit.entity.Animals) ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) ArmorStand(org.bukkit.entity.ArmorStand) EntityDamageByEntityEvent(org.bukkit.event.entity.EntityDamageByEntityEvent) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ISoliniaNPC(com.solinia.solinia.Interfaces.ISoliniaNPC) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) Wolf(org.bukkit.entity.Wolf) UUID(java.util.UUID) EventHandler(org.bukkit.event.EventHandler)

Example 3 with ISoliniaLivingEntity

use of com.solinia.solinia.Interfaces.ISoliniaLivingEntity in project solinia3-core by mixxit.

the class Solinia3CoreEntityListener method onPlayerInteractEntity.

@EventHandler
public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
    try {
        Timestamp mzExpiry = StateManager.getInstance().getEntityManager().getMezzed((LivingEntity) event.getPlayer());
        if (mzExpiry != null) {
            if (event.getPlayer() instanceof Player) {
                event.getPlayer().sendMessage("* You are mezzed!");
            }
            Utils.CancelEvent(event);
            ;
            return;
        }
    } catch (CoreStateInitException e) {
    }
    if (!(event.getRightClicked() instanceof LivingEntity)) {
        return;
    }
    if (!(event.getRightClicked() instanceof LivingEntity)) {
        return;
    }
    if (event.getRightClicked() instanceof Player) {
        return;
    }
    if (event.getHand() != EquipmentSlot.HAND || event.getRightClicked() == null) {
        return;
    }
    try {
        ISoliniaLivingEntity solentity = SoliniaLivingEntityAdapter.Adapt((LivingEntity) event.getRightClicked());
        if (solentity.getNpcid() > 0) {
            SoliniaPlayerAdapter.Adapt(event.getPlayer()).setInteraction(solentity.getBukkitLivingEntity().getUniqueId(), StateManager.getInstance().getConfigurationManager().getNPC(solentity.getNpcid()));
            solentity.processInteractionEvent(event.getPlayer(), InteractionType.CHAT, "hail");
        }
    } catch (CoreStateInitException e) {
        e.printStackTrace();
        return;
    }
}
Also used : ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) LivingEntity(org.bukkit.entity.LivingEntity) Player(org.bukkit.entity.Player) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) Timestamp(java.sql.Timestamp) EventHandler(org.bukkit.event.EventHandler)

Example 4 with ISoliniaLivingEntity

use of com.solinia.solinia.Interfaces.ISoliniaLivingEntity 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;
}
Also used : TextComponent(net.md_5.bungee.api.chat.TextComponent) Player(org.bukkit.entity.Player) ISoliniaSpell(com.solinia.solinia.Interfaces.ISoliniaSpell) EntityInsentient(net.minecraft.server.v1_12_R1.EntityInsentient) SoliniaEntitySpells(com.solinia.solinia.Models.SoliniaEntitySpells) ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) LivingEntity(org.bukkit.entity.LivingEntity) SoliniaLivingEntity(com.solinia.solinia.Models.SoliniaLivingEntity) ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) Wolf(org.bukkit.entity.Wolf) ChatColor(net.md_5.bungee.api.ChatColor) SoliniaActiveSpell(com.solinia.solinia.Models.SoliniaActiveSpell)

Example 5 with ISoliniaLivingEntity

use of com.solinia.solinia.Interfaces.ISoliniaLivingEntity in project solinia3-core by mixxit.

the class CommandNPCGive method onCommand.

@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    if (!(sender instanceof Player))
        return false;
    Player player = (Player) sender;
    try {
        ISoliniaPlayer solplayer = SoliniaPlayerAdapter.Adapt(player);
        if (args.length < 1) {
            player.sendMessage("Invalid syntax missing <itemid>");
            return true;
        }
        if (solplayer.getInteraction() == null) {
            player.sendMessage(ChatColor.GRAY + "* You are not currently interacting with an NPC");
            return true;
        }
        Entity entity = Bukkit.getEntity(solplayer.getInteraction());
        if (entity == null) {
            player.sendMessage(ChatColor.GRAY + "* The npc you are trying to interact with appears to no longer be available");
            return true;
        }
        if (!(entity instanceof LivingEntity)) {
            player.sendMessage(ChatColor.GRAY + "* The npc you are trying to interact with appears to no longer be living");
            return true;
        }
        ISoliniaLivingEntity solentity = SoliniaLivingEntityAdapter.Adapt((LivingEntity) entity);
        if (solentity.getNpcid() < 1) {
            player.sendMessage(ChatColor.GRAY + "* You are not currently interacting with an NPC");
            return true;
        }
        ISoliniaNPC solnpc = StateManager.getInstance().getConfigurationManager().getNPC(solentity.getNpcid());
        int itemid = Integer.parseInt(args[0]);
        if (itemid < 1) {
            player.sendMessage("ItemID must be greater than 0");
            return true;
        }
        ISoliniaItem item = StateManager.getInstance().getConfigurationManager().getItem(itemid);
        if (Utils.getPlayerTotalCountOfItemId(player, itemid) < 1) {
            player.sendMessage("Sorry but you do not have the quantity you are trying to give");
            return true;
        }
        // Check if the npc actually wants to receive this item
        boolean npcWantsItem = false;
        for (ISoliniaNPCEventHandler eventHandler : solnpc.getEventHandlers()) {
            if (!eventHandler.getInteractiontype().equals(InteractionType.ITEM))
                continue;
            System.out.println("Comparing item id: " + item.getId() + " to triggerdata " + eventHandler.getTriggerdata());
            if (Integer.parseInt(eventHandler.getTriggerdata()) != item.getId())
                continue;
            if (eventHandler.getChatresponse() != null && !eventHandler.getChatresponse().equals("")) {
                System.out.println("Checking if player meets requirements to hand in item");
                if (!eventHandler.playerMeetsRequirements(player)) {
                    player.sendMessage(ChatColor.GRAY + "[Hint] You do not meet the requirements to hand this quest item in. Either you are missing a quest step or have already completed this step");
                    continue;
                }
                System.out.println("NPC wants the item");
                npcWantsItem = true;
                String response = eventHandler.getChatresponse();
                solentity.say(solnpc.replaceChatWordsWithHints(response), player);
                eventHandler.awardPlayer((Player) player);
                Utils.removeItemsFromInventory(player, itemid, 1);
            }
        }
        if (npcWantsItem == false) {
            player.sendMessage(ChatColor.GRAY + "* This being does not want this item at this time");
        }
        return true;
    } catch (CoreStateInitException e) {
        player.sendMessage(e.getMessage());
    }
    return true;
}
Also used : ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) LivingEntity(org.bukkit.entity.LivingEntity) ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) Player(org.bukkit.entity.Player) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) ISoliniaItem(com.solinia.solinia.Interfaces.ISoliniaItem) ISoliniaNPCEventHandler(com.solinia.solinia.Interfaces.ISoliniaNPCEventHandler) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ISoliniaNPC(com.solinia.solinia.Interfaces.ISoliniaNPC) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer)

Aggregations

ISoliniaLivingEntity (com.solinia.solinia.Interfaces.ISoliniaLivingEntity)38 CoreStateInitException (com.solinia.solinia.Exceptions.CoreStateInitException)32 LivingEntity (org.bukkit.entity.LivingEntity)24 ISoliniaPlayer (com.solinia.solinia.Interfaces.ISoliniaPlayer)20 Player (org.bukkit.entity.Player)18 Entity (org.bukkit.entity.Entity)16 CraftEntity (org.bukkit.craftbukkit.v1_12_R1.entity.CraftEntity)8 ArrayList (java.util.ArrayList)7 PathEntity (net.minecraft.server.v1_12_R1.PathEntity)7 CraftLivingEntity (org.bukkit.craftbukkit.v1_12_R1.entity.CraftLivingEntity)7 Creature (org.bukkit.entity.Creature)7 ISoliniaNPC (com.solinia.solinia.Interfaces.ISoliniaNPC)6 SoliniaLivingEntity (com.solinia.solinia.Models.SoliniaLivingEntity)6 Timestamp (java.sql.Timestamp)6 ISoliniaSpell (com.solinia.solinia.Interfaces.ISoliniaSpell)5 Wolf (org.bukkit.entity.Wolf)5 EventHandler (org.bukkit.event.EventHandler)5 ISoliniaItem (com.solinia.solinia.Interfaces.ISoliniaItem)4 LocalDateTime (java.time.LocalDateTime)3 TextComponent (net.md_5.bungee.api.chat.TextComponent)3