-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
791 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
src/main/java/io/github/lucfr1746/LWardrobe/Metrics/UpdateChecker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package io.github.lucfr1746.LWardrobe.Metrics; | ||
|
||
import io.github.lucfr1746.LWardrobe.LWardrobe; | ||
import org.bukkit.Bukkit; | ||
import org.bukkit.ChatColor; | ||
import org.bukkit.plugin.PluginDescriptionFile; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
import java.util.Scanner; | ||
import java.util.function.Consumer; | ||
|
||
public class UpdateChecker { | ||
|
||
private final LWardrobe plugin; | ||
|
||
public UpdateChecker(LWardrobe plugin) { | ||
this.plugin = plugin; | ||
check(-1); | ||
} | ||
|
||
public void getLatestVersion(Consumer<String> consumer, int resourceId) { | ||
try (InputStream inputStream = new URI("https://api.spigotmc.org/legacy/update.php?resource=" + resourceId).toURL().openStream(); | ||
Scanner scanner = new Scanner(inputStream)) { | ||
|
||
if (scanner.hasNext()) { | ||
consumer.accept(scanner.next()); | ||
} | ||
} catch (IOException | URISyntaxException exception) { | ||
plugin.getLogger().info("Update checker is broken, can't find an update! " + exception.getMessage()); | ||
} | ||
} | ||
|
||
public void check(int resourceId) { | ||
// getLatestVersion(version -> { | ||
// PluginDescriptionFile pdf = plugin.getDescription(); | ||
// // Check if the current version matches the latest version. | ||
// if (pdf.getVersion().equalsIgnoreCase(version)) { | ||
// this.plugin.getLogger().info("Version: " + ChatColor.GREEN + pdf.getVersion()); | ||
// this.plugin.getLogger().info("Plugin is up to date!"); | ||
// } else { | ||
// this.plugin.getLogger().info("Version: " + ChatColor.RED + pdf.getVersion()); | ||
// this.plugin.getLogger().info("Plugin has an update! Download at: https://www.spigotmc.org/resources/" + resourceId); | ||
// } | ||
// }, resourceId); | ||
} | ||
} |
Oops, something went wrong.