Search in sources :

Example 1 with ISoliniaNPC

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

the class CommandEditNpc method onCommand.

@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    if (!(sender instanceof Player) && !(sender instanceof CommandSender))
        return false;
    if (sender instanceof Player) {
        Player player = (Player) sender;
        if (!player.isOp() && !player.hasPermission("solinia.editnpc")) {
            player.sendMessage("You do not have permission to access this command");
            return false;
        }
    }
    if (args.length == 0) {
        return false;
    }
    int npcid = Integer.parseInt(args[0]);
    if (args.length == 1) {
        try {
            ISoliniaNPC npc = StateManager.getInstance().getConfigurationManager().getNPC(npcid);
            if (npc != null) {
                npc.sendNpcSettingsToSender(sender);
            } else {
                sender.sendMessage("NPC ID doesnt exist");
            }
            return true;
        } catch (CoreStateInitException e) {
            sender.sendMessage(e.getMessage());
        }
    }
    if (args.length < 3) {
        sender.sendMessage("Insufficient arguments: npcid setting value");
        return false;
    }
    String setting = args[1];
    String value = args[2];
    // for 'text' based npc settings like trigger texts etc, get the whole thing as a string
    if (args.length > 3 && (setting.toLowerCase().contains("text") || setting.toLowerCase().contains("title"))) {
        value = "";
        int current = 0;
        for (String entry : args) {
            current++;
            if (current <= 2)
                continue;
            value = value + entry + " ";
        }
        value = value.trim();
    }
    if (npcid < 1) {
        sender.sendMessage("Invalid npc id");
        return false;
    }
    try {
        if (StateManager.getInstance().getConfigurationManager().getNPC(npcid) == null) {
            sender.sendMessage("Cannot locate npc id: " + npcid);
            return false;
        }
        if (StateManager.getInstance().getConfigurationManager().getNPC(npcid).isOperatorCreated() && !sender.isOp()) {
            sender.sendMessage("This npc was op created and you are not an op. Only ops can edit op npcs");
            return false;
        }
        try {
            StateManager.getInstance().getConfigurationManager().editNPC(npcid, setting, value);
            sender.sendMessage("Updating setting on npc");
        } catch (java.io.IOException e) {
            sender.sendMessage("Failed to update NPC - If this was a request to change custom head data, the mojang servers may be unable to fetch the player skin, try the same command again in a few moments");
        }
    } catch (InvalidNpcSettingException ne) {
        sender.sendMessage("Invalid NPC setting: " + ne.getMessage());
    } catch (CoreStateInitException e) {
        // TODO Auto-generated catch block
        sender.sendMessage(e.getMessage());
    }
    return true;
}
Also used : Player(org.bukkit.entity.Player) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ISoliniaNPC(com.solinia.solinia.Interfaces.ISoliniaNPC) CommandSender(org.bukkit.command.CommandSender) ConsoleCommandSender(org.bukkit.command.ConsoleCommandSender) InvalidNpcSettingException(com.solinia.solinia.Exceptions.InvalidNpcSettingException)

Example 2 with ISoliniaNPC

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

the class CommandCreateNPCEvent method onCommand.

@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    if (!(sender instanceof Player) && !(sender instanceof CommandSender))
        return false;
    if (sender instanceof Player) {
        Player player = (Player) sender;
        if (!player.isOp()) {
            player.sendMessage("This is an operator only command");
            return false;
        }
    }
    if (args.length < 4) {
        sender.sendMessage("Insufficient arguments: npcid eventtype trigger response");
        return false;
    }
    String response = "";
    int counter = 0;
    for (String entry : args) {
        counter++;
        if (counter < 4)
            continue;
        response += entry + " ";
    }
    if (response.length() > 0) {
        response = response.trim();
    }
    if (response.equals("")) {
        sender.sendMessage("Blank responses not allowed when creating an npc event");
        return false;
    }
    Integer npcid = Integer.parseInt(args[0]);
    String eventtype = args[1];
    String trigger = args[2];
    if (npcid < 1) {
        sender.sendMessage("NPC does not exist");
        return false;
    }
    try {
        ISoliniaNPC npc = StateManager.getInstance().getConfigurationManager().getNPC(npcid);
        if (npc == null) {
            sender.sendMessage("NPC does not exist");
            return false;
        }
        boolean foundtype = false;
        InteractionType interactiontype = null;
        for (InteractionType type : InteractionType.values()) {
            if (!type.name().toUpperCase().equals(eventtype))
                continue;
            foundtype = true;
            interactiontype = type;
            break;
        }
        if (foundtype == false) {
            sender.sendMessage("Cannot find interaction type specified");
            return false;
        }
        if (trigger == null || trigger.equals("")) {
            sender.sendMessage("Trigger provided is empty");
            return false;
        }
        boolean exists = false;
        for (ISoliniaNPCEventHandler seek : npc.getEventHandlers()) {
            if (!seek.getInteractiontype().equals(interactiontype))
                continue;
            if (!seek.getTriggerdata().toUpperCase().equals(trigger))
                continue;
            exists = true;
        }
        if (exists) {
            sender.sendMessage("Event handler already exists");
            return false;
        }
        SoliniaNPCEventHandler eventhandler = new SoliniaNPCEventHandler();
        eventhandler.setNpcId(npc.getId());
        eventhandler.setInteractiontype(interactiontype);
        eventhandler.setTriggerdata(trigger.toUpperCase());
        eventhandler.setChatresponse(response);
        npc.addEventHandler(eventhandler);
        sender.sendMessage("New EventHandler added to NPC");
    } catch (CoreStateInitException e) {
        sender.sendMessage(e.getMessage());
    }
    return true;
}
Also used : InteractionType(com.solinia.solinia.Models.InteractionType) SoliniaNPCEventHandler(com.solinia.solinia.Models.SoliniaNPCEventHandler) ISoliniaNPCEventHandler(com.solinia.solinia.Interfaces.ISoliniaNPCEventHandler) Player(org.bukkit.entity.Player) ISoliniaNPCEventHandler(com.solinia.solinia.Interfaces.ISoliniaNPCEventHandler) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ISoliniaNPC(com.solinia.solinia.Interfaces.ISoliniaNPC) CommandSender(org.bukkit.command.CommandSender) ConsoleCommandSender(org.bukkit.command.ConsoleCommandSender)

Example 3 with ISoliniaNPC

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

the class CommandCreateNpcCopy method onCommand.

@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    if (!(sender instanceof Player) && !(sender instanceof CommandSender))
        return false;
    if (sender instanceof Player) {
        Player player = (Player) sender;
        if (!player.isOp() && !player.hasPermission("solinia.createnpccopy")) {
            player.sendMessage("You do not have permission to access this command");
            return false;
        }
    }
    if (args.length < 2) {
        sender.sendMessage("Insufficient arguments: sourcenpcid npcname");
        return false;
    }
    int npcid = Integer.parseInt(args[0]);
    if (npcid < 1) {
        sender.sendMessage("Invalid npc id");
        return false;
    }
    try {
        if (StateManager.getInstance().getConfigurationManager().getNPC(npcid) == null) {
            sender.sendMessage("Cannot locate npc id: " + npcid);
            return false;
        }
        String name = "";
        int i = 0;
        for (String element : args) {
            if (i <= 0) {
                i++;
                continue;
            }
            name += element;
            i++;
        }
        if (name.equals("")) {
            sender.sendMessage("Name of NPC cannot be null");
            return false;
        }
        if (name.length() > 16) {
            sender.sendMessage("Name of NPC cannot exceed 16 characters");
            return false;
        }
        name = name.replace(" ", "_");
        ISoliniaNPC npc = SoliniaNPCFactory.CreateNPCCopy(npcid, name, sender.isOp());
        sender.sendMessage("Created NPC Copy: " + npc.getId());
    } catch (CoreStateInitException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        sender.sendMessage(e.getMessage());
    }
    return true;
}
Also used : Player(org.bukkit.entity.Player) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ISoliniaNPC(com.solinia.solinia.Interfaces.ISoliniaNPC) CommandSender(org.bukkit.command.CommandSender) ConsoleCommandSender(org.bukkit.command.ConsoleCommandSender)

Example 4 with ISoliniaNPC

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

the class Solinia3CoreEntityListener method onEntityDeath.

@EventHandler
public void onEntityDeath(EntityDeathEvent event) {
    if ((event.getEntity() instanceof ArmorStand)) {
        return;
    }
    if (!(event.getEntity() instanceof LivingEntity))
        return;
    if (event.getEntity() instanceof Player)
        return;
    if (!(event.getEntity().getLastDamageCause() instanceof EntityDamageByEntityEvent))
        return;
    if (event.getEntity() instanceof Animals && !Utils.isLivingEntityNPC((LivingEntity) event.getEntity()))
        return;
    EntityDamageByEntityEvent entitykiller = (EntityDamageByEntityEvent) event.getEntity().getLastDamageCause();
    Entity damager = entitykiller.getDamager();
    if (damager instanceof Projectile) {
        Projectile projectile = (Projectile) damager;
        damager = (Entity) projectile.getShooter();
    }
    if (!(damager instanceof LivingEntity))
        return;
    ISoliniaLivingEntity soldamagerentity = null;
    try {
        soldamagerentity = SoliniaLivingEntityAdapter.Adapt((LivingEntity) damager);
    } catch (CoreStateInitException e) {
    }
    // something
    if ((!(damager instanceof Player)) && Utils.isLivingEntityNPC((LivingEntity) damager)) {
        soldamagerentity.doSlayChat();
    }
    if (!(damager instanceof Player) && !soldamagerentity.isPet())
        return;
    try {
        ISoliniaLivingEntity livingEntity = SoliniaLivingEntityAdapter.Adapt(event.getEntity());
        ISoliniaPlayer player = null;
        if (damager instanceof Player) {
            player = SoliniaPlayerAdapter.Adapt((Player) damager);
        }
        if (soldamagerentity.isPet()) {
            if (damager instanceof Wolf) {
                Wolf w = (Wolf) damager;
                player = SoliniaPlayerAdapter.Adapt((Player) w.getOwner());
            }
        }
        if (player == null) {
            return;
        }
        Double experience = Utils.getExperienceRewardAverageForLevel(livingEntity.getLevel());
        // try to share with group
        ISoliniaGroup group = StateManager.getInstance().getGroupByMember(player.getUUID());
        if (group != null) {
            Integer dhighestlevel = 0;
            List<Integer> levelranges = new ArrayList<Integer>();
            for (UUID member : group.getMembers()) {
                ISoliniaPlayer playerchecked = SoliniaPlayerAdapter.Adapt(Bukkit.getPlayer(member));
                int checkedlevel = playerchecked.getLevel();
                levelranges.add(checkedlevel);
            }
            Collections.sort(levelranges);
            // get the highest person in the group
            dhighestlevel = levelranges.get(levelranges.size() - 1);
            int ihighlvl = (int) Math.floor(dhighestlevel);
            int ilowlvl = ihighlvl - 7;
            if (ilowlvl < 1) {
                ilowlvl = 1;
            }
            if (player.getLevel() < ilowlvl) {
                // as they are out of range of the group
                if (livingEntity.getLevel() >= player.getLevel() - 7) {
                    player.increasePlayerExperience(experience);
                    // Grant title for killing mob
                    if (livingEntity.getNpcid() > 0) {
                        ISoliniaNPC npc = StateManager.getInstance().getConfigurationManager().getNPC(livingEntity.getNpcid());
                        if (npc != null && !npc.getDeathGrantsTitle().equals("")) {
                            player.grantTitle(npc.getDeathGrantsTitle());
                        }
                        if (npc.isBoss() || npc.isRaidboss()) {
                            player.grantTitle("the Vanquisher");
                        }
                    }
                } else {
                    player.getBukkitPlayer().sendMessage(ChatColor.GRAY + "* The npc was too low level to gain experience from");
                }
            } else {
                for (UUID member : group.getMembers()) {
                    Player tgtplayer = Bukkit.getPlayer(member);
                    if (tgtplayer != null) {
                        ISoliniaPlayer tgtsolplayer = SoliniaPlayerAdapter.Adapt(tgtplayer);
                        int tgtlevel = tgtsolplayer.getLevel();
                        if (tgtlevel < ilowlvl) {
                            tgtplayer.sendMessage("You were out of level range to gain experience in this group (Min: " + ilowlvl + " Max: " + ihighlvl + ")");
                            continue;
                        }
                        if (!tgtplayer.getWorld().equals(player.getBukkitPlayer().getWorld())) {
                            tgtplayer.sendMessage("You were out of range for shared group xp (world)");
                            continue;
                        }
                        if (tgtplayer.getLocation().distance(player.getBukkitPlayer().getLocation()) <= 100) {
                            if (livingEntity.getLevel() >= (tgtsolplayer.getLevel() - 7)) {
                                tgtsolplayer.increasePlayerExperience(experience);
                                // Grant title for killing mob
                                if (livingEntity.getNpcid() > 0) {
                                    ISoliniaNPC npc = StateManager.getInstance().getConfigurationManager().getNPC(livingEntity.getNpcid());
                                    if (npc != null && !npc.getDeathGrantsTitle().equals("")) {
                                        tgtsolplayer.grantTitle(npc.getDeathGrantsTitle());
                                    }
                                    if (npc.isBoss() || npc.isRaidboss()) {
                                        tgtsolplayer.grantTitle("the Vanquisher");
                                    }
                                }
                            } else {
                                tgtplayer.sendMessage(ChatColor.GRAY + "* The npc was too low level to gain experience from");
                            }
                        } else {
                            tgtplayer.sendMessage("You were out of range for shared group xp (distance)");
                            continue;
                        }
                    }
                }
            }
        } else {
            if (livingEntity.getLevel() >= (player.getLevel() - 7)) {
                player.increasePlayerExperience(experience);
                // Grant title for killing mob
                if (livingEntity.getNpcid() > 0) {
                    ISoliniaNPC npc = StateManager.getInstance().getConfigurationManager().getNPC(livingEntity.getNpcid());
                    if (npc != null && !npc.getDeathGrantsTitle().equals("")) {
                        player.grantTitle(npc.getDeathGrantsTitle());
                    }
                    if (npc.isBoss() || npc.isRaidboss()) {
                        player.grantTitle("the Vanquisher");
                    }
                }
            } else {
                player.getBukkitPlayer().sendMessage(ChatColor.GRAY + "* The npc was too low level to gain experience from");
            }
        }
        if (livingEntity.getNpcid() > 0) {
            ISoliniaNPC npc = StateManager.getInstance().getConfigurationManager().getNPC(livingEntity.getNpcid());
            if (npc.getFactionid() > 0) {
                ISoliniaFaction faction = StateManager.getInstance().getConfigurationManager().getFaction(npc.getFactionid());
                player.decreaseFactionStanding(npc.getFactionid(), 50);
                for (FactionStandingEntry factionEntry : faction.getFactionEntries()) {
                    if (factionEntry.getValue() >= 1500) {
                        // If this is an ally of the faction, grant negative faction
                        player.decreaseFactionStanding(factionEntry.getFactionId(), 10);
                    }
                    if (factionEntry.getValue() <= -1500) {
                        // If this is an enemy of the faction, grant positive faction
                        player.increaseFactionStanding(factionEntry.getFactionId(), 1);
                    }
                }
            }
        }
        if (livingEntity.getNpcid() > 0) {
            ISoliniaNPC npc = StateManager.getInstance().getConfigurationManager().getNPC(livingEntity.getNpcid());
            if (npc != null && !npc.getDeathGrantsTitle().equals("")) {
                player.grantTitle(npc.getDeathGrantsTitle());
            }
            if (npc.isBoss() || npc.isRaidboss()) {
                player.grantTitle("the Vanquisher");
            }
            if (npc.isBoss() || npc.isRaidboss()) {
                Bukkit.broadcastMessage(ChatColor.RED + "[VICTORY] The foundations of the earth shake following the destruction of " + npc.getName() + " at the hands of " + player.getFullNameWithTitle() + "!" + ChatColor.RESET);
            }
        }
        player.giveMoney(1);
        livingEntity.dropLoot();
    } catch (CoreStateInitException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : 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) ISoliniaGroup(com.solinia.solinia.Interfaces.ISoliniaGroup) FactionStandingEntry(com.solinia.solinia.Models.FactionStandingEntry) ISoliniaFaction(com.solinia.solinia.Interfaces.ISoliniaFaction) ArrayList(java.util.ArrayList) Projectile(org.bukkit.entity.Projectile) ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) LivingEntity(org.bukkit.entity.LivingEntity) Animals(org.bukkit.entity.Animals) ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) ArmorStand(org.bukkit.entity.ArmorStand) EntityDamageByEntityEvent(org.bukkit.event.entity.EntityDamageByEntityEvent) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ISoliniaNPC(com.solinia.solinia.Interfaces.ISoliniaNPC) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) Wolf(org.bukkit.entity.Wolf) UUID(java.util.UUID) EventHandler(org.bukkit.event.EventHandler)

Example 5 with ISoliniaNPC

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

the class SoliniaNPCFactory method CreateNPCCopy.

public static ISoliniaNPC CreateNPCCopy(int npcid, String name, boolean operatorCreated) throws CoreStateInitException {
    ISoliniaNPC sourcenpc = StateManager.getInstance().getConfigurationManager().getNPC(npcid);
    SoliniaNPC npc = new SoliniaNPC();
    npc.setId(StateManager.getInstance().getConfigurationManager().getNextNPCId());
    npc.setName(name);
    npc.setBoss(sourcenpc.isBoss());
    npc.setRaidboss(sourcenpc.isRaidboss());
    npc.setRaidheroic(sourcenpc.isRaidheroic());
    npc.setAC(sourcenpc.getAC());
    npc.setAccuracyRating(sourcenpc.getAccuracyRating());
    npc.setAvoidanceRating(sourcenpc.getAvoidanceRating());
    npc.setAnimal(sourcenpc.isAnimal());
    npc.setUndead(sourcenpc.isUndead());
    npc.setClassid(sourcenpc.getClassid());
    npc.setRaceid(sourcenpc.getRaceid());
    npc.setHeroic(sourcenpc.isHeroic());
    npc.setBurning(sourcenpc.isBurning());
    npc.setChestitem(sourcenpc.getChestitem());
    npc.setClassid(sourcenpc.getClassid());
    npc.setCustomhead(sourcenpc.isCustomhead());
    npc.setCustomheaddata(sourcenpc.getCustomheaddata());
    npc.setDisguisetype(sourcenpc.getDisguisetype());
    npc.setFactionid(sourcenpc.getFactionid());
    npc.setFeetitem(sourcenpc.getFeetitem());
    npc.setGuard(sourcenpc.isGuard());
    npc.setHanditem(sourcenpc.getHanditem());
    npc.setHeaditem(sourcenpc.getHeaditem());
    npc.setInvisible(sourcenpc.isInvisible());
    npc.setKillTriggerText(sourcenpc.getKillTriggerText());
    npc.setLegsitem(sourcenpc.getLegsitem());
    npc.setLevel(sourcenpc.getLevel());
    npc.setLoottableid(sourcenpc.getLoottableid());
    npc.setMctype(sourcenpc.getMctype());
    npc.setMerchantid(sourcenpc.getMerchantid());
    npc.setOffhanditem(sourcenpc.getOffhanditem());
    npc.setRaceid(sourcenpc.getRaceid());
    npc.setRandomchatTriggerText(sourcenpc.getRandomchatTriggerText());
    npc.setRandomSpawn(sourcenpc.isRandomSpawn());
    npc.setRoamer(sourcenpc.isRoamer());
    npc.setUpsidedown(sourcenpc.isUpsidedown());
    npc.setUsedisguise(sourcenpc.isUsedisguise());
    npc.setOperatorCreated(operatorCreated);
    return StateManager.getInstance().getConfigurationManager().addNPC(npc);
}
Also used : ISoliniaNPC(com.solinia.solinia.Interfaces.ISoliniaNPC) ISoliniaNPC(com.solinia.solinia.Interfaces.ISoliniaNPC) SoliniaNPC(com.solinia.solinia.Models.SoliniaNPC)

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