181 lines
8.4 KiB
Java
181 lines
8.4 KiB
Java
package net.t2code.lib.Spigot.system;
|
|
|
|
import net.t2code.lib.Spigot.Lib.messages.send;
|
|
import net.t2code.lib.Spigot.Lib.minecraftVersion.MCVersion;
|
|
import net.t2code.lib.Spigot.Lib.minecraftVersion.NMSVersion;
|
|
import net.t2code.lib.Spigot.Lib.plugins.PluginCheck;
|
|
import net.t2code.lib.Spigot.Lib.vault.Vault;
|
|
import org.bukkit.Bukkit;
|
|
import org.bukkit.command.CommandSender;
|
|
import org.bukkit.entity.Player;
|
|
import org.bukkit.plugin.Plugin;
|
|
|
|
import java.io.*;
|
|
import java.nio.file.Files;
|
|
import java.text.SimpleDateFormat;
|
|
import java.util.Calendar;
|
|
import java.util.zip.ZipEntry;
|
|
import java.util.zip.ZipOutputStream;
|
|
|
|
|
|
public class CreateReportLog {
|
|
protected static void create(CommandSender sender) {
|
|
send.sender(sender, Main.prefix + " §6A DebugLog is created...");
|
|
String timeStampFile = new SimpleDateFormat("HH_mm_ss-dd_MM_yyyy").format(Calendar.getInstance().getTime());
|
|
|
|
File directory = new File(Main.getPath() + "/DebugLogs");
|
|
if (!directory.exists()) {
|
|
directory.mkdir();
|
|
}
|
|
|
|
File file = new File(Main.getPath(), "/DebugLogs/T2CodeLog.txt");
|
|
PrintWriter pWriter = null;
|
|
try {
|
|
pWriter = new PrintWriter(new FileWriter(file.getPath()));
|
|
String timeStamp = new SimpleDateFormat("HH:mm:ss dd.MM.yyyy").format(Calendar.getInstance().getTime());
|
|
pWriter.println("Created on: " + timeStamp);
|
|
pWriter.println();
|
|
pWriter.println("Server Bukkit version: " + MCVersion.isBuckitVersion);
|
|
pWriter.println("Server run on: " + MCVersion.isVersion);
|
|
pWriter.println("Server NMS: " + NMSVersion.isNMS);
|
|
pWriter.println();
|
|
pWriter.println("Online Mode: " + Bukkit.getOnlineMode());
|
|
pWriter.println("Worlds: " + Bukkit.getWorlds());
|
|
pWriter.println();
|
|
if (Vault.vaultEnable) {
|
|
pWriter.println("Vault: " + Bukkit.getPluginManager().getPlugin("Vault").getName() + " - " + Bukkit.getPluginManager().getPlugin("Vault").getDescription().getVersion());
|
|
} else pWriter.println("Vault: not connected");
|
|
if (Main.eco != null) {
|
|
String st;
|
|
st = Main.eco.getName();
|
|
if (Main.eco.getName().equals("CMIEconomy")) st = "CMI";
|
|
pWriter.println("Economy: " + Main.eco.isEnabled() + " - " + Main.eco.getName() + " - " + Bukkit.getPluginManager().getPlugin(st).getDescription().getVersion());
|
|
} else pWriter.println("Economy: not connected via vault");
|
|
if (Main.perm != null) {
|
|
pWriter.println("Permission: " + Main.perm.isEnabled() + " - " + Main.perm.getName() + " - " + Bukkit.getPluginManager().getPlugin(Main.perm.getName()).getDescription().getVersion());
|
|
} else pWriter.println("Permission: not connected via vault");
|
|
pWriter.println();
|
|
pWriter.println("Java: " + System.getProperty("java.version"));
|
|
pWriter.println("System: " + System.getProperty("os.name"));
|
|
pWriter.println("System: " + System.getProperty("os.version"));
|
|
pWriter.println("User Home: " + System.getProperty("user.home"));
|
|
pWriter.println();
|
|
pWriter.println("T2CodeLib: " + Main.plugin.getDescription().getVersion());
|
|
pWriter.println();
|
|
pWriter.println("Plugins: ");
|
|
for (Plugin pl : Bukkit.getPluginManager().getPlugins()) {
|
|
pWriter.println(" - " + pl.getName() + " - " + pl.getDescription().getVersion() + " - Enabled: " + pl.isEnabled() + " - Autors: " + pl.getDescription().getAuthors() + " - Website: " + pl.getDescription().getWebsite());
|
|
}
|
|
} catch (IOException ioe) {
|
|
ioe.printStackTrace();
|
|
} finally {
|
|
if (pWriter != null) {
|
|
pWriter.flush();
|
|
pWriter.close();
|
|
}
|
|
}
|
|
|
|
String filePath = Main.getPath() + "/DebugLogs/T2CodeLog.txt";
|
|
String log = "logs/latest.log";
|
|
String zipPath = "plugins/T2CodeLib/DebugLogs/T2CLog-" + timeStampFile + ".zip";
|
|
try (ZipOutputStream zip = new ZipOutputStream(new FileOutputStream(zipPath))) {
|
|
File fileToZip = new File(filePath);
|
|
zip.putNextEntry(new ZipEntry(fileToZip.getName()));
|
|
Files.copy(fileToZip.toPath(), zip);
|
|
|
|
//File logToZip = new File(log);
|
|
//zipOut.putNextEntry(new ZipEntry(logToZip.getName()));
|
|
//Files.copy(logToZip.toPath(), zipOut);
|
|
|
|
addFileToZip("", "logs/latest.log", zip, false);
|
|
|
|
//pluginToDebug("T2CodeLib", "T2CodeLib", zip); todo bugfix
|
|
pluginToDebug("T2C-LuckyBox", "T2C-LuckyBox", zip);
|
|
pluginToDebug("WonderBagShop", "WonderBagShop", zip);
|
|
pluginToDebug("CommandGUI", "CommandGUI", zip);
|
|
pluginToDebug("OPSecurity", "OPSecurity", zip);
|
|
pluginToDebug("PaPiTest", "PaPiTest", zip);
|
|
pluginToDebug("PlotSquaredGUI", "PlotSquaredGUI", zip);
|
|
pluginToDebug("T2C-Alias", "T2Code-Alias", zip);
|
|
|
|
pluginToDebug("LoreEditor", "LoreEditor", zip);
|
|
pluginToDebug("Booster", "Booster", zip);
|
|
pluginToDebug("AntiMapCopy", "AntiCopy", zip);
|
|
zip.closeEntry();
|
|
zip.close();
|
|
} catch (IOException e) {
|
|
e.printStackTrace();
|
|
}
|
|
file.delete();
|
|
if (sender instanceof Player) {
|
|
send.sender(sender, Main.prefix + " §6A DebugLog zip has been created. you can find it on in the files on your server under the path: §e" + zipPath);
|
|
send.console(Main.prefix + " §6A DebugLog zip has been created. you can find it on in the files on your server under the path: §e" + zipPath);
|
|
} else send.sender(sender, Main.prefix + " §6A DebugLog zip has been created. you can find it on in the files on your server under the path: §e" + zipPath);
|
|
|
|
}
|
|
|
|
private static void pluginToDebug(String pluginName, String jar, ZipOutputStream zip) throws IOException {
|
|
if (PluginCheck.pluginCheck(pluginName)) {
|
|
Plugin plugin = Bukkit.getPluginManager().getPlugin(pluginName);
|
|
File plConfigs = new File(plugin.getDataFolder().getPath());
|
|
if (plConfigs.exists()) {
|
|
addFolderToZip("T2Code-Plugins", plugin.getDataFolder().getPath(), zip);
|
|
}
|
|
File f = new File("plugins/");
|
|
File[] fileArray = f.listFiles();
|
|
|
|
for (File config : fileArray) {
|
|
if (config.getName().contains(jar) && config.getName().contains(".jar")) {
|
|
addFileToZip("T2Code-Plugins", config.getPath(), zip, false);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private static void addFolderToZip(String path, String srcFolder, ZipOutputStream zip) throws IOException {
|
|
File folder = new File(srcFolder);
|
|
if (folder.list() == null) {
|
|
addFileToZip(path + "/" + folder.getName(), srcFolder, zip, false);
|
|
} else if (folder.list().length == 0) {
|
|
addFileToZip(path, srcFolder, zip, true);
|
|
} else {
|
|
for (String fileName : folder.list()) {
|
|
if (path.equals("")) {
|
|
addFileToZip(folder.getName(), srcFolder + "/" + fileName, zip, false);
|
|
} else {
|
|
addFileToZip(path + "/" + folder.getName(), srcFolder + "/" + fileName, zip, false);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private static void addFileToZip(String path, String srcFile, ZipOutputStream zip, boolean flag) throws IOException {
|
|
File folder = new File(srcFile);
|
|
if (flag) {
|
|
zip.putNextEntry(new ZipEntry(path + "/" + folder.getName() + "/"));
|
|
} else {
|
|
if (folder.isDirectory()) {
|
|
addFolderToZip(path, srcFile, zip);
|
|
} else {
|
|
byte[] buf = new byte[1024];
|
|
int len;
|
|
FileInputStream in = new FileInputStream(srcFile);
|
|
|
|
if (path.equals("")) {
|
|
zip.putNextEntry(new ZipEntry((folder.getName())));
|
|
} else {
|
|
zip.putNextEntry(new ZipEntry((path + "/" + folder.getName())));
|
|
}
|
|
|
|
while ((len = in.read(buf)) > 0) {
|
|
try {
|
|
zip.write(buf, 0, len);
|
|
} catch (Exception ex){
|
|
ex.printStackTrace();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|