mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2024-11-22 10:36:06 +01:00
Added a theoretically working Hastebin option for mvv output.
This commit is contained in:
parent
4c9d108f08
commit
b201b09719
@ -36,7 +36,7 @@ public class VersionCommand extends MultiverseCommand {
|
||||
public VersionCommand(MultiverseCore plugin) {
|
||||
super(plugin);
|
||||
this.setName("Multiverse Version");
|
||||
this.setCommandUsage("/mv version " + ChatColor.GOLD + "-[pbg]");
|
||||
this.setCommandUsage("/mv version " + ChatColor.GOLD + "-[bh]");
|
||||
this.setArgRange(0, 1);
|
||||
this.addKey("mv version");
|
||||
this.addKey("mvv");
|
||||
@ -163,6 +163,9 @@ public class VersionCommand extends MultiverseCommand {
|
||||
if (args.get(0).equalsIgnoreCase("-b")) {
|
||||
// private post to pastebin
|
||||
pasteUrl = postToService(PasteServiceType.PASTEBIN, true, data, files);
|
||||
} else if (args.get(0).equalsIgnoreCase("-h")) {
|
||||
// private post to pastebin
|
||||
pasteUrl = postToService(PasteServiceType.HASTEBIN, true, data, files);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
@ -0,0 +1,81 @@
|
||||
package com.onarandombox.MultiverseCore.utils.webpaste;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonParser;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Pastes to {@code hastebin.com}.
|
||||
*/
|
||||
public class HastebinPasteService implements PasteService {
|
||||
|
||||
@Override
|
||||
public String encodeData(String data) {
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String encodeData(Map<String, String> data) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public URL getPostURL() {
|
||||
try {
|
||||
return new URL("https://hastebin.com/documents");
|
||||
} catch (MalformedURLException e) {
|
||||
return null; // should never hit here
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String postData(String encodedData, URL url) throws PasteFailedException {
|
||||
OutputStreamWriter wr = null;
|
||||
BufferedReader rd = null;
|
||||
try {
|
||||
URLConnection conn = url.openConnection();
|
||||
conn.setDoOutput(true);
|
||||
|
||||
wr = new OutputStreamWriter(conn.getOutputStream());
|
||||
rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
|
||||
|
||||
wr.write(encodedData);
|
||||
wr.flush();
|
||||
|
||||
String line;
|
||||
StringBuilder responseString = new StringBuilder();
|
||||
while ((line = rd.readLine()) != null) {
|
||||
responseString.append(line);
|
||||
}
|
||||
String key = new JsonParser().parse(responseString.toString()).getAsJsonObject().get("key").getAsString();
|
||||
|
||||
return "https://hastebin.com/" + key;
|
||||
} catch (Exception e) {
|
||||
throw new PasteFailedException(e);
|
||||
} finally {
|
||||
if (wr != null) {
|
||||
try {
|
||||
wr.close();
|
||||
} catch (IOException ignore) { }
|
||||
}
|
||||
if (rd != null) {
|
||||
try {
|
||||
rd.close();
|
||||
} catch (IOException ignore) { }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsMultiFile() {
|
||||
return false;
|
||||
}
|
||||
}
|
@ -16,6 +16,8 @@ public class PasteServiceFactory {
|
||||
switch(type) {
|
||||
case PASTEBIN:
|
||||
return new PastebinPasteService(isPrivate);
|
||||
case HASTEBIN:
|
||||
return new HastebinPasteService();
|
||||
case GITHUB:
|
||||
return new GithubPasteService(isPrivate);
|
||||
default:
|
||||
|
@ -11,6 +11,10 @@ public enum PasteServiceType {
|
||||
* @see PastebinPasteService
|
||||
*/
|
||||
PASTEBIN,
|
||||
/**
|
||||
* @see HastebinPasteService
|
||||
*/
|
||||
HASTEBIN,
|
||||
/**
|
||||
* @see GithubPasteService
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user