Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-12-27 00:22:51 +01:00
Add ViaVersion dump command to get all the relevant info we need by bug reports.
Dieser Commit ist enthalten in:
Ursprung
0f3daa5dc4
Commit
f2e4c37cd9
@ -132,6 +132,7 @@ public class ViaCommandHandler implements ViaVersionCommand, CommandExecutor, Ta
|
|||||||
registerSubCommand(new ListSubCmd());
|
registerSubCommand(new ListSubCmd());
|
||||||
registerSubCommand(new PPSSubCmd());
|
registerSubCommand(new PPSSubCmd());
|
||||||
registerSubCommand(new DebugSubCmd());
|
registerSubCommand(new DebugSubCmd());
|
||||||
|
registerSubCommand(new DumpSubCmd());
|
||||||
registerSubCommand(new DisplayLeaksSubCmd());
|
registerSubCommand(new DisplayLeaksSubCmd());
|
||||||
registerSubCommand(new DontBugMeSubCmd());
|
registerSubCommand(new DontBugMeSubCmd());
|
||||||
registerSubCommand(new AutoTeamSubCmd());
|
registerSubCommand(new AutoTeamSubCmd());
|
||||||
|
@ -0,0 +1,91 @@
|
|||||||
|
package us.myles.ViaVersion.commands.defaultsubs;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.GsonBuilder;
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
import us.myles.ViaVersion.ViaVersionPlugin;
|
||||||
|
import us.myles.ViaVersion.api.ViaVersion;
|
||||||
|
import us.myles.ViaVersion.api.command.ViaSubCommand;
|
||||||
|
import us.myles.ViaVersion.api.protocol.ProtocolRegistry;
|
||||||
|
import us.myles.ViaVersion.dump.DumpTemplate;
|
||||||
|
import us.myles.ViaVersion.dump.PluginInfo;
|
||||||
|
import us.myles.ViaVersion.dump.VersionInfo;
|
||||||
|
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.io.InvalidObjectException;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.nio.charset.Charset;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
public class DumpSubCmd extends ViaSubCommand {
|
||||||
|
private final Gson gson = new GsonBuilder().setPrettyPrinting().create();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String name() {
|
||||||
|
return "dump";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String description() {
|
||||||
|
return "Dump information about your server, this is helpful if you report bugs.";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean execute(final CommandSender sender, String[] args) {
|
||||||
|
VersionInfo version = new VersionInfo(
|
||||||
|
Bukkit.getServer().getVersion(),
|
||||||
|
Bukkit.getServer().getBukkitVersion(),
|
||||||
|
System.getProperty("java.version"),
|
||||||
|
System.getProperty("os.name"),
|
||||||
|
ProtocolRegistry.SERVER_PROTOCOL,
|
||||||
|
ProtocolRegistry.getSupportedVersions());
|
||||||
|
|
||||||
|
List<PluginInfo> plugins = new ArrayList<>();
|
||||||
|
for (Plugin p : Bukkit.getPluginManager().getPlugins())
|
||||||
|
plugins.add(new PluginInfo(p.isEnabled(), p.getDescription().getName(), p.getDescription().getVersion(), p.getDescription().getMain(), p.getDescription().getAuthors()));
|
||||||
|
|
||||||
|
final DumpTemplate template = new DumpTemplate(version, plugins);
|
||||||
|
|
||||||
|
Bukkit.getScheduler().runTaskAsynchronously((ViaVersionPlugin) ViaVersion.getInstance(), new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
HttpURLConnection con = (HttpURLConnection) new URL("http://hastebin.com/documents").openConnection();
|
||||||
|
|
||||||
|
con.setRequestProperty("Content-Type", "text/plain");
|
||||||
|
con.setRequestMethod("POST");
|
||||||
|
con.setDoOutput(true);
|
||||||
|
|
||||||
|
OutputStream out = con.getOutputStream();
|
||||||
|
out.write(gson.toJson(template).getBytes(Charset.forName("UTF-8")));
|
||||||
|
out.close();
|
||||||
|
|
||||||
|
JsonObject output = gson.fromJson(new InputStreamReader(con.getInputStream()), JsonObject.class);
|
||||||
|
con.getInputStream().close();
|
||||||
|
|
||||||
|
if (!output.has("key"))
|
||||||
|
throw new InvalidObjectException("Key is not given in Hastebin output");
|
||||||
|
|
||||||
|
sender.sendMessage(ChatColor.GREEN + "We've made a dump with useful information, report your issue and provide this url: " + getUrl(output.get("key").getAsString()));
|
||||||
|
} catch (Exception e) {
|
||||||
|
sender.sendMessage(ChatColor.RED + "Failed to dump, please check the console for more information");
|
||||||
|
((ViaVersionPlugin) ViaVersion.getInstance()).getLogger().log(Level.WARNING, "Could not paste ViaVersion dump to Hastebin", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getUrl(String id) {
|
||||||
|
return String.format("http://hastebin.com/%s.json", id);
|
||||||
|
}
|
||||||
|
}
|
13
src/main/java/us/myles/ViaVersion/dump/DumpTemplate.java
Normale Datei
13
src/main/java/us/myles/ViaVersion/dump/DumpTemplate.java
Normale Datei
@ -0,0 +1,13 @@
|
|||||||
|
package us.myles.ViaVersion.dump;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class DumpTemplate {
|
||||||
|
private VersionInfo versions;
|
||||||
|
private List<PluginInfo> plugins;
|
||||||
|
}
|
16
src/main/java/us/myles/ViaVersion/dump/PluginInfo.java
Normale Datei
16
src/main/java/us/myles/ViaVersion/dump/PluginInfo.java
Normale Datei
@ -0,0 +1,16 @@
|
|||||||
|
package us.myles.ViaVersion.dump;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class PluginInfo {
|
||||||
|
private boolean enabled;
|
||||||
|
private String name;
|
||||||
|
private String version;
|
||||||
|
private String main;
|
||||||
|
private List<String> authors;
|
||||||
|
}
|
18
src/main/java/us/myles/ViaVersion/dump/VersionInfo.java
Normale Datei
18
src/main/java/us/myles/ViaVersion/dump/VersionInfo.java
Normale Datei
@ -0,0 +1,18 @@
|
|||||||
|
package us.myles.ViaVersion.dump;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class VersionInfo {
|
||||||
|
private String version;
|
||||||
|
private String bukkitVersion;
|
||||||
|
private String javaVersion;
|
||||||
|
private String operatingSystem;
|
||||||
|
private int serverProtocol;
|
||||||
|
private Set<Integer> enabledPipelines;
|
||||||
|
}
|
||||||
|
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren