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.
This commit is contained in:
parent
93af93d5a0
commit
4f548e08a6
|
@ -15,6 +15,7 @@ These changes will (most likely) be included in the next version.
|
|||
- 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.
|
||||
- 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.
|
||||
- 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.
|
||||
- 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.
|
||||
|
||||
Thanks to:
|
||||
- minoneer for help with fixing and testing the teleport bug
|
||||
|
|
|
@ -2,35 +2,26 @@ package com.garbagemule.MobArena;
|
|||
|
||||
import org.bukkit.Server;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.StringJoiner;
|
||||
|
||||
class ServerVersionCheck {
|
||||
|
||||
private static final String[] EXACTS = {"1.13"};
|
||||
private static final String[] PREFIXES = {"1.13."};
|
||||
private static final String[] EXACTS = {"1.8", "1.9", "1.10", "1.11", "1.12"};
|
||||
private static final String[] PREFIXES = {"1.8.", "1.9.", "1.10.", "1.11.", "1.12."};
|
||||
|
||||
static void check(Server server) {
|
||||
String version = getMinecraftVersion(server);
|
||||
|
||||
for (String exact : EXACTS) {
|
||||
if (version.equals(exact)) {
|
||||
return;
|
||||
fail(version);
|
||||
}
|
||||
}
|
||||
for (String prefix : PREFIXES) {
|
||||
if (version.startsWith(prefix)) {
|
||||
return;
|
||||
fail(version);
|
||||
}
|
||||
}
|
||||
|
||||
throw new IllegalStateException(new StringJoiner(" ")
|
||||
.add("Incompatible server version!")
|
||||
.add("This build only works on " + Arrays.toString(EXACTS) + ",")
|
||||
.add("but this server is running " + version + ".")
|
||||
.add("Perhaps you downloaded the wrong build?")
|
||||
.toString()
|
||||
);
|
||||
}
|
||||
|
||||
private static String getMinecraftVersion(Server server) {
|
||||
|
@ -41,4 +32,13 @@ class ServerVersionCheck {
|
|||
return version.substring(start, end);
|
||||
}
|
||||
|
||||
private static void fail(String version) {
|
||||
throw new IllegalStateException(new StringJoiner(" ")
|
||||
.add("Incompatible server version!")
|
||||
.add("This build does not work on " + version + ".")
|
||||
.add("Perhaps you downloaded the wrong build?")
|
||||
.toString()
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,74 @@
|
|||
package com.garbagemule.MobArena;
|
||||
|
||||
import org.bukkit.Server;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@SuppressWarnings("WeakerAccess")
|
||||
@RunWith(MockitoJUnitRunner.StrictStubs.class)
|
||||
public class ServerVersionCheckTest {
|
||||
|
||||
public Server server;
|
||||
|
||||
@Rule
|
||||
public ExpectedException exception = ExpectedException.none();
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
server = mock(Server.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void oneFourteen() {
|
||||
win("git-Spigot-cafebae-dedbeef (MC: 1.14)");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void oneThirteen() {
|
||||
win("git-Spigot-f09662d-be557e6 (MC: 1.13.2)");
|
||||
}
|
||||
|
||||
private void win(String version) {
|
||||
when(server.getVersion()).thenReturn(version);
|
||||
ServerVersionCheck.check(server);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void oneTwelve() {
|
||||
fail("git-Spigot-79a30d7-acbc348 (MC: 1.12.2)");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void oneEleven() {
|
||||
fail("git-Spigot-3fb9445-6e3cec8 (MC: 1.11.2)");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void oneTen() {
|
||||
fail("git-Spigot-de459a2-51263e9 (MC: 1.10.2)");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void oneNine() {
|
||||
fail("git-Spigot-c6871e2-0cd0397 (MC: 1.9.4)");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void oneEight() {
|
||||
fail("git-Spigot-21fe707-e1ebe52 (MC: 1.8.8)");
|
||||
}
|
||||
|
||||
private void fail(String version) {
|
||||
when(server.getVersion()).thenReturn(version);
|
||||
exception.expect(IllegalStateException.class);
|
||||
ServerVersionCheck.check(server);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue