mirror of
https://github.com/EngineHub/WorldGuard.git
synced 2024-11-27 21:15:57 +01:00
Use EH pastebin and remove debug code.
This commit is contained in:
parent
d9e4b27cd2
commit
477f1188df
@ -27,7 +27,7 @@
|
||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||
import com.sk89q.worldguard.bukkit.util.logging.LoggerToChatHandler;
|
||||
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.SystemInfoReport;
|
||||
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...");
|
||||
|
||||
Futures.addCallback(new Pastebin().paste(result), new FutureCallback<URL>() {
|
||||
Futures.addCallback(new EngineHubPaste().paste(result), new FutureCallback<URL>() {
|
||||
@Override
|
||||
public void onSuccess(URL url) {
|
||||
sender.sendMessage(ChatColor.YELLOW + "WorldGuard report: " + url);
|
||||
sender.sendMessage(ChatColor.YELLOW + "WorldGuard report: " + url + ".report");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -92,19 +92,5 @@ 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();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user