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;
}
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();
}
}
Aggregations