Search in sources :

Example 36 with ISoliniaItem

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

the class Solinia3CorePlayerListener method onMerchantInventoryClick.

private void onMerchantInventoryClick(InventoryClickEvent event) {
    int merchantid = 0;
    int npcid = 0;
    ISoliniaNPCMerchant merchant = null;
    ISoliniaNPC npc = null;
    int page = 0;
    int nextpage = 0;
    try {
        merchantid = Utils.getInventoryMerchantID(event.getInventory());
        npcid = Utils.getInventoryNPCID(event.getInventory());
        page = Utils.getInventoryPage(event.getInventory());
        nextpage = Utils.getInventoryPage(event.getInventory());
    } catch (Exception e) {
        event.getView().getPlayer().sendMessage(e.getMessage());
        e.printStackTrace();
        Utils.CancelEvent(event);
        ;
        return;
    }
    if (merchantid == 0 || npcid == 0) {
        event.getView().getPlayer().sendMessage("Could not find npc " + npcid + " or merchant " + merchantid + " or page " + page);
        System.out.println("Could not find npc " + npcid + " or merchant " + merchantid);
        Utils.CancelEvent(event);
        ;
        return;
    }
    try {
        merchant = StateManager.getInstance().getConfigurationManager().getNPCMerchant(merchantid);
        npc = StateManager.getInstance().getConfigurationManager().getNPC(npcid);
    } catch (CoreStateInitException e) {
        event.getView().getPlayer().sendMessage("Cannot sell/buy right now");
        Utils.CancelEvent(event);
        ;
        return;
    }
    // event.getView().getPlayer().sendMessage("Detected Merchant Inventory Click for Merchant:" + merchantid + " Slot: " + event.getSlot() + " Raw Slot: " + event.getRawSlot());
    if (event.getRawSlot() < 0) {
        Utils.CancelEvent(event);
        ;
        return;
    }
    if (event.getCursor() == null || event.getCursor().getType().equals(Material.AIR)) {
        // event.getView().getPlayer().sendMessage("Detected AIR Cursor, assuming picking up");
        if (event.getRawSlot() > 26) {
            try {
                ISoliniaItem item = StateManager.getInstance().getConfigurationManager().getItem(event.getCurrentItem());
                if (item == null) {
                    event.getView().getPlayer().sendMessage("Merchants are not interested in this item");
                    Utils.CancelEvent(event);
                    ;
                    return;
                }
                if (item.isTemporary()) {
                    event.getView().getPlayer().sendMessage("Merchants are not interested in temporary items");
                    Utils.CancelEvent(event);
                    ;
                    return;
                }
            // Picked up sellable item
            } catch (CoreStateInitException e) {
                Utils.CancelEvent(event);
                ;
                event.getView().getPlayer().sendMessage("Cannot sell/buy right now");
                return;
            }
            return;
        } else {
            ItemStack pickingUpItem = event.getCurrentItem();
            if (pickingUpItem.getType().equals(Material.BARRIER)) {
                // event.getView().getPlayer().sendMessage("Ignoring barrier");
                Utils.CancelEvent(event);
                ;
                return;
            }
            // Do not allow movement of UI movers
            if (event.getRawSlot() == 18 || event.getRawSlot() == 26) {
                // event.getView().getPlayer().sendMessage("Moving Left or Right");
                if (event.getRawSlot() == 18) {
                    if ((page - 1) > 0) {
                        event.getView().getPlayer().closeInventory();
                        npc.sendMerchantItemListToPlayer((Player) event.getView().getPlayer(), page - 1);
                    }
                }
                if (event.getRawSlot() == 26) {
                    if (nextpage != 0) {
                        event.getView().getPlayer().closeInventory();
                        npc.sendMerchantItemListToPlayer((Player) event.getView().getPlayer(), nextpage + 1);
                    }
                }
                Utils.CancelEvent(event);
                ;
                return;
            }
            // Do not allow movement of identifiers
            if (event.getRawSlot() == 19) {
                // event.getView().getPlayer().sendMessage("Ignoring identifier block");
                Utils.CancelEvent(event);
                ;
                return;
            }
            // Picking up merchant item
            // event.getView().getPlayer().sendMessage("Picking up merchant item");
            event.setCursor(event.getCurrentItem());
            Utils.CancelEvent(event);
            ;
            return;
        }
    }
    if (event.getCursor() != null && !event.getCursor().getType().equals(Material.AIR)) {
        // Clicking item in cursor onto a slot
        if (event.getRawSlot() > 26) {
            // Dropping own item or buying
            if (event.getCursor().getItemMeta().getDisplayName().startsWith("Display Item: ")) {
                try {
                    if (!event.getCurrentItem().getType().equals(Material.AIR)) {
                        event.getView().getPlayer().sendMessage("You must place the item you wish to buy on an empty slot");
                        event.setCursor(new ItemStack(Material.AIR));
                        Utils.CancelEvent(event);
                        ;
                        return;
                    }
                    ISoliniaItem item = StateManager.getInstance().getConfigurationManager().getItem(event.getCursor());
                    int individualprice = item.getWorth();
                    // Total price
                    int price = individualprice * event.getCursor().getAmount();
                    if (price > StateManager.getInstance().getEconomy().getBalance((Player) event.getView().getPlayer())) {
                        event.getView().getPlayer().sendMessage("You do not have sufficient balance to buy this item in that quantity.");
                        event.setCursor(new ItemStack(Material.AIR));
                        Utils.CancelEvent(event);
                        ;
                        return;
                    }
                    EconomyResponse responsewithdraw = StateManager.getInstance().getEconomy().withdrawPlayer(Bukkit.getOfflinePlayer(((Player) event.getView().getPlayer()).getUniqueId()), price);
                    if (responsewithdraw.transactionSuccess()) {
                        ItemStack purchase = item.asItemStack();
                        event.setCursor(new ItemStack(Material.AIR));
                        Utils.CancelEvent(event);
                        ;
                        event.getClickedInventory().setItem(event.getSlot(), purchase);
                        event.getView().getPlayer().sendMessage(ChatColor.YELLOW + "* You pay $" + price + " for " + event.getCursor().getAmount() + " " + item.getDisplayname());
                        return;
                    } else {
                        System.out.println("Error withdrawing money from your account " + String.format(responsewithdraw.errorMessage));
                        event.getView().getPlayer().sendMessage(ChatColor.YELLOW + "* Error withdrawing money from your account " + String.format(responsewithdraw.errorMessage));
                        event.setCursor(new ItemStack(Material.AIR));
                        Utils.CancelEvent(event);
                        ;
                        return;
                    }
                } catch (CoreStateInitException e) {
                    event.getView().getPlayer().sendMessage("Cannot buy items from the merchant right now");
                    event.setCursor(new ItemStack(Material.AIR));
                    Utils.CancelEvent(event);
                    ;
                    return;
                }
            } else {
                // Dropping own item
                return;
            }
        } else {
            // Selling items or dropping item back
            if (event.getCursor().getItemMeta().getDisplayName().startsWith("Display Item: ")) {
                // Returning store item
                event.setCursor(new ItemStack(Material.AIR));
                Utils.CancelEvent(event);
                ;
                return;
            } else {
                try {
                    ISoliniaItem item = StateManager.getInstance().getConfigurationManager().getItem(event.getCursor());
                    int individualprice = item.getWorth();
                    // Total price
                    int price = individualprice * event.getCursor().getAmount();
                    EconomyResponse responsedeposit = StateManager.getInstance().getEconomy().depositPlayer((Player) event.getView().getPlayer(), price);
                    if (responsedeposit.transactionSuccess()) {
                        // Add to buy back list
                        // StateManager.getInstance().getEntityManager().addTemporaryMerchantItem(npc.getId(), item.getId(), event.getCursor().getAmount());
                        event.getView().getPlayer().sendMessage(ChatColor.YELLOW + "* You recieve $" + price + " as payment");
                        event.setCursor(new ItemStack(Material.AIR));
                        Utils.CancelEvent(event);
                        ;
                        return;
                    } else {
                        System.out.println("Error depositing money to users account " + String.format(responsedeposit.errorMessage));
                        event.getView().getPlayer().sendMessage(ChatColor.YELLOW + "* Error depositing money to your account " + String.format(responsedeposit.errorMessage));
                        Utils.CancelEvent(event);
                        ;
                        return;
                    }
                } catch (CoreStateInitException e) {
                    event.getView().getPlayer().sendMessage("Cannot sell item to merchant right now");
                    Utils.CancelEvent(event);
                    ;
                    return;
                }
            }
        }
    }
    event.getView().getPlayer().sendMessage("Please alert an admin of this message code: GMMI1");
    Utils.CancelEvent(event);
    ;
    return;
}
Also used : Player(org.bukkit.entity.Player) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) ISoliniaItem(com.solinia.solinia.Interfaces.ISoliniaItem) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ISoliniaNPCMerchant(com.solinia.solinia.Interfaces.ISoliniaNPCMerchant) ISoliniaNPC(com.solinia.solinia.Interfaces.ISoliniaNPC) EconomyResponse(net.milkbowl.vault.economy.EconomyResponse) ItemStack(org.bukkit.inventory.ItemStack) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) SoliniaItemException(com.solinia.solinia.Exceptions.SoliniaItemException)

Example 37 with ISoliniaItem

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

the class ChannelManager method sendLootListToDiscordChannel.

private void sendLootListToDiscordChannel(DiscordChannel discordChannel, String itemMatch) {
    try {
        String targetChannelId = getDefaultDiscordChannel();
        if (discordChannel.equals(DiscordChannel.ADMIN))
            targetChannelId = getAdminDiscordChannel();
        if (itemMatch.length() < 3) {
            sendToDiscordMC(null, targetChannelId, "Item search must be at least 3 characters: " + itemMatch);
            return;
        }
        List<ISoliniaItem> items = StateManager.getInstance().getConfigurationManager().getItemsByPartialName(itemMatch);
        int itemIdLookup = 0;
        try {
            itemIdLookup = Integer.parseInt(itemMatch);
            ISoliniaItem item = StateManager.getInstance().getConfigurationManager().getItem(itemIdLookup);
            items.add(item);
        } catch (Exception e) {
        }
        if (items.size() < 1) {
            sendToDiscordMC(null, targetChannelId, "Could not find item: " + itemMatch);
            return;
        }
        if (items.size() > 1) {
            String itemsMatched = "";
            for (ISoliniaItem item : items) {
                itemsMatched += item.getId() + " ";
            }
            if (itemsMatched.length() > 256) {
                itemsMatched = itemsMatched.substring(0, 250) + "...";
            }
            sendToDiscordMC(null, targetChannelId, "More than one item found with this string, please be more specific than '" + itemMatch + "' (Or Try ?loot with one of these IDs: " + itemsMatched.trim() + ")");
            return;
        }
        String itemname = "";
        for (ISoliniaItem item : items) {
            itemname = item.getDisplayname();
            List<Integer> lootDropIds = StateManager.getInstance().getConfigurationManager().getLootDropIdsWithItemId(item.getId());
            if (lootDropIds.size() < 1) {
                sendToDiscordMC(null, targetChannelId, "Item [" + itemname + "] not found in any loot drops");
                return;
            }
            List<Integer> lootTableIds = StateManager.getInstance().getConfigurationManager().getLootTablesWithLootDrops(lootDropIds);
            if (lootTableIds.size() < 1) {
                sendToDiscordMC(null, targetChannelId, "Item [" + itemname + "] not found in any loot tables");
                return;
            }
            List<String> matchingNpcList = new ArrayList<String>();
            String currentLine = "";
            for (ISoliniaNPC npc : StateManager.getInstance().getConfigurationManager().getNPCs()) {
                if (!lootTableIds.contains(npc.getLoottableid()))
                    continue;
                if ((currentLine + npc.getName() + " ").length() > 2000) {
                    matchingNpcList.add(currentLine);
                    currentLine = "";
                }
                currentLine += npc.getName() + " ";
            }
            if (!currentLine.equals("")) {
                matchingNpcList.add(currentLine);
            }
            for (String line : matchingNpcList) {
                sendToDiscordMC(null, targetChannelId, "Item [" + itemname + "] found on: " + line);
            }
        }
    } catch (CoreStateInitException e) {
    // ignore it
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ISoliniaItem(com.solinia.solinia.Interfaces.ISoliniaItem) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ISoliniaNPC(com.solinia.solinia.Interfaces.ISoliniaNPC) ArrayList(java.util.ArrayList) EventException(org.bukkit.event.EventException) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException)

Example 38 with ISoliniaItem

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

the class CommandClaim method onCommand.

@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    try {
        if (args.length < 1) {
            sender.sendMessage(ChatColor.GRAY + "Insufficient arguments (list,claim)");
            return true;
        }
        switch(args[0]) {
            case "list":
                if (!(sender instanceof Player))
                    return false;
                Player player = (Player) sender;
                ISoliniaPlayer solplayer = SoliniaPlayerAdapter.Adapt(player);
                sender.sendMessage("Current Claims: " + solplayer.getAccountClaims().size());
                for (SoliniaAccountClaim claim : solplayer.getAccountClaims()) {
                    ISoliniaItem item = StateManager.getInstance().getConfigurationManager().getItem(claim.getItemid());
                    if (item == null)
                        continue;
                    TextComponent tc = new TextComponent();
                    tc.setText(ChatColor.LIGHT_PURPLE + item.getDisplayname() + " /claim claim " + claim.getId());
                    tc.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_ITEM, new ComponentBuilder(item.asJsonString()).create()));
                    sender.spigot().sendMessage(tc);
                }
                return true;
            case "give":
                if (!sender.isOp())
                    return false;
                if (args.length < 3) {
                    sender.sendMessage("That is not a claim id - /claim give mcaccountname itemid");
                    return true;
                }
                String mcaccountname = args[1];
                int itemId = Integer.parseInt(args[2].toUpperCase());
                SoliniaAccountClaim newclaim = new SoliniaAccountClaim();
                newclaim.setId(StateManager.getInstance().getConfigurationManager().getNextAccountClaimId());
                newclaim.setMcname(mcaccountname);
                newclaim.setItemid(itemId);
                newclaim.setClaimed(false);
                StateManager.getInstance().getConfigurationManager().addAccountClaim(newclaim);
                sender.sendMessage("Account claim added!");
                return true;
            case "claim":
                if (!(sender instanceof Player))
                    return false;
                Player claimPlayer = (Player) sender;
                ISoliniaPlayer solClaimPlayer = SoliniaPlayerAdapter.Adapt(claimPlayer);
                sender.sendMessage("Current Claims: " + solClaimPlayer.getAccountClaims().size());
                if (args.length < 2) {
                    sender.sendMessage("That is not a claim id - /claim claim claimid (see /claim list)");
                    return true;
                }
                int seekClaimId = Integer.parseInt(args[1].toUpperCase());
                System.out.println("Looking up claims for player name: " + claimPlayer.getName() + " for claim ID: " + seekClaimId);
                SoliniaAccountClaim claim = StateManager.getInstance().getConfigurationManager().getAccountClaim(claimPlayer.getName().toUpperCase(), seekClaimId);
                if (claim == null) {
                    sender.sendMessage("That is not a valid claim - /claim claim claimid (see /claim list)");
                    return true;
                }
                ISoliniaItem item = StateManager.getInstance().getConfigurationManager().getItem(claim.getItemid());
                if (item == null) {
                    sender.sendMessage("That is not a valid claim item - /claim claim claimid (see /claim list)");
                    return true;
                }
                claimPlayer.getWorld().dropItemNaturally(claimPlayer.getLocation(), item.asItemStack());
                sender.sendMessage("Claim item dropped at your feet - ID: " + claim.getId());
                StateManager.getInstance().getConfigurationManager().removeClaim(claim.getId());
                return true;
            default:
                sender.sendMessage(ChatColor.GRAY + "Invalid arguments (list,claim)");
                return true;
        }
    } catch (CoreStateInitException e) {
    }
    return true;
}
Also used : SoliniaAccountClaim(com.solinia.solinia.Models.SoliniaAccountClaim) 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) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) ComponentBuilder(net.md_5.bungee.api.chat.ComponentBuilder)

Example 39 with ISoliniaItem

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

the class SoliniaLivingEntity method Attack.

@Override
public boolean Attack(ISoliniaLivingEntity defender, EntityDamageEvent event, boolean arrowHit, Solinia3CorePlugin plugin) {
    int baseDamage = (int) event.getDamage(DamageModifier.BASE);
    try {
        if (defender.isPlayer() && isPlayer()) {
            ISoliniaPlayer defenderPlayer = SoliniaPlayerAdapter.Adapt((Player) defender.getBukkitLivingEntity());
            ISoliniaPlayer attackerPlayer = SoliniaPlayerAdapter.Adapt((Player) this.getBukkitLivingEntity());
            if (defenderPlayer.getGroup() != null && attackerPlayer.getGroup() != null) {
                if (defenderPlayer.getGroup().getId().equals(attackerPlayer.getGroup().getId())) {
                    Utils.CancelEvent(event);
                    ;
                    return false;
                }
            }
        }
    } catch (CoreStateInitException e) {
    // ignore
    }
    if (isPlayer()) {
        Player player = (Player) this.getBukkitLivingEntity();
        if (player.isSneaking()) {
            try {
                ISoliniaPlayer solplayer = SoliniaPlayerAdapter.Adapt(player);
                if (solplayer.getClassObj() != null) {
                    if (solplayer.getClassObj().isSneakFromCrouch()) {
                        player.sendMessage("You cannot concentrate on combat while meditating or sneaking");
                        Utils.CancelEvent(event);
                        ;
                        return false;
                    }
                }
            } catch (CoreStateInitException e) {
            // do nothing
            }
        }
    }
    if (usingValidWeapon() == false) {
        Utils.CancelEvent(event);
        ;
        return false;
    } else {
        if (Utils.IsSoliniaItem(getBukkitLivingEntity().getEquipment().getItemInMainHand())) {
            try {
                ISoliniaItem soliniaitem = StateManager.getInstance().getConfigurationManager().getItem(getBukkitLivingEntity().getEquipment().getItemInMainHand());
                // TODO move this
                if (soliniaitem.getBaneUndead() > 0 && defender.isUndead())
                    baseDamage += soliniaitem.getBaneUndead();
            } catch (CoreStateInitException e) {
                Utils.CancelEvent(event);
                ;
                return false;
            }
        }
    }
    if (baseDamage < 1)
        baseDamage = 1;
    if (defender == null) {
        Utils.CancelEvent(event);
        ;
        return false;
    }
    if (defender.getBukkitLivingEntity().isDead() || this.getBukkitLivingEntity().isDead() || this.getBukkitLivingEntity().getHealth() < 0) {
        Utils.CancelEvent(event);
        ;
        return false;
    }
    if (isInulvnerable()) {
        Utils.CancelEvent(event);
        ;
        return false;
    }
    if (isFeigned()) {
        Utils.CancelEvent(event);
        ;
        return false;
    }
    ItemStack weapon = this.getBukkitLivingEntity().getEquipment().getItemInHand();
    DamageHitInfo my_hit = new DamageHitInfo();
    my_hit.skill = Utils.getSkillForMaterial(weapon.getType().toString()).getSkillname();
    if (arrowHit) {
        my_hit.skill = "ARCHERY";
    }
    // Now figure out damage
    my_hit.damage_done = 1;
    my_hit.min_damage = 0;
    int mylevel = getLevel();
    int hate = 0;
    my_hit.base_damage = baseDamage;
    // amount of hate is based on the damage done
    if (hate == 0 && my_hit.base_damage > 1)
        hate = my_hit.base_damage;
    if (my_hit.base_damage > 0) {
        my_hit.base_damage = getDamageCaps(my_hit.base_damage);
        tryIncreaseSkill(my_hit.skill, 1);
        tryIncreaseSkill("OFFENSE", 1);
        int ucDamageBonus = 0;
        if (getClassObj() != null && getClassObj().isWarriorClass() && getLevel() >= 28) {
            ucDamageBonus = getWeaponDamageBonus(weapon);
            my_hit.min_damage = ucDamageBonus;
            hate += ucDamageBonus;
        }
        // TODO Sinister Strikes
        int hit_chance_bonus = 0;
        // we need this a few times
        my_hit.offense = getOffense(my_hit.skill);
        my_hit.tohit = getTotalToHit(my_hit.skill, hit_chance_bonus);
        doAttack(plugin, defender, my_hit);
    }
    defender.addToHateList(getBukkitLivingEntity().getUniqueId(), hate);
    if (getBukkitLivingEntity().isDead()) {
        Utils.CancelEvent(event);
        ;
        return false;
    }
    if (my_hit.damage_done > 0) {
        triggerDefensiveProcs(defender, my_hit.damage_done, arrowHit);
        try {
            event.setDamage(DamageModifier.ABSORPTION, 0);
        } catch (UnsupportedOperationException e) {
        }
        try {
            event.setDamage(DamageModifier.ARMOR, 0);
        } catch (UnsupportedOperationException e) {
        }
        try {
            event.setDamage(DamageModifier.BASE, my_hit.damage_done);
        } catch (UnsupportedOperationException e) {
        }
        try {
            event.setDamage(DamageModifier.BLOCKING, 0);
        } catch (UnsupportedOperationException e) {
        }
        try {
            event.setDamage(DamageModifier.HARD_HAT, 0);
        } catch (UnsupportedOperationException e) {
        }
        try {
            event.setDamage(DamageModifier.MAGIC, 0);
        } catch (UnsupportedOperationException e) {
        }
        try {
            event.setDamage(DamageModifier.RESISTANCE, 0);
        } catch (UnsupportedOperationException e) {
        }
        DecimalFormat df = new DecimalFormat();
        df.setMaximumFractionDigits(2);
        if (getBukkitLivingEntity() instanceof Player) {
            String name = defender.getBukkitLivingEntity().getName();
            if (defender.getBukkitLivingEntity().getCustomName() != null)
                name = defender.getBukkitLivingEntity().getCustomName();
            if (defender.isPlayer())
                System.out.println("Detected player " + getBukkitLivingEntity().getName() + " vs player " + defender.getName());
            ((Player) getBukkitLivingEntity()).spigot().sendMessage(ChatMessageType.ACTION_BAR, new TextComponent("You hit " + name + " for " + df.format(event.getDamage()) + " " + df.format(defender.getBukkitLivingEntity().getHealth() - event.getDamage()) + "/" + df.format(defender.getBukkitLivingEntity().getMaxHealth()) + " " + my_hit.skill + " damage"));
            if (defender.isNPC()) {
                ISoliniaNPC npc;
                try {
                    npc = StateManager.getInstance().getConfigurationManager().getNPC(defender.getNpcid());
                } catch (CoreStateInitException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
            // Only players get this
            if (getDoubleAttackCheck()) {
                if (getBukkitLivingEntity() instanceof Player) {
                    ((Player) getBukkitLivingEntity()).sendMessage(ChatColor.GRAY + "* You double attack!");
                    tryIncreaseSkill("DOUBLEATTACK", 1);
                }
                defender.damage(plugin, my_hit.damage_done, this.getBukkitLivingEntity());
            }
            try {
                if (Utils.IsSoliniaItem(getBukkitLivingEntity().getEquipment().getItemInMainHand())) {
                    try {
                        ISoliniaItem soliniaitem = SoliniaItemAdapter.Adapt(getBukkitLivingEntity().getEquipment().getItemInMainHand());
                        if (soliniaitem != null) {
                            // Check if item has any proc effects
                            if (soliniaitem.getWeaponabilityid() > 0 && event.getCause().equals(DamageCause.ENTITY_ATTACK)) {
                                ISoliniaSpell procSpell = StateManager.getInstance().getConfigurationManager().getSpell(soliniaitem.getWeaponabilityid());
                                if (procSpell != null) {
                                    // Chance to proc
                                    int procChance = getProcChancePct();
                                    int roll = Utils.RandomBetween(0, 100);
                                    if (roll < procChance) {
                                        // TODO - For now apply self and group to attacker, else attach to target
                                        switch(Utils.getSpellTargetType(procSpell.getTargettype())) {
                                            case Self:
                                                procSpell.tryApplyOnEntity(plugin, this.getBukkitLivingEntity(), this.getBukkitLivingEntity());
                                                break;
                                            case Group:
                                                procSpell.tryApplyOnEntity(plugin, this.getBukkitLivingEntity(), this.getBukkitLivingEntity());
                                                break;
                                            default:
                                                procSpell.tryApplyOnEntity(plugin, this.getBukkitLivingEntity(), defender.getBukkitLivingEntity());
                                        }
                                    }
                                }
                            }
                        }
                    } catch (SoliniaItemException e) {
                    // skip
                    }
                }
                // Check if attacker has any WeaponProc effects
                SoliniaEntitySpells effects = StateManager.getInstance().getEntityManager().getActiveEntitySpells(this.getBukkitLivingEntity());
                if (effects != null) {
                    for (SoliniaActiveSpell activeSpell : effects.getActiveSpells()) {
                        ISoliniaSpell spell = StateManager.getInstance().getConfigurationManager().getSpell(activeSpell.getSpellId());
                        if (spell == null)
                            continue;
                        if (!spell.isWeaponProc())
                            continue;
                        for (ActiveSpellEffect spelleffect : activeSpell.getActiveSpellEffects()) {
                            if (spelleffect.getSpellEffectType().equals(SpellEffectType.WeaponProc)) {
                                if (spelleffect.getBase() < 0)
                                    continue;
                                ISoliniaSpell procSpell = StateManager.getInstance().getConfigurationManager().getSpell(spelleffect.getBase());
                                if (spell == null)
                                    continue;
                                // Chance to proc
                                int procChance = getProcChancePct();
                                int roll = Utils.RandomBetween(0, 100);
                                if (roll < procChance) {
                                    boolean itemUseSuccess = procSpell.tryApplyOnEntity(plugin, this.getBukkitLivingEntity(), defender.getBukkitLivingEntity());
                                    if (procSpell.getActSpellCost(this) > 0)
                                        if (itemUseSuccess) {
                                            if (getBukkitLivingEntity() instanceof Player) {
                                                SoliniaPlayerAdapter.Adapt((Player) getBukkitLivingEntity()).reducePlayerMana(procSpell.getActSpellCost(this));
                                            }
                                        }
                                }
                            }
                        }
                    }
                }
            } catch (CoreStateInitException e) {
            }
        }
        if (defender.getBukkitLivingEntity() instanceof Player) {
            ((Player) defender.getBukkitLivingEntity()).spigot().sendMessage(ChatMessageType.ACTION_BAR, new TextComponent("You were hit by " + getBukkitLivingEntity().getCustomName() + " for " + df.format(event.getDamage()) + " " + my_hit.skill + " damage"));
        }
        if (event.getDamage() > getBukkitLivingEntity().getHealth() && hasDeathSave() > 0) {
            Utils.CancelEvent(event);
            removeDeathSaves(plugin);
            getBukkitLivingEntity().sendMessage("* Your death save boon has saved you from death!");
            return false;
        }
        defender.damageHook(event.getDamage(), getBukkitLivingEntity());
        return true;
    } else {
        Utils.CancelEvent(event);
        return false;
    }
}
Also used : TextComponent(net.md_5.bungee.api.chat.TextComponent) Player(org.bukkit.entity.Player) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) ISoliniaItem(com.solinia.solinia.Interfaces.ISoliniaItem) ISoliniaSpell(com.solinia.solinia.Interfaces.ISoliniaSpell) DecimalFormat(java.text.DecimalFormat) SoliniaItemException(com.solinia.solinia.Exceptions.SoliniaItemException) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ISoliniaNPC(com.solinia.solinia.Interfaces.ISoliniaNPC) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) ItemStack(org.bukkit.inventory.ItemStack)

Example 40 with ISoliniaItem

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

the class SoliniaActiveSpell method applySummonItem.

private void applySummonItem(SpellEffect spellEffect, ISoliniaSpell soliniaSpell, int casterLevel) {
    int itemId = spellEffect.getBase();
    try {
        ISoliniaItem item = StateManager.getInstance().getConfigurationManager().getItem(itemId);
        if (item == null)
            return;
        if (!item.isTemporary())
            return;
        Entity ownerEntity = Bukkit.getEntity(this.getOwnerUuid());
        if (ownerEntity == null)
            return;
        if (!(ownerEntity instanceof LivingEntity))
            return;
        ownerEntity.getWorld().dropItem(ownerEntity.getLocation(), item.asItemStack());
    } catch (CoreStateInitException e) {
        return;
    }
}
Also used : CraftLivingEntity(org.bukkit.craftbukkit.v1_12_R1.entity.CraftLivingEntity) ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) LivingEntity(org.bukkit.entity.LivingEntity) CraftLivingEntity(org.bukkit.craftbukkit.v1_12_R1.entity.CraftLivingEntity) ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) Entity(org.bukkit.entity.Entity) CraftEntity(org.bukkit.craftbukkit.v1_12_R1.entity.CraftEntity) LivingEntity(org.bukkit.entity.LivingEntity) PathEntity(net.minecraft.server.v1_12_R1.PathEntity) ISoliniaItem(com.solinia.solinia.Interfaces.ISoliniaItem) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException)

Aggregations

ISoliniaItem (com.solinia.solinia.Interfaces.ISoliniaItem)41 CoreStateInitException (com.solinia.solinia.Exceptions.CoreStateInitException)37 ItemStack (org.bukkit.inventory.ItemStack)18 Player (org.bukkit.entity.Player)16 SoliniaItemException (com.solinia.solinia.Exceptions.SoliniaItemException)14 ISoliniaPlayer (com.solinia.solinia.Interfaces.ISoliniaPlayer)14 ArrayList (java.util.ArrayList)12 ISoliniaLivingEntity (com.solinia.solinia.Interfaces.ISoliniaLivingEntity)7 ISoliniaNPC (com.solinia.solinia.Interfaces.ISoliniaNPC)7 LivingEntity (org.bukkit.entity.LivingEntity)7 TextComponent (net.md_5.bungee.api.chat.TextComponent)5 CommandSender (org.bukkit.command.CommandSender)5 Entity (org.bukkit.entity.Entity)5 EventHandler (org.bukkit.event.EventHandler)5 ISoliniaLootDropEntry (com.solinia.solinia.Interfaces.ISoliniaLootDropEntry)4 ConsoleCommandSender (org.bukkit.command.ConsoleCommandSender)4 ISoliniaLootDrop (com.solinia.solinia.Interfaces.ISoliniaLootDrop)3 ISoliniaLootTableEntry (com.solinia.solinia.Interfaces.ISoliniaLootTableEntry)3 ISoliniaSpell (com.solinia.solinia.Interfaces.ISoliniaSpell)3 ISoliniaLootTable (com.solinia.solinia.Interfaces.ISoliniaLootTable)2