Search in sources :

Example 6 with ISoliniaNPC

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

the class Utils method patchNpcClasses.

private static void patchNpcClasses() {
    try {
        for (ISoliniaPatch patch : StateManager.getInstance().getConfigurationManager().getPatches()) {
            // Lookup npc and edit class
            String npcName = patch.getClasses().get(0);
            int rawClassId = Integer.parseInt(patch.getClasses().get(1));
            int convertedClass = convertRawClassToClass(rawClassId);
            ISoliniaNPC npc = StateManager.getInstance().getConfigurationManager().getPetNPCByName(npcName);
            if (npc == null)
                continue;
            npc.setClassid(convertedClass);
            System.out.println("Updated NPC: " + npc.getName() + " to class " + convertedClass);
        }
    } catch (CoreStateInitException e) {
    // skip
    }
}
Also used : ISoliniaPatch(com.solinia.solinia.Interfaces.ISoliniaPatch) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ISoliniaNPC(com.solinia.solinia.Interfaces.ISoliniaNPC)

Example 7 with ISoliniaNPC

use of com.solinia.solinia.Interfaces.ISoliniaNPC 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 8 with ISoliniaNPC

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

the class EntityManager method SpawnPet.

@Override
public LivingEntity SpawnPet(Plugin plugin, Player owner, ISoliniaSpell spell) {
    try {
        LivingEntity pet = StateManager.getInstance().getEntityManager().getPet(owner);
        if (pet != null) {
            StateManager.getInstance().getEntityManager().killPet(owner);
        }
        ISoliniaNPC npc = StateManager.getInstance().getConfigurationManager().getPetNPCByName(spell.getTeleportZone());
        if (npc == null)
            return null;
        if (npc.isPet() == false)
            return null;
        Wolf entity = (Wolf) owner.getWorld().spawnEntity(owner.getLocation(), EntityType.WOLF);
        entity.setMetadata("npcid", new FixedMetadataValue(plugin, "NPCID_" + npc.getId()));
        StateManager.getInstance().getEntityManager().setPet(owner, entity);
        entity.setAdult();
        entity.setTamed(true);
        entity.setOwner(owner);
        entity.setBreed(false);
        ISoliniaPlayer solplayer = SoliniaPlayerAdapter.Adapt(owner);
        entity.setCustomName(solplayer.getForename() + "'s Pet");
        entity.setCustomNameVisible(true);
        entity.setCanPickupItems(false);
        ISoliniaLivingEntity solentity = SoliniaLivingEntityAdapter.Adapt(entity);
        solentity.configurePetGoals();
        entity.setMaxHealth(solentity.getMaxHP());
        entity.setHealth(solentity.getMaxHP());
        net.minecraft.server.v1_12_R1.EntityInsentient entityhandle = (net.minecraft.server.v1_12_R1.EntityInsentient) ((org.bukkit.craftbukkit.v1_12_R1.entity.CraftLivingEntity) entity).getHandle();
        entityhandle.getAttributeInstance(GenericAttributes.ATTACK_DAMAGE).setValue((double) solentity.getMaxDamage());
        owner.sendMessage("New Pet spawned with HP: " + entity.getMaxHealth() + " and " + solentity.getMaxDamage() + " dmg");
        MobDisguise mob = new MobDisguise(DisguiseType.WOLF);
        switch(npc.getMctype().toUpperCase()) {
            case "WOLF":
                mob = new MobDisguise(DisguiseType.WOLF);
                break;
            case "SQUID":
                mob = new MobDisguise(DisguiseType.SQUID);
                break;
            case "PARROT":
                mob = new MobDisguise(DisguiseType.PARROT);
                break;
            case "SKELETON":
                mob = new MobDisguise(DisguiseType.SKELETON);
                break;
            case "BLAZE":
                mob = new MobDisguise(DisguiseType.BLAZE);
                break;
            case "IRON_GOLEM":
                mob = new MobDisguise(DisguiseType.IRON_GOLEM);
                break;
            case "GUARDIAN":
                mob = new MobDisguise(DisguiseType.GUARDIAN);
                break;
            default:
                mob = new MobDisguise(DisguiseType.WOLF);
                break;
        }
        DisguiseAPI.disguiseEntity(entity, mob);
        solentity.configurePetGoals();
        return entity;
    } catch (CoreStateInitException e) {
        return null;
    }
}
Also used : FixedMetadataValue(org.bukkit.metadata.FixedMetadataValue) MobDisguise(me.libraryaddict.disguise.disguisetypes.MobDisguise) ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) LivingEntity(org.bukkit.entity.LivingEntity) SoliniaLivingEntity(com.solinia.solinia.Models.SoliniaLivingEntity) ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ISoliniaNPC(com.solinia.solinia.Interfaces.ISoliniaNPC) Wolf(org.bukkit.entity.Wolf) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer)

Example 9 with ISoliniaNPC

use of com.solinia.solinia.Interfaces.ISoliniaNPC 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 10 with ISoliniaNPC

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

the class SoliniaNPC method processChatInteractionEvent.

@Override
public void processChatInteractionEvent(SoliniaLivingEntity solentity, LivingEntity triggerentity, String data) {
    String[] words = data.split(" ");
    // Merchant special commands
    if (words.length > 0) {
        // Check player has sufficient faction
        if (triggerentity instanceof Player)
            if (solentity.getNpcid() > 0) {
                try {
                    ISoliniaNPC npc = StateManager.getInstance().getConfigurationManager().getNPC(solentity.getNpcid());
                    if (npc.getFactionid() > 0) {
                        ISoliniaPlayer solPlayer = SoliniaPlayerAdapter.Adapt((Player) triggerentity);
                        PlayerFactionEntry factionEntry = solPlayer.getFactionEntry(npc.getFactionid());
                        if (factionEntry != null) {
                            switch(Utils.getFactionStandingType(factionEntry.getFactionId(), factionEntry.getValue())) {
                                case FACTION_THREATENLY:
                                case FACTION_SCOWLS:
                                    solentity.emote("* " + npc.getName() + " scowls angrily at " + solPlayer.getFullName());
                                    return;
                                default:
                                    break;
                            }
                        }
                    }
                } catch (CoreStateInitException e) {
                }
            }
        switch(words[0].toUpperCase()) {
            case "SHOP":
                if (triggerentity instanceof Player)
                    if (getMerchantid() > 0) {
                        if (words.length == 1) {
                            sendMerchantItemListToPlayer((Player) triggerentity, 1);
                            return;
                        }
                        int page = 1;
                        try {
                            page = Integer.parseInt(words[1]);
                        } catch (Exception e) {
                        }
                        if (page < 1)
                            page = 1;
                        sendMerchantItemListToPlayer((Player) triggerentity, page);
                    }
                return;
            case "LISTEFFECTS":
                if (triggerentity instanceof Player) {
                    if (((Player) triggerentity).isOp()) {
                        Player player = (Player) triggerentity;
                        try {
                            for (SoliniaActiveSpell spell : StateManager.getInstance().getEntityManager().getActiveEntitySpells(solentity.getBukkitLivingEntity()).getActiveSpells()) {
                                player.sendMessage(spell.getSpell().getName());
                                for (ActiveSpellEffect effect : spell.getActiveSpellEffects()) {
                                    player.sendMessage(" - " + effect.getSpellEffectType().name() + " " + effect.getBase());
                                }
                            }
                        } catch (CoreStateInitException e) {
                        // 
                        }
                    }
                }
                return;
            default:
                break;
        }
    }
    // Normal text matching
    for (ISoliniaNPCEventHandler handler : getEventHandlers()) {
        if (!handler.getInteractiontype().equals(InteractionType.CHAT))
            continue;
        if (!data.toUpperCase().contains(handler.getTriggerdata().toUpperCase()))
            continue;
        if (handler.getChatresponse() != null && !handler.getChatresponse().equals("")) {
            if ((triggerentity instanceof Player)) {
                if (!handler.playerMeetsRequirements((Player) triggerentity))
                    return;
            }
            String response = handler.getChatresponse();
            solentity.say(replaceChatWordsWithHints(response), triggerentity);
            if (triggerentity instanceof Player)
                handler.awardPlayer((Player) triggerentity);
            if (handler.getTeleportResponse() != null && !handler.getTeleportResponse().equals("")) {
                if (triggerentity instanceof Player) {
                    String[] zonedata = handler.getTeleportResponse().split(",");
                    // Dissasemble the value to ensure it is correct
                    String world = zonedata[0];
                    double x = Double.parseDouble(zonedata[1]);
                    double y = Double.parseDouble(zonedata[2]);
                    double z = Double.parseDouble(zonedata[3]);
                    Location loc = new Location(Bukkit.getWorld(world), x, y, z);
                    ((Player) triggerentity).teleport(loc);
                }
            }
        }
    }
    return;
}
Also used : Player(org.bukkit.entity.Player) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) ISoliniaNPCEventHandler(com.solinia.solinia.Interfaces.ISoliniaNPCEventHandler) InvalidNPCEventSettingException(com.solinia.solinia.Exceptions.InvalidNPCEventSettingException) InvalidNpcSettingException(com.solinia.solinia.Exceptions.InvalidNpcSettingException) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ISoliniaNPC(com.solinia.solinia.Interfaces.ISoliniaNPC) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) Location(org.bukkit.Location)

Aggregations

ISoliniaNPC (com.solinia.solinia.Interfaces.ISoliniaNPC)50 CoreStateInitException (com.solinia.solinia.Exceptions.CoreStateInitException)43 ISoliniaPlayer (com.solinia.solinia.Interfaces.ISoliniaPlayer)19 Player (org.bukkit.entity.Player)16 ISoliniaItem (com.solinia.solinia.Interfaces.ISoliniaItem)7 ISoliniaLivingEntity (com.solinia.solinia.Interfaces.ISoliniaLivingEntity)7 CommandSender (org.bukkit.command.CommandSender)6 ConsoleCommandSender (org.bukkit.command.ConsoleCommandSender)6 LivingEntity (org.bukkit.entity.LivingEntity)6 ISoliniaNPCEventHandler (com.solinia.solinia.Interfaces.ISoliniaNPCEventHandler)5 ArrayList (java.util.ArrayList)5 InvalidNpcSettingException (com.solinia.solinia.Exceptions.InvalidNpcSettingException)4 Entity (org.bukkit.entity.Entity)4 ISoliniaFaction (com.solinia.solinia.Interfaces.ISoliniaFaction)3 ItemStack (org.bukkit.inventory.ItemStack)3 InvalidNPCEventSettingException (com.solinia.solinia.Exceptions.InvalidNPCEventSettingException)2 SoliniaItemException (com.solinia.solinia.Exceptions.SoliniaItemException)2 ISoliniaLootTable (com.solinia.solinia.Interfaces.ISoliniaLootTable)2 SoliniaNPC (com.solinia.solinia.Models.SoliniaNPC)2 SoliniaNPCEventHandler (com.solinia.solinia.Models.SoliniaNPCEventHandler)2