|
17 | 17 |
|
18 | 18 | package me.kcra.takenaka.accessor.platform;
|
19 | 19 |
|
| 20 | +import org.jetbrains.annotations.ApiStatus; |
20 | 21 | import org.jetbrains.annotations.NotNull;
|
21 | 22 |
|
22 | 23 | import java.lang.reflect.InvocationTargetException;
|
|
33 | 34 | * @author Matouš Kučera
|
34 | 35 | */
|
35 | 36 | public enum MapperPlatforms implements MapperPlatform {
|
| 37 | + /** |
| 38 | + * A generic abstraction for Mojang software derivatives (Mojang mappings). |
| 39 | + */ |
| 40 | + MOJANG { |
| 41 | + private String minecraftVersion = null; |
| 42 | + |
| 43 | + { |
| 44 | + try { |
| 45 | + final Class<?> constClass = Class.forName("net.minecraft.SharedConstants", true, getClassLoader()); |
| 46 | + final Object gameVersion = constClass.getMethod("getCurrentVersion").invoke(null); |
| 47 | + |
| 48 | + minecraftVersion = (String) gameVersion.getClass().getMethod("getName").invoke(gameVersion); |
| 49 | + } catch (IllegalAccessException | InvocationTargetException e) { |
| 50 | + throw new RuntimeException("Failed to get Minecraft version", e); |
| 51 | + } catch (ClassNotFoundException | NoSuchMethodException ignored) { |
| 52 | + } |
| 53 | + } |
| 54 | + |
| 55 | + @Override |
| 56 | + public boolean isSupported() { |
| 57 | + return minecraftVersion != null; |
| 58 | + } |
| 59 | + |
| 60 | + @Override |
| 61 | + public @NotNull String getVersion() { |
| 62 | + if (!isSupported()) { |
| 63 | + throw new UnsupportedOperationException("Mojang is not supported by this environment"); |
| 64 | + } |
| 65 | + return minecraftVersion; |
| 66 | + } |
| 67 | + |
| 68 | + @Override |
| 69 | + public @NotNull String[] getMappingNamespaces() { |
| 70 | + return new String[] { "mojang" }; |
| 71 | + } |
| 72 | + }, |
| 73 | + |
36 | 74 | /**
|
37 | 75 | * An abstraction for platforms that implement the Bukkit API (Spigot mappings).
|
38 | 76 | */
|
@@ -84,39 +122,25 @@ public boolean isSupported() {
|
84 | 122 |
|
85 | 123 | /**
|
86 | 124 | * An abstraction for NeoForge-based platforms (Mojang mappings).
|
| 125 | + * |
| 126 | + * @deprecated use {@link #MOJANG} |
87 | 127 | */
|
| 128 | + @Deprecated |
| 129 | + @ApiStatus.ScheduledForRemoval(inVersion = "2.0.0") |
88 | 130 | NEOFORGE {
|
89 |
| - private String minecraftVersion = null; |
90 |
| - |
91 |
| - { |
92 |
| - try { |
93 |
| - final Class<?> neoFormVersionClass = Class.forName( |
94 |
| - "net.neoforged.neoforge.internal.versions.neoform.NeoFormVersion", |
95 |
| - true, getClassLoader() |
96 |
| - ); |
97 |
| - minecraftVersion = (String) neoFormVersionClass.getMethod("getMCVersion").invoke(null); |
98 |
| - } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { |
99 |
| - throw new RuntimeException("Failed to get Minecraft version", e); |
100 |
| - } catch (ClassNotFoundException ignored) { |
101 |
| - } |
102 |
| - } |
103 |
| - |
104 | 131 | @Override
|
105 | 132 | public boolean isSupported() {
|
106 |
| - return minecraftVersion != null; |
| 133 | + return MOJANG.isSupported(); |
107 | 134 | }
|
108 | 135 |
|
109 | 136 | @Override
|
110 | 137 | public @NotNull String getVersion() {
|
111 |
| - if (!isSupported()) { |
112 |
| - throw new UnsupportedOperationException("NeoForge is not supported by this environment"); |
113 |
| - } |
114 |
| - return minecraftVersion; |
| 138 | + return MOJANG.getVersion(); |
115 | 139 | }
|
116 | 140 |
|
117 | 141 | @Override
|
118 | 142 | public @NotNull String[] getMappingNamespaces() {
|
119 |
| - return new String[] { "mojang" }; |
| 143 | + return MOJANG.getMappingNamespaces(); |
120 | 144 | }
|
121 | 145 | },
|
122 | 146 |
|
|
0 commit comments