Search in sources :

Example 6 with ISoliniaItem

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

the class CommandNPCGive method onCommand.

@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    if (!(sender instanceof Player))
        return false;
    Player player = (Player) sender;
    try {
        ISoliniaPlayer solplayer = SoliniaPlayerAdapter.Adapt(player);
        if (args.length < 1) {
            player.sendMessage("Invalid syntax missing <itemid>");
            return true;
        }
        if (solplayer.getInteraction() == null) {
            player.sendMessage(ChatColor.GRAY + "* You are not currently interacting with an NPC");
            return true;
        }
        Entity entity = Bukkit.getEntity(solplayer.getInteraction());
        if (entity == null) {
            player.sendMessage(ChatColor.GRAY + "* The npc you are trying to interact with appears to no longer be available");
            return true;
        }
        if (!(entity instanceof LivingEntity)) {
            player.sendMessage(ChatColor.GRAY + "* The npc you are trying to interact with appears to no longer be living");
            return true;
        }
        ISoliniaLivingEntity solentity = SoliniaLivingEntityAdapter.Adapt((LivingEntity) entity);
        if (solentity.getNpcid() < 1) {
            player.sendMessage(ChatColor.GRAY + "* You are not currently interacting with an NPC");
            return true;
        }
        ISoliniaNPC solnpc = StateManager.getInstance().getConfigurationManager().getNPC(solentity.getNpcid());
        int itemid = Integer.parseInt(args[0]);
        if (itemid < 1) {
            player.sendMessage("ItemID must be greater than 0");
            return true;
        }
        ISoliniaItem item = StateManager.getInstance().getConfigurationManager().getItem(itemid);
        if (Utils.getPlayerTotalCountOfItemId(player, itemid) < 1) {
            player.sendMessage("Sorry but you do not have the quantity you are trying to give");
            return true;
        }
        // Check if the npc actually wants to receive this item
        boolean npcWantsItem = false;
        for (ISoliniaNPCEventHandler eventHandler : solnpc.getEventHandlers()) {
            if (!eventHandler.getInteractiontype().equals(InteractionType.ITEM))
                continue;
            System.out.println("Comparing item id: " + item.getId() + " to triggerdata " + eventHandler.getTriggerdata());
            if (Integer.parseInt(eventHandler.getTriggerdata()) != item.getId())
                continue;
            if (eventHandler.getChatresponse() != null && !eventHandler.getChatresponse().equals("")) {
                System.out.println("Checking if player meets requirements to hand in item");
                if (!eventHandler.playerMeetsRequirements(player)) {
                    player.sendMessage(ChatColor.GRAY + "[Hint] You do not meet the requirements to hand this quest item in. Either you are missing a quest step or have already completed this step");
                    continue;
                }
                System.out.println("NPC wants the item");
                npcWantsItem = true;
                String response = eventHandler.getChatresponse();
                solentity.say(solnpc.replaceChatWordsWithHints(response), player);
                eventHandler.awardPlayer((Player) player);
                Utils.removeItemsFromInventory(player, itemid, 1);
            }
        }
        if (npcWantsItem == false) {
            player.sendMessage(ChatColor.GRAY + "* This being does not want this item at this time");
        }
        return true;
    } catch (CoreStateInitException e) {
        player.sendMessage(e.getMessage());
    }
    return true;
}
Also used : ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) LivingEntity(org.bukkit.entity.LivingEntity) ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) Player(org.bukkit.entity.Player) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) ISoliniaItem(com.solinia.solinia.Interfaces.ISoliniaItem) ISoliniaNPCEventHandler(com.solinia.solinia.Interfaces.ISoliniaNPCEventHandler) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ISoliniaNPC(com.solinia.solinia.Interfaces.ISoliniaNPC) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer)

Example 7 with ISoliniaItem

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

the class CommandRebuildSpellItems method onCommand.

@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    if (!(sender instanceof Player) && !(sender instanceof CommandSender)) {
        sender.sendMessage("This is a Player/Console only command");
        return false;
    }
    if (sender instanceof Player) {
        Player player = (Player) sender;
        if (!player.isOp()) {
            player.sendMessage("This is an operator only command");
            return true;
        }
    }
    int updated = 0;
    sender.sendMessage("Rebuilding Item Lists, this may take some time");
    try {
        for (ISoliniaSpell spell : StateManager.getInstance().getConfigurationManager().getSpells()) {
            int worth = 10;
            int minLevel = 1;
            int lowestLevel = 1000;
            for (SoliniaSpellClass spellClass : spell.getAllowedClasses()) {
                if (spellClass.getMinlevel() < lowestLevel)
                    lowestLevel = spellClass.getMinlevel();
            }
            if (lowestLevel > minLevel && lowestLevel < 100)
                minLevel = lowestLevel;
            worth = worth * minLevel;
            // Spell exists
            if (StateManager.getInstance().getConfigurationManager().getSpellItem(spell.getId()).size() > 0) {
                for (ISoliniaItem item : StateManager.getInstance().getConfigurationManager().getSpellItem(spell.getId())) {
                    item.setAbilityid(spell.getId());
                    item.setDisplayname("Spell: " + spell.getName());
                    item.setSpellscroll(true);
                    item.setAllowedClassNames(new ArrayList<String>());
                    item.setLore("This appears to be some sort of   magical spell that could be       learned");
                    item.setWorth(worth);
                    StateManager.getInstance().getConfigurationManager().updateItem(item);
                    updated++;
                }
            } else {
                // Doesnt exist, create it
                ISoliniaItem item = SoliniaItemFactory.CreateItem(new ItemStack(Material.ENCHANTED_BOOK), sender.isOp());
                item.setAbilityid(spell.getId());
                item.setDisplayname("Spell: " + spell.getName());
                item.setSpellscroll(true);
                item.setAllowedClassNames(new ArrayList<String>());
                item.setLore("This appears to be some sort of   magical spell that could be       learned");
                item.setWorth(worth);
                StateManager.getInstance().getConfigurationManager().updateItem(item);
                updated++;
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        sender.sendMessage(e.getMessage());
    }
    sender.sendMessage("Updated " + updated + " items");
    return true;
}
Also used : Player(org.bukkit.entity.Player) ISoliniaSpell(com.solinia.solinia.Interfaces.ISoliniaSpell) ISoliniaItem(com.solinia.solinia.Interfaces.ISoliniaItem) CommandSender(org.bukkit.command.CommandSender) ConsoleCommandSender(org.bukkit.command.ConsoleCommandSender) ItemStack(org.bukkit.inventory.ItemStack) SoliniaSpellClass(com.solinia.solinia.Models.SoliniaSpellClass)

Example 8 with ISoliniaItem

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

the class SoliniaSpell method isValidEffectForEntity.

public static boolean isValidEffectForEntity(LivingEntity target, LivingEntity source, ISoliniaSpell soliniaSpell) throws CoreStateInitException {
    if (source == null) {
        System.out.println("Source was null for isValidEffectForEntity: " + soliniaSpell.getName() + " on target: " + target.getCustomName());
        return false;
    }
    if (target == null) {
        System.out.println("Target was null for isValidEffectForEntity: " + soliniaSpell.getName() + " from source: " + source.getCustomName());
        return false;
    }
    // Always allow self only spells if the target and source is the self
    if (source.getUniqueId().equals(target.getUniqueId()) && Utils.getSpellTargetType(soliniaSpell.getTargettype()).equals(SpellTargetType.Self)) {
        // just be sure to check the item its giving if its an item spell
        for (SpellEffect effect : soliniaSpell.getBaseSpellEffects()) {
            if (effect.getSpellEffectType().equals(SpellEffectType.SummonHorse)) {
                if (source instanceof Player) {
                    if (source.getUniqueId().equals(target.getUniqueId())) {
                        if (StateManager.getInstance().getPlayerManager().getPlayerLastChangeChar(source.getUniqueId()) != null) {
                            source.sendMessage("You can only summon a mount once per server session. Please wait for the next 4 hourly restart");
                            return false;
                        }
                    } else {
                        return false;
                    }
                } else {
                    return false;
                }
            }
            if (effect.getSpellEffectType().equals(SpellEffectType.SummonItem)) {
                System.out.println("Validating SummonItem for source: " + source.getCustomName());
                int itemId = effect.getBase();
                try {
                    ISoliniaItem item = StateManager.getInstance().getConfigurationManager().getItem(itemId);
                    System.out.println("Validating SummonItem for source: " + source.getCustomName());
                    if (item == null) {
                        System.out.println("Validating SummonItem said item was null");
                        return false;
                    }
                    if (!item.isTemporary()) {
                        System.out.println("Validating SummonItem said item was not temporary");
                        return false;
                    }
                    if (!(target instanceof LivingEntity)) {
                        System.out.println("Validating SummonItem said target was not a living entity");
                        return false;
                    }
                } catch (CoreStateInitException e) {
                    return false;
                }
            }
        }
        // System.out.println("Detected a self only spell (" + soliniaSpell.getName() + "), returning as valid, always");
        return true;
    }
    if (!source.getUniqueId().equals(target.getUniqueId()))
        if (!source.hasLineOfSight(target))
            return false;
    // Try not to kill potentially friendly player tameables with hostile spells
    if (target instanceof Tameable && target instanceof Creature && !soliniaSpell.isBeneficial()) {
        Tameable t = (Tameable) target;
        Creature cr = (Creature) target;
        if (t.getOwner() != null) {
            if (cr.getTarget() == null)
                return false;
            if (!cr.getTarget().getUniqueId().equals(source.getUniqueId()))
                return false;
        }
    }
    for (SpellEffect effect : soliniaSpell.getBaseSpellEffects()) {
        // and the spell is a detrimental
        if (source instanceof Player && target instanceof Player && soliniaSpell.isDetrimental()) {
            ISoliniaPlayer solsourceplayer = SoliniaPlayerAdapter.Adapt((Player) source);
            if (solsourceplayer.getGroup() != null) {
                if (solsourceplayer.getGroup().getMembers().contains(target.getUniqueId())) {
                    return false;
                }
            }
        }
        // Return false if the target is in the same faction as the npc and not self
        if (!(source instanceof Player) && !(target instanceof Player) && soliniaSpell.isDetrimental() && !source.getUniqueId().equals(target.getUniqueId())) {
            if (source instanceof LivingEntity && target instanceof LivingEntity) {
                ISoliniaLivingEntity solsourceEntity = SoliniaLivingEntityAdapter.Adapt(source);
                ISoliniaLivingEntity soltargetEntity = SoliniaLivingEntityAdapter.Adapt(target);
                if (solsourceEntity.isNPC() && soltargetEntity.isNPC()) {
                    ISoliniaNPC sourceNpc = StateManager.getInstance().getConfigurationManager().getNPC(solsourceEntity.getNpcid());
                    ISoliniaNPC targetNpc = StateManager.getInstance().getConfigurationManager().getNPC(solsourceEntity.getNpcid());
                    if (sourceNpc.getFactionid() > 0 && targetNpc.getFactionid() > 0) {
                        if (sourceNpc.getFactionid() == targetNpc.getFactionid())
                            return false;
                    }
                }
            }
        }
        if (effect.getSpellEffectType().equals(SpellEffectType.Revive)) {
            if (!(target instanceof Player)) {
                return false;
            }
            if (!(source instanceof Player))
                return false;
            Player sourcePlayer = (Player) source;
            if (!sourcePlayer.getInventory().getItemInOffHand().getType().equals(Material.NAME_TAG)) {
                sourcePlayer.sendMessage("You are not holding a Signaculum in your offhand (MC): " + sourcePlayer.getInventory().getItemInOffHand().getType().name());
                return false;
            }
            ItemStack item = sourcePlayer.getInventory().getItemInOffHand();
            if (item.getEnchantmentLevel(Enchantment.DURABILITY) != 1) {
                sourcePlayer.sendMessage("You are not holding a Signaculum in your offhand (EC)");
                return false;
            }
            if (!item.getItemMeta().getDisplayName().equals("Signaculum")) {
                sourcePlayer.sendMessage("You are not holding a Signaculum in your offhand (NC)");
                return false;
            }
            if (item.getItemMeta().getLore().size() < 5) {
                sourcePlayer.sendMessage("You are not holding a Signaculum in your offhand (LC)");
                return false;
            }
            String sigdataholder = item.getItemMeta().getLore().get(3);
            String[] sigdata = sigdataholder.split("\\|");
            if (sigdata.length != 2) {
                sourcePlayer.sendMessage("You are not holding a Signaculum in your offhand (SD)");
                return false;
            }
            String str_experience = sigdata[0];
            String str_stimetsamp = sigdata[1];
            int experience = Integer.parseInt(str_experience);
            Timestamp timestamp = Timestamp.valueOf(str_stimetsamp);
            LocalDateTime datetime = LocalDateTime.now();
            Timestamp currenttimestamp = Timestamp.valueOf(datetime);
            long maxminutes = 60 * 7;
            if ((currenttimestamp.getTime() - timestamp.getTime()) >= maxminutes * 60 * 1000) {
                sourcePlayer.sendMessage("This Signaculum has lost its binding to the soul");
                return false;
            }
            String playeruuidb64 = item.getItemMeta().getLore().get(4);
            String uuid = Utils.uuidFromBase64(playeruuidb64);
            Player targetplayer = Bukkit.getPlayer(UUID.fromString(uuid));
            if (targetplayer == null || !targetplayer.isOnline()) {
                sourcePlayer.sendMessage("You cannot resurrect that player as they are offline");
                return false;
            }
        }
        // Validate spelleffecttype rules
        if (effect.getSpellEffectType().equals(SpellEffectType.CurrentHP) || effect.getSpellEffectType().equals(SpellEffectType.CurrentHPOnce)) {
            // Ignore this rule if the spell is self
            if (!Utils.getSpellTargetType(soliniaSpell.getTargettype()).equals(SpellTargetType.Self)) {
                // If the effect is negative standard nuke and on self, cancel out
                if (effect.getBase() < 0 && target.equals(source))
                    return false;
            }
            // cancel
            if (source instanceof Player) {
                if (!(target instanceof Player)) {
                    ISoliniaLivingEntity soltargetentity = SoliniaLivingEntityAdapter.Adapt(target);
                    if (!soltargetentity.isPet()) {
                        if (effect.getBase() > 0)
                            return false;
                    }
                }
            }
        }
        if (effect.getSpellEffectType().equals(SpellEffectType.Illusion) || effect.getSpellEffectType().equals(SpellEffectType.IllusionaryTarget) || effect.getSpellEffectType().equals(SpellEffectType.IllusionCopy) || effect.getSpellEffectType().equals(SpellEffectType.IllusionOther) || effect.getSpellEffectType().equals(SpellEffectType.IllusionPersistence)) {
            // if target has spell effect of above already then we cant apply another
            for (SoliniaActiveSpell activeSpell : StateManager.getInstance().getEntityManager().getActiveEntitySpells(target).getActiveSpells()) {
                if (activeSpell.getSpell().getSpellEffectTypes().contains(SpellEffectType.Illusion))
                    return false;
                if (activeSpell.getSpell().getSpellEffectTypes().contains(SpellEffectType.IllusionaryTarget))
                    return false;
                if (activeSpell.getSpell().getSpellEffectTypes().contains(SpellEffectType.IllusionCopy))
                    return false;
                if (activeSpell.getSpell().getSpellEffectTypes().contains(SpellEffectType.IllusionOther))
                    return false;
                if (activeSpell.getSpell().getSpellEffectTypes().contains(SpellEffectType.IllusionPersistence))
                    return false;
            }
        }
        if (effect.getSpellEffectType().equals(SpellEffectType.SummonItem)) {
            System.out.println("Validating SummonItem for source: " + source.getCustomName());
            int itemId = effect.getBase();
            try {
                ISoliniaItem item = StateManager.getInstance().getConfigurationManager().getItem(itemId);
                System.out.println("Validating SummonItem for source: " + source.getCustomName());
                if (item == null) {
                    System.out.println("Validating SummonItem said item was null");
                    return false;
                }
                if (!item.isTemporary()) {
                    System.out.println("Validating SummonItem said item was not temporary");
                    return false;
                }
                if (!(target instanceof LivingEntity)) {
                    System.out.println("Validating SummonItem said target was not a living entity");
                    return false;
                }
            } catch (CoreStateInitException e) {
                return false;
            }
        }
        if (effect.getSpellEffectType().equals(SpellEffectType.ResistAll) || effect.getSpellEffectType().equals(SpellEffectType.ResistCold) || effect.getSpellEffectType().equals(SpellEffectType.ResistFire) || effect.getSpellEffectType().equals(SpellEffectType.ResistMagic) || effect.getSpellEffectType().equals(SpellEffectType.ResistPoison) || effect.getSpellEffectType().equals(SpellEffectType.ResistDisease) || effect.getSpellEffectType().equals(SpellEffectType.ResistCorruption)) {
            // If the effect is negative standard resist debuffer and on self, cancel out
            if (effect.getBase() < 0 && target.equals(source))
                return false;
        }
        if (effect.getSpellEffectType().equals(SpellEffectType.Mez)) {
            // If the effect is a mez, cancel out
            if (target.equals(source))
                return false;
        }
        if (effect.getSpellEffectType().equals(SpellEffectType.Stun)) {
            // If the effect is a stun, cancel out
            if (target.equals(source))
                return false;
        }
        if (effect.getSpellEffectType().equals(SpellEffectType.Root)) {
            // If the effect is a root, cancel out
            if (target.equals(source))
                return false;
        }
        if (effect.getSpellEffectType().equals(SpellEffectType.Blind)) {
            // If the effect is a blindness, cancel out
            if (target.equals(source))
                return false;
        }
        if (effect.getSpellEffectType().equals(SpellEffectType.DamageShield) && !(target instanceof Player) && !SoliniaLivingEntityAdapter.Adapt(target).isPet()) {
            // If the effect is a mez, cancel out
            if (target.equals(source))
                return false;
        }
        if (effect.getSpellEffectType().equals(SpellEffectType.NecPet) || effect.getSpellEffectType().equals(SpellEffectType.SummonPet) || effect.getSpellEffectType().equals(SpellEffectType.Teleport) || effect.getSpellEffectType().equals(SpellEffectType.Teleport2) || effect.getSpellEffectType().equals(SpellEffectType.Translocate) || effect.getSpellEffectType().equals(SpellEffectType.TranslocatetoAnchor)) {
            // If the effect is teleport and the target is not a player then fail
            if (!(target instanceof Player))
                return false;
            if (!(source instanceof Player))
                return false;
            // If the effect is a teleport and the target is not in a group or self then fail
            if (effect.getSpellEffectType().equals(SpellEffectType.Teleport) || effect.getSpellEffectType().equals(SpellEffectType.Teleport2) || effect.getSpellEffectType().equals(SpellEffectType.Translocate) || effect.getSpellEffectType().equals(SpellEffectType.TranslocatetoAnchor)) {
                // if target is not the player casting
                if (!target.getUniqueId().equals(source.getUniqueId())) {
                    ISoliniaPlayer solplayertarget = SoliniaPlayerAdapter.Adapt((Player) target);
                    if (solplayertarget == null)
                        return false;
                    if (solplayertarget.getGroup() == null)
                        return false;
                    if (!(solplayertarget.getGroup().getMembers().contains(source.getUniqueId())))
                        return false;
                }
            }
            if (effect.getSpellEffectType().equals(SpellEffectType.SummonPet) || effect.getSpellEffectType().equals(SpellEffectType.NecPet)) {
                try {
                    ISoliniaNPC npc = StateManager.getInstance().getConfigurationManager().getPetNPCByName(soliniaSpell.getTeleportZone());
                    if (npc == null) {
                        return false;
                    }
                    if (npc.isPet() == false) {
                        System.out.print("NPC " + soliniaSpell.getTeleportZone() + " is not defined as a pet");
                        return false;
                    }
                } catch (CoreStateInitException e) {
                    return false;
                }
            }
        }
    }
    return true;
}
Also used : LocalDateTime(java.time.LocalDateTime) Player(org.bukkit.entity.Player) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) ISoliniaItem(com.solinia.solinia.Interfaces.ISoliniaItem) Tameable(org.bukkit.entity.Tameable) Creature(org.bukkit.entity.Creature) Timestamp(java.sql.Timestamp) ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) LivingEntity(org.bukkit.entity.LivingEntity) ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ISoliniaNPC(com.solinia.solinia.Interfaces.ISoliniaNPC) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) ItemStack(org.bukkit.inventory.ItemStack)

Example 9 with ISoliniaItem

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

the class MythicMobsNPCEntityProvider method createNpcFile.

public String createNpcFile(ISoliniaNPC npc) {
    String mob = "";
    String uniquename = "NPCID_" + npc.getId();
    if (npc.getMctype() == null)
        return "";
    mob = uniquename + ":\r\n";
    mob = mob + "  Type: " + npc.getMctype() + "\r\n";
    if (npc.isUpsidedown() == true) {
        mob = mob + "  Display: Dinnerbone\r\n";
    } else {
        mob = mob + "  Display: " + npc.getName() + "\r\n";
    }
    double hp = Utils.getStatMaxHP(npc.getClassObj(), npc.getLevel(), 75);
    double damage = Utils.getMaxDamage(npc.getLevel(), 75);
    if (npc.isHeroic()) {
        hp += (Utils.getHeroicHPMultiplier() * npc.getLevel());
        damage += (Utils.getHeroicDamageMultiplier() * npc.getLevel());
    }
    if (npc.isBoss()) {
        hp += (Utils.getBossHPMultiplier() * npc.getLevel());
        damage += (Utils.getBossDamageMultiplier() * npc.getLevel());
    }
    if (npc.isRaidheroic()) {
        hp += (Utils.getRaidHeroicHPMultiplier() * npc.getLevel());
        damage += (Utils.getRaidHeroicDamageMultiplier() * npc.getLevel());
    }
    if (npc.isRaidboss()) {
        hp += (Utils.getRaidBossHPMultiplier() * npc.getLevel());
        damage += (Utils.getRaidBossDamageMultiplier() * npc.getLevel());
    }
    float movementSpeed = 0.3f;
    if (npc.isHeroic()) {
        movementSpeed = Utils.getHeroicRunSpeed();
    }
    if (npc.isBoss()) {
        movementSpeed = Utils.getBossRunSpeed();
    }
    if (npc.isRaidheroic()) {
        movementSpeed = Utils.getRaidHeroicRunSpeed();
    }
    if (npc.isRaidboss()) {
        movementSpeed = Utils.getRaidBossRunSpeed();
    }
    mob = mob + "  Health: " + hp + "\r\n";
    mob = mob + "  Damage: " + damage + "\r\n";
    mob = mob + "  MaxCombatDistance: 25\r\n";
    mob = mob + "  PreventOtherDrops: true\r\n";
    mob = mob + "  PreventRandomEquipment: true\r\n";
    mob = mob + "  Options:\r\n";
    mob = mob + "    MovementSpeed: " + movementSpeed + "\r\n";
    mob = mob + "    KnockbackResistance: 0.75\r\n";
    mob = mob + "    PreventMobKillDrops: true\r\n";
    mob = mob + "    PreventOtherDrops: true\r\n";
    mob = mob + "    Silent: true\r\n";
    mob = mob + "    ShowHealth: true\r\n";
    mob = mob + "    PreventRenaming: true\r\n";
    mob = mob + "    PreventRandomEquipment: true\r\n";
    mob = mob + "    AlwaysShowName: true\r\n";
    mob = mob + "  Modules:\r\n";
    mob = mob + "    ThreatTable: false\r\n";
    if (npc.isPet()) {
        mob = mob + "  Faction: FACTIONID_-1\r\n";
    } else {
        mob = mob + "  Faction: FACTIONID_" + npc.getFactionid() + "\r\n";
    }
    // Act as normal mob if without faction
    if (npc.getFactionid() > 0 || npc.isPet()) {
        mob = mob + "  AIGoalSelectors:\r\n";
        mob = mob + "  - 0 clear\r\n";
        mob = mob + "  - 1 skeletonbowattack\r\n";
        mob = mob + "  - 2 meleeattack\r\n";
        mob = mob + "  - 3 lookatplayers\r\n";
        if (npc.isRoamer()) {
            mob = mob + "  - 4 randomstroll\r\n";
        }
        mob = mob + "  AITargetSelectors:\r\n";
        mob = mob + "  - 0 clear\r\n";
        mob = mob + "  - 1 attacker\r\n";
        // NPC attack players
        if (!npc.isPet()) {
            try {
                ISoliniaFaction npcfaction = StateManager.getInstance().getConfigurationManager().getFaction(npc.getFactionid());
                if (npcfaction.getBase() == -1500) {
                    mob = mob + "  - 2 players\r\n";
                }
            } catch (CoreStateInitException e) {
            // skip
            }
        }
        // NPC attack NPCs
        if (npc.isGuard() || npc.isPet()) {
            // Always attack mobs with factionid 0
            mob = mob + "  - 3 SpecificFaction FACTIONID_0\r\n";
            // Attack all mobs with -1500 faction
            try {
                int curnum = 4;
                for (ISoliniaFaction faction : StateManager.getInstance().getConfigurationManager().getFactions()) {
                    if (faction.getBase() == -1500 && faction.getId() != npc.getFactionid()) {
                        mob = mob + "  - " + curnum + " SpecificFaction FACTIONID_" + faction.getId() + "\r\n";
                        curnum++;
                    }
                }
            } catch (CoreStateInitException e) {
            // skip
            }
        }
    }
    // then go ahead and use it! Better than that crap we have right?
    if (npc.getLoottableid() > 0) {
        try {
            ISoliniaLootTable lootTable = StateManager.getInstance().getConfigurationManager().getLootTable(npc.getLoottableid());
            if (lootTable != null) {
                List<ISoliniaItem> potentialChestArmour = new ArrayList<ISoliniaItem>();
                List<ISoliniaItem> potentialLegsArmour = new ArrayList<ISoliniaItem>();
                List<ISoliniaItem> potentialFeetArmour = new ArrayList<ISoliniaItem>();
                List<ISoliniaItem> potentialWeapons = new ArrayList<ISoliniaItem>();
                List<ISoliniaItem> potentialBows = new ArrayList<ISoliniaItem>();
                List<ISoliniaItem> potentialShields = new ArrayList<ISoliniaItem>();
                for (ISoliniaLootTableEntry loottableentry : lootTable.getEntries()) {
                    ISoliniaLootDrop lootdrop = StateManager.getInstance().getConfigurationManager().getLootDrop(loottableentry.getLootdropid());
                    for (ISoliniaLootDropEntry lootdropentry : lootdrop.getEntries()) {
                        ISoliniaItem item = StateManager.getInstance().getConfigurationManager().getItem(lootdropentry.getItemid());
                        if (ConfigurationManager.ArmourMaterials.contains(item.getBasename().toUpperCase())) {
                            if (item.getAllowedClassNames().size() == 0) {
                                if (item.getBasename().contains("CHESTPLATE"))
                                    potentialChestArmour.add(item);
                                if (item.getBasename().contains("LEGGINGS"))
                                    potentialLegsArmour.add(item);
                                if (item.getBasename().contains("BOOTS"))
                                    potentialFeetArmour.add(item);
                                continue;
                            }
                            if (npc.getClassObj() != null) {
                                if (item.getAllowedClassNames().contains(npc.getClassObj().getName())) {
                                    if (item.getBasename().contains("CHESTPLATE"))
                                        potentialChestArmour.add(item);
                                    if (item.getBasename().contains("LEGGINGS"))
                                        potentialLegsArmour.add(item);
                                    if (item.getBasename().contains("BOOTS"))
                                        potentialFeetArmour.add(item);
                                    continue;
                                }
                            }
                        }
                        if (ConfigurationManager.WeaponMaterials.contains(item.getBasename().toUpperCase())) {
                            if (item.getAllowedClassNames().size() == 0) {
                                if (item.getBasename().contains("SHIELD"))
                                    potentialShields.add(item);
                                else if (item.getBasename().contains("BOW"))
                                    potentialBows.add(item);
                                else
                                    potentialWeapons.add(item);
                                continue;
                            }
                            if (npc.getClassObj() != null) {
                                if (item.getAllowedClassNames().contains(npc.getClassObj().getName())) {
                                    if (item.getBasename().contains("SHIELD"))
                                        potentialShields.add(item);
                                    else
                                        potentialWeapons.add(item);
                                    continue;
                                }
                            }
                        }
                        if (ConfigurationManager.HandMaterials.contains(item.getBasename().toUpperCase())) {
                            if (item.getAllowedClassNames().size() == 0) {
                                if (item.getBasename().contains("SHIELD"))
                                    potentialShields.add(item);
                                else if (item.getBasename().contains("BOW"))
                                    potentialBows.add(item);
                                else
                                    potentialWeapons.add(item);
                                continue;
                            }
                            if (npc.getClassObj() != null) {
                                if (item.getAllowedClassNames().contains(npc.getClassObj().getName())) {
                                    if (item.getBasename().contains("SHIELD"))
                                        potentialShields.add(item);
                                    else
                                        potentialWeapons.add(item);
                                    continue;
                                }
                            }
                        }
                    }
                    mob = mob + "  Equipment:\r\n";
                    if (potentialShields.size() > 0) {
                        Collections.sort(potentialShields, new Comparator<ISoliniaItem>() {

                            public int compare(ISoliniaItem o1, ISoliniaItem o2) {
                                if (o1.getMinLevel() == o2.getMinLevel())
                                    return 0;
                                return o1.getMinLevel() > o2.getMinLevel() ? -1 : 1;
                            }
                        });
                        Collections.reverse(potentialShields);
                        System.out.println("Found better shield in lootdrop (" + potentialWeapons.get(0).getDisplayname() + "), using as shield");
                        writeCustomItem("plugins/MythicMobs/Items/CUSTOMITEMID" + potentialWeapons.get(0).getId() + ".yml", potentialWeapons.get(0));
                        mob = mob + "  - " + "CUSTOMITEMID_" + potentialWeapons.get(0).getId() + ":5\r\n";
                    } else {
                        if (npc.getOffhanditem() != null)
                            mob = mob + "  - " + npc.getOffhanditem() + ":5\r\n";
                    }
                    if (npc.isCustomhead() == true) {
                        if (npc.getCustomheaddata() != null) {
                            mob = mob + "  - CUSTOMHEADNPCID_" + npc.getId() + ":4\r\n";
                        } else {
                            if (npc.getHeaditem() != null)
                                mob = mob + "  - " + npc.getHeaditem() + ":4\r\n";
                        }
                    } else {
                        if (npc.getHeaditem() != null)
                            mob = mob + "  - " + npc.getHeaditem() + ":4\r\n";
                    }
                    if (potentialChestArmour.size() > 0) {
                        Collections.sort(potentialChestArmour, new Comparator<ISoliniaItem>() {

                            public int compare(ISoliniaItem o1, ISoliniaItem o2) {
                                if (o1.getMinLevel() == o2.getMinLevel())
                                    return 0;
                                return o1.getMinLevel() > o2.getMinLevel() ? -1 : 1;
                            }
                        });
                        Collections.reverse(potentialChestArmour);
                        System.out.println("Found better chest in lootdrop (" + potentialChestArmour.get(0).getDisplayname() + "), using as chest");
                        writeCustomItem("plugins/MythicMobs/Items/CUSTOMITEMID" + potentialChestArmour.get(0).getId() + ".yml", potentialChestArmour.get(0));
                        mob = mob + "  - " + "CUSTOMITEMID_" + potentialChestArmour.get(0).getId() + ":3\r\n";
                    } else {
                        if (npc.getChestitem() != null)
                            mob = mob + "  - " + npc.getChestitem() + ":3\r\n";
                    }
                    if (potentialLegsArmour.size() > 0) {
                        Collections.sort(potentialLegsArmour, new Comparator<ISoliniaItem>() {

                            public int compare(ISoliniaItem o1, ISoliniaItem o2) {
                                if (o1.getMinLevel() == o2.getMinLevel())
                                    return 0;
                                return o1.getMinLevel() > o2.getMinLevel() ? -1 : 1;
                            }
                        });
                        Collections.reverse(potentialLegsArmour);
                        System.out.println("Found better legs in lootdrop (" + potentialLegsArmour.get(0).getDisplayname() + "), using as weapon");
                        writeCustomItem("plugins/MythicMobs/Items/CUSTOMITEMID" + potentialLegsArmour.get(0).getId() + ".yml", potentialLegsArmour.get(0));
                        mob = mob + "  - " + "CUSTOMITEMID_" + potentialLegsArmour.get(0).getId() + ":2\r\n";
                    } else {
                        if (npc.getLegsitem() != null)
                            mob = mob + "  - " + npc.getLegsitem() + ":2\r\n";
                    }
                    if (potentialFeetArmour.size() > 0) {
                        Collections.sort(potentialFeetArmour, new Comparator<ISoliniaItem>() {

                            public int compare(ISoliniaItem o1, ISoliniaItem o2) {
                                if (o1.getMinLevel() == o2.getMinLevel())
                                    return 0;
                                return o1.getMinLevel() > o2.getMinLevel() ? -1 : 1;
                            }
                        });
                        Collections.reverse(potentialFeetArmour);
                        System.out.println("Found better feet in lootdrop (" + potentialFeetArmour.get(0).getDisplayname() + "), using as feet");
                        writeCustomItem("plugins/MythicMobs/Items/CUSTOMITEMID" + potentialFeetArmour.get(0).getId() + ".yml", potentialFeetArmour.get(0));
                        mob = mob + "  - " + "CUSTOMITEMID_" + potentialFeetArmour.get(0).getId() + ":1\r\n";
                    } else {
                        if (npc.getFeetitem() != null)
                            mob = mob + "  - " + npc.getFeetitem() + ":1\r\n";
                    }
                    if (npc.getClassObj() != null && npc.getClassObj().getName().toUpperCase().equals("RANGER") && potentialBows.size() > 0) {
                        Collections.sort(potentialBows, new Comparator<ISoliniaItem>() {

                            public int compare(ISoliniaItem o1, ISoliniaItem o2) {
                                if (o1.getMinLevel() == o2.getMinLevel())
                                    return 0;
                                return o1.getMinLevel() > o2.getMinLevel() ? -1 : 1;
                            }
                        });
                        Collections.reverse(potentialBows);
                        System.out.println("Found better weapon (bow) in lootdrop (" + potentialBows.get(0).getDisplayname() + "), using as weapon");
                        writeCustomItem("plugins/MythicMobs/Items/CUSTOMITEMID" + potentialBows.get(0).getId() + ".yml", potentialBows.get(0));
                        mob = mob + "  - " + "CUSTOMITEMID_" + potentialBows.get(0).getId() + ":0\r\n";
                    } else {
                        if (potentialWeapons.size() > 0) {
                            Collections.sort(potentialWeapons, new Comparator<ISoliniaItem>() {

                                public int compare(ISoliniaItem o1, ISoliniaItem o2) {
                                    if (o1.getMinLevel() == o2.getMinLevel())
                                        return 0;
                                    return o1.getMinLevel() > o2.getMinLevel() ? -1 : 1;
                                }
                            });
                            Collections.reverse(potentialWeapons);
                            System.out.println("Found better weapon in lootdrop (" + potentialWeapons.get(0).getDisplayname() + "), using as weapon");
                            writeCustomItem("plugins/MythicMobs/Items/CUSTOMITEMID" + potentialWeapons.get(0).getId() + ".yml", potentialWeapons.get(0));
                            mob = mob + "  - " + "CUSTOMITEMID_" + potentialWeapons.get(0).getId() + ":0\r\n";
                        } else {
                            if (npc.getHanditem() != null)
                                mob = mob + "  - " + npc.getHanditem() + ":0\r\n";
                        }
                    }
                }
            }
        } catch (CoreStateInitException e) {
        // skip
        }
    } else {
        if (npc.getHeaditem() != null || npc.getChestitem() != null || npc.getLegsitem() != null || npc.getFeetitem() != null || npc.getHanditem() != null || npc.getOffhanditem() != null) {
            mob = mob + "  Equipment:\r\n";
            if (npc.getOffhanditem() != null)
                mob = mob + "  - " + npc.getOffhanditem() + ":5\r\n";
            if (npc.isCustomhead() == true) {
                if (npc.getCustomheaddata() != null) {
                    mob = mob + "  - CUSTOMHEADNPCID_" + npc.getId() + ":4\r\n";
                } else {
                    if (npc.getHeaditem() != null)
                        mob = mob + "  - " + npc.getHeaditem() + ":4\r\n";
                }
            } else {
                if (npc.getHeaditem() != null)
                    mob = mob + "  - " + npc.getHeaditem() + ":4\r\n";
            }
            if (npc.getChestitem() != null)
                mob = mob + "  - " + npc.getChestitem() + ":3\r\n";
            if (npc.getLegsitem() != null)
                mob = mob + "  - " + npc.getLegsitem() + ":2\r\n";
            if (npc.getFeetitem() != null)
                mob = mob + "  - " + npc.getFeetitem() + ":1\r\n";
            if (npc.getHanditem() != null)
                mob = mob + "  - " + npc.getHanditem() + ":0\r\n";
        }
    }
    if (npc.isUsedisguise() == true) {
        mob = mob + "  Disguise:\r\n";
        if (npc.getDisguisetype().toLowerCase().contains("player-")) {
            mob = mob + "    Type: player\r\n";
        } else {
            mob = mob + "    Type: " + npc.getDisguisetype() + "\r\n";
        }
        if (npc.isBurning() == true) {
            mob = mob + "    Burning: true\r\n";
        }
        if (npc.getDisguisetype().toLowerCase().contains("player-")) {
            String[] disguisedata = npc.getDisguisetype().split("-");
            mob = mob + "    Player: " + npc.getName() + "\r\n";
            mob = mob + "    Skin: '" + disguisedata[1] + "'\r\n";
        }
    }
    if (npc.isBoss() == true || npc.isRaidboss()) {
        /*
				mob = mob + "  BossBar:\r\n";
				mob = mob + "    Enabled: true\r\n";
				mob = mob + "    Title: " + npc.getName() + "\r\n";
				mob = mob + "    Range: 200\r\n";
				mob = mob + "    CreateFog: true\r\n";
				mob = mob + "    DarkenSky: true\r\n";
				mob = mob + "    PlayMusic: true\r\n";
			*/
        if (npc.getDisguisetype() != null)
            if (npc.getDisguisetype().toLowerCase().contains("player-")) {
                String[] disguisedata = npc.getDisguisetype().split("-");
                mob = mob + "    Player: " + npc.getName() + "\r\n";
                mob = mob + "    Skin: '" + disguisedata[1] + "'\r\n";
            }
    }
    mob = mob + "  Skills:\r\n";
    if (npc.isInvisible() == true) {
        mob = mob + "  - potion{t=INVISIBILITY;d=2147483647;l=1} @self ~onSpawn\r\n";
    }
    return mob;
}
Also used : ISoliniaItem(com.solinia.solinia.Interfaces.ISoliniaItem) ISoliniaLootTableEntry(com.solinia.solinia.Interfaces.ISoliniaLootTableEntry) ISoliniaFaction(com.solinia.solinia.Interfaces.ISoliniaFaction) ArrayList(java.util.ArrayList) ISoliniaLootTable(com.solinia.solinia.Interfaces.ISoliniaLootTable) ISoliniaLootDrop(com.solinia.solinia.Interfaces.ISoliniaLootDrop) ISoliniaLootDropEntry(com.solinia.solinia.Interfaces.ISoliniaLootDropEntry) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException)

Example 10 with ISoliniaItem

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

the class Solinia3CorePlayerListener method onPlayerSwapHandItems.

@EventHandler
public void onPlayerSwapHandItems(PlayerSwapHandItemsEvent event) {
    if (event.isCancelled())
        return;
    try {
        ItemStack itemstack = event.getOffHandItem();
        if (itemstack == null)
            return;
        if (Utils.IsSoliniaItem(itemstack) && !itemstack.getType().equals(Material.ENCHANTED_BOOK)) {
            ISoliniaPlayer solplayer = SoliniaPlayerAdapter.Adapt((Player) event.getPlayer());
            ISoliniaItem soliniaitem = StateManager.getInstance().getConfigurationManager().getItem(itemstack);
            if (soliniaitem.getAllowedClassNames().size() == 0)
                return;
            if (solplayer.getClassObj() == null) {
                Utils.CancelEvent(event);
                ;
                event.getPlayer().sendMessage(ChatColor.GRAY + "Your class cannot wear this armour");
                return;
            }
            if (!soliniaitem.getAllowedClassNames().contains(solplayer.getClassObj().getName().toUpperCase())) {
                Utils.CancelEvent(event);
                ;
                event.getPlayer().getPlayer().sendMessage(ChatColor.GRAY + "Your class cannot wear this armour");
                return;
            }
            if (soliniaitem.getMinLevel() > solplayer.getLevel()) {
                Utils.CancelEvent(event);
                ;
                event.getPlayer().getPlayer().sendMessage(ChatColor.GRAY + "Your are not sufficient level wear this armour");
                return;
            }
            solplayer.updateMaxHp();
        }
    } catch (CoreStateInitException e) {
    }
}
Also used : ISoliniaItem(com.solinia.solinia.Interfaces.ISoliniaItem) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) ItemStack(org.bukkit.inventory.ItemStack) 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