11.6 Perform Update in Update Checker

This commit is contained in:
JaTiTV 2022-04-19 01:29:24 +02:00
parent abf95ecf0c
commit f27ec3c985
3 changed files with 28 additions and 24 deletions

View File

@ -6,7 +6,7 @@
<groupId>net.t2code</groupId>
<artifactId>T2CodeLib</artifactId>
<version>11.5</version>
<version>11.6</version>
<packaging>jar</packaging>
<name>T2CodeLib</name>

View File

@ -25,22 +25,27 @@ public class UpdateAPI {
public static HashMap<String, UpdateObject> PluginVersionen = new HashMap<>();
public static void join(Plugin plugin, String prefix, String perm, Player player, String spigot, String discord) {
String pluginVersion = plugin.getDescription().getVersion();
if (!player.hasPermission(perm) && !player.isOp()) {
return;
}
if (UpdateAPI.PluginVersionen.get(plugin.getName()) == null) {
new BukkitRunnable() {
@Override
public void run() {
join(plugin, prefix, perm, player, spigot, discord);
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {
@Override
public void run() {
String pluginVersion = plugin.getDescription().getVersion();
if (!player.hasPermission(perm) && !player.isOp()) {
return;
}
}.runTaskLater(plugin, 20L);
} else use(plugin, prefix, player, pluginVersion, UpdateAPI.PluginVersionen.get(plugin.getName()).publicVersion, spigot, discord);
if (UpdateAPI.PluginVersionen.get(plugin.getName()) == null) {
new BukkitRunnable() {
@Override
public void run() {
join(plugin, prefix, perm, player, spigot, discord);
}
}.runTaskLater(plugin, 20L);
} else use(plugin, prefix, player, pluginVersion, UpdateAPI.PluginVersionen.get(plugin.getName()).publicVersion, spigot, discord);
}
});
}
private static void use(Plugin plugin, String prefix, Player player, String pluginVersion, String publicVersion, String spigot, String discord) {
new BukkitRunnable() {
Bukkit.getScheduler().runTaskLaterAsynchronously(plugin, new Runnable() {
@Override
public void run() {
if (!pluginVersion.equals(publicVersion)) {
@ -49,19 +54,19 @@ public class UpdateAPI {
}
}
}
}.runTaskLater(plugin, 200L);
}, 200L);
}
public static void sendUpdateMsg(String Prefix, String Spigot, String Discord, String pluginVersion, String publicVersion) {
send.console("§4=========== " + Prefix + " §4===========");
if (publicVersion.toLowerCase().contains("dev") || publicVersion.toLowerCase().contains("beta") || publicVersion.toLowerCase().contains("snapshot")){
if (publicVersion.toLowerCase().contains("dev")){
if (publicVersion.toLowerCase().contains("dev") || publicVersion.toLowerCase().contains("beta") || publicVersion.toLowerCase().contains("snapshot")) {
if (publicVersion.toLowerCase().contains("dev")) {
send.console("§6A new §4DEV§6 version was found!");
}
if (publicVersion.toLowerCase().contains("beta")){
if (publicVersion.toLowerCase().contains("beta")) {
send.console("§6A new §2BETA§6 version was found!");
}
if (publicVersion.toLowerCase().contains("snapshot")){
if (publicVersion.toLowerCase().contains("snapshot")) {
send.console("§6A new §eSNAPSHOT§6 version was found!");
}
} else {
@ -78,18 +83,18 @@ public class UpdateAPI {
return;
}
send.player(player, Prefix);
if (publicVersion.toLowerCase().contains("dev") || publicVersion.toLowerCase().contains("beta") || publicVersion.toLowerCase().contains("snapshot")){
if (publicVersion.toLowerCase().contains("dev")){
if (publicVersion.toLowerCase().contains("dev") || publicVersion.toLowerCase().contains("beta") || publicVersion.toLowerCase().contains("snapshot")) {
if (publicVersion.toLowerCase().contains("dev")) {
TextComponent comp = new TextBuilder(Prefix + " §6A new §4DEV§6 version was found!")
.addHover("§6You can download it here: §e" + Spigot).addClickEvent(ClickEvent.Action.OPEN_URL, Spigot).build();
player.spigot().sendMessage(comp);
}
if (publicVersion.toLowerCase().contains("beta")){
if (publicVersion.toLowerCase().contains("beta")) {
TextComponent comp = new TextBuilder(Prefix + " §6A new §2BETA§6 version was found!")
.addHover("§6You can download it here: §e" + Spigot).addClickEvent(ClickEvent.Action.OPEN_URL, Spigot).build();
player.spigot().sendMessage(comp);
}
if (publicVersion.toLowerCase().contains("snapshot")){
if (publicVersion.toLowerCase().contains("snapshot")) {
TextComponent comp = new TextBuilder(Prefix + " §6A new §eSNAPSHOT§6 version was found!")
.addHover("§6You can download it here: §e" + Spigot).addClickEvent(ClickEvent.Action.OPEN_URL, Spigot).build();
player.spigot().sendMessage(comp);
@ -152,7 +157,7 @@ public class UpdateAPI {
}
public void getVersion(Consumer<String> consumer, String Prefix, String pluginVersion) {
if (!plugin.isEnabled()){
if (!plugin.isEnabled()) {
return;
}
Bukkit.getScheduler().runTaskAsynchronously(this.plugin, () -> {

View File

@ -13,7 +13,6 @@ public class JoinEvent implements Listener {
@EventHandler
public void onJoinEvent(PlayerLoginEvent event) {
Player player = event.getPlayer();
UpdateAPI.join(Main.plugin, Util.getPrefix(), "t2code.lib.updatemsg", event.getPlayer(), Main.spigot, Main.discord);
}
}