Search in sources :

Example 1 with ISoliniaGroup

use of com.solinia.solinia.Interfaces.ISoliniaGroup 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 2 with ISoliniaGroup

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

the class CoreState method declineGroupInvite.

public void declineGroupInvite(Player player) {
    UUID targetgroupid = getPlayerInviteGroupID(player);
    if (targetgroupid == null) {
        player.sendMessage("You have not been invited to join a group");
        return;
    }
    ISoliniaGroup group = getGroup(targetgroupid);
    if (group == null) {
        removePlayerGroupInvite(player);
        player.sendMessage("That group has disbanded");
        return;
    }
    Player owner = Bukkit.getPlayer(group.getOwner());
    if (owner != null) {
        System.out.println("group: " + group.getId() + " got a membership decline: " + player.getDisplayName());
        owner.sendMessage(player.getDisplayName() + " declined your group invite");
    }
    removePlayerGroupInvite(player);
}
Also used : Player(org.bukkit.entity.Player) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) ISoliniaGroup(com.solinia.solinia.Interfaces.ISoliniaGroup) UUID(java.util.UUID)

Example 3 with ISoliniaGroup

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

the class CoreState method removePlayerFromGroup.

public void removePlayerFromGroup(Player player) {
    ISoliniaGroup group = getGroupByMember(player.getUniqueId());
    if (group == null) {
        removePlayerGroupInvite(player);
        player.sendMessage("That group doesn't exist");
        return;
    }
    System.out.println("group: " + group.getId() + " lost a member: " + player.getDisplayName());
    sendGroupMessage(player, "has left the group!");
    group.getMembers().remove(player.getUniqueId());
    ScoreboardUtils.RemoveScoreboard(player.getUniqueId());
    for (UUID uuid : group.getMembers()) {
        ScoreboardUtils.UpdateGroupScoreboard(uuid, group);
    }
    if (group.getOwner().equals(player.getUniqueId())) {
        if (group.getMembers().size() > 0) {
            boolean foundnewowner = false;
            for (int i = 0; i < group.getMembers().size(); i++) {
                UUID newowner = group.getMembers().get(i);
                Player newownerplayer = Bukkit.getPlayer(newowner);
                if (newownerplayer != null) {
                    group.setOwner(newowner);
                    System.out.println("group: " + group.getId() + " has a new leader: " + newownerplayer.getDisplayName());
                    sendGroupMessage(newownerplayer, "is now the group leader!");
                    foundnewowner = true;
                    break;
                }
            }
            if (foundnewowner == false) {
                player.sendMessage("The group has disbanded");
                removeGroup(group.getId());
                return;
            }
        } else {
            player.sendMessage("The group has disbanded");
            removeGroup(group.getId());
            return;
        }
    }
    groups.put(group.getId(), group);
}
Also used : Player(org.bukkit.entity.Player) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) ISoliniaGroup(com.solinia.solinia.Interfaces.ISoliniaGroup) UUID(java.util.UUID)

Example 4 with ISoliniaGroup

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

the class CoreState method addPlayerToGroup.

private void addPlayerToGroup(UUID targetgroupid, Player player) {
    // TODO Auto-generated method stub
    ISoliniaGroup group = getGroup(targetgroupid);
    ISoliniaGroup existingroup = getGroupByMember(player.getUniqueId());
    if (existingroup != null) {
        removePlayerGroupInvite(player);
        player.sendMessage("You are already in a group");
        return;
    }
    if (group == null) {
        removePlayerGroupInvite(player);
        player.sendMessage("That group has disbanded");
        return;
    }
    if (group.getMembers().size() > 5) {
        removePlayerGroupInvite(player);
        player.sendMessage("That group is now full");
        return;
    }
    group.getMembers().add(player.getUniqueId());
    System.out.println("group: " + group.getId() + " gained a member: " + player.getDisplayName());
    for (UUID uuid : group.getMembers()) {
        ScoreboardUtils.UpdateGroupScoreboard(uuid, group);
    }
    sendGroupMessage(player, "has joined the group!");
    groups.put(group.getId(), group);
}
Also used : ISoliniaGroup(com.solinia.solinia.Interfaces.ISoliniaGroup) UUID(java.util.UUID)

Example 5 with ISoliniaGroup

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

the class CoreState method createNewGroup.

public ISoliniaGroup createNewGroup(Player leader) {
    UUID newgroupid = UUID.randomUUID();
    SoliniaGroup group = new SoliniaGroup();
    group.setId(newgroupid);
    group.setOwner(leader.getUniqueId());
    group.getMembers().add(leader.getUniqueId());
    groups.put(newgroupid, group);
    return groups.get(newgroupid);
}
Also used : SoliniaGroup(com.solinia.solinia.Models.SoliniaGroup) ISoliniaGroup(com.solinia.solinia.Interfaces.ISoliniaGroup) UUID(java.util.UUID)

Aggregations

ISoliniaGroup (com.solinia.solinia.Interfaces.ISoliniaGroup)10 UUID (java.util.UUID)8 Player (org.bukkit.entity.Player)6 ISoliniaPlayer (com.solinia.solinia.Interfaces.ISoliniaPlayer)5 CoreStateInitException (com.solinia.solinia.Exceptions.CoreStateInitException)3 ISoliniaLivingEntity (com.solinia.solinia.Interfaces.ISoliniaLivingEntity)2 Entity (org.bukkit.entity.Entity)2 LivingEntity (org.bukkit.entity.LivingEntity)2 EventHandler (org.bukkit.event.EventHandler)2 ISoliniaFaction (com.solinia.solinia.Interfaces.ISoliniaFaction)1 ISoliniaNPC (com.solinia.solinia.Interfaces.ISoliniaNPC)1 FactionStandingEntry (com.solinia.solinia.Models.FactionStandingEntry)1 SoliniaGroup (com.solinia.solinia.Models.SoliniaGroup)1 ArrayList (java.util.ArrayList)1 Animals (org.bukkit.entity.Animals)1 ArmorStand (org.bukkit.entity.ArmorStand)1 Projectile (org.bukkit.entity.Projectile)1 Wolf (org.bukkit.entity.Wolf)1 EntityDamageByEntityEvent (org.bukkit.event.entity.EntityDamageByEntityEvent)1