Search in sources :

Example 1 with SoliniaQuest

use of com.solinia.solinia.Models.SoliniaQuest 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 SoliniaQuest

use of com.solinia.solinia.Models.SoliniaQuest in project solinia3-core by mixxit.

the class JsonQuestRepository method commit.

@Override
public void commit() {
    // TODO Auto-generated method stub
    GsonBuilder gsonbuilder = new GsonBuilder();
    // gsonbuilder.setPrettyPrinting();
    Gson gson = gsonbuilder.create();
    String jsonOutput = gson.toJson(Quests.values(), new TypeToken<List<SoliniaQuest>>() {
    }.getType());
    try {
        File file = new File(filePath);
        if (!file.exists())
            file.createNewFile();
        FileOutputStream fileOut = new FileOutputStream(file);
        OutputStreamWriter outWriter = new OutputStreamWriter(fileOut);
        outWriter.append(jsonOutput);
        outWriter.close();
        fileOut.close();
        System.out.println("Commited " + Quests.size() + " Quests");
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : ISoliniaQuest(com.solinia.solinia.Interfaces.ISoliniaQuest) SoliniaQuest(com.solinia.solinia.Models.SoliniaQuest) GsonBuilder(com.google.gson.GsonBuilder) TypeToken(com.google.gson.reflect.TypeToken) FileOutputStream(java.io.FileOutputStream) FileNotFoundException(java.io.FileNotFoundException) Gson(com.google.gson.Gson) OutputStreamWriter(java.io.OutputStreamWriter) IOException(java.io.IOException) File(java.io.File)

Aggregations

ISoliniaQuest (com.solinia.solinia.Interfaces.ISoliniaQuest)2 SoliniaQuest (com.solinia.solinia.Models.SoliniaQuest)2 Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 TypeToken (com.google.gson.reflect.TypeToken)1 CoreStateInitException (com.solinia.solinia.Exceptions.CoreStateInitException)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 OutputStreamWriter (java.io.OutputStreamWriter)1 CommandSender (org.bukkit.command.CommandSender)1 ConsoleCommandSender (org.bukkit.command.ConsoleCommandSender)1 Player (org.bukkit.entity.Player)1