Skip to content

Commit 4f548e0

Browse files
committed
Use a blacklist for the server version check.
The whitelisting approach works well for the legacy builds, because the version landscape doesn't change with those. However, the main build on the master branch will not run on a server version other than 1.13, so come 1.14, MobArena will be broken. This commit fixes this problem by changing to a blacklisting approach for the main build on the master branch. Checking for versions that the build *can't* run on brings back MobArena's old resilience to version changes on the Minecraft side of things.
1 parent 93af93d commit 4f548e0

3 files changed

Lines changed: 88 additions & 13 deletions

File tree

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ These changes will (most likely) be included in the next version.
1515
- Fixed a bug introduced by a breaking API change in Spigot where a player with a nearly full inventory might cause item rewards to change stack amounts.
1616
- MobArena no longer uncancels teleport events that occur outside of its own context when players have the `mobarena.admin.teleport` permission. This fixes a bug where the permission could override the cancellation of events that weren't related to MobArena.
1717
- When resetting player health, MobArena now uses the player max health attribute base value rather than a fixed value of 20. This fixes crashes associated with max health values lower than 20, and ensures that players always get a full heal with values higher than 20.
18+
- The server version check on the main build (currently for 1.13) now explicitly looks for incompatible versions rather than compatible versions. This brings back the "works unless otherwise specified" nature of the plugin, and thus a MobArena build for Minecraft 1.13 should (knock-on-wood) work on 1.14.
1819

1920
Thanks to:
2021
- minoneer for help with fixing and testing the teleport bug

src/main/java/com/garbagemule/MobArena/ServerVersionCheck.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,26 @@
22

33
import org.bukkit.Server;
44

5-
import java.util.Arrays;
65
import java.util.StringJoiner;
76

87
class ServerVersionCheck {
98

10-
private static final String[] EXACTS = {"1.13"};
11-
private static final String[] PREFIXES = {"1.13."};
9+
private static final String[] EXACTS = {"1.8", "1.9", "1.10", "1.11", "1.12"};
10+
private static final String[] PREFIXES = {"1.8.", "1.9.", "1.10.", "1.11.", "1.12."};
1211

1312
static void check(Server server) {
1413
String version = getMinecraftVersion(server);
1514

1615
for (String exact : EXACTS) {
1716
if (version.equals(exact)) {
18-
return;
17+
fail(version);
1918
}
2019
}
2120
for (String prefix : PREFIXES) {
2221
if (version.startsWith(prefix)) {
23-
return;
22+
fail(version);
2423
}
2524
}
26-
27-
throw new IllegalStateException(new StringJoiner(" ")
28-
.add("Incompatible server version!")
29-
.add("This build only works on " + Arrays.toString(EXACTS) + ",")
30-
.add("but this server is running " + version + ".")
31-
.add("Perhaps you downloaded the wrong build?")
32-
.toString()
33-
);
3425
}
3526

3627
private static String getMinecraftVersion(Server server) {
@@ -41,4 +32,13 @@ private static String getMinecraftVersion(Server server) {
4132
return version.substring(start, end);
4233
}
4334

35+
private static void fail(String version) {
36+
throw new IllegalStateException(new StringJoiner(" ")
37+
.add("Incompatible server version!")
38+
.add("This build does not work on " + version + ".")
39+
.add("Perhaps you downloaded the wrong build?")
40+
.toString()
41+
);
42+
}
43+
4444
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package com.garbagemule.MobArena;
2+
3+
import org.bukkit.Server;
4+
import org.junit.Before;
5+
import org.junit.Rule;
6+
import org.junit.Test;
7+
import org.junit.rules.ExpectedException;
8+
import org.junit.runner.RunWith;
9+
import org.mockito.junit.MockitoJUnitRunner;
10+
11+
import static org.mockito.Mockito.mock;
12+
import static org.mockito.Mockito.when;
13+
14+
@SuppressWarnings("WeakerAccess")
15+
@RunWith(MockitoJUnitRunner.StrictStubs.class)
16+
public class ServerVersionCheckTest {
17+
18+
public Server server;
19+
20+
@Rule
21+
public ExpectedException exception = ExpectedException.none();
22+
23+
@Before
24+
public void setup() {
25+
server = mock(Server.class);
26+
}
27+
28+
@Test
29+
public void oneFourteen() {
30+
win("git-Spigot-cafebae-dedbeef (MC: 1.14)");
31+
}
32+
33+
@Test
34+
public void oneThirteen() {
35+
win("git-Spigot-f09662d-be557e6 (MC: 1.13.2)");
36+
}
37+
38+
private void win(String version) {
39+
when(server.getVersion()).thenReturn(version);
40+
ServerVersionCheck.check(server);
41+
}
42+
43+
@Test
44+
public void oneTwelve() {
45+
fail("git-Spigot-79a30d7-acbc348 (MC: 1.12.2)");
46+
}
47+
48+
@Test
49+
public void oneEleven() {
50+
fail("git-Spigot-3fb9445-6e3cec8 (MC: 1.11.2)");
51+
}
52+
53+
@Test
54+
public void oneTen() {
55+
fail("git-Spigot-de459a2-51263e9 (MC: 1.10.2)");
56+
}
57+
58+
@Test
59+
public void oneNine() {
60+
fail("git-Spigot-c6871e2-0cd0397 (MC: 1.9.4)");
61+
}
62+
63+
@Test
64+
public void oneEight() {
65+
fail("git-Spigot-21fe707-e1ebe52 (MC: 1.8.8)");
66+
}
67+
68+
private void fail(String version) {
69+
when(server.getVersion()).thenReturn(version);
70+
exception.expect(IllegalStateException.class);
71+
ServerVersionCheck.check(server);
72+
}
73+
74+
}

0 commit comments

Comments
 (0)