Skip to content

Commit

Permalink
Updated version command
Browse files Browse the repository at this point in the history
Check if update is available if `/mcaip version` is executed
  • Loading branch information
Shweit committed Sep 3, 2024
1 parent c1f17d9 commit 7d9dac8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.shweit.serverapi.MinecraftServerAPI;
import com.shweit.serverapi.commands.SubCommand;
import com.shweit.serverapi.utils.CheckForUpdate;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
Expand All @@ -27,6 +28,20 @@ public String getSyntax() {
@Override
public void perform(final CommandSender commandSender, final Command command, final String label, final String[] args) {
commandSender.sendMessage(ChatColor.GREEN + "MinecraftServerAPI version: " + ChatColor.GOLD + MinecraftServerAPI.getInstance().getDescription().getVersion());
commandSender.sendMessage("");
commandSender.sendMessage(ChatColor.GREEN + "Check for updates...");

// Check for updates
CheckForUpdate checkForUpdate = new CheckForUpdate();
boolean updateAvailable = checkForUpdate.checkForPluginUpdate();
if (updateAvailable) {
commandSender.sendMessage(ChatColor.GREEN + "Update available! New Version: "
+ ChatColor.GOLD + MinecraftServerAPI.getInstance().getDescription().getVersion()
+ ChatColor.GREEN + " -> " + ChatColor.GOLD + checkForUpdate.latestVersion
);
} else {
commandSender.sendMessage(ChatColor.GREEN + "No updates available.");
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public final class CheckForUpdate implements Listener {

private static final String GITHUB_API_URL = "https://api.github.com/repos/Shweit/MinecraftServerAPI/releases/latest";
private static final String USER_AGENT = "Mozilla/5.0";
private String latestVersion;
public String latestVersion;

public boolean checkForPluginUpdate() {
latestVersion = fetchLatestVersion();
Expand Down

0 comments on commit 7d9dac8

Please sign in to comment.