diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/HMCCosmeticsPlugin.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/HMCCosmeticsPlugin.java index 30c658c1..3312a40a 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/HMCCosmeticsPlugin.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/HMCCosmeticsPlugin.java @@ -26,6 +26,7 @@ import com.jeff_media.updatechecker.UpdateChecker; import org.bstats.bukkit.Metrics; import org.bukkit.Bukkit; import org.bukkit.Location; +import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.permissions.Permission; @@ -46,6 +47,8 @@ public final class HMCCosmeticsPlugin extends JavaPlugin { private static YamlConfigurationLoader configLoader; private static final int pluginId = 13873; private static boolean hasModelEngine = false; + private static boolean onLatestVersion = true; + private static String latestVersion = ""; @Override public void onEnable() { @@ -62,11 +65,24 @@ public final class HMCCosmeticsPlugin extends JavaPlugin { } // Update Checker - new UpdateChecker(this, UpdateCheckSource.POLYMART, "1879") - .setDownloadLink("https://polymart.org/resource/1879") + UpdateChecker checker = new UpdateChecker(this, UpdateCheckSource.POLYMART, "1879") + .onSuccess((commandSenders, latestVersion) -> { + this.latestVersion = (String) latestVersion; + if (!this.latestVersion.equalsIgnoreCase(getDescription().getVersion())) { + getLogger().info("+++++++++++++++++++++++++++++++++++"); + getLogger().info("There is a new update for HMCCosmetics!"); + getLogger().info("Please download it as soon as possible for possible fixes and new features."); + getLogger().info("Current Version " + getDescription().getVersion() + " | Latest Version " + latestVersion); + getLogger().info("Spigot: https://www.spigotmc.org/resources/100107/"); + getLogger().info("Polymart: https://polymart.org/resource/1879"); + getLogger().info("+++++++++++++++++++++++++++++++++++"); + } + }) + .setNotifyRequesters(false) + .setNotifyOpsOnJoin(false) .checkEveryXHours(24) .checkNow(); - + onLatestVersion = checker.isUsingLatestVersion(); // File setup if (!getDataFolder().exists()) { saveDefaultConfig(); @@ -241,4 +257,10 @@ public final class HMCCosmeticsPlugin extends JavaPlugin { public static boolean hasModelEngine() { return hasModelEngine; } + public static boolean isOnLatestVersion() { + return onLatestVersion; + } + public static String getLatestVersion() { + return latestVersion; + } } diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/listener/PlayerConnectionListener.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/listener/PlayerConnectionListener.java index a6c91772..88ea466f 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/listener/PlayerConnectionListener.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/listener/PlayerConnectionListener.java @@ -18,6 +18,18 @@ public class PlayerConnectionListener implements Listener { @EventHandler public void onPlayerJoin(PlayerJoinEvent event) { + if (event.getPlayer().isOp() || event.getPlayer().hasPermission("hmccosmetics.notifyupdate")) { + if (!HMCCosmeticsPlugin.getLatestVersion().equalsIgnoreCase(HMCCosmeticsPlugin.getInstance().getDescription().getVersion()) && HMCCosmeticsPlugin.getLatestVersion() != null) + MessagesUtil.sendMessageNoKey( + event.getPlayer(), + "
" + + "There is a new version of HMCCosmetics available!
" + + "Current version: " + HMCCosmeticsPlugin.getInstance().getDescription().getVersion() + " | Latest version: " + HMCCosmeticsPlugin.getLatestVersion() + "
" + + "Download it on Spigot or Polymart!" + + "
" + ); + } + Runnable run = () -> { CosmeticUser user = Database.get(event.getPlayer().getUniqueId()); CosmeticUsers.addUser(user);