Fix SQL on 1.17 (hacky) and optimized CompatibilityManager

This commit is contained in:
nossr50
2021-06-15 14:19:30 -07:00
parent 78dc56d263
commit 7e28799f94
6 changed files with 131 additions and 52 deletions

View File

@ -51,7 +51,8 @@ public final class SQLDatabaseManager implements DatabaseManager {
String connectionString = "jdbc:mysql://" + mcMMO.p.getGeneralConfig().getMySQLServerName()
+ ":" + 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 +=
"?verifyServerCertificate=false"+
"&useSSL=true"+

View File

@ -483,7 +483,7 @@ public class mcMMO extends JavaPlugin {
return upgradeManager;
}
public static CompatibilityManager getCompatibilityManager() {
public static @Nullable CompatibilityManager getCompatibilityManager() {
return platformManager.getCompatibilityManager();
}

View File

@ -30,10 +30,10 @@ import java.util.HashMap;
*/
//TODO: I need to rewrite this crap
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 final MinecraftGameVersion minecraftGameVersion;
private final NMSVersion nmsVersion;
private final @NotNull MinecraftGameVersion minecraftGameVersion;
private final @NotNull NMSVersion nmsVersion;
/* Compatibility Layers */
// private PlayerAttackCooldownExploitPreventionLayer playerAttackCooldownExploitPreventionLayer;
@ -42,7 +42,7 @@ public class CompatibilityManager {
private AbstractMasterAnglerCompatibility masterAnglerCompatibility;
private WorldCompatibilityLayer worldCompatibilityLayer;
public CompatibilityManager(MinecraftGameVersion minecraftGameVersion) {
public CompatibilityManager(@NotNull MinecraftGameVersion minecraftGameVersion) {
mcMMO.p.getLogger().info("Loading compatibility layers...");
this.minecraftGameVersion = minecraftGameVersion;
this.nmsVersion = determineNMSVersion();
@ -77,24 +77,8 @@ public class CompatibilityManager {
}
private void initWorldCompatibilityLayer() {
if(minecraftGameVersion.getMinorVersion().asInt() > 17
|| (minecraftGameVersion.getMinorVersion().asInt() >= 16 && minecraftGameVersion.getPatchVersion().asInt() >= 4)
|| minecraftGameVersion.getMajorVersion().asInt() >= 2) {
if(hasNewWorldMinHeightAPI()) {
worldCompatibilityLayer = new WorldCompatibilityLayer_1_16_4();
} else {
worldCompatibilityLayer = new WorldCompatibilityLayer() {
@Override
public int getMinWorldHeight(@NotNull World world) {
return WorldCompatibilityLayer.super.getMinWorldHeight(world);
}
@Override
public int getMaxWorldHeight(@NotNull World world) {
return WorldCompatibilityLayer.super.getMaxWorldHeight(world);
}
};
}
if(minecraftGameVersion.isAtLeast(1, 17, 0)) {
worldCompatibilityLayer = new WorldCompatibilityLayer_1_16_4();
} else {
worldCompatibilityLayer = new WorldCompatibilityLayer() {
@Override
@ -111,37 +95,15 @@ public class CompatibilityManager {
}
private void initMasterAnglerLayer() {
if(minecraftGameVersion.getMinorVersion().asInt() >= 16 || minecraftGameVersion.getMajorVersion().asInt() >= 2) {
if(hasNewFishingHookAPI()) {
masterAnglerCompatibility = new MasterAnglerCompatibilityLayer();
}
if(minecraftGameVersion.isAtLeast(1, 16, 3)) {
masterAnglerCompatibility = new MasterAnglerCompatibilityLayer();
} else {
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() {
if(minecraftGameVersion.getMinorVersion().asInt() >= 16) {
if(minecraftGameVersion.isAtLeast(1, 16, 0)) {
bungeeSerializerCompatibilityLayer = new BungeeModernSerializerCompatibilityLayer();
} else {
bungeeSerializerCompatibilityLayer = new BungeeLegacySerializerCompatibilityLayer();
@ -151,7 +113,7 @@ public class CompatibilityManager {
}
private void initPersistentDataLayer() {
if(minecraftGameVersion.getMinorVersion().asInt() >= 14 || minecraftGameVersion.getMajorVersion().asInt() >= 2) {
if(minecraftGameVersion.isAtLeast(1, 14, 2)) {
persistentDataLayer = new SpigotPersistentDataLayer_1_14();
} else {
@ -162,7 +124,7 @@ public class CompatibilityManager {
}
//TODO: move to text manager
public void reportCompatibilityStatus(CommandSender commandSender) {
public void reportCompatibilityStatus(@NotNull CommandSender commandSender) {
if(isFullyCompatibleServerSoftware) {
commandSender.sendMessage(LocaleLoader.getString("mcMMO.Template.Prefix",
"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()));
}
public boolean isCompatibilityLayerOperational(CompatibilityType compatibilityType) {
public boolean isCompatibilityLayerOperational(@NotNull CompatibilityType compatibilityType) {
return supportedLayers.get(compatibilityType);
}
@ -192,6 +154,12 @@ public class CompatibilityManager {
}
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) {
switch (minecraftGameVersion.getMinorVersion().asInt()) {
case 12:
@ -237,4 +205,8 @@ public class CompatibilityManager {
public @NotNull WorldCompatibilityLayer getWorldCompatibilityLayer() {
return worldCompatibilityLayer;
}
public @Nullable MinecraftGameVersion getMinecraftGameVersion() {
return minecraftGameVersion;
}
}

View File

@ -27,4 +27,37 @@ public class MinecraftGameVersion extends MajorMinorPatchVersion {
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;
}
}