From 2792d09bac1d6346d2fc2c22d267f67bf2f1fe13 Mon Sep 17 00:00:00 2001 From: ThisTestUser Date: Tue, 24 Sep 2024 16:20:31 +0000 Subject: [PATCH] Revamp version check and delete update check + Bump plugin version --- build.gradle.kts | 2 +- .../solarrabbit/largeraids/LargeRaids.java | 26 ++++------ .../largeraids/ResourceChecker.java | 35 -------------- .../trigger/omen/KillCaptainListener.java | 4 +- .../largeraids/util/VersionUtil.java | 47 +------------------ 5 files changed, 13 insertions(+), 101 deletions(-) delete mode 100644 src/main/java/com/solarrabbit/largeraids/ResourceChecker.java diff --git a/build.gradle.kts b/build.gradle.kts index 930c834..da843e5 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -8,7 +8,7 @@ plugins { } group = "com.solarrabbit" -version = "1.11.1" +version = "1.11.2" description = "LargeRaids" val mcVersion = "1.20.6" diff --git a/src/main/java/com/solarrabbit/largeraids/LargeRaids.java b/src/main/java/com/solarrabbit/largeraids/LargeRaids.java index 8b95457..1e74adf 100644 --- a/src/main/java/com/solarrabbit/largeraids/LargeRaids.java +++ b/src/main/java/com/solarrabbit/largeraids/LargeRaids.java @@ -61,11 +61,17 @@ public final class LargeRaids extends JavaPlugin { public void onEnable() { logger = new PluginLogger(); - if (!VersionUtil.isSupported()) { - log("Server implementation version not supported!", Level.FAIL); - return; + if (!VersionUtil.VERSION.equals(Bukkit.getServer().getMinecraftVersion())) { + boolean skipCheck = LargeRaids.class.getResource("/BYPASS_VERSION_CHECK.txt") != null; + log(String.format("Server version is not supported! Supported Version: %s, Your Version: %s", + VersionUtil.VERSION, Bukkit.getServer().getMinecraftVersion()), Level.FAIL, false); + if (!skipCheck) { + log("You can allow the plugin to run anyways (not recommended) " + + "by placing BYPASS_VERSION_CHECK.txt inside the plugin JAR", Level.FAIL); + return; + } + log("Unexpected crashes or errors may occur!", Level.WARN); } - fetchSpigotUpdates(); // Initialize bstats final int pluginId = 13910; @@ -257,16 +263,4 @@ private boolean testConfig() { return pass; } - private void fetchSpigotUpdates() { - final int resourceId = 95422; - final String resourcePage = "https://www.spigotmc.org/resources/largeraids-1-14-x-1-18-x.95422/"; - ResourceChecker checker = new ResourceChecker(); - checker.hasUpdate(this, resourceId).whenComplete((res, ex) -> { - if (ex != null) - log("Unable to retrieve updates from spigot website", Level.WARN); - else if (res) - log("New updates available, download it at " + resourcePage, Level.WARN); - }); - } - } diff --git a/src/main/java/com/solarrabbit/largeraids/ResourceChecker.java b/src/main/java/com/solarrabbit/largeraids/ResourceChecker.java deleted file mode 100644 index 033a259..0000000 --- a/src/main/java/com/solarrabbit/largeraids/ResourceChecker.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.solarrabbit.largeraids; - -import java.io.IOException; -import java.net.URL; -import java.util.Scanner; -import java.util.concurrent.CompletableFuture; - -import com.solarrabbit.largeraids.util.VersionUtil; - -import org.bukkit.plugin.java.JavaPlugin; - -public class ResourceChecker { - private static final String UPDATE_BASE_URL = "https://api.spigotmc.org/legacy/update.php?resource="; - - public CompletableFuture hasUpdate(JavaPlugin plugin, int resourceId) { - final String pluginVersion = plugin.getDescription().getVersion(); - return CompletableFuture.supplyAsync(() -> getVersion(resourceId)) - .thenApply(update -> VersionUtil.compare(update, pluginVersion) > 0); - } - - private String getVersion(int resourceId) { - try { - URL url = new URL(UPDATE_BASE_URL + resourceId); - Scanner scanner = new Scanner(url.openStream()); - if (!scanner.hasNextLine()) - return null; - String version = scanner.nextLine(); - scanner.close(); - return version; - } catch (IOException e) { - return null; - } - } - -} diff --git a/src/main/java/com/solarrabbit/largeraids/trigger/omen/KillCaptainListener.java b/src/main/java/com/solarrabbit/largeraids/trigger/omen/KillCaptainListener.java index 1d9b035..48b3222 100644 --- a/src/main/java/com/solarrabbit/largeraids/trigger/omen/KillCaptainListener.java +++ b/src/main/java/com/solarrabbit/largeraids/trigger/omen/KillCaptainListener.java @@ -2,7 +2,6 @@ import com.solarrabbit.largeraids.LargeRaids; import com.solarrabbit.largeraids.trigger.Trigger; -import com.solarrabbit.largeraids.util.VersionUtil; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -39,8 +38,7 @@ public void onOmenIncrease(EntityPotionEffectEvent evt) { prevAmplifier = effect == null ? -1 : effect.getAmplifier(); break; case ADDED: - Cause cause = VersionUtil.getServerMinorVersion() == 14 ? Cause.UNKNOWN : Cause.PATROL_CAPTAIN; - if (evt.getCause() != cause) // Could be added by commands or the plugin itself + if (evt.getCause() != Cause.PATROL_CAPTAIN) // Could be added by commands or the plugin itself return; if (evt.getNewEffect().getAmplifier() == 0) // Ignore newly applied effect return; diff --git a/src/main/java/com/solarrabbit/largeraids/util/VersionUtil.java b/src/main/java/com/solarrabbit/largeraids/util/VersionUtil.java index 27295ff..8f22777 100644 --- a/src/main/java/com/solarrabbit/largeraids/util/VersionUtil.java +++ b/src/main/java/com/solarrabbit/largeraids/util/VersionUtil.java @@ -3,7 +3,6 @@ import com.mojang.authlib.GameProfile; import com.solarrabbit.largeraids.nms.*; -import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Raid; import org.bukkit.Server; @@ -12,7 +11,7 @@ import org.bukkit.entity.Vex; public class VersionUtil { - private static final String VERSION = "1.20.6"; + public static final String VERSION = "1.20.6"; public static AbstractBlockPositionWrapper getBlockPositionWrapper(Location location) { return getBlockPositionWrapper(location.getX(), location.getY(), location.getZ()); @@ -60,48 +59,4 @@ public static AbstractCraftVexWrapper getCraftVexWrapper(Vex vex) { return new com.solarrabbit.largeraids.versioned.nms.CraftVexWrapper(vex); } - public static int getServerMinorVersion() { - return getMinorVersion(getServerVersion()); - } - - public static boolean isSupported() { - String apiVersion = getAPIVersion(); - if (VERSION.equals(apiVersion)) - return true; - return false; - } - - public static int compare(String versionA, String versionB) { - int majDiff = getMajorVersion(versionA) - getMajorVersion(versionB); - if (majDiff != 0) - return majDiff; - int minorDiff = getMinorVersion(versionA) - getMinorVersion(versionB); - if (minorDiff != 0) - return minorDiff; - return getPatchVersion(versionA) - getPatchVersion(versionB); - } - - private static int getMajorVersion(String version) { - String[] splits = version.split("\\."); - return Integer.parseInt(splits[0]); - } - - private static int getMinorVersion(String version) { - String[] splits = version.split("\\."); - return splits.length < 2 ? 0 : Integer.parseInt(splits[1]); - } - - private static int getPatchVersion(String version) { - String[] splits = version.split("\\."); - return splits.length < 3 ? 0 : Integer.parseInt(splits[2]); - } - - private static String getServerVersion() { - return getCraftServerWrapper(Bukkit.getServer()).getServer().getServerVersion(); - } - - private static String getAPIVersion() { - return Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3]; - } - }