Skip to content

Commit bdbc580

Browse files
Disable the Ad Mod if loaded on an unsupported version
1 parent c6093a8 commit bdbc580

File tree

1 file changed

+43
-1
lines changed

1 file changed

+43
-1
lines changed

src/main/java/gg/essential/ad/EssentialAd.java

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
//#if MC>=11600
2929
//$$ import net.minecraft.client.gui.widget.Widget;
30+
//$$ import net.minecraft.util.SharedConstants;
3031
//#endif
3132

3233
//#if FORGE
@@ -35,7 +36,7 @@
3536

3637
//#if MC>=11600
3738
//#else
38-
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
39+
import net.minecraftforge.common.ForgeVersion;
3940
//#endif
4041

4142
//#if MC>=11800
@@ -56,6 +57,25 @@ public class EssentialAd {
5657
public static final Gson GSON = new GsonBuilder().setPrettyPrinting().create();
5758
public static final AdConfig CONFIG = AdConfig.load();
5859

60+
private static final Set<String> FABRIC_SUPPORTED_VERSIONS = new HashSet<>(Arrays.asList(
61+
"1.16.5",
62+
"1.17.1",
63+
"1.18", "1.18.1", "1.18.2",
64+
"1.19", "1.19.1", "1.19.2", "1.19.3", "1.19.4",
65+
"1.20", "1.20.1", "1.20.2", "1.20.4", "1.20.6",
66+
"1.21", "1.21.1", "1.21.2", "1.21.3", "1.21.4"
67+
));
68+
69+
private static final Set<String> FORGE_SUPPORTED_VERSIONS = new HashSet<>(Arrays.asList(
70+
"1.8.9",
71+
"1.12.2",
72+
"1.16.5",
73+
"1.17.1",
74+
"1.18.2",
75+
"1.19.2", "1.19.3", "1.19.4",
76+
"1.20.1", "1.20.2", "1.20.4"
77+
));
78+
5979
private static final Set<String> MAIN_MENU_BUTTONS = new HashSet<>(Collections.singletonList("menu.multiplayer"));
6080
private static final Set<String> PAUSE_MENU_BUTTONS = new HashSet<>(Arrays.asList(
6181
//#if MC>=12100
@@ -75,6 +95,28 @@ public EssentialAd() {
7595
if (EssentialUtil.isEssentialOrContainerLoaded()) return;
7696
if (CONFIG.shouldHideButtons()) return;
7797

98+
//#if MC>=11600
99+
//$$ String version = SharedConstants.getVersion().getId();
100+
//#else
101+
String version;
102+
try {
103+
// Accessing via reflection so the compiler does not inline the value at build time.
104+
version = (String) ForgeVersion.class.getDeclaredField("mcVersion").get(null);
105+
} catch (Exception e) {
106+
LOGGER.error("Failed to determine Minecraft version", e);
107+
return;
108+
}
109+
//#endif
110+
111+
//#if FABRIC
112+
//$$ if (!FABRIC_SUPPORTED_VERSIONS.contains(version)) {
113+
//#else
114+
if (!FORGE_SUPPORTED_VERSIONS.contains(version)) {
115+
//#endif
116+
LOGGER.info("Minecraft version {} is not supported by Essential, disabling Ad Mod", version);
117+
return;
118+
}
119+
78120
//#if FORGE
79121
MinecraftForge.EVENT_BUS.register(this);
80122
MinecraftForge.EVENT_BUS.register(ModalManager.INSTANCE);

0 commit comments

Comments
 (0)