use of gs.mclo.java.APIResponse in project mclogs-fabric by aternosorg.
the class MclogsFabricLoader method share.
public static int share(ServerCommandSource source, String filename) {
MclogsAPI.mcversion = source.getMinecraftServer().getVersion();
logger.log(Level.INFO, "Sharing " + filename);
source.sendFeedback(new LiteralText("Sharing " + filename), false);
try {
Path logs = source.getMinecraftServer().getFile("logs/").toPath();
Path log = logs.resolve(filename);
if (!log.getParent().equals(logs)) {
throw new FileNotFoundException();
}
APIResponse response = MclogsAPI.share(log);
if (response.success) {
LiteralText feedback = new LiteralText("Your log has been uploaded: ");
feedback.setStyle(Style.EMPTY.withColor(Formatting.GREEN));
LiteralText link = new LiteralText(response.url);
Style linkStyle = Style.EMPTY.withColor(Formatting.BLUE);
linkStyle = linkStyle.withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, response.url));
link.setStyle(linkStyle);
source.sendFeedback(feedback.append(link), true);
return 1;
} else {
logger.error("An error occurred when uploading your log: ");
logger.error(response.error);
LiteralText error = new LiteralText("An error occurred. Check your log for more details");
source.sendError(error);
return 0;
}
} catch (FileNotFoundException | IllegalArgumentException e) {
LiteralText error = new LiteralText("The log file " + filename + " doesn't exist. Use '/mclogs list' to list all logs.");
source.sendError(error);
return -1;
} catch (IOException e) {
source.sendError(new LiteralText("An error occurred. Check your log for more details"));
logger.error("Could not get log file!");
logger.error(e);
return 0;
}
}
Aggregations