9
0
mirror of https://github.com/Xiao-MoMi/Custom-Crops.git synced 2025-12-23 17:09:21 +00:00
This commit is contained in:
Xiao-MoMi
2023-03-14 21:10:31 +08:00
parent f154e9fa05
commit 84ed09d35a
14 changed files with 93 additions and 127 deletions

View File

@@ -1,15 +1,27 @@
package net.momirealms.customcrops.helper;
import de.tr7zw.changeme.nbtapi.utils.MinecraftVersion;
import de.tr7zw.changeme.nbtapi.utils.VersionChecker;
import net.momirealms.customcrops.CustomCrops;
import org.bukkit.Bukkit;
import java.lang.reflect.Field;
public class VersionHelper {
private boolean isNewerThan1_19_R2;
private String version;
private final CustomCrops plugin;
public VersionHelper(CustomCrops plugin) {
this.plugin = plugin;
isVersionNewerThan1_19_R2();
disableUseLessInfo();
}
public boolean isVersionNewerThan1_19_R2() {
if (version == null) {
version = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3];
version = plugin.getServer().getClass().getPackage().getName().split("\\.")[3];
String[] split = version.split("_");
int main_ver = Integer.parseInt(split[1]);
if (main_ver >= 20) isNewerThan1_19_R2 = true;
@@ -18,4 +30,37 @@ public class VersionHelper {
}
return isNewerThan1_19_R2;
}
private void disableUseLessInfo() {
MinecraftVersion.disableBStats();
MinecraftVersion.disableUpdateCheck();
VersionChecker.hideOk = true;
try {
Field field = MinecraftVersion.class.getDeclaredField("version");
field.setAccessible(true);
MinecraftVersion minecraftVersion;
try {
minecraftVersion = MinecraftVersion.valueOf(version.replace("v", "MC"));
} catch (IllegalArgumentException ex) {
minecraftVersion = MinecraftVersion.UNKNOWN;
}
field.set(MinecraftVersion.class, minecraftVersion);
} catch (NoSuchFieldException | IllegalAccessException e) {
throw new RuntimeException(e);
}
boolean hasGsonSupport;
try {
Class.forName("com.google.gson.Gson");
hasGsonSupport = true;
} catch (Exception ex) {
hasGsonSupport = false;
}
try {
Field field= MinecraftVersion.class.getDeclaredField("hasGsonSupport");
field.setAccessible(true);
field.set(Boolean.class, hasGsonSupport);
} catch (NoSuchFieldException | IllegalAccessException e) {
throw new RuntimeException(e);
}
}
}