PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/DebugPaste.java

77 lines
4.2 KiB
Java
Raw Normal View History

package com.intellectualcrafters.plot.commands;
import com.intellectualsites.commands.CommandDeclaration;
2015-07-27 06:30:50 +02:00
import com.intellectualsites.commands.CommandCaller;
2015-07-26 16:51:12 +02:00
import com.plotsquared.bukkit.BukkitMain;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.HastebinUtility;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.TaskManager;
import org.bukkit.Bukkit;
2015-07-19 16:18:46 +02:00
import org.bukkit.plugin.Plugin;
import java.io.File;
import java.io.IOException;
@CommandDeclaration(
command = "debugpaste",
aliases = {"dp"},
usage = "/plot debugpaste",
description = "Upload settings.yml & latest.log to hastebin",
permission = "plots.debugpaste",
category = CommandCategory.DEBUG
)
public class DebugPaste extends SubCommand {
@Override
public boolean onCommand(final CommandCaller caller, String[] args) {
TaskManager.runTaskAsync(new Runnable() {
@Override
public void run() {
try {
2015-07-19 16:18:46 +02:00
String settingsYML = HastebinUtility.upload(PS.get().configFile);
2015-07-26 13:40:48 +02:00
String latestLOG;
try {
latestLOG = HastebinUtility.upload(new File(BukkitMain.THIS.getDirectory(), "../../logs/latest.log"));
} catch(final Exception e) {
caller.message("&clatest.log is too big to be pasted, will ignore");
2015-07-26 13:40:48 +02:00
latestLOG = "too big :(";
}
2015-07-19 16:18:46 +02:00
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());
caller.message(C.DEBUG_REPORT_CREATED.s().replace("%url%", link));
} catch (IOException e) {
e.printStackTrace();
}
}
});
return true;
}
}