Merge pull request 'NewDebugZip' (#11) from NewDebugZip into 13.3

Reviewed-on: #11
This commit is contained in:
JaTiTV
2022-11-13 15:31:20 +00:00
11 changed files with 274 additions and 43 deletions

View File

@@ -12,6 +12,7 @@ import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.bukkit.entity.Player;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -25,7 +26,7 @@ public class CmdExecuter implements CommandExecutor, TabCompleter {
return false;
}
if (args.length == 0) {
T2Ctemplate.sendInfo(sender,T2CodeLibMain.getPlugin(), Util.getSpigotID(),Util.getDiscord(),null, Util.getInfoText());
T2Ctemplate.sendInfo(sender, T2CodeLibMain.getPlugin(), Util.getSpigotID(), Util.getDiscord(), null, Util.getInfoText());
return false;
}
switch (args[0].toLowerCase()) {
@@ -34,24 +35,44 @@ public class CmdExecuter implements CommandExecutor, TabCompleter {
case "pl":
case "version":
case "ver":
T2Ctemplate.sendInfo(sender,T2CodeLibMain.getPlugin(), Util.getSpigotID(),Util.getDiscord(),null, Util.getInfoText());
T2Ctemplate.sendInfo(sender, T2CodeLibMain.getPlugin(), Util.getSpigotID(), Util.getDiscord(), null, Util.getInfoText());
return false;
case "reloadconfig":
SelectLibConfig.onSelect();
return false;
case "debug":
if (args.length != 2) {
if (args.length < 2) {
T2Csend.sender(sender, "§4Use: §7/t2code debug createReportLog");
return false;
}
if ("createreportlog".equals(args[1].toLowerCase())) {
Bukkit.getScheduler().runTaskAsynchronously(T2CodeLibMain.getPlugin(), new Runnable() {
@Override
public void run() {
CreateReportLog.create(sender);
switch (args[1].toLowerCase()) {
case "createreportlog":
Bukkit.getScheduler().runTaskAsynchronously(T2CodeLibMain.getPlugin(), new Runnable() {
@Override
public void run() {
try {
CreateReportLog.create(sender);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
});
break;
case "deleteReportLog":
if (args.length != 3) {
T2Csend.sender(sender, "§4Use: §7/t2code debug deleteReportLog [id]");
return false;
}
});
} else T2Csend.sender(sender, "§4Use: §7/t2code debug createReportLog");
try {
CreateReportLog.delete(args[2]);
} catch (IOException e) {
throw new RuntimeException(e);
}
break;
default:
T2Csend.sender(sender, "§4Use: §7/t2code debug createReportLog/deleteReportLog");
break;
}
return false;
default:
@@ -84,6 +105,7 @@ public class CmdExecuter implements CommandExecutor, TabCompleter {
if (sender.hasPermission("t2code.admin")) {
if (hasPermission(p, arg1.get("debug")) && passend("debug", args[1])) {
list.add("createReportLog");
list.add("deleteReportLog");
}
}
return list;

View File

@@ -5,13 +5,23 @@ import net.t2code.t2codelib.SPIGOT.api.messages.T2Csend;
import net.t2code.t2codelib.SPIGOT.api.minecraftVersion.T2CmcVersion;
import net.t2code.t2codelib.SPIGOT.api.plugins.T2CpluginCheck;
import net.t2code.t2codelib.Util;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.mime.MultipartEntity;
import org.apache.http.entity.mime.content.FileBody;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.json.JSONObject;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.file.Files;
import java.text.SimpleDateFormat;
import java.util.Calendar;
@@ -19,7 +29,7 @@ import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
public class CreateReportLog {
protected static void create(CommandSender sender) {
protected static void create(CommandSender sender) throws IOException {
T2Csend.sender(sender, Util.getPrefix() + " §6A DebugLog is created...");
String timeStampFile = new SimpleDateFormat("HH_mm_ss-dd_MM_yyyy").format(Calendar.getInstance().getTime());
@@ -120,10 +130,26 @@ public class CreateReportLog {
e.printStackTrace();
}
file.delete();
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("https://debug.t2code.net/uploadFile");
File zipFile = new File(zipPath);
FileBody bin = new FileBody(zipFile);
MultipartEntity reqEntity = new MultipartEntity();
reqEntity.addPart("file", bin);
httppost.setEntity(reqEntity);
HttpResponse response = httpclient.execute(httppost);
HttpEntity resEntity = response.getEntity();
String responseString = EntityUtils.toString(resEntity, "UTF-8");
JSONObject obj = new JSONObject(responseString);
String downloadURL = obj.getString("fileDownloadUri");
String fileID = obj.getString("fileID");
String fileType = obj.getString("fileType");
Integer fileSize = obj.getInt("size");
zipFile.delete();
if (sender instanceof Player) {
T2Csend.sender(sender, Util.getPrefix() + " §6A DebugLog zip has been created. you can find it on in the files on your server under the path: §e" + zipPath);
T2Csend.console(Util.getPrefix() + " §6A DebugLog zip has been created. you can find it on in the files on your server under the path: §e" + zipPath);
} else T2Csend.sender(sender, Util.getPrefix() + " §6A DebugLog zip has been created. you can find it on in the files on your server under the path: §e" + zipPath);
T2Csend.sender(sender, Util.getPrefix() + "<green>A DebugLog zip has been created. You can download it <click:open_url:'url'><gold>here</gold></click>. Please enter the following key in the ticket: <gold>key</gold></green><br><dark_red>Do not share the download URL with anyone!</dark_red><br><click:run_command:'/t2code debug deleteReportLog key'><green>You can <b>delte </b>yor Debug-File by clicking me.</green></click>".replace("key",fileID).replace("url",downloadURL));
T2Csend.console(Util.getPrefix() + " §6A DebugLog zip has been created. You can download it here: url.\n§6Please enter the following key in the ticket: §e[key].\n§4Do not share the download URL with anyone!\nYou can delte yor Debug-File with the following command: /t2code debug deleteReportLog key.".replace("[key]",fileID).replace("url",downloadURL));
} else T2Csend.sender(sender, Util.getPrefix() + " §6A DebugLog zip has been created. You can download it here: url.\n§6Please enter the following key in the ticket: §e[key].\n§4Do not share the download URL with anyone!\nYou can delte yor Debug-File with the following command: /t2code debug deleteReportLog key.".replace("[key]",fileID).replace("url",downloadURL));
}
@@ -190,4 +216,10 @@ public class CreateReportLog {
}
}
}
public static void delete(String arg) throws IOException {
URL url = new URL("https://debug.t2code.net/delte/" + arg);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setRequestMethod("GET");
}
}

View File

@@ -39,7 +39,7 @@ public final class T2CodeLibMain extends JavaPlugin {
plugin = this;
autor = plugin.getDescription().getAuthors();
version = plugin.getDescription().getVersion();
this.adventure = BukkitAudiences.create(this);
adventure = BukkitAudiences.create(this);
long long_ = T2Ctemplate.onLoadHeader(Util.getPrefix(), autor, version, Util.getSpigot(), Util.getDiscord());
String prefix = Util.getPrefix();
@@ -90,9 +90,9 @@ public final class T2CodeLibMain extends JavaPlugin {
SelectLibConfig.onSelect();
SelectLibMsg.onSelect();
T2CupdateAPI.onUpdateCheck(plugin, prefix, Util.getSpigotID(), Util.getDiscord());
T2CupdateAPI.onUpdateCheck(plugin, prefix, Util.getGit(), Util.getSpigotID(), Util.getDiscord());
Metrics.Bstats(plugin, Util.getBstatsID());
if (SelectLibConfig.getBungee()){
if (SelectLibConfig.getBungee()) {
Bukkit.getMessenger().registerOutgoingPluginChannel(plugin, "t2c:bcmd");
}
@@ -155,7 +155,7 @@ public final class T2CodeLibMain extends JavaPlugin {
private static BukkitAudiences adventure;
public static BukkitAudiences adventure() {
public BukkitAudiences getAdventure() {
if (adventure == null) {
throw new IllegalStateException("Tried to access Adventure when the plugin was disabled!");
}