Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
deeedcd408 | |||
e4c4aee0f7 |
2
pom.xml
2
pom.xml
@@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>net.t2code</groupId>
|
||||
<artifactId>T2CodeLib</artifactId>
|
||||
<version>13.4</version>
|
||||
<version>13.6</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>T2CodeLib</name>
|
||||
|
@@ -1,12 +1,11 @@
|
||||
package net.t2code.t2codelib.SPIGOT.api.update;
|
||||
|
||||
import com.sun.org.apache.xpath.internal.operations.Bool;
|
||||
import net.t2code.t2codelib.SPIGOT.api.messages.T2Csend;
|
||||
import net.t2code.t2codelib.SPIGOT.system.T2CodeLibMain;
|
||||
import net.t2code.t2codelib.UpdateType;
|
||||
import net.t2code.t2codelib.SPIGOT.system.config.config.SelectLibConfig;
|
||||
import net.t2code.t2codelib.T2CupdateObject;
|
||||
import net.t2code.t2codelib.T2CupdateWebData;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
@@ -18,7 +17,16 @@ public class T2CupdateAPI {
|
||||
public static HashMap<String, T2CupdateObject> pluginVersions = new HashMap<>();
|
||||
|
||||
public static void join(Plugin plugin, String prefix, String perm, Player player, Integer spigotID, String discord) {
|
||||
if (! pluginVersions.get(plugin.getName()).updateCheckOnJoin) {
|
||||
if (pluginVersions.get(plugin.getName()) == null){
|
||||
Bukkit.getScheduler().runTaskLaterAsynchronously(T2CodeLibMain.getPlugin(), new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
join(plugin,prefix,perm,player,spigotID,discord);
|
||||
}
|
||||
},2*20L);
|
||||
}
|
||||
|
||||
if (!pluginVersions.get(plugin.getName()).updateCheckOnJoin) {
|
||||
return;
|
||||
}
|
||||
if (!player.hasPermission(perm) && !player.isOp()) {
|
||||
@@ -170,82 +178,7 @@ public class T2CupdateAPI {
|
||||
return text;
|
||||
}
|
||||
|
||||
public static void onUpdateCheck(Plugin plugin, String prefix, int spigotID, String discord) {
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
(new T2CupdateChecker((JavaPlugin) plugin, spigotID)).getVersion((update_version) -> {
|
||||
T2CupdateObject update = new T2CupdateObject(
|
||||
plugin.getName(),
|
||||
plugin.getDescription().getVersion(),
|
||||
new T2CupdateWebData("OLD", update_version, "", "https://www.spigotmc.org/resources/" + spigotID, "",
|
||||
"https://www.spigotmc.org/resources/" + spigotID, false),
|
||||
false,
|
||||
!plugin.getDescription().getVersion().equals(update_version),
|
||||
true
|
||||
);
|
||||
pluginVersions.put(plugin.getName(), update);
|
||||
if (pluginVersions.get(plugin.getName()).updateAvailable) {
|
||||
if (!update.load) {
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
update.load = true;
|
||||
sendUpdateMsg(prefix, discord, update.webData, plugin);
|
||||
}
|
||||
}.runTaskLaterAsynchronously(plugin, 200L);
|
||||
} else sendUpdateMsg(prefix, discord, update.webData, plugin);
|
||||
} else {
|
||||
if (!update.load) {
|
||||
T2Csend.console(prefix + " §2No update found.");
|
||||
update.load = true;
|
||||
}
|
||||
}
|
||||
}, prefix, plugin.getDescription().getVersion(),true,true,60);
|
||||
}
|
||||
}.runTaskTimerAsynchronously(plugin, 0L, SelectLibConfig.getUpdateCheckTimeInterval() * 60 * 20L);
|
||||
}
|
||||
|
||||
public static void onUpdateCheck(Plugin plugin, String prefix, String gitKey, Integer spigotID, String discord, Boolean updateCheckOnJoin, Boolean seePreReleaseUpdates, Integer timeInterval) {
|
||||
String RepoURL = "https://git.t2code.net/api/v1/repos/" + gitKey + "/releases?limit=1";
|
||||
if (!seePreReleaseUpdates) {
|
||||
RepoURL = RepoURL + "&pre-release=false";
|
||||
}
|
||||
if (!RepoURL.contains("?limit=1")) {
|
||||
RepoURL = RepoURL + "?limit=1";
|
||||
}
|
||||
String finalRepoURL = RepoURL;
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
(new T2CupdateCheckerGit((JavaPlugin) plugin)).getVersion((webData) -> {
|
||||
T2CupdateObject update = new T2CupdateObject(
|
||||
plugin.getName(),
|
||||
plugin.getDescription().getVersion(),
|
||||
webData,
|
||||
false,
|
||||
!plugin.getDescription().getVersion().equals(webData.getVersion()),
|
||||
updateCheckOnJoin
|
||||
);
|
||||
pluginVersions.put(plugin.getName(), update);
|
||||
if (pluginVersions.get(plugin.getName()).updateAvailable) {
|
||||
if (!update.load) {
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
update.load = true;
|
||||
sendUpdateMsg(prefix, discord, webData, plugin);
|
||||
}
|
||||
}.runTaskLaterAsynchronously(plugin, 600L);
|
||||
} else sendUpdateMsg(prefix, discord, webData, plugin);
|
||||
} else {
|
||||
if (!update.load) {
|
||||
T2Csend.console(prefix + " §2No update found.");
|
||||
update.load = true;
|
||||
}
|
||||
}
|
||||
}, plugin.getDescription().getVersion(), spigotID, finalRepoURL, updateCheckOnJoin, seePreReleaseUpdates, timeInterval);
|
||||
}
|
||||
}.runTaskTimerAsynchronously(plugin, 0L, timeInterval * 60 * 20L);
|
||||
new T2CupdateCheckerGit((JavaPlugin) plugin, prefix, gitKey, spigotID, discord, updateCheckOnJoin, seePreReleaseUpdates, timeInterval);
|
||||
}
|
||||
}
|
||||
|
@@ -1,76 +0,0 @@
|
||||
package net.t2code.t2codelib.SPIGOT.api.update;
|
||||
|
||||
import net.t2code.t2codelib.T2CupdateObject;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.util.Scanner;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class T2CupdateChecker {
|
||||
private JavaPlugin plugin;
|
||||
private int resourceId;
|
||||
|
||||
public T2CupdateChecker(JavaPlugin plugin, int resourceId) {
|
||||
this.plugin = plugin;
|
||||
this.resourceId = resourceId;
|
||||
}
|
||||
|
||||
public void getVersion(Consumer<String> consumer, String Prefix, String pluginVersion, Boolean updateCheckOnJoin, Boolean seePreReleaseUpdates, Integer timeInterval) {
|
||||
if (!plugin.isEnabled()) {
|
||||
return;
|
||||
}
|
||||
Bukkit.getScheduler().runTaskAsynchronously(this.plugin, () -> {
|
||||
try {
|
||||
InputStream inputStream = (new URL("https://api.spigotmc.org/legacy/update.php?resource=" + this.resourceId)).openStream();
|
||||
try {
|
||||
Scanner scanner = new Scanner(inputStream);
|
||||
|
||||
try {
|
||||
if (scanner.hasNext()) {
|
||||
consumer.accept(scanner.next());
|
||||
}
|
||||
} catch (Throwable var8) {
|
||||
try {
|
||||
scanner.close();
|
||||
} catch (Throwable var7) {
|
||||
var8.addSuppressed(var7);
|
||||
}
|
||||
throw var8;
|
||||
}
|
||||
scanner.close();
|
||||
} catch (Throwable var9) {
|
||||
if (inputStream != null) {
|
||||
try {
|
||||
inputStream.close();
|
||||
} catch (Throwable var6) {
|
||||
var9.addSuppressed(var6);
|
||||
}
|
||||
}
|
||||
throw var9;
|
||||
}
|
||||
inputStream.close();
|
||||
} catch (IOException var10) {
|
||||
Boolean load = false;
|
||||
if (T2CupdateAPI.pluginVersions.containsKey(plugin.getName())){
|
||||
load = T2CupdateAPI.pluginVersions.get(plugin.getName()).load;
|
||||
}
|
||||
|
||||
T2CupdateObject update = new T2CupdateObject(
|
||||
plugin.getName(),
|
||||
pluginVersion,
|
||||
null,
|
||||
load,
|
||||
false,
|
||||
updateCheckOnJoin
|
||||
|
||||
);
|
||||
T2CupdateAPI.pluginVersions.put(plugin.getName(), update);
|
||||
this.plugin.getLogger().severe("§4 Cannot look for updates: " + var10.getMessage());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@@ -1,9 +1,11 @@
|
||||
package net.t2code.t2codelib.SPIGOT.api.update;
|
||||
|
||||
import net.t2code.t2codelib.SPIGOT.api.messages.T2Csend;
|
||||
import net.t2code.t2codelib.T2CupdateObject;
|
||||
import net.t2code.t2codelib.T2CupdateWebData;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
@@ -15,10 +17,55 @@ import java.util.Date;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class T2CupdateCheckerGit {
|
||||
private JavaPlugin plugin;
|
||||
private final JavaPlugin plugin;
|
||||
private T2CupdateObject t2CupdateObject;
|
||||
|
||||
public T2CupdateCheckerGit(JavaPlugin plugin) {
|
||||
|
||||
public T2CupdateCheckerGit(JavaPlugin plugin, String prefix, String gitKey, Integer spigotID, String discord, Boolean updateCheckOnJoin, Boolean seePreReleaseUpdates, Integer timeInterval) {
|
||||
this.plugin = plugin;
|
||||
|
||||
String RepoURL = "https://git.t2code.net/api/v1/repos/" + gitKey + "/releases?limit=1";
|
||||
if (!seePreReleaseUpdates) {
|
||||
RepoURL = RepoURL + "&pre-release=false";
|
||||
}
|
||||
String finalRepoURL = RepoURL;
|
||||
|
||||
Bukkit.getScheduler().runTaskTimerAsynchronously(plugin, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
getVersion((webData) -> {
|
||||
T2CupdateObject update = new T2CupdateObject(
|
||||
plugin.getName(),
|
||||
plugin.getDescription().getVersion(),
|
||||
webData,
|
||||
t2CupdateObject != null && t2CupdateObject.load,
|
||||
!plugin.getDescription().getVersion().equals(webData.getVersion()),
|
||||
updateCheckOnJoin
|
||||
);
|
||||
|
||||
T2CupdateAPI.pluginVersions.put(plugin.getName(), update);
|
||||
if (T2CupdateAPI.pluginVersions.get(plugin.getName()).updateAvailable) {
|
||||
if (!update.load) {
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
update.load = true;
|
||||
T2CupdateAPI.sendUpdateMsg(prefix, discord, webData, plugin);
|
||||
}
|
||||
}.runTaskLaterAsynchronously(plugin, 600L);
|
||||
} else T2CupdateAPI.sendUpdateMsg(prefix, discord, webData, plugin);
|
||||
} else {
|
||||
if (!update.load) {
|
||||
T2Csend.console(prefix + " §2No update found.");
|
||||
update.load = true;
|
||||
}
|
||||
}
|
||||
|
||||
t2CupdateObject = update;
|
||||
|
||||
}, plugin.getDescription().getVersion(), spigotID, finalRepoURL, updateCheckOnJoin, seePreReleaseUpdates, timeInterval);
|
||||
}
|
||||
}, 0L, timeInterval * 60 * 20L);
|
||||
}
|
||||
|
||||
public void getVersion(Consumer<T2CupdateWebData> consumer, String pluginVersion, Integer spigotID, String URL, Boolean updateCheckOnJoin, Boolean seePreReleaseUpdates, Integer timeInterval) {
|
||||
|
@@ -143,15 +143,14 @@ public class CreateReportLog {
|
||||
file.delete();
|
||||
File zipFile = new File(zipPath);
|
||||
|
||||
if (!confirmUpload){
|
||||
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);
|
||||
|
||||
Files.move(Paths.get(zipPath),Paths.get(directory+"/"+zipFile.getName()));
|
||||
zipFile.delete();
|
||||
if (!confirmUpload) {
|
||||
Files.move(Paths.get(zipPath), Paths.get(directory + "/" + zipFile.getName()));
|
||||
zipFile.delete();
|
||||
directoryTemp.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" + directory + "/" + zipFile.getName());
|
||||
}
|
||||
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" + directory + "/" + zipFile.getName());
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -179,7 +178,7 @@ public class CreateReportLog {
|
||||
"<br>[prefix] <dark_red>Do not share the download URL with anyone!</dark_red>" +
|
||||
"<br><hover:show_text:'<yellow>Click to delete</yellow>'><click:run_command:'/t2code debug deleteReportLog [key]'>[prefix] <green>You can <b>delte</b> yor Debug-File by clicking me.</green>" +
|
||||
"<br>[prefix] <color:#910d06>(If you do not delete the debug file, it will be deleted automatically after <red>14</red> days!)</color></click></hover>")
|
||||
.replace("[key]", fileID).replace("[url]", downloadURL).replace("[prefix]",Util.getPrefix()));
|
||||
.replace("[key]", fileID).replace("[url]", downloadURL).replace("[prefix]", Util.getPrefix()));
|
||||
}
|
||||
T2Csend.console(Util.getPrefix() + (" <gold>A DebugLog zip has been created. You can download it here:</gold> <yellow>[url]</yellow>" +
|
||||
"<br><gold>Please enter the following key in the ticket:</gold> <yellow>[key]</yellow>." +
|
||||
|
Reference in New Issue
Block a user