Search in sources :

Example 1 with ISoliniaQuest

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

the class CommandCreateQuest 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 < 1) {
        sender.sendMessage("Insufficient arguments: name");
        return false;
    }
    String questname = args[0];
    if (questname.equals("")) {
        sender.sendMessage("Invalid quest name");
        return false;
    }
    try {
        for (ISoliniaQuest quest : StateManager.getInstance().getConfigurationManager().getQuests()) {
            if (quest.getName().toUpperCase().equals(questname.toUpperCase())) {
                sender.sendMessage("That quest already exists");
                return false;
            }
        }
        SoliniaQuest quest = new SoliniaQuest();
        quest.setId(StateManager.getInstance().getConfigurationManager().getNextQuestId());
        quest.setName(questname);
        StateManager.getInstance().getConfigurationManager().addQuest(quest);
        sender.sendMessage("Quest created! [" + quest.getId() + "]");
    } catch (CoreStateInitException e) {
        sender.sendMessage(e.getMessage());
    }
    return true;
}
Also used : ISoliniaQuest(com.solinia.solinia.Interfaces.ISoliniaQuest) Player(org.bukkit.entity.Player) ISoliniaQuest(com.solinia.solinia.Interfaces.ISoliniaQuest) SoliniaQuest(com.solinia.solinia.Models.SoliniaQuest) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) CommandSender(org.bukkit.command.CommandSender) ConsoleCommandSender(org.bukkit.command.ConsoleCommandSender)

Example 2 with ISoliniaQuest

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

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

the class JsonQuestRepository method reload.

@Override
public void reload() {
    List<ISoliniaQuest> file = new ArrayList<ISoliniaQuest>();
    try {
        Gson gson = new Gson();
        BufferedReader br = new BufferedReader(new FileReader(filePath));
        file = gson.fromJson(br, new TypeToken<List<SoliniaQuest>>() {
        }.getType());
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
    Quests.clear();
    for (ISoliniaQuest i : file) {
        Quests.put(i.getId(), i);
    }
    System.out.println("Reloaded " + Quests.size() + " Quests");
}
Also used : ISoliniaQuest(com.solinia.solinia.Interfaces.ISoliniaQuest) ArrayList(java.util.ArrayList) BufferedReader(java.io.BufferedReader) FileNotFoundException(java.io.FileNotFoundException) Gson(com.google.gson.Gson) FileReader(java.io.FileReader) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

ISoliniaQuest (com.solinia.solinia.Interfaces.ISoliniaQuest)3 CoreStateInitException (com.solinia.solinia.Exceptions.CoreStateInitException)2 Gson (com.google.gson.Gson)1 InvalidNPCEventSettingException (com.solinia.solinia.Exceptions.InvalidNPCEventSettingException)1 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 SoliniaQuest (com.solinia.solinia.Models.SoliniaQuest)1 BufferedReader (java.io.BufferedReader)1 FileNotFoundException (java.io.FileNotFoundException)1 FileReader (java.io.FileReader)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 CommandSender (org.bukkit.command.CommandSender)1 ConsoleCommandSender (org.bukkit.command.ConsoleCommandSender)1 Player (org.bukkit.entity.Player)1