mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-08-06 14:35:26 +02:00
Fix SQL on 1.17 (hacky) and optimized CompatibilityManager
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user