Search in sources :

Example 1 with InvalidNPCEventSettingException

use of com.solinia.solinia.Exceptions.InvalidNPCEventSettingException in project solinia3-core by mixxit.

the class SoliniaNPCEventHandler method editTriggerEventSetting.

@Override
public void editTriggerEventSetting(String setting, String value) throws InvalidNPCEventSettingException {
    switch(setting.toLowerCase()) {
        case "randomisedgearsuffix":
            setRandomisedGearSuffix(value);
            break;
        case "title":
            setTitle(value);
            break;
        case "awardstitle":
            setAwardsTitle(Boolean.parseBoolean(value));
            break;
        case "triggerdata":
            if (value.equals(""))
                throw new InvalidNPCEventSettingException("Triggerdata is empty");
            if (value.contains(" "))
                throw new InvalidNPCEventSettingException("Triggerdata can only be one value");
            setTriggerdata(value.toUpperCase());
            break;
        case "chatresponse":
            if (value.equals(""))
                throw new InvalidNPCEventSettingException("Chatresponse is empty");
            setChatresponse(value);
            break;
        case "requiresquest":
            int questid = Integer.parseInt(value);
            if (questid < 1)
                throw new InvalidNPCEventSettingException("Invalid quest id");
            try {
                ISoliniaQuest quest = StateManager.getInstance().getConfigurationManager().getQuest(questid);
                if (quest == null)
                    throw new InvalidNPCEventSettingException("Invalid quest id");
            } catch (CoreStateInitException e) {
                throw new InvalidNPCEventSettingException("State not initialised");
            }
            setRequiresQuest(questid);
            break;
        case "awardsquest":
            int aquestid = Integer.parseInt(value);
            if (aquestid < 1)
                throw new InvalidNPCEventSettingException("Invalid quest id");
            try {
                ISoliniaQuest quest = StateManager.getInstance().getConfigurationManager().getQuest(aquestid);
                if (quest == null)
                    throw new InvalidNPCEventSettingException("Invalid quest id");
            } catch (CoreStateInitException e) {
                throw new InvalidNPCEventSettingException("State not initialised");
            }
            setAwardsQuest(aquestid);
            break;
        case "requiresquestflag":
            setRequiresQuestFlag(value);
            break;
        case "awardsquestflag":
            setAwardsQuestFlag(value);
            break;
        case "teleportresponse":
            try {
                String[] zonedata = value.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]);
                setTeleportResponse(world + "," + x + "," + y + "," + z);
                break;
            } catch (Exception e) {
                throw new InvalidNPCEventSettingException("Teleport zone value must be in format: world,x,y,z");
            }
        case "awardsrandomisedgear":
            setAwardsRandomisedGear(Boolean.parseBoolean(value));
            break;
        case "awardsitem":
            int itemId = Integer.parseInt(value);
            if (itemId < 1)
                throw new InvalidNPCEventSettingException("Invalid item ID");
            if (getAwardsQuestFlag() == null || getAwardsQuestFlag().equals(""))
                throw new InvalidNPCEventSettingException("You cannot set an awardsitem to a npc event handler unless the npc awards a quest flag -  this is to prevent duplicated awards");
            try {
                ISoliniaItem item = StateManager.getInstance().getConfigurationManager().getItem(itemId);
                if (item == null)
                    throw new InvalidNPCEventSettingException("Invalid item id");
            } catch (CoreStateInitException e) {
                throw new InvalidNPCEventSettingException("State not initialised");
            }
            setAwardsItem(itemId);
            break;
        default:
            throw new InvalidNPCEventSettingException("Invalid NPC Event setting. Valid Options are: triggerdata,chatresponse,interactiontype,requiresquest,awardsquest,requiresquestflag,awardsquestflag,awardsitem");
    }
}
Also used : ISoliniaQuest(com.solinia.solinia.Interfaces.ISoliniaQuest) ISoliniaItem(com.solinia.solinia.Interfaces.ISoliniaItem) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) InvalidNPCEventSettingException(com.solinia.solinia.Exceptions.InvalidNPCEventSettingException) InvalidNPCEventSettingException(com.solinia.solinia.Exceptions.InvalidNPCEventSettingException) InvalidNpcSettingException(com.solinia.solinia.Exceptions.InvalidNpcSettingException) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) InvalidSpellSettingException(com.solinia.solinia.Exceptions.InvalidSpellSettingException) SoliniaItemException(com.solinia.solinia.Exceptions.SoliniaItemException)

Example 2 with InvalidNPCEventSettingException

use of com.solinia.solinia.Exceptions.InvalidNPCEventSettingException 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)

Aggregations

CoreStateInitException (com.solinia.solinia.Exceptions.CoreStateInitException)2 InvalidNPCEventSettingException (com.solinia.solinia.Exceptions.InvalidNPCEventSettingException)2 InvalidNpcSettingException (com.solinia.solinia.Exceptions.InvalidNpcSettingException)1 InvalidSpellSettingException (com.solinia.solinia.Exceptions.InvalidSpellSettingException)1 SoliniaItemException (com.solinia.solinia.Exceptions.SoliniaItemException)1 ISoliniaItem (com.solinia.solinia.Interfaces.ISoliniaItem)1 ISoliniaNPC (com.solinia.solinia.Interfaces.ISoliniaNPC)1 ISoliniaNPCEventHandler (com.solinia.solinia.Interfaces.ISoliniaNPCEventHandler)1 ISoliniaQuest (com.solinia.solinia.Interfaces.ISoliniaQuest)1 CommandSender (org.bukkit.command.CommandSender)1 ConsoleCommandSender (org.bukkit.command.ConsoleCommandSender)1 Player (org.bukkit.entity.Player)1