Skip to content

Commit

Permalink
feat(UpdateChecker): show version and click on version to open url
Browse files Browse the repository at this point in the history
  • Loading branch information
ezTxmMC committed Jul 27, 2024
1 parent 609a768 commit 926b25b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import de.eztxm.luckprefix.LuckPrefix;
import de.eztxm.luckprefix.util.GroupManager;
import de.eztxm.luckprefix.util.PlayerManager;
import de.eztxm.luckprefix.util.TextUtil;
import de.eztxm.luckprefix.util.UpdateChecker;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import net.luckperms.api.LuckPerms;
import net.luckperms.api.LuckPermsProvider;
Expand Down Expand Up @@ -36,12 +36,11 @@ public void onJoin(PlayerJoinEvent event) {
}, 1, config.getLong("UpdateTime") * 20);
playerManager.addJoinScheduler(player.getUniqueId(), bukkitTask);
playerManager.addUserGroup(player.getUniqueId(), group);
if (!new UpdateChecker(LuckPrefix.getInstance().getDescription().getVersion()).latestVersion()) {
UpdateChecker checker = new UpdateChecker(LuckPrefix.getInstance().getDescription().getVersion());
if (!checker.latestVersion()) {
player.sendMessage(ChatColor.translateAlternateColorCodes('&',
LegacyComponentSerializer.legacyAmpersand().serialize(
MiniMessage.miniMessage().deserialize(LuckPrefix.getInstance().getPrefix() +
"There is a new update available: https://modrinth.com/plugin/luckprefix")
)
LegacyComponentSerializer.legacyAmpersand().serialize(new TextUtil(LuckPrefix.getInstance().getPrefix() +
"There is a new update available: <u><click:open_url:https://modrinth.com/plugin/luckprefix>" + checker.getLatestVersion()).miniMessage())
));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,22 @@ public UpdateChecker(String version) {
}

public boolean latestVersion() {
String latestVersion = getLatestVersion();
if (latestVersion == null) return true;
return latestVersion.equalsIgnoreCase(version);
}

public String getLatestVersion() {
try {
String urlString = "https://cdn.eztxm.de/plugin/luckprefix/manifest.json";
URL url = new URL(urlString);
BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
String line = reader.readLine();
JSONObject jsonObject = new JSONObject(line);
return jsonObject.getString("Latest-Version").equalsIgnoreCase(version);
return jsonObject.getString("Latest-Version");
} catch (IOException e) {
return true;
e.fillInStackTrace();
}
return null;
}
}
}

0 comments on commit 926b25b

Please sign in to comment.