Use EH pastebin and remove debug code.

This commit is contained in:
sk89q 2015-01-12 22:19:49 -08:00
parent d9e4b27cd2
commit 477f1188df
3 changed files with 82 additions and 17 deletions

View File

@ -27,7 +27,7 @@
import com.sk89q.worldguard.bukkit.WorldGuardPlugin; import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.bukkit.util.logging.LoggerToChatHandler; import com.sk89q.worldguard.bukkit.util.logging.LoggerToChatHandler;
import com.sk89q.worldguard.bukkit.util.report.*; import com.sk89q.worldguard.bukkit.util.report.*;
import com.sk89q.worldguard.util.paste.Pastebin; import com.sk89q.worldguard.util.paste.EngineHubPaste;
import com.sk89q.worldguard.util.report.ReportList; import com.sk89q.worldguard.util.report.ReportList;
import com.sk89q.worldguard.util.report.SystemInfoReport; import com.sk89q.worldguard.util.report.SystemInfoReport;
import com.sk89q.worldguard.util.task.Task; import com.sk89q.worldguard.util.task.Task;
@ -131,10 +131,10 @@ public void report(CommandContext args, final CommandSender sender) throws Comma
sender.sendMessage(ChatColor.YELLOW + "Now uploading to Pastebin..."); sender.sendMessage(ChatColor.YELLOW + "Now uploading to Pastebin...");
Futures.addCallback(new Pastebin().paste(result), new FutureCallback<URL>() { Futures.addCallback(new EngineHubPaste().paste(result), new FutureCallback<URL>() {
@Override @Override
public void onSuccess(URL url) { public void onSuccess(URL url) {
sender.sendMessage(ChatColor.YELLOW + "WorldGuard report: " + url); sender.sendMessage(ChatColor.YELLOW + "WorldGuard report: " + url + ".report");
} }
@Override @Override

View File

@ -0,0 +1,79 @@
/*
* WorldGuard, a suite of tools for Minecraft
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldGuard team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldguard.util.paste;
import com.google.common.util.concurrent.ListenableFuture;
import com.sk89q.worldguard.util.net.HttpRequest;
import com.sk89q.worldguard.util.net.HttpRequest.Form;
import org.json.simple.JSONValue;
import java.io.IOException;
import java.net.URL;
import java.util.Map;
import java.util.concurrent.Callable;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class EngineHubPaste implements Paster {
private static final Pattern URL_PATTERN = Pattern.compile("https?://.+$");
@Override
public ListenableFuture<URL> paste(String content) {
return Pasters.getExecutor().submit(new PasteTask(content));
}
private final class PasteTask implements Callable<URL> {
private final String content;
private PasteTask(String content) {
this.content = content;
}
@Override
public URL call() throws IOException, InterruptedException {
Form form = Form.create();
form.add("content", content);
form.add("from", "worldguard");
URL url = HttpRequest.url("http://paste.enginehub.org/paste");
String result = HttpRequest.post(url)
.bodyForm(form)
.execute()
.expectResponseCode(200)
.returnContent()
.asString("UTF-8").trim();
Object object = JSONValue.parse(result);
if (object instanceof Map) {
@SuppressWarnings("unchecked")
String urlString = String.valueOf(((Map<Object, Object>) object).get("url"));
Matcher m = URL_PATTERN.matcher(urlString);
if (m.matches()) {
return new URL(urlString);
}
}
throw new IOException("Failed to save paste; instead, got: " + result);
}
}
}

View File

@ -93,18 +93,4 @@ public URL call() throws IOException, InterruptedException {
} }
} }
public static void main(String[] args) {
Futures.addCallback(new Pastebin().paste("hi there"), new FutureCallback<URL>() {
@Override
public void onSuccess(URL url) {
System.out.println("got: " + url);
}
@Override
public void onFailure(Throwable throwable) {
throwable.printStackTrace();
}
});
}
} }