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 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 = 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; else if (main_ver == 19) isNewerThan1_19_R2 = Integer.parseInt(split[2].substring(1)) >= 2; else isNewerThan1_19_R2 = false; } 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); } } }