Search in sources :

Example 71 with ISoliniaPlayer

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

the class ConfigurationManager method updateKingsAndEmperors.

@Override
public void updateKingsAndEmperors() {
    List<UUID> goodkingCache = new ArrayList<UUID>();
    List<UUID> neutralkingCache = new ArrayList<UUID>();
    List<UUID> evilkingCache = new ArrayList<UUID>();
    for (ISoliniaRace race : getRaces()) {
        HashMap<UUID, Integer> kingCount = new HashMap<UUID, Integer>();
        try {
            for (ISoliniaPlayer player : StateManager.getInstance().getPlayerManager().getCharacters()) {
                if (player.getRaceId() != race.getId())
                    continue;
                if (!player.isMain())
                    continue;
                if (player.getFealty() == null)
                    continue;
                ISoliniaPlayer fealtyPlayer = StateManager.getInstance().getPlayerManager().getMainCharacterDataOnly(player.getFealty());
                if (fealtyPlayer.getRaceId() != player.getRaceId())
                    continue;
                if (!fealtyPlayer.isMain())
                    continue;
                if (fealtyPlayer.isAlignmentEmperor())
                    continue;
                if (!kingCount.containsKey(player.getFealty())) {
                    kingCount.put(player.getFealty(), 1);
                } else {
                    kingCount.put(player.getFealty(), kingCount.get(player.getFealty()) + 1);
                }
            }
            Entry<UUID, Integer> maxEntry = null;
            for (Entry<UUID, Integer> entry : kingCount.entrySet()) {
                if (maxEntry == null || entry.getValue() > maxEntry.getValue()) {
                    maxEntry = entry;
                }
            }
            if (maxEntry != null) {
                if (race.getKing() == null || !race.getKing().equals(maxEntry.getKey()))
                    StateManager.getInstance().getConfigurationManager().getRace(race.getId()).setKing(maxEntry.getKey());
                switch(race.getAlignment()) {
                    case "GOOD":
                        goodkingCache.add(maxEntry.getKey());
                        break;
                    case "NEUTRAL":
                        neutralkingCache.add(maxEntry.getKey());
                        break;
                    case "EVIL":
                        evilkingCache.add(maxEntry.getKey());
                        break;
                    default:
                        break;
                }
            }
        } catch (CoreStateInitException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    try {
        // Good
        HashMap<UUID, Integer> goodkingCount = new HashMap<UUID, Integer>();
        if (StateManager.getInstance().getConfigurationManager().getAlignment("GOOD") != null)
            for (UUID king : goodkingCache) {
                ISoliniaPlayer player = StateManager.getInstance().getPlayerManager().getMainCharacterDataOnly(king);
                if (player == null)
                    continue;
                if (!player.isMain())
                    continue;
                if (player.getRace() == null)
                    continue;
                if (!player.isRacialKing())
                    continue;
                if (player.getVoteEmperor() == null)
                    continue;
                if (player.getVoteEmperor().equals(player.getUUID()))
                    continue;
                ISoliniaPlayer fealty = StateManager.getInstance().getPlayerManager().getMainCharacterDataOnly(player.getVoteEmperor());
                if (fealty == null)
                    continue;
                if (fealty.getRace() == null)
                    continue;
                if (!fealty.getRace().getAlignment().equals(player.getRace().getAlignment()))
                    continue;
                if (fealty.isRacialKing())
                    continue;
                if (!goodkingCount.containsKey(player.getVoteEmperor())) {
                    goodkingCount.put(player.getVoteEmperor(), 1);
                } else {
                    goodkingCount.put(player.getVoteEmperor(), goodkingCount.get(player.getVoteEmperor()) + 1);
                }
            }
        Entry<UUID, Integer> maxEntry = null;
        for (Entry<UUID, Integer> entry : goodkingCount.entrySet()) {
            if (maxEntry == null || entry.getValue() > maxEntry.getValue()) {
                maxEntry = entry;
            }
        }
        if (maxEntry != null) {
            ISoliniaAlignment alignment = StateManager.getInstance().getConfigurationManager().getAlignment("GOOD");
            if (alignment.getEmperor() == null || !alignment.getEmperor().equals(maxEntry.getKey()))
                StateManager.getInstance().getConfigurationManager().getAlignment("GOOD").setEmperor(maxEntry.getKey());
        }
        // Neutral
        HashMap<UUID, Integer> neutralkingCount = new HashMap<UUID, Integer>();
        if (StateManager.getInstance().getConfigurationManager().getAlignment("NEUTRAL") != null)
            for (UUID king : neutralkingCache) {
                ISoliniaPlayer player = StateManager.getInstance().getPlayerManager().getMainCharacterDataOnly(king);
                if (player == null)
                    continue;
                if (player.getRace() == null)
                    continue;
                if (!player.isRacialKing())
                    continue;
                if (player.getVoteEmperor() == null)
                    continue;
                if (player.getVoteEmperor().equals(player.getUUID()))
                    continue;
                ISoliniaPlayer fealty = StateManager.getInstance().getPlayerManager().getMainCharacterDataOnly(player.getVoteEmperor());
                if (fealty == null)
                    continue;
                if (fealty.getRace() == null)
                    continue;
                if (!fealty.getRace().getAlignment().equals(player.getRace().getAlignment()))
                    continue;
                if (fealty.isRacialKing())
                    continue;
                if (!neutralkingCount.containsKey(player.getVoteEmperor())) {
                    neutralkingCount.put(player.getVoteEmperor(), 1);
                } else {
                    neutralkingCount.put(player.getVoteEmperor(), neutralkingCount.get(player.getVoteEmperor()) + 1);
                }
            }
        maxEntry = null;
        for (Entry<UUID, Integer> entry : neutralkingCount.entrySet()) {
            if (maxEntry == null || entry.getValue() > maxEntry.getValue()) {
                maxEntry = entry;
            }
        }
        if (maxEntry != null) {
            ISoliniaAlignment alignment = StateManager.getInstance().getConfigurationManager().getAlignment("NEUTRAL");
            if (alignment.getEmperor() == null || !alignment.getEmperor().equals(maxEntry.getKey()))
                StateManager.getInstance().getConfigurationManager().getAlignment("NEUTRAL").setEmperor(maxEntry.getKey());
        }
        // Evil
        HashMap<UUID, Integer> evilkingCount = new HashMap<UUID, Integer>();
        if (StateManager.getInstance().getConfigurationManager().getAlignment("EVIL") != null)
            for (UUID king : evilkingCache) {
                ISoliniaPlayer player = StateManager.getInstance().getPlayerManager().getMainCharacterDataOnly(king);
                if (player == null)
                    continue;
                if (player.getRace() == null)
                    continue;
                if (!player.isRacialKing())
                    continue;
                if (player.getVoteEmperor() == null)
                    continue;
                if (player.getVoteEmperor().equals(player.getUUID()))
                    continue;
                ISoliniaPlayer fealty = StateManager.getInstance().getPlayerManager().getMainCharacterDataOnly(player.getVoteEmperor());
                if (fealty == null)
                    continue;
                if (fealty.getRace() == null)
                    continue;
                if (!fealty.getRace().getAlignment().equals(player.getRace().getAlignment()))
                    continue;
                if (fealty.isRacialKing())
                    continue;
                if (!evilkingCount.containsKey(player.getVoteEmperor())) {
                    evilkingCount.put(player.getVoteEmperor(), 1);
                } else {
                    evilkingCount.put(player.getVoteEmperor(), evilkingCount.get(player.getVoteEmperor()) + 1);
                }
            }
        maxEntry = null;
        for (Entry<UUID, Integer> entry : evilkingCount.entrySet()) {
            if (maxEntry == null || entry.getValue() > maxEntry.getValue()) {
                maxEntry = entry;
            }
        }
        if (maxEntry != null) {
            ISoliniaAlignment alignment = StateManager.getInstance().getConfigurationManager().getAlignment("EVIL");
            if (alignment.getEmperor() == null || !alignment.getEmperor().equals(maxEntry.getKey()))
                StateManager.getInstance().getConfigurationManager().getAlignment("EVIL").setEmperor(maxEntry.getKey());
        }
    } catch (CoreStateInitException e) {
    // try next loop
    }
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ArrayList(java.util.ArrayList) ISoliniaAlignment(com.solinia.solinia.Interfaces.ISoliniaAlignment) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) UUID(java.util.UUID) ISoliniaRace(com.solinia.solinia.Interfaces.ISoliniaRace)

Example 72 with ISoliniaPlayer

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

the class Solinia3CorePlayerListener method onInventoryClick.

@EventHandler
public void onInventoryClick(InventoryClickEvent event) {
    if (Utils.isInventoryMerchant(event.getInventory())) {
        onMerchantInventoryClick(event);
        return;
    }
    if (event.isCancelled())
        return;
    try {
        if (StateManager.getInstance().getPlayerManager().getApplyingAugmentation(event.getView().getPlayer().getUniqueId()) != null && StateManager.getInstance().getPlayerManager().getApplyingAugmentation(event.getView().getPlayer().getUniqueId()) > 0) {
            event.getView().getPlayer().sendMessage("* Attempting to apply augmentation");
            ItemStack targetItemStack = event.getCurrentItem();
            ISoliniaItem sourceAugSoliniaItem = StateManager.getInstance().getConfigurationManager().getItem(StateManager.getInstance().getPlayerManager().getApplyingAugmentation(event.getView().getPlayer().getUniqueId()));
            if (!sourceAugSoliniaItem.isAugmentation()) {
                event.getView().getPlayer().sendMessage("The item you are attempting to apply from is not an augmentation");
                StateManager.getInstance().getPlayerManager().setApplyingAugmentation(event.getView().getPlayer().getUniqueId(), 0);
                event.getView().getPlayer().sendMessage("* Ended applying Augmentation");
                Utils.CancelEvent(event);
                ;
                return;
            }
            if (!Utils.IsSoliniaItem(targetItemStack) || targetItemStack.getType().equals(Material.ENCHANTED_BOOK)) {
                event.getView().getPlayer().sendMessage("This augmentation cannot be applied to this item type");
                StateManager.getInstance().getPlayerManager().setApplyingAugmentation(event.getView().getPlayer().getUniqueId(), 0);
                event.getView().getPlayer().sendMessage("* Ended applying Augmentation");
                Utils.CancelEvent(event);
                ;
                return;
            }
            if (targetItemStack.getAmount() != 1) {
                event.getView().getPlayer().sendMessage("You cannot apply an augmentation to multiple items at once, please seperate the target item");
                StateManager.getInstance().getPlayerManager().setApplyingAugmentation(event.getView().getPlayer().getUniqueId(), 0);
                System.out.println("Ended applying augmentation");
                event.getView().getPlayer().sendMessage("* Ended applying Augmentation");
                Utils.CancelEvent(event);
                ;
                return;
            }
            if (ItemStackUtils.getAugmentationItemId(targetItemStack) != null && ItemStackUtils.getAugmentationItemId(targetItemStack) != 0) {
                event.getView().getPlayer().sendMessage("This item already has an augmentation applied");
                StateManager.getInstance().getPlayerManager().setApplyingAugmentation(event.getView().getPlayer().getUniqueId(), 0);
                System.out.println("Ended applying augmentation");
                event.getView().getPlayer().sendMessage("* Ended applying Augmentation");
                Utils.CancelEvent(event);
                ;
                return;
            }
            ISoliniaItem targetSoliniaItem = StateManager.getInstance().getConfigurationManager().getItem(targetItemStack);
            if (!targetSoliniaItem.getAcceptsAugmentationSlotType().equals(sourceAugSoliniaItem.getAugmentationFitsSlotType())) {
                event.getView().getPlayer().sendMessage("This augmentation does not fit in this items slot type");
                StateManager.getInstance().getPlayerManager().setApplyingAugmentation(event.getView().getPlayer().getUniqueId(), 0);
                System.out.println("Ended applying augmentation");
                event.getView().getPlayer().sendMessage("* Ended applying Augmentation");
                Utils.CancelEvent(event);
                ;
                return;
            }
            if (Utils.getPlayerTotalCountOfItemId(((Player) event.getView().getPlayer()), sourceAugSoliniaItem.getId()) < 1) {
                event.getView().getPlayer().sendMessage("You do not have enough of this augmentation in your inventory to apply it to an item");
                StateManager.getInstance().getPlayerManager().setApplyingAugmentation(event.getView().getPlayer().getUniqueId(), 0);
                System.out.println("Ended applying augmentation");
                event.getView().getPlayer().sendMessage("* Ended applying Augmentation");
                Utils.CancelEvent(event);
                ;
                return;
            }
            ItemMeta newMeta = ItemStackUtils.applyAugmentationToItemStack(targetItemStack, sourceAugSoliniaItem.getId());
            targetItemStack.setItemMeta(newMeta);
            ((Player) event.getView().getPlayer()).getWorld().dropItemNaturally(((Player) event.getView().getPlayer()).getLocation(), targetItemStack);
            ((Player) event.getView().getPlayer()).getInventory().setItem(event.getSlot(), null);
            ((Player) event.getView().getPlayer()).updateInventory();
            Utils.removeItemsFromInventory(((Player) event.getView().getPlayer()), sourceAugSoliniaItem.getId(), 1);
            event.getView().getPlayer().sendMessage("Augmentation Applied to Item Successfully");
            StateManager.getInstance().getPlayerManager().setApplyingAugmentation(event.getView().getPlayer().getUniqueId(), 0);
            System.out.println("Ended applying augmentation");
            event.getView().getPlayer().sendMessage("* Ended applying Augmentation");
            Utils.CancelEvent(event);
            ;
            return;
        }
        ISoliniaPlayer solplayer = SoliniaPlayerAdapter.Adapt((Player) event.getView().getPlayer());
        // Shift clicking
        if (event.isShiftClick()) {
            ItemStack itemstack = event.getCurrentItem();
            if (itemstack == null)
                return;
            if (Utils.IsSoliniaItem(itemstack) && !itemstack.getType().equals(Material.ENCHANTED_BOOK)) {
                ISoliniaItem soliniaitem = StateManager.getInstance().getConfigurationManager().getItem(itemstack);
                if (soliniaitem.getAllowedClassNames().size() == 0)
                    return;
                if (solplayer.getClassObj() == null) {
                    Utils.CancelEvent(event);
                    ;
                    event.getView().getPlayer().sendMessage(ChatColor.GRAY + "Your class cannot wear this armour");
                    return;
                }
                if (!soliniaitem.getAllowedClassNames().contains(solplayer.getClassObj().getName().toUpperCase())) {
                    Utils.CancelEvent(event);
                    ;
                    event.getView().getPlayer().sendMessage(ChatColor.GRAY + "Your class cannot wear this armour");
                    return;
                }
                if (soliniaitem.getMinLevel() > solplayer.getLevel()) {
                    Utils.CancelEvent(event);
                    ;
                    event.getView().getPlayer().sendMessage(ChatColor.GRAY + "Your are not sufficient level wear this armour");
                    return;
                }
                solplayer.updateMaxHp();
            }
        }
        // Actual clicking
        if (event.getSlotType().equals(SlotType.ARMOR)) {
            ItemStack itemstack = event.getCursor();
            if (itemstack == null)
                return;
            if (Utils.IsSoliniaItem(itemstack) && !itemstack.getType().equals(Material.ENCHANTED_BOOK)) {
                ISoliniaItem soliniaitem = StateManager.getInstance().getConfigurationManager().getItem(itemstack);
                if (soliniaitem.getMinLevel() > solplayer.getLevel()) {
                    Utils.CancelEvent(event);
                    ;
                    event.getView().getPlayer().sendMessage(ChatColor.GRAY + "Your are not sufficient level wear this armour");
                    return;
                }
                if (soliniaitem.getAllowedClassNames().size() == 0)
                    return;
                if (solplayer.getClassObj() == null) {
                    Utils.CancelEvent(event);
                    ;
                    event.getView().getPlayer().sendMessage(ChatColor.GRAY + "Your class cannot wear this armour");
                    return;
                }
                if (!soliniaitem.getAllowedClassNames().contains(solplayer.getClassObj().getName().toUpperCase())) {
                    Utils.CancelEvent(event);
                    ;
                    event.getView().getPlayer().sendMessage(ChatColor.GRAY + "Your class cannot wear this armour");
                    return;
                }
                solplayer.updateMaxHp();
            }
        }
        // shield changes to slotid 40
        if (event.getSlot() == 40) {
            ItemStack itemstack = event.getCursor();
            if (itemstack == null)
                return;
            if (Utils.IsSoliniaItem(itemstack) && !itemstack.getType().equals(Material.ENCHANTED_BOOK)) {
                ISoliniaItem soliniaitem = StateManager.getInstance().getConfigurationManager().getItem(itemstack);
                if (soliniaitem.getAllowedClassNames().size() == 0)
                    return;
                if (solplayer.getClassObj() == null) {
                    Utils.CancelEvent(event);
                    ;
                    event.getView().getPlayer().sendMessage(ChatColor.GRAY + "Your class cannot wear this armour");
                    return;
                }
                if (!soliniaitem.getAllowedClassNames().contains(solplayer.getClassObj().getName().toUpperCase())) {
                    Utils.CancelEvent(event);
                    ;
                    event.getView().getPlayer().sendMessage(ChatColor.GRAY + "Your class cannot wear this armour");
                    return;
                }
                if (soliniaitem.getMinLevel() > solplayer.getLevel()) {
                    Utils.CancelEvent(event);
                    ;
                    event.getView().getPlayer().sendMessage(ChatColor.GRAY + "Your are not sufficient level wear this armour");
                    return;
                }
                solplayer.updateMaxHp();
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : Player(org.bukkit.entity.Player) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) ISoliniaItem(com.solinia.solinia.Interfaces.ISoliniaItem) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) ItemStack(org.bukkit.inventory.ItemStack) ItemMeta(org.bukkit.inventory.meta.ItemMeta) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) SoliniaItemException(com.solinia.solinia.Exceptions.SoliniaItemException) EventHandler(org.bukkit.event.EventHandler)

Example 73 with ISoliniaPlayer

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

the class Solinia3CorePlayerListener method onPlayerDeath.

@EventHandler
public void onPlayerDeath(PlayerDeathEvent event) {
    event.setDeathMessage("");
    try {
        StateManager.getInstance().getEntityManager().clearEntityEffects(plugin, event.getEntity().getUniqueId());
        ISoliniaPlayer player = SoliniaPlayerAdapter.Adapt(event.getEntity());
        if (player != null) {
            double experienceLoss = Utils.calculateExpLoss(player);
            player.reducePlayerNormalExperience(experienceLoss);
            player.dropResurrectionItem((int) experienceLoss);
        }
    } catch (CoreStateInitException e) {
    }
}
Also used : CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) EventHandler(org.bukkit.event.EventHandler)

Example 74 with ISoliniaPlayer

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

the class Solinia3CoreVoteListener method onVotifierEvent.

@EventHandler(priority = EventPriority.NORMAL)
public void onVotifierEvent(VotifierEvent event) {
    Vote vote = event.getVote();
    Player player = plugin.getServer().getPlayer(vote.getUsername());
    String uuid = "";
    if (player != null)
        uuid = player.getUniqueId().toString();
    else
        try {
            uuid = Utils.getUUIDFromPlayerName(vote.getUsername());
            uuid = java.util.UUID.fromString(uuid.replaceFirst("(\\p{XDigit}{8})(\\p{XDigit}{4})(\\p{XDigit}{4})(\\p{XDigit}{4})(\\p{XDigit}+)", "$1-$2-$3-$4-$5")).toString();
        } catch (IOException e1) {
            System.out.println("Cannot find player to associate inspiration to (" + vote.getUsername() + ") [WebLookup]");
        }
    if (uuid == null || uuid.equals("")) {
        System.out.println("Cannot find player to associate inspiration to (" + vote.getUsername() + ")");
        return;
    }
    System.out.println("Vote received: " + vote.getUsername() + " UUID: " + uuid + " from " + vote.getServiceName() + " " + vote.getAddress());
    try {
        ISoliniaPlayer solplayer = StateManager.getInstance().getPlayerManager().getPlayerAndDoNotCreate(UUID.fromString(uuid));
        if (solplayer != null) {
            solplayer.setInspiration(solplayer.getInspiration() + 1);
            if (player != null) {
                player.sendMessage(ChatColor.YELLOW + "* You have gained inspiration! See /inspiration");
            }
        } else {
            System.out.println("Cannot find player to associate inspiration to (" + vote.getUsername() + ")");
        }
    } catch (CoreStateInitException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : Vote(com.vexsoftware.votifier.model.Vote) Player(org.bukkit.entity.Player) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) IOException(java.io.IOException) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) EventHandler(org.bukkit.event.EventHandler)

Example 75 with ISoliniaPlayer

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

the class ChannelManager method sendTopToDiscordChannel.

private void sendTopToDiscordChannel(DiscordChannel discordChannel, String classname) {
    try {
        String targetChannelId = getDefaultDiscordChannel();
        if (discordChannel.equals(DiscordChannel.ADMIN))
            targetChannelId = getAdminDiscordChannel();
        int rank = 1;
        for (ISoliniaPlayer player : StateManager.getInstance().getPlayerManager().getTopLevelPlayers(classname)) {
            sendToDiscordMC(null, targetChannelId, rank + ": " + player.getFullName() + " " + player.getLevel() + " level " + player.getClassObj().getName() + " aas: " + player.getAARanks().size());
            rank++;
        }
    } catch (CoreStateInitException e) {
    // ignore it
    }
}
Also used : CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) 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