|
@@ -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 NMSVersion nmsVersion;
|
|
|
|
|
|
+ private final @NotNull MinecraftGameVersion minecraftGameVersion;
|
|
|
|
+ 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,24 +77,8 @@ public class CompatibilityManager {
|
|
}
|
|
}
|
|
|
|
|
|
private void initWorldCompatibilityLayer() {
|
|
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 {
|
|
} else {
|
|
worldCompatibilityLayer = new WorldCompatibilityLayer() {
|
|
worldCompatibilityLayer = new WorldCompatibilityLayer() {
|
|
@Override
|
|
@Override
|
|
@@ -111,37 +95,15 @@ public class CompatibilityManager {
|
|
}
|
|
}
|
|
|
|
|
|
private void initMasterAnglerLayer() {
|
|
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 {
|
|
} 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;
|
|
|
|
+ }
|
|
}
|
|
}
|