16.7_dev-19
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
package net.t2code.t2codelib.SPIGOT.api.update;
|
||||
|
||||
import net.t2code.t2codelib.SPIGOT.api.messages.T2C_Send;
|
||||
import net.t2code.t2codelib.SPIGOT.system.T2CodeLibMain;
|
||||
import net.t2code.t2codelib.SPIGOT.system.T2C_Main;
|
||||
import net.t2code.t2codelib.SPIGOT.system.config.config.T2C_LibConfig;
|
||||
import net.t2code.t2codelib.UpdateType;
|
||||
import net.t2code.t2codelib.T2CupdateObject;
|
||||
import net.t2code.t2codelib.T2CupdateWebData;
|
||||
import net.t2code.t2codelib.Util;
|
||||
import net.t2code.t2codelib.util.T2C_UpdateType;
|
||||
import net.t2code.t2codelib.util.T2C_UpdateObject;
|
||||
import net.t2code.t2codelib.util.T2C_UpdateWebData;
|
||||
import net.t2code.t2codelib.util.T2C_Util;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
@@ -16,16 +16,11 @@ import org.bukkit.scheduler.BukkitRunnable;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class T2C_UpdateAPI {
|
||||
public static HashMap<String, T2CupdateObject> pluginVersions = new HashMap<>();
|
||||
public static HashMap<String, T2C_UpdateObject> pluginVersions = new HashMap<>();
|
||||
|
||||
public static void join(Plugin plugin, String prefix, String perm, Player player, Integer spigotID, String discord) {
|
||||
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);
|
||||
Bukkit.getScheduler().runTaskLaterAsynchronously(T2C_Main.getPlugin(), () -> join(plugin, prefix, perm, player, spigotID, discord), 2 * 20L);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -44,22 +39,23 @@ public class T2C_UpdateAPI {
|
||||
}.runTaskLaterAsynchronously(plugin, 20L);
|
||||
return;
|
||||
}
|
||||
T2CupdateWebData webData = pluginVersions.get(plugin.getName()).webData;
|
||||
T2C_UpdateWebData webData = pluginVersions.get(plugin.getName()).webData;
|
||||
if (!pluginVersions.get(plugin.getName()).updateAvailable) return;
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
sendUpdateMsg(prefix, webData, discord, plugin, player);
|
||||
}
|
||||
}.runTaskLaterAsynchronously(T2CodeLibMain.getPlugin(), 200L);
|
||||
}.runTaskLaterAsynchronously(T2C_Main.getPlugin(), 200L);
|
||||
}
|
||||
|
||||
public static void sendUpdateMsg(String prefix, T2CupdateWebData webData, String discord, Plugin plugin, Player player) {
|
||||
public static void sendUpdateMsg(String prefix, T2C_UpdateWebData webData, String discord, Plugin plugin, Player player) {
|
||||
String publicVersion = webData.getVersion();
|
||||
String pluginVersion = plugin.getDescription().getVersion();
|
||||
if (!pluginVersions.get(plugin.getName()).updateAvailable) {
|
||||
return;
|
||||
}
|
||||
String updateStatusVersion = getUpdateType(webData);
|
||||
String st = "[prefix]<br>" +
|
||||
"<click:open_url:'[link]'><hover:show_text:'<color:#6e90ff>You can download it here: <yellow>[link]</yellow></color>'>[prefix] <color:#6e90ff>A new</color> [value] <color:#6e90ff>version was" +
|
||||
" found!</color></hover></click><br>" +
|
||||
@@ -69,81 +65,40 @@ public class T2C_UpdateAPI {
|
||||
"[prefix] <color:#ff9499><hover:show_text:'<red>Click for more information</red>'><click:run_command:'/t2c updateinfo " + plugin.getName() + "'>Update information</click></hover></color><br>" +
|
||||
"[prefix]";
|
||||
|
||||
String updateStatusVersion;
|
||||
|
||||
if (webData.isPreRelease()) {
|
||||
//todo if (!SelectLibConfig.getSeePreReleaseUpdates()) return;
|
||||
updateStatusVersion = UpdateType.PRERELEASE.text;
|
||||
if (publicVersion.toLowerCase().contains("dev")) {
|
||||
updateStatusVersion = UpdateType.DEVELOPMENT.text;
|
||||
}
|
||||
if (publicVersion.toLowerCase().contains("beta")) {
|
||||
updateStatusVersion = UpdateType.BETA.text;
|
||||
}
|
||||
if (publicVersion.toLowerCase().contains("snapshot")) {
|
||||
updateStatusVersion = UpdateType.SNAPSHOT.text;
|
||||
}
|
||||
} else updateStatusVersion = UpdateType.STABLE.text;
|
||||
|
||||
T2C_Send.player(player, st.replace("[prefix]", prefix).replace("[value]", updateStatusVersion).replace("[link]", webData.getUpdateUrl())
|
||||
.replace("[plv]", pluginVersion).replace("[puv]", publicVersion).replace("[dc]", discord));
|
||||
}
|
||||
|
||||
public static void sendUpdateMsg(String prefix, String discord, T2CupdateWebData webData, Plugin plugin) {
|
||||
public static void sendUpdateMsg(String prefix, String discord, T2C_UpdateWebData webData, Plugin plugin) {
|
||||
String publicVersion = webData.getVersion();
|
||||
String pluginVersion = plugin.getDescription().getVersion();
|
||||
String updateStatusVersion;
|
||||
if (webData.isPreRelease()) {
|
||||
updateStatusVersion = UpdateType.PRERELEASE.text;
|
||||
if (publicVersion.toLowerCase().contains("dev")) {
|
||||
updateStatusVersion = UpdateType.DEVELOPMENT.text;
|
||||
}
|
||||
if (publicVersion.toLowerCase().contains("beta")) {
|
||||
updateStatusVersion = UpdateType.BETA.text;
|
||||
}
|
||||
if (publicVersion.toLowerCase().contains("snapshot")) {
|
||||
updateStatusVersion = UpdateType.SNAPSHOT.text;
|
||||
}
|
||||
} else updateStatusVersion = UpdateType.STABLE.text;
|
||||
String s1 = " <color:#6e90ff>A new [value] version was found!</color>".replace("[value]", updateStatusVersion);
|
||||
String s2 = " <color:#6e90ff>Your version: <red>" + pluginVersion + "</red> <gray>-</gray> Current version:</color> <green>" + webData.getVersion() + "</green>";
|
||||
String s3 = " <color:#6e90ff>You can download it here:</color> <yellow>" + webData.getUpdateUrl() + "</yellow>";
|
||||
String s4 = " <color:#6e90ff>You can find more information on Discord:</color> <yellow>" + discord + "</yellow>";
|
||||
String updateStatusVersion = getUpdateType(webData);
|
||||
String s1 = "<color:#6e90ff>A new [value] version was found!</color>".replace("[value]", updateStatusVersion);
|
||||
String s2 = "<color:#6e90ff>Your version: <red>" + pluginVersion + "</red> <gray>-</gray> Current version:</color> <green>" + webData.getVersion() + "</green>";
|
||||
String s3 = "<color:#6e90ff>You can download it here:</color> <yellow>" + webData.getUpdateUrl() + "</yellow>";
|
||||
String s4 = "<color:#6e90ff>You can find more information on Discord:</color> <yellow>" + discord + "</yellow>";
|
||||
|
||||
T2C_Send.sendFrameCenter(prefix,s1,s2,s3,s4);
|
||||
T2C_Send.console(T2C_Send.getFrameCenter(prefix, true, s1, s2, s3, s4));
|
||||
}
|
||||
|
||||
public static String updateInfo(String[] args, Boolean player) {
|
||||
T2CupdateObject object;
|
||||
T2C_UpdateObject object;
|
||||
try {
|
||||
object = T2C_UpdateAPI.pluginVersions.get(args[1]);
|
||||
} catch (Exception e) {
|
||||
return Util.getPrefix() + " <red>The plugin <yellow>" + args[1] + "</yellow> is not registered in the update checker of T2Code!</red>";
|
||||
return T2C_Util.getPrefix() + " <red>The plugin <yellow>" + args[1] + "</yellow> is not registered in the update checker of T2Code!</red>";
|
||||
}
|
||||
if (object == null) return Util.getPrefix() + " <red>The plugin <yellow>" + args[1] + "</yellow> is not registered in the update checker of T2Code!</red>";
|
||||
T2CupdateWebData webData = object.webData;
|
||||
if (object == null) return T2C_Util.getPrefix() + " <red>The plugin <yellow>" + args[1] + "</yellow> is not registered in the update checker of T2Code!</red>";
|
||||
T2C_UpdateWebData webData = object.webData;
|
||||
if (webData == null) {
|
||||
return Util.getPrefix() + " <b><dark_red>It could not be checked for updates with the plugin <yellow>" + args[1] + "</yellow>!</dark_red></b>";
|
||||
return T2C_Util.getPrefix() + " <b><dark_red>It could not be checked for updates with the plugin <yellow>" + args[1] + "</yellow>!</dark_red></b>";
|
||||
}
|
||||
String pluginName = T2C_UpdateAPI.pluginVersions.get(args[1]).pluginName;
|
||||
String pluginVersion = T2C_UpdateAPI.pluginVersions.get(args[1]).pluginVersion;
|
||||
|
||||
String updateTitle = webData.getUpdateTitle();
|
||||
String updateVersion = webData.getVersion();
|
||||
String updateType;
|
||||
|
||||
if (webData.isPreRelease()) {
|
||||
updateType = UpdateType.PRERELEASE.text;
|
||||
if (updateVersion.toLowerCase().contains("dev")) {
|
||||
updateType = UpdateType.DEVELOPMENT.text;
|
||||
}
|
||||
if (updateVersion.toLowerCase().contains("beta")) {
|
||||
updateType = UpdateType.BETA.text;
|
||||
}
|
||||
if (updateVersion.toLowerCase().contains("snapshot")) {
|
||||
updateType = UpdateType.SNAPSHOT.text;
|
||||
}
|
||||
} else updateType = UpdateType.STABLE.text;
|
||||
String publicVersion = webData.getVersion();
|
||||
String updateType = getUpdateType(webData);
|
||||
|
||||
String updateAt = webData.getPublishedAt();
|
||||
String updateUpdate = webData.getUpdateUrl();
|
||||
@@ -153,7 +108,7 @@ public class T2C_UpdateAPI {
|
||||
String pluginVersionString = "<br><dark_red>║</dark_red> <color:#6e90ff>Your version:</color> <color:#5eff89>" + pluginVersion + "</color>";
|
||||
String updateInfoString = "<br><dark_red>║</dark_red> <color:#09ff00>[value]:</color>";
|
||||
String updateTitleString = "<br><dark_red>║</dark_red> <color:#6e90ff>Title:</color> <color:#5eff89>" + updateTitle + "</color>";
|
||||
String updateVersionString = "<br><dark_red>║</dark_red> <color:#6e90ff>Version:</color> <color:#5eff89>" + updateVersion + "</color>";
|
||||
String updateVersionString = "<br><dark_red>║</dark_red> <color:#6e90ff>Version:</color> <color:#5eff89>" + publicVersion + "</color>";
|
||||
String updateAtString = "<br><dark_red>║</dark_red> <color:#6e90ff>Published on:</color> <color:#5eff89>" + updateAt + "</color>";
|
||||
String updateTypeString = "<br><dark_red>║</dark_red> <color:#6e90ff>Version type:</color> <color:#5eff89>" + updateType + "</color>";
|
||||
|
||||
@@ -187,4 +142,22 @@ public class T2C_UpdateAPI {
|
||||
if ((boolean) T2C_LibConfig.VALUES.updateCheckFullDisable.getValue()) return;
|
||||
new T2C_UpdateCheckerGit((JavaPlugin) plugin, prefix, gitKey, spigotID, discord, updateCheckOnJoin, seePreReleaseUpdates, timeInterval);
|
||||
}
|
||||
|
||||
private static String getUpdateType(T2C_UpdateWebData webData) {
|
||||
String updateType;
|
||||
String publicVersion = webData.getVersion();
|
||||
if (webData.isPreRelease()) {
|
||||
updateType = T2C_UpdateType.PRERELEASE.text;
|
||||
if (publicVersion.toLowerCase().contains("dev")) {
|
||||
updateType = T2C_UpdateType.DEVELOPMENT.text;
|
||||
}
|
||||
if (publicVersion.toLowerCase().contains("beta")) {
|
||||
updateType = T2C_UpdateType.BETA.text;
|
||||
}
|
||||
if (publicVersion.toLowerCase().contains("snapshot")) {
|
||||
updateType = T2C_UpdateType.SNAPSHOT.text;
|
||||
}
|
||||
} else updateType = T2C_UpdateType.STABLE.text;
|
||||
return updateType;
|
||||
}
|
||||
}
|
||||
|
@@ -1,10 +1,11 @@
|
||||
package net.t2code.t2codelib.SPIGOT.api.update;
|
||||
|
||||
import net.t2code.t2codelib.SPIGOT.api.debug.T2C_Debug;
|
||||
import net.t2code.t2codelib.SPIGOT.api.messages.T2C_Send;
|
||||
import net.t2code.t2codelib.SPIGOT.system.T2CodeLibMain;
|
||||
import net.t2code.t2codelib.SPIGOT.system.T2C_Main;
|
||||
import net.t2code.t2codelib.SPIGOT.system.config.config.T2C_LibConfig;
|
||||
import net.t2code.t2codelib.T2CupdateObject;
|
||||
import net.t2code.t2codelib.T2CupdateWebData;
|
||||
import net.t2code.t2codelib.util.T2C_UpdateObject;
|
||||
import net.t2code.t2codelib.util.T2C_UpdateWebData;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
@@ -20,7 +21,7 @@ import java.util.function.Consumer;
|
||||
|
||||
public class T2C_UpdateCheckerGit {
|
||||
private final JavaPlugin plugin;
|
||||
private T2CupdateObject t2CupdateObject;
|
||||
private T2C_UpdateObject t2CupdateObject;
|
||||
|
||||
|
||||
public T2C_UpdateCheckerGit(JavaPlugin plugin, String prefix, String gitKey, Integer spigotID, String discord, Boolean updateCheckOnJoin, Boolean seePreReleaseUpdates, Integer timeInterval) {
|
||||
@@ -42,7 +43,7 @@ public class T2C_UpdateCheckerGit {
|
||||
public void run() {
|
||||
if ((boolean) T2C_LibConfig.VALUES.updateCheckFullDisable.getValue()) return;
|
||||
getVersion((webData) -> {
|
||||
T2CupdateObject update = new T2CupdateObject(
|
||||
T2C_UpdateObject update = new T2C_UpdateObject(
|
||||
plugin.getName(),
|
||||
plugin.getDescription().getVersion(),
|
||||
webData,
|
||||
@@ -53,7 +54,7 @@ public class T2C_UpdateCheckerGit {
|
||||
|
||||
T2C_UpdateAPI.pluginVersions.put(plugin.getName(), update);
|
||||
if (T2C_UpdateAPI.pluginVersions.get(plugin.getName()) == null) {
|
||||
T2C_Send.debugmsg(T2CodeLibMain.getPlugin(), "'" + plugin.getName() + "' UpdateAPI T2CupdateAPI.pluginVersions.get(plugin.getName()) == null");
|
||||
T2C_Debug.debugmsg(T2C_Main.getPlugin(), "'" + plugin.getName() + "' UpdateAPI T2CupdateAPI.pluginVersions.get(plugin.getName()) == null");
|
||||
return;
|
||||
}
|
||||
if (T2C_UpdateAPI.pluginVersions.get(plugin.getName()).updateAvailable) {
|
||||
@@ -80,7 +81,7 @@ public class T2C_UpdateCheckerGit {
|
||||
}, 10L, finalInterval * 60 * 20L);
|
||||
}
|
||||
|
||||
public void getVersion(Consumer<T2CupdateWebData> consumer, String pluginVersion, Integer spigotID, String URL, Boolean updateCheckOnJoin, Boolean seePreReleaseUpdates, Integer timeInterval) {
|
||||
public void getVersion(Consumer<T2C_UpdateWebData> consumer, String pluginVersion, Integer spigotID, String URL, Boolean updateCheckOnJoin, Boolean seePreReleaseUpdates, Integer timeInterval) {
|
||||
if (!plugin.isEnabled()) {
|
||||
return;
|
||||
}
|
||||
@@ -128,14 +129,14 @@ public class T2C_UpdateCheckerGit {
|
||||
updateUrl = "https://www.spigotmc.org/resources/" + spigotID;
|
||||
}
|
||||
|
||||
T2CupdateWebData webData = new T2CupdateWebData(updateTitle, version, updateDescription, updateUrl, publishedAt, downloadURL, gitURL, preRelease);
|
||||
T2C_UpdateWebData webData = new T2C_UpdateWebData(updateTitle, version, updateDescription, updateUrl, publishedAt, downloadURL, gitURL, preRelease);
|
||||
consumer.accept(webData);
|
||||
} catch (Exception exception) {
|
||||
Boolean load = false;
|
||||
if (T2C_UpdateAPI.pluginVersions.containsKey(plugin.getName())) {
|
||||
load = T2C_UpdateAPI.pluginVersions.get(plugin.getName()).load;
|
||||
}
|
||||
T2CupdateObject update = new T2CupdateObject(
|
||||
T2C_UpdateObject update = new T2C_UpdateObject(
|
||||
plugin.getName(),
|
||||
pluginVersion,
|
||||
null,
|
||||
|
Reference in New Issue
Block a user