Search in sources :

Example 1 with ISoliniaPlayer

use of com.solinia.solinia.Interfaces.ISoliniaPlayer 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 ISoliniaPlayer

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

the class Solinia3CoreItemPickupListener method PickupItem.

@EventHandler
public void PickupItem(PlayerPickupItemEvent e) {
    ItemStack pickedUpItemStack = e.getItem().getItemStack();
    // Replace oxygen items with durability items
    if (pickedUpItemStack.getEnchantmentLevel(Enchantment.OXYGEN) > 999) {
        e.getPlayer().sendMessage("Detected an item in the old format, converting to the new format. Please drop all your old items and pick them up if you are having problems with them");
        try {
            ISoliniaItem latestitem = StateManager.getInstance().getConfigurationManager().getItemByOxygen(pickedUpItemStack);
            if (pickedUpItemStack != null) {
                if (latestitem != null) {
                    ItemStack latestitemstack = latestitem.asItemStack();
                    pickedUpItemStack.setItemMeta(latestitemstack.getItemMeta());
                } else {
                    // this is an item that is broken
                    e.getPlayer().sendMessage("This item is no longer implemented");
                    Utils.CancelEvent(e);
                    e.getItem().remove();
                }
            }
        } catch (CoreStateInitException eOxy) {
        }
    }
    String temporaryGuid = null;
    Integer augmentationItemId = null;
    try {
        if (Utils.IsSoliniaItem(pickedUpItemStack) && pickedUpItemStack.getType().equals(Material.ENCHANTED_BOOK)) {
            e.getPlayer().sendMessage(ChatColor.GRAY + "You have picked up an ability! To use it, hold it in your hand and right click!");
            ISoliniaItem latestitem = StateManager.getInstance().getConfigurationManager().getItem(pickedUpItemStack);
            if (pickedUpItemStack != null) {
                if (latestitem != null) {
                    ItemStack latestitemstack = latestitem.asItemStack();
                    pickedUpItemStack.setItemMeta(latestitemstack.getItemMeta());
                } else {
                    // this is an item that is broken
                    e.getPlayer().sendMessage("This item is no longer implemented");
                    Utils.CancelEvent(e);
                    e.getItem().remove();
                }
            }
            if (latestitem.getDiscoverer() == null || latestitem.getDiscoverer().equals("")) {
                latestitem.setDiscoverer(e.getPlayer().getCustomName());
                e.getPlayer().getServer().broadcastMessage(ChatColor.YELLOW + "* " + latestitem.getDisplayname() + " was discovered by " + e.getPlayer().getCustomName() + "!");
                StateManager.getInstance().getChannelManager().sendToDiscordMC(null, StateManager.getInstance().getChannelManager().getDefaultDiscordChannel(), latestitem.getDisplayname() + " was discovered by " + e.getPlayer().getCustomName() + "!");
            }
        }
        if (Utils.IsSoliniaItem(pickedUpItemStack) && !(pickedUpItemStack.getType().equals(Material.ENCHANTED_BOOK))) {
            Map<Enchantment, Integer> oldenchantments = pickedUpItemStack.getEnchantments();
            ISoliniaItem latestitem = StateManager.getInstance().getConfigurationManager().getItem(pickedUpItemStack);
            if (latestitem.getDiscoverer() == null || latestitem.getDiscoverer().equals("")) {
                latestitem.setDiscoverer(e.getPlayer().getCustomName());
                e.getPlayer().getServer().broadcastMessage(ChatColor.YELLOW + "* " + latestitem.getDisplayname() + " was discovered by " + e.getPlayer().getCustomName() + "!");
                StateManager.getInstance().getChannelManager().sendToDiscordMC(null, StateManager.getInstance().getChannelManager().getDefaultDiscordChannel(), latestitem.getDisplayname() + " was discovered by " + e.getPlayer().getCustomName() + "!");
            }
            if (pickedUpItemStack != null) {
                ItemStack latestitemstack = latestitem.asItemStack();
                // We need to store this information before we change the itemmeta, so we can update it afterwards
                if (latestitem.isTemporary()) {
                    temporaryGuid = ItemStackUtils.getTemporaryItemGuid(pickedUpItemStack);
                }
                augmentationItemId = ItemStackUtils.getAugmentationItemId(pickedUpItemStack);
                // Now go and replace the itemmeta
                pickedUpItemStack.setItemMeta(latestitemstack.getItemMeta());
                // Now re-apply enchantments that it had before
                for (Map.Entry<Enchantment, Integer> entry : oldenchantments.entrySet()) {
                    Enchantment key = entry.getKey();
                    Integer value = entry.getValue();
                    if (value < 1000) {
                        pickedUpItemStack.addUnsafeEnchantment(key, value);
                    }
                }
                // Since the item is temporary, attempt to apply the temporary timestamp it had prior to this
                if (latestitem.isTemporary()) {
                    pickedUpItemStack.setItemMeta(ItemStackUtils.applyTemporaryStamp(pickedUpItemStack, temporaryGuid));
                }
                if (augmentationItemId != null && augmentationItemId != 0) {
                    pickedUpItemStack.setItemMeta(ItemStackUtils.applyAugmentationToItemStack(pickedUpItemStack, augmentationItemId));
                }
            }
        }
        // group messages
        if (Utils.IsSoliniaItem(pickedUpItemStack)) {
            ISoliniaItem item;
            try {
                item = SoliniaItemAdapter.Adapt(pickedUpItemStack);
                if (item.getAllowedClassNames().size() > 0) {
                    ISoliniaPlayer solPlayer = SoliniaPlayerAdapter.Adapt(e.getPlayer());
                    if (solPlayer.getGroup() != null && solPlayer.getGroup().getMembers() != null)
                        for (UUID playerUuid : solPlayer.getGroup().getMembers()) {
                            if (playerUuid.equals(e.getPlayer().getUniqueId()))
                                continue;
                            Player groupMember = Bukkit.getPlayer(playerUuid);
                            ISoliniaPlayer groupSolPlayer = SoliniaPlayerAdapter.Adapt(groupMember);
                            if (groupSolPlayer != null) {
                                if (groupSolPlayer.getClassObj() != null)
                                    if (item.getAllowedClassNames().contains(groupSolPlayer.getClassObj().getName().toUpperCase())) {
                                        TextComponent tc = new TextComponent();
                                        tc.setText("* " + groupSolPlayer.getFullName() + " picked up an item of interest to your class: [" + ChatColor.AQUA + item.getDisplayname() + ChatColor.RESET + "]");
                                        tc.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_ITEM, new ComponentBuilder(item.asJsonString()).create()));
                                        groupSolPlayer.getBukkitPlayer().spigot().sendMessage(tc);
                                    }
                            }
                        }
                }
            } catch (SoliniaItemException e1) {
            }
        }
    } catch (CoreStateInitException coreException) {
    // do nothing
    }
}
Also used : TextComponent(net.md_5.bungee.api.chat.TextComponent) HoverEvent(net.md_5.bungee.api.chat.HoverEvent) Player(org.bukkit.entity.Player) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) ISoliniaItem(com.solinia.solinia.Interfaces.ISoliniaItem) SoliniaItemException(com.solinia.solinia.Exceptions.SoliniaItemException) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) ItemStack(org.bukkit.inventory.ItemStack) Enchantment(org.bukkit.enchantments.Enchantment) UUID(java.util.UUID) Map(java.util.Map) ComponentBuilder(net.md_5.bungee.api.chat.ComponentBuilder) EventHandler(org.bukkit.event.EventHandler)

Example 3 with ISoliniaPlayer

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

the class Solinia3CoreEntityListener method onEntityDamageEvent.

@EventHandler
public void onEntityDamageEvent(EntityDamageEvent event) {
    if (event.isCancelled())
        return;
    if ((event.getEntity() instanceof Player)) {
        if (!(event.getCause().equals(EntityDamageEvent.DamageCause.FALL)))
            return;
        Player player = (Player) event.getEntity();
        ISoliniaPlayer solplayer;
        try {
            solplayer = SoliniaPlayerAdapter.Adapt(player);
            if (solplayer == null)
                return;
            boolean cancelFall = solplayer.getSafefallCheck();
            if (cancelFall == true) {
                Utils.CancelEvent(event);
                ;
                solplayer.emote(ChatColor.GRAY + "* " + solplayer.getFullName() + " lands softly, breaking their fall");
                solplayer.tryIncreaseSkill("SAFEFALL", 1);
                return;
            }
        } catch (CoreStateInitException e) {
            return;
        }
    }
}
Also used : Player(org.bukkit.entity.Player) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) EventHandler(org.bukkit.event.EventHandler)

Example 4 with ISoliniaPlayer

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

the class CommandVoteEmperor method onCommand.

@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    if (!(sender instanceof Player)) {
        return false;
    }
    if (args.length < 1)
        return false;
    if (Bukkit.getPlayer(args[0]) == null) {
        sender.sendMessage("Cannot find player");
        return true;
    }
    try {
        Player fealtyTo = Bukkit.getPlayer(args[0]);
        ISoliniaPlayer sourcePlayer = SoliniaPlayerAdapter.Adapt((Player) sender);
        ISoliniaPlayer fealtyPlayer = SoliniaPlayerAdapter.Adapt(fealtyTo);
        if (!sourcePlayer.isMain()) {
            sender.sendMessage("You must be your main character to vote");
            return true;
        }
        if (!fealtyPlayer.isMain()) {
            sender.sendMessage("You can only vote for a main character");
            return true;
        }
        if (sourcePlayer.getRaceId() < 1 || fealtyPlayer.getRaceId() < 1) {
            sender.sendMessage("You and your target must both have a race set");
            return true;
        }
        if (!sourcePlayer.getRace().getAlignment().equals(fealtyPlayer.getRace().getAlignment())) {
            sender.sendMessage("You can only vote for an emperor of the same alignment");
            return true;
        }
        if (!sourcePlayer.isRacialKing()) {
            sender.sendMessage("Only a King may vote for an emperor");
            return true;
        }
        if (fealtyPlayer.isRacialKing()) {
            sender.sendMessage("A King may not be an Emperor");
        }
        sourcePlayer.setVoteEmperor(fealtyTo.getUniqueId());
        return true;
    } catch (CoreStateInitException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        sender.sendMessage(e.getMessage());
        return true;
    }
}
Also used : ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) Player(org.bukkit.entity.Player) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer)

Example 5 with ISoliniaPlayer

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

the class JsonPlayerRepository method reload.

@Override
public void reload() {
    List<ISoliniaPlayer> filePlayers = new ArrayList<ISoliniaPlayer>();
    try {
        Gson gson = new Gson();
        BufferedReader br = new BufferedReader(new FileReader(filePath));
        filePlayers = gson.fromJson(br, new TypeToken<List<SoliniaPlayer>>() {
        }.getType());
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
    players.clear();
    for (ISoliniaPlayer player : filePlayers) {
        players.put(player.getUUID(), player);
    }
    System.out.println("Reloaded " + players.size() + " players");
}
Also used : ArrayList(java.util.ArrayList) BufferedReader(java.io.BufferedReader) FileNotFoundException(java.io.FileNotFoundException) Gson(com.google.gson.Gson) FileReader(java.io.FileReader) ArrayList(java.util.ArrayList) List(java.util.List) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer)

Aggregations

ISoliniaPlayer (com.solinia.solinia.Interfaces.ISoliniaPlayer)89 CoreStateInitException (com.solinia.solinia.Exceptions.CoreStateInitException)85 Player (org.bukkit.entity.Player)57 ISoliniaNPC (com.solinia.solinia.Interfaces.ISoliniaNPC)16 ISoliniaLivingEntity (com.solinia.solinia.Interfaces.ISoliniaLivingEntity)13 ISoliniaItem (com.solinia.solinia.Interfaces.ISoliniaItem)12 EventHandler (org.bukkit.event.EventHandler)11 LivingEntity (org.bukkit.entity.LivingEntity)10 ArrayList (java.util.ArrayList)9 UUID (java.util.UUID)9 SoliniaItemException (com.solinia.solinia.Exceptions.SoliniaItemException)8 TextComponent (net.md_5.bungee.api.chat.TextComponent)8 ItemStack (org.bukkit.inventory.ItemStack)8 CommandSender (org.bukkit.command.CommandSender)5 ConsoleCommandSender (org.bukkit.command.ConsoleCommandSender)5 Entity (org.bukkit.entity.Entity)5 Timestamp (java.sql.Timestamp)4 LocalDateTime (java.time.LocalDateTime)4 ComponentBuilder (net.md_5.bungee.api.chat.ComponentBuilder)4 HoverEvent (net.md_5.bungee.api.chat.HoverEvent)4