This commit is contained in:
boy0001 2015-07-20 15:14:52 +10:00
commit 154e002dee
3 changed files with 47 additions and 16 deletions

View File

@ -8,6 +8,7 @@ import com.intellectualcrafters.plot.util.HastebinUtility;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.TaskManager;
import org.bukkit.Bukkit;
import org.bukkit.plugin.Plugin;
import java.io.File;
import java.io.IOException;
@ -24,10 +25,35 @@ public class DebugPaste extends SubCommand {
@Override
public void run() {
try {
String link = HastebinUtility.upload(PS.get().configFile);
MainUtil.sendMessage(plr, C.SETTINGS_PASTE_UPLOADED.s().replace("%url%", link));
link = HastebinUtility.upload(new File(BukkitMain.THIS.getDirectory(), "../../logs/latest.log"));
MainUtil.sendMessage(plr, C.LATEST_LOG_UPLOADED.s().replace("%url%", link));
String settingsYML = HastebinUtility.upload(PS.get().configFile);
String latestLOG = HastebinUtility.upload(new File(BukkitMain.THIS.getDirectory(), "../../logs/latest.log"));
StringBuilder b = new StringBuilder();
b.append("# Welcome to this paste\n# It is meant to provide us at IntellectualSites with better information about your problem\n\n# We will start with some informational files\n");
b.append("links.settings_yml: '").append(settingsYML).append("'\n");
b.append("links.latest_log: '").append(latestLOG).append("'\n");
b.append("\n# YAAAS! Now let us move on to the server info\n");
b.append("version.server: '").append(Bukkit.getServer().getVersion()).append("'\n");
b.append("version.bukkit: '").append(Bukkit.getBukkitVersion()).append("'\n");
b.append("online_mode: ").append(Bukkit.getServer().getOnlineMode()).append("\n");
b.append("plugins:");
for (final Plugin p : Bukkit.getPluginManager().getPlugins()) {
b.append("\n ").append(p.getName()).append(":\n ").append("version: '").append(p.getDescription().getVersion()).append("'").append("\n enabled: ").append(p.isEnabled());
}
b.append("\n\n# YAY! Now, let's see what we can find in your JVM\n");
Runtime runtime = Runtime.getRuntime();
b.append("memory.free: ").append(runtime.freeMemory()).append("\n");
b.append("memory.max: ").append(runtime.maxMemory()).append("\n");
b.append("java.specification.version: '").append(System.getProperty("java.specification.version")).append("'\n");
b.append("java.vendor: '").append(System.getProperty("java.vendor")).append("'\n");
b.append("java.version: '").append(System.getProperty("java.version")).append("'\n");
b.append("os.arch: '").append(System.getProperty("os.arch")).append("'\n");
b.append("os.name: '").append(System.getProperty("os.name")).append("'\n");
b.append("os.version: '").append(System.getProperty("os.version")).append("'\n\n");
b.append("# Okay :D Great. You are now ready to create your bug report!");
b.append("\n# You can do so at https://github.com/IntellectualSites/PlotSquared/issues");
String link = HastebinUtility.upload(b.toString());
MainUtil.sendMessage(plr, C.DEBUG_REPORT_CREATED.s().replace("%url%", link));
} catch (IOException e) {
e.printStackTrace();
}

View File

@ -283,8 +283,9 @@ public enum C {
* Player not found
*/
INVALID_PLAYER("$2Player not found: $1%s.", "Errors"),
SETTINGS_PASTE_UPLOADED("$2settings.yml was uploaded to: $1%url%", "Paste"),
LATEST_LOG_UPLOADED("$2latest.log was uploaded to: $1%url%", "Paste"),
// SETTINGS_PASTE_UPLOADED("$2settings.yml was uploaded to: $1%url%", "Paste"),
// LATEST_LOG_UPLOADED("$2latest.log was uploaded to: $1%url%", "Paste"),
DEBUG_REPORT_CREATED("$1Uploaded a full debug to: $1%url%", "Paste"),
/*
*
*/

View File

@ -11,14 +11,7 @@ public class HastebinUtility {
public static final String BIN_URL = "http://hastebin.com/documents", USER_AGENT = "Mozilla/5.0";
public static final Pattern PATTERN = Pattern.compile("\\{\"key\":\"([\\S\\s]*)\"\\}");
public static String upload(final File file) throws IOException {
StringBuilder content = new StringBuilder();
BufferedReader reader = new BufferedReader(new FileReader(file));
String line;
while ((line = reader.readLine()) != null) {
content.append(line).append("\n");
}
reader.close();
public static String upload(final String string) throws IOException {
URL url = new URL(BIN_URL);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
@ -27,7 +20,7 @@ public class HastebinUtility {
connection.setDoOutput(true);
DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream());
outputStream.writeUTF(content.toString());
outputStream.write(string.getBytes());
outputStream.flush();
outputStream.close();
@ -45,9 +38,20 @@ public class HastebinUtility {
if (matcher.matches()) {
return "http://hastebin.com/" + matcher.group(1);
} else {
throw new RuntimeException("Coldn't read response!");
throw new RuntimeException("Couldn't read response!");
}
}
public static String upload(final File file) throws IOException {
StringBuilder content = new StringBuilder();
BufferedReader reader = new BufferedReader(new FileReader(file));
String line;
while ((line = reader.readLine()) != null) {
content.append(line).append("\n");
}
reader.close();
return upload(content.toString());
}
}