Bukkit.getScheduler().runTaskAsynchronously(CraftBookPlugin.inst(), new Runnable() {
@Override
public void run () {
Bukkit.getLogger().info("Starting Upload");
Wiki wiki = new Wiki("wiki.sk89q.com");
wiki.setMaxLag(0);
wiki.setThrottle(5000);
wiki.setResolveRedirects(true);
try {
Bukkit.getLogger().info("Logging In");
wiki.login(username, password);
Bukkit.getLogger().info("Logged in Successfully!");
int amount = 0;
String failed = "";
for(RegisteredICFactory ric : ICManager.inst().getICList()) {
if(toUpload.contains("ALL") || toUpload.contains(ric.getId())) {
if(missingDocuments.contains(ric.getId())) {
if(failed.length() == 0)
failed = ric.getId();
else
failed = failed + "," + ric.getId();
continue; //Ignore this, bad docs.
}
Bukkit.getLogger().info("Uploading " + ric.getId() + "...");
StringBuilder builder = new StringBuilder();
BufferedReader reader = new BufferedReader(new FileReader(new File(file, ric.getId() + ".txt")));
String line = null;
while((line = reader.readLine()) != null) {
builder.append(line);
builder.append("\n");
}
reader.close();
wiki.edit("CraftBook/" + ric.getId(), builder.toString(), "Automated update of '" + ric.getId() + "' by " + username);
Bukkit.getLogger().info("Uploaded: " + ric.getId());
amount++;
}