Search in sources :

Example 1 with ISoliniaNPCEventHandler

use of com.solinia.solinia.Interfaces.ISoliniaNPCEventHandler 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 2 with ISoliniaNPCEventHandler

use of com.solinia.solinia.Interfaces.ISoliniaNPCEventHandler 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 3 with ISoliniaNPCEventHandler

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

Example 4 with ISoliniaNPCEventHandler

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

the class CommandEditNpcEvent 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 == 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.sendNPCEvents(sender);
            } else {
                sender.sendMessage("NPC ID doesnt exist");
            }
            return true;
        } catch (CoreStateInitException e) {
            sender.sendMessage(e.getMessage());
        }
    }
    String triggertext = args[1];
    if (args.length == 2) {
        try {
            ISoliniaNPC npc = StateManager.getInstance().getConfigurationManager().getNPC(npcid);
            if (npc != null) {
                boolean found = false;
                for (ISoliniaNPCEventHandler handler : npc.getEventHandlers()) {
                    if (handler.getTriggerdata().toUpperCase().equals(triggertext.toUpperCase())) {
                        found = true;
                        npc.sendNPCEvent(sender, triggertext);
                    }
                }
                if (found == false) {
                    sender.sendMessage("Trigger event doesnt exist on npc");
                }
            } else {
                sender.sendMessage("NPC ID doesnt exist");
            }
            return true;
        } catch (CoreStateInitException e) {
            sender.sendMessage(e.getMessage());
        }
    }
    if (args.length < 4) {
        sender.sendMessage("Insufficient arguments: npcid triggertext setting value");
        return false;
    }
    String setting = args[2];
    String value = args[3];
    // for 'text' based npc settings like trigger texts etc, get the whole thing as a string
    if (args.length > 4 && (setting.toLowerCase().equals("chatresponse") || setting.toLowerCase().equals("title") || setting.toLowerCase().equals("randomisedgearsuffix"))) {
        value = "";
        int current = 0;
        for (String entry : args) {
            current++;
            if (current <= 3)
                continue;
            value = value + entry + " ";
        }
        value = value.trim();
    }
    if (npcid < 1) {
        sender.sendMessage("Invalid NPC id");
        return false;
    }
    try {
        ISoliniaNPC npc = StateManager.getInstance().getConfigurationManager().getNPC(npcid);
        if (npc != null) {
            boolean found = false;
            for (ISoliniaNPCEventHandler handler : npc.getEventHandlers()) {
                if (handler.getTriggerdata().toUpperCase().equals(triggertext.toUpperCase())) {
                    found = true;
                }
            }
            if (found == false) {
                sender.sendMessage("Trigger event doesnt exist on npc");
                return false;
            }
        } else {
            sender.sendMessage("NPC ID doesnt exist");
            return false;
        }
        StateManager.getInstance().getConfigurationManager().editNpcTriggerEvent(npcid, triggertext, setting, value);
        sender.sendMessage("Updating setting on NPC Event");
    } catch (InvalidNPCEventSettingException ne) {
        sender.sendMessage("Invalid NPC Event Setting: " + ne.getMessage());
    } catch (CoreStateInitException e) {
        // TODO Auto-generated catch block
        sender.sendMessage(e.getMessage());
    }
    return true;
}
Also used : 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) InvalidNPCEventSettingException(com.solinia.solinia.Exceptions.InvalidNPCEventSettingException)

Example 5 with ISoliniaNPCEventHandler

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

the class SoliniaNPC method replaceChatWordsWithHints.

@Override
public String replaceChatWordsWithHints(String message) {
    List<String> messages = Arrays.asList(message.toUpperCase().split(" "));
    if (getEventHandlers().size() > 0) {
        String searchlist = "";
        for (String messageword : messages) {
            searchlist += messageword + ",";
        }
    }
    for (ISoliniaNPCEventHandler handler : getEventHandlers()) {
        if (!handler.getInteractiontype().equals(InteractionType.CHAT))
            continue;
        if (!messages.contains(handler.getTriggerdata().toUpperCase()))
            continue;
        message = message.toLowerCase().replace(handler.getTriggerdata().toLowerCase(), "[" + handler.getTriggerdata().toLowerCase() + "]");
    }
    message = message.replace("[", "[" + ChatColor.LIGHT_PURPLE);
    message = message.replace("]", ChatColor.AQUA + "]");
    return message.toLowerCase();
}
Also used : ISoliniaNPCEventHandler(com.solinia.solinia.Interfaces.ISoliniaNPCEventHandler)

Aggregations

ISoliniaNPCEventHandler (com.solinia.solinia.Interfaces.ISoliniaNPCEventHandler)7 CoreStateInitException (com.solinia.solinia.Exceptions.CoreStateInitException)5 ISoliniaNPC (com.solinia.solinia.Interfaces.ISoliniaNPC)5 Player (org.bukkit.entity.Player)4 InvalidNPCEventSettingException (com.solinia.solinia.Exceptions.InvalidNPCEventSettingException)2 ISoliniaItem (com.solinia.solinia.Interfaces.ISoliniaItem)2 ISoliniaLivingEntity (com.solinia.solinia.Interfaces.ISoliniaLivingEntity)2 ISoliniaPlayer (com.solinia.solinia.Interfaces.ISoliniaPlayer)2 SoliniaNPCEventHandler (com.solinia.solinia.Models.SoliniaNPCEventHandler)2 CommandSender (org.bukkit.command.CommandSender)2 ConsoleCommandSender (org.bukkit.command.ConsoleCommandSender)2 Entity (org.bukkit.entity.Entity)2 LivingEntity (org.bukkit.entity.LivingEntity)2 Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 InvalidNpcSettingException (com.solinia.solinia.Exceptions.InvalidNpcSettingException)1 ISoliniaNPCEventHandlerTypeAdapterFactory (com.solinia.solinia.Factories.ISoliniaNPCEventHandlerTypeAdapterFactory)1 InteractionType (com.solinia.solinia.Models.InteractionType)1 BufferedReader (java.io.BufferedReader)1 FileNotFoundException (java.io.FileNotFoundException)1