Skip to content

Commit

Permalink
Revamp version check and delete update check
Browse files Browse the repository at this point in the history
+ Bump plugin version
  • Loading branch information
ThisTestUser committed Sep 24, 2024
1 parent bed94e0 commit 2792d09
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 101 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ plugins {
}

group = "com.solarrabbit"
version = "1.11.1"
version = "1.11.2"
description = "LargeRaids"
val mcVersion = "1.20.6"

Expand Down
26 changes: 10 additions & 16 deletions src/main/java/com/solarrabbit/largeraids/LargeRaids.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
});
}

}
35 changes: 0 additions & 35 deletions src/main/java/com/solarrabbit/largeraids/ResourceChecker.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
47 changes: 1 addition & 46 deletions src/main/java/com/solarrabbit/largeraids/util/VersionUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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());
Expand Down Expand Up @@ -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];
}

}

0 comments on commit 2792d09

Please sign in to comment.