Stop checking for updates upstream
This commit is contained in:
1 parent
b1c3f3ab73
commit
ef6d26e34a
3 files changed
+4
-104
No files matched your search
@@ -0,0 +1,3 @@
|
||||
v1.0.2:
|
||||
|
||||
- Stop checking for updates from upstream.
|
||||
+1
-1
@@ -29,7 +29,7 @@ kotlin { jvmToolchain(17) }
|
||||
/* ----------------------------- Metadata ------------------------------ */
|
||||
group = "net.trueog.hologram-og"
|
||||
|
||||
version = "1.0.1" // Declare plugin version (will be in .jar).
|
||||
version = "1.0.2" // Declare plugin version (will be in .jar).
|
||||
|
||||
val apiVersion = "1.19" // Declare minecraft server target version.
|
||||
|
||||
|
||||
-103
@@ -1,23 +1,13 @@
|
||||
package org.blackninja745studios.lightweightholograms;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.event.ClickEvent;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.format.TextDecoration;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.parser.JSONParser;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Scanner;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public final class LightweightHolograms extends JavaPlugin implements Listener {
|
||||
@@ -61,13 +51,8 @@ public final class LightweightHolograms extends JavaPlugin implements Listener {
|
||||
|
||||
getLogger().log(Level.INFO, "Successfully loaded!");
|
||||
|
||||
if (!getConfig().isSet("check-versions"))
|
||||
getConfig().set("check-versions", true);
|
||||
saveConfig();
|
||||
|
||||
if (getConfig().getBoolean("check-versions"))
|
||||
outdated = checkUpdates();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -86,29 +71,6 @@ public final class LightweightHolograms extends JavaPlugin implements Listener {
|
||||
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onJoin(PlayerJoinEvent e) {
|
||||
|
||||
if (getConfig().getBoolean("check-versions")
|
||||
&& (e.getPlayer().isOp() || e.getPlayer().hasPermission("holograms.command")) && outdated)
|
||||
{
|
||||
|
||||
e.getPlayer()
|
||||
.sendMessage(appendPluginPrefix(Component.text(
|
||||
"Warning! This version of LightweightHolograms is outdated! (" + version + ")",
|
||||
NamedTextColor.WHITE)));
|
||||
e.getPlayer().sendMessage(Component
|
||||
.text("For latest performance and security updates, please download the latest version ",
|
||||
NamedTextColor.WHITE)
|
||||
.append(Component.text("here", NamedTextColor.WHITE)
|
||||
.clickEvent(ClickEvent.openUrl("https://modrinth.com/plugin/lightweightholograms"))
|
||||
.decorate(TextDecoration.UNDERLINED))
|
||||
.append(Component.text("!", NamedTextColor.WHITE)));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static Component appendPluginPrefix(Component c) {
|
||||
|
||||
return Component.text("[", NamedTextColor.DARK_GRAY).append(Component.text("Lightweight", NamedTextColor.GREEN))
|
||||
@@ -117,69 +79,4 @@ public final class LightweightHolograms extends JavaPlugin implements Listener {
|
||||
|
||||
}
|
||||
|
||||
public boolean checkUpdates() {
|
||||
|
||||
getLogger().log(Level.INFO, "Checking version... (You can disable this in config.yml)");
|
||||
try {
|
||||
|
||||
URL url = new URL("https://api.github.com/repos/MSKatKing/LightweightHolograms/releases/latest");
|
||||
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
||||
conn.setRequestMethod("GET");
|
||||
conn.connect();
|
||||
|
||||
InputStream inputStream = conn.getInputStream();
|
||||
String response = new Scanner(inputStream, "UTF-8").useDelimiter("\\A").next();
|
||||
|
||||
JSONObject assets = (JSONObject) (new JSONParser().parse(response));
|
||||
|
||||
if (!assets.isEmpty()) {
|
||||
|
||||
String latestVersion = (String) assets.get("tag_name");
|
||||
|
||||
String[] latest = latestVersion.split("\\.");
|
||||
String[] current = version.split("\\.");
|
||||
|
||||
int length = Math.max(latest.length, current.length);
|
||||
|
||||
for (int i = 0; i < length; i++) {
|
||||
|
||||
int part1 = i < latest.length ? Integer.parseInt(latest[i]) : 0;
|
||||
int part2 = i < current.length ? Integer.parseInt(current[i]) : 0;
|
||||
|
||||
if (part2 > part1) {
|
||||
|
||||
getLogger().log(Level.WARNING,
|
||||
"This version is ahead of the latest version (v" + latestVersion
|
||||
+ "), which means it is a dev version (v" + version
|
||||
+ "). Please proceed with caution!");
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
if (part1 > part2) {
|
||||
|
||||
getLogger().log(Level.INFO, "New version found! (" + latestVersion
|
||||
+ ") Don't forget to download it at https://modrinth.com/plugin/lightweightholograms!");
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
getLogger().log(Level.INFO, "No new updates found!");
|
||||
|
||||
} catch (Exception e) {
|
||||
|
||||
getLogger().log(Level.WARNING,
|
||||
"Unable to check for updates! Please consult https://modrinth.com/plugin/lightweightholograms to see if there is a later version available.");
|
||||
getLogger().log(Level.WARNING, e.getMessage());
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user