Search in sources :

Example 31 with ISoliniaItem

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

the class SoliniaPlayer method getEquippedSoliniaItems.

@Override
public List<ISoliniaItem> getEquippedSoliniaItems(boolean excludeMainHand) {
    List<ISoliniaItem> items = new ArrayList<ISoliniaItem>();
    try {
        List<ItemStack> itemStacks = new ArrayList<ItemStack>() {

            {
                if (excludeMainHand == false) {
                    add(getBukkitPlayer().getInventory().getItemInMainHand());
                }
                add(getBukkitPlayer().getInventory().getItemInOffHand());
                addAll(Arrays.asList(getBukkitPlayer().getInventory().getArmorContents()));
            }
        };
        for (ItemStack itemstack : itemStacks) {
            if (itemstack == null)
                continue;
            if (Utils.IsSoliniaItem(itemstack)) {
                ISoliniaItem item = StateManager.getInstance().getConfigurationManager().getItem(itemstack);
                if (item == null)
                    continue;
                if (item.isSpellscroll())
                    continue;
                items.add(item);
                Integer augmentationId = ItemStackUtils.getAugmentationItemId(itemstack);
                ISoliniaItem augItem = null;
                if (augmentationId != null && augmentationId != 0) {
                    augItem = StateManager.getInstance().getConfigurationManager().getItem(augmentationId);
                    items.add(augItem);
                }
            }
        }
        // Also check non-ui items
        if (this.getFingersItem() > 0) {
            ISoliniaItem item = StateManager.getInstance().getConfigurationManager().getItem(this.getFingersItem());
            if (item != null) {
                if (!item.isSpellscroll())
                    items.add(item);
            }
        }
        if (this.getShouldersItem() > 0) {
            ISoliniaItem item = StateManager.getInstance().getConfigurationManager().getItem(this.getShouldersItem());
            if (item != null) {
                if (!item.isSpellscroll())
                    items.add(item);
            }
        }
        if (this.getNeckItem() > 0) {
            ISoliniaItem item = StateManager.getInstance().getConfigurationManager().getItem(this.getNeckItem());
            if (item != null) {
                if (!item.isSpellscroll())
                    items.add(item);
            }
        }
    } catch (CoreStateInitException e) {
    }
    return items;
}
Also used : ISoliniaItem(com.solinia.solinia.Interfaces.ISoliniaItem) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ArrayList(java.util.ArrayList) ItemStack(org.bukkit.inventory.ItemStack)

Example 32 with ISoliniaItem

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

the class SoliniaPlayer method interact.

@Override
public void interact(Plugin plugin, PlayerInteractEvent event) {
    // TODO Auto-generated method stub
    ItemStack itemstack = event.getItem();
    try {
        // this is the item not in offhand
        if (event.getHand() == EquipmentSlot.HAND && (event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK)) {
            if (itemstack == null) {
                return;
            }
            if ((!Utils.IsSoliniaItem(itemstack)))
                return;
            // We have our custom item id, lets check it exists
            ISoliniaItem item = StateManager.getInstance().getConfigurationManager().getItem(itemstack);
            if (item == null) {
                return;
            }
            // Start applying an augmentation
            if ((event.getAction().equals(Action.RIGHT_CLICK_AIR) || event.getAction().equals(Action.RIGHT_CLICK_BLOCK)) && item.isAugmentation()) {
                if (StateManager.getInstance().getPlayerManager().getApplyingAugmentation(event.getPlayer().getUniqueId()) == null || StateManager.getInstance().getPlayerManager().getApplyingAugmentation(event.getPlayer().getUniqueId()) == 0) {
                    StateManager.getInstance().getPlayerManager().setApplyingAugmentation(event.getPlayer().getUniqueId(), item.getId());
                    event.getPlayer().sendMessage("* Applying " + item.getDisplayname() + " to an item, please right click the item you wish to apply this augmentation to. . To cancel applying, right click while holding this item again");
                } else {
                    StateManager.getInstance().getPlayerManager().setApplyingAugmentation(event.getPlayer().getUniqueId(), 0);
                    event.getPlayer().sendMessage("* Cancelled applying augmentation");
                }
                return;
            }
            if ((event.getAction().equals(Action.RIGHT_CLICK_AIR) || event.getAction().equals(Action.RIGHT_CLICK_BLOCK)) && item.isPetControlRod()) {
                LivingEntity targetmob = Utils.getTargettedLivingEntity(event.getPlayer(), 50);
                if (targetmob != null) {
                    item.useItemOnEntity(plugin, event.getPlayer(), targetmob, false);
                    return;
                }
            }
            if (item.getAbilityid() < 1) {
                return;
            }
            if (ItemStackUtils.isPotion(itemstack)) {
                // Handled by on consume event
                return;
            }
            ISoliniaSpell spell = StateManager.getInstance().getConfigurationManager().getSpell(item.getAbilityid());
            // Only applies to consumable items
            if ((event.getAction().equals(Action.RIGHT_CLICK_AIR) || event.getAction().equals(Action.RIGHT_CLICK_BLOCK)) && item.isConsumable()) {
                if (itemstack.getAmount() > 1) {
                    event.getPlayer().sendMessage("Tried to use an entire stack at once! Cancelling, did you forget to split them?");
                    return;
                }
                LivingEntity targetmob = Utils.getTargettedLivingEntity(event.getPlayer(), spell.getRange());
                if (targetmob != null) {
                    item.useItemOnEntity(plugin, event.getPlayer(), targetmob, true);
                    event.getPlayer().setItemInHand(null);
                    event.getPlayer().updateInventory();
                    return;
                } else {
                    item.useItemOnEntity(plugin, event.getPlayer(), event.getPlayer(), true);
                    event.getPlayer().setItemInHand(null);
                    event.getPlayer().updateInventory();
                    return;
                }
            }
            // Only applies to non-consumable items
            if ((event.getAction().equals(Action.RIGHT_CLICK_AIR) || event.getAction().equals(Action.RIGHT_CLICK_BLOCK)) && !item.isConsumable() && !itemstack.getType().equals(Material.ENCHANTED_BOOK)) {
                LivingEntity targetmob = Utils.getTargettedLivingEntity(event.getPlayer(), spell.getRange());
                if (targetmob != null) {
                    item.useItemOnEntity(plugin, event.getPlayer(), targetmob, true);
                    return;
                } else {
                    item.useItemOnEntity(plugin, event.getPlayer(), event.getPlayer(), true);
                    return;
                }
            }
            // Only applies to spell effects
            if (!itemstack.getType().equals(Material.ENCHANTED_BOOK)) {
                return;
            }
            // Reroute action depending on target
            if (event.getAction().equals(Action.RIGHT_CLICK_AIR) || event.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
                doCastSpellItem(plugin, spell, event.getPlayer(), item);
            }
        }
    } catch (CoreStateInitException e) {
        e.printStackTrace();
    }
}
Also used : ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) LivingEntity(org.bukkit.entity.LivingEntity) ISoliniaItem(com.solinia.solinia.Interfaces.ISoliniaItem) ISoliniaSpell(com.solinia.solinia.Interfaces.ISoliniaSpell) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ItemStack(org.bukkit.inventory.ItemStack)

Example 33 with ISoliniaItem

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

the class SoliniaLivingEntity method dropLoot.

@Override
public void dropLoot() {
    if (isPlayer())
        return;
    try {
        if (getNpcid() > 0) {
            ISoliniaNPC npc = StateManager.getInstance().getConfigurationManager().getNPC(getNpcid());
            if (npc.getLoottableid() == 0)
                return;
            ISoliniaLootTable table = StateManager.getInstance().getConfigurationManager().getLootTable(npc.getLoottableid());
            List<ISoliniaLootDropEntry> absoluteitems = new ArrayList<ISoliniaLootDropEntry>();
            List<ISoliniaLootDropEntry> rollitems = new ArrayList<ISoliniaLootDropEntry>();
            for (ISoliniaLootTableEntry entry : StateManager.getInstance().getConfigurationManager().getLootTable(table.getId()).getEntries()) {
                ISoliniaLootDrop droptable = StateManager.getInstance().getConfigurationManager().getLootDrop(entry.getLootdropid());
                for (ISoliniaLootDropEntry dropentry : StateManager.getInstance().getConfigurationManager().getLootDrop(droptable.getId()).getEntries()) {
                    if (dropentry.isAlways() == true) {
                        absoluteitems.add(dropentry);
                        continue;
                    }
                    rollitems.add(dropentry);
                }
            }
            if (absoluteitems.size() == 0 && rollitems.size() == 0)
                return;
            int dropcount = StateManager.getInstance().getWorldPerkDropCountModifier();
            Random r = new Random();
            int randomInt = r.nextInt(100) + 1;
            if (rollitems.size() > 0) {
                // Based on the chance attempt to drop this item
                for (int i = 0; i < dropcount; i++) {
                    ISoliniaLootDropEntry droptableentry = rollitems.get(new Random().nextInt(rollitems.size()));
                    ISoliniaItem item = StateManager.getInstance().getConfigurationManager().getItem(droptableentry.getItemid());
                    randomInt = r.nextInt(100) + 1;
                    // Handle unique item checking also
                    if (item.isArtifact() == true && item.isArtifactFound() == true)
                        continue;
                    if (randomInt <= droptableentry.getChance()) {
                        // Handle unique item setting also
                        if (item.isArtifact() == true && item.isArtifactFound() == false)
                            item.setArtifactFound(true);
                        getBukkitLivingEntity().getLocation().getWorld().dropItem(getBukkitLivingEntity().getLocation(), item.asItemStack());
                    }
                }
            }
            // Always drop these items
            if (absoluteitems.size() > 0) {
                for (int i = 0; i < absoluteitems.size(); i++) {
                    ISoliniaItem item = StateManager.getInstance().getConfigurationManager().getItem(absoluteitems.get(i).getItemid());
                    for (int c = 0; c < absoluteitems.get(i).getCount(); c++) {
                        // Handle unique item checking also
                        if (item.isArtifact() == true && item.isArtifactFound() == true)
                            continue;
                        getBukkitLivingEntity().getLocation().getWorld().dropItem(getBukkitLivingEntity().getLocation(), item.asItemStack());
                        // Handle unique item setting also
                        if (item.isArtifact() == true && item.isArtifactFound() == false)
                            item.setArtifactFound(true);
                    }
                }
            }
        } else {
        /*
				 * This is no longer needed now we have loot drops int itemDropMinimum = 95; if
				 * (Utils.RandomChance(itemDropMinimum)) { if (getBukkitLivingEntity()
				 * instanceof Monster)
				 * getBukkitLivingEntity().getWorld().dropItem(this.getBukkitLivingEntity().
				 * getLocation(),SoliniaItemFactory.GenerateRandomLoot().asItemStack()); }
				 */
        }
    } catch (CoreStateInitException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : ISoliniaLootDropEntry(com.solinia.solinia.Interfaces.ISoliniaLootDropEntry) ISoliniaItem(com.solinia.solinia.Interfaces.ISoliniaItem) Random(java.util.Random) ISoliniaLootTableEntry(com.solinia.solinia.Interfaces.ISoliniaLootTableEntry) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ISoliniaNPC(com.solinia.solinia.Interfaces.ISoliniaNPC) ArrayList(java.util.ArrayList) ISoliniaLootTable(com.solinia.solinia.Interfaces.ISoliniaLootTable) ISoliniaLootDrop(com.solinia.solinia.Interfaces.ISoliniaLootDrop)

Example 34 with ISoliniaItem

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

the class SoliniaNPCEventHandler method awardPlayer.

@Override
public void awardPlayer(Player triggerentity) {
    try {
        ISoliniaPlayer player = SoliniaPlayerAdapter.Adapt(triggerentity);
        if (getAwardsQuest() > 0) {
            boolean foundQuest = false;
            for (PlayerQuest playerQuest : player.getPlayerQuests()) {
                if (playerQuest.getQuestId() == getAwardsQuest()) {
                    foundQuest = true;
                }
            }
            if (foundQuest == false)
                player.addPlayerQuest(getAwardsQuest());
        }
        if (getAwardsQuestFlag() != null && !getAwardsQuestFlag().equals("")) {
            boolean foundQuestFlag = false;
            for (String playerQuestFlag : player.getPlayerQuestFlags()) {
                if (playerQuestFlag.equals(getAwardsQuestFlag())) {
                    foundQuestFlag = true;
                }
            }
            if (foundQuestFlag == false) {
                player.addPlayerQuestFlag(getAwardsQuestFlag());
                // All item awards must be accompanied with a quest flag else they will repeat the item return over and over
                if (getAwardsItem() > 0) {
                    System.out.println("Awarding item with awardquestflag: " + getAwardsQuestFlag());
                    ISoliniaItem item = StateManager.getInstance().getConfigurationManager().getItem(getAwardsItem());
                    final int awarditemid = getAwardsItem();
                    final UUID uuid = player.getBukkitPlayer().getUniqueId();
                    if (item != null) {
                        Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Bukkit.getPluginManager().getPlugin("Solinia3Core"), new Runnable() {

                            public void run() {
                                try {
                                    ItemStack itemStack = item.asItemStack();
                                    ISoliniaItem item = StateManager.getInstance().getConfigurationManager().getItem(awarditemid);
                                    Bukkit.getPlayer(uuid).getWorld().dropItem(Bukkit.getPlayer(uuid).getLocation(), itemStack);
                                    System.out.println("Awarded item: " + item.getDisplayname());
                                } catch (CoreStateInitException e) {
                                // skip
                                }
                            }
                        });
                    }
                }
                if (this.isAwardsTitle() == true) {
                    if (this.getTitle() != null) {
                        if (!this.getTitle().equals("")) {
                            player.grantTitle(this.getTitle());
                        }
                    }
                }
                if (isAwardsRandomisedGear() == true) {
                    String suffix = "of Randomisation";
                    if (getRandomisedGearSuffix() != null) {
                        if (!getRandomisedGearSuffix().equals("")) {
                            suffix = getRandomisedGearSuffix();
                        }
                    }
                    System.out.println("Awarding randomisedgear with awardquestflag: " + getAwardsQuestFlag());
                    int playertier = 1;
                    if (player.getLevel() >= 1 && player.getLevel() < 11)
                        playertier = 1;
                    if (player.getLevel() >= 11 && player.getLevel() < 21)
                        playertier = 2;
                    if (player.getLevel() >= 21 && player.getLevel() < 31)
                        playertier = 3;
                    if (player.getLevel() >= 31 && player.getLevel() < 41)
                        playertier = 4;
                    if (player.getLevel() >= 41 && player.getLevel() < 51)
                        playertier = 5;
                    if (player.getLevel() >= 51 && player.getLevel() < 61)
                        playertier = 6;
                    try {
                        // always give the next tier up and then we will reset the player requirements ot current level
                        // this ability is for special seasonal rewards only
                        playertier += 1;
                        List<Integer> items = SoliniaItemFactory.CreateClassItemSet(player.getClassObj(), playertier, suffix, false, true);
                        for (int itemid : items) {
                            ISoliniaItem item = StateManager.getInstance().getConfigurationManager().getItem(itemid);
                            final String playerName = player.getBukkitPlayer().getName();
                            final int minLevel = player.getLevel();
                            final int finalitemid = itemid;
                            if (item != null) {
                                Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Bukkit.getPluginManager().getPlugin("Solinia3Core"), new Runnable() {

                                    public void run() {
                                        try {
                                            ISoliniaItem item = StateManager.getInstance().getConfigurationManager().getItem(finalitemid);
                                            item.setMinLevel(minLevel);
                                            SoliniaAccountClaim claim = new SoliniaAccountClaim();
                                            claim.setId(StateManager.getInstance().getConfigurationManager().getNextAccountClaimId());
                                            claim.setMcname(playerName);
                                            claim.setItemid(finalitemid);
                                            claim.setClaimed(false);
                                            Player claimPlayer = Bukkit.getPlayer(playerName);
                                            if (claimPlayer != null) {
                                                claimPlayer.sendMessage(ChatColor.GOLD + "You have been awarded with a claim item! See /claim");
                                            }
                                            StateManager.getInstance().getConfigurationManager().addAccountClaim(claim);
                                            System.out.println("Awarded Claim: " + item.getDisplayname() + " to " + playerName);
                                        } catch (CoreStateInitException e) {
                                        // skip
                                        }
                                    }
                                });
                            }
                        }
                    } catch (SoliniaItemException e1) {
                        // TODO Auto-generated catch block
                        e1.printStackTrace();
                    }
                }
            }
        }
    } catch (CoreStateInitException e) {
        System.out.println(e.getMessage());
        return;
    }
}
Also used : 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) UUID(java.util.UUID) ItemStack(org.bukkit.inventory.ItemStack)

Example 35 with ISoliniaItem

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

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