|
2 | 2 |
|
3 | 3 | import org.bukkit.Bukkit; |
4 | 4 |
|
| 5 | +import java.util.LinkedHashMap; |
| 6 | +import java.util.Map; |
| 7 | + |
5 | 8 | public final class ServerUtils { |
6 | 9 |
|
7 | 10 | public static final String VERSION = Bukkit.getBukkitVersion().split("-")[0]; |
8 | 11 | public static final String BUILD; |
9 | 12 |
|
10 | 13 | static { |
| 14 | + boolean isPaper = false; |
| 15 | + |
| 16 | + try { |
| 17 | + Class.forName("com.destroystokyo.paper.PaperConfig"); |
| 18 | + isPaper = true; |
| 19 | + } catch (ClassNotFoundException ignored) { } |
| 20 | + |
11 | 21 | String[] buildParts = Bukkit.getVersion().split("-"); |
12 | 22 |
|
13 | 23 | if (buildParts.length >= 3) { |
14 | | - BUILD = buildParts[2]; |
| 24 | + BUILD = isPaper ? buildParts[2] : buildParts[0]; |
15 | 25 | } else { |
16 | 26 | BUILD = "UNKNOWN"; |
17 | 27 | } |
18 | 28 | } |
19 | 29 |
|
20 | 30 | private ServerUtils() { } |
21 | 31 |
|
| 32 | + @SuppressWarnings("SpellCheckingInspection") |
22 | 33 | public static String getServerVariant() { |
23 | | - try { |
24 | | - Class.forName("net.pl3x.purpur.PurpurConfig"); |
25 | | - return "Purpur"; |
26 | | - } catch (ClassNotFoundException e) { |
| 34 | + final Map<String, String> variants = new LinkedHashMap<>(); |
| 35 | + variants.put("Purpur", "net.pl3x.purpur.PurpurConfig"); |
| 36 | + variants.put("Airplane", "gg.airplane.AirplaneConfig"); |
| 37 | + variants.put("Tuinity", "com.tuinity.tuinity.config.TuinityConfig"); |
| 38 | + variants.put("Paper", "com.destroystokyo.paper.PaperConfig"); |
| 39 | + variants.put("Spigot", "org.spigotmc.SpigotConfig"); |
| 40 | + |
| 41 | + for (Map.Entry<String, String> variant : variants.entrySet()) { |
27 | 42 | try { |
28 | | - Class.forName("com.tuinity.tuinity.config.TuinityConfig"); |
29 | | - return "Tuinity"; |
30 | | - } catch (ClassNotFoundException e1) { |
31 | | - try { |
32 | | - Class.forName("com.destroystokyo.paper.PaperConfig"); |
33 | | - return "Paper"; |
34 | | - } catch (ClassNotFoundException e2) { |
35 | | - try { |
36 | | - Class.forName("org.spigotmc.SpigotConfig"); |
37 | | - return "Spigot"; |
38 | | - } catch (ClassNotFoundException e3) { |
39 | | - return "Unknown"; |
40 | | - } |
41 | | - } |
42 | | - } |
| 43 | + Class.forName(variant.getValue()); |
| 44 | + return variant.getKey(); |
| 45 | + } catch (ClassNotFoundException ignored) { } |
43 | 46 | } |
| 47 | + |
| 48 | + return "Unknown"; |
44 | 49 | } |
45 | 50 |
|
46 | 51 | } |
0 commit comments