customizable time interval for the UpdateChecker

This commit is contained in:
JaTiTV 2021-12-31 02:36:03 +01:00
parent 9d0902f611
commit 6cbae613a3
10 changed files with 21 additions and 16 deletions

View File

@ -82,9 +82,12 @@ public class UpdateAPI {
private static Boolean noUpdate = true; private static Boolean noUpdate = true;
public static void onUpdateCheck(Plugin plugin, String Prefix, String Spigot, int SpigotID, String Discord) { public static void onUpdateCheck(Plugin plugin, String Prefix, String Spigot, int SpigotID, String Discord) {
onUpdateCheck(plugin, Prefix, Spigot, SpigotID, Discord, 60);
}
public static void onUpdateCheck(Plugin plugin, String Prefix, String Spigot, int SpigotID, String Discord, Integer timeInMin) {
int taskID = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() { int taskID = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {
public void run() { public void run() {
(new UpdateAPI((JavaPlugin) plugin, SpigotID)).getVersion((update_version) -> { (new UpdateAPI((JavaPlugin) plugin, SpigotID)).getVersion((update_version) -> {
UpdateObject update = new UpdateObject( UpdateObject update = new UpdateObject(
plugin.getName(), plugin.getName(),
@ -92,7 +95,6 @@ public class UpdateAPI {
update_version update_version
); );
UpdateAPI.PluginVersionen.put(plugin.getName(), update); UpdateAPI.PluginVersionen.put(plugin.getName(), update);
if (!plugin.getDescription().getVersion().equalsIgnoreCase(update_version)) { if (!plugin.getDescription().getVersion().equalsIgnoreCase(update_version)) {
noUpdate = true; noUpdate = true;
new BukkitRunnable() { new BukkitRunnable() {
@ -102,7 +104,6 @@ public class UpdateAPI {
} }
}.runTaskLater(plugin, 600L); }.runTaskLater(plugin, 600L);
} else { } else {
if (noUpdate) { if (noUpdate) {
send.console(Prefix + " §2No update found."); send.console(Prefix + " §2No update found.");
noUpdate = false; noUpdate = false;
@ -110,7 +111,7 @@ public class UpdateAPI {
} }
}, Prefix, plugin.getDescription().getVersion()); }, Prefix, plugin.getDescription().getVersion());
} }
}, 0L, 20 * 60 * 60L); }, 0L, timeInMin * 60 * 20L);
} }
private JavaPlugin plugin; private JavaPlugin plugin;

View File

@ -48,18 +48,17 @@ public final class Main extends JavaPlugin {
plugin = this; plugin = this;
autor = plugin.getDescription().getAuthors(); autor = plugin.getDescription().getAuthors();
version = plugin.getDescription().getVersion(); version = plugin.getDescription().getVersion();
UpdateAPI.onUpdateCheck(plugin, prefix, spigot, spigotID, discord);
new UpdateChecker(this, 12345).getVersion(ver -> {
if (this.getDescription().getVersion().equals(version)) {
if (Double.parseDouble(ver) < Double.parseDouble(version)) {
send.console(prefix + " §4 §e-------------------");
send.console(prefix + " §eYou are running §4" + version + " §eof " + prefix + "§e! §4This is a trial version! §eSome features may not be working as expected. Please report all bugs here: http://dc.t2code.net §4UpdateChecker & bStats may be disabled!");
send.console(prefix + " §4 §e-------------------");
}
}
});
Long long_; Long long_;
long_ = T2CodeTemplate.onLoadHeader(prefix, autor, version, spigot, discord); long_ = T2CodeTemplate.onLoadHeader(prefix, autor, version, spigot, discord);
if (Util.getSnapshot()){
send.console(prefix + " §eYou are running §4" + version + " §eof " + prefix + "§e! §4This is a trial version! §eSome features may not be working as expected. Please report all bugs here: http://dc.t2code.net §4UpdateChecker & bStats may be disabled!");
send.console(prefix + " §4 §e-------------------");
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
//send.console("§4 _|_|_|_|_| _|_| _|_|_| _| "); //send.console("§4 _|_|_|_|_| _|_| _|_|_| _| ");
//send.console("§4 _| _| _| _| _|_| _|_|_| _|_| "); //send.console("§4 _| _| _| _| _|_| _|_|_| _|_| ");
@ -109,6 +108,7 @@ public final class Main extends JavaPlugin {
LanguagesCreate.langCreate(); LanguagesCreate.langCreate();
SelectLibConfig.onSelect(); SelectLibConfig.onSelect();
SelectLibMsg.onSelect(prefix); SelectLibMsg.onSelect(prefix);
UpdateAPI.onUpdateCheck(plugin, prefix, spigot, spigotID, discord);
Metrics.Bstats(plugin, bstatsID); Metrics.Bstats(plugin, bstatsID);
Bukkit.getServer().getPluginManager().registerEvents(new JoinEvent(), plugin); Bukkit.getServer().getPluginManager().registerEvents(new JoinEvent(), plugin);

View File

@ -12,6 +12,7 @@ import java.io.IOException;
public class ConfigCreate { public class ConfigCreate {
private static Boolean UpdateCheckOnJoin = true; private static Boolean UpdateCheckOnJoin = true;
private static Integer UpdateCheckTimeInterval = 60;
private static Boolean Debug = false; private static Boolean Debug = false;
private static String language = "english"; private static String language = "english";
@ -38,7 +39,8 @@ public class ConfigCreate {
File config = new File(Main.getPath(), "config.yml"); File config = new File(Main.getPath(), "config.yml");
YamlConfiguration yamlConfiguration = YamlConfiguration.loadConfiguration(config); YamlConfiguration yamlConfiguration = YamlConfiguration.loadConfiguration(config);
Config.set("Plugin.UpdateCheckOnJoin", UpdateCheckOnJoin, yamlConfiguration); Config.set("Plugin.UpdateCheck.OnJoin", UpdateCheckOnJoin, yamlConfiguration);
Config.set("Plugin.UpdateCheck.TimeInterval", UpdateCheckTimeInterval, yamlConfiguration);
Config.set("Plugin.language", language, yamlConfiguration); Config.set("Plugin.language", language, yamlConfiguration);
Config.set("BungeeCord.Enable", Bungee, yamlConfiguration); Config.set("BungeeCord.Enable", Bungee, yamlConfiguration);

View File

@ -9,6 +9,7 @@ public class SelectLibConfig {
public static Boolean UpdateCheckOnJoin; public static Boolean UpdateCheckOnJoin;
public static Integer UpdateCheckTimeInterval;
public static Boolean Debug; public static Boolean Debug;
public static String language; public static String language;
public static Boolean InventoriesCloseByServerStop; public static Boolean InventoriesCloseByServerStop;
@ -17,7 +18,8 @@ public class SelectLibConfig {
File config = new File(Main.getPath(), "config.yml"); File config = new File(Main.getPath(), "config.yml");
YamlConfiguration yamlConfiguration = YamlConfiguration.loadConfiguration(config); YamlConfiguration yamlConfiguration = YamlConfiguration.loadConfiguration(config);
UpdateCheckOnJoin = yamlConfiguration.getBoolean("Plugin.UpdateCheckOnJoin"); UpdateCheckOnJoin = yamlConfiguration.getBoolean("Plugin.UpdateCheck.OnJoin");
UpdateCheckTimeInterval = yamlConfiguration.getInt("Plugin.UpdateCheck.TimeInterval");
Debug = yamlConfiguration.getBoolean("Plugin.Debug"); Debug = yamlConfiguration.getBoolean("Plugin.Debug");
language = yamlConfiguration.getString("Plugin.language"); language = yamlConfiguration.getString("Plugin.language");
InventoriesCloseByServerStop = yamlConfiguration.getBoolean("Player.Inventories.CloseByServerStop"); InventoriesCloseByServerStop = yamlConfiguration.getBoolean("Player.Inventories.CloseByServerStop");