mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-25 22:56:45 +01:00
Fix SQL on 1.17 (hacky) and optimized CompatibilityManager
This commit is contained in:
parent
78dc56d263
commit
7e28799f94
@ -1,5 +1,13 @@
|
|||||||
Version 2.1.199
|
Version 2.1.199
|
||||||
|
Fixed a bug that caused MySQL/MariaDB to malfunction for 1.17 (see notes)
|
||||||
Renamed Deepslate Lapis Lazuli Ore to Deepslate Lapis Ore in experience.yml and config.yml
|
Renamed Deepslate Lapis Lazuli Ore to Deepslate Lapis Ore in experience.yml and config.yml
|
||||||
|
Added some code to prevent mcMMO from breaking if it doesn't recognize the version of the game
|
||||||
|
Optimized CompatibilitySupportLayer - this handles some of the logic for supporting multiple versions of the game
|
||||||
|
Added Unit Tests for MinecraftGameVersion
|
||||||
|
|
||||||
|
NOTES:
|
||||||
|
I have temporarily disabled SSL for MySQL/MariaDB for 1.17 ( proper fix coming soon )
|
||||||
|
|
||||||
Version 2.1.198
|
Version 2.1.198
|
||||||
Fixed a bug where Smelting didn't work with the new 1.17 materials
|
Fixed a bug where Smelting didn't work with the new 1.17 materials
|
||||||
Updated dependency Adventure to 4.8.0 (thanks TheBusyBiscuit)
|
Updated dependency Adventure to 4.8.0 (thanks TheBusyBiscuit)
|
||||||
|
@ -51,7 +51,8 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
|||||||
String connectionString = "jdbc:mysql://" + mcMMO.p.getGeneralConfig().getMySQLServerName()
|
String connectionString = "jdbc:mysql://" + mcMMO.p.getGeneralConfig().getMySQLServerName()
|
||||||
+ ":" + mcMMO.p.getGeneralConfig().getMySQLServerPort() + "/" + mcMMO.p.getGeneralConfig().getMySQLDatabaseName();
|
+ ":" + mcMMO.p.getGeneralConfig().getMySQLServerPort() + "/" + mcMMO.p.getGeneralConfig().getMySQLDatabaseName();
|
||||||
|
|
||||||
if(mcMMO.p.getGeneralConfig().getMySQLSSL())
|
if(!mcMMO.getCompatibilityManager().getMinecraftGameVersion().isAtLeast(1, 17, 0) //Temporary hack for SQL and 1.17 support
|
||||||
|
&& mcMMO.p.getGeneralConfig().getMySQLSSL())
|
||||||
connectionString +=
|
connectionString +=
|
||||||
"?verifyServerCertificate=false"+
|
"?verifyServerCertificate=false"+
|
||||||
"&useSSL=true"+
|
"&useSSL=true"+
|
||||||
|
@ -483,7 +483,7 @@ public class mcMMO extends JavaPlugin {
|
|||||||
return upgradeManager;
|
return upgradeManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static CompatibilityManager getCompatibilityManager() {
|
public static @Nullable CompatibilityManager getCompatibilityManager() {
|
||||||
return platformManager.getCompatibilityManager();
|
return platformManager.getCompatibilityManager();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,10 +30,10 @@ import java.util.HashMap;
|
|||||||
*/
|
*/
|
||||||
//TODO: I need to rewrite this crap
|
//TODO: I need to rewrite this crap
|
||||||
public class CompatibilityManager {
|
public class CompatibilityManager {
|
||||||
private HashMap<CompatibilityType, Boolean> supportedLayers;
|
private @NotNull HashMap<CompatibilityType, Boolean> supportedLayers;
|
||||||
private boolean isFullyCompatibleServerSoftware = true; //true if all compatibility layers load successfully
|
private boolean isFullyCompatibleServerSoftware = true; //true if all compatibility layers load successfully
|
||||||
private final MinecraftGameVersion minecraftGameVersion;
|
private final @NotNull MinecraftGameVersion minecraftGameVersion;
|
||||||
private final NMSVersion nmsVersion;
|
private final @NotNull NMSVersion nmsVersion;
|
||||||
|
|
||||||
/* Compatibility Layers */
|
/* Compatibility Layers */
|
||||||
// private PlayerAttackCooldownExploitPreventionLayer playerAttackCooldownExploitPreventionLayer;
|
// private PlayerAttackCooldownExploitPreventionLayer playerAttackCooldownExploitPreventionLayer;
|
||||||
@ -42,7 +42,7 @@ public class CompatibilityManager {
|
|||||||
private AbstractMasterAnglerCompatibility masterAnglerCompatibility;
|
private AbstractMasterAnglerCompatibility masterAnglerCompatibility;
|
||||||
private WorldCompatibilityLayer worldCompatibilityLayer;
|
private WorldCompatibilityLayer worldCompatibilityLayer;
|
||||||
|
|
||||||
public CompatibilityManager(MinecraftGameVersion minecraftGameVersion) {
|
public CompatibilityManager(@NotNull MinecraftGameVersion minecraftGameVersion) {
|
||||||
mcMMO.p.getLogger().info("Loading compatibility layers...");
|
mcMMO.p.getLogger().info("Loading compatibility layers...");
|
||||||
this.minecraftGameVersion = minecraftGameVersion;
|
this.minecraftGameVersion = minecraftGameVersion;
|
||||||
this.nmsVersion = determineNMSVersion();
|
this.nmsVersion = determineNMSVersion();
|
||||||
@ -77,10 +77,7 @@ public class CompatibilityManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void initWorldCompatibilityLayer() {
|
private void initWorldCompatibilityLayer() {
|
||||||
if(minecraftGameVersion.getMinorVersion().asInt() > 17
|
if(minecraftGameVersion.isAtLeast(1, 17, 0)) {
|
||||||
|| (minecraftGameVersion.getMinorVersion().asInt() >= 16 && minecraftGameVersion.getPatchVersion().asInt() >= 4)
|
|
||||||
|| minecraftGameVersion.getMajorVersion().asInt() >= 2) {
|
|
||||||
if(hasNewWorldMinHeightAPI()) {
|
|
||||||
worldCompatibilityLayer = new WorldCompatibilityLayer_1_16_4();
|
worldCompatibilityLayer = new WorldCompatibilityLayer_1_16_4();
|
||||||
} else {
|
} else {
|
||||||
worldCompatibilityLayer = new WorldCompatibilityLayer() {
|
worldCompatibilityLayer = new WorldCompatibilityLayer() {
|
||||||
@ -89,19 +86,6 @@ public class CompatibilityManager {
|
|||||||
return WorldCompatibilityLayer.super.getMinWorldHeight(world);
|
return WorldCompatibilityLayer.super.getMinWorldHeight(world);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getMaxWorldHeight(@NotNull World world) {
|
|
||||||
return WorldCompatibilityLayer.super.getMaxWorldHeight(world);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
worldCompatibilityLayer = new WorldCompatibilityLayer() {
|
|
||||||
@Override
|
|
||||||
public int getMinWorldHeight(@NotNull World world) {
|
|
||||||
return WorldCompatibilityLayer.super.getMinWorldHeight(world);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getMaxWorldHeight(@NotNull World world) {
|
public int getMaxWorldHeight(@NotNull World world) {
|
||||||
return WorldCompatibilityLayer.super.getMaxWorldHeight(world);
|
return WorldCompatibilityLayer.super.getMaxWorldHeight(world);
|
||||||
@ -111,37 +95,15 @@ public class CompatibilityManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void initMasterAnglerLayer() {
|
private void initMasterAnglerLayer() {
|
||||||
if(minecraftGameVersion.getMinorVersion().asInt() >= 16 || minecraftGameVersion.getMajorVersion().asInt() >= 2) {
|
if(minecraftGameVersion.isAtLeast(1, 16, 3)) {
|
||||||
if(hasNewFishingHookAPI()) {
|
|
||||||
masterAnglerCompatibility = new MasterAnglerCompatibilityLayer();
|
masterAnglerCompatibility = new MasterAnglerCompatibilityLayer();
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
masterAnglerCompatibility = null;
|
masterAnglerCompatibility = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean hasNewWorldMinHeightAPI() {
|
|
||||||
try {
|
|
||||||
Class<?> checkForClass = Class.forName("org.bukkit.World");
|
|
||||||
checkForClass.getMethod("getMinHeight");
|
|
||||||
return true;
|
|
||||||
} catch (ClassNotFoundException | NoSuchMethodException e) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean hasNewFishingHookAPI() {
|
|
||||||
try {
|
|
||||||
Class<?> checkForClass = Class.forName("org.bukkit.entity.FishHook");
|
|
||||||
checkForClass.getMethod("getMinWaitTime");
|
|
||||||
return true;
|
|
||||||
} catch (ClassNotFoundException | NoSuchMethodException e) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void initBungeeSerializerLayer() {
|
private void initBungeeSerializerLayer() {
|
||||||
if(minecraftGameVersion.getMinorVersion().asInt() >= 16) {
|
if(minecraftGameVersion.isAtLeast(1, 16, 0)) {
|
||||||
bungeeSerializerCompatibilityLayer = new BungeeModernSerializerCompatibilityLayer();
|
bungeeSerializerCompatibilityLayer = new BungeeModernSerializerCompatibilityLayer();
|
||||||
} else {
|
} else {
|
||||||
bungeeSerializerCompatibilityLayer = new BungeeLegacySerializerCompatibilityLayer();
|
bungeeSerializerCompatibilityLayer = new BungeeLegacySerializerCompatibilityLayer();
|
||||||
@ -151,7 +113,7 @@ public class CompatibilityManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void initPersistentDataLayer() {
|
private void initPersistentDataLayer() {
|
||||||
if(minecraftGameVersion.getMinorVersion().asInt() >= 14 || minecraftGameVersion.getMajorVersion().asInt() >= 2) {
|
if(minecraftGameVersion.isAtLeast(1, 14, 2)) {
|
||||||
persistentDataLayer = new SpigotPersistentDataLayer_1_14();
|
persistentDataLayer = new SpigotPersistentDataLayer_1_14();
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
@ -162,7 +124,7 @@ public class CompatibilityManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//TODO: move to text manager
|
//TODO: move to text manager
|
||||||
public void reportCompatibilityStatus(CommandSender commandSender) {
|
public void reportCompatibilityStatus(@NotNull CommandSender commandSender) {
|
||||||
if(isFullyCompatibleServerSoftware) {
|
if(isFullyCompatibleServerSoftware) {
|
||||||
commandSender.sendMessage(LocaleLoader.getString("mcMMO.Template.Prefix",
|
commandSender.sendMessage(LocaleLoader.getString("mcMMO.Template.Prefix",
|
||||||
"mcMMO is fully compatible with the currently running server software."));
|
"mcMMO is fully compatible with the currently running server software."));
|
||||||
@ -179,7 +141,7 @@ public class CompatibilityManager {
|
|||||||
commandSender.sendMessage(LocaleLoader.getString("mcMMO.Template.Prefix", "NMS Status - " + nmsVersion.toString()));
|
commandSender.sendMessage(LocaleLoader.getString("mcMMO.Template.Prefix", "NMS Status - " + nmsVersion.toString()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isCompatibilityLayerOperational(CompatibilityType compatibilityType) {
|
public boolean isCompatibilityLayerOperational(@NotNull CompatibilityType compatibilityType) {
|
||||||
return supportedLayers.get(compatibilityType);
|
return supportedLayers.get(compatibilityType);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -192,6 +154,12 @@ public class CompatibilityManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private @NotNull NMSVersion determineNMSVersion() {
|
private @NotNull NMSVersion determineNMSVersion() {
|
||||||
|
//This bit here helps prevent mcMMO breaking if it isn't updated but the game continues to update
|
||||||
|
if(minecraftGameVersion.isAtLeast(1, 17, 0)) {
|
||||||
|
return NMSVersion.NMS_1_17;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Messy but it works
|
||||||
if (minecraftGameVersion.getMajorVersion().asInt() == 1) {
|
if (minecraftGameVersion.getMajorVersion().asInt() == 1) {
|
||||||
switch (minecraftGameVersion.getMinorVersion().asInt()) {
|
switch (minecraftGameVersion.getMinorVersion().asInt()) {
|
||||||
case 12:
|
case 12:
|
||||||
@ -237,4 +205,8 @@ public class CompatibilityManager {
|
|||||||
public @NotNull WorldCompatibilityLayer getWorldCompatibilityLayer() {
|
public @NotNull WorldCompatibilityLayer getWorldCompatibilityLayer() {
|
||||||
return worldCompatibilityLayer;
|
return worldCompatibilityLayer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public @Nullable MinecraftGameVersion getMinecraftGameVersion() {
|
||||||
|
return minecraftGameVersion;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,4 +27,37 @@ public class MinecraftGameVersion extends MajorMinorPatchVersion {
|
|||||||
super(majorVerNumber, minorVerNumber);
|
super(majorVerNumber, minorVerNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns whether or not the Minecraft version is at least equal to or higher than a target version
|
||||||
|
* @param majorVerNumber target major version number - for example 1.16.5 , the 1 is the major version
|
||||||
|
* @param minorVerNumber target minor version number - for example 1.16.5, the 16 is the minor version
|
||||||
|
* @param patchVerNumber target patch version number - for example 1.16.5, the 5 is the patch version number
|
||||||
|
*
|
||||||
|
* @return returns true if Minecraft is at least a certain version
|
||||||
|
*/
|
||||||
|
public boolean isAtLeast(int majorVerNumber, int minorVerNumber, int patchVerNumber) {
|
||||||
|
//First check if the major version is higher, if it is we have no need to check minor version or patch version
|
||||||
|
|
||||||
|
if(getMajorVersion().asInt() > majorVerNumber) {
|
||||||
|
return true; //Major version is one higher and hierarchically more important than the other versions
|
||||||
|
}
|
||||||
|
|
||||||
|
if(getMajorVersion().asInt() < majorVerNumber) {
|
||||||
|
return false; //Major version is below, so return false
|
||||||
|
}
|
||||||
|
|
||||||
|
//Major version meets the requirement, check minor version
|
||||||
|
|
||||||
|
if(getMinorVersion().asInt() > minorVerNumber) {
|
||||||
|
return true; //Minor version is one higher and hierarchically more important than patch version, so exit here
|
||||||
|
}
|
||||||
|
|
||||||
|
if(getMinorVersion().asInt() < minorVerNumber) {
|
||||||
|
return false; //Minor version is at least one version behind, return false
|
||||||
|
}
|
||||||
|
|
||||||
|
//Minor version meets the requirement, check patch version
|
||||||
|
return getPatchVersion().asInt() >= patchVerNumber;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,65 @@
|
|||||||
|
package com.gmail.nossr50.util.platform;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
class MinecraftGameVersionTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAtLeast() {
|
||||||
|
//TODO: Remove redundant tests
|
||||||
|
MinecraftGameVersion oneEightEight = new MinecraftGameVersion(1, 8, 8);
|
||||||
|
MinecraftGameVersion oneSixteenFive = new MinecraftGameVersion(1, 16, 5);
|
||||||
|
MinecraftGameVersion oneTwo = new MinecraftGameVersion(1, 2);
|
||||||
|
|
||||||
|
//1.8.8
|
||||||
|
assertTrue(oneEightEight.isAtLeast(1, 8, 7));
|
||||||
|
assertFalse(oneEightEight.isAtLeast(1, 9, 0));
|
||||||
|
|
||||||
|
//1.16.5
|
||||||
|
assertTrue(oneSixteenFive.isAtLeast(1, 15, 2));
|
||||||
|
assertFalse(oneSixteenFive.isAtLeast(1, 17, 0));
|
||||||
|
|
||||||
|
//1.2
|
||||||
|
assertTrue(oneTwo.isAtLeast(1, 2, 0));
|
||||||
|
|
||||||
|
//Test major version number
|
||||||
|
MinecraftGameVersion majorVersionTest = new MinecraftGameVersion(2, 0, 0);
|
||||||
|
|
||||||
|
assertFalse(majorVersionTest.isAtLeast(3, 0, 0));
|
||||||
|
assertFalse(majorVersionTest.isAtLeast(3, 1, 0));
|
||||||
|
assertFalse(majorVersionTest.isAtLeast(3, 0, 2));
|
||||||
|
|
||||||
|
assertTrue(majorVersionTest.isAtLeast(2, 0, 0));
|
||||||
|
assertTrue(majorVersionTest.isAtLeast(1, 0, 0));
|
||||||
|
|
||||||
|
|
||||||
|
//Test minor version number
|
||||||
|
MinecraftGameVersion minorVersionTest = new MinecraftGameVersion(0, 3, 0);
|
||||||
|
|
||||||
|
assertFalse(minorVersionTest.isAtLeast(0, 4, 0));
|
||||||
|
assertFalse(minorVersionTest.isAtLeast(1, 4, 0));
|
||||||
|
assertFalse(minorVersionTest.isAtLeast(0, 4, 1));
|
||||||
|
|
||||||
|
assertTrue(minorVersionTest.isAtLeast(0, 1, 0));
|
||||||
|
assertTrue(minorVersionTest.isAtLeast(0, 2, 0));
|
||||||
|
assertTrue(minorVersionTest.isAtLeast(0, 2, 1));
|
||||||
|
assertTrue(minorVersionTest.isAtLeast(0, 3, 0));
|
||||||
|
|
||||||
|
//Test patch version number
|
||||||
|
|
||||||
|
MinecraftGameVersion patchVersionTest = new MinecraftGameVersion(0, 0, 5);
|
||||||
|
|
||||||
|
assertFalse(patchVersionTest.isAtLeast(1, 0, 0));
|
||||||
|
assertFalse(patchVersionTest.isAtLeast(0, 0, 6));
|
||||||
|
assertFalse(patchVersionTest.isAtLeast(0, 1, 4));
|
||||||
|
assertFalse(patchVersionTest.isAtLeast(1, 1, 4));
|
||||||
|
|
||||||
|
assertTrue(patchVersionTest.isAtLeast(0, 0, 1));
|
||||||
|
assertTrue(patchVersionTest.isAtLeast(0, 0, 2));
|
||||||
|
assertTrue(patchVersionTest.isAtLeast(0, 0, 3));
|
||||||
|
assertTrue(patchVersionTest.isAtLeast(0, 0, 4));
|
||||||
|
assertTrue(patchVersionTest.isAtLeast(0, 0, 5));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user