mirror of
https://github.com/HibiscusMC/HibiscusCommons.git
synced 2025-12-23 17:09:21 +00:00
feat: recode handling of nms version check
This commit is contained in:
@@ -2,13 +2,21 @@ package me.lojosho.hibiscuscommons.nms;
|
|||||||
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import me.lojosho.hibiscuscommons.HibiscusCommonsPlugin;
|
import me.lojosho.hibiscuscommons.HibiscusCommonsPlugin;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
public class NMSHandlers {
|
public class NMSHandlers {
|
||||||
|
|
||||||
private static final String[] SUPPORTED_VERSION = new String[]{"v1_18_R2", "v1_19_R1", "v1_19_R2", "v1_19_R3", "v1_20_R1", "v1_20_R2", "v1_20_R3", "v1_20_R4"};
|
private static final HashMap<String, String> VERSION_MAP = new HashMap<>() {{
|
||||||
|
put("1.19.4", "v1_19_R3");
|
||||||
|
put("1.20", "v1_20_R1");
|
||||||
|
put("1.20.2", "v1_20_R2");
|
||||||
|
put("1.20.4", "v1_20_R3");
|
||||||
|
put("1.20.6", "v1_20_R4");
|
||||||
|
}};
|
||||||
private static NMSHandler handler;
|
private static NMSHandler handler;
|
||||||
@Getter
|
@Getter
|
||||||
private static String version;
|
private static String version;
|
||||||
@@ -30,10 +38,11 @@ public class NMSHandlers {
|
|||||||
|
|
||||||
public static void setup() {
|
public static void setup() {
|
||||||
if (handler != null) return;
|
if (handler != null) return;
|
||||||
final String packageName = HibiscusCommonsPlugin.getInstance().getServer().getClass().getPackage().getName();
|
final String bukkitVersion = Bukkit.getServer().getBukkitVersion();
|
||||||
String packageVersion = packageName.substring(packageName.lastIndexOf('.') + 1);
|
String minecraftVersion = bukkitVersion.substring(0, bukkitVersion.indexOf('-'));
|
||||||
|
String packageVersion = VERSION_MAP.get(minecraftVersion);
|
||||||
|
|
||||||
for (String selectedVersion : SUPPORTED_VERSION) {
|
for (String selectedVersion : VERSION_MAP.values()) {
|
||||||
if (!selectedVersion.contains(packageVersion)) {
|
if (!selectedVersion.contains(packageVersion)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user